From f0daa2470ea069c3488276d2ecb1f92c6fdc86b3 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 7 Aug 2009 12:17:37 -0600 Subject: [PATCH] Initial stab at moving base.php code into Application.php Using IMP as a test case. Proposed usage: Every application script directly require_once's Application.php This inits HORDE_BASE and Autoloading. To init app, call new ***_Application(array('init' => $foo)) where $foo is either true or an array of options to pass to init(). lib/base.local.php is now config/horde.local.php --- imp/acl.php | 3 +- imp/ajax.php | 9 ++- imp/attachment.php | 5 +- imp/compose-dimp.php | 3 +- imp/compose-mimp.php | 3 +- imp/compose.php | 4 +- imp/contacts.php | 4 +- imp/fetchmailprefs.php | 3 +- imp/filterprefs.php | 3 +- imp/folders-mimp.php | 3 +- imp/folders.php | 22 +------ imp/index-dimp.php | 3 +- imp/index.php | 3 +- imp/lib/Api.php | 60 ++++++++--------- imp/lib/Application.php | 142 ++++++++++++++++++++++++++++++++++++---- imp/lib/Auth.php | 9 +-- imp/lib/Block/Foldersummary.php | 4 +- imp/lib/Block/Newmail.php | 4 +- imp/lib/Block/summary.php | 4 +- imp/lib/Block/tree_folders.php | 4 +- imp/lib/IMP.php | 2 +- imp/lib/base.load.php | 28 -------- imp/lib/base.php | 89 ------------------------- imp/mailbox-mimp.php | 3 +- imp/mailbox.php | 3 +- imp/message-dimp.php | 3 +- imp/message-mimp.php | 3 +- imp/message.php | 3 +- imp/pgp.php | 3 +- imp/rss.php | 4 +- imp/saveimage.php | 3 +- imp/search.php | 3 +- imp/smime.php | 3 +- imp/stationery.php | 4 +- imp/test.php | 3 +- imp/thread.php | 3 +- imp/view.php | 13 ++-- 37 files changed, 229 insertions(+), 239 deletions(-) delete mode 100644 imp/lib/base.load.php delete mode 100644 imp/lib/base.php diff --git a/imp/acl.php b/imp/acl.php index 4e27e241f..bd8060ed0 100644 --- a/imp/acl.php +++ b/imp/acl.php @@ -12,7 +12,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* 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 a04b59816..69fb06e53 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -148,8 +148,7 @@ function _getQuota() } // Need to load Horde_Util:: to give us access to Horde_Util::getPathInfo(). -require_once dirname(__FILE__) . '/lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; $action = basename(Horde_Util::getPathInfo()); if (empty($action)) { // This is the only case where we really don't return anything, since @@ -160,13 +159,13 @@ if (empty($action)) { // The following actions do not need write access to the session and // should be opened read-only for performance reasons. +$session_control = null; if (in_array($action, array('chunkContent', 'Html2Text', 'Text2Html', 'GetReplyData', 'FetchmailDialog'))) { - $imp_session_control = 'readonly'; + $session_control = 'readonly'; } -$imp_authentication = 'throw'; try { - require_once IMP_BASE . '/lib/base.php'; + new IMP_Application(array('init' => 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 352b341d4..4a976c343 100644 --- a/imp/attachment.php +++ b/imp/attachment.php @@ -16,9 +16,8 @@ // We do not need to be authenticated to get the file. Most users won't send // linked attachments just to other IMP users. -$imp_authentication = 'none'; -$imp_session_control = 'none'; -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => array('authentication' => 'none', 'session_control' => 'none'))); $self_url = Horde::selfUrl(false, true, true); diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index 87ff8b633..7ce03c0a2 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -25,7 +25,8 @@ function _removeAutoSaveDraft($index) } } -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* Determine if compose mode is disabled. */ $compose_disable = !IMP::canCompose(); diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index afa7ab762..efd7af1a2 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -26,7 +26,8 @@ function _getIMPContents($index, $mailbox) } } -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* The message text and headers. */ $msg = ''; diff --git a/imp/compose.php b/imp/compose.php index bf954e6e9..3ce0251f4 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -56,8 +56,8 @@ function _getIMPContents($index, $mailbox) } -$imp_session_control = 'netscape'; -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => array('session_control' => 'netscape'))); /* The message headers and text. */ $header = array(); diff --git a/imp/contacts.php b/imp/contacts.php index fcba21ef3..cb9e562f0 100644 --- a/imp/contacts.php +++ b/imp/contacts.php @@ -10,8 +10,8 @@ * @package IMP */ -$imp_authentication = 'horde'; -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => array('authentication' => 'horde'))); /* Get the lists of address books through the API. */ $source_list = $registry->call('contacts/sources'); diff --git a/imp/fetchmailprefs.php b/imp/fetchmailprefs.php index 07fef9813..b73c2183f 100644 --- a/imp/fetchmailprefs.php +++ b/imp/fetchmailprefs.php @@ -10,7 +10,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* Initialize Fetchmail libraries. */ $fm_account = new IMP_Fetchmail_Account(); diff --git a/imp/filterprefs.php b/imp/filterprefs.php index 38159a4a6..86d81cf55 100644 --- a/imp/filterprefs.php +++ b/imp/filterprefs.php @@ -9,7 +9,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); require_once 'Horde/Prefs/UI.php'; extract(Horde::loadConfiguration('prefs.php', array('prefGroups', '_prefs'), 'imp')); diff --git a/imp/folders-mimp.php b/imp/folders-mimp.php index e4e207085..73e9e57a5 100644 --- a/imp/folders-mimp.php +++ b/imp/folders-mimp.php @@ -16,7 +16,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* 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 9dbb159df..bece3fbd5 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -13,25 +13,9 @@ * @package IMP */ -<<<<<<< Updated upstream -/** - * Utility function to return a url for the various images. - */ -function _image($name, $alt) -{ - static $cache = array(); - - $val = $name['value']; - if (!empty($cache[$val])) { - return $cache[$val]; - } - - $cache[$val] = Horde::img($name['icon'], $name['alt'], null, $name['icondir']); - - return $cache[$val]; -} - -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); +Horde::addScriptFile('folders.js', 'imp', true); /* Redirect back to the mailbox if folder use is not allowed. */ if (!$conf['user']['allow_folders']) { diff --git a/imp/index-dimp.php b/imp/index-dimp.php index b1074e08c..68fc8ef11 100644 --- a/imp/index-dimp.php +++ b/imp/index-dimp.php @@ -12,7 +12,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); $scripts = array( array('ContextSensitive.js', 'imp', true), diff --git a/imp/index.php b/imp/index.php index 9b7bd2d8c..ed36150d2 100644 --- a/imp/index.php +++ b/imp/index.php @@ -10,7 +10,8 @@ */ // Will redirect to login page if not authenticated. -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); // Load initial page as defined by view mode & preferences. require IMP_Auth::getInitialPage(); diff --git a/imp/lib/Api.php b/imp/lib/Api.php index 49eaf66ad..eacc1b13e 100644 --- a/imp/lib/Api.php +++ b/imp/lib/Api.php @@ -51,9 +51,9 @@ class IMP_Api extends Horde_Registry_Api */ public function changeLanguage() { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return; } @@ -113,9 +113,9 @@ class IMP_Api extends Horde_Registry_Api */ public function cacheOutput($params) { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { throw new Horde_Exception('No cache data available'); } @@ -258,8 +258,8 @@ class IMP_Api extends Horde_Registry_Api */ public function prefsStatus() { - $GLOBALS['imp_authentication'] = 'none'; - require_once dirname(__FILE__) . '/base.php'; + require_once dirname(__FILE__) . '/Application.php'; + new IMP_Application(array('init' => array('authentication' => 'none'))); $notification = Horde_Notification::singleton(); $notification->detach('status'); @@ -495,8 +495,8 @@ class IMP_Api extends Horde_Registry_Api */ public function batchCompose($args = array(), $extra = array()) { - $GLOBALS['imp_authentication'] = 'none'; - require_once dirname(__FILE__) . '/base.php'; + require_once dirname(__FILE__) . '/Application.php'; + new IMP_Application(array('init' => array('authentication' => 'none'))); $links = array(); foreach ($args as $i => $arg) { @@ -513,9 +513,9 @@ class IMP_Api extends Horde_Registry_Api */ public function folderlist() { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return false; } @@ -533,9 +533,9 @@ class IMP_Api extends Horde_Registry_Api */ public function createFolder($folder) { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return false; } @@ -555,9 +555,9 @@ class IMP_Api extends Horde_Registry_Api */ public function deleteMessages($mailbox, $indices) { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return false; } @@ -577,9 +577,9 @@ class IMP_Api extends Horde_Registry_Api */ public function copyMessages($mailbox, $indices, $target) { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return false; } @@ -599,9 +599,9 @@ class IMP_Api extends Horde_Registry_Api */ public function moveMessages($mailbox, $indices, $target) { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return false; } @@ -622,9 +622,9 @@ class IMP_Api extends Horde_Registry_Api */ public function flagMessages($mailbox, $indices, $flags, $set) { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return false; } @@ -643,9 +643,9 @@ class IMP_Api extends Horde_Registry_Api */ public function msgEnvelope($mailbox, $indices) { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return false; } @@ -664,9 +664,9 @@ class IMP_Api extends Horde_Registry_Api */ public function searchMailbox($mailbox, $query) { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return false; } @@ -684,9 +684,9 @@ class IMP_Api extends Horde_Registry_Api */ public function mailboxCacheId($mailbox) { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return false; } @@ -708,9 +708,9 @@ class IMP_Api extends Horde_Registry_Api */ public function server() { + require_once dirname(__FILE__) . '/Application.php'; try { - $GLOBALS['imp_authentication'] = 'throw'; - require_once dirname(__FILE__) . '/base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return null; } @@ -736,8 +736,8 @@ class IMP_Api extends Horde_Registry_Api public function favouriteRecipients($limit, $filter = array('new', 'forward', 'reply', 'redirect')) { - $GLOBALS['imp_authentication'] = 'none'; - require_once dirname(__FILE__) . '/base.php'; + require_once dirname(__FILE__) . '/Application.php'; + new IMP_Application(array('init' => array('authentication' => 'none'))); if ($GLOBALS['conf']['sentmail']['driver'] != 'none') { $sentmail = IMP_Sentmail::factory(); diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 82adb972f..c450d488a 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -1,4 +1,26 @@ + * 'init' - (boolean|array) If true, perform application init. If an + * array, perform application init and pass the array to init(). + * */ - public function __construct() + public function __construct($args = array()) { + if (!empty($args['init'])) { + $this->init(is_array($args['init']) ? $args['init'] : array()); + } + /* Only available if admin config is set for this server/login. */ + $this->disabled = array('init'); if (empty($_SESSION['imp']['admin'])) { - $this->disabled = array('authAddUser', 'authRemoveUser', 'authUserList'); + $this->disabled = array_merge($this->disabled, array('authAddUser', 'authRemoveUser', 'authUserList')); + } + } + + /** + * IMP base initialization. + * + * Global variables defined: + * $imp_imap - An IMP_Imap object + * $imp_mbox - Current mailbox information + * $imp_notify - A Horde_Notification_Listener object + * $imp_search - An IMP_Search object + * + * @param array $args Optional arguments: + *
+     * '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
+     * 'no_compress' - (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
+     * 
+ */ + public function init($args = array()) + { + $args = array_merge(array( + 'authentication' => null, + 'nocompress' => false, + 'session_control' => null + ), $args); + + self::$authType = $args['authentication']; + self::$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); + } + + // All other initialization occurs in IMP::initialize(). + IMP::initialize(); } /** @@ -120,8 +245,7 @@ class IMP_Application extends Horde_Registry_Application */ public function authAuthenticate($userId, $credentials) { - $GLOBALS['imp_authentication'] = 'none'; - require_once dirname(__FILE__) . '/base.php'; + $this->init(array('authentication' => 'none')); $new_session = IMP_Auth::authenticate(array( 'password' => $credentials['password'], @@ -149,13 +273,7 @@ class IMP_Application extends Horde_Registry_Application */ public function authTransparent() { - /* Transparent auth is a bit goofy - we most likely have reached this - * code from the pushApp() call in base.php already. As such, some of - * the IMP init has not yet been done, so we need to do the necessary - * init here or else things will fail in IMP_Auth. */ - $GLOBALS['imp_authentication'] = 'none'; - require_once dirname(__FILE__) . '/base.php'; - IMP::initialize(); + $this->init(array('authentication' => 'none')); return IMP_Auth::transparent(); } @@ -167,7 +285,7 @@ class IMP_Application extends Horde_Registry_Application public function authAuthenticateCallback() { if (Horde_Auth::getAuth()) { - require_once dirname(__FILE__) . '/base.php'; + $this->init(); IMP_Auth::authenticateCallback(); } } diff --git a/imp/lib/Auth.php b/imp/lib/Auth.php index 59ffa5689..7c8957616 100644 --- a/imp/lib/Auth.php +++ b/imp/lib/Auth.php @@ -22,13 +22,6 @@ class IMP_Auth static public $prefServer = null; /** - * The auth type to use. - * - * @var string - */ - static public $authType = null; - - /** * Authenticate to the mail server. * * @param array $credentials An array of login credentials. If empty, @@ -46,7 +39,7 @@ class IMP_Auth static public function authenticate($credentials = array()) { // Do 'horde' authentication. - if (self::$authType == 'horde') { + if (IMP_Application::$authType == 'horde') { if (Horde_Auth::getAuth()) { return false; } diff --git a/imp/lib/Block/Foldersummary.php b/imp/lib/Block/Foldersummary.php index 8c7f62d66..e5325b0f0 100644 --- a/imp/lib/Block/Foldersummary.php +++ b/imp/lib/Block/Foldersummary.php @@ -14,9 +14,9 @@ class IMP_Block_Foldersummary extends Horde_Block function _content() { - $GLOBALS['imp_authentication'] = 'throw'; + require_once dirname(__FILE__) . '/../Application.php'; try { - require_once dirname(__FILE__) . '/../base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return; } diff --git a/imp/lib/Block/Newmail.php b/imp/lib/Block/Newmail.php index 3d7179059..6a6ac6a0b 100644 --- a/imp/lib/Block/Newmail.php +++ b/imp/lib/Block/Newmail.php @@ -14,9 +14,9 @@ class IMP_Block_Newmail extends Horde_Block function _content() { - $GLOBALS['imp_authentication'] = 'throw'; + require_once dirname(__FILE__) . '/../Application.php'; try { - require_once dirname(__FILE__) . '/../base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return; } diff --git a/imp/lib/Block/summary.php b/imp/lib/Block/summary.php index 9ab3da351..a2b06fcdc 100644 --- a/imp/lib/Block/summary.php +++ b/imp/lib/Block/summary.php @@ -39,9 +39,9 @@ class Horde_Block_imp_summary extends Horde_Block { global $notification, $prefs, $registry; - $GLOBALS['imp_authentication'] = 'throw'; + require_once dirname(__FILE__) . '/../Application.php'; try { - require_once dirname(__FILE__) . '/../base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return; } diff --git a/imp/lib/Block/tree_folders.php b/imp/lib/Block/tree_folders.php index b0bd677f3..3f97613c6 100644 --- a/imp/lib/Block/tree_folders.php +++ b/imp/lib/Block/tree_folders.php @@ -17,9 +17,9 @@ class Horde_Block_imp_tree_folders extends Horde_Block function _buildTree(&$tree, $indent = 0, $parent = null) { - $GLOBALS['imp_authentication'] = 'throw'; + require_once dirname(__FILE__) . '/../Application.php'; try { - require_once dirname(__FILE__) . '/../base.php'; + new IMP_Application(array('init' => array('authentication' => 'throw'))); } catch (Horde_Exception $e) { return; } diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 495e2351e..569fb775b 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -68,7 +68,7 @@ class IMP } // Start compression. - if (!Horde_Util::nonInputVar('imp_no_compress')) { + if (IMP_Application::$noCompress) { Horde::compressOutput(); } diff --git a/imp/lib/base.load.php b/imp/lib/base.load.php deleted file mode 100644 index d7b1de949..000000000 --- a/imp/lib/base.load.php +++ /dev/null @@ -1,28 +0,0 @@ - - * $imp_authentication - 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 - * $imp_no_compress - Controls whether the page should be compressed - * $imp_session_control - 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 - * - * - * Global variables defined: - * $imp_imap - An IMP_Imap object - * $imp_mbox - Current mailbox information - * $imp_notify - A Horde_Notification_Listener object - * $imp_search - An IMP_Search object - * - * Copyright 1999-2009 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (GPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. - * - * @package IMP - */ - -// Determine BASE directories. -require_once dirname(__FILE__) . '/base.load.php'; - -// Load the Horde Framework core. -require_once HORDE_BASE . '/lib/core.php'; - -// Registry. -$s_ctrl = 0; -switch (Horde_Util::nonInputVar('imp_session_control')) { -case 'netscape': - if ($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; -} -$registry = Horde_Registry::singleton($s_ctrl); - -// Determine imp authentication type. -$authentication = Horde_Util::nonInputVar('imp_authentication'); -if ($authentication == 'horde') { - // Autoloading for imp is not set until pushApp(), so need to add lib - // path here explicitly. - Horde_Autoloader::addClassPattern('/^IMP(?:$|_)/i', IMP_BASE . '/lib'); - IMP_Auth::$authType = 'horde'; -} - -try { - $registry->pushApp('imp', array('check_perms' => ($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 ($authentication == 'throw') { - throw $e; - } - } - - Horde_Auth::authenticateFailure('imp', $e); -} - -// All other initialization occurs in IMP::initialize(). -IMP::initialize(); diff --git a/imp/mailbox-mimp.php b/imp/mailbox-mimp.php index a78fbd366..c125c2ae4 100644 --- a/imp/mailbox-mimp.php +++ b/imp/mailbox-mimp.php @@ -20,7 +20,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* Determine if mailbox is readonly. */ $readonly = $imp_imap->isReadOnly($imp_mbox['mailbox']); diff --git a/imp/mailbox.php b/imp/mailbox.php index 6f9a18951..0087a66f6 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -38,7 +38,8 @@ function _outputSummaries($msgs) } -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* Call the mailbox redirection hook, if requested. */ try { diff --git a/imp/message-dimp.php b/imp/message-dimp.php index 87d8c2c0d..757ace4cd 100644 --- a/imp/message-dimp.php +++ b/imp/message-dimp.php @@ -10,7 +10,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); $folder = Horde_Util::getFormData('folder'); $index = Horde_Util::getFormData('uid'); diff --git a/imp/message-mimp.php b/imp/message-mimp.php index 2fdc135ab..a31245e93 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -18,7 +18,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* Make sure we have a valid index. */ $imp_mailbox = IMP_Mailbox::singleton($imp_mbox['mailbox'], $imp_mbox['index']); diff --git a/imp/message.php b/imp/message.php index d647f9760..7b061c4a5 100644 --- a/imp/message.php +++ b/imp/message.php @@ -26,7 +26,8 @@ function _moveAfterAction() !$GLOBALS['prefs']->getValue('use_trash')); } -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => 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 664ba6b93..94b3b5ed1 100644 --- a/imp/pgp.php +++ b/imp/pgp.php @@ -70,7 +70,8 @@ function _reloadWindow() Horde_Util::closeWindowJS('opener.focus();opener.location.href="' . $href . '";'); } -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); $imp_pgp = Horde_Crypt::singleton(array('IMP', 'Pgp')); $secure_check = Horde::isConnectionSecure(); diff --git a/imp/rss.php b/imp/rss.php index 357ea59ca..fa210568b 100644 --- a/imp/rss.php +++ b/imp/rss.php @@ -9,9 +9,9 @@ * @package IMP */ -$imp_authentication = 'throw'; +require_once dirname(__FILE__) . '/lib/Application.php'; try { - require_once dirname(__FILE__) . '/lib/base.php'; + new IMP_Application(array('init' => 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 d0f8251fd..8d2c6a162 100644 --- a/imp/saveimage.php +++ b/imp/saveimage.php @@ -9,7 +9,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); $id = Horde_Util::getFormData('id'); $index = Horde_Util::getFormData('index'); diff --git a/imp/search.php b/imp/search.php index 0b46a81c9..e6159411d 100644 --- a/imp/search.php +++ b/imp/search.php @@ -18,7 +18,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* Load mailbox page if searching is not allowed. */ if ($_SESSION['imp']['protocol'] == 'pop') { diff --git a/imp/smime.php b/imp/smime.php index 5113afd07..0106510ee 100644 --- a/imp/smime.php +++ b/imp/smime.php @@ -80,7 +80,8 @@ function _printKeyInfo($cert) } -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); $imp_smime = Horde_Crypt::singleton(array('IMP', 'Smime')); $secure_check = Horde::isConnectionSecure(); diff --git a/imp/stationery.php b/imp/stationery.php index b667bc6da..3d894011a 100644 --- a/imp/stationery.php +++ b/imp/stationery.php @@ -9,8 +9,8 @@ * @package IMP */ -$imp_authentication = 'horde'; -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => array('authentication' => 'horde'))); require_once 'Horde/Prefs/UI.php'; $compose_url = Horde::getServiceLink('options', 'imp'); diff --git a/imp/test.php b/imp/test.php index 671bcd269..e5a4400e4 100644 --- a/imp/test.php +++ b/imp/test.php @@ -100,8 +100,7 @@ function _errorMsg($e) /* Include Horde's core.php file. */ -require_once dirname(__FILE__) . '/lib/base.load.php'; -include_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; /* We should have loaded the Horde_String class, from the Horde_Util * package, in core.php. If Horde_String:: isn't defined, then we're not diff --git a/imp/thread.php b/imp/thread.php index 870f75346..aa9224c8a 100644 --- a/imp/thread.php +++ b/imp/thread.php @@ -9,7 +9,8 @@ * @package IMP */ -require_once dirname(__FILE__) . '/lib/base.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; +new IMP_Application(array('init' => true)); /* What mode are we in? * DEFAULT/'thread' - Thread mode diff --git a/imp/view.php b/imp/view.php index 4577f2bba..bcb81392e 100644 --- a/imp/view.php +++ b/imp/view.php @@ -45,17 +45,14 @@ function _fullMessageTextLength($ob) return $len; } -require_once dirname(__FILE__) . '/lib/base.load.php'; -require_once HORDE_BASE . '/lib/core.php'; +require_once dirname(__FILE__) . '/lib/Application.php'; /* Don't compress if we are already sending in compressed format. */ $actionID = Horde_Util::getFormData('actionID'); -if (($actionID == 'download_all') || Horde_Util::getFormData('zip')) { - $imp_no_compress = true; -} - -$imp_session_control = 'readonly'; -require_once dirname(__FILE__) . '/lib/base.php'; +new IMP_Application(array('init' => array( + 'session_control' => 'readonly', + 'nocompress' => (($actionID == 'download_all') || Horde_Util::getFormData('zip')) +))); $ctype = Horde_Util::getFormData('ctype'); $id = Horde_Util::getFormData('id'); -- 2.11.0