]>
src.bluestatic.org Git - viewsvn.git/blob - includes/paths.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # ViewSVN [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
14 * Handles the various methods that are used to navigate
21 * Path managing class that constructs and parses input
22 * and output for paths
36 * Constructor: determine the type of linking to use
38 * @param integer Path management type
44 if ($type < 1 OR $type > 2)
46 $viewsvn->trigger
->error('invalid path management type');
49 $this->type
= (int)$type;
53 * Constructs a repository browser link
57 * @param string Base path
58 * @param string Browser path, separated using '/'
60 * @return string Link path
62 function out($base, $addpath)
66 $url = $this->fetch_arguments($base);
67 $addpath = $this->sanitize($addpath);
72 return $url[0] . '?path=' . $addpath . ($url[1] ? '&' . $url[1] : '');
74 // advanced path system
75 else if ($this->type
== 2)
77 return $url[0] . ($addpath{0} != '/' ? '/' : '') . $addpath . ($url[1] ? '?' . $url[1] : '');
82 * Parses an incoming path with the various methods
83 * and returns a universal form
87 * @return string Universal path, separated using '/'
96 $path = $viewsvn->in
['path'];
98 // advanced path system
99 else if ($this->type
== 2)
101 if (@$_SERVER['PATH_INFO'])
103 $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
107 $viewsvn->trigger
->error('server does not support type 2 management');
113 $viewsvn->trigger
->error('invalid path sent');
116 if (!$viewsvn->repos
->verify($this->fetch_repos($path), $this->fetch_path($path)))
118 $viewsvn->trigger
->error('invalid path');
125 * Returns the name of the repository from a upath
129 * @param string Universal path
131 * @return string Repository name
133 function fetch_repos($path)
135 $temp = preg_split('#/#', $path, 0, PREG_SPLIT_NO_EMPTY
);
140 * Returns the path without the repository from a upath
144 * @param string Universal path
146 * @return string Relative path
148 function fetch_path($path)
150 $temp = preg_split('#/#', $path, 0, PREG_SPLIT_NO_EMPTY
);
152 return '/' . implode('/', $temp);
156 * Fetches any URL parameters a link has
160 * @param string Original URL
162 * @return array Two-element array: base path (no trailing '?'), arguments
164 function fetch_arguments($url)
168 if (($pos = strpos($url, '?')) !== false)
170 $return[0] = substr($url, 0, strlen($url) - $pos +
1);
171 $return[1] = substr($url, $pos +
1);
183 * Sanitizes a path for passing
189 * @return string Cleaned string
191 function sanitize($path)
193 return preg_replace('#[^a-z0-9\./\-]*#i', '', $path);
197 /*=====================================================================*\
198 || ###################################################################
201 || ###################################################################
202 \*=====================================================================*/