mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
- internal change on building cache files
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
01/03/2009
|
||||||
|
- internal change on building cache files
|
||||||
|
|
||||||
01/02/2009
|
01/02/2009
|
||||||
- update cached_timestamp at the template object after cache file is written to avoid possible side effects
|
- update cached_timestamp at the template object after cache file is written to avoid possible side effects
|
||||||
- use internally always SMARTY_CACHING_LIFETIME_* constants
|
- use internally always SMARTY_CACHING_LIFETIME_* constants
|
||||||
|
@@ -53,7 +53,6 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
|||||||
public $cached_timestamp = null;
|
public $cached_timestamp = null;
|
||||||
private $isCached = null;
|
private $isCached = null;
|
||||||
private $cache_resource_object = null;
|
private $cache_resource_object = null;
|
||||||
private $cacheFileWritten = false;
|
|
||||||
private $cacheFileChecked = false;
|
private $cacheFileChecked = false;
|
||||||
// template variables
|
// template variables
|
||||||
public $tpl_vars = array();
|
public $tpl_vars = array();
|
||||||
@@ -324,30 +323,14 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
|||||||
/**
|
/**
|
||||||
* Writes the cached template output
|
* Writes the cached template output
|
||||||
*/
|
*/
|
||||||
public function writeCachedContent ()
|
public function writeCachedContent ($content)
|
||||||
{
|
{
|
||||||
if ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) {
|
if ($this->resource_object->isEvaluated || !($this->caching == SMARTY_CACHING_LIFETIME_CURRENT || $this->caching == SMARTY_CACHING_LIFETIME_SAVED)) {
|
||||||
// don't write cache file
|
// don't write cache file
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->properties['cache_lifetime'] = $this->cache_lifetime;
|
$this->properties['cache_lifetime'] = $this->cache_lifetime;
|
||||||
$this->properties['has_nocache_code'] = false;
|
return $this->cache_resource_object->writeCachedContent($this, $this->createPropertyHeader(true) . $content);
|
||||||
// get text between non-cached items
|
|
||||||
$cache_split = preg_split("!/\*%%SmartyNocache:{$this->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$this->properties['nocache_hash']}%%\*/!s", $this->rendered_content);
|
|
||||||
// get non-cached items
|
|
||||||
preg_match_all("!/\*%%SmartyNocache:{$this->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$this->properties['nocache_hash']}%%\*/!s", $this->rendered_content, $cache_parts);
|
|
||||||
$output = '';
|
|
||||||
// loop over items, stitch back together
|
|
||||||
foreach($cache_split as $curr_idx => $curr_split) {
|
|
||||||
// escape PHP tags in template content
|
|
||||||
$output .= preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php echo \'$1\'; ?>', $curr_split);
|
|
||||||
if (isset($cache_parts[0][$curr_idx])) {
|
|
||||||
$this->properties['has_nocache_code'] = true;
|
|
||||||
// remove nocache tags from cache output
|
|
||||||
$output .= preg_replace("!/\*/?%%SmartyNocache:{$this->properties['nocache_hash']}%%\*/!", '', $cache_parts[0][$curr_idx]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->cache_resource_object->writeCachedContent($this, $this->createPropertyHeader(true) . $output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -484,18 +467,29 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
|||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::start_cache($this);
|
Smarty_Internal_Debug::start_cache($this);
|
||||||
}
|
}
|
||||||
// dummy renderung because of {function} nocache handling
|
$this->properties['has_nocache_code'] = false;
|
||||||
|
// get text between non-cached items
|
||||||
|
$cache_split = preg_split("!/\*%%SmartyNocache:{$this->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$this->properties['nocache_hash']}%%\*/!s", $this->rendered_content);
|
||||||
|
// get non-cached items
|
||||||
|
preg_match_all("!/\*%%SmartyNocache:{$this->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$this->properties['nocache_hash']}%%\*/!s", $this->rendered_content, $cache_parts);
|
||||||
|
$output = '';
|
||||||
|
// loop over items, stitch back together
|
||||||
|
foreach($cache_split as $curr_idx => $curr_split) {
|
||||||
|
// escape PHP tags in template content
|
||||||
|
$output .= preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php echo \'$1\'; ?>', $curr_split);
|
||||||
|
if (isset($cache_parts[0][$curr_idx])) {
|
||||||
|
$this->properties['has_nocache_code'] = true;
|
||||||
|
// remove nocache tags from cache output
|
||||||
|
$output .= preg_replace("!/\*/?%%SmartyNocache:{$this->properties['nocache_hash']}%%\*/!", '', $cache_parts[0][$curr_idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// rendering (must be done before writing cache file because of {function} nocache handling)
|
||||||
$_smarty_tpl = $this;
|
$_smarty_tpl = $this;
|
||||||
ob_start();
|
ob_start();
|
||||||
eval("?>" . $this->rendered_content);
|
eval("?>" . $output);
|
||||||
ob_get_clean();
|
$this->rendered_content = ob_get_clean();
|
||||||
// write rendered template
|
// write cache file content
|
||||||
if (!$this->cacheFileWritten) {
|
$this->writeCachedContent($output);
|
||||||
$this->writeCachedContent($this);
|
|
||||||
$this->cacheFileWritten = true;
|
|
||||||
}
|
|
||||||
// cache file may contain nocache code. read it back for processing
|
|
||||||
$this->rendered_content = $this->cache_resource_object->getCachedContents($this);
|
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::end_cache($this);
|
Smarty_Internal_Debug::end_cache($this);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user