5 * @subpackage plugins
\r
9 * Prepend the cache information to the cache file
\r
12 * @param string $tpl_file
\r
13 * @param string $cache_id
\r
14 * @param string $compile_id
\r
15 * @param string $results
\r
19 // $tpl_file, $cache_id, $compile_id, $results
\r
21 function smarty_core_write_cache_file($params, &$smarty)
\r
24 // put timestamp in cache header
\r
25 $smarty->_cache_info['timestamp'] = time();
\r
26 if ($smarty->cache_lifetime > -1){
\r
28 $smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] + $smarty->cache_lifetime;
\r
30 // cache will never expire
\r
31 $smarty->_cache_info['expires'] = -1;
\r
34 // collapse {nocache...}-tags
\r
35 $params['results'] = preg_replace('!((\{nocache\:([0-9a-f]{32})#(\d+)\})'
\r
37 .'{/nocache\:\\3#\\4\})!Us'
\r
39 ,$params['results']);
\r
40 $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
\r
42 // prepend the cache header info into cache file
\r
43 $params['results'] = serialize($smarty->_cache_info)."\n".$params['results'];
\r
45 if (!empty($smarty->cache_handler_func)) {
\r
46 // use cache_handler function
\r
47 call_user_func_array($smarty->cache_handler_func,
\r
48 array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
\r
50 // use local cache file
\r
52 if(!@is_writable($smarty->cache_dir)) {
\r
53 // cache_dir not writable, see if it exists
\r
54 if(!@is_dir($smarty->cache_dir)) {
\r
55 $smarty->trigger_error('the $cache_dir \'' . $smarty->cache_dir . '\' does not exist, or is not a directory.', E_USER_ERROR);
\r
58 $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);
\r
62 $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
\r
63 $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
\r
64 $_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true);
\r
65 require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php');
\r
66 smarty_core_write_file($_params, $smarty);
\r
71 /* vim: set expandtab: */
\r