We now can get revision information:
[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 * This is a utility class that should be accessed in a static fashion. It
30 * is responsbile for various parsing mechanisms, mainly.
31 *
32 * @package ViewSVN
33 * @version $Id$
34 */
35 class SVNCommon
36 {
37 // ###################################################################
38 /**
39 * Prepares data for output
40 *
41 * @access public
42 *
43 * @param string Standard data
44 *
45 * @return string Output-ready data
46 */
47 function format($string)
48 {
49 // convert entities
50 $string = htmlspecialchars($string);
51
52 // tabs to 5 spaces
53 $string = str_replace("\t", ' ', $string);
54
55 // spaces to nbsp
56 if (true)
57 {
58 $string = preg_replace('#( +)#e', 'SVNCommon::format_spaces("\1")', $string);
59 }
60 // no word wrap
61 else
62 {
63 $string = str_replace(' ', '&nbsp;', $string);
64 }
65
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);
69
70 // nl2br
71 $string = nl2br($string);
72
73 return $string;
74 }
75
76 // ###################################################################
77 /**
78 * Counts the spaces and replaces two or more ones
79 *
80 * @access private
81 *
82 * @param string Spaced string
83 *
84 * @return string &nbsp;'d string
85 */
86 function format_spaces($thestring)
87 {
88 if (strlen($thestring) >= 2)
89 {
90 $thestring = str_replace(' ', '&nbsp;', $thestring);
91 }
92
93 return $thestring;
94 }
95
96 // ###################################################################
97 /**
98 * Prints the file changed list
99 *
100 * @access public
101 *
102 * @public array List of file changes
103 * @public string The repository
104 * @public integer Current revision
105 *
106 * @return string Processed HTML
107 */
108 function construct_file_changes($changes, $repos, $revision)
109 {
110 global $viewsvn;
111
112 $files = '';
113
114 foreach ($changes AS $file)
115 {
116 switch ($file['action'])
117 {
118 case 'A':
119 $class = 'file_add';
120 $tooltip = $viewsvn->lang->string('Added');
121 break;
122 case 'D':
123 $class = 'file_delete';
124 $tooltip = $viewsvn->lang->string('Deleted');
125 break;
126 case 'M':
127 $class = 'file_modify';
128 $tooltip = $viewsvn->lang->string('Modified');
129 break;
130 case 'R':
131 $class = 'file_replace';
132 $tooltip = $viewsvn->lang->string('Replaced');
133 break;
134 }
135
136 $show['from'] = (bool)$file['from'];
137
138 if ($file['from'])
139 {
140 $class = 'file_move';
141 $tooltip = 'Moved/Copied';
142 preg_match('#(.*):([0-9]+)#', $file['from'], $matches);
143 $link['from'] = $viewsvn->path . '/view.php/' . $repos . '/' . $matches[1] . Paths::fetch_rev_str(false, $matches[2]);
144 }
145
146 $link['file'] = $viewsvn->path . '/view.php/' . $repos . $file['value'] . Paths::fetch_rev_str(false, $revision);
147
148 eval('$files .= "' . $viewsvn->template->fetch('file_change') . '";');
149 }
150
151 return $files;
152 }
153
154 // ###################################################################
155 /**
156 * Generates a clean revision number
157 *
158 * @access public
159 *
160 * @param integer Revision number
161 *
162 * @return mixed Cleaned revision or HEAD
163 */
164 function rev($revision)
165 {
166 if (($revision = intval($revision)) < 1)
167 {
168 $revision = 'HEAD';
169 }
170 return $revision;
171 }
172 }
173
174 /*=====================================================================*\
175 || ###################################################################
176 || # $HeadURL$
177 || # $Id$
178 || ###################################################################
179 \*=====================================================================*/
180 ?>