From dc9872e0e2d50abd67ecb7c8f735df1f91ce3de2 Mon Sep 17 00:00:00 2001 From: uwetews Date: Sat, 19 Dec 2015 21:55:32 +0100 Subject: [PATCH] - bugfix broken PHP 5.2 compatibility https://github.com/smarty-php/smarty/issues/139 --- change_log.txt | 2 +- libs/Smarty.class.php | 2 +- .../smarty_internal_compile_foreach.php | 2 +- ...y_internal_compile_private_foreachsection.php | 11 ++++------- ...internal_compile_private_special_variable.php | 16 ++++++++++------ .../smarty_internal_compile_section.php | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/change_log.txt b/change_log.txt index 73ea00d4..c3198b05 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,7 +1,7 @@  ===== 3.1.29-dev ===== (xx.xx.2015) 19.12.2015 - bugfix using $smarty.capture.foo in expressions could fail https://github.com/smarty-php/smarty/pull/138 - - bugfix broken PHP 5.2 compatibility + - bugfix broken PHP 5.2 compatibility https://github.com/smarty-php/smarty/issues/139 - remove no longer used code - improvement make sure that compiled and cache templates never can contain a trailing '?>? diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 2cc7ea76..074a4a8d 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -118,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.29-dev/12'; + const SMARTY_VERSION = '3.1.29-dev/13'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_foreach.php b/libs/sysplugins/smarty_internal_compile_foreach.php index fd301aab..178a0a52 100644 --- a/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/libs/sysplugins/smarty_internal_compile_foreach.php @@ -59,7 +59,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo * * @var array */ - public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total'); + public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total'); /** * Valid properties of $item@xxx variable diff --git a/libs/sysplugins/smarty_internal_compile_private_foreachsection.php b/libs/sysplugins/smarty_internal_compile_private_foreachsection.php index 50c25bdb..16f23335 100644 --- a/libs/sysplugins/smarty_internal_compile_private_foreachsection.php +++ b/libs/sysplugins/smarty_internal_compile_private_foreachsection.php @@ -50,7 +50,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com * * @var array */ - public static $nameProperties = array(); + public $nameProperties = array(); /** * {section} tag has no item properties @@ -112,8 +112,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com if ($named) { $this->resultOffsets['named'] = $this->startOffset + 3; $this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.]("; - $className = get_class($this); - $properties = $className::$nameProperties; + $properties = $this->nameProperties; } else { $this->resultOffsets['item'] = $this->startOffset + 3; $this->propertyPreg .= "([\$]{$attributes['item']}[@]("; @@ -204,17 +203,15 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com * @return string compiled code * @throws \SmartyCompilerException */ - public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) + public function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { $tag = strtolower(trim($parameter[ 0 ], '"\'')); $name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false; if (!$name) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); } - /* @var Smarty_Internal_Compile_Foreach|Smarty_Internal_Compile_Section $className */ - $className = 'Smarty_Internal_Compile_' . ucfirst($tag); $property = isset($parameter[ 2 ]) ? strtolower($compiler->getId($parameter[ 2 ])) : false; - if (!$property || !in_array($property, $className::$nameProperties)) { + if (!$property || !in_array($property, $this->nameProperties)) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true); } $tagVar = "'__smarty_{$tag}_{$name}'"; diff --git a/libs/sysplugins/smarty_internal_compile_private_special_variable.php b/libs/sysplugins/smarty_internal_compile_private_special_variable.php index e3cd2877..7092fc54 100644 --- a/libs/sysplugins/smarty_internal_compile_private_special_variable.php +++ b/libs/sysplugins/smarty_internal_compile_private_special_variable.php @@ -29,7 +29,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2)); - $variable = strtolower($compiler->getId($_index[0])); + $variable = strtolower($compiler->getId($_index[ 0 ])); if ($variable === false) { $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true); } @@ -39,7 +39,11 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C switch ($variable) { case 'foreach': case 'section': - return Smarty_Internal_Compile_Private_ForeachSection::compileSpecialVariable(array(), $compiler, $_index); + if (!isset($compiler->_tag_objects[ $variable ])) { + $class = 'Smarty_Internal_Compile_' . ucfirst($variable); + $compiler->_tag_objects[ $variable ] = new $class; + } + return $compiler->_tag_objects[ $variable ]->compileSpecialVariable(array(), $compiler, $_index); case 'capture': if (class_exists('Smarty_Internal_Compile_Capture')) { return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); @@ -92,14 +96,14 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C $compiler->trigger_template_error("(secure mode) constants not permitted"); break; } - if (strpos($_index[1], '$') === false && strpos($_index[1], '\'') === false) { + if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) { return "@constant('{$_index[1]}')"; } else { return "@constant({$_index[1]})"; } case 'config': - if (isset($_index[2])) { + if (isset($_index[ 2 ])) { return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)"; } else { return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])"; @@ -115,10 +119,10 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C return "'$_rdelim'"; default: - $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid'); + $compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is invalid'); break; } - if (isset($_index[1])) { + if (isset($_index[ 1 ])) { array_shift($_index); foreach ($_index as $_ind) { $compiled_ref = $compiled_ref . "[$_ind]"; diff --git a/libs/sysplugins/smarty_internal_compile_section.php b/libs/sysplugins/smarty_internal_compile_section.php index dccbc0ff..40b297a6 100644 --- a/libs/sysplugins/smarty_internal_compile_section.php +++ b/libs/sysplugins/smarty_internal_compile_section.php @@ -59,7 +59,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo * * @var array */ - public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', + public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', 'index_prev', 'index_next'); /**