]>
src.bluestatic.org Git - viewsvn.git/blob - includes/paths.php
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
45 * Path to Enscript binary
51 * Constructor: determine the type of linking to use
53 * @param integer Path management type
59 if ($type < 1 OR $type > 2)
61 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path management type specified in [includes/config.php]'));
64 $this->type
= (int)$type;
68 * Constructs a repository browser link
72 * @param string Base path
73 * @param string Browser path, separated using '/'
75 * @return string Link path
77 function out($base, $addpath)
81 $url = $this->fetch_arguments($base);
82 $addpath = $this->sanitize($addpath);
87 return $url[0] . '?path=' . $addpath . ($url[1] ? '&' . $url[1] : '');
89 // advanced path system
90 else if ($this->type
== 2)
92 return $url[0] . ($addpath{0} != '/' ? '/' : '') . $addpath . ($url[1] ? '?' . $url[1] : '');
97 * Parses an incoming path with the various methods
98 * and returns a universal form
102 * @return string Universal path, separated using '/'
109 if ($this->type
== 1)
111 $path = $viewsvn->in
['path'];
113 // advanced path system
114 else if ($this->type
== 2)
116 if (@$_SERVER['PATH_INFO'])
118 $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
122 $viewsvn->trigger
->error($viewsvn->lang
->string('Your server does not support type-2 path management'));
128 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path sent'));
131 if (!$viewsvn->repos
->verify($this->fetch_repos($path), $this->fetch_path($path)))
133 $viewsvn->trigger
->error($viewsvn->lang
->string('The path specified could not be verified'));
140 * Create path breadcrumb
144 * @param string Universal path
145 * @param bool Add trailing slash
147 * @return string Breadcrumb HTML
149 function construct_breadcrumb($path, $doslash = true)
156 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
157 $count = count($temp) - 1;
159 foreach ($temp AS $val => $item)
162 $itembit .= (($count != $val OR @$viewsvn->svn
->common
->isdir($itembit)) ? '/' : '');
163 $html .= '<a href="' . $viewsvn->path
. '/' . $this->out('browse.php' . $this->fetch_rev_str(), $itembit) . '">' . $item . '</a>'. ($count != $val ? ' / ' : '');
170 * Returns the name of the repository from a upath
174 * @param string Universal path
176 * @return string Repository name
178 function fetch_repos($path)
180 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
185 * Returns the path without the repository from a upath
189 * @param string Universal path
190 * @param bool Preceding slash
192 * @return string Relative path
194 function fetch_path($path, $doslash = false)
196 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
198 return ($doslash ? '/' : '') . implode('/', $temp);
202 * Fetches any URL parameters a link has
206 * @param string Original URL
208 * @return array Two-element array: base path (no trailing '?'), arguments
210 function fetch_arguments($url)
214 $bits = parse_url($url);
216 if (isset($bits['query']))
218 $return[0] = $bits['path'];
219 $return[1] = $bits['query'];
223 $return[0] = $bits['path'];
231 * Determines if the root path has been reached
235 * @param string Universal path
237 * @return bool Root of path?
239 function is_root_path($path)
241 $path = $this->fetch_path($path);
242 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
243 if (count($temp) > 0)
254 * Returns the current sanitized revision
258 * @param bool High-low or not
259 * @param mixed High revision (or regular)
260 * @param mixed Low revision
262 * @return mixed Revision number or HEAD
264 function fetch_rev_num($highlow = false, $high = null, $low = null)
270 if (isset($viewsvn->in
['high']) AND is_null($high))
272 $high = $viewsvn->svn
->rev($viewsvn->in
['high']);
274 else if (is_null($high))
279 if (isset($viewsvn->in
['low']) AND is_null($low))
281 $low = $viewsvn->svn
->rev($viewsvn->in
['low']);
283 else if (is_null($low))
293 if (is_int($high) AND is_int($low) AND $low > $high)
300 return array('high' => $high, 'low' => $low);
304 if (isset($viewsvn->in
['rev']) AND is_null($high))
306 $rev = $viewsvn->svn
->rev($viewsvn->in
['rev']);
308 else if (is_null($high))
322 * Returns a GET string with sanitized revision data
326 * @param bool High-low or not
327 * @param mixed High revision (or regular)
328 * @param mixed Low revision
330 * @return string Revision GET data
332 function fetch_rev_str($highlow = false, $high = null, $low = null)
334 $rev = $this->fetch_rev_num($highlow, $high, $low);
338 return '?low=' . $rev['low'] . '&high=' . $rev['high'];
342 return '?rev=' . $rev;
347 * Sanitizes a path for passing
353 * @return string Cleaned string
355 function sanitize($path)
357 return preg_replace('#[^a-z0-9\./\-_]*#i', '', $path);
361 /*=====================================================================*\
362 || ###################################################################
365 || ###################################################################
366 \*=====================================================================*/