From 3b9e557766e0dec35f26b4038125aa8be1cd9f34 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 30 Nov 2009 16:41:24 -0700 Subject: [PATCH] IMP can now be initialized from the 'init' arg to pushApp() --- imp/lib/Application.php | 96 +++++++++++++++++----- imp/lib/IMP.php | 55 ------------- .../LoginTasks/SystemTask/GarbageCollection.php | 2 - imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php | 2 - .../LoginTasks/Task/DeleteAttachmentsMonthly.php | 2 - imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php | 2 - imp/lib/LoginTasks/Task/PurgeSentmail.php | 4 - imp/lib/LoginTasks/Task/PurgeSpam.php | 4 - imp/lib/LoginTasks/Task/PurgeTrash.php | 4 - imp/lib/LoginTasks/Task/RenameSentmailMonthly.php | 4 - 10 files changed, 75 insertions(+), 100 deletions(-) diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 0ebbcd50d..2dd6d9d6c 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -47,18 +47,18 @@ class IMP_Application extends Horde_Registry_Application public $version = 'H4 (5.0-git)'; /** - * The auth type to use. + * Disable compression of pages? * - * @var string + * @var boolean */ - static public $authType = null; + protected $noCompress = false; /** - * Disable compression of pages? + * The auth type to use. * - * @var boolean + * @var string */ - static public $noCompress = false; + static public $authType = null; /** * Cached data for prefs pages. @@ -68,19 +68,27 @@ class IMP_Application extends Horde_Registry_Application static public $prefsCache = array(); /** + * Has init previously been called? + * + * @var boolean + */ + static protected $_init = false; + + /** * Constructor. * * @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 init().
+     *          array, perform application init and pass the array to
+     *          self::_impInit().
      * 'tz' - (boolean) If true, sets the current time zone on the server.
      * 
*/ public function __construct($args = array()) { if (!empty($args['init'])) { - $this->init(is_array($args['init']) ? $args['init'] : array()); + $this->_impInit(is_array($args['init']) ? $args['init'] : array()); } if (!empty($args['tz'])) { @@ -88,7 +96,6 @@ class IMP_Application extends Horde_Registry_Application } /* Only available if admin config is set for this server/login. */ - $this->disabled = array('init'); if (empty($_SESSION['imp']['admin'])) { $this->disabled = array_merge($this->disabled, array('authAddUser', 'authRemoveUser', 'authUserList')); } @@ -121,7 +128,7 @@ class IMP_Application extends Horde_Registry_Application * [DEFAULT] - Start read/write session * */ - public function init($args = array()) + protected function _impInit($args = array()) { $args = array_merge(array( 'authentication' => null, @@ -130,7 +137,7 @@ class IMP_Application extends Horde_Registry_Application ), $args); self::$authType = $args['authentication']; - self::$noCompress = $args['nocompress']; + $this->_noCompress = $args['nocompress']; // Registry. $s_ctrl = 0; @@ -168,8 +175,59 @@ class IMP_Application extends Horde_Registry_Application Horde_Auth::authenticateFailure('imp', $e); } - // All other initialization occurs in IMP::initialize(). - IMP::initialize(); + $this->init(); + } + + /** + * Initialization function. + */ + public function init() + { + if (self::$_init) { + return; + } + + if (!defined('IMP_TEMPLATES')) { + $registry = Horde_Registry::singleton(); + 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(); + } + + // Initialize some message parsing variables. + Horde_Mime::$brokenRFC2231 = !empty($GLOBALS['conf']['mailformat']['brokenrfc2231']); + + // Set default message character set, if necessary + if ($def_charset = $GLOBALS['prefs']->getValue('default_msg_charset')) { + Horde_Mime_Part::$defaultCharset = $def_charset; + Horde_Mime_Headers::$defaultCharset = $def_charset; + } + + $GLOBALS['notification'] = Horde_Notification::singleton(); + $viewmode = IMP::getViewMode(); + + if ($viewmode == 'mimp') { + $GLOBALS['imp_notify'] = $GLOBALS['notification']->attach('status', null, 'IMP_Notification_Listener_StatusMobile'); + } else { + $GLOBALS['imp_notify'] = $GLOBALS['notification']->attach('status', array('viewmode' => $viewmode), 'IMP_Notification_Listener_Status'); + if ($viewmode == 'imp') { + $GLOBALS['notification']->attach('audio'); + } + } + + // Initialize global $imp_mbox array. This call also initializes the + // IMP_Search object. + IMP::setCurrentMailboxInfo(); + + self::$_init = true; } /* Horde permissions. */ @@ -327,7 +385,7 @@ class IMP_Application extends Horde_Registry_Application */ public function authAuthenticate($userId, $credentials) { - $this->init(array('authentication' => 'none')); + $this->_impInit(array('authentication' => 'none')); $new_session = IMP_Auth::authenticate(array( 'password' => $credentials['password'], @@ -353,7 +411,7 @@ class IMP_Application extends Horde_Registry_Application */ public function authTransparent($auth_ob) { - $this->init(array('authentication' => 'none')); + $this->_impInit(array('authentication' => 'none')); return IMP_Auth::transparent($auth_ob); } @@ -365,7 +423,7 @@ class IMP_Application extends Horde_Registry_Application public function authAuthenticateCallback() { if (Horde_Auth::getAuth()) { - $this->init(); + $this->_impInit(); IMP_Auth::authenticateCallback(); } } @@ -448,10 +506,6 @@ class IMP_Application extends Horde_Registry_Application */ public function prefsInit($group) { - /* TODO: Remove once Horde_Registry_Application calling is figured - * out and pushApp:load_base works again. */ - IMP::initialize(); - /* Add necessary javascript files here (so they are added to the * document HEAD). */ switch ($group) { @@ -984,7 +1038,7 @@ class IMP_Application extends Horde_Registry_Application public function changeLanguage() { try { - $this->init(array('authentication' => 'throw')); + $this->_impInit(array('authentication' => 'throw')); } catch (Horde_Exception $e) { return; } diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 4eb20b869..4107d0415 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -50,61 +50,6 @@ class IMP /* prepareMenu() cache. */ static private $_menuTemplate = null; - /* Has init previously been called? */ - static private $_init = false; - - /** - * Performs IMP initialization. - */ - static public function initialize() - { - if (self::$_init) { - return; - } - - if (!defined('IMP_TEMPLATES')) { - $registry = Horde_Registry::singleton(); - define('IMP_TEMPLATES', $registry->get('templates')); - } - - // Start compression. - if (!IMP_Application::$noCompress) { - Horde::compressOutput(); - } - - // Initialize global $imp_imap object. - if (!isset($GLOBALS['imp_imap'])) { - $GLOBALS['imp_imap'] = new IMP_Imap(); - } - - // Initialize some message parsing variables. - Horde_Mime::$brokenRFC2231 = !empty($GLOBALS['conf']['mailformat']['brokenrfc2231']); - - // Set default message character set, if necessary - if ($def_charset = $GLOBALS['prefs']->getValue('default_msg_charset')) { - Horde_Mime_Part::$defaultCharset = $def_charset; - Horde_Mime_Headers::$defaultCharset = $def_charset; - } - - $GLOBALS['notification'] = Horde_Notification::singleton(); - $viewmode = self::getViewMode(); - - if ($viewmode == 'mimp') { - $GLOBALS['imp_notify'] = $GLOBALS['notification']->attach('status', null, 'IMP_Notification_Listener_StatusMobile'); - } else { - $GLOBALS['imp_notify'] = $GLOBALS['notification']->attach('status', array('viewmode' => $viewmode), 'IMP_Notification_Listener_Status'); - if ($viewmode == 'imp') { - $GLOBALS['notification']->attach('audio'); - } - } - - // Initialize global $imp_mbox array. This call also initializes the - // IMP_Search object. - IMP::setCurrentMailboxInfo(); - - self::$_init = true; - } - /** * Returns the current view mode for IMP. * diff --git a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php index eba564ec8..167f30d9d 100644 --- a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php +++ b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php @@ -24,8 +24,6 @@ class IMP_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_Syste */ public function execute() { - IMP::initialize(); - /* Purge non-existent nav_poll entries. */ $imaptree = IMP_Imap_Tree::singleton(); $imaptree->getPollList(true, true); diff --git a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php index c47b2d05f..5c3265bf4 100644 --- a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php +++ b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php @@ -24,8 +24,6 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT */ public function execute() { - IMP::initialize(); - $this->_upgradeSortPrefs(); $this->_upgradeVirtualFolders(); } diff --git a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php index 50802a4ac..46bfde39e 100644 --- a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php +++ b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php @@ -29,8 +29,6 @@ class IMP_LoginTasks_Task_DeleteAttachmentsMonthly extends Horde_LoginTasks_Task */ public function execute() { - IMP::initialize(); - /* Find the UNIX timestamp of the last second that we will not * purge. */ $del_time = gmmktime(0, 0, 0, date('n') - $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'), 1, date('Y')); diff --git a/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php b/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php index 506bfa896..91f334b0c 100644 --- a/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php +++ b/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php @@ -31,8 +31,6 @@ class IMP_LoginTasks_Task_DeleteSentmailMonthly extends Horde_LoginTasks_Task */ public function execute() { - IMP::initialize(); - /* Get list of all folders, parse through and get the list of all old sent-mail folders. Then sort this array according to the date. */ diff --git a/imp/lib/LoginTasks/Task/PurgeSentmail.php b/imp/lib/LoginTasks/Task/PurgeSentmail.php index 8eeea7c62..21fb59bf0 100644 --- a/imp/lib/LoginTasks/Task/PurgeSentmail.php +++ b/imp/lib/LoginTasks/Task/PurgeSentmail.php @@ -35,8 +35,6 @@ class IMP_LoginTasks_Task_PurgeSentmail extends Horde_LoginTasks_Task */ public function execute() { - IMP::initialize(); - $imp_folder = IMP_Folder::singleton(); $imp_message = IMP_Message::singleton(); @@ -84,8 +82,6 @@ class IMP_LoginTasks_Task_PurgeSentmail extends Horde_LoginTasks_Task */ public function describe() { - IMP::initialize(); - $mbox_list = array_map(array('IMP', 'displayFolder'), $this->_getFolders()); return sprintf(_("All messages in the folder(s) \"%s\" older than %s days will be permanently deleted."), diff --git a/imp/lib/LoginTasks/Task/PurgeSpam.php b/imp/lib/LoginTasks/Task/PurgeSpam.php index aaa4b1aa1..3401ed0e5 100644 --- a/imp/lib/LoginTasks/Task/PurgeSpam.php +++ b/imp/lib/LoginTasks/Task/PurgeSpam.php @@ -34,8 +34,6 @@ class IMP_LoginTasks_Task_PurgeSpam extends Horde_LoginTasks_Task */ public function execute() { - IMP::initialize(); - /* If there is no Spam folder set, just return. */ $spam_folder = IMP::folderPref($GLOBALS['prefs']->getValue('spam_folder'), true); if (!$spam_folder) { @@ -79,8 +77,6 @@ class IMP_LoginTasks_Task_PurgeSpam extends Horde_LoginTasks_Task */ public function describe() { - IMP::initialize(); - return sprintf(_("All messages in your \"%s\" folder older than %s days will be permanently deleted."), IMP::displayFolder(IMP::folderPref($GLOBALS['prefs']->getValue('spam_folder'), true)), $GLOBALS['prefs']->getValue('purge_spam_keep')); diff --git a/imp/lib/LoginTasks/Task/PurgeTrash.php b/imp/lib/LoginTasks/Task/PurgeTrash.php index 80a2ec1f6..e428b87bc 100644 --- a/imp/lib/LoginTasks/Task/PurgeTrash.php +++ b/imp/lib/LoginTasks/Task/PurgeTrash.php @@ -33,8 +33,6 @@ class IMP_LoginTasks_Task_PurgeTrash extends Horde_LoginTasks_Task */ public function execute() { - IMP::initialize(); - /* If we aren't using a Trash folder or if there is no Trash folder set, just return. */ $trash_folder = IMP::folderPref($GLOBALS['prefs']->getValue('trash_folder'), true); @@ -79,8 +77,6 @@ class IMP_LoginTasks_Task_PurgeTrash extends Horde_LoginTasks_Task */ public function describe() { - IMP::initialize(); - return sprintf(_("All messages in your \"%s\" folder older than %s days will be permanently deleted."), IMP::displayFolder(IMP::folderPref($GLOBALS['prefs']->getValue('trash_folder'), true)), $GLOBALS['prefs']->getValue('purge_trash_keep')); diff --git a/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php b/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php index 0e73e7870..7d3f5a544 100644 --- a/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php +++ b/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php @@ -31,8 +31,6 @@ class IMP_LoginTasks_Task_RenameSentmailMonthly extends Horde_LoginTasks_Task */ public function execute() { - IMP::initialize(); - $success = true; $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp')); @@ -66,8 +64,6 @@ class IMP_LoginTasks_Task_RenameSentmailMonthly extends Horde_LoginTasks_Task */ public function describe() { - IMP::initialize(); - $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp')); $new_folders = $old_folders = array(); -- 2.11.0