00001 <?php 00019 // $tpl_file, $cache_id, $compile_id, $results 00020 00021 function smarty_core_write_cache_file($params, &$smarty) 00022 { 00023 00024 // put timestamp in cache header 00025 $smarty->_cache_info['timestamp'] = time(); 00026 if ($smarty->cache_lifetime > -1){ 00027 // expiration set 00028 $smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] + $smarty->cache_lifetime; 00029 } else { 00030 // cache will never expire 00031 $smarty->_cache_info['expires'] = -1; 00032 } 00033 00034 // collapse nocache.../nocache-tags 00035 if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!', $params['results'], $match, PREG_PATTERN_ORDER)) { 00036 // remove everything between every pair of outermost noache.../nocache-tags 00037 // and replace it by a single nocache-tag 00038 // this new nocache-tag will be replaced by dynamic contents in 00039 // smarty_core_process_compiled_includes() on a cache-read 00040 00041 $match_count = count($match[0]); 00042 $results = preg_split('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!', $params['results'], -1, PREG_SPLIT_DELIM_CAPTURE); 00043 00044 $level = 0; 00045 $j = 0; 00046 for ($i=0, $results_count = count($results); $i < $results_count && $j < $match_count; $i++) { 00047 if ($results[$i] == $match[0][$j]) { 00048 // nocache tag 00049 if ($match[1][$j]) { // closing tag 00050 $level--; 00051 unset($results[$i]); 00052 } else { // opening tag 00053 if ($level++ > 0) unset($results[$i]); 00054 } 00055 $j++; 00056 } elseif ($level > 0) { 00057 unset($results[$i]); 00058 } 00059 } 00060 $params['results'] = implode('', $results); 00061 } 00062 $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials; 00063 00064 // prepend the cache header info into cache file 00065 $_cache_info = serialize($smarty->_cache_info); 00066 $params['results'] = strlen($_cache_info) . "\n" . $_cache_info . $params['results']; 00067 00068 if (!empty($smarty->cache_handler_func)) { 00069 // use cache_handler function 00070 call_user_func_array($smarty->cache_handler_func, 00071 array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], $smarty->_cache_info['expires'])); 00072 } else { 00073 // use local cache file 00074 00075 if(!@is_writable($smarty->cache_dir)) { 00076 // cache_dir not writable, see if it exists 00077 if(!@is_dir($smarty->cache_dir)) { 00078 $smarty->trigger_error('the $cache_dir \'' . $smarty->cache_dir . '\' does not exist, or is not a directory.', E_USER_ERROR); 00079 return false; 00080 } 00081 $smarty->trigger_error('unable to write to $cache_dir \'' . realpath($smarty->cache_dir) . '\'. Be sure $cache_dir is writable by the web server user.', E_USER_ERROR); 00082 return false; 00083 } 00084 00085 $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']); 00086 $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id); 00087 $_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true); 00088 require_once(SMARTY_CORE_DIR . 'core.write_file.php'); 00089 smarty_core_write_file($_params, $smarty); 00090 return true; 00091 } 00092 } 00093 00094 /* vim: set expandtab: */ 00095 00096 ?>
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
