Location: PHPKode > scripts > Ja2BU > libs/plugins/core.exists_cache_file.php
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * checks if a cache file exists, determine if it needs to be
 * regenerated or not
 *
 * @param string $tpl_file
 * @param string $cache_id
 * @param string $compile_id
 * @param string $results
 * @return boolean
 */    
 
//  $tpl_file, $cache_id, $compile_id, &$results
 
function smarty_core_exists_cache_file(&$params, &$this)
{
    static  $content_cache = array();

    if ($this->force_compile) {
        // force compile enabled, always regenerate
        return false;
    }

    if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) {
        list($params['results'], $this->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']];
        return true;
    }

    if (!empty($this->cache_handler_func)) {
        // use cache_handler function
        call_user_func_array($this->cache_handler_func,
                             array('read', &$this, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id']));
    } 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);
        $params['results'] = $this->_read_file($_cache_file);
    }

    if (empty($params['results'])) {
        // nothing to parse (error?), regenerate cache
        return false;
    }

    $rem_left = "<"."?php /* ";
    $rem_right = "*/ ?".">";
    $cache_split = explode("\n", $params['results'], 2);
    $cache_header = substr($cache_split[0], strlen($rem_left), strlen($cache_split[0])-strlen($rem_left)-strlen($rem_right));

    $this->_cache_info = unserialize($cache_header);

    if ($this->caching == 2 && isset ($this->_cache_info['expires'])){
        // caching by expiration time
        if ($this->_cache_info['expires'] > -1 && (time() > $this->_cache_info['expires'])) {
        // cache expired, regenerate
        return false;
        }
    } else {
        // caching by lifetime
        if ($this->cache_lifetime > -1 && (time() - $this->_cache_info['timestamp'] > $this->cache_lifetime)) {
        // cache expired, regenerate
        return false;
        }
    }

    if ($this->compile_check) {
        foreach (array_keys($this->_cache_info['template']) as $_template_dep) {
			$_params = array('tpl_path' => $_template_dep);
			$this->_execute_core_function('fetch_template_info', $_params);
            if ($this->_cache_info['timestamp'] < $_params['template_timestamp']) {
                // template file has changed, regenerate cache
                return false;
            }
        }

        if (isset($this->_cache_info['config'])) {
            foreach (array_keys($this->_cache_info['config']) as $config_dep) {
                if ($this->_cache_info['timestamp'] < filemtime($this->config_dir . DIRECTORY_SEPARATOR . $config_dep)) {
                    // config file has changed, regenerate cache
                    return false;
                }
            }
        }
    }

    $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $this->_cache_info);

    return true;
}

/* vim: set expandtab: */

?>
Return current item: Ja2BU