Fully convert ingo to Horde_Registry_Application
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 20 Jan 2010 05:53:17 +0000 (22:53 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 20 Jan 2010 15:35:08 +0000 (08:35 -0700)
16 files changed:
ingo/blacklist.php
ingo/filters.php
ingo/forward.php
ingo/lib/Api.php
ingo/lib/Application.php
ingo/lib/Block/overview.php
ingo/lib/base.load.php [deleted file]
ingo/lib/base.php [deleted file]
ingo/rule.php
ingo/script.php
ingo/scripts/ingo-postfix-policyd
ingo/scripts/upgrades/convert_datatree_shares_to_sql.php
ingo/scripts/upgrades/convert_prefs_to_sql.php
ingo/spam.php
ingo/vacation.php
ingo/whitelist.php

index fc85b02..291e2eb 100644 (file)
@@ -11,7 +11,8 @@
  * @author Michael Slusarz <slusarz@horde.org>
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('ingo');
 
 /* Redirect if blacklist is not available. */
 if (!in_array(Ingo_Storage::ACTION_BLACKLIST, $_SESSION['ingo']['script_categories'])) {
index 9158f88..aa63686 100644 (file)
@@ -10,7 +10,8 @@
  * @author Mike Cochrane <mike@graftonhall.co.nz>
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('ingo');
 
 /* Get the list of filter rules. */
 $filters = &$ingo_storage->retrieve(Ingo_Storage::ACTION_FILTERS);
index 9f62d6a..f742b35 100644 (file)
@@ -10,7 +10,8 @@
  * @author Todd Merritt <tmerritt@email.arizona.edu>
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('ingo');
 
 /* Redirect if forward is not available. */
 if (!in_array(Ingo_Storage::ACTION_FORWARD, $_SESSION['ingo']['script_categories'])) {
index c6b4dc2..3cf195d 100644 (file)
@@ -29,7 +29,6 @@ class Ingo_Api extends Horde_Registry_Api
      */
     public function blacklistFrom($addresses)
     {
-        require_once dirname(__FILE__) . '/../lib/base.php';
         if (!empty($GLOBALS['ingo_shares'])) {
             $_SESSION['ingo']['current_share'] = $signature;
         }
@@ -64,7 +63,6 @@ class Ingo_Api extends Horde_Registry_Api
      */
     public function whitelistFrom($addresses)
     {
-        require_once dirname(__FILE__) . '/../lib/base.php';
         if (!empty($GLOBALS['ingo_shares'])) {
             $_SESSION['ingo']['current_share'] = $signature;
         }
@@ -89,8 +87,6 @@ class Ingo_Api extends Horde_Registry_Api
      */
     public function canApplyFilters()
     {
-        require_once dirname(__FILE__) . '/../lib/base.php';
-
         $ingo_script = Ingo::loadIngoScript();
         return $ingo_script
             ? $ingo_script->performAvailable()
@@ -106,7 +102,6 @@ class Ingo_Api extends Horde_Registry_Api
      */
     public function applyFilters($params = array())
     {
-        require_once dirname(__FILE__) . '/../lib/base.php';
         if (!empty($GLOBALS['ingo_shares'])) {
             $_SESSION['ingo']['current_share'] = $signature;
         }
@@ -132,7 +127,6 @@ class Ingo_Api extends Horde_Registry_Api
      */
     public function setVacation($info)
     {
-        require_once dirname(__FILE__) . '/../lib/base.php';
         if (!empty($GLOBALS['ingo_shares'])) {
             $_SESSION['ingo']['current_share'] = $signature;
         }
@@ -204,7 +198,6 @@ class Ingo_Api extends Horde_Registry_Api
      */
     public function disableVacation()
     {
-        require_once dirname(__FILE__) . '/../lib/base.php';
         if (!empty($GLOBALS['ingo_shares'])) {
             $_SESSION['ingo']['current_share'] = $signature;
         }
index 0941687..4b707d0 100644 (file)
@@ -2,8 +2,39 @@
 /**
  * Ingo application API.
  *
+ * This file defines Horde's core API interface. Other core Horde libraries
+ * can interact with Horde through this API.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
  * See the enclosed file LICENSE for license information (ASL).  If you
  * did not receive this file, see http://www.horde.org/licenses/asl.php.
+ *
+ * @package Ingo
+ */
+
+/* Determine the base directories. */
+if (!defined('INGO_BASE')) {
+    define('INGO_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(INGO_BASE . '/config/horde.local.php')) {
+        include INGO_BASE . '/config/horde.local.php';
+    } else {
+        define('HORDE_BASE', INGO_BASE . '/..');
+    }
+}
+
+/* Load the Horde Framework core (needed to autoload
+ * Horde_Registry_Application::). */
+require_once HORDE_BASE . '/lib/core.php';
+
+/**
+ * Ingo application API.
+ *
  */
 class Ingo_Application extends Horde_Registry_Application
 {
@@ -15,6 +46,56 @@ class Ingo_Application extends Horde_Registry_Application
     public $version = 'H4 (2.0-git)';
 
     /**
+     * Initialization function.
+     *
+     * Global variables defined:
+     *   $all_rulesets - TODO
+     *   $ingo_shares - TODO
+     *   $ingo_storage - TODO
+     */
+    protected function _init()
+    {
+        // Load the Ingo_Storage driver.
+        $GLOBALS['ingo_storage'] = Ingo_Storage::factory();
+
+        // Create the ingo session (if needed).
+        if (!isset($_SESSION['ingo']) || !is_array($_SESSION['ingo'])) {
+            Ingo_Session::createSession();
+        }
+
+        // Create shares if necessary.
+        $driver = Ingo::getDriver();
+        if ($driver->supportShares()) {
+            $GLOBALS['ingo_shares'] = Horde_Share::singleton($registry->getApp());
+            $GLOBALS['all_rulesets'] = Ingo::listRulesets();
+
+            /* If personal share doesn't exist then create it. */
+            $signature = $_SESSION['ingo']['backend']['id'] . ':' . Horde_Auth::getAuth();
+            if (!$GLOBALS['ingo_shares']->exists($signature)) {
+                $identity = Horde_Prefs_Identity::singleton();
+                $name = $identity->getValue('fullname');
+                if (trim($name) == '') {
+                    $name = Horde_Auth::getOriginalAuth();
+                }
+                $share = $GLOBALS['ingo_shares']->newShare($signature);
+                $share->set('name', $name);
+                $GLOBALS['ingo_shares']->addShare($share);
+                $GLOBALS['all_rulesets'][$signature] = $share;
+            }
+
+            /* Select current share. */
+            $_SESSION['ingo']['current_share'] = Horde_Util::getFormData('ruleset', @$_SESSION['ingo']['current_share']);
+            if (empty($_SESSION['ingo']['current_share']) ||
+                empty($GLOBALS['all_rulesets'][$_SESSION['ingo']['current_share']]) ||
+                !$GLOBALS['all_rulesets'][$_SESSION['ingo']['current_share']]->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
+                $_SESSION['ingo']['current_share'] = $signature;
+            }
+        } else {
+            $GLOBALS['ingo_shares'] = null;
+        }
+    }
+
+    /**
      * Returns a list of available permissions.
      *
      * @return array  An array describing all available permissions.
@@ -86,8 +167,6 @@ class Ingo_Application extends Horde_Registry_Application
             return PEAR::raiseError(_("You are not allowed to remove user data."));
         }
 
-        require_once dirname(__FILE__) . '/../lib/base.php';
-
         /* Remove all filters/rules owned by the user. */
         $result = $GLOBALS['ingo_storage']->removeUserData($user);
         if (is_a($result, 'PEAR_Error')) {
index d92bd28..8cc9330 100644 (file)
@@ -33,8 +33,6 @@ class Horde_Block_ingo_overview extends Horde_Block {
      */
     function _content()
     {
-        require_once dirname(__FILE__) . '/../base.php';
-
         /* Get list of filters */
         $filters = &$GLOBALS['ingo_storage']->retrieve(Ingo_Storage::ACTION_FILTERS);
         $html = '<table width="100%" height="100%">';
diff --git a/ingo/lib/base.load.php b/ingo/lib/base.load.php
deleted file mode 100644 (file)
index 21185c6..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 Ingo
- */
-
-if (!defined('INGO_BASE')) {
-    define('INGO_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(INGO_BASE . '/config/horde.local.php')) {
-        include INGO_BASE . '/config/horde.local.php';
-    } else {
-        define('HORDE_BASE', INGO_BASE . '/..');
-    }
-}
diff --git a/ingo/lib/base.php b/ingo/lib/base.php
deleted file mode 100644 (file)
index 957014b..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-/**
- * Ingo base inclusion file.
- *
- * This file brings in all of the dependencies that every Ingo
- * script will need and sets up objects that all scripts use.
- *
- * The following global variables are used:
- * <pre>
- * $ingo_authentication - The type of authentication to use:
- *   'none'  - Do not authenticate
- *   [DEFAULT] - Authenticate; on failed auth redirect to login screen
- * </pre>
- *
- * Global variables defined:
- *   $ingo_shared  - TODO
- *   $ingo_storage - The Ingo_Storage:: object to use for storing rules.
- *   $no_compress  - Controls whether the page should be compressed
- *
- * See the enclosed file LICENSE for license information (ASL).  If you
- * did not receive this file, see http://www.horde.org/licenses/asl.php.
- */
-
-// 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('ingo', array('check_perms' => (Horde_Util::nonInputVar('ingo_authentication') != 'none'), 'logintasks' => true));
-} catch (Horde_Exception $e) {
-    Horde_Auth::authenticateFailure('ingo', $e);
-}
-$conf = &$GLOBALS['conf'];
-
-if (!defined('INGO_TEMPLATES')) {
-    define('INGO_TEMPLATES', $registry->get('templates'));
-}
-
-// Notification system.
-$notification = Horde_Notification::singleton();
-$notification->attach('status');
-
-// Start compression.
-if (!Horde_Util::nonInputVar('no_compress')) {
-    Horde::compressOutput();
-}
-
-// Load the Ingo_Storage driver. It appears in the global variable
-// $ingo_storage.
-$GLOBALS['ingo_storage'] = Ingo_Storage::factory();
-
-// Create the ingo session (if needed).
-if (!isset($_SESSION['ingo']) || !is_array($_SESSION['ingo'])) {
-    Ingo_Session::createSession();
-}
-
-// Create shares if necessary.
-$driver = Ingo::getDriver();
-if ($driver->supportShares()) {
-    $GLOBALS['ingo_shares'] = Horde_Share::singleton($registry->getApp());
-    $GLOBALS['all_rulesets'] = Ingo::listRulesets();
-
-    /* If personal share doesn't exist then create it. */
-    $signature = $_SESSION['ingo']['backend']['id'] . ':' . Horde_Auth::getAuth();
-    if (!$GLOBALS['ingo_shares']->exists($signature)) {
-        $identity = Horde_Prefs_Identity::singleton();
-        $name = $identity->getValue('fullname');
-        if (trim($name) == '') {
-            $name = Horde_Auth::getOriginalAuth();
-        }
-        $share = &$GLOBALS['ingo_shares']->newShare($signature);
-        $share->set('name', $name);
-        $GLOBALS['ingo_shares']->addShare($share);
-        $GLOBALS['all_rulesets'][$signature] = &$share;
-    }
-
-    /* Select current share. */
-    $_SESSION['ingo']['current_share'] = Horde_Util::getFormData('ruleset', @$_SESSION['ingo']['current_share']);
-    if (empty($_SESSION['ingo']['current_share']) ||
-        empty($GLOBALS['all_rulesets'][$_SESSION['ingo']['current_share']]) ||
-        !$GLOBALS['all_rulesets'][$_SESSION['ingo']['current_share']]->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) {
-        $_SESSION['ingo']['current_share'] = $signature;
-    }
-} else {
-    $GLOBALS['ingo_shares'] = null;
-}
index 9b7df83..2c5e472 100644 (file)
@@ -11,7 +11,8 @@
  * @author Michael Slusarz <slusarz@horde.org>
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('ingo');
 
 /* Check rule permissions. */
 if (!$GLOBALS['perms']->hasAppPermission('allow_rules')) {
index 32ce2f6..70199b4 100644 (file)
@@ -8,7 +8,8 @@
  * @author Mike Cochrane <mike@graftonhall.co.nz>
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('ingo');
 
 /* Redirect if script updating is not available. */
 if (!$_SESSION['ingo']['script_generate']) {
index 7b4f4ee..5953147 100755 (executable)
  * sender is blacklisted.
  */
 
-// Do CLI checks and environment setup first.
-require_once dirname(__FILE__) . '/../../lib/core.php';
-
-// Make sure no one runs this from the web.
-if (!Horde_Cli::runningFromCLI()) {
-    exit(1);
-}
-
-// Load the CLI environment - make sure there's no time limit, init some
-// variables, etc.
-Horde_Cli::init();
-
-// Include needed libraries.
-$ingo_authentication = 'none';
-require_once dirname(__FILE__) . '/../lib/base.php';
+require_once dirname(__FILE__) . '/../../lib/Application.php';
+Horde_Registry::appInit('ingo', array('authentication' => 'none', 'cli' => true));
 
 // Initialize authentication manager.
 $auth = Horde_Auth::singleton($conf['auth']['driver']);
index 1f082ff..398a7b1 100755 (executable)
@@ -7,15 +7,9 @@
  */
 
 /* Set up the CLI environment */
-require_once dirname(__FILE__) . '/../../../lib/core.php';
-if (!Horde_Cli::runningFromCli()) {
-    exit("Must be run from the command line\n");
-}
+require_once dirname(__FILE__) . '/../../../lib/Application.php';
+Horde_Registry::appInit('ingo', array('authentication' => 'none', 'cli' => true));
 $cli = Horde_Cli::singleton();
-$cli->init();
-
-/* Grab what we need to steal the DB config */
-require_once HORDE_BASE . '/config/conf.php';
 
 $config = $GLOBALS['conf']['sql'];
 unset($config['charset']);
index 419aeba..01f28a8 100755 (executable)
  * @author Jan Schneider <jan@horde.org>
  */
 
-/* Do CLI checks and environment setup first. */
-require_once dirname(__FILE__) . '/../../../lib/core.php';
-
-/* Make sure no one runs this from the web. */
-if (!Horde_Cli::runningFromCLI()) {
-    exit("Must be run from the command line\n");
-}
-
-/* Load the CLI environment - make sure there's no time limit, init some
- * variables, etc. */
-Horde_Cli::init();
+require_once dirname(__FILE__) . '/../../../lib/Application.php';
+Horde_Registry::appInit('ingo', array('authentication' => 'none', 'cli' => true));
 $cli = Horde_Cli::singleton();
 
-/* Initialize the needed libraries. */
-$ingo_authentication = 'none';
-require_once dirname(__FILE__) . '/../../lib/base.php';
-
 /* Initialize storage backends. */
 if ($conf['storage']['driver'] != 'sql') {
     $cli->fatal('You need to configure an SQL storage backend in Ingo\'s configuration', __FILE__, __LINE__);
index 75dc343..2cb9ffa 100644 (file)
@@ -38,8 +38,8 @@ class Horde_Form_Type_ingo_folders extends Horde_Form_Type {
 
 }
 
-
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('ingo');
 
 if (!in_array(Ingo_Storage::ACTION_SPAM, $_SESSION['ingo']['script_categories'])) {
     $notification->push(_("Simple spam filtering is not supported in the current filtering driver."), 'horde.error');
index aac061d..ed248ed 100644 (file)
@@ -10,7 +10,8 @@
  * @author Mike Cochrane <mike@graftonhall.co.nz>
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('ingo');
 
 /* Redirect if vacation is not available. */
 if (!in_array(Ingo_Storage::ACTION_VACATION, $_SESSION['ingo']['script_categories'])) {
index 35747d7..17d0940 100644 (file)
@@ -12,7 +12,8 @@
  * @author Michael Slusarz <slusarz@horde.org>
  */
 
-require_once dirname(__FILE__) . '/lib/base.php';
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('ingo');
 
 /* Redirect if whitelist not available. */
 if (!in_array(Ingo_Storage::ACTION_WHITELIST, $_SESSION['ingo']['script_categories'])) {