Migrating stuff from Paths to Node_Controller
[viewsvn.git] / includes / node.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 Node_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 /**
110 * Constructor
111 *
112 * @access public
113 */
114 function Node_Controller($nodepath)
115 {
116 global $viewsvn;
117
118 // variables
119 $this->fullpath = $nodepath;
120
121 $temp = preg_split('#/#', $this->fullpath, -1, PREG_SPLIT_NO_EMPTY);
122
123 $this->repos = $temp[0];
124
125 unset($temp[0]);
126 $this->path = '/' . implode('/', $temp);
127
128 // objects
129 $this->registry =& $viewsvn;
130
131 $this->repospath = $this->registry->repos->fetch_path($this->repos);
132
133 $this->revnum = Paths::fetch_rev_num();
134 $this->revstr = Paths::fetch_rev_str();
135
136 require_once('./includes/shellcmd.php');
137 $this->xquery = new Shell($this);
138
139 require_once('./includes/svnlib.php');
140 $this->library = new SVNLib($this);
141
142 require_once('./includes/cachev.php');
143 $this->cachev = new cacheV($this);
144 }
145
146 // ###################################################################
147 /**
148 * Produces a link href that allows for a completely different path
149 * than the one in the controller. This is used for navigating upstream.
150 *
151 * @access public
152 *
153 * @param string Base path (e.g. browse.php)
154 * @param string New relative path
155 *
156 * @return string Constructed path
157 */
158 function href_struct($base, $path)
159 {
160 $url = Paths::fetch_arguments($base);
161 $path = Paths::sanitize($addpath);
162
163 return $this->registry->path . '/' . $url[0] . '/' . $this->repos . ($path{0} != '/' ? '/' : '') . $path . ($url[1] ? '?' . $url[1] : '');
164 }
165
166 // ###################################################################
167 /**
168 * Compounds a path by adding another level. This is used for navigating
169 * downstream.
170 *
171 * @access public
172 *
173 * @param string Base path (e.g. browse.php)
174 * @param string Attach path (or none for current)
175 *
176 * @return string Constructed path
177 */
178 function href_compound($base, $attach = null)
179 {
180 $url = Paths::fetch_arguments($base);
181 $attach = Paths::sanitize($attach);
182
183 if ($attach === null)
184 {
185 $path = $this->path;
186 }
187 else
188 {
189 $path = $this->path . ($attach{0} != '/' ? '/' : '') . $attach;
190 }
191
192 return $this->href_struct($base, $path);
193 }
194
195 // ###################################################################
196 /**
197 * Constructs a repository browser link
198 *
199 * @access public
200 *
201 * @param string Base path
202 * @param string Browser path, separated using '/'
203 *
204 * @return string Link path
205 */
206 function out($base, $addpath = null)
207 {
208 global $viewsvn;
209
210 if ($addpath === null)
211 {
212 $addpath = $this->path;
213 }
214
215 $url = Paths::fetch_arguments($base);
216 $addpath = Paths::sanitize($addpath);
217
218 // standard URL type
219 if ($this->registry->paths->type == 1)
220 {
221 return $url[0] . '?path=' . $addpath . ($url[1] ? '&amp;' . $url[1] : '');
222 }
223 // advanced path system
224 else if ($this->registry->paths->type == 2)
225 {
226 return $url[0] . '/' . $this->repos . ($addpath{0} != '/' ? '/' : '') . $addpath . ($url[1] ? '?' . $url[1] : '');
227 }
228 }
229
230 // ###################################################################
231 /**
232 * Create path breadcrumb
233 *
234 * @access public
235 *
236 * @return string Breadcrumb HTML
237 */
238 function construct_breadcrumb()
239 {
240 $html = '/ ';
241 $itembit = '/';
242
243 $temp = preg_split('#/#', $this->path, -1, PREG_SPLIT_NO_EMPTY);
244 $count = count($temp) - 1;
245
246 foreach ($temp AS $val => $item)
247 {
248 $itembit .= $item;
249 $itembit .= (($count != $val OR $this->cachev->isdir($itembit)) ? '/' : '');
250 $html .= '<a href="' . $this->href_struct('browse.php' . $this->revstr, $itembit) . '">' . $item . '</a>'. ($count != $val ? ' / ' : '');
251 }
252
253 return $html;
254 }
255 }
256
257 /*=====================================================================*\
258 || ###################################################################
259 || # $HeadURL$
260 || # $Id$
261 || ###################################################################
262 \*=====================================================================*/
263 ?>