IMP can now be initialized from the 'init' arg to pushApp()
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 30 Nov 2009 23:41:24 +0000 (16:41 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 30 Nov 2009 23:50:38 +0000 (16:50 -0700)
imp/lib/Application.php
imp/lib/IMP.php
imp/lib/LoginTasks/SystemTask/GarbageCollection.php
imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php
imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php
imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php
imp/lib/LoginTasks/Task/PurgeSentmail.php
imp/lib/LoginTasks/Task/PurgeSpam.php
imp/lib/LoginTasks/Task/PurgeTrash.php
imp/lib/LoginTasks/Task/RenameSentmailMonthly.php

index 0ebbcd5..2dd6d9d 100644 (file)
@@ -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:
      * <pre>
      * '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.
      * </pre>
      */
     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
      * </pre>
      */
-    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;
         }
index 4eb20b8..4107d04 100644 (file)
@@ -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.
      *
index eba564e..167f30d 100644 (file)
@@ -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);
index c47b2d0..5c3265b 100644 (file)
@@ -24,8 +24,6 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT
      */
     public function execute()
     {
-        IMP::initialize();
-
         $this->_upgradeSortPrefs();
         $this->_upgradeVirtualFolders();
     }
index 50802a4..46bfde3 100644 (file)
@@ -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'));
index 506bfa8..91f334b 100644 (file)
@@ -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. */
index 8eeea7c..21fb59b 100644 (file)
@@ -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."),
index aaa4b1a..3401ed0 100644 (file)
@@ -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'));
index 80a2ec1..e428b87 100644 (file)
@@ -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'));
index 0e73e78..7d3f5a5 100644 (file)
@@ -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();