- bugfix template caching did not care about file.tpl in different template_dir

- bugfix {include $file} was broken when merge_compiled_incluges = true
- bugfix {include} was broken when merge_compiled_incluges = true and same indluded template
  was used in different main templates in one compilation run
This commit is contained in:
uwe.tews@googlemail.com
2011-09-18 02:31:58 +00:00
parent c9be9cd7f9
commit a44d9a6ac9
8 changed files with 28 additions and 19 deletions

View File

@@ -1,4 +1,10 @@
===== Smarty 3.1 trunk =====
18.09.2011
- bugfix template caching did not care about file.tpl in different template_dir
- bugfix {include $file} was broken when merge_compiled_incluges = true
- bugfix {include} was broken when merge_compiled_incluges = true and same indluded template
was used in different main templates in one compilation run
17.09.2011
- bugfix lock_id for file resource would create invalid filepath
- bugfix resource caching did not care about file.tpl in different template_dir

View File

@@ -533,6 +533,12 @@ class Smarty extends Smarty_Internal_TemplateBase {
* @var bool
*/
public $_parserdebug = false;
/**
* Saved parameter of merged templates during compilation
*
* @var array
*/
public $merged_templates_func = array();
/**#@-*/
/**
@@ -1126,7 +1132,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
$compile_id = $compile_id === null ? $this->compile_id : $compile_id;
// already in template cache?
$_templateId = sha1($template . $cache_id . $compile_id);
$_templateId = sha1(join(DIRECTORY_SEPARATOR, $this->getTemplateDir()).$template . $cache_id . $compile_id);
if ($do_clone) {
if (isset($this->template_objects[$_templateId])) {
// return cached template object

View File

@@ -178,7 +178,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
$uid = $tpl->source->uid;
}
// remove from template cache
unset($smarty->template_objects[sha1($tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()),$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
}
return $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id);
}

View File

@@ -154,10 +154,10 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
if ($tpl->source->exists) {
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
// remove from template cache
unset($smarty->template_objects[sha1($tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()).$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
} else {
// remove from template cache
unset($smarty->template_objects[sha1($tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()).$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
return 0;
}
}

View File

@@ -49,12 +49,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('_any');
/**
* Saved parameter of merged templates
*
* @var array
*/
private static $merged_templates_func = array();
/**
* Compiles code for the {include} tag
@@ -131,15 +125,16 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
if (($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) && !$compiler->template->source->recompiled
&& !($compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache)) && $_caching != Smarty::CACHING_LIFETIME_CURRENT) {
// check if compiled code can be merged (contains no variable part)
if (!$compiler->has_variable_string && (substr_count($include_file, '"') == 2 or substr_count($include_file, "'") == 2) and substr_count($include_file, '(') == 0) {
if (!$compiler->has_variable_string && (substr_count($include_file, '"') == 2 or substr_count($include_file, "'") == 2)
and substr_count($include_file, '(') == 0 and substr_count($include_file, '$_smarty_tpl->') == 0) {
$tpl_name = null;
eval("\$tpl_name = $include_file;");
if (!isset(self::$merged_templates_func[$tpl_name]) || $compiler->inheritance) {
if (!isset($compiler->smarty->merged_templates_func[$tpl_name]) || $compiler->inheritance) {
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $compiler->template->compile_id);
// save unique function name
self::$merged_templates_func[$tpl_name]['func'] = $tpl->properties['unifunc'] = 'content_'.uniqid();
$compiler->smarty->merged_templates_func[$tpl_name]['func'] = $tpl->properties['unifunc'] = 'content_'.uniqid();
// use current nocache hash for inlined code
self::$merged_templates_func[$tpl_name]['nocache_hash'] = $tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$compiler->smarty->merged_templates_func[$tpl_name]['nocache_hash'] = $tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
if ($compiler->template->caching) {
// needs code for cached page but no cache file
$tpl->caching = self::CACHING_NOCACHE_CODE;
@@ -190,14 +185,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase {
$_has_vars = false;
}
if ($has_compiled_template) {
$_hash = self::$merged_templates_func[$tpl_name]['nocache_hash'];
$_hash = $compiler->smarty->merged_templates_func[$tpl_name]['nocache_hash'];
$_output = "<?php /* Call merged included template \"" . $tpl_name . "\" */\n";
$_output .= "\$_tpl_stack[] = \$_smarty_tpl;\n";
$_output .= " \$_smarty_tpl = \$_smarty_tpl->setupInlineSubTemplate($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, '$_hash');\n";
if (isset($_assign)) {
$_output .= 'ob_start(); ';
}
$_output .= self::$merged_templates_func[$tpl_name]['func']. "(\$_smarty_tpl);\n";
$_output .= $compiler->smarty->merged_templates_func[$tpl_name]['func']. "(\$_smarty_tpl);\n";
$_output .= "\$_smarty_tpl = array_pop(\$_tpl_stack); ";
if (isset($_assign)) {
$_output .= " \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_variable(ob_get_clean());";

View File

@@ -589,7 +589,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// cache template object under a unique ID
// do not cache eval resources
if ($this->source->type != 'eval') {
$this->smarty->template_objects[sha1($this->template_resource . $this->cache_id . $this->compile_id)] = $this;
$this->smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $this->smarty->getTemplateDir()).$this->template_resource . $this->cache_id . $this->compile_id)] = $this;
}
return $this->source;

View File

@@ -106,6 +106,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
}
}
}
// must reset merge template date
$_template->smarty->merged_templates_func = array();
// get rendered template
// disable caching for evaluated code
if ($_template->source->recompiled) {

View File

@@ -192,10 +192,10 @@ class Smarty_Internal_Utility {
if ($tpl->source->exists) {
$_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
// remove from template cache
unset($smarty->template_objects[sha1($tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()).$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
} else {
// remove from template cache
unset($smarty->template_objects[sha1($tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()).$tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
return 0;
}
$_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1);