diff --git a/change_log.txt b/change_log.txt index 37aaa80c..827c12c7 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,7 @@ +08/07/2010 +- bugfix on assigning multidimensional arrays within templates +- corrected bugfix for truncate modifier + 07/07/2010 - bugfix the truncate modifier needs to check if the string is utf-8 encoded or not - bugfix support of script files relative to trusted_dir diff --git a/libs/plugins/modifier.truncate.php b/libs/plugins/modifier.truncate.php index ead4ec5b..308fd48c 100644 --- a/libs/plugins/modifier.truncate.php +++ b/libs/plugins/modifier.truncate.php @@ -31,7 +31,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', return ''; if (is_callable('mb_strlen')) { - if (mb_detect_encoding($text, 'UTF-8, ISO-8859-1') === 'UTF-8') { + if (mb_detect_encoding($string, 'UTF-8, ISO-8859-1') === 'UTF-8') { // $string has utf-8 encoding if (mb_strlen($string) > $length) { $length -= min($length, mb_strlen($etc)); diff --git a/libs/sysplugins/smarty_internal_compile_assign.php b/libs/sysplugins/smarty_internal_compile_assign.php index 57c4ce70..9d907278 100644 --- a/libs/sysplugins/smarty_internal_compile_assign.php +++ b/libs/sysplugins/smarty_internal_compile_assign.php @@ -1,25 +1,25 @@ compiler = $compiler; @@ -45,21 +45,17 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase { $_scope = SMARTY_PARENT_SCOPE; } elseif ($_attr['scope'] == '\'root\'') { $_scope = SMARTY_ROOT_SCOPE; - } elseif ($_attr['scope'] == '\'global\'') { + } elseif ($_attr['scope'] == '\'global\'') { $_scope = SMARTY_GLOBAL_SCOPE; } } // compiled output if (isset($_attr['smarty_internal_index'])) { - if ($_attr['smarty_internal_index'] == '') { - return "append($_attr[var],$_attr[value],false,$_nocache,$_scope);?>"; - } else { - return "append($_attr[var],\$_tmp,true,$_nocache,$_scope); unset (\$_tmp);?>"; - } + return "tpl_vars[$_attr[var]]) || !is_array(\$_smarty_tpl->tpl_vars[$_attr[var]]->value)) \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$_attr[smarty_internal_index] = $_attr[value];?>"; } else { - return "assign($_attr[var],$_attr[value],$_nocache,$_scope);?>"; + return "tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);?>"; } } } -?> +?> \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index bb334595..24059dba 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -806,6 +806,26 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { } } + /** + * creates a loacal Smarty variable for array assihgments + */ + public function createLocalArrayVariable($tpl_var, $nocache = false, $scope = SMARTY_LOCAL_SCOPE) + { + if (!isset($this->tpl_vars[$tpl_var])) { + $tpl_var_inst = $this->getVariable($tpl_var, null, true, false); + if ($tpl_var_inst instanceof Undefined_Smarty_Variable) { + $this->tpl_vars[$tpl_var] = new Smarty_variable(array(), $nocache, $scope); + } else { + $this->tpl_vars[$tpl_var] = clone $tpl_var_inst; + if ($scope != SMARTY_LOCAL_SCOPE) { + $this->tpl_vars[$tpl_var]->scope = $scope; + } + } + } + if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) { + settype($this->tpl_vars[$tpl_var]->value, 'array'); + } + } /** * wrapper for display */ diff --git a/libs/sysplugins/smarty_internal_templateparser.php b/libs/sysplugins/smarty_internal_templateparser.php index d4c69f71..444d596e 100644 --- a/libs/sysplugins/smarty_internal_templateparser.php +++ b/libs/sysplugins/smarty_internal_templateparser.php @@ -1997,7 +1997,6 @@ static public $yy_action = array( 121 => 121, 122 => 122, 124 => 124, - 185 => 124, 126 => 126, 127 => 127, 128 => 128, @@ -2049,6 +2048,7 @@ static public $yy_action = array( 181 => 181, 182 => 182, 183 => 183, + 185 => 185, ); #line 92 "smarty_internal_templateparser.y" function yy_r0(){ $this->_retvalue = $this->yystack[$this->yyidx + 0]->minor; } @@ -2456,7 +2456,7 @@ static public $yy_action = array( function yy_r122(){ $this->_retvalue = '['.$this->compiler->compileTag('private_special_variable','[\'section\'][\''.$this->yystack[$this->yyidx + -3]->minor.'\'][\''.$this->yystack[$this->yyidx + -1]->minor.'\']').']'; } #line 2453 "smarty_internal_templateparser.php" #line 484 "smarty_internal_templateparser.y" - function yy_r124(){$this->_retvalue = ''; } + function yy_r124(){$this->_retvalue = '[]'; } #line 2456 "smarty_internal_templateparser.php" #line 492 "smarty_internal_templateparser.y" function yy_r126(){$this->_retvalue = $this->yystack[$this->yyidx + -1]->minor.'.'.$this->yystack[$this->yyidx + 0]->minor; } @@ -2614,6 +2614,9 @@ static public $yy_action = array( #line 624 "smarty_internal_templateparser.y" function yy_r183(){ $this->_retvalue = new _smarty_dq_content($this, $this->yystack[$this->yyidx + 0]->minor); } #line 2612 "smarty_internal_templateparser.php" +#line 631 "smarty_internal_templateparser.y" + function yy_r185(){$this->_retvalue = ''; } +#line 2615 "smarty_internal_templateparser.php" private $_retvalue; @@ -2675,7 +2678,7 @@ static public $yy_action = array( $this->internalError = true; $this->yymajor = $yymajor; $this->compiler->trigger_template_error(); -#line 2675 "smarty_internal_templateparser.php" +#line 2678 "smarty_internal_templateparser.php" } function yy_accept() @@ -2692,7 +2695,7 @@ static public $yy_action = array( $this->internalError = false; $this->retvalue = $this->_retvalue; //echo $this->retvalue."\n\n"; -#line 2693 "smarty_internal_templateparser.php" +#line 2696 "smarty_internal_templateparser.php" } function doParse($yymajor, $yytokenvalue)