Cache output handling has moved to Horde
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 17 Jul 2009 18:07:33 +0000 (12:07 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 17 Jul 2009 18:07:33 +0000 (12:07 -0600)
imp/cache.php [deleted file]
imp/lib/IMP.php
imp/lib/UI/Compose.php
imp/lib/api.php

diff --git a/imp/cache.php b/imp/cache.php
deleted file mode 100644 (file)
index 12eafae..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/**
- * Cached data output script.
- *
- * Parameters in (via PATH_INFO):
- *   1st parameter = The type of content to output ('css', 'fckeditor', 'js')
- *   2nd parameter = Cache ID
- *
- * Copyright 2007-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package IMP
- */
-
-/* The amount of time (in minutes) to cache the generated CSS and JS files.
- * DEFAULT: 525600 = 1 year */
-$expire_time = 525600;
-
-// 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';
-$path_info = trim(Horde_Util::getPathInfo(), '/');
-if (empty($path_info)) {
-    exit;
-}
-
-// 'fckeditor' output won't have a second slash, so ignore errors
-$old_error = error_reporting(0);
-list($type, $cid) = explode('/', $path_info, 2);
-error_reporting($old_error);
-
-/* Allow CSS and JS caches to be cached on the browser since there is no
- * dynamic code that will change over the course of a session. Can't cache
- * fckeditor setting as it may change. Only authenticate for 'fckeditor'
- * actions (for access to user's prefs). */
-if ($type == 'fckeditor') {
-    $session_cache_limiter = 'nocache';
-} else {
-    $session_cache_limiter = 'public';
-    session_cache_expire($expire_time);
-    @define('AUTH_HANDLER', true);
-    $authentication = 'none';
-}
-$session_control = 'readonly';
-$session_timeout = 'none';
-require_once IMP_BASE . '/lib/base.php';
-
-switch ($type) {
-case 'css':
-    $type = 'text/css';
-    $lifetime = (empty($GLOBALS['conf']['server']['cachecssparams']['lifetime'])) ? 0 : $GLOBALS['conf']['server']['cachecssparams']['lifetime'];
-    break;
-
-case 'fckeditor':
-    header('Content-Type: text/javascript');
-    echo 'FCKConfig.ToolbarSets["ImpToolbar"] = ' . $GLOBALS['prefs']->getValue('fckeditor_buttons') . ';' . "\n" .
-        // To more closely match "normal" textarea behavior, send <BR> on
-        // enter instead of <P>.
-        'FCKConfig.EnterMode = \'br\';' . "\n" .
-        'FCKConfig.ShiftEnterMode = \'p\';';
-    exit;
-
-case 'js':
-    $type = 'text/javascript';
-    $lifetime = (empty($GLOBALS['conf']['server']['cachejsparams']['lifetime'])) ? 0 : $GLOBALS['conf']['server']['cachejsparams']['lifetime'];
-    break;
-
-default:
-    exit;
-}
-
-if (empty($cid)) {
-    exit;
-}
-
-if (!($cache = IMP::getCache())) {
-    Horde::fatal(new Horde_Exception('No cache backend available.'));
-}
-
-// If cache info doesn't exist, just output an empty body.
-header('Content-Type: ' . $type);
-$cache->output($cid, $lifetime);
index a49d004..103aa39 100644 (file)
@@ -1354,8 +1354,9 @@ class IMP
             break;
 
         case 'horde_cache':
+            // Do lifetime checking here, not on cache display page.
             $exists = $cache->exists($sig, empty($conf['server']['cachejsparams']['lifetime']) ? 0 : $conf['server']['cachejsparams']['lifetime']);
-            $js_url = self::getCacheURL('js', $sig);
+            $js_url = Horde::getCacheUrl('js', array('cid' => $sig));
             break;
         }
 
@@ -1391,25 +1392,6 @@ class IMP
     }
 
     /**
-     * Creates a URL for cached IMP data.
-     *
-     * @param string $type  The cache type.
-     * @param string $cid   The cache id.
-     *
-     * @return string  The URL to the cache page.
-     */
-    static public function getCacheURL($type, $cid)
-    {
-        $parts = array(
-            $GLOBALS['registry']->get('webroot', 'imp'),
-            'cache.php',
-            $type,
-            $cid
-        );
-        return Horde::url(implode('/', $parts));
-    }
-
-    /**
      * Outputs the necessary style tags, honoring local configuration
      * choices as to stylesheet caching.
      *
@@ -1466,8 +1448,9 @@ class IMP
                 break;
 
             case 'horde_cache':
+                // Do lifetime checking here, not on cache display page.
                 $exists = $cache->exists($sig, empty($GLOBALS['conf']['server']['cachecssparams']['lifetime']) ? 0 : $GLOBALS['conf']['server']['cachecssparams']['lifetime']);
-                $css_url = self::getCacheURL('css', $sig);
+                $css_url = Horde::getCacheUrl('css', array('cid' => $sig));
                 break;
             }
 
index 8d552c1..a72da07 100644 (file)
@@ -182,7 +182,9 @@ class IMP_UI_Compose
         $fck_buttons = $GLOBALS['prefs']->getValue('fckeditor_buttons');
         if (!empty($fck_buttons)) {
             $js_onload = array(
-                'oFCKeditor.Config.CustomConfigurationsPath = "' . IMP::getCacheURL('fckeditor', null) . '"',
+                // This needs to work even if Horde_Cache is not available,
+                // so need to use app-specific cache output.
+                'oFCKeditor.Config.CustomConfigurationsPath = "' . Horde::getCacheUrl('app', array('app' => 'imp', 'id' => 'fckeditor')) . '"',
                 'oFCKeditor.ToolbarSet = "ImpToolbar"'
             );
             if ($mode == 'imp') {
index aa1c11a..4b463cc 100644 (file)
@@ -124,6 +124,15 @@ $_services = array_merge($_services, array(
         'type' => 'boolean'
     ),
 
+    /* Cache display method. */
+    'cacheOutput' => array(
+        'args' => array(
+            '{urn:horde}hashHash'
+        ),
+        'type' => '{urn:horde}hashHash'
+    ),
+
+    /* Horde_Auth_Application method. */
     'authAuthenticate' => array(
         'args' => array(
             'userID' => 'string',
@@ -517,6 +526,37 @@ function _imp_changeLanguage()
 }
 
 /**
+ * Application-specific cache output driver.
+ *
+ * @param array $params  A list of params needed (USED: 'id').
+ *
+ * @return array  See Horde::getCacheUrl().
+ * @throws Horde_Exception
+ */
+function _imp_cacheOutput($params)
+{
+    $GLOBALS['authentication'] = 'none';
+    require_once dirname(__FILE__) . '/base.php';
+
+    if (IMP::checkAuthentication(true)) {
+        switch ($params['id']) {
+        case 'fckeditor':
+            return array(
+                'data' =>
+                     'FCKConfig.ToolbarSets["ImpToolbar"] = ' . $GLOBALS['prefs']->getValue('fckeditor_buttons') . ';' . "\n" .
+                     // To more closely match "normal" textarea behavior,
+                     // send <BR> on enter instead of <P>.
+                     'FCKConfig.EnterMode = \'br\';' . "\n" .
+                     'FCKConfig.ShiftEnterMode = \'p\';',
+                'type' => 'text/javascript'
+            );
+        }
+    }
+
+    throw new Horde_Exception('No cache data available');
+}
+
+/**
  * Tries to authenticate with the mail server and create a mail session.
  *
  * @param string $userID      The username of the user.