From 2e3c500863301908fd7688f3000dcc30d5e12e13 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 27 Aug 2005 08:58:02 +0000 Subject: [PATCH] Added path management --- global.php | 21 +++++++ includes/init.php | 15 +++-- includes/paths.php | 129 ++++++++++++++++++++++++++++++++++++++++ includes/repository.php | 77 ++++++++++++++++++++---- index.php | 13 ++++ 5 files changed, 240 insertions(+), 15 deletions(-) create mode 100644 global.php create mode 100644 includes/paths.php diff --git a/global.php b/global.php new file mode 100644 index 0000000..b469efc --- /dev/null +++ b/global.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/includes/init.php b/includes/init.php index 8dc8f9f..4452f95 100644 --- a/includes/init.php +++ b/includes/init.php @@ -16,13 +16,13 @@ define('ISSO_MT_START', microtime()); // ################################################################### // configuration file -if (!file_exists('./config.php')) +if (!file_exists('./includes/config.php')) { echo 'includes/config.php needs to be present!'; exit; } -require_once('./config.php'); +require_once('./includes/config.php'); // ################################################################### // init isso @@ -42,19 +42,24 @@ $viewsvn->exec_sanitize_data(); // ################################################################### // imaginary reporter -require_once('./imaginary.php'); +require_once('./includes/imaginary.php'); $viewsvn->trigger =& new Imaginary(); // ################################################################### // load shell subsystem -require_once('./shellcmd.php'); +require_once('./includes/shellcmd.php'); $viewsvn->shell =& new Shell(); // ################################################################### // setup repository -require_once('./repository.php'); +require_once('./includes/repository.php'); $viewsvn->repos =& new Repository($repository, $iscontainer); +// ################################################################### +// path manager +require_once('./includes/paths.php'); +$viewsvn->paths =& new Paths($pathtype); + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/includes/paths.php b/includes/paths.php new file mode 100644 index 0000000..3d0e418 --- /dev/null +++ b/includes/paths.php @@ -0,0 +1,129 @@ + 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] . '/' . $viewsvn->fetch_sourcepath($addpath) . ($url[1] ? '?' . $url[1] : ''); + } + } + + /** + * 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); + $return[1] = substr($url, $pos + 1); + } + else + { + $return[0] = $url; + $return[1] = ''; + } + + return $return; + } + + /** + * 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$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/includes/repository.php b/includes/repository.php index 37873c4..f50a0f4 100644 --- a/includes/repository.php +++ b/includes/repository.php @@ -26,6 +26,24 @@ */ class Repository { + /** + * Array of valid repositories + * @var array + */ + var $repositories = array(); + + /** + * Root path to the repository + * @var string + */ + var $path; + + /** + * Whether or not the path is a container + * @var bool + */ + var $container; + /** * Constructor: prepare for repository * @@ -36,19 +54,18 @@ class Repository { global $viewsvn; - $repos = array(); + $this->path = $viewsvn->fetch_sourcepath($path); + $this->container = (bool)$iscontainer; - $path = $viewsvn->fetch_sourcepath($path); - - if ($iscontainer) + if ($this->container) { - if ($dir = @opendir($path)) + if ($dir = @opendir($this->path)) { while (($file = readdir($dir)) !== false) { - if (is_dir($path . $file) AND $file{0} != '.' AND is_dir($path . $file . '/' . 'db')) + if (is_dir($this->path . $file) AND $file{0} != '.' AND is_dir($this->path . $file . '/' . 'db')) { - $repos[] = $file; + $this->repositories[] = $file; } } closedir($dir); @@ -56,17 +73,57 @@ class Repository } else { - if (is_dir($path . 'db')) + if (is_dir($this->path . 'db')) { - $repos[] = $path; + $this->repositories[] = $this->path; } } - if (count($repos) < 1) + if (count($this->repositories) < 1) { $viewsvn->trigger->error('no valid repositories'); } } + + /** + * Returns a list of repositories + * + * @access public + * + * @return array List of repositories + */ + function fetch_list() + { + return $this->repositories; + } + + /** + * Returns a path to a repository + * + * @access public + * + * @param string Repository name + * + * @return string Full path to the repository + */ + function fetch_path($repository = '') + { + global $viewsvn; + + if (!in_array($repository, $this->fetch_list())) + { + $viewsvn->trigger->error('invalid repository name'); + } + + if ($this->container) + { + return $this->path . $repository; + } + else + { + return $this->path; + } + } } /*=====================================================================*\ diff --git a/index.php b/index.php index 1e01b16..84aeadd 100644 --- a/index.php +++ b/index.php @@ -10,6 +10,19 @@ || ################################################################### || \*=====================================================================*/ +require_once('./global.php'); + +echo ''; + /*=====================================================================*\ || ################################################################### || # $HeadURL$ -- 2.43.5