File: cache.php

package info (click to toggle)
imp4 4.2-4lenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,252 kB
  • ctags: 5,316
  • sloc: php: 21,340; xml: 19,302; makefile: 68; sql: 14
file content (85 lines) | stat: -rw-r--r-- 2,794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?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
 *
 * $Horde: imp/cache.php,v 1.3.2.7 2008/05/06 17:54:04 slusarz Exp $
 *
 * Copyright 2007-2008 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>
 */

/* The amount of time (in minutes) to cache the generated CSS and JS files.
 * DEFAULT: 525600 = 1 year */
$expire_time = 525600;

/* Load IMP.php to access IMP::getPathInfo(). */
@define('IMP_BASE', dirname(__FILE__));
require_once IMP_BASE . '/lib/IMP.php';
$path_info = trim(IMP::getPathInfo(), '/');
if (empty($path_info)) {
    exit;
}
list($type, $cid) = explode('/', $path_info, 2);

/* 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;
}

require_once 'Horde/Cache.php';
$cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
if (is_a($cache, 'PEAR_Error')) {
   Horde::logMessage('No cache backend available.', __FILE__, __LINE__, PEAR_LOG_ERR);
    exit;
}

// If cache info doesn't exist, just output an empty body.
header('Content-Type: ' . $type);
$cache->output($cid, $lifetime);