introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop

This commit is contained in:
uwetews
2015-08-10 21:57:06 +02:00
parent 5c9c57df7d
commit 0260b525b8
10 changed files with 107 additions and 60 deletions
@@ -28,6 +28,7 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$compiler->loopNesting++;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'while', $compiler->nocache);
@@ -38,6 +39,7 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$_output = "<?php\n";
if (is_array($parameter['if condition'])) {
if ($compiler->nocache) {
$_nocache = ',true';
@@ -56,7 +58,7 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
$_nocache = '';
}
if (is_array($parameter['if condition']['var'])) {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
"]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] .
"$_nocache);\n";
@@ -64,17 +66,16 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
$parameter['if condition']['value'] . ") {?>";
} else {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
"])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
"] = new Smarty_Variable(null{$_nocache});";
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
$parameter['if condition']['value'] . ") {?>";
}
return $_output;
} else {
return "<?php while ({$parameter['if condition']}) {?>";
}
$_output .= "while ({$parameter['if condition']}) {?>";
}
return $_output;
}
}
@@ -96,12 +97,12 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->loopNesting--;
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
$compiler->nocache = $this->closeTag($compiler, array('while'));
return "<?php }?>";
return "<?php }?>\n";
}
}