mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- bugfix broken PHP 5.2 compatibility https://github.com/smarty-php/smarty/issues/139
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
===== 3.1.29-dev ===== (xx.xx.2015)
|
===== 3.1.29-dev ===== (xx.xx.2015)
|
||||||
19.12.2015
|
19.12.2015
|
||||||
- bugfix using $smarty.capture.foo in expressions could fail https://github.com/smarty-php/smarty/pull/138
|
- 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
|
- remove no longer used code
|
||||||
- improvement make sure that compiled and cache templates never can contain a trailing '?>?
|
- improvement make sure that compiled and cache templates never can contain a trailing '?>?
|
||||||
|
|
||||||
|
@@ -118,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.29-dev/12';
|
const SMARTY_VERSION = '3.1.29-dev/13';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -59,7 +59,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
|||||||
*
|
*
|
||||||
* @var array
|
* @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
|
* Valid properties of $item@xxx variable
|
||||||
|
@@ -50,7 +50,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $nameProperties = array();
|
public $nameProperties = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {section} tag has no item properties
|
* {section} tag has no item properties
|
||||||
@@ -112,8 +112,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
|
|||||||
if ($named) {
|
if ($named) {
|
||||||
$this->resultOffsets['named'] = $this->startOffset + 3;
|
$this->resultOffsets['named'] = $this->startOffset + 3;
|
||||||
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
|
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
|
||||||
$className = get_class($this);
|
$properties = $this->nameProperties;
|
||||||
$properties = $className::$nameProperties;
|
|
||||||
} else {
|
} else {
|
||||||
$this->resultOffsets['item'] = $this->startOffset + 3;
|
$this->resultOffsets['item'] = $this->startOffset + 3;
|
||||||
$this->propertyPreg .= "([\$]{$attributes['item']}[@](";
|
$this->propertyPreg .= "([\$]{$attributes['item']}[@](";
|
||||||
@@ -204,17 +203,15 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
|
|||||||
* @return string compiled code
|
* @return string compiled code
|
||||||
* @throws \SmartyCompilerException
|
* @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 ], '"\''));
|
$tag = strtolower(trim($parameter[ 0 ], '"\''));
|
||||||
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
|
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
|
||||||
if (!$name) {
|
if (!$name) {
|
||||||
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
|
$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;
|
$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);
|
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true);
|
||||||
}
|
}
|
||||||
$tagVar = "'__smarty_{$tag}_{$name}'";
|
$tagVar = "'__smarty_{$tag}_{$name}'";
|
||||||
|
@@ -29,7 +29,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
|||||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||||
{
|
{
|
||||||
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
|
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
|
||||||
$variable = strtolower($compiler->getId($_index[0]));
|
$variable = strtolower($compiler->getId($_index[ 0 ]));
|
||||||
if ($variable === false) {
|
if ($variable === false) {
|
||||||
$compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
|
$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) {
|
switch ($variable) {
|
||||||
case 'foreach':
|
case 'foreach':
|
||||||
case 'section':
|
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':
|
case 'capture':
|
||||||
if (class_exists('Smarty_Internal_Compile_Capture')) {
|
if (class_exists('Smarty_Internal_Compile_Capture')) {
|
||||||
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
|
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");
|
$compiler->trigger_template_error("(secure mode) constants not permitted");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strpos($_index[1], '$') === false && strpos($_index[1], '\'') === false) {
|
if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
|
||||||
return "@constant('{$_index[1]}')";
|
return "@constant('{$_index[1]}')";
|
||||||
} else {
|
} else {
|
||||||
return "@constant({$_index[1]})";
|
return "@constant({$_index[1]})";
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'config':
|
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)";
|
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
|
||||||
} else {
|
} else {
|
||||||
return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
|
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'";
|
return "'$_rdelim'";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
|
$compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is invalid');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (isset($_index[1])) {
|
if (isset($_index[ 1 ])) {
|
||||||
array_shift($_index);
|
array_shift($_index);
|
||||||
foreach ($_index as $_ind) {
|
foreach ($_index as $_ind) {
|
||||||
$compiled_ref = $compiled_ref . "[$_ind]";
|
$compiled_ref = $compiled_ref . "[$_ind]";
|
||||||
|
@@ -59,7 +59,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
|||||||
*
|
*
|
||||||
* @var array
|
* @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');
|
'index_prev', 'index_next');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user