]>
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 browser paths
30 the majority of this stuff should go into the controller.
31 the string creators may need to go into a static class or something. or not. we'll see.
36 * This is a utility class that should be accessed in a static fashion. It
37 * provides tools for parsing incoming data into variables.
44 // ###################################################################
46 * Parses the incoming path variables and returns a sanitized path that
47 * is used to init the Controller
51 * @return string Universal path, separated using '/'
57 if (defined('PATH_OVERRIDE') AND PATH_OVERRIDE
== 1)
62 if (@$_SERVER['PATH_INFO'])
64 $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
68 $viewsvn->trigger
->error($viewsvn->lang
->string('Your server does not support type-2 path management'));
73 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path sent'));
79 // ###################################################################
81 * Returns the name of the repository from a upath
85 * @param string Universal path
87 * @return string Repository name
89 function fetch_repos($path)
91 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
95 // ###################################################################
97 * Returns the path without the repository from a upath
101 * @param string Universal path
102 * @param bool Preceding slash
104 * @return string Relative path
106 function fetch_path($path, $doslash = false)
108 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
110 return ($doslash ? '/' : '') . implode('/', $temp);
113 // ###################################################################
115 * Fetches any URL parameters a link has
119 * @param string Original URL
121 * @return array Two-element array: base path (no trailing '?'), arguments
123 function fetch_arguments($url)
127 $bits = parse_url($url);
129 if (isset($bits['query']))
131 $return[0] = $bits['path'];
132 $return[1] = $bits['query'];
136 $return[0] = $bits['path'];
143 // ###################################################################
145 * Determines if the root path has been reached
149 * @param string Universal path
151 * @return bool Root of path?
153 function is_root_path($path)
155 $path = Paths
::fetch_path($path);
156 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
157 if (sizeof($temp) > 0)
167 // ###################################################################
169 * Returns the current sanitized revision
173 * @param bool High-low or not
174 * @param mixed High revision (or regular)
175 * @param mixed Low revision
177 * @return mixed Revision number or HEAD
179 function fetch_rev_num($highlow = false, $high = null, $low = null)
185 if (isset($viewsvn->in
['high']) AND is_null($high))
187 $high = SVNCommon
::rev($viewsvn->in
['high']);
189 else if (is_null($high))
194 if (isset($viewsvn->in
['low']) AND is_null($low))
196 $low = SVNCommon
::rev($viewsvn->in
['low']);
198 else if (is_null($low))
208 if (is_int($high) AND is_int($low) AND $low > $high)
215 return array('high' => $high, 'low' => $low);
219 if (isset($viewsvn->in
['rev']) AND is_null($high))
221 $rev = SVNCommon
::rev($viewsvn->in
['rev']);
223 else if (is_null($high))
236 // ###################################################################
238 * Returns a GET string with sanitized revision data
242 * @param bool High-low or not
243 * @param mixed High revision (or regular)
244 * @param mixed Low revision
246 * @return string Revision GET data
248 function fetch_rev_str($highlow = false, $high = null, $low = null)
250 $rev = Paths
::fetch_rev_num($highlow, $high, $low);
254 return '?low=' . $rev['low'] . '&high=' . $rev['high'];
258 return '?rev=' . $rev;
262 // ###################################################################
264 * Sanitizes a path for passing
270 * @return string Cleaned string
272 function sanitize($path)
274 return preg_replace('#[^a-z0-9\./\-_]*#i', '', $path);
278 /*=====================================================================*\
279 || ###################################################################
282 || ###################################################################
283 \*=====================================================================*/