From 8a6ef7fc0455586fdffc40bae22f215c98742233 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 9 Apr 2007 02:14:50 +0000 Subject: [PATCH] Fixing the browser (mostly) --- browse.php | 49 ++---- global.php | 19 ++- includes/class_revision.php | 87 +++++++++++ includes/controller.php | 246 ------------------------------ includes/functions.php | 54 +++++++ includes/init.php | 2 + includes/repository.php | 16 +- templates/default/browse_node.tpl | 12 +- 8 files changed, 182 insertions(+), 303 deletions(-) create mode 100644 includes/class_revision.php delete mode 100644 includes/controller.php create mode 100644 includes/functions.php diff --git a/browse.php b/browse.php index 65c9749..0a95e96 100644 --- a/browse.php +++ b/browse.php @@ -27,29 +27,15 @@ $fetchtemplates = array( require_once('./global.php'); -$navbar = $controller->construct_breadcrumb(); +$navbar = ConstructNavbar(); // ################################################################### -$latest = $controller->cachev->fetch_node(); - -$link['log'] = $controller->href_compound('log.php'); - -$show['head'] = ($latest['revision'] != $controller->revctx); -if ($show['head']) -{ - $link['gohead'] = $controller->href_compound('browse.php', null, Paths::fetch_rev_str(false, 'HEAD')); - $link['diffhead'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(true, 'HEAD', $controller->revctx)); -} - -$show['prev'] = ($controller->cachev->fetch_prev_revision($controller->revctx) != -1); -if ($show['prev']) -{ - $link['diffprev'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(false, $controller->revctx)); -} +$revision = new Revision($input->in['repos'], $input->in['rev']); // ################################################################### +/* $show['props'] = false; $proplist = ''; if (sizeof($latest['properties']) > 0) @@ -61,34 +47,21 @@ if (sizeof($latest['properties']) > 0) eval('$proplist .= "' . $template->fetch('property') . '";'); } } +*/ // ################################################################### -$revinfo = $controller->cachev->fetch_revision($controller->revctx); +// $revinfo['message_clean'] = SVNCommon::format_log_message($revinfo['message']); +// $revinfo['date'] = SVNCommon::format_date_string($revinfo['dateline']); -$revinfo['message_clean'] = SVNCommon::format_log_message($revinfo['message']); -$revinfo['date'] = SVNCommon::format_date_string($revinfo['dateline']); - -$listing = $controller->library->command('ls'); +$listing = BSXml::Parse($lib->run('ls --xml -r' . $revision->revision . ' ' . $lib->arg($repos->fetchPath($input->in['repos']) . $input->in['path']), true)); +BSXml::UnifyNode($listing['lists']['list']['entry']); $nodes = ''; - -foreach ($listing AS $item) +foreach ($listing['lists']['list']['entry'] AS $item) { - if ($item[ strlen($item) - 1 ] == '/') - { - $show['directory'] = true; - $browse = $controller->href_compound('browse.php', $item); - } - else - { - $show['directory'] = false; - $view = $controller->href_compound('view.php', $item); - $blame = $controller->href_compound('blame.php', $item); - } - - $log = $controller->href_compound('log.php', $item); - + $isDir = ($item['kind'] == 'dir'); + $item = $item['name']['value']; eval('$nodes .= "' . $template->fetch('browse_node') . '";'); } diff --git a/global.php b/global.php index 7ef6af3..c62433f 100644 --- a/global.php +++ b/global.php @@ -20,10 +20,23 @@ \*=====================================================================*/ require_once('./includes/init.php'); -require_once('./includes/controller.php'); -$input->in['rev'] = $input->clean(substr($input->in['path'], strpos($input->in['path'], '@') + 1), TYPE_UINT); -$input->in['path'] = substr($input->in['path'], 0, strpos($input->in['path'], '@')); +require_once('./includes/functions.php'); +require_once('./includes/class_revision.php'); + +// ################################################################### +// define the path variables +$atpos = strpos($input->in['path'], '@'); +$input->in['rev'] = $input->clean(substr($input->in['path'], $atpos + 1), TYPE_UINT); +if ($atpos !== false) +{ + $input->in['path'] = substr($input->in['path'], 0, strpos($input->in['path'], '@')); +} + +// ################################################################### +// setup the SVN library +require_once('./includes/class_libsvn.php'); +BSRegister::Register('lib', $lib = new LibSVN($conf['paths']['svn'])); $fetchtemplates[] = 'header'; $fetchtemplates[] = 'footer'; diff --git a/includes/class_revision.php b/includes/class_revision.php new file mode 100644 index 0000000..30740cd --- /dev/null +++ b/includes/class_revision.php @@ -0,0 +1,87 @@ +path = BSRegister::Get('repos')->fetchPath($repos); + $this->repos = $repos; + + $this->_fetchRevision($rev); + } + + // ################################################################### + /** + * Gets the desired XML revision information from the repository + * + * @param integer Desired revision + */ + private function _fetchRevision($desired) + { + $xml = BSXml::Parse(BSRegister::Get('lib')->run('info --xml ' . ($desired > 0 ? '-r' . intval($desired) . ' ' : '') . BSRegister::Get('lib')->arg($this->path), true)); + $this->revision = intval($xml['info']['entry']['commit']['revision']); + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/includes/controller.php b/includes/controller.php deleted file mode 100644 index ceed0e5..0000000 --- a/includes/controller.php +++ /dev/null @@ -1,246 +0,0 @@ -fullpath = $nodepath; - - $temp = preg_split('#/#', $this->fullpath, -1, PREG_SPLIT_NO_EMPTY); - - $this->repos = $temp[0]; - - unset($temp[0]); - $this->path = '/' . implode('/', $temp); - - // objects - $this->registry =& $viewsvn; - - $this->repospath = $this->registry->repos->fetch_path($this->repos); - - $this->revnum = Paths::fetch_rev_num(); - $this->revstr = Paths::fetch_rev_str(); - - require_once('./includes/shellcmd.php'); - $this->xquery = new Shell($this); - - require_once('./includes/svnlib.php'); - $this->library = new SVNLib($this); - - require_once('./includes/cachev.php'); - $this->cachev = new cacheV($this); - - $this->revctx = $this->cachev->fetch_revision_context($this->revnum); - $this->revctx = $this->revctx['revision']; - } - - // ################################################################### - /** - * Produces a link href that allows for a completely different path - * than the one in the controller. This is used for navigating upstream. - * - * @access public - * - * @param string Base path (e.g. browse.php) - * @param string New relative path - * - * @return string Constructed path - */ - function href_struct($base, $path) - { - $url = Paths::fetch_arguments($base); - $path = Paths::sanitize($path); - - return $this->registry->path . '/' . $url[0] . '/' . $this->repos . ($path{0} != '/' ? '/' : '') . $path . ($url[1] ? '?' . $url[1] : ''); - } - - // ################################################################### - /** - * Compounds a path by adding another level. This is used for navigating - * downstream. - * - * @access public - * - * @param string Base path (e.g. browse.php) - * @param string Attach path (or none for current) - * @param bool Attach a given revision string, null for none - * - * @return string Constructed path - */ - function href_compound($base, $attach = null, $revstr = null) - { - $url = Paths::fetch_arguments($base . ($revstr === null ? ((strpos($base, '?') !== false) ? '&' . $this->revstr : $this->revstr) : $revstr)); - - if ($attach === null) - { - $path = $this->path; - } - else - { - $attach = Paths::sanitize($attach); - $path = $this->path . (($attach[0] != '/' AND $this->path[ strlen($this->path) - 1 ] != '/') ? '/' : '') . $attach; - } - - return $this->href_struct($base . ($url[1] ? '?' . $url[1] : ''), $path); - } - - // ################################################################### - /** - * Create path breadcrumb - * - * @access public - * - * @return string Breadcrumb HTML - */ - function construct_breadcrumb() - { - $html = '/ '; - - $temp = preg_split('#/#', $this->fullpath, -1, PREG_SPLIT_NO_EMPTY); - $count = sizeof($temp) - 1; - - $donerepos = false; - - foreach ($temp AS $val => $item) - { - if ($donerepos != false) - { - $itembit .= $item; - $this->registry->debug($item . " > " . $itembit); - $itembit .= (($count != $val OR $this->cachev->isdir($itembit)) ? '/' : ''); - } - - $donerepos = true; - $html .= '' . $item . ''. ($count != $val ? ' / ' : ''); - } - - return $html; - } -} - -/*=====================================================================*\ -|| ################################################################### -|| # $HeadURL$ -|| # $Id$ -|| ################################################################### -\*=====================================================================*/ -?> \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php new file mode 100644 index 0000000..cf35e0b --- /dev/null +++ b/includes/functions.php @@ -0,0 +1,54 @@ +in['path'], -1, PREG_SPLIT_NO_EMPTY); + if (empty($path)) + { + return '/'; + } + + $html = ''; + $build = ''; + foreach ($path AS $part) + { + $build .= '/' . $part; + $html .= '/ ' . $part . ' '; + } + + return $html; +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/includes/init.php b/includes/init.php index 140fe13..dbc0a53 100644 --- a/includes/init.php +++ b/includes/init.php @@ -43,6 +43,8 @@ require_once('ISSO/Register.php'); require_once('ISSO/Functions.php'); require_once('ISSO/Xml.php'); +BSRegister::SetDebug($debug); + BSRegister::Register('db', $db = BSRegister::LoadModule('DbMySql')); $db->connect($conf['db']['server'], $conf['db']['user'], $conf['db']['pass'], $conf['db']['name'], 0); diff --git a/includes/repository.php b/includes/repository.php index 90da906..ff86454 100644 --- a/includes/repository.php +++ b/includes/repository.php @@ -93,7 +93,7 @@ class Repository if (sizeof($this->repositories) < 1) { - $viewsvn->trigger->error($viewsvn->lang->string('There are no valid repositories')); + $viewsvn->trigger->error(_('There are no valid repositories')); } } @@ -112,19 +112,17 @@ class Repository /** * Returns a path to a repository * - * @access public - * * @param string Repository name * * @return string Full path to the repository */ - function fetch_path($repository = '') + public function fetchPath($repository = '') { global $viewsvn; - if (!in_array($repository, $this->fetch_list())) + if (!in_array($repository, $this->repositories)) { - $viewsvn->trigger->error($viewsvn->lang->string('Invalid repository name specified')); + $viewsvn->trigger->error(_('Invalid repository name specified')); } if ($this->container) @@ -141,18 +139,16 @@ class Repository /** * Verifies a path inside a repository * - * @access public - * * @param string Repository name * @param string Path * * @return bool Validity */ - function verify($repos, $path) + public function verify($repos, $path) { global $viewsvn; - if ($repospath = $this->fetch_path($repos)) + if ($repospath = $this->fetchPath($repos)) { return true; } diff --git a/templates/default/browse_node.tpl b/templates/default/browse_node.tpl index c2102a7..d67275c 100644 --- a/templates/default/browse_node.tpl +++ b/templates/default/browse_node.tpl @@ -1,11 +1,11 @@
- - $item + + $item/ - $item + $item - - {@"Blame"} - +
\ No newline at end of file -- 2.22.5