]> src.bluestatic.org Git - viewsvn.git/blob - includes/svncommon.php
Fixing SVNCommon::construct_file_changes()
[viewsvn.git] / includes / svncommon.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Common functions that aren't Xquery-related and advanced query systems
24 *
25 * @package ViewSVN
26 */
27
28 /**
29 * Interacts with the command line subsystem to
30 * access SVN information
31 *
32 * @package ViewSVN
33 * @version $Id$
34 */
35 class SVNCommon
36 {
37 /**
38 * Prepares data for output
39 *
40 * @access public
41 *
42 * @param string Standard data
43 *
44 * @return string Output-ready data
45 */
46 function format($string)
47 {
48 // convert entities
49 $string = htmlspecialchars($string);
50
51 // tabs to 5 spaces
52 $string = str_replace("\t", ' ', $string);
53
54 // spaces to nbsp
55 if (true)
56 {
57 $string = preg_replace('#( +)#e', 'SVNCommon::format_spaces("\1")', $string);
58 }
59 // no word wrap
60 else
61 {
62 $string = str_replace(' ', '&nbsp;', $string);
63 }
64
65 // convert advanced diff
66 $string = str_replace(array('{@+' . '+}', '{@-' . '-}'), array('<span class="diff_add_bit">', '<span class="diff_del_bit">'), $string);
67 $string = str_replace(array('{/@+' . '+}', '{/@-' . '-}'), '</span>', $string);
68
69 // nl2br
70 $string = nl2br($string);
71
72 return $string;
73 }
74
75 /**
76 * Formats a SVN log message
77 *
78 * @access public
79 *
80 * @param string Unformatted log message
81 *
82 * @return string Output-ready log message
83 */
84 function format_log_message($message)
85 {
86 global $viewsvn;
87
88 $message = $viewsvn->entity_encode($message);
89
90 $message = preg_replace('#r([0-9]+)#e', '"<a href=\"" . $viewsvn->path . "/" . $viewsvn->paths->out("diff.php" . $viewsvn->paths->fetch_rev_str(true, "\1", 0), $viewsvn->paths->fetch_repos($viewsvn->paths->parse()) . "/") . "\">r\1</a>"', $message);
91
92 $list = false;
93 $lines = explode("\n", $message);
94 $message = '';
95 foreach ($lines AS $line)
96 {
97 if (preg_match('#^\s*?(\*|\-)\s?(.*)#', $line, $matches))
98 {
99 if ($list)
100 {
101 $message .= '<li>' . $matches[2] . '</li>';
102 }
103 else
104 {
105 $message .= '<ul class="list">';
106 $message .= '<li>' . $matches[2] . '</li>';
107 }
108 $list = true;
109 }
110 else
111 {
112 if ($list)
113 {
114 $message .= '</ul>';
115 $message .= $line;
116 }
117 else
118 {
119 $message .= $line;
120 $message .= '<br />';
121 }
122 $list = false;
123 }
124
125 $message .= "\n";
126 }
127
128 if ($list)
129 {
130 $message .= '</ul>';
131 }
132
133 $message = preg_replace('#(<br />)*$#', '', $message);
134
135 return $message;
136 }
137
138 // ###################################################################
139 /**
140 * Parses a date from Xquery XML outut
141 *
142 * @access public
143 *
144 * @param string Date string
145 *
146 * @return string Formatted and readable date string
147 */
148 function format_date_string($string)
149 {
150 // 2005-01-23T20:42:53.703057Z
151 return preg_replace('#(....)\-(..)\-(..)T(..):(..):(..).(.*)Z#e', 'gmdate("r", mktime(\4, \5, \6, \2, \3, \1))', $string);
152 }
153
154 /**
155 * Counts the spaces and replaces two or more ones
156 *
157 * @access private
158 *
159 * @param string Spaced string
160 *
161 * @return string &nbsp;'d string
162 */
163 function format_spaces($thestring)
164 {
165 if (strlen($thestring) >= 2)
166 {
167 $thestring = str_replace(' ', '&nbsp;', $thestring);
168 }
169
170 return $thestring;
171 }
172
173 /**
174 * Prints the file changed list
175 *
176 * @access public
177 *
178 * @public array List of file changes
179 * @public string The repository
180 * @public integer Current revision
181 *
182 * @return string Processed HTML
183 */
184 function construct_file_changes($changes, $repos, $revision)
185 {
186 global $viewsvn;
187
188 $files = '';
189
190 foreach ($changes AS $file)
191 {
192 switch ($file['action'])
193 {
194 case 'A':
195 $class = 'file_add';
196 $tooltip = $viewsvn->lang->string('Added');
197 break;
198 case 'D':
199 $class = 'file_delete';
200 $tooltip = $viewsvn->lang->string('Deleted');
201 break;
202 case 'M':
203 $class = 'file_modify';
204 $tooltip = $viewsvn->lang->string('Modified');
205 break;
206 case 'R':
207 $class = 'file_replace';
208 $tooltip = $viewsvn->lang->string('Replaced');
209 break;
210 }
211
212 $show['from'] = (bool)$file['from'];
213
214 if ($file['from'])
215 {
216 $class = 'file_move';
217 $tooltip = 'Moved/Copied';
218 preg_match('#(.*):([0-9]+)#', $file['from'], $matches);
219 $link['from'] = $viewsvn->path . '/view.php/' . $repos . '/' . $matches[1] . Paths::fetch_rev_str(false, $matches[2]);
220 }
221
222 $link['file'] = $viewsvn->path . '/view.php/' . $repos . $file['value'] . Paths::fetch_rev_str(false, $revision);
223
224 eval('$files .= "' . $viewsvn->template->fetch('file_change') . '";');
225 }
226
227 return $files;
228 }
229
230 /**
231 * Generates a clean revision number
232 *
233 * @access public
234 *
235 * @param integer Revision number
236 *
237 * @return mixed Cleaned revision or HEAD
238 */
239 function rev($revision)
240 {
241 if (($revision = intval($revision)) < 1)
242 {
243 $revision = 'HEAD';
244 }
245 return $revision;
246 }
247 }
248
249 /*=====================================================================*\
250 || ###################################################################
251 || # $HeadURL$
252 || # $Id$
253 || ###################################################################
254 \*=====================================================================*/
255 ?>