Added path management
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 27 Aug 2005 08:58:02 +0000 (08:58 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 27 Aug 2005 08:58:02 +0000 (08:58 +0000)
global.php [new file with mode: 0644]
includes/init.php
includes/paths.php [new file with mode: 0644]
includes/repository.php
index.php

diff --git a/global.php b/global.php
new file mode 100644 (file)
index 0000000..b469efc
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+/*=====================================================================*\
+|| ################################################################### ||
+|| # ViewSVN [#]version[#]
+|| # --------------------------------------------------------------- # ||
+|| # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
+|| # This file may not be reproduced in any way without permission.  # ||
+|| # --------------------------------------------------------------- # ||
+|| # User License Agreement at http://www.iris-studios.com/license/  # ||
+|| ################################################################### ||
+\*=====================================================================*/
+
+require_once('./includes/init.php');
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file
index 8dc8f9fc44df42d11fc455cb81094d7f177ae9eb..4452f95407417d90167aadebf20301667896784a 100644 (file)
@@ -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 (file)
index 0000000..3d0e418
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+/*=====================================================================*\
+|| ################################################################### ||
+|| # ViewSVN [#]version[#]
+|| # --------------------------------------------------------------- # ||
+|| # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
+|| # This file may not be reproduced in any way without permission.  # ||
+|| # --------------------------------------------------------------- # ||
+|| # User License Agreement at http://www.iris-studios.com/license/  # ||
+|| ################################################################### ||
+\*=====================================================================*/
+
+/**
+* Handles the various methods that are used to navigate
+* browser paths
+*
+* @package     ViewSVN
+*/
+
+/**
+* Path managing class that constructs and parses input
+* and output for paths
+*
+* @package     ViewSVN
+* @version     $Id$
+*/
+class Paths
+{
+       /**
+       * Path manager type
+       * @var  integer
+       */
+       var $type;
+       
+       /**
+       * Constructor: determine the type of linking to use
+       *
+       * @param        integer Path management type
+       */
+       function Paths($type)
+       {
+               global $viewsvn;
+               
+               if ($type < 1 OR $type > 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] ? '&amp;' . $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
index 37873c49e1cb38fc508b848631e5aca46516eafc..f50a0f40e3f8cde865468f5f6ac6372d8bcbb985 100644 (file)
 */
 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;
+               }
+       }
 }
 
 /*=====================================================================*\
index 1e01b16ae3be1d2928e3bbb027c781719e2f9e52..84aeadde9bdcca359a7e07ca064ac5f55ba30463 100644 (file)
--- a/index.php
+++ b/index.php
 || ################################################################### ||
 \*=====================================================================*/
 
+require_once('./global.php');
+
+echo '<ul>';
+echo "\n";
+
+foreach ($viewsvn->repos->fetch_list() AS $repos)
+{
+       echo '<li><a href="' . $viewsvn->paths->out('browse.php?do=stuff', $repos) . '">' . $repos . '</a></li>';
+       echo "\n";
+}
+
+echo '</ul>';
+
 /*=====================================================================*\
 || ###################################################################
 || # $HeadURL$