diff --git a/change_log.txt b/change_log.txt index 280d7970..3db75cab 100644 --- a/change_log.txt +++ b/change_log.txt @@ -5,6 +5,7 @@ - move auto load filter methods into extension - move $smarty->getTemplateVars() into extension - move getStreamVariable() into extension + - move $smarty->append() and $smarty->appendByRef() into extension 27.06.2015 - bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64 diff --git a/libs/Autoloader.php b/libs/Autoloader.php index 503c8832..21a9a6bb 100644 --- a/libs/Autoloader.php +++ b/libs/Autoloader.php @@ -82,6 +82,7 @@ class Smarty_Autoloader 'smarty_internal_extension_loadplugin' => true, 'smarty_internal_extension_clearcompiled' => true, 'smarty_internal_extension_getvars' => true, + 'smarty_internal_extension_append' => true, 'smarty_internal_filter_handler' => true, 'smarty_internal_function_call_handler' => true, 'smarty_internal_cacheresource_file' => true, diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index e4ea1483..11fd8ae2 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.28-dev/15'; + const SMARTY_VERSION = '3.1.28-dev/16'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_data.php b/libs/sysplugins/smarty_internal_data.php index 5ea03577..f7efa82d 100644 --- a/libs/sysplugins/smarty_internal_data.php +++ b/libs/sysplugins/smarty_internal_data.php @@ -121,53 +121,7 @@ class Smarty_Internal_Data */ public function append($tpl_var, $value = null, $merge = false, $nocache = false) { - if (is_array($tpl_var)) { - // $tpl_var is an array, ignore $value - foreach ($tpl_var as $_key => $_val) { - if ($_key != '') { - if (!isset($this->tpl_vars[$_key])) { - $tpl_var_inst = $this->getVariable($_key, null, true, false); - if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { - $this->tpl_vars[$_key] = new Smarty_Variable(null, $nocache); - } else { - $this->tpl_vars[$_key] = clone $tpl_var_inst; - } - } - if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) { - settype($this->tpl_vars[$_key]->value, 'array'); - } - if ($merge && is_array($_val)) { - foreach ($_val as $_mkey => $_mval) { - $this->tpl_vars[$_key]->value[$_mkey] = $_mval; - } - } else { - $this->tpl_vars[$_key]->value[] = $_val; - } - } - } - } else { - if ($tpl_var != '' && isset($value)) { - if (!isset($this->tpl_vars[$tpl_var])) { - $tpl_var_inst = $this->getVariable($tpl_var, null, true, false); - if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { - $this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); - } else { - $this->tpl_vars[$tpl_var] = clone $tpl_var_inst; - } - } - 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'); - } - if ($merge && is_array($value)) { - foreach ($value as $_mkey => $_mval) { - $this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval; - } - } else { - $this->tpl_vars[$tpl_var]->value[] = $value; - } - } - } - + Smarty_Internal_Extension_Append::append($this, $tpl_var, $value, $merge, $nocache); return $this; } @@ -182,22 +136,7 @@ class Smarty_Internal_Data */ public function appendByRef($tpl_var, &$value, $merge = false) { - if ($tpl_var != '' && isset($value)) { - if (!isset($this->tpl_vars[$tpl_var])) { - $this->tpl_vars[$tpl_var] = new Smarty_Variable(); - } - if (!is_array($this->tpl_vars[$tpl_var]->value)) { - settype($this->tpl_vars[$tpl_var]->value, 'array'); - } - if ($merge && is_array($value)) { - foreach ($value as $_key => $_val) { - $this->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key]; - } - } else { - $this->tpl_vars[$tpl_var]->value[] = &$value; - } - } - + Smarty_Internal_Extension_Append::appendByRef($this, $tpl_var, $value, $merge); return $this; } diff --git a/libs/sysplugins/smarty_internal_extension_append.php b/libs/sysplugins/smarty_internal_extension_append.php new file mode 100644 index 00000000..0845fb2f --- /dev/null +++ b/libs/sysplugins/smarty_internal_extension_append.php @@ -0,0 +1,105 @@ + $_val) { + if ($_key != '') { + if (!isset($obj->tpl_vars[$_key])) { + $tpl_var_inst = Smarty_Internal_Extension_GetVars::getVariable($obj, $_key, null, true, false); + if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { + $obj->tpl_vars[$_key] = new Smarty_Variable(null, $nocache); + } else { + $obj->tpl_vars[$_key] = clone $tpl_var_inst; + } + } + if (!(is_array($obj->tpl_vars[$_key]->value) || $obj->tpl_vars[$_key]->value instanceof ArrayAccess)) { + settype($obj->tpl_vars[$_key]->value, 'array'); + } + if ($merge && is_array($_val)) { + foreach ($_val as $_mkey => $_mval) { + $obj->tpl_vars[$_key]->value[$_mkey] = $_mval; + } + } else { + $obj->tpl_vars[$_key]->value[] = $_val; + } + } + } + } else { + if ($tpl_var != '' && isset($value)) { + if (!isset($obj->tpl_vars[$tpl_var])) { + $tpl_var_inst = Smarty_Internal_Extension_GetVars::getVariable($obj, $tpl_var, null, true, false); + if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { + $obj->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); + } else { + $obj->tpl_vars[$tpl_var] = clone $tpl_var_inst; + } + } + if (!(is_array($obj->tpl_vars[$tpl_var]->value) || $obj->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) { + settype($obj->tpl_vars[$tpl_var]->value, 'array'); + } + if ($merge && is_array($value)) { + foreach ($value as $_mkey => $_mval) { + $obj->tpl_vars[$tpl_var]->value[$_mkey] = $_mval; + } + } else { + $obj->tpl_vars[$tpl_var]->value[] = $value; + } + } + } + + return $obj; + } + + /** + * appends values to template variables by reference + * + * @param string $tpl_var the template variable name + * @param mixed &$value the referenced value to append + * @param boolean $merge flag if array elements shall be merged + * + * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public static function appendByRef($obj, $tpl_var, &$value, $merge) + { + if ($tpl_var != '' && isset($value)) { + if (!isset($obj->tpl_vars[$tpl_var])) { + $obj->tpl_vars[$tpl_var] = new Smarty_Variable(); + } + if (!is_array($obj->tpl_vars[$tpl_var]->value)) { + settype($obj->tpl_vars[$tpl_var]->value, 'array'); + } + if ($merge && is_array($value)) { + foreach ($value as $_key => $_val) { + $obj->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key]; + } + } else { + $obj->tpl_vars[$tpl_var]->value[] = &$value; + } + } + + return $obj; + } +} \ No newline at end of file