From 3c96ff13f7304145bec05103b308f18b4ece20b0 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 19 Jan 2010 22:53:17 -0700 Subject: [PATCH] Fully convert ingo to Horde_Registry_Application --- ingo/blacklist.php | 3 +- ingo/filters.php | 3 +- ingo/forward.php | 3 +- ingo/lib/Api.php | 7 -- ingo/lib/Application.php | 83 +++++++++++++++++++- ingo/lib/Block/overview.php | 2 - ingo/lib/base.load.php | 25 ------ ingo/lib/base.php | 90 ---------------------- ingo/rule.php | 3 +- ingo/script.php | 3 +- ingo/scripts/ingo-postfix-policyd | 17 +--- .../upgrades/convert_datatree_shares_to_sql.php | 10 +-- ingo/scripts/upgrades/convert_prefs_to_sql.php | 17 +--- ingo/spam.php | 4 +- ingo/vacation.php | 3 +- ingo/whitelist.php | 3 +- 16 files changed, 103 insertions(+), 173 deletions(-) delete mode 100644 ingo/lib/base.load.php delete mode 100644 ingo/lib/base.php diff --git a/ingo/blacklist.php b/ingo/blacklist.php index fc85b02ee..291e2ebad 100644 --- a/ingo/blacklist.php +++ b/ingo/blacklist.php @@ -11,7 +11,8 @@ * @author Michael Slusarz */ -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'])) { diff --git a/ingo/filters.php b/ingo/filters.php index 9158f88b6..aa63686b2 100644 --- a/ingo/filters.php +++ b/ingo/filters.php @@ -10,7 +10,8 @@ * @author Mike Cochrane */ -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); diff --git a/ingo/forward.php b/ingo/forward.php index 9f62d6a45..f742b35bc 100644 --- a/ingo/forward.php +++ b/ingo/forward.php @@ -10,7 +10,8 @@ * @author Todd Merritt */ -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'])) { diff --git a/ingo/lib/Api.php b/ingo/lib/Api.php index c6b4dc282..3cf195d10 100644 --- a/ingo/lib/Api.php +++ b/ingo/lib/Api.php @@ -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; } diff --git a/ingo/lib/Application.php b/ingo/lib/Application.php index 094168781..4b707d01e 100644 --- a/ingo/lib/Application.php +++ b/ingo/lib/Application.php @@ -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')) { diff --git a/ingo/lib/Block/overview.php b/ingo/lib/Block/overview.php index d92bd287f..8cc933065 100644 --- a/ingo/lib/Block/overview.php +++ b/ingo/lib/Block/overview.php @@ -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 = ''; diff --git a/ingo/lib/base.load.php b/ingo/lib/base.load.php deleted file mode 100644 index 21185c66b..000000000 --- a/ingo/lib/base.load.php +++ /dev/null @@ -1,25 +0,0 @@ - - * $ingo_authentication - The type of authentication to use: - * 'none' - Do not authenticate - * [DEFAULT] - Authenticate; on failed auth redirect to login screen - * - * - * 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; -} diff --git a/ingo/rule.php b/ingo/rule.php index 9b7df83bd..2c5e472d4 100644 --- a/ingo/rule.php +++ b/ingo/rule.php @@ -11,7 +11,8 @@ * @author Michael Slusarz */ -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')) { diff --git a/ingo/script.php b/ingo/script.php index 32ce2f63b..70199b4ba 100644 --- a/ingo/script.php +++ b/ingo/script.php @@ -8,7 +8,8 @@ * @author Mike Cochrane */ -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']) { diff --git a/ingo/scripts/ingo-postfix-policyd b/ingo/scripts/ingo-postfix-policyd index 7b4f4ee80..595314766 100755 --- a/ingo/scripts/ingo-postfix-policyd +++ b/ingo/scripts/ingo-postfix-policyd @@ -60,21 +60,8 @@ * 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']); diff --git a/ingo/scripts/upgrades/convert_datatree_shares_to_sql.php b/ingo/scripts/upgrades/convert_datatree_shares_to_sql.php index 1f082ffe9..398a7b1b3 100755 --- a/ingo/scripts/upgrades/convert_datatree_shares_to_sql.php +++ b/ingo/scripts/upgrades/convert_datatree_shares_to_sql.php @@ -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']); diff --git a/ingo/scripts/upgrades/convert_prefs_to_sql.php b/ingo/scripts/upgrades/convert_prefs_to_sql.php index 419aeba02..01f28a839 100755 --- a/ingo/scripts/upgrades/convert_prefs_to_sql.php +++ b/ingo/scripts/upgrades/convert_prefs_to_sql.php @@ -18,23 +18,10 @@ * @author Jan Schneider */ -/* 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__); diff --git a/ingo/spam.php b/ingo/spam.php index 75dc3438a..2cb9ffa95 100644 --- a/ingo/spam.php +++ b/ingo/spam.php @@ -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'); diff --git a/ingo/vacation.php b/ingo/vacation.php index aac061d9d..ed248edc8 100644 --- a/ingo/vacation.php +++ b/ingo/vacation.php @@ -10,7 +10,8 @@ * @author Mike Cochrane */ -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'])) { diff --git a/ingo/whitelist.php b/ingo/whitelist.php index 35747d72d..17d094035 100644 --- a/ingo/whitelist.php +++ b/ingo/whitelist.php @@ -12,7 +12,8 @@ * @author Michael Slusarz */ -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'])) { -- 2.11.0