]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_runtime_cachemodify.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_runtime_cachemodify.php
1 <?php
2
3 /**
4  * Inline Runtime Methods render, setSourceByUid, setupSubTemplate
5  *
6  * @package    Smarty
7  * @subpackage PluginsInternal
8  * @author     Uwe Tews
9  *
10  **/
11 class Smarty_Internal_Runtime_CacheModify
12 {
13     /**
14      * check client side cache
15      *
16      * @param \Smarty_Template_Cached   $cached
17      * @param \Smarty_Internal_Template $_template
18      * @param  string                   $content
19      */
20     public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
21     {
22         $_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
23         $_last_modified_date =
24             @substr($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 0, strpos($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 'GMT') + 3);
25         if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) {
26             switch (PHP_SAPI) {
27                 case 'cgi': // php-cgi < 5.3
28                 case 'cgi-fcgi': // php-cgi >= 5.3
29                 case 'fpm-fcgi': // php-fpm >= 5.3.3
30                     header('Status: 304 Not Modified');
31                     break;
32
33                 case 'cli':
34                     if ( /* ^phpunit */
35                     !empty($_SERVER[ 'SMARTY_PHPUNIT_DISABLE_HEADERS' ]) /* phpunit$ */
36                     ) {
37                         $_SERVER[ 'SMARTY_PHPUNIT_HEADERS' ][] = '304 Not Modified';
38                     }
39                     break;
40
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 }