2 /*=====================================================================*\
3 || ################################################################### ||
4 || # ViewSVN [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
14 * Handles the various methods that are used to navigate
21 * Path managing class that constructs and parses input
22 * and output for paths
36 * Constructor: determine the type of linking to use
38 * @param integer Path management type
44 if ($type < 1 OR $type > 2)
46 $viewsvn->trigger
->error('invalid path management type');
49 $this->type
= (int)$type;
53 * Constructs a repository browser link
57 * @param string Base path
58 * @param string Browser path, separated using '/'
60 * @return string Link path
62 function out($base, $addpath)
66 $url = $this->fetch_arguments($base);
67 $addpath = $this->sanitize($addpath);
72 return $url[0] . '?path=' . $addpath . ($url[1] ?
'&' . $url[1] : '');
74 // advanced path system
75 else if ($this->type
== 2)
77 return $url[0] . ($addpath{0} != '/' ?
'/' : '') . $addpath . ($url[1] ?
'?' . $url[1] : '');
82 * Parses an incoming path with the various methods
83 * and returns a universal form
87 * @return string Universal path, separated using '/'
96 $path = $viewsvn->in
['path'];
98 // advanced path system
99 else if ($this->type
== 2)
101 if (@$_SERVER['PATH_INFO'])
103 $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
107 $viewsvn->trigger
->error('server does not support type 2 management');
113 $viewsvn->trigger
->error('invalid path sent');
116 if (!$viewsvn->repos
->verify($this->fetch_repos($path), $this->fetch_path($path)))
118 $viewsvn->trigger
->error('invalid path');
125 * Create path breadcrumb
129 * @param string Universal path
130 * @param bool Add trailing slash
132 * @return string Breadcrumb HTML
134 function construct_breadcrumb($path, $doslash = true
)
139 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
140 $count = count($temp) - 1;
142 foreach ($temp AS $val => $item)
144 $itembit .= $item . (($count != $val) ?
'/' : ($doslash ?
'/' : ''));
145 $html .= ($count == $val ?
'<strong>' : '<a href="/viewsvn/' . $this->out('browse.php' . $this->fetch_rev_str(), $itembit) . '">') . $item . ($count == $val ?
'</strong>' : '</a>') . ($count != $val ?
' / ' : '');
152 * Returns the name of the repository from a upath
156 * @param string Universal path
158 * @return string Repository name
160 function fetch_repos($path)
162 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
167 * Returns the path without the repository from a upath
171 * @param string Universal path
172 * @param bool Preceding slash
174 * @return string Relative path
176 function fetch_path($path, $doslash = false
)
178 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
180 return ($doslash ?
'/' : '') . implode('/', $temp);
184 * Fetches any URL parameters a link has
188 * @param string Original URL
190 * @return array Two-element array: base path (no trailing '?'), arguments
192 function fetch_arguments($url)
196 $bits = parse_url($url);
198 if (isset($bits['query']))
200 $return[0] = $bits['path'];
201 $return[1] = $bits['query'];
205 $return[0] = $bits['path'];
213 * Determines if the root path has been reached
217 * @param string Universal path
219 * @return bool Root of path?
221 function is_root_path($path)
223 $path = $this->fetch_path($path);
224 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
225 if (count($temp) > 0)
236 * Returns the current sanitized revision
240 * @param bool High-low or not
241 * @param mixed High revision (or regular)
242 * @param mixed Low revision
244 * @return mixed Revision number or HEAD
246 function fetch_rev_num($highlow = false
, $high = null
, $low = null
)
252 if (isset($viewsvn->in
['high']) AND is_null($high))
254 $high = $viewsvn->svn
->rev($viewsvn->in
['high']);
256 else if (is_null($high))
261 if (isset($viewsvn->in
['low']))
263 $low = $viewsvn->svn
->rev($viewsvn->in
['low']);
265 else if (is_null($low))
275 if (is_int($high) AND is_int($low) AND $low > $high)
282 return array('high' => $high, 'low' => $low);
286 if (isset($viewsvn->in
['rev']) AND is_null($high))
288 $rev = $viewsvn->svn
->rev($viewsvn->in
['rev']);
290 else if (is_null($high))
304 * Returns a GET string with sanitized revision data
308 * @param bool High-low or not
309 * @param mixed High revision (or regular)
310 * @param mixed Low revision
312 * @return string Revision GET data
314 function fetch_rev_str($highlow = false
, $high = null
, $low = null
)
316 $rev = $this->fetch_rev_num($highlow, $high, $low);
320 return '?low=' . $rev['low'] . '&high=' . $rev['high'];
324 return '?rev=' . $rev;
329 * Sanitizes a path for passing
335 * @return string Cleaned string
337 function sanitize($path)
339 return preg_replace('#[^a-z0-9\./\-_]*#i', '', $path);
343 /*=====================================================================*\
344 || ###################################################################
347 || ###################################################################
348 \*=====================================================================*/