From: Michael M Slusarz Date: Wed, 20 Jan 2010 06:39:06 +0000 (-0700) Subject: Fully convert chora to Horde_Registry_Application X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=81aee7e91f7214c9e181bdc30649e9bb9eeb6483;p=horde.git Fully convert chora to Horde_Registry_Application --- diff --git a/chora/annotate.php b/chora/annotate.php index 9a84bb865..d2a080389 100644 --- a/chora/annotate.php +++ b/chora/annotate.php @@ -9,7 +9,8 @@ * @package Chora */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('chora'); /* Spawn the file object. */ try { diff --git a/chora/browsedir.php b/chora/browsedir.php index fc32adb1f..19c095545 100644 --- a/chora/browsedir.php +++ b/chora/browsedir.php @@ -10,7 +10,8 @@ * @package Chora */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('chora'); if (!$atdir) { require CHORA_BASE . '/browsefile.php'; diff --git a/chora/browsefile.php b/chora/browsefile.php index f5fc78cd9..74f324b10 100644 --- a/chora/browsefile.php +++ b/chora/browsefile.php @@ -12,7 +12,8 @@ * @package Chora */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('chora'); if ($atdir) { require CHORA_BASE . '/browsedir.php'; diff --git a/chora/co.php b/chora/co.php index 373b61964..470b8345f 100644 --- a/chora/co.php +++ b/chora/co.php @@ -9,7 +9,8 @@ * @package Chora */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('chora'); /* If we know we're at a directory, just go to browse.php. */ if ($atdir) { diff --git a/chora/cvsgraph.php b/chora/cvsgraph.php index 5df8bda5f..5a96b0700 100644 --- a/chora/cvsgraph.php +++ b/chora/cvsgraph.php @@ -12,7 +12,8 @@ * @package Chora */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('chora'); // Exit if cvsgraph isn't active or it's not supported. if (empty($conf['paths']['cvsgraph']) || !$VC->hasFeature('branches')) { diff --git a/chora/diff.php b/chora/diff.php index 895cd7c50..0ede4187f 100644 --- a/chora/diff.php +++ b/chora/diff.php @@ -9,7 +9,8 @@ * @package Chora */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('chora'); /* Spawn the repository and file objects */ try { diff --git a/chora/history.php b/chora/history.php index ad8f3f0af..66382ef23 100644 --- a/chora/history.php +++ b/chora/history.php @@ -9,7 +9,8 @@ * @package Chora */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('chora'); // TODO - This currently doesn't work. Chora::fatal('History display is currently broken', '500 Internal Server Error'); diff --git a/chora/lib/Application.php b/chora/lib/Application.php index 7a9309ee1..9adb41366 100644 --- a/chora/lib/Application.php +++ b/chora/lib/Application.php @@ -2,11 +2,35 @@ /** * Chora application API. * - * This file defines Chora's external API interface. Other applications can - * interact with Chora through this API. + * This file defines Horde's core API interface. Other core Horde libraries + * can interact with Chora through this API. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @package Chora */ + +if (!defined('CHORA_BASE')) { + define('CHORA_BASE', dirname(__FILE__) . '/..'); +} + +if (!defined('HORDE_BASE')) { + /* If horde does not live directly under the app directory, the HORDE_BASE + * constant should be defined in config/horde.local.php. */ + if (file_exists(CHORA_BASE . '/config/horde.local.php')) { + include CHORA_BASE . '/config/horde.local.php'; + } else { + define('HORDE_BASE', CHORA_BASE . '/..'); + } +} + +/* Load the Horde Framework core (needed to autoload + * Horde_Registry_Application::). */ +require_once HORDE_BASE . '/lib/core.php'; + class Chora_Application extends Horde_Registry_Application { /** @@ -17,30 +41,162 @@ class Chora_Application extends Horde_Registry_Application public $version = 'H4 (3.0-git)'; /** + * TODO + */ + static protected $perms = array(); + + /** + * Initialization function. + * + * Global variables defined: + * $sourceroots + */ + protected function _init() + { + global $conf; + global $acts, $defaultActs, $where, $atdir, $fullname, $sourceroot; + + try { + $GLOBALS['sourceroots'] = Horde::loadConfiguration('sourceroots.php', 'sourceroots'); + } catch (Horde_Exception $e) { + $GLOBALS['notification']->push($e); + $GLOBALS['sourceroots'] = array(); + } + $sourceroots = Chora::sourceroots(); + + /** + * Variables we wish to propagate across web pages + * sbt = Sort By Type (name, age, author, etc) + * ha = Hide Attic Files + * ord = Sort order + * + * Obviously, defaults go into $defaultActs :) + * TODO: defaults of 1 will not get propagated correctly - avsm + * XXX: Rewrite this propagation code, since it sucks - avsm + */ + $defaultActs = array( + 'sbt' => constant($conf['options']['defaultsort']), + 'sa' => 0, + 'ord' => Horde_Vcs::SORT_ASCENDING, + 'ws' => 1, + 'onb' => 0, + 'rev' => 0, + ); + + /* Use the last sourceroot used as the default value if the user has + * that preference. */ + $last_sourceroot = $GLOBALS['prefs']->getValue('last_sourceroot') + ? $GLOBALS['prefs']->getValue('last_sourceroot') + : null; + + if (!empty($last_sourceroot) && + !empty($sourceroots[$last_sourceroot]) && + is_array($sourceroots[$last_sourceroot])) { + $defaultActs['rt'] = $last_sourceroot; + } else { + foreach ($sourceroots as $key => $val) { + if (isset($val['default']) || !isset($defaultActs['rt'])) { + $defaultActs['rt'] = $key; + } + } + } + + $acts = array(); + if (!isset($defaultActs['rt'])) { + Chora::fatal(_("No repositories found.")); + return; + } + + /* See if any have been passed as GET variables, and if so, assign + * them into the acts array. */ + foreach ($defaultActs as $key => $default) { + $acts[$key] = Horde_Util::getFormData($key, $default); + } + + if (!isset($sourceroots[$acts['rt']])) { + Chora::fatal(_("Malformed URL"), '400 Bad Request'); + } + + $sourcerootopts = $sourceroots[$acts['rt']]; + $sourceroot = $acts['rt']; + + // Cache. + if (empty($conf['caching'])) { + $cache = null; + } else { + $cache = Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); + } + + $conf['paths']['temp'] = Horde::getTempDir(); + + try { + $GLOBALS['VC'] = Horde_Vcs::factory(Horde_String::ucfirst($sourcerootopts['type']), + array('cache' => $cache, + 'sourceroot' => $sourcerootopts['location'], + 'paths' => $conf['paths'], + 'username' => isset($sourcerootopts['username']) ? $sourcerootopts['username'] : '', + 'password' => isset($sourcerootopts['password']) ? $sourcerootopts['password'] : '')); + } catch (Horde_Vcs_Exception $e) { + Chora::fatal($e); + } + + $conf['paths']['sourceroot'] = $sourcerootopts['location']; + $conf['paths']['cvsusers'] = $sourcerootopts['location'] . '/' . (isset($sourcerootopts['cvsusers']) ? $sourcerootopts['cvsusers'] : ''); + $conf['paths']['introText'] = CHORA_BASE . '/config/' . (isset($sourcerootopts['intro']) ? $sourcerootopts['intro'] : ''); + $conf['options']['introTitle'] = isset($sourcerootopts['title']) ? $sourcerootopts['title'] : ''; + $conf['options']['sourceRootName'] = $sourcerootopts['name']; + + $where = Horde_Util::getFormData('f', '/'); + + /* Location relative to the sourceroot. */ + $where = preg_replace(array('|^/|', '|\.\.|'), '', $where); + + /* Store last repository viewed */ + $GLOBALS['prefs']->setValue('last_sourceroot', $acts['rt']); + + $fullname = $sourcerootopts['location'] . (substr($sourcerootopts['location'], -1) == '/' ? '' : '/') . $where; + + if ($sourcerootopts['type'] == 'cvs') { + $fullname = preg_replace('|/$|', '', $fullname); + $atdir = @is_dir($fullname); + } else { + $atdir = !$where || (substr($where, -1) == '/'); + } + $where = preg_replace('|/$|', '', $where); + + if (($sourcerootopts['type'] == 'cvs') && + !@is_dir($sourcerootopts['location'])) { + Chora::fatal(_("Sourceroot not found. This could be a misconfiguration by the server administrator, or the server could be having temporary problems. Please try again later."), '500 Internal Server Error'); + } + + if (Chora::isRestricted($where)) { + Chora::fatal(sprintf(_("%s: Forbidden by server configuration"), $where), '403 Forbidden'); + } + } + + /** * Returns a list of available permissions. * * @return array An array describing all available permissions. */ public function perms() { - static $perms = array(); - - if (!empty($perms)) { - return $perms; + if (!empty(self::$_perms)) { + return self::$_perms; } require_once dirname(__FILE__) . '/../config/sourceroots.php'; - $perms['tree']['chora']['sourceroots'] = false; - $perms['title']['chora:sourceroots'] = _("Repositories"); + self::$_perms['tree']['chora']['sourceroots'] = false; + self::$_perms['title']['chora:sourceroots'] = _("Repositories"); // Run through every source repository foreach ($sourceroots as $sourceroot => $srconfig) { - $perms['tree']['chora']['sourceroots'][$sourceroot] = false; - $perms['title']['chora:sourceroots:' . $sourceroot] = $srconfig['name']; + self::$_perms['tree']['chora']['sourceroots'][$sourceroot] = false; + self::$_perms['title']['chora:sourceroots:' . $sourceroot] = $srconfig['name']; } - return $perms; + return self::$_perms; } /** diff --git a/chora/lib/Block/tree_menu.php b/chora/lib/Block/tree_menu.php index fc4e3d047..5e8c64ebc 100644 --- a/chora/lib/Block/tree_menu.php +++ b/chora/lib/Block/tree_menu.php @@ -10,7 +10,6 @@ class Horde_Block_chora_tree_menu extends Horde_Block function _buildTree(&$tree, $indent = 0, $parent = null) { define('CHORA_ERROR_HANDLER', true); - require_once dirname(__FILE__) . '/../base.php'; $arr = array(); asort($GLOBALS['sourceroots']); diff --git a/chora/lib/Chora.php b/chora/lib/Chora.php index 7caf0c15f..446bd616c 100644 --- a/chora/lib/Chora.php +++ b/chora/lib/Chora.php @@ -35,131 +35,6 @@ class Chora static public $fdcache; /** - * Initialize global variables and objects. - */ - static public function initialize() - { - global $acts, $defaultActs, $where, $atdir, $fullname, $sourceroot; - - try { - $GLOBALS['sourceroots'] = Horde::loadConfiguration('sourceroots.php', 'sourceroots'); - } catch (Horde_Exception $e) { - $GLOBALS['notification']->push($e); - $GLOBALS['sourceroots'] = array(); - } - $sourceroots = self::sourceroots(); - - /** - * Variables we wish to propagate across web pages - * sbt = Sort By Type (name, age, author, etc) - * ha = Hide Attic Files - * ord = Sort order - * - * Obviously, defaults go into $defaultActs :) - * TODO: defaults of 1 will not get propagated correctly - avsm - * XXX: Rewrite this propagation code, since it sucks - avsm - */ - $defaultActs = array( - 'sbt' => constant($GLOBALS['conf']['options']['defaultsort']), - 'sa' => 0, - 'ord' => Horde_Vcs::SORT_ASCENDING, - 'ws' => 1, - 'onb' => 0, - 'rev' => 0, - ); - - /* Use the last sourceroot used as the default value if the user has - * that preference. */ - $last_sourceroot = $GLOBALS['prefs']->getValue('last_sourceroot') - ? $GLOBALS['prefs']->getValue('last_sourceroot') - : null; - - if (!empty($last_sourceroot) && - !empty($sourceroots[$last_sourceroot]) && - is_array($sourceroots[$last_sourceroot])) { - $defaultActs['rt'] = $last_sourceroot; - } else { - foreach ($sourceroots as $key => $val) { - if (isset($val['default']) || !isset($defaultActs['rt'])) { - $defaultActs['rt'] = $key; - } - } - } - - $acts = array(); - if (!isset($defaultActs['rt'])) { - self::fatal(_("No repositories found.")); - return; - } - - /* See if any have been passed as GET variables, and if so, assign - * them into the acts array. */ - foreach ($defaultActs as $key => $default) { - $acts[$key] = Horde_Util::getFormData($key, $default); - } - - if (!isset($sourceroots[$acts['rt']])) { - self::fatal(_("Malformed URL"), '400 Bad Request'); - } - - $sourcerootopts = $sourceroots[$acts['rt']]; - $sourceroot = $acts['rt']; - - // Cache. - if (empty($GLOBALS['conf']['caching'])) { - $cache = null; - } else { - $cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); - } - - $GLOBALS['conf']['paths']['temp'] = Horde::getTempDir(); - - try { - $GLOBALS['VC'] = Horde_Vcs::factory(Horde_String::ucfirst($sourcerootopts['type']), - array('cache' => $cache, - 'sourceroot' => $sourcerootopts['location'], - 'paths' => $GLOBALS['conf']['paths'], - 'username' => isset($sourcerootopts['username']) ? $sourcerootopts['username'] : '', - 'password' => isset($sourcerootopts['password']) ? $sourcerootopts['password'] : '')); - } catch (Horde_Vcs_Exception $e) { - self::fatal($e); - } - - $GLOBALS['conf']['paths']['sourceroot'] = $sourcerootopts['location']; - $GLOBALS['conf']['paths']['cvsusers'] = $sourcerootopts['location'] . '/' . (isset($sourcerootopts['cvsusers']) ? $sourcerootopts['cvsusers'] : ''); - $GLOBALS['conf']['paths']['introText'] = CHORA_BASE . '/config/' . (isset($sourcerootopts['intro']) ? $sourcerootopts['intro'] : ''); - $GLOBALS['conf']['options']['introTitle'] = isset($sourcerootopts['title']) ? $sourcerootopts['title'] : ''; - $GLOBALS['conf']['options']['sourceRootName'] = $sourcerootopts['name']; - - $where = Horde_Util::getFormData('f', '/'); - - /* Location relative to the sourceroot. */ - $where = preg_replace(array('|^/|', '|\.\.|'), '', $where); - - /* Store last repository viewed */ - $GLOBALS['prefs']->setValue('last_sourceroot', $acts['rt']); - - $fullname = $sourcerootopts['location'] . (substr($sourcerootopts['location'], -1) == '/' ? '' : '/') . $where; - - if ($sourcerootopts['type'] == 'cvs') { - $fullname = preg_replace('|/$|', '', $fullname); - $atdir = @is_dir($fullname); - } else { - $atdir = !$where || (substr($where, -1) == '/'); - } - $where = preg_replace('|/$|', '', $where); - - if (($sourcerootopts['type'] == 'cvs') && - !@is_dir($sourcerootopts['location'])) { - self::fatal(_("Sourceroot not found. This could be a misconfiguration by the server administrator, or the server could be having temporary problems. Please try again later."), '500 Internal Server Error'); - } - - if (self::isRestricted($where)) { - self::fatal(sprintf(_("%s: Forbidden by server configuration"), $where), '403 Forbidden'); - } - } - - /** * Create the breadcrumb directory listing. * * @param string $where The current filepath. diff --git a/chora/lib/base.load.php b/chora/lib/base.load.php deleted file mode 100644 index 8f1d5ed86..000000000 --- a/chora/lib/base.load.php +++ /dev/null @@ -1,25 +0,0 @@ -pushApp('chora', array('logintasks' => true)); -} catch (Horde_Exception $e) { - Horde_Auth::authenticateFailure('chora', $e); -} -$conf = &$GLOBALS['conf']; -define('CHORA_TEMPLATES', $registry->get('templates')); - -// Notification system. -$notification = Horde_Notification::singleton(); -$notification->attach('status'); - -// Initialize objects, path, etc. -Chora::initialize(); - -// Start compression. -if (!Horde_Util::nonInputVar('no_compress')) { - Horde::compressOutput(); -} diff --git a/chora/patchsets.php b/chora/patchsets.php index 0bb427e5e..91b4863af 100644 --- a/chora/patchsets.php +++ b/chora/patchsets.php @@ -13,7 +13,8 @@ * @package Chora */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('chora'); // Exit if patchset feature is not available. if (!$GLOBALS['VC']->hasFeature('patchsets')) { diff --git a/chora/stats.php b/chora/stats.php index d53480e53..fc298056d 100644 --- a/chora/stats.php +++ b/chora/stats.php @@ -11,7 +11,8 @@ * @package Chora */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('chora'); try { $fl = $VC->getFileObject($where);