- bugfix on assigning multidimensional arrays within templates

- corrected bugfix for truncate modifier
This commit is contained in:
Uwe.Tews
2010-07-08 18:30:03 +00:00
parent 396d7aa8a5
commit db38a0aaec
5 changed files with 52 additions and 29 deletions

View File

@@ -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

View File

@@ -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));

View File

@@ -1,25 +1,25 @@
<?php
/**
* Smarty Internal Plugin Compile Assign
*
* Compiles the {assign} tag
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
* Smarty Internal Plugin Compile Assign
*
* Compiles the {assign} tag
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Assign Class
*/
* Smarty Internal Plugin Compile Assign Class
*/
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
/**
* Compiles code for the {assign} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @return string compiled code
*/
* Compiles code for the {assign} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @return string compiled code
*/
public function compile($args, $compiler)
{
$this->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 "<?php \$_smarty_tpl->append($_attr[var],$_attr[value],false,$_nocache,$_scope);?>";
} else {
return "<?php \$_tmp$_attr[smarty_internal_index] = $_attr[value]; \$_smarty_tpl->append($_attr[var],\$_tmp,true,$_nocache,$_scope); unset (\$_tmp);?>";
}
return "<?php if (!isset(\$_smarty_tpl->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 "<?php \$_smarty_tpl->assign($_attr[var],$_attr[value],$_nocache,$_scope);?>";
return "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);?>";
}
}
}
?>
?>

View File

@@ -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
*/

View File

@@ -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)