2) { $viewsvn->trigger->error('invalid path management type'); } $this->type = (int)$type; } /** * Constructs a repository browser link * * @access public * * @param string Base path * @param string Browser path, separated using '/' * * @return string Link path */ function out($base, $addpath) { global $viewsvn; $url = $this->fetch_arguments($base); $addpath = $this->sanitize($addpath); // standard URL type if ($this->type == 1) { return $url[0] . '?path=' . $addpath . ($url[1] ? '&' . $url[1] : ''); } // advanced path system else if ($this->type == 2) { return $url[0] . ($addpath{0} != '/' ? '/' : '') . $addpath . ($url[1] ? '?' . $url[1] : ''); } } /** * Parses an incoming path with the various methods * and returns a universal form * * @access public * * @return string Universal path, separated using '/' */ function parse() { global $viewsvn; // standard URL type if ($this->type == 1) { $path = $viewsvn->in['path']; } // advanced path system else if ($this->type == 2) { if (@$_SERVER['PATH_INFO']) { $path = $viewsvn->sanitize($_SERVER['PATH_INFO']); } else { $viewsvn->trigger->error('server does not support type 2 management'); } } if (!$path) { $viewsvn->trigger->error('invalid path sent'); } if (!$viewsvn->repos->verify($this->fetch_repos($path), $this->fetch_path($path))) { $viewsvn->trigger->error('invalid path'); } return $path; } /** * Returns the name of the repository from a upath * * @access public * * @param string Universal path * * @return string Repository name */ function fetch_repos($path) { $temp = preg_split('#/#', $path, 0, PREG_SPLIT_NO_EMPTY); return $temp[0]; } /** * Returns the path without the repository from a upath * * @access public * * @param string Universal path * * @return string Relative path */ function fetch_path($path) { $temp = preg_split('#/#', $path, 0, PREG_SPLIT_NO_EMPTY); unset($temp[0]); return '/' . implode('/', $temp); } /** * Fetches any URL parameters a link has * * @access public * * @param string Original URL * * @return array Two-element array: base path (no trailing '?'), arguments */ function fetch_arguments($url) { $return = array(); if (($pos = strpos($url, '?')) !== false) { $return[0] = substr($url, 0, strlen($url) - $pos + 1); $return[1] = substr($url, $pos + 1); } else { $return[0] = $url; $return[1] = ''; } return $return; } /** * Determines if the root path has been reached * * @access public * * @param string Universal path * * @return bool Root of path? */ function is_root_path($path) { $path = $this->fetch_path($path); $temp = preg_split('#/#', $path, 0, PREG_SPLIT_NO_EMPTY); if (count($temp) > 0) { return false; } else { return true; } } /** * Sanitizes a path for passing * * @access private * * @param string Path * * @return string Cleaned string */ function sanitize($path) { return preg_replace('#[^a-z0-9\./\-]*#i', '', $path); } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>