]>
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 * Constructor: determine the type of linking to use
47 * @param integer Path management type
53 if ($type < 1 OR $type > 2)
55 $viewsvn->trigger
->error('invalid path management type');
58 $this->type
= (int)$type;
62 * Constructs a repository browser link
66 * @param string Base path
67 * @param string Browser path, separated using '/'
69 * @return string Link path
71 function out($base, $addpath)
75 $url = $this->fetch_arguments($base);
76 $addpath = $this->sanitize($addpath);
81 return $url[0] . '?path=' . $addpath . ($url[1] ? '&' . $url[1] : '');
83 // advanced path system
84 else if ($this->type
== 2)
86 return $url[0] . ($addpath{0} != '/' ? '/' : '') . $addpath . ($url[1] ? '?' . $url[1] : '');
91 * Parses an incoming path with the various methods
92 * and returns a universal form
96 * @return string Universal path, separated using '/'
103 if ($this->type
== 1)
105 $path = $viewsvn->in
['path'];
107 // advanced path system
108 else if ($this->type
== 2)
110 if (@$_SERVER['PATH_INFO'])
112 $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
116 $viewsvn->trigger
->error('server does not support type 2 management');
122 $viewsvn->trigger
->error('invalid path sent');
125 if (!$viewsvn->repos
->verify($this->fetch_repos($path), $this->fetch_path($path)))
127 $viewsvn->trigger
->error('invalid path');
134 * Create path breadcrumb
138 * @param string Universal path
139 * @param bool Add trailing slash
141 * @return string Breadcrumb HTML
143 function construct_breadcrumb($path, $doslash = true)
150 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
151 $count = count($temp) - 1;
153 foreach ($temp AS $val => $item)
156 $itembit .= (($count != $val OR @$viewsvn->svn
->common
->isdir($itembit)) ? '/' : '');
157 $html .= '<a href="' . $viewsvn->path
. '/' . $this->out('browse.php' . $this->fetch_rev_str(), $itembit) . '">' . $item . '</a>'. ($count != $val ? ' / ' : '');
164 * Returns the name of the repository from a upath
168 * @param string Universal path
170 * @return string Repository name
172 function fetch_repos($path)
174 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
179 * Returns the path without the repository from a upath
183 * @param string Universal path
184 * @param bool Preceding slash
186 * @return string Relative path
188 function fetch_path($path, $doslash = false)
190 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
192 return ($doslash ? '/' : '') . implode('/', $temp);
196 * Fetches any URL parameters a link has
200 * @param string Original URL
202 * @return array Two-element array: base path (no trailing '?'), arguments
204 function fetch_arguments($url)
208 $bits = parse_url($url);
210 if (isset($bits['query']))
212 $return[0] = $bits['path'];
213 $return[1] = $bits['query'];
217 $return[0] = $bits['path'];
225 * Determines if the root path has been reached
229 * @param string Universal path
231 * @return bool Root of path?
233 function is_root_path($path)
235 $path = $this->fetch_path($path);
236 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
237 if (count($temp) > 0)
248 * Returns the current sanitized revision
252 * @param bool High-low or not
253 * @param mixed High revision (or regular)
254 * @param mixed Low revision
256 * @return mixed Revision number or HEAD
258 function fetch_rev_num($highlow = false, $high = null, $low = null)
264 if (isset($viewsvn->in
['high']) AND is_null($high))
266 $high = $viewsvn->svn
->rev($viewsvn->in
['high']);
268 else if (is_null($high))
273 if (isset($viewsvn->in
['low']))
275 $low = $viewsvn->svn
->rev($viewsvn->in
['low']);
277 else if (is_null($low))
287 if (is_int($high) AND is_int($low) AND $low > $high)
294 return array('high' => $high, 'low' => $low);
298 if (isset($viewsvn->in
['rev']) AND is_null($high))
300 $rev = $viewsvn->svn
->rev($viewsvn->in
['rev']);
302 else if (is_null($high))
316 * Returns a GET string with sanitized revision data
320 * @param bool High-low or not
321 * @param mixed High revision (or regular)
322 * @param mixed Low revision
324 * @return string Revision GET data
326 function fetch_rev_str($highlow = false, $high = null, $low = null)
328 $rev = $this->fetch_rev_num($highlow, $high, $low);
332 return '?low=' . $rev['low'] . '&high=' . $rev['high'];
336 return '?rev=' . $rev;
341 * Sanitizes a path for passing
347 * @return string Cleaned string
349 function sanitize($path)
351 return preg_replace('#[^a-z0-9\./\-_]*#i', '', $path);
355 /*=====================================================================*\
356 || ###################################################################
359 || ###################################################################
360 \*=====================================================================*/