From b23cc31ca5d964fd8f9be807871eb0595aee63d9 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 13 Jan 2010 16:31:33 -0700 Subject: [PATCH] Further flesh out base Horde initialization. There is two ways Horde applications can be initialized: through a Horde_Registry API call and by directly loading the application (i.e. loading a script in an application). Both methods (may) require base initialization of the application (things like setting up paths to the template files, creating app-specific objects) but the latter also requires that the app initially be pushed on the stack. Since this latter behavior needs to be done in all applications, and is essentially the same in all apps, move it to the globally accessible function Horde_Registry::appInit(). Other benefits: initiation of compression can now be done in a single place Test out this new framework by converting Turba. Add new syntax to Skeleton. --- framework/Core/lib/Horde/Registry.php | 105 ++++++++++++-- framework/Core/lib/Horde/Registry/Application.php | 36 +++++ horde/admin/alarms.php | 2 +- horde/admin/cmdshell.php | 2 +- horde/admin/datatree.php | 2 +- horde/admin/groups.php | 2 +- horde/admin/perms/addchild.php | 2 +- horde/admin/perms/delete.php | 2 +- horde/admin/perms/edit.php | 2 +- horde/admin/perms/index.php | 2 +- horde/admin/phpshell.php | 2 +- horde/admin/sessions.php | 2 +- horde/admin/setup/config.php | 2 +- horde/admin/setup/diff.php | 2 +- horde/admin/setup/index.php | 2 +- horde/admin/setup/scripts.php | 2 +- horde/admin/signup_confirm.php | 2 +- horde/admin/sqlshell.php | 2 +- horde/admin/user.php | 2 +- horde/bin/alarms | 2 +- horde/bin/db_migrate | 2 +- horde/index.php | 2 +- horde/lib/Application.php | 64 +-------- horde/login.php | 2 +- horde/rampage.php | 2 +- horde/rpc.php | 2 +- horde/scripts/cookie_login.php | 2 +- horde/scripts/get_login.php | 2 +- horde/scripts/http_login_refer.php | 2 +- horde/scripts/import_squirrelmail_file_prefs.php | 2 +- horde/scripts/import_squirrelmail_sql_prefs.php | 2 +- .../upgrades/2008-04-09_horde_syncml_map.php | 2 +- .../upgrades/convert_datatree_groups_to_sql.php | 2 +- .../upgrades/convert_datatree_perms_to_sql.php | 2 +- horde/scripts/upgrades/migrate_user_categories.php | 2 +- .../upgrades/move_history_out_of_datatree.php | 2 +- horde/services/cache.php | 2 +- horde/services/cacheview.php | 2 +- horde/services/changepassword.php | 2 +- horde/services/confirm.php | 2 +- horde/services/facebook.php | 2 +- horde/services/go.php | 2 +- horde/services/help/index.php | 2 +- horde/services/images/view.php | 2 +- horde/services/imple.php | 2 +- horde/services/javascript.php | 2 +- horde/services/keyboard.php | 2 +- horde/services/language.php | 2 +- horde/services/logintasks.php | 2 +- horde/services/obrowser/index.php | 2 +- horde/services/portal/cloud_search.php | 2 +- horde/services/portal/edit.php | 2 +- horde/services/portal/index.php | 2 +- horde/services/portal/mobile.php | 2 +- horde/services/portal/rpcsum.php | 2 +- horde/services/portal/sidebar.php | 2 +- horde/services/portal/syncml.php | 2 +- horde/services/problem.php | 2 +- horde/services/resetpassword.php | 2 +- horde/services/shares/edit.php | 2 +- horde/services/snooze.php | 2 +- horde/services/twitter.php | 2 +- horde/services/twitterapi.php | 2 +- horde/signup.php | 2 +- horde/test.php | 5 +- imp/acl.php | 2 +- imp/ajax.php | 2 +- imp/attachment.php | 2 +- imp/compose-dimp.php | 2 +- imp/compose-mimp.php | 2 +- imp/compose.php | 2 +- imp/contacts.php | 2 +- imp/filterprefs.php | 2 +- imp/folders-mimp.php | 2 +- imp/folders.php | 3 +- imp/index-dimp.php | 2 +- imp/index.php | 2 +- imp/lib/Application.php | 157 ++++----------------- imp/lib/Auth.php | 3 +- imp/lib/Block/Foldersummary.php | 6 - imp/lib/Block/Newmail.php | 6 - imp/lib/Block/summary.php | 6 - imp/lib/Block/tree_folders.php | 6 - imp/mailbox-mimp.php | 2 +- imp/mailbox.php | 2 +- imp/message-dimp.php | 2 +- imp/message-mimp.php | 2 +- imp/message.php | 2 +- imp/pgp.php | 2 +- imp/rss.php | 2 +- imp/saveimage.php | 2 +- imp/search-basic.php | 2 +- imp/search.php | 2 +- imp/smime.php | 2 +- imp/stationery.php | 2 +- imp/thread.php | 2 +- imp/view.php | 4 +- skeleton/config/horde.local.php.dist | 4 + skeleton/lib/Application.php | 56 ++++++++ skeleton/lib/base.load.php | 25 ---- skeleton/lib/base.php | 31 ---- skeleton/list.php | 3 +- turba/add.php | 4 +- turba/addressbooks/create.php | 4 +- turba/addressbooks/delete.php | 4 +- turba/addressbooks/edit.php | 4 +- turba/addressbooks/index.php | 3 +- turba/browse.php | 3 +- turba/contact.php | 3 +- turba/data.php | 3 +- turba/delete.php | 3 +- turba/deletefile.php | 3 +- turba/edit.php | 4 +- turba/index.php | 4 +- turba/lib/Api.php | 32 +---- turba/lib/Application.php | 137 +++++++++++++++++- turba/lib/Block/minisearch.php | 2 - turba/lib/Block/tree_menu.php | 2 - turba/lib/base.load.php | 25 ---- turba/lib/base.php | 103 -------------- turba/lib/tests/ApiTest.php | 1 - turba/lib/tests/KolabTestBase.php | 9 +- turba/minisearch.php | 3 +- turba/scripts/import_squirrelmail_file_abook.php | 13 +- turba/scripts/import_squirrelmail_sql_abook.php | 15 +- turba/scripts/upgrades/2.1_to_2.2_sql_schema.php | 3 +- .../scripts/upgrades/2005-09-23_flat_comments.php | 8 +- .../upgrades/2007-06-17_delete_old_vbooks.php | 6 +- .../scripts/upgrades/2007-06-17_flatten_shares.php | 6 +- .../upgrades/convert_datatree_shares_to_sql.php | 3 +- turba/scripts/upgrades/public_to_horde_share.php | 14 +- turba/search.php | 3 +- turba/vcard.php | 3 +- turba/view.php | 3 +- 134 files changed, 513 insertions(+), 610 deletions(-) create mode 100644 skeleton/config/horde.local.php.dist delete mode 100644 skeleton/lib/base.load.php delete mode 100644 skeleton/lib/base.php delete mode 100644 turba/lib/base.load.php delete mode 100644 turba/lib/base.php diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 9c114cf82..f399047ab 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -84,6 +84,95 @@ class Horde_Registry public $applications = array(); /** + * Application initialization (called from within an application). + * Solves chicken-and-egg problem - need a way to init Horde environment + * from application without an active Horde_Registry object. + * + * Page compression will be started (if configured) via this function. + * + * Global variables defined: + * $registry - Registry object + * + * @param string $app The application to initialize. + * @param array $args Optional arguments: + *
+     * 'admin' - (boolean) Require authenticated user to be an admin?
+     * 'authentication' - (string) The type of authentication to use:
+     *   'none'  - Do not authenticate
+     *   'throw' - Authenticate; on no auth, throw a Horde_Exception
+     *   [DEFAULT] - Authenticate; on no auth redirect to login screen
+     * 'nocompress' - (boolean) Controls whether the page should be
+     *                compressed.
+     * 'nologintasks' - (boolean) If set, don't perform logintasks (never
+     *                  performed if authentication is 'none').
+     * 'session_control' - (string) Sets special session control limitations:
+     *   'netscape' - TODO; start read/write session
+     *   'none' - Do not start a session
+     *   'readonly' - Start session readonly
+     *   [DEFAULT] - Start read/write session
+     * 
+ * + * @return Horde_Registry_Application The application object. + * @throws Horde_Exception + */ + static public function appInit($app, $args = array()) + { + $args = array_merge(array( + 'admin' => false, + 'authentication' => null, + 'nocompress' => false, + 'nologintasks' => false, + 'session_control' => null + ), $args); + + // Registry. + $s_ctrl = 0; + switch ($args['session_control']) { + case 'netscape': + if ($GLOBALS['browser']->isBrowser('mozilla')) { + session_cache_limiter('private, must-revalidate'); + } + break; + + case 'none': + $s_ctrl = self::SESSION_NONE; + break; + + case 'readonly': + $s_ctrl = self::SESSION_READONLY; + break; + } + + $GLOBALS['registry'] = self::singleton($s_ctrl); + $appob = $GLOBALS['registry']->getApiInstance($app, 'application'); + $appob->initParams = $args; + + try { + $GLOBALS['registry']->pushApp($app, array('check_perms' => ($args['authentication'] != 'none'), 'logintasks' => !$args['nologintasks'])); + + if ($args['admin'] && !Horde_Auth::isAdmin()) { + throw new Horde_Exception('Not an admin'); + } + } catch (Horde_Exception $e) { + $appob->appInitFailure($e); + + if ($args['authentication'] == 'throw') { + throw $e; + } + + Horde_Auth::authenticateFailure($app, $e); + } + + if (!$args['nocompress']) { + Horde::compressOutput(); + } + + $appob->init(); + + return $appob; + } + + /** * Returns a reference to the global Horde_Registry object, only creating * it if it doesn't already exist. * @@ -357,7 +446,7 @@ class Horde_Registry foreach (array_keys($this->applications) as $app) { if (in_array($this->applications[$app]['status'], $status)) { try { - $api = $this->_getApiInstance($app, 'api'); + $api = $this->getApiInstance($app, 'api'); $this->_cache['api'][$app] = array( 'api' => array_diff(get_class_methods($api), array('__construct'), $api->disabled), 'links' => $api->links, @@ -381,7 +470,7 @@ class Horde_Registry * @return Horde_Registry_Api|Horde_Registry_Application The API object. * @throws Horde_Exception */ - protected function _getApiInstance($app, $type) + public function getApiInstance($app, $type) { if (isset($this->_cache['ob'][$app][$type])) { return $this->_cache['ob'][$app][$type]; @@ -403,7 +492,7 @@ class Horde_Registry throw new Horde_Exception("$app does not have an API"); } - $this->_cache['ob'][$app][$type] = new $classname; + $this->_cache['ob'][$app][$type] = new $classname(); return $this->_cache['ob'][$app][$type]; } @@ -551,7 +640,7 @@ class Horde_Registry public function hasAppMethod($app, $method) { try { - $appob = $this->_getApiInstance($app, 'application'); + $appob = $this->getApiInstance($app, 'application'); } catch (Horde_Exception $e) { return false; } @@ -605,7 +694,7 @@ class Horde_Registry } /* Load the API now. */ - $api = $this->_getApiInstance($app, 'api'); + $api = $this->getApiInstance($app, 'api'); /* Make sure that the function actually exists. */ if (!method_exists($api, $call)) { @@ -662,7 +751,7 @@ class Horde_Registry } /* Load the API now. */ - $api = $this->_getApiInstance($app, 'application'); + $api = $this->getApiInstance($app, 'application'); /* Switch application contexts now, if necessary, before * including any files which might do it for us. Return an @@ -1122,7 +1211,7 @@ class Horde_Registry } try { - $api = $this->_getApiInstance($app, 'application'); + $api = $this->getApiInstance($app, 'application'); return $api->version; } catch (Horde_Exception $e) { return 'unknown'; @@ -1143,7 +1232,7 @@ class Horde_Registry } try { - $api = $this->_getApiInstance($app, 'application'); + $api = $this->getApiInstance($app, 'application'); return $api->mobileView; } catch (Horde_Exception $e) { return false; diff --git a/framework/Core/lib/Horde/Registry/Application.php b/framework/Core/lib/Horde/Registry/Application.php index b9689ce5f..f76574d12 100644 --- a/framework/Core/lib/Horde/Registry/Application.php +++ b/framework/Core/lib/Horde/Registry/Application.php @@ -34,11 +34,47 @@ class Horde_Registry_Application public $disabled = array(); /** + * The init params used. + * + * @var array + */ + public $initParams = array(); + + /** + * Has init() previously been called? + * + * @var boolean + */ + protected $_initDone = false; + + /** + * Application-specific code to run if application auth fails. + * Called from Horde_Registry::appInit(). + * + * @param Horde_Exception $e The exception object. + */ + public function appInitFailure($e) + { + } + + /** * Initialization. Does any necessary init needed to setup the full * environment for the application. */ public function init() { + if (!$this->_initDone) { + $this->_initDone = true; + $this->_init(); + } + } + + /** + * Initialization code for an application should be defined in this + * function. + */ + protected function _init() + { } } diff --git a/horde/admin/alarms.php b/horde/admin/alarms.php index b9daa51fc..76aef3cc4 100644 --- a/horde/admin/alarms.php +++ b/horde/admin/alarms.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); $horde_alarm = Horde_Alarm::factory(); $methods = array(); diff --git a/horde/admin/cmdshell.php b/horde/admin/cmdshell.php index 094aa883b..d95bcf9dd 100644 --- a/horde/admin/cmdshell.php +++ b/horde/admin/cmdshell.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); $title = _("Command Shell"); require HORDE_TEMPLATES . '/common-header.inc'; diff --git a/horde/admin/datatree.php b/horde/admin/datatree.php index ddf8eb560..070e3e10e 100644 --- a/horde/admin/datatree.php +++ b/horde/admin/datatree.php @@ -27,7 +27,7 @@ function addTree($parent, $parent_id, $indent = 1) } require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); require_once 'Horde/DataTree.php'; $tree = Horde_Tree::factory('datatree', 'Html'); diff --git a/horde/admin/groups.php b/horde/admin/groups.php index f90d48b58..4d5a70f7d 100644 --- a/horde/admin/groups.php +++ b/horde/admin/groups.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); require_once 'Horde/Group.php'; $groups = Group::singleton(); diff --git a/horde/admin/perms/addchild.php b/horde/admin/perms/addchild.php index 271ad6b14..e4b2a364f 100644 --- a/horde/admin/perms/addchild.php +++ b/horde/admin/perms/addchild.php @@ -10,7 +10,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); /* Set up the form variables. */ $vars = Horde_Variables::getDefaultVariables(); diff --git a/horde/admin/perms/delete.php b/horde/admin/perms/delete.php index d9c70f180..faa30003f 100644 --- a/horde/admin/perms/delete.php +++ b/horde/admin/perms/delete.php @@ -10,7 +10,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); /* Set up the form variables. */ $vars = Horde_Variables::getDefaultVariables(); diff --git a/horde/admin/perms/edit.php b/horde/admin/perms/edit.php index 9bb063cea..7931f2279 100644 --- a/horde/admin/perms/edit.php +++ b/horde/admin/perms/edit.php @@ -10,7 +10,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); /* Set up the form variables. */ $vars = &Horde_Variables::getDefaultVariables(); diff --git a/horde/admin/perms/index.php b/horde/admin/perms/index.php index 2374ef251..a03a7f38d 100644 --- a/horde/admin/perms/index.php +++ b/horde/admin/perms/index.php @@ -10,7 +10,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); $perm_id = Horde_Util::getFormData('perm_id'); diff --git a/horde/admin/phpshell.php b/horde/admin/phpshell.php index deff4ecda..11398e523 100644 --- a/horde/admin/phpshell.php +++ b/horde/admin/phpshell.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); $title = _("PHP Shell"); Horde::addScriptFile('stripe.js', 'horde'); diff --git a/horde/admin/sessions.php b/horde/admin/sessions.php index a95e8e35c..c3a05c1a1 100644 --- a/horde/admin/sessions.php +++ b/horde/admin/sessions.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); $type = !empty($conf['sessionhandler']['type']) ? $conf['sessionhandler']['type'] : 'none'; if ($type == 'external') { diff --git a/horde/admin/setup/config.php b/horde/admin/setup/config.php index a8ea974e0..18699d73d 100644 --- a/horde/admin/setup/config.php +++ b/horde/admin/setup/config.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); if (!Horde_Util::extensionExists('domxml') && !Horde_Util::extensionExists('dom')) { diff --git a/horde/admin/setup/diff.php b/horde/admin/setup/diff.php index 18f2fdce1..6a235ee41 100644 --- a/horde/admin/setup/diff.php +++ b/horde/admin/setup/diff.php @@ -10,7 +10,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); /* Set up the diff renderer. */ $render_type = Horde_Util::getFormData('render', 'inline'); diff --git a/horde/admin/setup/index.php b/horde/admin/setup/index.php index 1f9066c7e..e1296967a 100644 --- a/horde/admin/setup/index.php +++ b/horde/admin/setup/index.php @@ -11,7 +11,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); /** * Does an FTP upload to save the configuration. diff --git a/horde/admin/setup/scripts.php b/horde/admin/setup/scripts.php index b268fbcaa..d50fc899d 100644 --- a/horde/admin/setup/scripts.php +++ b/horde/admin/setup/scripts.php @@ -13,7 +13,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); /* Get form data. */ $setup = Horde_Util::getFormData('setup'); diff --git a/horde/admin/signup_confirm.php b/horde/admin/signup_confirm.php index e5d721d79..83a0eba4b 100644 --- a/horde/admin/signup_confirm.php +++ b/horde/admin/signup_confirm.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/base.php'; -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); // Make sure signups are enabled before proceeding $auth = Horde_Auth::singleton($conf['auth']['driver']); diff --git a/horde/admin/sqlshell.php b/horde/admin/sqlshell.php index 01516a0af..47c97d6e3 100644 --- a/horde/admin/sqlshell.php +++ b/horde/admin/sqlshell.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); $title = _("SQL Shell"); Horde::addScriptFile('stripe.js', 'horde'); diff --git a/horde/admin/user.php b/horde/admin/user.php index ac9b4221c..1dcaf0d80 100644 --- a/horde/admin/user.php +++ b/horde/admin/user.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('admin' => true)); +Horde_Registry::appInit('horde', array('admin' => true)); $auth = Horde_Auth::singleton($conf['auth']['driver']); diff --git a/horde/bin/alarms b/horde/bin/alarms index 7a6e769ce..23ee79619 100755 --- a/horde/bin/alarms +++ b/horde/bin/alarms @@ -22,7 +22,7 @@ if (!Horde_Cli::runningFromCLI()) { Horde_Cli::init(); // Include needed libraries. -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); // Authenticate as administrator. if (!count($conf['auth']['admins'])) { diff --git a/horde/bin/db_migrate b/horde/bin/db_migrate index 9a7474364..474235361 100755 --- a/horde/bin/db_migrate +++ b/horde/bin/db_migrate @@ -23,7 +23,7 @@ Horde_Cli::init(); $cli = Horde_Cli::singleton(); // Include needed libraries. -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); // Get a database connection $db = $GLOBALS['injector']->getInstance('db-manager'); diff --git a/horde/index.php b/horde/index.php index aa98d2e08..fbb74f708 100644 --- a/horde/index.php +++ b/horde/index.php @@ -11,7 +11,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new Horde_Application(array('authentication' => 'none', 'nologintasks' => true)); +Horde_Registry::appInit('horde', array('authentication' => 'none', 'nologintasks' => true)); $main_page = Horde_Util::nonInputVar('horde_login_url', Horde_Util::getFormData('url')); diff --git a/horde/lib/Application.php b/horde/lib/Application.php index b2bbdd12b..7f5ab31b3 100644 --- a/horde/lib/Application.php +++ b/horde/lib/Application.php @@ -25,84 +25,28 @@ class Horde_Application extends Horde_Registry_Application public $version = '4.0-git'; /** - * Constructor. + * Application initialization. * * Global variables defined: * $notification - Notification object - * $registry - Registry object * * Global constants defined: * HORDE_TEMPLATES - (string) Location of template files. - * - * @param array $args Optional arguments: - *
-     * 'admin' - (boolean) Require authenticated user to be and admin?
-     * 'authentication' - (string) The type of authentication to use:
-     *   'none'  - Do not authenticate
-     *   'throw' - Authenticate; on no auth, throw a Horde_Exception
-     *   [DEFAULT] - Authenticate; on no auth redirect to login screen
-     * 'nocompress' - (boolean) Controls whether the page should be
-     *                compressed.
-     * 'nologintasks' - (boolean) If set, don't perform logintasks (never
-     *                  performed if authentication is 'none').
-     * 'session_control' - (string) Sets special session control limitations:
-     *   'none' - Do not start a session
-     *   'readonly' - Start session readonly
-     *   [DEFAULT] - Start read/write session
-     * 
*/ - public function __construct($args = array()) + protected function _init() { - $args = array_merge(array( - 'admin' => false, - 'authentication' => null, - 'nocompress' => false, - 'nologintasks' => false, - 'session_control' => null - ), $args); - - // Registry. - $s_ctrl = 0; - switch ($args['session_control']) { - case 'none': - $s_ctrl = Horde_Registry::SESSION_NONE; - break; - - case 'readonly': - $s_ctrl = Horde_Registry::SESSION_READONLY; - break; - } - $GLOBALS['registry'] = Horde_Registry::singleton($s_ctrl); - - try { - $GLOBALS['registry']->pushApp('horde', array('check_perms' => ($args['authentication'] != 'none'), 'logintasks' => !$args['nologintasks'])); - - if ($args['admin'] && !Horde_Auth::isAdmin()) { - throw new Horde_Exception('Not an admin'); - } - } catch (Horde_Exception $e) { - if ($args['authentication'] == 'throw') { - throw $e; - } - - Horde_Auth::authenticateFailure('horde', $e); - } - if (!defined('HORDE_TEMPLATES')) { define('HORDE_TEMPLATES', $GLOBALS['registry']->get('templates')); } $GLOBALS['notification'] = Horde_Notification::singleton(); $GLOBALS['notification']->attach('status'); - - // Start compression. - if (!$args['nocompress']) { - Horde::compressOutput(); - } } /** * Returns a list of available permissions. + * + * @return array TODO */ public function perms() { diff --git a/horde/login.php b/horde/login.php index eecc58c23..7eef8cdfa 100644 --- a/horde/login.php +++ b/horde/login.php @@ -77,7 +77,7 @@ function _getLogoutReasonString($code) * constructor. */ require_once dirname(__FILE__) . '/lib/Application.php'; try { - new Horde_Application(array('authentication' => 'throw', 'nologintasks' => true)); + Horde_Registry::appInit('horde', array('authentication' => 'throw', 'nologintasks' => true)); } catch (Horde_Exception $e) {} $app = Horde_Util::getFormData('app'); diff --git a/horde/rampage.php b/horde/rampage.php index 84a086bdd..ab71eb896 100644 --- a/horde/rampage.php +++ b/horde/rampage.php @@ -24,7 +24,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); // Set up our request and routing objects $request = new Horde_Controller_Request_Http(); diff --git a/horde/rpc.php b/horde/rpc.php index 0ba1e43dd..cc12b3754 100644 --- a/horde/rpc.php +++ b/horde/rpc.php @@ -78,7 +78,7 @@ if (($ra = Horde_Util::getGet('requestMissingAuthorization')) !== null) { } /* Load base libraries. */ -new Horde_Application(array('authentication' => 'none', 'nocompress' => $nocompress, 'session_control' => $session_control)); +Horde_Registry::appInit('horde', array('authentication' => 'none', 'nocompress' => $nocompress, 'session_control' => $session_control)); /* Load the RPC backend based on $serverType. */ $server = Horde_Rpc::factory($serverType, $params); diff --git a/horde/scripts/cookie_login.php b/horde/scripts/cookie_login.php index 2e5d21dc6..61371be3e 100644 --- a/horde/scripts/cookie_login.php +++ b/horde/scripts/cookie_login.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); $auth = Horde_Auth::singleton($conf['auth']['driver']); diff --git a/horde/scripts/get_login.php b/horde/scripts/get_login.php index 98a4ad971..73360edd2 100644 --- a/horde/scripts/get_login.php +++ b/horde/scripts/get_login.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); $auth = Horde_Auth::singleton($conf['auth']['driver']); diff --git a/horde/scripts/http_login_refer.php b/horde/scripts/http_login_refer.php index 1586f2a9d..c1e3d88e4 100644 --- a/horde/scripts/http_login_refer.php +++ b/horde/scripts/http_login_refer.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); $auth = Horde_Auth::singleton($conf['auth']['driver']); diff --git a/horde/scripts/import_squirrelmail_file_prefs.php b/horde/scripts/import_squirrelmail_file_prefs.php index dbfed1ec5..6e34610c7 100755 --- a/horde/scripts/import_squirrelmail_file_prefs.php +++ b/horde/scripts/import_squirrelmail_file_prefs.php @@ -39,7 +39,7 @@ $data = $argv[1]; // Make sure we load Horde base to get the auth config require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); require_once dirname(__FILE__) . '/import_squirrelmail_prefs.php'; diff --git a/horde/scripts/import_squirrelmail_sql_prefs.php b/horde/scripts/import_squirrelmail_sql_prefs.php index 3438b5210..7f1f3c250 100755 --- a/horde/scripts/import_squirrelmail_sql_prefs.php +++ b/horde/scripts/import_squirrelmail_sql_prefs.php @@ -37,7 +37,7 @@ if ($argc != 2) { $dsn = $argv[1]; // Make sure we load Horde base to get the auth config -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); require_once dirname(__FILE__) . '/import_squirrelmail_prefs.php'; diff --git a/horde/scripts/upgrades/2008-04-09_horde_syncml_map.php b/horde/scripts/upgrades/2008-04-09_horde_syncml_map.php index 19b8be229..711edd8ac 100755 --- a/horde/scripts/upgrades/2008-04-09_horde_syncml_map.php +++ b/horde/scripts/upgrades/2008-04-09_horde_syncml_map.php @@ -18,7 +18,7 @@ if (!Horde_Cli::runningFromCLI()) { Horde_Cli::init(); $cli = Horde_Cli::singleton(); -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); require_once 'Horde/DataTree.php'; $datatree = DataTree::factory('sql', diff --git a/horde/scripts/upgrades/convert_datatree_groups_to_sql.php b/horde/scripts/upgrades/convert_datatree_groups_to_sql.php index 9c5bd770c..9ad3cde24 100755 --- a/horde/scripts/upgrades/convert_datatree_groups_to_sql.php +++ b/horde/scripts/upgrades/convert_datatree_groups_to_sql.php @@ -17,7 +17,7 @@ if (!Horde_Cli::runningFromCLI()) { // some variables, etc. Horde_Cli::init(); -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); require_once 'Horde/Group.php'; $g = Group::factory(); diff --git a/horde/scripts/upgrades/convert_datatree_perms_to_sql.php b/horde/scripts/upgrades/convert_datatree_perms_to_sql.php index 177cc2260..145562e01 100755 --- a/horde/scripts/upgrades/convert_datatree_perms_to_sql.php +++ b/horde/scripts/upgrades/convert_datatree_perms_to_sql.php @@ -17,7 +17,7 @@ if (!Horde_Cli::runningFromCLI()) { // some variables, etc. Horde_Cli::init(); -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); $p = Perms::factory('datatree'); diff --git a/horde/scripts/upgrades/migrate_user_categories.php b/horde/scripts/upgrades/migrate_user_categories.php index a118b8522..21e60ef2b 100755 --- a/horde/scripts/upgrades/migrate_user_categories.php +++ b/horde/scripts/upgrades/migrate_user_categories.php @@ -20,7 +20,7 @@ if (!Horde_Cli::runningFromCLI()) { // some variables, etc. Horde_Cli::init(); -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); $cli = Horde_Cli::singleton(); $cManager = new Horde_Prefs_CategoryManager(); diff --git a/horde/scripts/upgrades/move_history_out_of_datatree.php b/horde/scripts/upgrades/move_history_out_of_datatree.php index 0209fab42..7ef41f197 100755 --- a/horde/scripts/upgrades/move_history_out_of_datatree.php +++ b/horde/scripts/upgrades/move_history_out_of_datatree.php @@ -21,7 +21,7 @@ $cli = Horde_Cli::singleton(); $cli->writeln($cli->yellow("Beginning migration. This may take a very long time to complete.")); $cli->writeln(); -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); require_once 'Horde/DataTree.php'; $datatree = DataTree::factory('sql', array_merge(Horde::getDriverConfig('datatree', 'sql'), diff --git a/horde/services/cache.php b/horde/services/cache.php index a4151afae..58efda2be 100644 --- a/horde/services/cache.php +++ b/horde/services/cache.php @@ -41,7 +41,7 @@ if (empty($args['nocache'])) { $session_cache_limiter = 'nocache'; } -new Horde_Application(array('authentication' => 'none', 'session_control' => 'readonly')); +Horde_Registry::appInit('horde', array('authentication' => 'none', 'session_control' => 'readonly')); switch ($type) { case 'app': diff --git a/horde/services/cacheview.php b/horde/services/cacheview.php index eb13ea803..82278cb36 100644 --- a/horde/services/cacheview.php +++ b/horde/services/cacheview.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('nologintasks' => true)); +Horde_Registry::appInit('horde', array('nologintasks' => true)); $cid = Horde_Util::getFormData('cid'); if (empty($cid)) { diff --git a/horde/services/changepassword.php b/horde/services/changepassword.php index 882c4a450..3291292a6 100644 --- a/horde/services/changepassword.php +++ b/horde/services/changepassword.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('nologintasks' => true)); +Horde_Registry::appInit('horde', array('nologintasks' => true)); // Make sure auth backend allows passwords to be reset. $auth = Horde_Auth::singleton($conf['auth']['driver']); diff --git a/horde/services/confirm.php b/horde/services/confirm.php index 63e5c5acd..182e45514 100644 --- a/horde/services/confirm.php +++ b/horde/services/confirm.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('nologintasks' => true)); +Horde_Registry::appInit('horde', array('nologintasks' => true)); $identity = Horde_Prefs_Identity::singleton(); list($message, $type) = $identity->confirmIdentity(Horde_Util::getFormData('h')); diff --git a/horde/services/facebook.php b/horde/services/facebook.php index 0da4985ef..544f963f0 100644 --- a/horde/services/facebook.php +++ b/horde/services/facebook.php @@ -11,7 +11,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); if (empty($GLOBALS['conf']['facebook']['enabled']) || empty($GLOBALS['conf']['facebook']['key']) || diff --git a/horde/services/go.php b/horde/services/go.php index cc9fd5368..f82ede207 100644 --- a/horde/services/go.php +++ b/horde/services/go.php @@ -13,7 +13,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('authentication' => 'none', 'session_control' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none', 'session_control' => 'none')); if (empty($_GET['url'])) { exit; diff --git a/horde/services/help/index.php b/horde/services/help/index.php index 25d9e80b9..b8bf1c531 100644 --- a/horde/services/help/index.php +++ b/horde/services/help/index.php @@ -7,7 +7,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); $rtl = isset(Horde_Nls::$config['rtl'][$language]); $title = _("Help"); diff --git a/horde/services/images/view.php b/horde/services/images/view.php index e3ac9b621..3b2a4b785 100644 --- a/horde/services/images/view.php +++ b/horde/services/images/view.php @@ -11,7 +11,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('nologintasks' => true)); +Horde_Registry::appInit('horde', array('nologintasks' => true)); /* Get file info. The following parameters are available: * 'f' - the filename. diff --git a/horde/services/imple.php b/horde/services/imple.php index 9bd059e4b..f6412a539 100644 --- a/horde/services/imple.php +++ b/horde/services/imple.php @@ -58,7 +58,7 @@ if (!empty($args['post'])) { } } -new Horde_Application(array('nologintasks' => true, 'session_control' => empty($args['sessionWrite']) ? 'readonly' : null)); +Horde_Registry::appInit('horde', array('nologintasks' => true, 'session_control' => empty($args['sessionWrite']) ? 'readonly' : null)); $impleargs = $impleName; if (isset($args['impleApp'])) { diff --git a/horde/services/javascript.php b/horde/services/javascript.php index 421fd7c13..0b998fd26 100644 --- a/horde/services/javascript.php +++ b/horde/services/javascript.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('session_control' => 'readonly')); +Horde_Registry::appInit('horde', array('session_control' => 'readonly')); // Figure out if we've been inlined, or called directly. $send_headers = strstr($_SERVER['PHP_SELF'], 'javascript.php'); diff --git a/horde/services/keyboard.php b/horde/services/keyboard.php index 6c7cb4f1d..ad8361d28 100644 --- a/horde/services/keyboard.php +++ b/horde/services/keyboard.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('nologintasks' => true)); +Horde_Registry::appInit('horde', array('nologintasks' => true)); $title = _("Special Character Input"); require HORDE_TEMPLATES . '/common-header.inc'; diff --git a/horde/services/language.php b/horde/services/language.php index f26192b1f..fd24ada65 100644 --- a/horde/services/language.php +++ b/horde/services/language.php @@ -11,7 +11,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); /* Set the language. */ $_SESSION['horde_language'] = Horde_Nls::select(); diff --git a/horde/services/logintasks.php b/horde/services/logintasks.php index 4b784f2d9..5bbb2a46e 100644 --- a/horde/services/logintasks.php +++ b/horde/services/logintasks.php @@ -12,7 +12,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('nologintasks' => true)); +Horde_Registry::appInit('horde', array('nologintasks' => true)); /* If no 'module' parameter passed in, die with an error. */ if (!($app = basename(Horde_Util::getFormData('app')))) { diff --git a/horde/services/obrowser/index.php b/horde/services/obrowser/index.php index 1f0574c40..b1e3958c4 100644 --- a/horde/services/obrowser/index.php +++ b/horde/services/obrowser/index.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); $path = Horde_Util::getFormData('path'); diff --git a/horde/services/portal/cloud_search.php b/horde/services/portal/cloud_search.php index 8692c9eb7..fdc73c4d0 100644 --- a/horde/services/portal/cloud_search.php +++ b/horde/services/portal/cloud_search.php @@ -15,7 +15,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('nologintaks' => true)); +Horde_Registry::appInit('horde', array('nologintaks' => true)); // If/when more apps support the searchTags api calls, we should probably // find a better solution to putting the apps hardcoded like this. diff --git a/horde/services/portal/edit.php b/horde/services/portal/edit.php index d89231882..d135d6052 100644 --- a/horde/services/portal/edit.php +++ b/horde/services/portal/edit.php @@ -11,7 +11,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); // Instantiate the blocks objects. $blocks = Horde_Block_Collection::singleton('portal'); diff --git a/horde/services/portal/index.php b/horde/services/portal/index.php index 0d32d6df7..0c9759733 100644 --- a/horde/services/portal/index.php +++ b/horde/services/portal/index.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); // Get full name. $identity = Horde_Prefs_Identity::singleton(); diff --git a/horde/services/portal/mobile.php b/horde/services/portal/mobile.php index ddb1a0df0..af7d808bc 100644 --- a/horde/services/portal/mobile.php +++ b/horde/services/portal/mobile.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); $identity = Horde_Prefs_Identity::singleton(); $fullname = $identity->getValue('fullname'); diff --git a/horde/services/portal/rpcsum.php b/horde/services/portal/rpcsum.php index 194efb939..dedd79dd9 100644 --- a/horde/services/portal/rpcsum.php +++ b/horde/services/portal/rpcsum.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); $rpc_servers = @unserialize($prefs->getValue('remote_summaries')); if (!is_array($rpc_servers)) { diff --git a/horde/services/portal/sidebar.php b/horde/services/portal/sidebar.php index 6bfee80f3..db1728aa5 100644 --- a/horde/services/portal/sidebar.php +++ b/horde/services/portal/sidebar.php @@ -203,7 +203,7 @@ function buildMenu() } require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); if (!Horde_Auth::getAuth() && !$conf['menu']['always']) { Horde_Auth::authenticateFailure(); diff --git a/horde/services/portal/syncml.php b/horde/services/portal/syncml.php index 8c96690b6..cb79aeed0 100644 --- a/horde/services/portal/syncml.php +++ b/horde/services/portal/syncml.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); $backend = SyncML_Backend::factory('Horde'); diff --git a/horde/services/problem.php b/horde/services/problem.php index 3f1fad64b..ad1355ed2 100644 --- a/horde/services/problem.php +++ b/horde/services/problem.php @@ -17,7 +17,7 @@ function _returnToPage() } require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); if (!Horde::showService('problem')) { _returnToPage(); diff --git a/horde/services/resetpassword.php b/horde/services/resetpassword.php index 72e43d581..a90d555d2 100644 --- a/horde/services/resetpassword.php +++ b/horde/services/resetpassword.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); // Make sure auth backend allows passwords to be reset. $auth = Horde_Auth::singleton($conf['auth']['driver']); diff --git a/horde/services/shares/edit.php b/horde/services/shares/edit.php index bcc639f3e..b493c97b8 100644 --- a/horde/services/shares/edit.php +++ b/horde/services/shares/edit.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); // Exit if the user shouldn't be able to change share permissions. if (!empty($conf['share']['no_sharing'])) { diff --git a/horde/services/snooze.php b/horde/services/snooze.php index 15f0ab5c4..147162961 100644 --- a/horde/services/snooze.php +++ b/horde/services/snooze.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('nologintasks' => true)); +Horde_Registry::appInit('horde', array('nologintasks' => true)); $alarm = Horde_Alarm::factory(); $id = Horde_Util::getPost('alarm'); diff --git a/horde/services/twitter.php b/horde/services/twitter.php index e31b626dc..b7d27a5ab 100644 --- a/horde/services/twitter.php +++ b/horde/services/twitter.php @@ -10,7 +10,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(); +Horde_Registry::appInit('horde'); if (empty($GLOBALS['conf']['twitter']['enabled'])) { $horde_url = Horde::url($registry->get('webroot', 'horde') . '/index.php'); diff --git a/horde/services/twitterapi.php b/horde/services/twitterapi.php index 31a43f3fc..f9f55e1a6 100644 --- a/horde/services/twitterapi.php +++ b/horde/services/twitterapi.php @@ -14,7 +14,7 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -new Horde_Application(array('nologintasks' => true)); +Horde_Registry::appInit('horde', array('nologintasks' => true)); $twitter = new Services_Twitter($_SESSION['horde']['twitterblock']['username'], $_SESSION['horde']['twitterblock']['password']); diff --git a/horde/signup.php b/horde/signup.php index 595f2f822..8bf0ebd6b 100644 --- a/horde/signup.php +++ b/horde/signup.php @@ -9,7 +9,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); $auth = Horde_Auth::singleton($conf['auth']['driver']); diff --git a/horde/test.php b/horde/test.php index f765b9713..e365f8d4b 100644 --- a/horde/test.php +++ b/horde/test.php @@ -20,7 +20,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -$api = new Horde_Application(array('authentication' => 'none')); +Horde_Registry::appInit('horde', array('authentication' => 'none')); if (!empty($conf['testdisable'])) { echo '

Horde test scripts have been disabled in the local configuration.

'; @@ -49,8 +49,7 @@ $app_version = $registry->getVersion($app); /* If we've gotten this far, we should have found enough of Horde to run * tests. Create the testing object. */ if ($app != 'horde') { - $registry->pushApp($app, array('check_perms' => false)); - print "C"; + $registry->pushApp($app, array('check_perms' => false, 'init' => true)); } $classname = ucfirst($app) . '_Test'; if (!class_exists($classname)) { diff --git a/imp/acl.php b/imp/acl.php index 2b4e6d35e..26ec52127 100644 --- a/imp/acl.php +++ b/imp/acl.php @@ -13,7 +13,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); /* Redirect back to the options screen if ACL is not enabled. */ $prefs_url = Horde::getServiceLink('options', 'imp'); diff --git a/imp/ajax.php b/imp/ajax.php index 51f7460a4..920bba6c5 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -159,7 +159,7 @@ if (in_array($action, array('chunkContent', 'Html2Text', 'Text2Html', 'GetReplyD } try { - new IMP_Application(array('init' => array('authentication' => 'throw', 'session_control' => $session_control))); + Horde_Registry::appInit('imp', array('authentication' => 'throw', 'session_control' => $session_control)); } catch (Horde_Exception $e) { /* Handle session timeouts when they come from an AJAX request. */ if (($e->getCode() == Horde_Registry::AUTH_FAILURE) && diff --git a/imp/attachment.php b/imp/attachment.php index 921ae58b8..4e92a100d 100644 --- a/imp/attachment.php +++ b/imp/attachment.php @@ -17,7 +17,7 @@ // We do not need to be authenticated to get the file. Most users won't send // linked attachments just to other IMP users. require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => array('authentication' => 'none', 'session_control' => 'none'))); +Horde_Registry::appInit('imp', array('authentication' => 'none', 'session_control' => 'none')); // Lets see if we are even able to send the user an attachment. if (!$conf['compose']['link_attachments']) { diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index e27d473b5..a25b574f1 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -18,7 +18,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true, 'tz' => true)); +Horde_Registry::appInit('imp', array('tz' => true)); /* Determine if compose mode is disabled. */ $compose_disable = !IMP::canCompose(); diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 797a7db64..2e61e685d 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -13,7 +13,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true, 'tz' => true)); +Horde_Registry::appInit('imp', array('tz' => true)); /* The message text and headers. */ $expand = array(); diff --git a/imp/compose.php b/imp/compose.php index 3c7bd6ef3..e46376b93 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -42,7 +42,7 @@ function _popupSuccess() require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => array('session_control' => 'netscape'), 'tz' => true)); +Horde_Registry::appInit('imp', array('session_control' => 'netscape', 'tz' => true)); /* The message headers and text. */ $header = array(); diff --git a/imp/contacts.php b/imp/contacts.php index 245d33e43..f65c2fb9c 100644 --- a/imp/contacts.php +++ b/imp/contacts.php @@ -11,7 +11,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => array('authentication' => 'horde'))); +Horde_Registry::appInit('imp', array('authentication' => 'horde')); /* Get the lists of address books through the API. */ $source_list = $registry->call('contacts/sources'); diff --git a/imp/filterprefs.php b/imp/filterprefs.php index e588a1626..a2137fbde 100644 --- a/imp/filterprefs.php +++ b/imp/filterprefs.php @@ -10,7 +10,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); /* Are preferences locked? */ $login_locked = $prefs->isLocked('filter_on_login') || empty($_SESSION['imp']['filteravail']); diff --git a/imp/folders-mimp.php b/imp/folders-mimp.php index 95bc833f2..62d1db566 100644 --- a/imp/folders-mimp.php +++ b/imp/folders-mimp.php @@ -17,7 +17,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); /* Redirect back to the mailbox if folder use is not allowed. */ if (empty($conf['user']['allow_folders'])) { diff --git a/imp/folders.php b/imp/folders.php index e32e49c87..85fa93f91 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -14,7 +14,8 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); + Horde::addScriptFile('folders.js', 'imp'); /* Redirect back to the mailbox if folder use is not allowed. */ diff --git a/imp/index-dimp.php b/imp/index-dimp.php index 1d17fed04..2905c493e 100644 --- a/imp/index-dimp.php +++ b/imp/index-dimp.php @@ -13,7 +13,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); $scripts = array( array('ContextSensitive.js', 'imp'), diff --git a/imp/index.php b/imp/index.php index 5495e575d..30fec5124 100644 --- a/imp/index.php +++ b/imp/index.php @@ -11,7 +11,7 @@ // Will redirect to login page if not authenticated. require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); // Load initial page as defined by view mode & preferences. require IMP_Auth::getInitialPage(); diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 2656a5188..a8bd8e2f7 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -47,20 +47,6 @@ class IMP_Application extends Horde_Registry_Application public $version = 'H4 (5.0-git)'; /** - * Disable compression of pages? - * - * @var boolean - */ - protected $_noCompress = false; - - /** - * The auth type to use. - * - * @var string - */ - static public $authType = null; - - /** * Cached data for prefs pages. * * @var array @@ -68,41 +54,33 @@ class IMP_Application extends Horde_Registry_Application static public $prefsCache = array(); /** - * Has init previously been called? - * - * @var boolean + * Constructor. */ - static protected $_init = false; + public function __construct() + { + /* Methods only available if admin config is set for this + * server/login. */ + if (empty($_SESSION['imp']['admin'])) { + $this->disabled = array_merge($this->disabled, array('authAddUser', 'authRemoveUser', 'authUserList')); + } + } /** - * Constructor. + * Application-specific code to run if application auth fails. * - * @param array $args The following entries: - *
-     * 'init' - (boolean|array) If true, perform application init. If an
-     *          array, perform application init and pass the array to
-     *          self::_impInit().
-     * 'tz' - (boolean) If true, sets the current time zone on the server.
-     * 
+ * @param Horde_Exception $e The exception object. */ - public function __construct($args = array()) + public function appInitFailure($e) { - if (!empty($args['init'])) { - $this->_impInit(is_array($args['init']) ? $args['init'] : array()); - } - - if (!empty($args['tz'])) { - Horde_Nls::setTimeZone(); - } - - /* Only available if admin config is set for this server/login. */ - if (empty($_SESSION['imp']['admin'])) { - $this->disabled = array_merge($this->disabled, array('authAddUser', 'authRemoveUser', 'authUserList')); + if (($e->getCode() == Horde_Registry::AUTH_FAILURE) && + Horde_Util::getFormData('composeCache')) { + $imp_compose = IMP_Compose::singleton(); + $imp_compose->sessionExpireDraft(); } } /** - * IMP base initialization. + * Initialization function. * * Global variables defined: * $imp_imap - An IMP_Imap object @@ -110,86 +88,20 @@ class IMP_Application extends Horde_Registry_Application * $imp_notify - A Horde_Notification_Listener object * $imp_search - An IMP_Search object * $notification - Notification object - * $registry - Registry object * * Global constants defined: * IMP_TEMPLATES - (string) Location of template files. * - * @param array $args Optional arguments: + * When calling Horde_Registry::appInit(), the following parameters are + * also supported: *
-     * 'authentication' - (string) The type of authentication to use:
-     *   'horde' - Only use horde authentication
-     *   'none'  - Do not authenticate
-     *   'throw' - Authenticate to IMAP/POP server; on no auth, throw a
-     *             Horde_Exception
-     *   [DEFAULT] - Authenticate to IMAP/POP server; on no auth redirect to
-     *               login screen
-     * 'nocompress' - (boolean) Controls whether the page should be
-     *                 compressed.
-     * 'session_control' - (string) Sets special session control limitations:
-     *   'netscape' - TODO; start read/write session
-     *   'none' - Do not start a session
-     *   'readonly' - Start session readonly
-     *   [DEFAULT] - Start read/write session
+     * 'tz' - (boolean) If true, sets the current time zone on the server.
      * 
*/ - protected function _impInit($args = array()) + protected function _init() { - $args = array_merge(array( - 'authentication' => null, - 'nocompress' => false, - 'session_control' => null - ), $args); - - self::$authType = $args['authentication']; - $this->_noCompress = $args['nocompress']; - - // Registry. - $s_ctrl = 0; - switch ($args['session_control']) { - case 'netscape': - if ($GLOBALS['browser']->isBrowser('mozilla')) { - session_cache_limiter('private, must-revalidate'); - } - break; - - case 'none': - $s_ctrl = Horde_Registry::SESSION_NONE; - break; - - case 'readonly': - $s_ctrl = Horde_Registry::SESSION_READONLY; - break; - } - $GLOBALS['registry'] = Horde_Registry::singleton($s_ctrl); - - try { - $GLOBALS['registry']->pushApp('imp', array('check_perms' => ($args['authentication'] != 'none'), 'logintasks' => true)); - } catch (Horde_Exception $e) { - if ($e->getCode() == Horde_Registry::AUTH_FAILURE) { - if (Horde_Util::getFormData('composeCache')) { - $imp_compose = IMP_Compose::singleton(); - $imp_compose->sessionExpireDraft(); - } - - if ($args['authentication'] == 'throw') { - throw $e; - } - } - - Horde_Auth::authenticateFailure('imp', $e); - } - - $this->init(); - } - - /** - * Initialization function. - */ - public function init() - { - if (self::$_init) { - return; + if (!empty($this->initParams['tz'])) { + Horde_Nls::setTimeZone(); } if (!defined('IMP_TEMPLATES')) { @@ -197,11 +109,6 @@ class IMP_Application extends Horde_Registry_Application define('IMP_TEMPLATES', $registry->get('templates')); } - // Start compression. - if (!$this->_noCompress) { - Horde::compressOutput(); - } - // Initialize global $imp_imap object. if (!isset($GLOBALS['imp_imap'])) { $GLOBALS['imp_imap'] = new IMP_Imap(); @@ -231,8 +138,6 @@ class IMP_Application extends Horde_Registry_Application // Initialize global $imp_mbox array. This call also initializes the // IMP_Search object. IMP::setCurrentMailboxInfo(); - - self::$_init = true; } /* Horde permissions. */ @@ -390,7 +295,7 @@ class IMP_Application extends Horde_Registry_Application */ public function authAuthenticate($userId, $credentials) { - $this->_impInit(array('authentication' => 'none')); + $this->init(); $new_session = IMP_Auth::authenticate(array( 'password' => $credentials['password'], @@ -416,7 +321,7 @@ class IMP_Application extends Horde_Registry_Application */ public function authTransparent($auth_ob) { - $this->_impInit(array('authentication' => 'none')); + $this->init(); return IMP_Auth::transparent($auth_ob); } @@ -428,7 +333,7 @@ class IMP_Application extends Horde_Registry_Application public function authAuthenticateCallback() { if (Horde_Auth::getAuth()) { - $this->_impInit(); + $this->init(); IMP_Auth::authenticateCallback(); } } @@ -742,9 +647,6 @@ class IMP_Application extends Horde_Registry_Application */ public function prefsStatus() { - require_once dirname(__FILE__) . '/Application.php'; - new IMP_Application(array('init' => array('authentication' => 'none'))); - $notification = Horde_Notification::singleton(); $notification->replace('status', array('prefs' => true, 'viewmode' => 'dimp'), 'IMP_Notification_Listener_Status'); } @@ -1075,12 +977,7 @@ class IMP_Application extends Horde_Registry_Application */ public function changeLanguage() { - try { - $this->_impInit(array('authentication' => 'throw')); - } catch (Horde_Exception $e) { - return; - } - + $this->init(); $this->_mailboxesChanged(); $GLOBALS['imp_search']->initialize(true); } diff --git a/imp/lib/Auth.php b/imp/lib/Auth.php index 124296e59..8f7b8a50b 100644 --- a/imp/lib/Auth.php +++ b/imp/lib/Auth.php @@ -32,7 +32,8 @@ class IMP_Auth static public function authenticate($credentials = array()) { // Do 'horde' authentication. - if (IMP_Application::$authType == 'horde') { + $imp_app = $GLOBALS['registry']->getApiInstance('imp', 'application'); + if ($imp_app->initParams['authentication'] == 'horde') { if (Horde_Auth::getAuth()) { return false; } diff --git a/imp/lib/Block/Foldersummary.php b/imp/lib/Block/Foldersummary.php index 0623985c4..352d2bf9c 100644 --- a/imp/lib/Block/Foldersummary.php +++ b/imp/lib/Block/Foldersummary.php @@ -14,12 +14,6 @@ class IMP_Block_Foldersummary extends Horde_Block protected function _content() { - try { - new IMP_Application(array('init' => array('authentication' => 'throw'))); - } catch (Horde_Exception $e) { - return; - } - /* Filter on INBOX display, if requested. */ if ($GLOBALS['prefs']->getValue('filter_on_display')) { $imp_filter = new IMP_Filter(); diff --git a/imp/lib/Block/Newmail.php b/imp/lib/Block/Newmail.php index 22fdaea3c..564362982 100644 --- a/imp/lib/Block/Newmail.php +++ b/imp/lib/Block/Newmail.php @@ -14,12 +14,6 @@ class IMP_Block_Newmail extends Horde_Block protected function _content() { - try { - new IMP_Application(array('init' => array('authentication' => 'throw'))); - } catch (Horde_Exception $e) { - return; - } - /* Filter on INBOX display, if requested. */ if ($GLOBALS['prefs']->getValue('filter_on_display')) { $imp_filter = new IMP_Filter(); diff --git a/imp/lib/Block/summary.php b/imp/lib/Block/summary.php index e4f9c2a3e..2cefa9a02 100644 --- a/imp/lib/Block/summary.php +++ b/imp/lib/Block/summary.php @@ -35,12 +35,6 @@ class Horde_Block_imp_summary extends Horde_Block { global $notification, $prefs, $registry; - try { - new IMP_Application(array('init' => array('authentication' => 'throw'))); - } catch (Horde_Exception $e) { - return; - } - $html = ''; /* Filter on INBOX display, if requested. */ diff --git a/imp/lib/Block/tree_folders.php b/imp/lib/Block/tree_folders.php index 2d697542a..edd2ac2a9 100644 --- a/imp/lib/Block/tree_folders.php +++ b/imp/lib/Block/tree_folders.php @@ -17,12 +17,6 @@ class Horde_Block_imp_tree_folders extends Horde_Block protected function _buildTree(&$tree, $indent = 0, $parent = null) { - try { - new IMP_Application(array('init' => array('authentication' => 'throw'))); - } catch (Horde_Exception $e) { - return; - } - /* Run filters now */ if ($GLOBALS['prefs']->getValue('filter_on_sidebar')) { $imp_filter = new IMP_Filter(); diff --git a/imp/mailbox-mimp.php b/imp/mailbox-mimp.php index 6a5f7861f..b14cd7156 100644 --- a/imp/mailbox-mimp.php +++ b/imp/mailbox-mimp.php @@ -21,7 +21,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true, 'tz' => true)); +Horde_Registry::appInit('imp', array('tz' => true)); /* Determine if mailbox is readonly. */ $readonly = $imp_imap->isReadOnly($imp_mbox['mailbox']); diff --git a/imp/mailbox.php b/imp/mailbox.php index 27a79c995..ff120f3c0 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -39,7 +39,7 @@ function _outputSummaries($msgs) require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true, 'tz' => true)); +Horde_Registry::appInit('imp', array('tz' => true)); /* Call the mailbox redirection hook, if requested. */ try { diff --git a/imp/message-dimp.php b/imp/message-dimp.php index d8f71316b..019dbcffe 100644 --- a/imp/message-dimp.php +++ b/imp/message-dimp.php @@ -11,7 +11,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); $folder = Horde_Util::getFormData('folder'); $uid = Horde_Util::getFormData('uid'); diff --git a/imp/message-mimp.php b/imp/message-mimp.php index 81d2fbb08..1ac7677de 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -19,7 +19,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true, 'tz' => true)); +Horde_Registry::appInit('imp', array('tz' => true)); /* Make sure we have a valid index. */ $imp_mailbox = IMP_Mailbox::singleton($imp_mbox['mailbox'], $imp_mbox['uid'] . IMP::IDX_SEP . $imp_mbox['thismailbox']); diff --git a/imp/message.php b/imp/message.php index 35e8895d9..5c6fc3c61 100644 --- a/imp/message.php +++ b/imp/message.php @@ -20,7 +20,7 @@ function _returnToMailbox($startIndex = null, $actID = null) } require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true, 'tz' => true)); +Horde_Registry::appInit('imp', array('tz' => true)); /* We know we are going to be exclusively dealing with this mailbox, so * select it on the IMAP server (saves some STATUS calls). Open R/W to clear diff --git a/imp/pgp.php b/imp/pgp.php index 3ef42ea84..9f9c9c446 100644 --- a/imp/pgp.php +++ b/imp/pgp.php @@ -78,7 +78,7 @@ function _reloadWindow() } require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); $imp_pgp = Horde_Crypt::singleton(array('IMP', 'Pgp')); $secure_check = Horde::isConnectionSecure(); diff --git a/imp/rss.php b/imp/rss.php index c648059b9..e229ce408 100644 --- a/imp/rss.php +++ b/imp/rss.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/lib/Application.php'; try { - new IMP_Application(array('init' => array('authentication' => 'throw'))); + Horde_Registry::appInit('imp', array('authentication' => 'throw')); } catch (Horde_Exception $e) { //!$auth->authenticate($_SERVER['PHP_AUTH_USER'], array('password' => isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null)))) { header('WWW-Authenticate: Basic realm="IMP RSS Interface"'); diff --git a/imp/saveimage.php b/imp/saveimage.php index 54b1ac624..8f875754c 100644 --- a/imp/saveimage.php +++ b/imp/saveimage.php @@ -12,7 +12,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); $id = Horde_Util::getFormData('id'); $muid = Horde_Util::getFormData('muid'); diff --git a/imp/search-basic.php b/imp/search-basic.php index 3fd886353..5103ed943 100644 --- a/imp/search-basic.php +++ b/imp/search-basic.php @@ -12,7 +12,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); if ($_SESSION['imp']['protocol'] == 'pop') { if ($_SESSION['imp']['view'] == 'imp') { diff --git a/imp/search.php b/imp/search.php index 578cb5366..daea04c8d 100644 --- a/imp/search.php +++ b/imp/search.php @@ -29,7 +29,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); /* Load basic search if javascript is not enabled or searching is not * allowed (basic page will do the required redirection in the latter case). */ diff --git a/imp/smime.php b/imp/smime.php index 334e0505a..47e6f99ec 100644 --- a/imp/smime.php +++ b/imp/smime.php @@ -88,7 +88,7 @@ function _printKeyInfo($cert) require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true)); +Horde_Registry::appInit('imp'); $imp_smime = Horde_Crypt::singleton(array('IMP', 'Smime')); $secure_check = Horde::isConnectionSecure(); diff --git a/imp/stationery.php b/imp/stationery.php index 9a8201656..437553631 100644 --- a/imp/stationery.php +++ b/imp/stationery.php @@ -10,7 +10,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => array('authentication' => 'horde'))); +Horde_Registry::appInit('imp', array('authentication' => 'horde')); $compose_url = Horde::getServiceLink('options', 'imp'); diff --git a/imp/thread.php b/imp/thread.php index 019730027..bf72f1d45 100644 --- a/imp/thread.php +++ b/imp/thread.php @@ -10,7 +10,7 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; -new IMP_Application(array('init' => true, 'tz' => true)); +Horde_Registry::appInit('imp', array('tz' => true)); /* What mode are we in? * DEFAULT/'thread' - Thread mode diff --git a/imp/view.php b/imp/view.php index 4f138a761..606581bd0 100644 --- a/imp/view.php +++ b/imp/view.php @@ -43,10 +43,10 @@ require_once dirname(__FILE__) . '/lib/Application.php'; /* Don't compress if we are already sending in compressed format. */ $actionID = Horde_Util::getFormData('actionID'); -new IMP_Application(array('init' => array( +Horde_Registry::appInit('imp', array( 'nocompress' => (($actionID == 'download_all') || Horde_Util::getFormData('zip')), 'session_control' => 'readonly' -))); +)); $ctype = Horde_Util::getFormData('ctype'); $id = Horde_Util::getFormData('id'); diff --git a/skeleton/config/horde.local.php.dist b/skeleton/config/horde.local.php.dist new file mode 100644 index 000000000..9793ac39b --- /dev/null +++ b/skeleton/config/horde.local.php.dist @@ -0,0 +1,4 @@ +get('templates')); + } + + // Notification system. + $notification = Horde_Notification::singleton(); + $notification->attach('status'); + } + + /** * Generate the menu to use on the prefs page. * * @return Horde_Menu A Horde_Menu object. diff --git a/skeleton/lib/base.load.php b/skeleton/lib/base.load.php deleted file mode 100644 index 4ec90e31b..000000000 --- a/skeleton/lib/base.load.php +++ /dev/null @@ -1,25 +0,0 @@ -pushApp('skeleton', array('check_perms' => true, 'logintasks' => true)); -} catch (Horde_Exception $e) { - Horde_Auth::authenticateFailure('skeleton', $e); -} - -$conf = &$GLOBALS['conf']; -@define('SKELETON_TEMPLATES', $registry->get('templates')); - -// Notification system. -$notification = Horde_Notification::singleton(); -$notification->attach('status'); - -// Start output compression. -Horde::compressOutput(); diff --git a/skeleton/list.php b/skeleton/list.php index 82fd49f99..518cea4fb 100644 --- a/skeleton/list.php +++ b/skeleton/list.php @@ -10,7 +10,8 @@ * @author Your Name */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('skeleton'); $title = _("List"); diff --git a/turba/add.php b/turba/add.php index 652b865be..82562fd37 100644 --- a/turba/add.php +++ b/turba/add.php @@ -10,7 +10,9 @@ * @author Chuck Hagenbuch */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); + require_once TURBA_BASE . '/lib/Forms/AddContact.php'; /* Setup some variables. */ diff --git a/turba/addressbooks/create.php b/turba/addressbooks/create.php index d59a4f991..aac846703 100644 --- a/turba/addressbooks/create.php +++ b/turba/addressbooks/create.php @@ -8,7 +8,9 @@ * did not receive this file, see http://www.horde.org/licenses/asl.php. */ -require_once dirname(__FILE__) . '/../lib/base.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; +Horde_Registry::appInit('turba'); + require_once TURBA_BASE . '/lib/Forms/CreateAddressBook.php'; // Exit if this isn't an authenticated user, or if there's no source diff --git a/turba/addressbooks/delete.php b/turba/addressbooks/delete.php index 34cd6215e..44546d837 100644 --- a/turba/addressbooks/delete.php +++ b/turba/addressbooks/delete.php @@ -8,7 +8,9 @@ * did not receive this file, see http://www.horde.org/licenses/asl.php. */ -require_once dirname(__FILE__) . '/../lib/base.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; +Horde_Registry::appInit('turba'); + require_once TURBA_BASE . '/lib/Forms/DeleteAddressBook.php'; // Exit if this isn't an authenticated user, or if there's no source diff --git a/turba/addressbooks/edit.php b/turba/addressbooks/edit.php index fe19c428d..b28a5e69e 100644 --- a/turba/addressbooks/edit.php +++ b/turba/addressbooks/edit.php @@ -8,7 +8,9 @@ * did not receive this file, see http://www.horde.org/licenses/asl.php. */ -require_once dirname(__FILE__) . '/../lib/base.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; +Horde_Registry::appInit('turba'); + require_once TURBA_BASE . '/lib/Forms/EditAddressBook.php'; // Exit if this isn't an authenticated user, or if there's no source diff --git a/turba/addressbooks/index.php b/turba/addressbooks/index.php index da4f92c5d..adc92902e 100644 --- a/turba/addressbooks/index.php +++ b/turba/addressbooks/index.php @@ -8,7 +8,8 @@ * did not receive this file, see http://www.horde.org/licenses/asl.php. */ -require_once dirname(__FILE__) . '/../lib/base.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; +Horde_Registry::appInit('turba'); // Exit if this isn't an authenticated user, or if there's no source // configured for shares. diff --git a/turba/browse.php b/turba/browse.php index 62a65e1aa..504debad2 100644 --- a/turba/browse.php +++ b/turba/browse.php @@ -11,7 +11,8 @@ * @package Turba */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); $params = array( 'vars' => Horde_Variables::getDefaultVariables(), diff --git a/turba/contact.php b/turba/contact.php index b1cc1ca31..2cf623253 100644 --- a/turba/contact.php +++ b/turba/contact.php @@ -10,7 +10,8 @@ * @author Chuck Hagenbuch */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); $vars = Horde_Variables::getDefaultVariables(); $source = $vars->get('source'); diff --git a/turba/data.php b/turba/data.php index ca423d76b..7607a727c 100644 --- a/turba/data.php +++ b/turba/data.php @@ -78,7 +78,8 @@ function _getBareEmail($address, $allow_multi = false) return implode(', ', $result); } -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); if (!$conf['menu']['import_export']) { require TURBA_BASE . '/index.php'; diff --git a/turba/delete.php b/turba/delete.php index 2e78a78cc..0ccca965a 100644 --- a/turba/delete.php +++ b/turba/delete.php @@ -10,7 +10,8 @@ * @author Chuck Hagenbuch */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); $source = Horde_Util::getFormData('source'); $key = Horde_Util::getFormData('key'); diff --git a/turba/deletefile.php b/turba/deletefile.php index ad30be0ac..9eeafbb4d 100644 --- a/turba/deletefile.php +++ b/turba/deletefile.php @@ -10,7 +10,8 @@ * @author Chuck Hagenbuch */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); if ($conf['documents']['type'] == 'none') { exit; diff --git a/turba/edit.php b/turba/edit.php index 3e9e11d72..67538da85 100644 --- a/turba/edit.php +++ b/turba/edit.php @@ -10,7 +10,9 @@ * @author Chuck Hagenbuch */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); + require_once TURBA_BASE . '/lib/Forms/EditContact.php'; $listView = null; diff --git a/turba/index.php b/turba/index.php index 6d3b6b90c..52ef65ec9 100644 --- a/turba/index.php +++ b/turba/index.php @@ -10,7 +10,9 @@ * @author Chuck Hagenbuch */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); + require TURBA_BASE . '/' . ($browse_source_count ? basename($prefs->getValue('initial_page')) : 'search.php'); diff --git a/turba/lib/Api.php b/turba/lib/Api.php index 43819d46f..ef1c7c852 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -40,11 +40,8 @@ class Turba_Api extends Horde_Registry_Api return false; } - require_once dirname(__FILE__) . '/base.php'; - global $cfgSources; - @list($source, $key) = explode('.', $id, 2); - if (isset($cfgSources[$source]) && $key) { + if (isset($GLOBALS['cfgSources'][$source]) && $key) { $driver = Turba_Driver::singleton($source); if (!is_a($driver, 'PEAR_Error')) { $object = $driver->getObject($key); @@ -76,8 +73,6 @@ class Turba_Api extends Horde_Registry_Api */ public function sources($writeable = false) { - require_once dirname(__FILE__) . '/base.php'; - $addressbooks = Turba::getAddressBooks($writeable ? Horde_Perms::EDIT : Horde_Perms::READ); foreach ($addressbooks as $addressbook => $config) { $addressbooks[$addressbook] = $config['title']; @@ -95,7 +90,6 @@ class Turba_Api extends Horde_Registry_Api */ public function fields($source = null) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources, $attributes; if (empty($source) || !isset($cfgSources[$source])) { @@ -122,8 +116,7 @@ class Turba_Api extends Horde_Registry_Api { global $prefs; - // Bring in turba's base and a clean copy of sources. - require_once dirname(__FILE__) . '/base.php'; + // Bring in a clean copy of sources. require TURBA_BASE . '/config/sources.php'; if (!empty($_SESSION['turba']['has_share'])) { @@ -170,7 +163,6 @@ class Turba_Api extends Horde_Registry_Api */ public function browse($path = '', $properties = array()) { - require_once dirname(__FILE__) . '/base.php'; global $registry, $cfgSources; // Default properties. @@ -395,7 +387,6 @@ class Turba_Api extends Horde_Registry_Api */ public function path_delete($path) { - require_once dirname(__FILE__) . '/base.php'; global $registry, $cfgSources; // Strip off the application name if present @@ -442,8 +433,6 @@ class Turba_Api extends Horde_Registry_Api */ public function listContacts($sources = null) { - require_once dirname(__FILE__) . '/base.php'; - global $cfgSources, $prefs; /* Get default address book from user preferences. */ @@ -499,7 +488,6 @@ class Turba_Api extends Horde_Registry_Api public function listBy($action, $timestamp, $sources = null) { global $prefs, $cfgSources; - require_once dirname(__FILE__) . '/base.php'; /* Get default address book from user preferences. */ if (empty($sources)) { @@ -559,7 +547,6 @@ class Turba_Api extends Horde_Registry_Api public function getActionTimestamp($uid, $action, $sources = null) { global $prefs, $cfgSources; - require_once dirname(__FILE__) . '/base.php'; /* Get default address book from user preferences. */ if (empty($sources)) { @@ -612,7 +599,6 @@ class Turba_Api extends Horde_Registry_Api public function import($content, $contentType = 'array', $import_source = null) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources, $prefs; /* Get default address book from user preferences. */ @@ -743,7 +729,6 @@ class Turba_Api extends Horde_Registry_Api */ public function export($uid, $contentType, $sources = null, $fields = null) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources, $prefs; /* Get default address book from user preferences. */ @@ -855,7 +840,6 @@ class Turba_Api extends Horde_Registry_Api */ public function getOwnContactObject() { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources; $own_contact = $GLOBALS['prefs']->getValue('own_contact'); @@ -913,7 +897,6 @@ class Turba_Api extends Horde_Registry_Api return true; } - require_once dirname(__FILE__) . '/base.php'; global $cfgSources, $prefs; /* Get default address book from user preferences. */ @@ -979,7 +962,6 @@ class Turba_Api extends Horde_Registry_Api */ public function replace($uid, $content, $contentType, $sources = null) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources, $prefs; /* Get default address book from user preferences. */ @@ -1082,7 +1064,6 @@ class Turba_Api extends Horde_Registry_Api $fields = array(), $matchBegin = false, $forceSource = false) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources, $attributes, $prefs; if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources)) { @@ -1273,7 +1254,6 @@ class Turba_Api extends Horde_Registry_Api */ public function getContact($source = null, $objectId = '') { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources; if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources)) { @@ -1311,7 +1291,6 @@ class Turba_Api extends Horde_Registry_Api */ public function getContacts($source = '', $objectIds = array()) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources; $results = array(); if (!is_array($objectIds)) { @@ -1355,7 +1334,6 @@ class Turba_Api extends Horde_Registry_Api */ public function getAllAttributeValues($field = '', $sources = array()) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources; if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources)) { @@ -1400,8 +1378,6 @@ class Turba_Api extends Horde_Registry_Api */ public function listTimeObjectCategories() { - require_once dirname(__FILE__) . '/base.php'; - $categories = array(); foreach ($GLOBALS['attributes'] as $key => $attribute) { if ($attribute['type'] == 'monthdayyear' && @@ -1429,7 +1405,6 @@ class Turba_Api extends Horde_Registry_Api */ public function listTimeObjects($time_categories, $start, $end) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources; $start = new Horde_Date($start); @@ -1571,7 +1546,6 @@ class Turba_Api extends Horde_Registry_Api $value = '', $source = '') { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources; if (empty($source) || !isset($cfgSources[$source])) { @@ -1661,7 +1635,6 @@ class Turba_Api extends Horde_Registry_Api public function getField($address = '', $field = '', $sources = array(), $strict = false, $multiple = false) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources; if (empty($address)) { @@ -1722,7 +1695,6 @@ class Turba_Api extends Horde_Registry_Api */ public function deleteField($address = '', $field = '', $sources = array()) { - require_once dirname(__FILE__) . '/base.php'; global $cfgSources; if (empty($address)) { diff --git a/turba/lib/Application.php b/turba/lib/Application.php index b12219dc7..16f5c27f6 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -2,8 +2,34 @@ /** * Turba application API. * + * This file defines Horde's core API interface. Other core Horde libraries + * can interact with Horde through this API. + * + * 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 Turba */ + +/* Determine the base directories. */ +if (!defined('TURBA_BASE')) { + define('TURBA_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(TURBA_BASE . '/config/horde.local.php')) { + include TURBA_BASE . '/config/horde.local.php'; + } else { + define('HORDE_BASE', TURBA_BASE . '/..'); + } +} + +/* Load the Horde Framework core (needed to autoload + * Horde_Registry_Application::). */ +require_once HORDE_BASE . '/lib/core.php'; + class Turba_Application extends Horde_Registry_Application { /** @@ -14,6 +40,114 @@ class Turba_Application extends Horde_Registry_Application public $version = 'H4 (3.0-git)'; /** + * Initialization. + * + * Global variables defined: + * $addSources - TODO + * $attributes - TODO + * $browse_source_count - TODO + * $browse_source_options - TODO + * $cfgSources - TODO + * $copymove_source_options - TODO + * $copymoveSources - TODO + * $notification - Notification object + * $turba_shares - TODO + * + * Global constants defined: + * TURBA_TEMPLATES - (string) Location of template files. + * + * When calling Horde_Registry::appInit(), the following parameters are + * also supported: + *
+     * 'user' - (string) Set authentication to this user.
+     * 
+ */ + protected function _init() + { + if (isset($this->initParams['user'])) { + Horde_Auth::setAuth($this->initParams['user'], array()); + } + + if (!defined('TURBA_TEMPLATES')) { + define('TURBA_TEMPLATES', $GLOBALS['registry']->get('templates')); + } + + $GLOBALS['notification'] = Horde_Notification::singleton(); + $GLOBALS['notification']->attach('status'); + + // Turba source and attribute configuration. + include TURBA_BASE . '/config/attributes.php'; + include TURBA_BASE . '/config/sources.php'; + + /* UGLY UGLY UGLY - we should NOT be using this as a global + * variable all over the place. */ + $GLOBALS['cfgSources'] = &$cfgSources; + + // See if any of our sources are configured to use Horde_Share. + foreach ($cfgSources as $key => $cfg) { + if (!empty($cfg['use_shares'])) { + // Create a share instance. + $_SESSION['turba']['has_share'] = true; + $GLOBALS['turba_shares'] = Horde_Share::singleton('turba'); + $cfgSources = Turba::getConfigFromShares($cfgSources); + break; + } + } + + $GLOBALS['attributes'] = $attributes; + $cfgSources = Turba::permissionsFilter($cfgSources); + + // Build the directory sources select widget. + $default_source = Horde_Util::nonInputVar('source'); + if (empty($default_source)) { + $default_source = empty($_SESSION['turba']['source']) + ? Turba::getDefaultAddressBook() + : $_SESSION['turba']['source']; + $default_source = Horde_Util::getFormData('source', $default_source); + } + + $GLOBALS['browse_source_count'] = 0; + $GLOBALS['browse_source_options'] = ''; + + foreach (Turba::getAddressBooks() as $key => $curSource) { + if (!empty($curSource['browse'])) { + $selected = ($key == $default_source) ? ' selected="selected"' : ''; + $GLOBALS['browse_source_options'] .= ''; + + ++$GLOBALS['browse_source_count']; + + if (empty($default_source)) { + $default_source = $key; + } + } + } + + if (empty($cfgSources[$default_source]['browse'])) { + $default_source = Turba::getDefaultAddressBook(); + } + $_SESSION['turba']['source'] = $default_source; + $GLOBALS['default_source'] = $default_source; + + /* Only set $add_source_options if there is at least one editable + * address book that is not the current address book. */ + $addSources = Turba::getAddressBooks(Horde_Perms::EDIT, array('require_add' => true)); + $copymove_source_options = ''; + $copymoveSources = $addSources; + unset($copymoveSources[$default_source]); + foreach ($copymoveSources as $key => $curSource) { + if ($key != $default_source) { + $copymove_source_options .= ''; + } + } + + $GLOBALS['addSources'] = $addSources; + $GLOBALS['copymove_source_options'] = $copymove_source_options; + $GLOBALS['copymoveSources'] = $copymoveSources; + } + + /** * Returns a list of available permissions. * * @return array An array describing all available permissions. @@ -25,7 +159,6 @@ class Turba_Application extends Horde_Registry_Application return $perms; } - require_once dirname(__FILE__) . '/base.php'; require TURBA_BASE . '/config/sources.php'; $perms['tree']['turba']['sources'] = false; @@ -126,8 +259,6 @@ class Turba_Application extends Horde_Registry_Application */ public function removeUserData($user) { - require_once dirname(__FILE__) . '/base.php'; - if (!Horde_Auth::isAdmin() && $user != Horde_Auth::getAuth()) { return PEAR::raiseError(_("You are not allowed to remove user data.")); } diff --git a/turba/lib/Block/minisearch.php b/turba/lib/Block/minisearch.php index fa04a19e1..192855f72 100644 --- a/turba/lib/Block/minisearch.php +++ b/turba/lib/Block/minisearch.php @@ -31,8 +31,6 @@ class Horde_Block_turba_minisearch extends Horde_Block { */ function _content() { - require_once dirname(__FILE__) . '/../base.php'; - if ($GLOBALS['browser']->hasFeature('iframes')) { Horde::addScriptFile('prototype.js', 'horde'); return Horde_Util::bufferOutput( diff --git a/turba/lib/Block/tree_menu.php b/turba/lib/Block/tree_menu.php index 1bb8afc7c..d4b23140f 100644 --- a/turba/lib/Block/tree_menu.php +++ b/turba/lib/Block/tree_menu.php @@ -14,8 +14,6 @@ class Horde_Block_turba_tree_menu extends Horde_Block { { global $registry; - require_once dirname(__FILE__) . '/../base.php'; - $browse = Horde::applicationUrl('browse.php'); $add = Horde::applicationUrl('add.php'); $icondir = $registry->getImageDir() . '/menu'; diff --git a/turba/lib/base.load.php b/turba/lib/base.load.php deleted file mode 100644 index 507789b8c..000000000 --- a/turba/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 - * $no_compress - Controls whether the page should be compressed - * - */ - -// Determine BASE directories. -require_once dirname(__FILE__) . '/base.load.php'; - -// Load the Horde Framework core, and set up inclusion paths. -require_once HORDE_BASE . '/lib/core.php'; - -// Registry. -$registry = Horde_Registry::singleton(); -try { - $registry->pushApp('turba', array('check_perms' => (Horde_Util::nonInputVar('turba_authentication') != 'none'), 'logintasks' => true)); -} catch (Horde_Exception $e) { - Horde_Auth::authenticateFailure('turba', $e); -} -$conf = $GLOBALS['conf']; -define('TURBA_TEMPLATES', $registry->get('templates')); - -// Notification system. -$notification = Horde_Notification::singleton(); -$notification->attach('status'); - -// Turba source and attribute configuration. -include TURBA_BASE . '/config/attributes.php'; -include TURBA_BASE . '/config/sources.php'; - -// Ensure we have cfgSources in global scope since base.php might be loaded -// within a function scope and the share hooks require access to cfgSources. -$GLOBALS['cfgSources'] = $cfgSources; - -// See if any of our sources are configured to use Horde_Share. -foreach ($cfgSources as $key => $cfg) { - if (!empty($cfg['use_shares'])) { - $_SESSION['turba']['has_share'] = true; - break; - } -} -if (!empty($_SESSION['turba']['has_share'])) { - // Create a share instance. - $GLOBALS['turba_shares'] = Horde_Share::singleton($registry->getApp()); - $GLOBALS['cfgSources'] = Turba::getConfigFromShares($cfgSources); -} -$GLOBALS['cfgSources'] = Turba::permissionsFilter($GLOBALS['cfgSources']); -$GLOBALS['attributes'] = $attributes; - -// Build the directory sources select widget. -$default_source = Horde_Util::nonInputVar('source'); -if (empty($default_source)) { - $default_source = empty($_SESSION['turba']['source']) ? Turba::getDefaultAddressBook() : $_SESSION['turba']['source']; - $default_source = Horde_Util::getFormData('source', $default_source); -} -$GLOBALS['browse_source_options'] = ''; -$GLOBALS['browse_source_count'] = 0; -foreach (Turba::getAddressBooks() as $key => $curSource) { - if (!empty($curSource['browse'])) { - $selected = ($key == $default_source) ? ' selected="selected"' : ''; - $GLOBALS['browse_source_options'] .= ''; - - $GLOBALS['browse_source_count']++; - - if (empty($default_source)) { - $default_source = $key; - } - } -} -if (empty($cfgSources[$default_source]['browse'])) { - $default_source = Turba::getDefaultAddressBook(); -} -$_SESSION['turba']['source'] = $default_source; - -// Only set $add_source_options if there is at least one editable address book -// that is not the current address book. -$addSources = Turba::getAddressBooks(Horde_Perms::EDIT, array('require_add' => true)); -$copymove_source_options = ''; -$copymoveSources = $addSources; -unset($copymoveSources[$default_source]); -foreach ($copymoveSources as $key => $curSource) { - if ($key != $default_source) { - $copymove_source_options .= ''; - } -} -$GLOBALS['addSources'] = $addSources; - -// Start compression, if requested. -if (!Horde_Util::nonInputVar('no_compress')) { - Horde::compressOutput(); -} diff --git a/turba/lib/tests/ApiTest.php b/turba/lib/tests/ApiTest.php index 144ff7e7f..fecb4cfe7 100644 --- a/turba/lib/tests/ApiTest.php +++ b/turba/lib/tests/ApiTest.php @@ -28,7 +28,6 @@ class Turba_ApiTest extends Turba_TestBase { return; } - require_once TURBA_BASE . '/lib/base.php'; $GLOBALS['source'] = '_test_sql'; $GLOBALS['cfgSources'] = array('_test_sql' => $this->getDriverConfig()); diff --git a/turba/lib/tests/KolabTestBase.php b/turba/lib/tests/KolabTestBase.php index ea7821c6b..5675602cb 100644 --- a/turba/lib/tests/KolabTestBase.php +++ b/turba/lib/tests/KolabTestBase.php @@ -143,7 +143,6 @@ class Turba_KolabTestBase extends Horde_Kolab_Test_Storage $GLOBALS['registry']->pushApp('turba', array('check_perms' => false)); // Turba base libraries. - require_once dirname(__FILE__) . '/../../lib/base.load.php'; require_once TURBA_BASE . '/lib/Turba.php'; require_once TURBA_BASE . '/lib/Driver.php'; require_once TURBA_BASE . '/lib/Object.php'; @@ -162,12 +161,14 @@ class Turba_KolabTestBase extends Horde_Kolab_Test_Storage $GLOBALS['cfgSources'] = Turba::getConfigFromShares($cfgSources); } - function provideServerName() { + function provideServerName() + { return 'localhost.localdomain'; } - function provideHordeBase() { - require_once dirname(__FILE__) . '/../../lib/base.load.php'; + function provideHordeBase() + { + require_once dirname(__FILE__) . '/../Application.php'; return HORDE_BASE; } } diff --git a/turba/minisearch.php b/turba/minisearch.php index 78770a1d9..542a482a6 100644 --- a/turba/minisearch.php +++ b/turba/minisearch.php @@ -10,7 +10,8 @@ * @author Chuck Hagenbuch */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); $search = Horde_Util::getFormData('search'); $results = array(); diff --git a/turba/scripts/import_squirrelmail_file_abook.php b/turba/scripts/import_squirrelmail_file_abook.php index 7a770e6a1..7cfe548e2 100755 --- a/turba/scripts/import_squirrelmail_file_abook.php +++ b/turba/scripts/import_squirrelmail_file_abook.php @@ -17,8 +17,7 @@ */ // Do CLI checks and environment setup first. -require_once dirname(__FILE__) . '/../lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; // Makre sure no one runs this from the web. if (!Horde_Cli::runningFromCli()) { @@ -39,16 +38,8 @@ if ($argc != 2) { $data = $argv[1]; // Make sure we load Horde base to get the auth config -$horde_authentication = 'none'; -require_once HORDE_BASE . '/lib/base.php'; -if ($conf['auth']['admins']) { - Horde_Auth::setAuth($conf['auth']['admins'][0], array()); -} +Horde_Registry::appInit('turba', array('authentication' => 'none', 'user' => $conf['auth']['admins'] ? $conf['auth']['admins'][0] : null)); -// Now that we are authenticated, we can load Turba's base. Otherwise, the -// share code breaks, causing a new, completely empty share to be created on -// the DataTree with no owner. -require_once TURBA_BASE . '/lib/base.php'; require_once TURBA_BASE . '/lib/Object/Group.php'; // Get list of SquirrelMail address book files diff --git a/turba/scripts/import_squirrelmail_sql_abook.php b/turba/scripts/import_squirrelmail_sql_abook.php index ae8f2f677..298d74431 100755 --- a/turba/scripts/import_squirrelmail_sql_abook.php +++ b/turba/scripts/import_squirrelmail_sql_abook.php @@ -16,8 +16,7 @@ */ // Do CLI checks and environment setup first. -require_once dirname(__FILE__) . '/../lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; // Makre sure no one runs this from the web. if (!Horde_Cli::runningFromCli()) { @@ -37,19 +36,9 @@ if ($argc != 2) { } $dsn = $argv[1]; -// Make sure we load Horde base to get the auth config -$horde_authentication = 'none'; -require_once HORDE_BASE . '/lib/base.php'; -if ($conf['auth']['admins']) { - Horde_Auth::setAuth($conf['auth']['admins'][0], array()); -} +Horde_Registry::appInit('turba', array('authentication' => 'none', 'user' => $conf['auth']['admins'] ? $conf['auth']['admins'][0] : null)); -// Now that we are authenticated, we can load Turba's base. Otherwise, the -// share code breaks, causing a new, completely empty share to be created on -// the DataTree with no owner. -require_once TURBA_BASE . '/lib/base.php'; require_once TURBA_BASE . '/lib/Object/Group.php'; -require_once 'Horde/Mime/Address.php'; // Connect to database. $db = DB::connect($dsn); diff --git a/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php b/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php index aafba7894..edfc05c59 100755 --- a/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php +++ b/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php @@ -33,8 +33,7 @@ $do_email = true; /* YOU SHOULD NOT HAVE TO TOUCH ANYTHING BELOW THIS LINE */ /* Set up the CLI environment */ -require_once dirname(__FILE__) . '/../lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/../../lib/Application.php'; if (!Horde_Cli::runningFromCli()) { exit("Must be run from the command line\n"); } diff --git a/turba/scripts/upgrades/2005-09-23_flat_comments.php b/turba/scripts/upgrades/2005-09-23_flat_comments.php index 6ca31eae7..8c9c83258 100755 --- a/turba/scripts/upgrades/2005-09-23_flat_comments.php +++ b/turba/scripts/upgrades/2005-09-23_flat_comments.php @@ -10,8 +10,7 @@ */ // Do CLI checks and environment setup first. -require_once dirname(__FILE__) . '/../lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; // Make sure no one runs this from the web. if (!Horde_Cli::runningFromCLI()) { @@ -22,15 +21,14 @@ if (!Horde_Cli::runningFromCLI()) { // variables, etc. Horde_Cli::init(); -$turba_authentication = 'none'; -require_once TURBA_BASE . '/lib/base.php'; +Horde_Registry::appInit('turba', array('authentication' => 'none')); // Instantiate DataTree. require_once 'Horde/DataTree.php'; $driver = $conf['datatree']['driver']; $params = array_merge(Horde::getDriverConfig('datatree', $driver), array('group' => 'agora.forums.turba')); -$datatree = &DataTree::singleton($driver, $params); +$datatree = DataTree::singleton($driver, $params); // Load comments. $forums = $datatree->get(DATATREE_FORMAT_TREE, DATATREE_ROOT); diff --git a/turba/scripts/upgrades/2007-06-17_delete_old_vbooks.php b/turba/scripts/upgrades/2007-06-17_delete_old_vbooks.php index 81bb82392..edcd838f0 100755 --- a/turba/scripts/upgrades/2007-06-17_delete_old_vbooks.php +++ b/turba/scripts/upgrades/2007-06-17_delete_old_vbooks.php @@ -6,8 +6,7 @@ */ // Do CLI checks and environment setup first. -require_once dirname(__FILE__) . '/../lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; // Make sure no one runs this from the web. if (!Horde_Cli::runningFromCLI()) { @@ -18,8 +17,7 @@ if (!Horde_Cli::runningFromCLI()) { // some variables, etc. Horde_Cli::init(); -$turba_authentication = 'none'; -require_once TURBA_BASE . '/lib/base.php'; +Horde_Registry::appInit('turba', array('authentication' => 'none')); // Re-load source config. // require TURBA_BASE . '/config/sources.php'; diff --git a/turba/scripts/upgrades/2007-06-17_flatten_shares.php b/turba/scripts/upgrades/2007-06-17_flatten_shares.php index 22be23ad4..46126235c 100755 --- a/turba/scripts/upgrades/2007-06-17_flatten_shares.php +++ b/turba/scripts/upgrades/2007-06-17_flatten_shares.php @@ -6,8 +6,7 @@ */ // Do CLI checks and environment setup first. -require_once dirname(__FILE__) . '/../lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; // Make sure no one runs this from the web. if (!Horde_Cli::runningFromCLI()) { @@ -18,8 +17,7 @@ if (!Horde_Cli::runningFromCLI()) { // some variables, etc. Horde_Cli::init(); -$turba_authentication = 'none'; -require_once TURBA_BASE . '/lib/base.php'; +Horde_Registry::appInit('turba', array('authentication' => 'none')); // Re-load source config. require TURBA_BASE . '/config/sources.php'; diff --git a/turba/scripts/upgrades/convert_datatree_shares_to_sql.php b/turba/scripts/upgrades/convert_datatree_shares_to_sql.php index 4393a7e8c..0aefe9fdf 100755 --- a/turba/scripts/upgrades/convert_datatree_shares_to_sql.php +++ b/turba/scripts/upgrades/convert_datatree_shares_to_sql.php @@ -8,8 +8,7 @@ */ /* Set up the CLI environment */ -require_once dirname(__FILE__) . '/../lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/../../lib/Application.php'; if (!Horde_Cli::runningFromCli()) { exit("Must be run from the command line\n"); } diff --git a/turba/scripts/upgrades/public_to_horde_share.php b/turba/scripts/upgrades/public_to_horde_share.php index 6bc62c309..9374efcaa 100755 --- a/turba/scripts/upgrades/public_to_horde_share.php +++ b/turba/scripts/upgrades/public_to_horde_share.php @@ -19,8 +19,7 @@ */ // Load Horde and Turba enviroments -require_once dirname(__FILE__) . '/../lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/../lib/Application.php'; // Set up the CLI enviroment. if (!Horde_Cli::runningFromCLI()) { @@ -30,16 +29,7 @@ Horde_Cli::init(); $CLI = Horde_Cli::singleton(); // Make sure we load Horde base to get the auth config -$horde_authentication = 'none'; -require_once HORDE_BASE . '/lib/base.php'; -if ($conf['auth']['admins']) { - Horde_Auth::setAuth($conf['auth']['admins'][0], array()); -} - -// Now that we are authenticated, we can load Turba's base. Otherwise, -// the share code breaks, causing a new, completely empty share to be -// created on the DataTree with no owner. -require_once TURBA_BASE . '/lib/base.php'; +Horde_Registry::appInit('turba', array('authentication' => 'none', 'user' => $conf['auth']['admins'] ? $conf['auth']['admins'][0] : null)); $CLI->writeln('This script will turn all entries in the SQL address book into a globally shared address book.'); $CLI->writeln('Make sure you read the script comments and be sure you know what you are doing.'); diff --git a/turba/search.php b/turba/search.php index 3970d2aa7..a039d1b07 100644 --- a/turba/search.php +++ b/turba/search.php @@ -67,7 +67,8 @@ function updateSortOrderFromVars() } } -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); /* Verify if the search mode variable is passed in form or is * registered in the session. Always use basic search by default. */ diff --git a/turba/vcard.php b/turba/vcard.php index 83a410c82..22d1d1753 100644 --- a/turba/vcard.php +++ b/turba/vcard.php @@ -10,7 +10,8 @@ * @author Chuck Hagenbuch */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); $source = Horde_Util::getFormData('source'); if (!isset($cfgSources[$source])) { diff --git a/turba/view.php b/turba/view.php index 954e4594e..0b26104c2 100644 --- a/turba/view.php +++ b/turba/view.php @@ -10,7 +10,8 @@ * @author Jan Schneider */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); if ($conf['documents']['type'] == 'none') { throw new Turba_Exception(_("The VFS backend needs to be configured to enable attachment uploads.")); -- 2.11.0