mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
- move $smarty->append() and $smarty->appendByRef() into extension
This commit is contained in:
@@ -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
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
105
libs/sysplugins/smarty_internal_extension_append.php
Normal file
105
libs/sysplugins/smarty_internal_extension_append.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Extension Append
|
||||
*
|
||||
* getStreamVariable() method
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsInternal
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_Internal_Extension_Append
|
||||
{
|
||||
/**
|
||||
* appends values to template variables
|
||||
*
|
||||
* @param array|string $tpl_var the template variable name(s)
|
||||
* @param mixed $value the value to append
|
||||
* @param boolean $merge flag if array elements shall be merged
|
||||
* @param boolean $nocache if true any output of this variable will be not cached
|
||||
*
|
||||
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
|
||||
*/
|
||||
public static function append($obj, $tpl_var, $value, $merge, $nocache)
|
||||
{
|
||||
if (is_array($tpl_var)) {
|
||||
// $tpl_var is an array, ignore $value
|
||||
foreach ($tpl_var as $_key => $_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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user