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 * Handles the various methods that are used to navigate
30 * Path managing class that constructs and parses input
31 * and output for paths. This is essentially a controller
32 * of all current information.
46 * The universal path that is currently being browsed
52 * Current repository that we're in
58 * Current internal path inside the repository
64 * Constructor: determine the type of linking to use
66 * @param integer Path management type
72 if ($type < 1 OR $type > 2)
74 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path management type specified in [includes/config.php]'));
77 $this->type
= (int)$type;
79 $this->path
= $this->parse();
83 * Constructs a repository browser link
87 * @param string Base path
88 * @param string Browser path, separated using '/'
90 * @return string Link path
92 function out($base, $addpath)
96 $url = $this->fetch_arguments($base);
97 $addpath = $this->sanitize($addpath);
100 if ($this->type
== 1)
102 return $url[0] . '?path=' . $addpath . ($url[1] ?
'&' . $url[1] : '');
104 // advanced path system
105 else if ($this->type
== 2)
107 return $url[0] . ($addpath{0} != '/' ?
'/' : '') . $addpath . ($url[1] ?
'?' . $url[1] : '');
112 * Parses an incoming path with the various methods
113 * and returns a universal form
117 * @return string Universal path, separated using '/'
123 if (defined('PATH_OVERRIDE') AND PATH_OVERRIDE
== 1)
129 if ($this->type
== 1)
131 $path = $viewsvn->in
['path'];
133 // advanced path system
134 else if ($this->type
== 2)
136 if (@$_SERVER['PATH_INFO'])
138 $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
142 $viewsvn->trigger
->error($viewsvn->lang
->string('Your server does not support type-2 path management'));
148 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path sent'));
151 if (!$viewsvn->repos
->verify($this->repos
= $this->fetch_repos($path), $this->relpath
= $this->fetch_path($path)))
153 $viewsvn->trigger
->error($viewsvn->lang
->string('The path specified could not be verified'));
160 * Create path breadcrumb
164 * @param string Universal path
165 * @param bool Add trailing slash
167 * @return string Breadcrumb HTML
169 function construct_breadcrumb($path, $doslash = true
)
176 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
177 $count = count($temp) - 1;
179 foreach ($temp AS $val => $item)
182 $itembit .= (($count != $val OR @$viewsvn->svn
->common
->isdir($itembit)) ?
'/' : '');
183 $html .= '<a href="' . $viewsvn->path
. '/' . $this->out('browse.php' . $this->fetch_rev_str(), $itembit) . '">' . $item . '</a>'. ($count != $val ?
' / ' : '');
190 * Returns the name of the repository from a upath
194 * @param string Universal path
196 * @return string Repository name
198 function fetch_repos($path)
200 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
205 * Returns the path without the repository from a upath
209 * @param string Universal path
210 * @param bool Preceding slash
212 * @return string Relative path
214 function fetch_path($path, $doslash = false
)
216 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
218 return ($doslash ?
'/' : '') . implode('/', $temp);
222 * Fetches any URL parameters a link has
226 * @param string Original URL
228 * @return array Two-element array: base path (no trailing '?'), arguments
230 function fetch_arguments($url)
234 $bits = parse_url($url);
236 if (isset($bits['query']))
238 $return[0] = $bits['path'];
239 $return[1] = $bits['query'];
243 $return[0] = $bits['path'];
251 * Determines if the root path has been reached
255 * @param string Universal path
257 * @return bool Root of path?
259 function is_root_path($path)
261 $path = $this->fetch_path($path);
262 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
263 if (count($temp) > 0)
274 * Returns the current sanitized revision
278 * @param bool High-low or not
279 * @param mixed High revision (or regular)
280 * @param mixed Low revision
282 * @return mixed Revision number or HEAD
284 function fetch_rev_num($highlow = false
, $high = null
, $low = null
)
290 if (isset($viewsvn->in
['high']) AND is_null($high))
292 $high = $viewsvn->svn
->rev($viewsvn->in
['high']);
294 else if (is_null($high))
299 if (isset($viewsvn->in
['low']) AND is_null($low))
301 $low = $viewsvn->svn
->rev($viewsvn->in
['low']);
303 else if (is_null($low))
313 if (is_int($high) AND is_int($low) AND $low > $high)
320 return array('high' => $high, 'low' => $low);
324 if (isset($viewsvn->in
['rev']) AND is_null($high))
326 $rev = $viewsvn->svn
->rev($viewsvn->in
['rev']);
328 else if (is_null($high))
342 * Returns a GET string with sanitized revision data
346 * @param bool High-low or not
347 * @param mixed High revision (or regular)
348 * @param mixed Low revision
350 * @return string Revision GET data
352 function fetch_rev_str($highlow = false
, $high = null
, $low = null
)
354 $rev = $this->fetch_rev_num($highlow, $high, $low);
358 return '?low=' . $rev['low'] . '&high=' . $rev['high'];
362 return '?rev=' . $rev;
367 * Sanitizes a path for passing
373 * @return string Cleaned string
375 function sanitize($path)
377 return preg_replace('#[^a-z0-9\./\-_]*#i', '', $path);
381 /*=====================================================================*\
382 || ###################################################################
385 || ###################################################################
386 \*=====================================================================*/