Initial stab at moving base.php code into Application.php
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 7 Aug 2009 18:17:37 +0000 (12:17 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 11 Aug 2009 18:48:19 +0000 (12:48 -0600)
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

37 files changed:
imp/acl.php
imp/ajax.php
imp/attachment.php
imp/compose-dimp.php
imp/compose-mimp.php
imp/compose.php
imp/contacts.php
imp/fetchmailprefs.php
imp/filterprefs.php
imp/folders-mimp.php
imp/folders.php
imp/index-dimp.php
imp/index.php
imp/lib/Api.php
imp/lib/Application.php
imp/lib/Auth.php
imp/lib/Block/Foldersummary.php
imp/lib/Block/Newmail.php
imp/lib/Block/summary.php
imp/lib/Block/tree_folders.php
imp/lib/IMP.php
imp/lib/base.load.php [deleted file]
imp/lib/base.php [deleted file]
imp/mailbox-mimp.php
imp/mailbox.php
imp/message-dimp.php
imp/message-mimp.php
imp/message.php
imp/pgp.php
imp/rss.php
imp/saveimage.php
imp/search.php
imp/smime.php
imp/stationery.php
imp/test.php
imp/thread.php
imp/view.php

index 4e27e24..bd8060e 100644 (file)
@@ -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');
index a04b598..69fb06e 100644 (file)
@@ -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) {
index 352b341..4a976c3 100644 (file)
@@ -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);
 
index 87ff8b6..7ce03c0 100644 (file)
@@ -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();
index afa7ab7..efd7af1 100644 (file)
@@ -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 = '';
index bf954e6..3ce0251 100644 (file)
@@ -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();
index fcba21e..cb9e562 100644 (file)
@@ -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');
index 07fef98..b73c218 100644 (file)
@@ -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();
index 38159a4..86d81cf 100644 (file)
@@ -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'));
index e4e2070..73e9e57 100644 (file)
@@ -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'])) {
index 9dbb159..bece3fb 100644 (file)
  * @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']) {
index b1074e0..68fc8ef 100644 (file)
@@ -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),
index 9b7bd2d..ed36150 100644 (file)
@@ -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();
index 49eaf66..eacc1b1 100644 (file)
@@ -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();
index 82adb97..c450d48 100644 (file)
@@ -1,4 +1,26 @@
 <?php
+
+/* Determine the base directories. */
+$curr_dir = dirname(__FILE__);
+
+if (!defined('IMP_BASE')) {
+    define('IMP_BASE', $curr_dir . '/..');
+}
+
+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(IMP_BASE . '/config/horde.local.php')) {
+        include IMP_BASE . '/config/horde.local.php';
+    } else {
+        define('HORDE_BASE', $curr_dir . '/../..');
+    }
+}
+
+/* Load the Horde Framework core (needed to autoload
+ * Horde_Registry_Application::). */
+require_once HORDE_BASE . '/lib/core.php';
+
 /**
  * IMP application API.
  *
@@ -27,14 +49,117 @@ class IMP_Application extends Horde_Registry_Application
     public $version = 'H4 (5.0-git)';
 
     /**
+     * The auth type to use.
+     *
+     * @var string
+     */
+    static public $authType = null;
+
+    /**
+     * Disable compression of pages?
+     *
+     * @var boolean
+     */
+    static public $noCompress = 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().
+     * </pre>
      */
-    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:
+     * <pre>
+     * '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
+     * </pre>
+     */
+    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();
         }
     }
index 59ffa56..7c89576 100644 (file)
@@ -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;
             }
index 8c7f62d..e5325b0 100644 (file)
@@ -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;
         }
index 3d71790..6a6ac6a 100644 (file)
@@ -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;
         }
index 9ab3da3..a2b06fc 100644 (file)
@@ -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;
         }
index b0bd677..3f97613 100644 (file)
@@ -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;
         }
index 495e235..569fb77 100644 (file)
@@ -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 (file)
index d7b1de9..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-/**
- * Script to determine the correct *_BASE values.
- *
- * Copyright 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
- */
-
-$curr_dir = dirname(__FILE__);
-
-if (!defined('HORDE_BASE')) {
-    /* Temporary fix - if horde does not live directly under the app
-     * directory, the HORDE_BASE constant should be defined in
-     * lib/base.local.php. */
-    if (file_exists($curr_dir . '/base.local.php')) {
-        include $curr_dir . '/base.local.php';
-    } else {
-        define('HORDE_BASE', $curr_dir . '/../..');
-    }
-}
-
-if (!defined('IMP_BASE')) {
-    define('IMP_BASE', $curr_dir . '/..');
-}
diff --git a/imp/lib/base.php b/imp/lib/base.php
deleted file mode 100644 (file)
index ad72db9..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-/**
- * IMP base inclusion file. This file brings in all of the dependencies that
- * every IMP script will need, and sets up objects that all scripts use.
- *
- * The following global variables are used:
- * <pre>
- * $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
- * </pre>
- *
- * 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();
index a78fbd3..c125c2a 100644 (file)
@@ -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']);
index 6f9a189..0087a66 100644 (file)
@@ -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 {
index 87d8c2c..757ace4 100644 (file)
@@ -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');
index 2fdc135..a31245e 100644 (file)
@@ -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']);
index d647f97..7b061c4 100644 (file)
@@ -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
index 664ba6b..94b3b5e 100644 (file)
@@ -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();
index 357ea59..fa21056 100644 (file)
@@ -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"');
index d0f8251..8d2c6a1 100644 (file)
@@ -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');
index 0b46a81..e615941 100644 (file)
@@ -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') {
index 5113afd..0106510 100644 (file)
@@ -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();
index b667bc6..3d89401 100644 (file)
@@ -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');
index 671bcd2..e5a4400 100644 (file)
@@ -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
index 870f753..aa9224c 100644 (file)
@@ -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
index 4577f2b..bcb8139 100644 (file)
@@ -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');