diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index c6b26e30..8351e4f0 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.28-dev/44'; + const SMARTY_VERSION = '3.1.28-dev/45'; /** * define variable scopes @@ -192,6 +192,17 @@ class Smarty extends Smarty_Internal_TemplateBase const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler'; + /** + * Resource caching modes + */ + const RESOURCE_CACHE_OFF = 0; + + const RESOURCE_CACHE_AUTOMATIC = 1; // cache template objects by rules + + const RESOURCE_CACHE_TEMPLATE = 2; // cache all template objects + + const RESOURCE_CACHE_ON = 4; // cache source nad compiled resources + /**#@-*/ /** @@ -582,14 +593,7 @@ class Smarty extends Smarty_Internal_TemplateBase * * @var bool */ - public $resource_caching = false; - - /** - * enable template resource caching - * - * @var bool - */ - public $template_resource_caching = true; + public $resource_cache_mode = 1; /** * check If-Modified-Since headers @@ -724,6 +728,13 @@ class Smarty extends Smarty_Internal_TemplateBase */ public $_parserdebug = false; + /** + * removed properties + * + * @var array + */ + public $obsoleteProperties = array('resource_caching', 'template_resource_caching'); + /**#@-*/ /** @@ -1610,6 +1621,8 @@ class Smarty extends Smarty_Internal_TemplateBase if (isset($allowed[$name])) { return $this->{$allowed[$name]}(); + } elseif (in_array($name, $this->obsoleteProperties)) { + return null; } else { trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); } @@ -1631,6 +1644,8 @@ class Smarty extends Smarty_Internal_TemplateBase if (isset($allowed[$name])) { $this->{$allowed[$name]}($value); + } elseif (in_array($name, $this->obsoleteProperties)) { + return; } else { trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); } diff --git a/libs/sysplugins/smarty_internal_compile_for.php b/libs/sysplugins/smarty_internal_compile_for.php index 5bac5501..7b86d485 100644 --- a/libs/sysplugins/smarty_internal_compile_for.php +++ b/libs/sysplugins/smarty_internal_compile_for.php @@ -34,6 +34,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase */ public function compile($args, $compiler, $parameter) { + $compiler->loopNesting++; if ($parameter == 0) { $this->required_attributes = array('start', 'to'); $this->optional_attributes = array('max', 'step'); @@ -44,7 +45,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase // check and get attributes $_attr = $this->getAttributes($compiler, $args); - $output = "tpl_vars[$var] = new Smarty_Variable;"; - $output .= " \$_smarty_tpl->tpl_vars[$var]->value{$index} = $_statement[value];\n"; + $output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;\n"; + $output .= "\$_smarty_tpl->tpl_vars[$var]->value{$index} = {$_statement['value']};\n"; } if (is_array($_attr['var'])) { $var = $_attr['var']['var']; @@ -64,7 +65,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase $var = $_attr['var']; $index = ''; } - $output .= " if ($_attr[ifexp]) { for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n"; + $output .= "if ($_attr[ifexp]) {\nfor (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n"; } else { $_statement = $_attr['start']; if (is_array($_statement['var'])) { @@ -148,6 +149,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase */ public function compile($args, $compiler, $parameter) { + $compiler->loopNesting--; // check and get attributes $_attr = $this->getAttributes($compiler, $args); // must endblock be nocache? @@ -157,10 +159,11 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse')); - if ($openTag == 'forelse') { - return ""; - } else { - return ""; - } + $output = "\n"; + return $output; } } diff --git a/libs/sysplugins/smarty_internal_compile_foreach.php b/libs/sysplugins/smarty_internal_compile_foreach.php index b19d8a9e..f7f7b472 100644 --- a/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/libs/sysplugins/smarty_internal_compile_foreach.php @@ -87,6 +87,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { + $compiler->loopNesting++; // init $this->isNamed = false; // check and get attributes @@ -317,8 +318,7 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); + $compiler->loopNesting--; // must endblock be nocache? if ($compiler->nocache) { $compiler->tag_nocache = true; diff --git a/libs/sysplugins/smarty_internal_compile_function.php b/libs/sysplugins/smarty_internal_compile_function.php index eddef0f8..b8139fd0 100644 --- a/libs/sysplugins/smarty_internal_compile_function.php +++ b/libs/sysplugins/smarty_internal_compile_function.php @@ -53,6 +53,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { + $compiler->loopNesting++; // check and get attributes $_attr = $this->getAttributes($compiler, $args); @@ -101,6 +102,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { + $compiler->loopNesting--; $this->compiler = $compiler; $saved_data = $this->closeTag($compiler, array('function')); $_attr = $saved_data[0]; diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php index 84ae64c2..22d535f2 100644 --- a/libs/sysplugins/smarty_internal_compile_include.php +++ b/libs/sysplugins/smarty_internal_compile_include.php @@ -88,6 +88,12 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase } } + // + if ($compiler->loopNesting > 0) { + $_cache_tpl = 'true'; + } else { + $_cache_tpl = 'false'; + } // assume caching is off $_caching = Smarty::CACHING_OFF; @@ -271,9 +277,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase //$compiler->suppressNocacheProcessing = true; } if (isset($_assign)) { - $_output .= " \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}'));\n"; + $_output .= " \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}'));\n"; } else { - $_output .= "echo \$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}');\n"; + $_output .= "echo \$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, {$_cache_tpl}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}');\n"; } if ($update_compile_id) { $_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"); @@ -292,9 +298,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase } // was there an assign attribute if (isset($_assign)) { - $_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope));\n"; + $_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, {$_cache_tpl}));\n"; } else { - $_output .= "echo \$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope);\n"; + $_output .= "echo \$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, {$_cache_tpl});\n"; } if ($update_compile_id) { $_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"; diff --git a/libs/sysplugins/smarty_internal_compile_section.php b/libs/sysplugins/smarty_internal_compile_section.php index f0f9853d..079903c2 100644 --- a/libs/sysplugins/smarty_internal_compile_section.php +++ b/libs/sysplugins/smarty_internal_compile_section.php @@ -87,6 +87,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) { + $compiler->loopNesting++; // check and get attributes $_attr = $this->getAttributes($compiler, $args); $attributes = array('name' => $compiler->getId($_attr['name'])); @@ -118,7 +119,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo $namedAttr = $this->matchResults['named']; } $namedAttr['index'] = true; - $output = " $attr_value) { switch ($attr_name) { case 'loop': @@ -428,9 +429,7 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) { - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - + $compiler->loopNesting--; // must endblock be nocache? if ($compiler->nocache) { $compiler->tag_nocache = true; diff --git a/libs/sysplugins/smarty_internal_compile_while.php b/libs/sysplugins/smarty_internal_compile_while.php index 2f484888..233cc729 100644 --- a/libs/sysplugins/smarty_internal_compile_while.php +++ b/libs/sysplugins/smarty_internal_compile_while.php @@ -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 = "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 = "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 = "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 ""; - } + $_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 ""; + return "\n"; } } diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index a51e1cb8..c0c3e2ef 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -83,6 +83,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public $_capture_stack = array(0 => array()); + /** + * Template Id + * + * @var string + */ + public $templateId = ''; + /** * Known template functions * @@ -118,6 +125,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase // Template resource $this->template_resource = $template_resource; $this->source = Smarty_Template_Source::load($this); + $this->templateId = $this->getTemplateId($template_resource, $this->cache_id, $this->compile_id); // copy block data of template inheritance if ($this->parent instanceof Smarty_Internal_Template) { $this->block_data = $this->parent->block_data; @@ -448,9 +456,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase * * @returns string template content */ - public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope) + public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $cache_tpl) { - $tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope); + $tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $cache_tpl); return $tpl->render(); } @@ -467,28 +475,28 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase * * @returns \Smarty_Internal_Template template object */ - public function setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope) + public function setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $cache_tpl) { - $tpl = $_templateId = null; - if ($this->smarty->template_resource_caching) { - $_templateId = $this->getTemplateId($template, $cache_id, $compile_id); - // already in template cache? - if (isset($this->smarty->template_objects[$_templateId])) { - // clone cached template object because of possible recursive call - $tpl = clone $this->smarty->template_objects[$_templateId]; - $tpl->parent = $this; - if ((bool) $tpl->caching !== (bool) $caching) { - unset($tpl->compiled); - } - $tpl->caching = $caching; - $tpl->cache_lifetime = $cache_lifetime; + $_templateId = $this->getTemplateId($template, $cache_id, $compile_id); + // already in template cache? + if (isset($this->smarty->template_objects[$_templateId])) { + // clone cached template object because of possible recursive call + $tpl = clone $this->smarty->template_objects[$_templateId]; + $tpl->parent = $this; + if ((bool) $tpl->caching !== (bool) $caching) { + unset($tpl->compiled); } - } - if (!isset($tpl)) { + $tpl->caching = $caching; + $tpl->cache_lifetime = $cache_lifetime; + } else { $tpl = new $this->smarty->template_class($template, $this->smarty, $this, $cache_id, $compile_id, $caching, $cache_lifetime); - if ($this->smarty->template_resource_caching && !$tpl->source->recompiled) { - $this->smarty->template_objects[$_templateId] = $tpl; - } + } + if (!$tpl->source->recompiled && !isset($this->smarty->template_objects[$_templateId]) && + (isset($this->smarty->template_objects[$this->templateId]) || + ($cache_tpl && $this->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_AUTOMATIC) || + $this->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) + ) { + $this->smarty->template_objects[$_templateId] = $tpl; } if ($caching == 9999) { $tpl->cached = $this->cached; @@ -531,9 +539,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase * * @returns object template content */ - public function getInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $hash, $content_func) + public function getInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $cache_tpl, $hash, $content_func) { - $tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope); + $tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $cache_tpl); + if (!isset($tpl->compiled)) { + $tpl->compiled = $this->compiled; + } $tpl->compiled->nocache_hash = $hash; if ($this->smarty->debugging) { Smarty_Internal_Debug::start_template($tpl); diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index f5238b2b..6c2f5ad5 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -178,7 +178,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data { $smarty = isset($this->smarty) ? $this->smarty : $this; $smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, - false); + false); return $this; } @@ -457,6 +457,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data $status = true; } elseif (property_exists($this->smarty, $property_name)) { $status = false; + } elseif (in_array($name, $this->smarty->obsoleteProperties)) { + return null; + } else { } $_resolved_property_source[$property_name] = $status; } diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index b8a5791a..1569b4ba 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -319,6 +319,13 @@ abstract class Smarty_Internal_TemplateCompilerBase */ public $variable_filter_stack = array(); + /** + * Loop nesting count + * + * @var int + */ + public $loopNesting = 0; + /** * Strip preg pattern *