]>
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)
155 $itembit .= $item . ($count != $val ? '/' : '');
156 $html .= '<a href="' . $viewsvn->path
. '/' . $this->out('browse.php' . $this->fetch_rev_str(), $itembit) . '">' . $item . '</a>'. ($count != $val ? ' / ' : '');
163 * Returns the name of the repository from a upath
167 * @param string Universal path
169 * @return string Repository name
171 function fetch_repos($path)
173 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
178 * Returns the path without the repository from a upath
182 * @param string Universal path
183 * @param bool Preceding slash
185 * @return string Relative path
187 function fetch_path($path, $doslash = false)
189 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
191 return ($doslash ? '/' : '') . implode('/', $temp);
195 * Fetches any URL parameters a link has
199 * @param string Original URL
201 * @return array Two-element array: base path (no trailing '?'), arguments
203 function fetch_arguments($url)
207 $bits = parse_url($url);
209 if (isset($bits['query']))
211 $return[0] = $bits['path'];
212 $return[1] = $bits['query'];
216 $return[0] = $bits['path'];
224 * Determines if the root path has been reached
228 * @param string Universal path
230 * @return bool Root of path?
232 function is_root_path($path)
234 $path = $this->fetch_path($path);
235 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
236 if (count($temp) > 0)
247 * Returns the current sanitized revision
251 * @param bool High-low or not
252 * @param mixed High revision (or regular)
253 * @param mixed Low revision
255 * @return mixed Revision number or HEAD
257 function fetch_rev_num($highlow = false, $high = null, $low = null)
263 if (isset($viewsvn->in
['high']) AND is_null($high))
265 $high = $viewsvn->svn
->rev($viewsvn->in
['high']);
267 else if (is_null($high))
272 if (isset($viewsvn->in
['low']))
274 $low = $viewsvn->svn
->rev($viewsvn->in
['low']);
276 else if (is_null($low))
286 if (is_int($high) AND is_int($low) AND $low > $high)
293 return array('high' => $high, 'low' => $low);
297 if (isset($viewsvn->in
['rev']) AND is_null($high))
299 $rev = $viewsvn->svn
->rev($viewsvn->in
['rev']);
301 else if (is_null($high))
315 * Returns a GET string with sanitized revision data
319 * @param bool High-low or not
320 * @param mixed High revision (or regular)
321 * @param mixed Low revision
323 * @return string Revision GET data
325 function fetch_rev_str($highlow = false, $high = null, $low = null)
327 $rev = $this->fetch_rev_num($highlow, $high, $low);
331 return '?low=' . $rev['low'] . '&high=' . $rev['high'];
335 return '?rev=' . $rev;
340 * Sanitizes a path for passing
346 * @return string Cleaned string
348 function sanitize($path)
350 return preg_replace('#[^a-z0-9\./\-_]*#i', '', $path);
354 /*=====================================================================*\
355 || ###################################################################
358 || ###################################################################
359 \*=====================================================================*/