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.
46 // ###################################################################
48 * Parses the incoming path variables and returns a sanitized path that
49 * is used to init the Node_Controller
53 * @return string Universal path, separated using '/'
59 if (defined('PATH_OVERRIDE') AND PATH_OVERRIDE
== 1)
64 if (@$_SERVER['PATH_INFO'])
66 $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
70 $viewsvn->trigger
->error($viewsvn->lang
->string('Your server does not support type-2 path management'));
75 $viewsvn->trigger
->error($viewsvn->lang
->string('Invalid path sent'));
82 * Returns the name of the repository from a upath
86 * @param string Universal path
88 * @return string Repository name
90 function fetch_repos($path)
92 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
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);
114 * Fetches any URL parameters a link has
118 * @param string Original URL
120 * @return array Two-element array: base path (no trailing '?'), arguments
122 function fetch_arguments($url)
126 $bits = parse_url($url);
128 if (isset($bits['query']))
130 $return[0] = $bits['path'];
131 $return[1] = $bits['query'];
135 $return[0] = $bits['path'];
143 * Determines if the root path has been reached
147 * @param string Universal path
149 * @return bool Root of path?
151 function is_root_path($path)
153 $path = $this->fetch_path($path);
154 $temp = preg_split('#/#', $path, -1, PREG_SPLIT_NO_EMPTY
);
155 if (count($temp) > 0)
166 * Returns the current sanitized revision
170 * @param bool High-low or not
171 * @param mixed High revision (or regular)
172 * @param mixed Low revision
174 * @return mixed Revision number or HEAD
176 function fetch_rev_num($highlow = false
, $high = null
, $low = null
)
182 if (isset($viewsvn->in
['high']) AND is_null($high))
184 $high = $viewsvn->svn
->rev($viewsvn->in
['high']);
186 else if (is_null($high))
191 if (isset($viewsvn->in
['low']) AND is_null($low))
193 $low = $viewsvn->svn
->rev($viewsvn->in
['low']);
195 else if (is_null($low))
205 if (is_int($high) AND is_int($low) AND $low > $high)
212 return array('high' => $high, 'low' => $low);
216 if (isset($viewsvn->in
['rev']) AND is_null($high))
218 $rev = SVNCommon
::rev($viewsvn->in
['rev']);
220 else if (is_null($high))
234 * Returns a GET string with sanitized revision data
238 * @param bool High-low or not
239 * @param mixed High revision (or regular)
240 * @param mixed Low revision
242 * @return string Revision GET data
244 function fetch_rev_str($highlow = false
, $high = null
, $low = null
)
246 $rev = Paths
::fetch_rev_num($highlow, $high, $low);
250 return '?low=' . $rev['low'] . '&high=' . $rev['high'];
254 return '?rev=' . $rev;
259 * Sanitizes a path for passing
265 * @return string Cleaned string
267 function sanitize($path)
269 return preg_replace('#[^a-z0-9\./\-_]*#i', '', $path);
273 /*=====================================================================*\
274 || ###################################################################
277 || ###################################################################
278 \*=====================================================================*/