00001 <?php
00019
00020
00021 function smarty_core_read_cache_file(&$params, &$smarty)
00022 {
00023 static $content_cache = array();
00024
00025 if ($smarty->force_compile) {
00026
00027 return false;
00028 }
00029
00030 if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) {
00031 list($params['results'], $smarty->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']];
00032 return true;
00033 }
00034
00035 if (!empty($smarty->cache_handler_func)) {
00036
00037 call_user_func_array($smarty->cache_handler_func,
00038 array('read', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
00039 } else {
00040
00041 $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
00042 $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
00043 $params['results'] = $smarty->_read_file($_cache_file);
00044 }
00045
00046 if (empty($params['results'])) {
00047
00048 return false;
00049 }
00050
00051 $_contents = $params['results'];
00052 $_info_start = strpos($_contents, "\n") + 1;
00053 $_info_len = (int)substr($_contents, 0, $_info_start - 1);
00054 $_cache_info = unserialize(substr($_contents, $_info_start, $_info_len));
00055 $params['results'] = substr($_contents, $_info_start + $_info_len);
00056
00057 if ($smarty->caching == 2 && isset ($_cache_info['expires'])){
00058
00059 if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) {
00060
00061 return false;
00062 }
00063 } else {
00064
00065 if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) {
00066
00067 return false;
00068 }
00069 }
00070
00071 if ($smarty->compile_check) {
00072 $_params = array('get_source' => false, 'quiet'=>true);
00073 foreach (array_keys($_cache_info['template']) as $_template_dep) {
00074 $_params['resource_name'] = $_template_dep;
00075 if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
00076
00077 return false;
00078 }
00079 }
00080
00081 if (isset($_cache_info['config'])) {
00082 $_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false, 'quiet'=>true);
00083 foreach (array_keys($_cache_info['config']) as $_config_dep) {
00084 $_params['resource_name'] = $_config_dep;
00085 if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
00086
00087 return false;
00088 }
00089 }
00090 }
00091 }
00092
00093 $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info);
00094
00095 $smarty->_cache_info = $_cache_info;
00096 return true;
00097 }
00098
00099
00100
00101 ?>