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
31 the majority of this stuff should go into the controller.
32 the string creators may need to go into a static class or something. or not. we'll see.
37 * Path managing class that constructs and parses input
38 * and output for paths. This is essentially a controller
39 * of all current information.
53 * The universal path that is currently being browsed
59 * Current repository that we're in
65 * Current internal path inside the repository
71 * The current revision number
77 * The current revision as a string argument
83 * Constructor: determine the type of linking to use
85 * @param integer Path management type
91 if ($type < 1 OR $type > 2)
93 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path management type specified in [includes/config.php]'));
96 $this->type
= (int)$type;
98 $this->path
= $this->parse();
99 $this->revnum
= $this->revnum
;
100 $this->revstr
= $this->revstr
;
104 * Constructs a repository browser link
108 * @param string Base path
109 * @param string Browser path, separated using '/'
111 * @return string Link path
113 function out($base, $addpath)
117 $url = $this->fetch_arguments($base);
118 $addpath = $this->sanitize($addpath);
121 if ($this->type
== 1)
123 return $url[0] . '?path=' . $addpath . ($url[1] ?
'&' . $url[1] : '');
125 // advanced path system
126 else if ($this->type
== 2)
128 return $url[0] . ($addpath{0} != '/' ?
'/' : '') . $addpath . ($url[1] ?
'?' . $url[1] : '');
133 * Parses an incoming path with the various methods
134 * and returns a universal form
138 * @return string Universal path, separated using '/'
144 if (defined('PATH_OVERRIDE') AND PATH_OVERRIDE
== 1)
150 if ($this->type
== 1)
152 $path = $viewsvn->in
['path'];
154 // advanced path system
155 else if ($this->type
== 2)
157 if (@$_SERVER['PATH_INFO'])
159 $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
163 $viewsvn->trigger
->error($viewsvn->lang
->string('Your server does not support type-2 path management'));
169 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path sent'));
172 if (!$viewsvn->repos
->verify($this->repos
= $this->fetch_repos($path), $this->relpath
= $this->fetch_path($path)))
174 $viewsvn->trigger
->error($viewsvn->lang
->string('The path specified could not be verified'));
181 * Returns the name of the repository from a upath
185 * @param string Universal path
187 * @return string Repository name
189 function fetch_repos($path)
191 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
196 * Returns the path without the repository from a upath
200 * @param string Universal path
201 * @param bool Preceding slash
203 * @return string Relative path
205 function fetch_path($path, $doslash = false
)
207 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
209 return ($doslash ?
'/' : '') . implode('/', $temp);
213 * Fetches any URL parameters a link has
217 * @param string Original URL
219 * @return array Two-element array: base path (no trailing '?'), arguments
221 function fetch_arguments($url)
225 $bits = parse_url($url);
227 if (isset($bits['query']))
229 $return[0] = $bits['path'];
230 $return[1] = $bits['query'];
234 $return[0] = $bits['path'];
242 * Determines if the root path has been reached
246 * @param string Universal path
248 * @return bool Root of path?
250 function is_root_path($path)
252 $path = $this->fetch_path($path);
253 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
254 if (count($temp) > 0)
265 * Returns the current sanitized revision
269 * @param bool High-low or not
270 * @param mixed High revision (or regular)
271 * @param mixed Low revision
273 * @return mixed Revision number or HEAD
275 function fetch_rev_num($highlow = false
, $high = null
, $low = null
)
281 if (isset($viewsvn->in
['high']) AND is_null($high))
283 $high = $viewsvn->svn
->rev($viewsvn->in
['high']);
285 else if (is_null($high))
290 if (isset($viewsvn->in
['low']) AND is_null($low))
292 $low = $viewsvn->svn
->rev($viewsvn->in
['low']);
294 else if (is_null($low))
304 if (is_int($high) AND is_int($low) AND $low > $high)
311 return array('high' => $high, 'low' => $low);
315 if (isset($viewsvn->in
['rev']) AND is_null($high))
317 $rev = $viewsvn->svn
->rev($viewsvn->in
['rev']);
319 else if (is_null($high))
333 * Returns a GET string with sanitized revision data
337 * @param bool High-low or not
338 * @param mixed High revision (or regular)
339 * @param mixed Low revision
341 * @return string Revision GET data
343 function fetch_rev_str($highlow = false
, $high = null
, $low = null
)
345 $rev = $this->fetch_rev_num($highlow, $high, $low);
349 return '?low=' . $rev['low'] . '&high=' . $rev['high'];
353 return '?rev=' . $rev;
358 * Sanitizes a path for passing
364 * @return string Cleaned string
366 function sanitize($path)
368 return preg_replace('#[^a-z0-9\./\-_]*#i', '', $path);
372 /*=====================================================================*\
373 || ###################################################################
376 || ###################################################################
377 \*=====================================================================*/