changed git call from https to git readonly
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / core / core.read_cache_file.php
1 <?php\r
2 /**\r
3  * Smarty plugin\r
4  * @package Smarty\r
5  * @subpackage plugins\r
6  */\r
7 \r
8 /**\r
9  * read a cache file, determine if it needs to be\r
10  * regenerated or not\r
11  *\r
12  * @param string $tpl_file\r
13  * @param string $cache_id\r
14  * @param string $compile_id\r
15  * @param string $results\r
16  * @return boolean\r
17  */\r
18 \r
19 //  $tpl_file, $cache_id, $compile_id, &$results\r
20 \r
21 function smarty_core_read_cache_file(&$params, &$smarty)\r
22 {\r
23     static  $content_cache = array();\r
24 \r
25     if ($smarty->force_compile) {\r
26         // force compile enabled, always regenerate\r
27         return false;\r
28     }\r
29 \r
30     if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) {\r
31         list($params['results'], $smarty->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']];\r
32         return true;\r
33     }\r
34 \r
35     if (!empty($smarty->cache_handler_func)) {\r
36         // use cache_handler function\r
37         call_user_func_array($smarty->cache_handler_func,\r
38                              array('read', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));\r
39     } else {\r
40         // use local cache file\r
41         $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);\r
42         $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);\r
43         $params['results'] = $smarty->_read_file($_cache_file);\r
44     }\r
45 \r
46     if (empty($params['results'])) {\r
47         // nothing to parse (error?), regenerate cache\r
48         return false;\r
49     }\r
50 \r
51     $cache_split = explode("\n", $params['results'], 2);\r
52     $cache_header = $cache_split[0];\r
53 \r
54     $_cache_info = unserialize($cache_header);\r
55 \r
56     if ($smarty->caching == 2 && isset ($_cache_info['expires'])){\r
57         // caching by expiration time\r
58         if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) {\r
59             // cache expired, regenerate\r
60             return false;\r
61         }\r
62     } else {\r
63         // caching by lifetime\r
64         if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) {\r
65             // cache expired, regenerate\r
66             return false;\r
67         }\r
68     }\r
69 \r
70     if ($smarty->compile_check) {\r
71         $_params = array('get_source' => false, 'quiet'=>true);\r
72         foreach (array_keys($_cache_info['template']) as $_template_dep) {\r
73             $_params['resource_name'] = $_template_dep;\r
74             if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {\r
75                 // template file has changed, regenerate cache\r
76                 return false;\r
77             }\r
78         }\r
79 \r
80         if (isset($_cache_info['config'])) {\r
81             $_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false, 'quiet'=>true);\r
82             foreach (array_keys($_cache_info['config']) as $_config_dep) {\r
83                 $_params['resource_name'] = $_config_dep;\r
84                 if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {\r
85                     // config file has changed, regenerate cache\r
86                     return false;\r
87                 }\r
88             }\r
89         }\r
90     }\r
91 \r
92     foreach ($_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {\r
93         if (empty($smarty->_cache_serials[$_include_file_path])) {\r
94             $smarty->_include($_include_file_path, true);\r
95         }\r
96 \r
97         if ($smarty->_cache_serials[$_include_file_path] != $_cache_serial) {\r
98             /* regenerate */\r
99             return false;\r
100         }\r
101     }\r
102     $params['results'] = $cache_split[1];\r
103     $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info);\r
104 \r
105     $smarty->_cache_info = $_cache_info;\r
106     return true;\r
107 }\r
108 \r
109 /* vim: set expandtab: */\r
110 \r
111 ?>\r