1: <?php
2: 3: 4: 5: 6:
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18:
19:
20:
21: function smarty_core_write_cache_file($params, &$smarty)
22: {
23:
24:
25: $smarty->_cache_info['timestamp'] = time();
26: if ($smarty->cache_lifetime > -1){
27:
28: $smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] + $smarty->cache_lifetime;
29: } else {
30:
31: $smarty->_cache_info['expires'] = -1;
32: }
33:
34:
35: if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!', $params['results'], $match, PREG_PATTERN_ORDER)) {
36:
37:
38:
39:
40:
41: $match_count = count($match[0]);
42: $results = preg_split('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!', $params['results'], -1, PREG_SPLIT_DELIM_CAPTURE);
43:
44: $level = 0;
45: $j = 0;
46: for ($i=0, $results_count = count($results); $i < $results_count && $j < $match_count; $i++) {
47: if ($results[$i] == $match[0][$j]) {
48:
49: if ($match[1][$j]) {
50: $level--;
51: unset($results[$i]);
52: } else {
53: if ($level++ > 0) unset($results[$i]);
54: }
55: $j++;
56: } elseif ($level > 0) {
57: unset($results[$i]);
58: }
59: }
60: $params['results'] = implode('', $results);
61: }
62: $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
63:
64:
65: $_cache_info = serialize($smarty->_cache_info);
66: $params['results'] = strlen($_cache_info) . "\n" . $_cache_info . $params['results'];
67:
68: if (!empty($smarty->cache_handler_func)) {
69:
70: call_user_func_array($smarty->cache_handler_func,
71: array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], $smarty->_cache_info['expires']));
72: } else {
73:
74:
75: if(!@is_writable($smarty->cache_dir)) {
76:
77: if(!@is_dir($smarty->cache_dir)) {
78: $smarty->trigger_error('the $cache_dir \'' . $smarty->cache_dir . '\' does not exist, or is not a directory.', E_USER_ERROR);
79: return false;
80: }
81: $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);
82: return false;
83: }
84:
85: $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
86: $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
87: $_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true);
88: require_once(SMARTY_CORE_DIR . 'core.write_file.php');
89: smarty_core_write_file($_params, $smarty);
90: return true;
91: }
92: }
93:
94:
95:
96: ?>
97: