]>
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. 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 * The current revision number
70 * The current revision as a string argument
76 * Constructor: determine the type of linking to use
78 * @param integer Path management type
84 if ($type < 1 OR $type > 2)
86 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path management type specified in [includes/config.php]'));
89 $this->type
= (int)$type;
91 $this->path
= $this->parse();
92 $this->revnum
= $this->revnum
;
93 $this->revstr
= $this->revstr
;
97 * Constructs a repository browser link
101 * @param string Base path
102 * @param string Browser path, separated using '/'
104 * @return string Link path
106 function out($base, $addpath)
110 $url = $this->fetch_arguments($base);
111 $addpath = $this->sanitize($addpath);
114 if ($this->type
== 1)
116 return $url[0] . '?path=' . $addpath . ($url[1] ? '&' . $url[1] : '');
118 // advanced path system
119 else if ($this->type
== 2)
121 return $url[0] . ($addpath{0} != '/' ? '/' : '') . $addpath . ($url[1] ? '?' . $url[1] : '');
126 * Parses an incoming path with the various methods
127 * and returns a universal form
131 * @return string Universal path, separated using '/'
137 if (defined('PATH_OVERRIDE') AND PATH_OVERRIDE
== 1)
143 if ($this->type
== 1)
145 $path = $viewsvn->in
['path'];
147 // advanced path system
148 else if ($this->type
== 2)
150 if (@$_SERVER['PATH_INFO'])
152 $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
156 $viewsvn->trigger
->error($viewsvn->lang
->string('Your server does not support type-2 path management'));
162 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path sent'));
165 if (!$viewsvn->repos
->verify($this->repos
= $this->fetch_repos($path), $this->relpath
= $this->fetch_path($path)))
167 $viewsvn->trigger
->error($viewsvn->lang
->string('The path specified could not be verified'));
174 * Create path breadcrumb
178 * @param string Universal path
179 * @param bool Add trailing slash
181 * @return string Breadcrumb HTML
183 function construct_breadcrumb($path, $doslash = true)
190 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
191 $count = count($temp) - 1;
193 foreach ($temp AS $val => $item)
196 $itembit .= (($count != $val OR @$viewsvn->svn
->common
->isdir($itembit)) ? '/' : '');
197 $html .= '<a href="' . $viewsvn->path
. '/' . $this->out('browse.php' . $this->revstr
, $itembit) . '">' . $item . '</a>'. ($count != $val ? ' / ' : '');
204 * Returns the name of the repository from a upath
208 * @param string Universal path
210 * @return string Repository name
212 function fetch_repos($path)
214 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
219 * Returns the path without the repository from a upath
223 * @param string Universal path
224 * @param bool Preceding slash
226 * @return string Relative path
228 function fetch_path($path, $doslash = false)
230 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
232 return ($doslash ? '/' : '') . implode('/', $temp);
236 * Fetches any URL parameters a link has
240 * @param string Original URL
242 * @return array Two-element array: base path (no trailing '?'), arguments
244 function fetch_arguments($url)
248 $bits = parse_url($url);
250 if (isset($bits['query']))
252 $return[0] = $bits['path'];
253 $return[1] = $bits['query'];
257 $return[0] = $bits['path'];
265 * Determines if the root path has been reached
269 * @param string Universal path
271 * @return bool Root of path?
273 function is_root_path($path)
275 $path = $this->fetch_path($path);
276 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
277 if (count($temp) > 0)
288 * Returns the current sanitized revision
292 * @param bool High-low or not
293 * @param mixed High revision (or regular)
294 * @param mixed Low revision
296 * @return mixed Revision number or HEAD
298 function fetch_rev_num($highlow = false, $high = null, $low = null)
304 if (isset($viewsvn->in
['high']) AND is_null($high))
306 $high = $viewsvn->svn
->rev($viewsvn->in
['high']);
308 else if (is_null($high))
313 if (isset($viewsvn->in
['low']) AND is_null($low))
315 $low = $viewsvn->svn
->rev($viewsvn->in
['low']);
317 else if (is_null($low))
327 if (is_int($high) AND is_int($low) AND $low > $high)
334 return array('high' => $high, 'low' => $low);
338 if (isset($viewsvn->in
['rev']) AND is_null($high))
340 $rev = $viewsvn->svn
->rev($viewsvn->in
['rev']);
342 else if (is_null($high))
356 * Returns a GET string with sanitized revision data
360 * @param bool High-low or not
361 * @param mixed High revision (or regular)
362 * @param mixed Low revision
364 * @return string Revision GET data
366 function fetch_rev_str($highlow = false, $high = null, $low = null)
368 $rev = $this->fetch_rev_num($highlow, $high, $low);
372 return '?low=' . $rev['low'] . '&high=' . $rev['high'];
376 return '?rev=' . $rev;
381 * Sanitizes a path for passing
387 * @return string Cleaned string
389 function sanitize($path)
391 return preg_replace('#[^a-z0-9\./\-_]*#i', '', $path);
395 /*=====================================================================*\
396 || ###################################################################
399 || ###################################################################
400 \*=====================================================================*/