- browse.php basics in place
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 27 Aug 2005 21:30:22 +0000 (21:30 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 27 Aug 2005 21:30:22 +0000 (21:30 +0000)
- added SVNLib

browse.php
includes/init.php
includes/paths.php
includes/repository.php
includes/svnlib.php

index 22073f856faf2b568b8942d1507d36ae8340e117..ecdd9fca78db372aebb54e0c90c3281cbd75a30f 100644 (file)
@@ -16,7 +16,32 @@ $path = $viewsvn->paths->parse();
 $repos = $viewsvn->paths->fetch_repos($path);
 $relpath = $viewsvn->paths->fetch_path($path);
 
+$listing = $viewsvn->svn->ls($repos, $relpath, 0);
 
+print_r($listing);
+
+echo '<ul>';
+echo "\n";
+
+echo '<li><a href="/viewsvn/' . $viewsvn->paths->out('browse.php', $path . '..') . '">Up One Level</a></li>';
+echo "\n";
+
+foreach ($listing AS $item)
+{
+       echo '<li>';
+       if ($item{ strlen($item) - 1 } == '/')
+       {
+               echo '<a href="/viewsvn/' . $viewsvn->paths->out('browse.php', $path . $item) . '">' . $item . '</a>';
+       }
+       else
+       {
+               echo '<a href="/viewsvn/' . $viewsvn->paths->out('log.php', $path . $item) . '">'. $item . '</a>';
+       }
+       echo '</li>';
+       echo "\n";
+}
+
+echo '</ul>';
 
 /*=====================================================================*\
 || ###################################################################
index 4452f95407417d90167aadebf20301667896784a..285665510e9e090e4182213d90784f6099b60aec 100644 (file)
@@ -60,6 +60,11 @@ $viewsvn->repos =& new Repository($repository, $iscontainer);
 require_once('./includes/paths.php');
 $viewsvn->paths =& new Paths($pathtype);
 
+// ###################################################################
+// initialize SVN
+require_once('./includes/svnlib.php');
+$viewsvn->svn =& new SVNLib($svnpath);
+
 /*=====================================================================*\
 || ###################################################################
 || # $HeadURL$
index 3d8e593a9d94e88ae910d2c4584b3db0062f33e5..877de03669b34a8f8f9f92fdf9b70222a4643484 100644 (file)
@@ -74,7 +74,7 @@ class Paths
                // advanced path system
                else if ($this->type == 2)
                {
-                       return $url[0] . '/' . $viewsvn->fetch_sourcepath($addpath) . ($url[1] ? '?' . $url[1] : '');
+                       return $url[0] . ($addpath{0} != '/' ? '/' : '') . $viewsvn->fetch_sourcepath($addpath) . ($url[1] ? '?' . $url[1] : '');
                }
        }
        
@@ -98,7 +98,7 @@ class Paths
                // advanced path system
                else if ($this->type == 2)
                {
-                       if ($_SERVER['PATH_INFO'])
+                       if (@$_SERVER['PATH_INFO'])
                        {
                                $path = $viewsvn->sanitize($_SERVER['PATH_INFO']);
                        }
@@ -190,7 +190,7 @@ class Paths
        */
        function sanitize($path)
        {
-               return preg_replace('#[^a-z0-9\.]*#i', '', $path);
+               return preg_replace('#[^a-z0-9\./\-]*#i', '', $path);
        }
 }
 
index 82d77aa5e5d26283719189851732c35bfe81f28f..7d93339ab41734ed6b129dd3b898fbadb1777901 100644 (file)
@@ -117,11 +117,11 @@ class Repository
                
                if ($this->container)
                {
-                       return $this->path . $repository;
+                       return 'file://' . $this->path . $repository;
                }
                else
                {
-                       return $this->path;
+                       return 'file://' . $this->path;
                }
        }
        
index 1e01b16ae3be1d2928e3bbb027c781719e2f9e52..ce6dc6c9901e99a3cd1366bde2d006f58a501df0 100644 (file)
 || ################################################################### ||
 \*=====================================================================*/
 
+/**
+* Command line interface with the SVN commands
+*
+* @package     ViewSVN
+*/
+
+/**
+* Interacts with the command line subsystem to
+* access SVN information
+*
+* @package     ViewSVN
+* @version     $Id$
+*/
+class SVNLib
+{
+       /**
+       * Path to the SVN binary
+       * @var  string
+       */
+       var $svnpath;
+       
+       /**
+       * Constructor: validate SVN path
+       *
+       * @param        string  Path to SVN binary
+       */
+       function SVNLib($svnpath)
+       {
+               global $viewsvn;
+               
+               $this->svnpath = $viewsvn->shell->cmd($svnpath);
+               
+               $access = $viewsvn->shell->exec($this->svnpath . ' --version');
+               
+               if (!$access)
+               {
+                       $viewsvn->trigger->error('svn binary could not be found');
+               }
+               
+               if (!preg_match('#^svn, version (.*?)\)$#i', trim($access[0])))
+               {
+                       $viewsvn->trigger->error('svn binary does not pass test');
+               }
+       }
+       
+       /**
+       * Executes the SVN binary
+       *
+       * @access       private
+       *
+       * @param        string  Command
+       *
+       * @return       array   Output
+       */
+       function svn($command)
+       {
+               global $viewsvn;
+               
+               return $viewsvn->shell->exec($this->svnpath . ' ' . $command . ' 2>&1');
+       }
+       
+       /**
+       * SVN Wrapper: standard command system
+       *
+       * @access       private
+       *
+       * @param        string  SVN command
+       * @param        string  Repository
+       * @param        string  Path
+       * @param        integer Revision
+       *
+       * @return       array   Lines of output
+       */
+       function std($command, $repos, $path, $revision)
+       {
+               global $viewsvn;
+               
+               $revision = $this->rev($revision);
+               $repospath = $viewsvn->repos->fetch_path($repos);
+               
+               return $this->svn($command . ' -r' . $revision . ' ' . $repospath . $path);
+       }
+       
+       /**
+       * SVN Wrapper: blame
+       *
+       * @access       protected
+       *
+       * @param        string  Repository
+       * @param        string  Path
+       * @param        integer Revision
+       *
+       * @return       array   Lines of blame output
+       */
+       function blame($repos, $path, $revision)
+       {
+               return $this->std('blame', $repos, $path, $revision);
+       }
+       
+       /**
+       * SVN Wrapper: cat
+       *
+       * @access       protected
+       *
+       * @param        string  Repository
+       * @param        string  Path
+       * @param        integer Revision
+       *
+       * @return       array   Lines of cat output
+       */
+       function cat($repos, $path, $revision)
+       {
+               return $this->std('cat', $repos, $path, $revision);
+       }
+       
+       /**
+       * SVN Wrapper: ls (list)
+       *
+       * @access       protected
+       *
+       * @param        string  Repository
+       * @param        string  Path
+       * @param        integer Revision
+       *
+       * @return       array   Lines of list output
+       */
+       function ls($repos, $path, $revision)
+       {
+               return $this->std('list', $repos, $path, $revision);
+       }
+       
+       /**
+       * Generates a clean revision number
+       *
+       * @access       public
+       *
+       * @param        integer Revision number
+       *
+       * @return       mixed   Cleaned revision or HEAD
+       */
+       function rev($revision)
+       {
+               if (($revision = intval($revision)) < 1)
+               {
+                       $revision = 'HEAD';
+               }
+               return $revision;
+       }
+}
+
 /*=====================================================================*\
 || ###################################################################
 || # $HeadURL$