Fully convert chora to Horde_Registry_Application
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 20 Jan 2010 06:39:06 +0000 (23:39 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 20 Jan 2010 16:33:00 +0000 (09:33 -0700)
14 files changed:
chora/annotate.php
chora/browsedir.php
chora/browsefile.php
chora/co.php
chora/cvsgraph.php
chora/diff.php
chora/history.php
chora/lib/Application.php
chora/lib/Block/tree_menu.php
chora/lib/Chora.php
chora/lib/base.load.php [deleted file]
chora/lib/base.php [deleted file]
chora/patchsets.php
chora/stats.php

index 9a84bb8..d2a0803 100644 (file)
@@ -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 {
index fc32adb..19c0955 100644 (file)
@@ -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';
index f5fc78c..74f324b 100644 (file)
@@ -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';
index 373b619..470b834 100644 (file)
@@ -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) {
index 5df8bda..5a96b07 100644 (file)
@@ -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')) {
index 895cd7c..0ede418 100644 (file)
@@ -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 {
index ad8f3f0..66382ef 100644 (file)
@@ -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');
index 7a9309e..9adb413 100644 (file)
@@ -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;
     }
 
     /**
index fc4e3d0..5e8c64e 100644 (file)
@@ -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']);
index 7caf0c1..446bd61 100644 (file)
@@ -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 (file)
index 8f1d5ed..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/**
- * Script to determine the correct *_BASE values.
- *
- * Copyright 2009-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 . '/..');
-    }
-}
diff --git a/chora/lib/base.php b/chora/lib/base.php
deleted file mode 100644 (file)
index a5d1ac4..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-/**
- * Chora base inclusion file.
- *
- * This file brings in all of the dependencies that every Chora script
- * will need, and sets up objects that all scripts use.
- *
- * The following global variables are used:
- *   $no_compress  -  Controls whether the page should be compressed
- */
-
-// Determine BASE directories.
-require_once dirname(__FILE__) . '/base.load.php';
-
-// Load the Horde Framework core.
-require_once HORDE_BASE . '/lib/core.php';
-
-// Registry
-$registry = Horde_Registry::singleton();
-try {
-    $registry->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();
-}
index 0bb427e..91b4863 100644 (file)
@@ -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')) {
index d53480e..fc29805 100644 (file)
@@ -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);