Add contextual revision number which should be used EVERYWHERE :)
[viewsvn.git] / includes / controller.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 * Node Controller
24 *
25 * This class represents one node in SVN. For each node that you need
26 * to display information about, create a new instance of this class.
27 * Generally, however, this one instance should be able to handle
28 * the needs of the entire class.
29 *
30 * @author Iris Studios, Inc.
31 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
32 * @version $Revision$
33 * @package ViewSVN
34 *
35 */
36 class Controller
37 {
38 /**
39 * Registry class
40 * @var object
41 * @access private
42 */
43 var $registry = null;
44
45 /**
46 * Xquery layer
47 * @var object
48 * @access private
49 */
50 var $xquery = null;
51
52 /**
53 * Xquery method library
54 * @var object
55 * @access private
56 */
57 var $library = null;
58
59 /**
60 * cacheV layer
61 * @var object
62 * @access private
63 */
64 var $cachev = null;
65
66 /**
67 * Full, universal path of the node
68 * @var string
69 * @access public
70 */
71 var $fullpath;
72
73 /**
74 * Repository of the path
75 * @var string
76 * @access public
77 */
78 var $repos;
79
80 /**
81 * The full path to the repository
82 * @var string
83 * @access public
84 */
85 var $repospath;
86
87 /**
88 * Relative path in the repository
89 * @var string
90 * @access public
91 */
92 var $path;
93
94 /**
95 * The current revision number
96 * @var integer
97 * @access public
98 */
99 var $revnum;
100
101 /**
102 * The current revision as a string argument
103 * @var string
104 * @access public
105 */
106 var $revstr;
107
108 /**
109 * The revision number in context for this node. For instance, r40 may be passed, but the file only has revision 38 (and that's what this would be)
110 * @var integer
111 * @access public
112 */
113 var $revctx;
114
115 // ###################################################################
116 /**
117 * Constructor
118 *
119 * @access public
120 */
121 function Controller($nodepath)
122 {
123 global $viewsvn;
124
125 // variables
126 $this->fullpath = $nodepath;
127
128 $temp = preg_split('#/#', $this->fullpath, -1, PREG_SPLIT_NO_EMPTY);
129
130 $this->repos = $temp[0];
131
132 unset($temp[0]);
133 $this->path = '/' . implode('/', $temp);
134
135 // objects
136 $this->registry =& $viewsvn;
137
138 $this->repospath = $this->registry->repos->fetch_path($this->repos);
139
140 $this->revnum = Paths::fetch_rev_num();
141 $this->revstr = Paths::fetch_rev_str();
142
143 require_once('./includes/shellcmd.php');
144 $this->xquery = new Shell($this);
145
146 require_once('./includes/svnlib.php');
147 $this->library = new SVNLib($this);
148
149 require_once('./includes/cachev.php');
150 $this->cachev = new cacheV($this);
151
152 $this->revctx = $this->cachev->fetch_revision_context($this->revnum);
153 $this->revctx = $this->revctx['revision'];
154 }
155
156 // ###################################################################
157 /**
158 * Produces a link href that allows for a completely different path
159 * than the one in the controller. This is used for navigating upstream.
160 *
161 * @access public
162 *
163 * @param string Base path (e.g. browse.php)
164 * @param string New relative path
165 *
166 * @return string Constructed path
167 */
168 function href_struct($base, $path)
169 {
170 $url = Paths::fetch_arguments($base);
171 $path = Paths::sanitize($path);
172
173 return $this->registry->path . '/' . $url[0] . '/' . $this->repos . ($path{0} != '/' ? '/' : '') . $path . ($url[1] ? '?' . $url[1] : '');
174 }
175
176 // ###################################################################
177 /**
178 * Compounds a path by adding another level. This is used for navigating
179 * downstream.
180 *
181 * @access public
182 *
183 * @param string Base path (e.g. browse.php)
184 * @param string Attach path (or none for current)
185 * @param bool Attach a given revision string, null for none
186 *
187 * @return string Constructed path
188 */
189 function href_compound($base, $attach = null, $revstr = null)
190 {
191 $url = Paths::fetch_arguments($base . ($revstr === null ? ((strpos($base, '?') !== false) ? '&' . $this->revstr : $this->revstr) : $revstr));
192
193 if ($attach === null)
194 {
195 $path = $this->path;
196 }
197 else
198 {
199 $attach = Paths::sanitize($attach);
200 $path = $this->path . (($attach[0] != '/' AND $this->path[ strlen($this->path) - 1 ] != '/') ? '/' : '') . $attach;
201 }
202
203 return $this->href_struct($base . ($url[1] ? '?' . $url[1] : ''), $path);
204 }
205
206 // ###################################################################
207 /**
208 * Constructs a repository browser link
209 *
210 * @access public
211 *
212 * @param string Base path
213 * @param string Browser path, separated using '/'
214 *
215 * @return string Link path
216 */
217 function out($base, $addpath = null)
218 {
219 global $viewsvn;
220
221 if ($addpath === null)
222 {
223 $addpath = $this->path;
224 }
225
226 $url = Paths::fetch_arguments($base);
227 $addpath = Paths::sanitize($addpath);
228
229 // standard URL type
230 if ($this->registry->paths->type == 1)
231 {
232 return $url[0] . '?path=' . $addpath . ($url[1] ? '&amp;' . $url[1] : '');
233 }
234 // advanced path system
235 else if ($this->registry->paths->type == 2)
236 {
237 return $url[0] . '/' . $this->repos . ($addpath{0} != '/' ? '/' : '') . $addpath . ($url[1] ? '?' . $url[1] : '');
238 }
239 }
240
241 // ###################################################################
242 /**
243 * Create path breadcrumb
244 *
245 * @access public
246 *
247 * @return string Breadcrumb HTML
248 */
249 function construct_breadcrumb()
250 {
251 $html = '/ ';
252
253 $temp = preg_split('#/#', $this->fullpath, -1, PREG_SPLIT_NO_EMPTY);
254 $count = sizeof($temp) - 1;
255
256 foreach ($temp AS $val => $item)
257 {
258 $itembit = $item;
259 $itembit .= (($count != $val OR $this->cachev->isdir($itembit)) ? '/' : '');
260 $html .= '<a href="' . $this->href_struct('browse.php' . $this->revstr, ($val == 0 ? '' : $itembit)) . '">' . $item . '</a>'. ($count != $val ? ' / ' : '');
261 }
262
263 return $html;
264 }
265 }
266
267 /*=====================================================================*\
268 || ###################################################################
269 || # $HeadURL$
270 || # $Id$
271 || ###################################################################
272 \*=====================================================================*/
273 ?>