- bugfix on nocache {block} tags in parent templates

This commit is contained in:
Uwe.Tews
2010-01-09 19:23:35 +00:00
parent 6c020763a8
commit a3459b2e3a
5 changed files with 23 additions and 11 deletions

View File

@@ -1,3 +1,6 @@
01/09/2009
- bugfix on nocache {block} tags in parent templates
01/08/2009 01/08/2009
- bugfix on variable filters. filter/nofilter attributes did not work on output statements - bugfix on variable filters. filter/nofilter attributes did not work on output statements

View File

@@ -30,7 +30,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$this->_open_tag('block', $save); $this->_open_tag('block', $save);
$compiler->template->extract_code = true; $compiler->template->extract_code = true;
$compiler->template->extracted_compiled_code = ''; $compiler->template->extracted_compiled_code = '';
$compiler->template->has_code = false; $compiler->has_code = false;
return true; return true;
} }
} }
@@ -66,7 +66,11 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
$_tpl = $this->smarty->createTemplate('string:' . $this->smarty->block_data[$_name]['source'], null, null, $compiler->template); $_tpl = $this->smarty->createTemplate('string:' . $this->smarty->block_data[$_name]['source'], null, null, $compiler->template);
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$_tpl->template_filepath = $this->smarty->block_data[$_name]['file']; $_tpl->template_filepath = $this->smarty->block_data[$_name]['file'];
$_tpl->forceNocache = true; if ($compiler->nocache) {
$_tpl->forceNocache = 2;
} else {
$_tpl->forceNocache = 1;
}
$_tpl->suppressHeader = true; $_tpl->suppressHeader = true;
$_tpl->suppressFileDependency = true; $_tpl->suppressFileDependency = true;
if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) { if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
@@ -87,7 +91,9 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
$_output = $compiler->template->extracted_compiled_code; $_output = $compiler->template->extracted_compiled_code;
} }
$compiler->template->extracted_compiled_code = $saved_data[1]; $compiler->template->extracted_compiled_code = $saved_data[1];
$compiler->template->extract_code = $saved_data[2]; $compiler->template->extract_code = $saved_data[2];
// $_output content has already nocache code processed
$compiler->suppressNocacheProcessing = true;
return $_output; return $_output;
} }
} }

View File

@@ -40,8 +40,8 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase {
$compiler->template->required_plugins = array('compiled' => array(), 'cache' => array()); $compiler->template->required_plugins = array('compiled' => array(), 'cache' => array());
$compiler->template->extract_code = true; $compiler->template->extract_code = true;
$compiler->template->extracted_compiled_code = ''; $compiler->template->extracted_compiled_code = '';
$compiler->template->has_code = false;
$compiler->template->has_nocache_code = false; $compiler->template->has_nocache_code = false;
$compiler->has_code = false;
return true; return true;
} }
} }

View File

@@ -39,10 +39,10 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
// init the lexer/parser to compile the template // init the lexer/parser to compile the template
$this->lex = new $this->lexer_class($_content, $this); $this->lex = new $this->lexer_class($_content, $this);
$this->parser = new $this->parser_class($this->lex, $this); $this->parser = new $this->parser_class($this->lex, $this);
// $this->parser->PrintTrace(); if (isset($this->smarty->_parserdebug)) $this->parser->PrintTrace();
// get tokens from lexer and parse them // get tokens from lexer and parse them
while ($this->lex->yylex() && !$this->abort_and_recompile) { while ($this->lex->yylex() && !$this->abort_and_recompile) {
// echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token ".htmlentities($this->lex->value)."</pre>"; if (isset($this->smarty->_parserdebug)) echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token ".htmlentities($this->lex->value)."</pre>";
$this->parser->doParse($this->lex->token, $this->lex->value); $this->parser->doParse($this->lex->token, $this->lex->value);
} }

View File

@@ -12,6 +12,10 @@
* Main compiler class * Main compiler class
*/ */
class Smarty_Internal_TemplateCompilerBase { class Smarty_Internal_TemplateCompilerBase {
// hash for nocache sections
private $nocache_hash = null;
// suppress generation of nocache code
public $suppressNocacheProcessing = false;
// compile tag objects // compile tag objects
static $_tag_objects = array(); static $_tag_objects = array();
// tag stack // tag stack
@@ -20,8 +24,6 @@ class Smarty_Internal_TemplateCompilerBase {
public $template = null; public $template = null;
// required plugins // required plugins
public $required_plugins_call = array(); public $required_plugins_call = array();
// hash for nocache sections
private $nocache_hash = null;
/** /**
* Initialize compiler * Initialize compiler
@@ -331,10 +333,10 @@ class Smarty_Internal_TemplateCompilerBase {
public function processNocacheCode ($content, $is_code) public function processNocacheCode ($content, $is_code)
{ {
// If the template is not evaluated and we have a nocache section and or a nocache tag // If the template is not evaluated and we have a nocache section and or a nocache tag
if ($is_code) { if ($is_code && !empty($content)) {
// generate replacement code // generate replacement code
if ((!$this->template->resource_object->isEvaluated || $this->template->forceNocache) && $this->template->caching && if ((!$this->template->resource_object->isEvaluated || $this->template->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing &&
($this->nocache || $this->tag_nocache)) { ($this->nocache || $this->tag_nocache || $this->template->forceNocache == 2)) {
$this->tag_nocache = false; $this->tag_nocache = false;
$this->template->has_nocache_code = true; $this->template->has_nocache_code = true;
$_output = str_replace("'", "\'", $content); $_output = str_replace("'", "\'", $content);
@@ -354,6 +356,7 @@ class Smarty_Internal_TemplateCompilerBase {
} else { } else {
$_output = $content; $_output = $content;
} }
$this->suppressNocacheProcessing = false;
return $_output; return $_output;
} }
/** /**