00001 <?php
00019
00020
00021 function smarty_core_write_cache_file($params, &$smarty)
00022 {
00023
00024
00025 $smarty->_cache_info['timestamp'] = time();
00026 if ($smarty->cache_lifetime > -1){
00027
00028 $smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] + $smarty->cache_lifetime;
00029 } else {
00030
00031 $smarty->_cache_info['expires'] = -1;
00032 }
00033
00034
00035 if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!', $params['results'], $match, PREG_PATTERN_ORDER)) {
00036
00037
00038
00039
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
00049 if ($match[1][$j]) {
00050 $level--;
00051 unset($results[$i]);
00052 } else {
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
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
00070 call_user_func_array($smarty->cache_handler_func,
00071 array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
00072 } else {
00073
00074
00075 if(!@is_writable($smarty->cache_dir)) {
00076
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 ?>