Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2809 rexy 1
<?php
2
 
3
/**
4
 * Inline Runtime Methods render, setSourceByUid, setupSubTemplate
5
 *
6
 * @package    Smarty
7
 * @subpackage PluginsInternal
8
 * @author     Uwe Tews
9
 **/
10
class Smarty_Internal_Runtime_CacheModify
11
{
12
    /**
13
     * check client side cache
14
     *
15
     * @param \Smarty_Template_Cached   $cached
16
     * @param \Smarty_Internal_Template $_template
17
     * @param string                    $content
18
     *
19
     * @throws \Exception
20
     * @throws \SmartyException
21
     */
22
    public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
23
    {
24
        $_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
25
        $_last_modified_date =
26
            @substr($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 0, strpos($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 'GMT') + 3);
27
        if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) {
28
            switch (PHP_SAPI) {
29
                case 'cgi': // php-cgi < 5.3
30
                case 'cgi-fcgi': // php-cgi >= 5.3
31
                case 'fpm-fcgi': // php-fpm >= 5.3.3
32
                    header('Status: 304 Not Modified');
33
                    break;
34
                case 'cli':
35
                    if (/* ^phpunit */
36
                    !empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
37
                    ) {
38
                        $_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = '304 Not Modified';
39
                    }
40
                    break;
41
                default:
42
                    if (/* ^phpunit */
43
                    !empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
44
                    ) {
45
                        $_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = '304 Not Modified';
46
                    } else {
47
                        header($_SERVER[ 'SERVER_PROTOCOL' ] . ' 304 Not Modified');
48
                    }
49
                    break;
50
            }
51
        } else {
52
            switch (PHP_SAPI) {
53
                case 'cli':
54
                    if (/* ^phpunit */
55
                    !empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
56
                    ) {
57
                        $_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] =
58
                            'Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT';
59
                    }
60
                    break;
61
                default:
62
                    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT');
63
                    break;
64
            }
65
            echo $content;
66
        }
67
    }
68
}