- Blame now works
[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 * Prints the file changed list
40 *
41 * @access public
42 *
43 * @public array List of file changes
44 * @public string The repository
45 * @public integer Current revision
46 *
47 * @return string Processed HTML
48 */
49 function construct_file_changes($changes, $repos, $revision)
50 {
51 global $viewsvn;
52
53 $files = '';
54
55 foreach ($changes AS $file)
56 {
57 switch ($file['action'])
58 {
59 case 'A':
60 $class = 'file_add';
61 $tooltip = $viewsvn->lang->string('Added');
62 break;
63 case 'D':
64 $class = 'file_delete';
65 $tooltip = $viewsvn->lang->string('Deleted');
66 break;
67 case 'M':
68 $class = 'file_modify';
69 $tooltip = $viewsvn->lang->string('Modified');
70 break;
71 case 'R':
72 $class = 'file_replace';
73 $tooltip = $viewsvn->lang->string('Replaced');
74 break;
75 }
76
77 $show['from'] = (bool)$file['from'];
78
79 if ($file['from'])
80 {
81 $class = 'file_move';
82 $tooltip = 'Moved/Copied';
83 preg_match('#(.*):([0-9]+)#', $file['from'], $matches);
84 $link['from'] = $viewsvn->path . '/view.php/' . $repos . '/' . $matches[1] . Paths::fetch_rev_str(false, $matches[2]);
85 }
86
87 $link['file'] = $viewsvn->path . '/view.php/' . $repos . $file['value'] . Paths::fetch_rev_str(false, $revision);
88
89 eval('$files .= "' . $viewsvn->template->fetch('file_change') . '";');
90 }
91
92 return $files;
93 }
94
95 // ###################################################################
96 /**
97 * Generates a clean revision number
98 *
99 * @access public
100 *
101 * @param integer Revision number
102 *
103 * @return mixed Cleaned revision or HEAD
104 */
105 function rev($revision)
106 {
107 if (($revision = intval($revision)) < 1)
108 {
109 $revision = 'HEAD';
110 }
111 return $revision;
112 }
113 }
114
115 /*=====================================================================*\
116 || ###################################################################
117 || # $HeadURL$
118 || # $Id$
119 || ###################################################################
120 \*=====================================================================*/
121 ?>