<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Prepend the cache information to the cache file
* and write it
*
* @param string $tpl_file
* @param string $cache_id
* @param string $compile_id
* @param string $results
* @return true|null
*/
// $tpl_file, $cache_id, $compile_id, $results
function smarty_core_write_cache_file(&$params, &$this)
{
// put timestamp in cache header
$this->_cache_info['timestamp'] = time();
if ($this->cache_lifetime > -1){
// expiration set
$this->_cache_info['expires'] = $this->_cache_info['timestamp'] + $this->cache_lifetime;
} else {
// cache will never expire
$this->_cache_info['expires'] = -1;
}
// prepend the cache header info into cache file
$rem_left = "<"."?php /* ";
$rem_right = "*/ ?".">";
if (!empty($this->cache_handler_func)) {
// use cache_handler function
$_params = $params;
$_params['results'] = $rem_left.serialize($this->_cache_info).$rem_right."\n".$_params['results'];
call_user_func_array($this->cache_handler_func,
array('write', &$this, &$_params['results'], $_params['tpl_file'], $_params['cache_id'], $_params['compile_id']));
ob_start();
eval('?>' . $params['results']);
$params['results'] = ob_get_contents();
ob_end_clean();
} else {
// use local cache file
$_auto_id = $this->_get_auto_id($params['cache_id'], $params['compile_id']);
$_cache_file = $this->_get_auto_filename($this->cache_dir, $params['tpl_file'], $_auto_id);
$cacheSmarty = $this; // create a copy of current Smarty object
$cacheSmarty->left_delimiter = $this->_cache_left_delimiter;
$cacheSmarty->right_delimiter = $this->_cache_right_delimiter;
$cacheSmarty->caching = 0; // disable caching for final output
$cacheSmarty->_compile_template("evaluated template", $params['results'], $source);
$params['results'] = $rem_left.serialize($this->_cache_info).$rem_right."\n".$source;
$_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true);
$this->_execute_core_function('write_file', $_params);
ob_start();
include($_cache_file);
$params['results'] = ob_get_contents();
ob_end_clean();
return true;
}
}
/* vim: set expandtab: */
?>