+++ /dev/null
-<?php\r
-/**\r
- * Smarty plugin\r
- * @package Smarty\r
- * @subpackage plugins\r
- */\r
-\r
-/**\r
- * read a cache file, determine if it needs to be\r
- * regenerated or not\r
- *\r
- * @param string $tpl_file\r
- * @param string $cache_id\r
- * @param string $compile_id\r
- * @param string $results\r
- * @return boolean\r
- */\r
-\r
-// $tpl_file, $cache_id, $compile_id, &$results\r
-\r
-function smarty_core_read_cache_file(&$params, &$smarty)\r
-{\r
- static $content_cache = array();\r
-\r
- if ($smarty->force_compile) {\r
- // force compile enabled, always regenerate\r
- return false;\r
- }\r
-\r
- if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) {\r
- list($params['results'], $smarty->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']];\r
- return true;\r
- }\r
-\r
- if (!empty($smarty->cache_handler_func)) {\r
- // use cache_handler function\r
- call_user_func_array($smarty->cache_handler_func,\r
- array('read', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));\r
- } else {\r
- // use local cache file\r
- $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);\r
- $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);\r
- $params['results'] = $smarty->_read_file($_cache_file);\r
- }\r
-\r
- if (empty($params['results'])) {\r
- // nothing to parse (error?), regenerate cache\r
- return false;\r
- }\r
-\r
- $cache_split = explode("\n", $params['results'], 2);\r
- $cache_header = $cache_split[0];\r
-\r
- $_cache_info = unserialize($cache_header);\r
-\r
- if ($smarty->caching == 2 && isset ($_cache_info['expires'])){\r
- // caching by expiration time\r
- if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) {\r
- // cache expired, regenerate\r
- return false;\r
- }\r
- } else {\r
- // caching by lifetime\r
- if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) {\r
- // cache expired, regenerate\r
- return false;\r
- }\r
- }\r
-\r
- if ($smarty->compile_check) {\r
- $_params = array('get_source' => false, 'quiet'=>true);\r
- foreach (array_keys($_cache_info['template']) as $_template_dep) {\r
- $_params['resource_name'] = $_template_dep;\r
- if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {\r
- // template file has changed, regenerate cache\r
- return false;\r
- }\r
- }\r
-\r
- if (isset($_cache_info['config'])) {\r
- $_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false, 'quiet'=>true);\r
- foreach (array_keys($_cache_info['config']) as $_config_dep) {\r
- $_params['resource_name'] = $_config_dep;\r
- if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {\r
- // config file has changed, regenerate cache\r
- return false;\r
- }\r
- }\r
- }\r
- }\r
-\r
- foreach ($_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {\r
- if (empty($smarty->_cache_serials[$_include_file_path])) {\r
- $smarty->_include($_include_file_path, true);\r
- }\r
-\r
- if ($smarty->_cache_serials[$_include_file_path] != $_cache_serial) {\r
- /* regenerate */\r
- return false;\r
- }\r
- }\r
- $params['results'] = $cache_split[1];\r
- $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info);\r
-\r
- $smarty->_cache_info = $_cache_info;\r
- return true;\r
-}\r
-\r
-/* vim: set expandtab: */\r
-\r
-?>\r