]>
src.bluestatic.org Git - viewsvn.git/blob - includes/svncommon.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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.
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
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 \*=====================================================================*/
23 * Common functions that aren't Xquery-related and advanced query systems
29 * This is a utility class that should be accessed in a static fashion. It
30 * is responsbile for various parsing mechanisms, mainly.
37 // ###################################################################
39 * Prepares data for output
43 * @param string Standard data
45 * @return string Output-ready data
47 function format($string)
50 $string = htmlspecialchars($string);
53 $string = str_replace("\t", ' ', $string);
58 $string = preg_replace('#( +)#e', 'SVNCommon::format_spaces("\1")', $string);
63 $string = str_replace(' ', ' ', $string);
66 // convert advanced diff
67 $string = str_replace(array('{@+' . '+}', '{@-' . '-}'), array('<span class="diff_add_bit">', '<span class="diff_del_bit">'), $string);
68 $string = str_replace(array('{/@+' . '+}', '{/@-' . '-}'), '</span>', $string);
71 $string = nl2br($string);
76 // ###################################################################
78 * Formats a SVN log message
82 * @param string Unformatted log message
84 * @return string Output-ready log message
86 function format_log_message($message)
90 $message = $viewsvn->entity_encode($message);
92 $message = preg_replace('#r([0-9]+)#e', '"<a href=\"" . $viewsvn->maincontrol->href_struct("diff.php" . $viewsvn->paths->fetch_rev_str(true, "\1", 0), "/") . "\">r\1</a>"', $message);
95 $lines = explode("\n", $message);
97 foreach ($lines AS $line)
99 if (preg_match('#^\s*?(\*|\-)\s?(.*)#', $line, $matches))
103 $message .= '<li>' . $matches[2] . '</li>';
107 $message .= '<ul class="list">';
108 $message .= '<li>' . $matches[2] . '</li>';
122 $message .= '<br />';
135 $message = preg_replace('#(<br />)*$#', '', $message);
140 // ###################################################################
142 * Parses a date from Xquery XML outut
146 * @param string Date string
148 * @return string Formatted and readable date string
150 function format_date_string($string)
152 // 2005-01-23T20:42:53.703057Z
153 return preg_replace('#(....)\-(..)\-(..)T(..):(..):(..).(.*)Z#e', 'gmdate("r", mktime(\4, \5, \6, \2, \3, \1))', $string);
156 // ###################################################################
158 * Counts the spaces and replaces two or more ones
162 * @param string Spaced string
164 * @return string 'd string
166 function format_spaces($thestring)
168 if (strlen($thestring) >= 2)
170 $thestring = str_replace(' ', ' ', $thestring);
176 // ###################################################################
178 * Prints the file changed list
182 * @public array List of file changes
183 * @public string The repository
184 * @public integer Current revision
186 * @return string Processed HTML
188 function construct_file_changes($changes, $repos, $revision)
194 foreach ($changes AS $file)
196 switch ($file['action'])
200 $tooltip = $viewsvn->lang
->string('Added');
203 $class = 'file_delete';
204 $tooltip = $viewsvn->lang
->string('Deleted');
207 $class = 'file_modify';
208 $tooltip = $viewsvn->lang
->string('Modified');
211 $class = 'file_replace';
212 $tooltip = $viewsvn->lang
->string('Replaced');
216 $show['from'] = (bool)$file['from'];
220 $class = 'file_move';
221 $tooltip = 'Moved/Copied';
222 preg_match('#(.*):([0-9]+)#', $file['from'], $matches);
223 $link['from'] = $viewsvn->path
. '/view.php/' . $repos . '/' . $matches[1] . Paths
::fetch_rev_str(false, $matches[2]);
226 $link['file'] = $viewsvn->path
. '/view.php/' . $repos . $file['value'] . Paths
::fetch_rev_str(false, $revision);
228 eval('$files .= "' . $viewsvn->template
->fetch('file_change') . '";');
234 // ###################################################################
236 * Generates a clean revision number
240 * @param integer Revision number
242 * @return mixed Cleaned revision or HEAD
244 function rev($revision)
246 if (($revision = intval($revision)) < 1)
254 /*=====================================================================*\
255 || ###################################################################
258 || ###################################################################
259 \*=====================================================================*/