]>
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 * Interacts with the command line subsystem to
30 * access SVN information
38 * Prepares data for output
42 * @param string Standard data
44 * @return string Output-ready data
46 function format($string)
49 $string = htmlspecialchars($string);
52 $string = str_replace("\t", ' ', $string);
57 $string = preg_replace('#( +)#e', 'SVNCommon::format_spaces("\1")', $string);
62 $string = str_replace(' ', ' ', $string);
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);
70 $string = nl2br($string);
76 * Formats a SVN log message
80 * @param string Unformatted log message
82 * @return string Output-ready log message
84 function format_log_message($message)
88 $message = $viewsvn->entity_encode($message);
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);
93 $lines = explode("\n", $message);
95 foreach ($lines AS $line)
97 if (preg_match('#^\s*?(\*|\-)\s?(.*)#', $line, $matches))
101 $message .= '<li>' . $matches[2] . '</li>';
105 $message .= '<ul class="list">';
106 $message .= '<li>' . $matches[2] . '</li>';
120 $message .= '<br />';
133 $message = preg_replace('#(<br />)*$#', '', $message);
138 // ###################################################################
140 * Parses a date from Xquery XML outut
144 * @param string Date string
146 * @return string Formatted and readable date string
148 function format_date_string($string)
150 // 2005-01-23T20:42:53.703057Z
151 return preg_replace('#(....)\-(..)\-(..)T(..):(..):(..).(.*)Z#e', 'gmdate("r", mktime(\4, \5, \6, \2, \3, \1))', $string);
155 * Counts the spaces and replaces two or more ones
159 * @param string Spaced string
161 * @return string 'd string
163 function format_spaces($thestring)
165 if (strlen($thestring) >= 2)
167 $thestring = str_replace(' ', ' ', $thestring);
174 * Prints the file changed list
178 * @public array List of file changes
179 * @public string The repository
180 * @public integer Current revision
182 * @return string Processed HTML
184 function construct_file_changes($changes, $repos, $revision)
190 foreach ($changes AS $file)
192 switch ($file['action'])
196 $tooltip = $viewsvn->lang
->string('Added');
199 $class = 'file_delete';
200 $tooltip = $viewsvn->lang
->string('Deleted');
203 $class = 'file_modify';
204 $tooltip = $viewsvn->lang
->string('Modified');
207 $class = 'file_replace';
208 $tooltip = $viewsvn->lang
->string('Replaced');
212 $show['from'] = (bool)$file['from'];
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]);
222 $link['file'] = $viewsvn->path
. '/view.php/' . $repos . $file['value'] . Paths
::fetch_rev_str(false, $revision);
224 eval('$files .= "' . $viewsvn->template
->fetch('file_change') . '";');
231 * Generates a clean revision number
235 * @param integer Revision number
237 * @return mixed Cleaned revision or HEAD
239 function rev($revision)
241 if (($revision = intval($revision)) < 1)
249 /*=====================================================================*\
250 || ###################################################################
253 || ###################################################################
254 \*=====================================================================*/