Commit 7e30c1dd authored by Mario's avatar Mario

update smarty to version 3.1.29

parent 78bf4564
......@@ -21,17 +21,17 @@ Smarty 3.1.28
fetch() and display()
=====================
The fetch() and display() methods of the template object accept now optionally the same parameter
as the corresponding Smarty methods to get tne content of another template.
as the corresponding Smarty methods to get the content of another template.
Example:
$template->display(); Does display template of template object
$template->dispaly('foo.tpl'); Does display template 'foo.bar'
$template->display('foo.tpl'); Does display template 'foo.bar'
File: resource
==============
Multiple template_dir entries can now be selected by a comma separated list of indices.
The template_dir array is searched in the order of the indices. (Could be used to change the default search order)
Example:
$smarty->display([1],[0]foo.bar');
$smarty->display('[1],[0]foo.bar');
Filter support
==============
......@@ -130,4 +130,4 @@ Smarty 3.1.22
Smarty::DEBUG_INDIVIDUAL will create for each display() and fetch() call an individual debug window.
.
\ No newline at end of file
 ===== 3.1.28 ===== (13.12.2015)
 ===== 3.1.29 ===== (21.12.2015)
21.12.2015
- optimization improve speed of filetime checks on extends and extendsall resource
20.12.2015
- bugfix failure when the default resource type was set to 'extendsall' https://github.com/smarty-php/smarty/issues/123
- update compilation of Smarty special variables
- bugfix add addition check for OS type on normalizaition of file path https://github.com/smarty-php/smarty/issues/134
- bugfix the source uid of the extendsall resource must contain $template_dir settings https://github.com/smarty-php/smarty/issues/123
19.12.2015
- bugfix using $smarty.capture.foo in expressions could fail https://github.com/smarty-php/smarty/pull/138
- bugfix broken PHP 5.2 compatibility https://github.com/smarty-php/smarty/issues/139
- remove no longer used code
- improvement make sure that compiled and cache templates never can contain a trailing '?>?
18.12.2015
- bugfix regression when modifier parameter was follow by math https://github.com/smarty-php/smarty/issues/132
17.12.2015
- bugfix {$smarty.capture.nameFail} did lowercase capture name https://github.com/smarty-php/smarty/issues/135
- bugfix using {block append/prepend} on same block in multiple levels of inheritance templates could fail (forum topic 25827)
- bugfix text content consisting of just a single '0' like in {if true}0{/if} was suppressed (forum topic 25834)
16.12.2015
- bugfix {foreach} did fail if from atrribute is a Generator class https://github.com/smarty-php/smarty/issues/128
- bugfix direct access $smarty->template_dir = 'foo'; should call Smarty::setTemplateDir() https://github.com/smarty-php/smarty/issues/121
15.12.2015
- bugfix {$smarty.cookies.foo} did return the $_COOKIE array not the 'foo' value https://github.com/smarty-php/smarty/issues/122
- bugfix a call to clearAllCache() and other should clear all internal template object caches (forum topic 25828)
14.12.2015
- bugfix {$smarty.config.foo} broken in 3.1.28 https://github.com/smarty-php/smarty/issues/120
- bugfix multiple calls of {section} with same name droped E_NOTICE error https://github.com/smarty-php/smarty/issues/118
===== 3.1.28 ===== (13.12.2015)
13.12.2015
- bugfix {foreach} and {section} with uppercase characters in name attribute did not work (forum topic 25819)
- bugfix $smarty->debugging_ctrl = 'URL' did not work (forum topic 25811)
- bugfix Debug Console could display incorrect data when using subtemplates
09.12.2015
- bugix Smarty did fail under PHP 7.0.0 with use_include_path = true;
- bugfix Smarty did fail under PHP 7.0.0 with use_include_path = true;
09.12.2015
-bugfix {strip} should exclude some html tags from stripping, related to fix for https://github.com/smarty-php/smarty/issues/111
- bugfix {strip} should exclude some html tags from stripping, related to fix for https://github.com/smarty-php/smarty/issues/111
08.12.2015
- bugfix internal template function data got stored in wrong compiled file https://github.com/smarty-php/smarty/issues/114
......
......@@ -27,7 +27,7 @@
* @author Uwe Tews
* @author Rodney Rehm
* @package Smarty
* @version 3.1.28
* @version 3.1.29
*/
/**
......@@ -118,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.28';
const SMARTY_VERSION = '3.1.29';
/**
* define variable scopes
......@@ -677,15 +677,20 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* removed properties
*
* @var array
* @var string[]
*/
private static $obsoleteProperties = array('resource_caching', 'template_resource_caching',
'direct_access_security', '_dir_perms', '_file_perms',
'plugin_search_order', 'inheritance_merge_compiled_includes');
private static $accessMap = array('template_dir' => 'getTemplateDir', 'config_dir' => 'getConfigDir',
'plugins_dir' => 'getPluginsDir', 'compile_dir' => 'getCompileDir',
'cache_dir' => 'getCacheDir',);
/**
* List of private properties which will call getter/setter ona direct access
*
* @var array
*/
private static $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
'cache_dir' => 'CacheDir',);
/**#@-*/
......@@ -1173,7 +1178,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$path = str_replace($nds, DS, $path);
}
if ($realpath === true && $path[0] !== '/' && $path[1] !== ':') {
if ($realpath === true && (($path[0] !== '/' && DS == '/') || ($path[1] !== ':' && DS != '/'))) {
$path = getcwd() . DS . $path;
}
while ((strpos($path, '.' . DS) !== false) || (strpos($path, DS . DS) !== false)) {
......@@ -1344,7 +1349,8 @@ class Smarty extends Smarty_Internal_TemplateBase
{
if (isset(self::$accessMap[$name])) {
return $this->{self::$accessMap[$name]}();
$method = 'get' . self::$accessMap[$name];
return $this->{$method}();
} elseif (in_array($name, self::$obsoleteProperties)) {
return null;
} else {
......@@ -1363,7 +1369,8 @@ class Smarty extends Smarty_Internal_TemplateBase
public function __set($name, $value)
{
if (isset(self::$accessMap[$name])) {
$this->{self::$accessMap[$name]}($value);
$method = 'set' . self::$accessMap[$name];
$this->{$method}($value);
} elseif (in_array($name, self::$obsoleteProperties)) {
return;
} else {
......
......@@ -215,12 +215,9 @@ abstract class Smarty_CacheResource
*/
public function invalidLoadedCache(Smarty $smarty)
{
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if (isset($tpl->cached)) {
unset ($smarty->_cache['template_objects'][$key]);
}
}
$smarty->_cache['isCached'] = array();
if (isset($smarty->ext->_subtemplate)) {
$smarty->ext->_subtemplate->tplObjects = array();
}
}
}
......@@ -142,7 +142,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
}
$compiler->suppressNocacheProcessing = true;
$compiler->has_code = true;
$output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 3, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
$output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 4, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
return $output;
}
}
......
......@@ -69,13 +69,12 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
*/
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// make all lower case
$parameter = array_map('strtolower', $parameter);
$tag = trim($parameter[0], '"\'');
if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) {
$tag = strtolower(trim($parameter[ 0 ], '"\''));
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
if (!$name) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
}
return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null";
return "(isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null)";
}
}
......
......@@ -59,7 +59,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
*
* @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
......@@ -183,8 +183,10 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
foreach ($saveVars as $k => $code) {
$output .= "{$local}{$k} = {$code}\n";
}
if (isset($itemAttr['show']) || isset($itemAttr['total']) || isset($namedAttr['total']) || isset($namedAttr['show']) || isset($itemAttr['last']) || isset($namedAttr['last'])) {
$output .= "{$local}total = \$_smarty_tpl->smarty->ext->_foreach->count(\$_from);\n";
}
$output .= "{$itemVar} = new Smarty_Variable();\n";
$output .= "{$local}total = \$_smarty_tpl->smarty->ext->_foreach->count(\$_from);\n";
if (isset($itemAttr['show'])) {
$output .= "{$itemVar}->show = ({$local}total > 0);\n";
}
......@@ -210,7 +212,6 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
$output .= "{$foreachVar} = new Smarty_Variable({$_vars});\n";
}
}
$output .= "if ({$local}total) {\n";
if (isset($attributes['key'])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}'] = new Smarty_Variable();\n";
}
......@@ -226,7 +227,9 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
if ($needIteration) {
$output .= "{$local}iteration=0;\n";
}
$output .= "{$itemVar}->_loop = false;\n";
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
$output .= "{$itemVar}->_loop = true;\n";
if (isset($attributes['key']) && isset($itemAttr['key'])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
}
......@@ -296,7 +299,7 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
$output = "<?php\n";
$output .= "{$itemVar} = {$local}saved_local_item;\n";
$output .= "}\n";
$output .= "} else {\n?>";
$output .= "if (!{$itemVar}->_loop) {\n?>";
return $output;
}
}
......@@ -332,7 +335,6 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
if ($restore) {
$output .= "{$itemVar} = {$local}saved_local_item;\n";
$output .= "}\n";
}
$output .= "}\n";
foreach ($restoreVars as $restore) {
......
......@@ -50,7 +50,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*
* @var array
*/
public static $nameProperties = array();
public $nameProperties = array();
/**
* {section} tag has no item properties
......@@ -112,8 +112,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
if ($named) {
$this->resultOffsets['named'] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
$className = get_class($this);
$properties = $className::$nameProperties;
$properties = $this->nameProperties;
} else {
$this->resultOffsets['item'] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]{$attributes['item']}[@](";
......@@ -204,17 +203,15 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
* @return string compiled code
* @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 ], '"\''));
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
if (!$name) {
$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;
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);
}
$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)
{
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
$variable = strtolower($compiler->getId($_index[0]));
$variable = strtolower($compiler->getId($_index[ 0 ]));
if ($variable === false) {
$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) {
case 'foreach':
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':
if (class_exists('Smarty_Internal_Compile_Capture')) {
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
......@@ -54,7 +58,8 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
$compiler->trigger_template_error("(secure mode) super globals not permitted");
break;
}
return '$_COOKIE';
$compiled_ref = '$_COOKIE';
break;
case 'get':
case 'post':
case 'env':
......@@ -80,9 +85,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
return 'dirname($_smarty_tpl->source->filepath)';
case 'version':
$_version = Smarty::SMARTY_VERSION;
return "'$_version'";
return "Smarty::SMARTY_VERSION";
case 'const':
if (isset($compiler->smarty->security_policy) &&
......@@ -91,33 +94,27 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
$compiler->trigger_template_error("(secure mode) constants not permitted");
break;
}
if (strpos($_index[1], '$') === false && strpos($_index[1], '\'') === false) {
if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
return "@constant('{$_index[1]}')";
} else {
return "@constant({$_index[1]})";
}
case 'config':
if (isset($_index[2])) {
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
if (isset($_index[ 2 ])) {
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
} else {
return "\$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])";
return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
}
case 'ldelim':
$_ldelim = $compiler->smarty->left_delimiter;
return "'$_ldelim'";
return "\$_smarty_tpl->smarty->left_delimiter";
case 'rdelim':
$_rdelim = $compiler->smarty->right_delimiter;
return "'$_rdelim'";
return "\$_smarty_tpl->smarty->right_delimiter";
default:
$compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
$compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined');
break;
}
if (isset($_index[1])) {
if (isset($_index[ 1 ])) {
array_shift($_index);
foreach ($_index as $_ind) {
$compiled_ref = $compiled_ref . "[$_ind]";
......
......@@ -59,7 +59,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
*
* @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');
/**
......@@ -103,7 +103,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$initLocal = array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__section_{$attributes['name']}'] : false",);
$initLocal = array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
$initNamedProperty = array();
$initFor = array();
$incFor = array();
......
......@@ -187,6 +187,21 @@ class Smarty_Internal_Data
return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
}
/**
* gets the object of a Smarty variable
*
* @param string $variable the name of the Smarty variable
* @param Smarty_Internal_Data $_ptr optional pointer to data object
* @param boolean $searchParents search also in parent data
* @param bool $error_enable
*
* @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable
* @deprecated since 3.1.28 please use Smarty_Internal_Data::getTemplateVars() instead.
*/
public function getVariable($variable = null, Smarty_Internal_Data $_ptr = null, $searchParents = true, $error_enable = true){
return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable);
}
/**
* Follow the parent chain an merge template and config variables
*
......
......@@ -114,14 +114,6 @@ class Smarty_Internal_Extension_Clear
}
}
}
// remove from template cache
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if (isset($tpl->cached) && $tpl->cached->filepath == (string) $_file) {
unset($smarty->_cache['template_objects'][$key]);
}
}
}
$_count += @unlink((string) $_file) ? 1 : 0;
if (function_exists('opcache_invalidate')) {
opcache_invalidate((string) $_file);
......
......@@ -34,10 +34,7 @@ class Smarty_Internal_Method_ClearAllCache
{
// load cache resource and call clearAll
$_cache_resource = Smarty_CacheResource::load($smarty, $type);
if ($smarty->caching_type != 'file') {
$_cache_resource->invalidLoadedCache($smarty);
}
$_cache_resource->invalidLoadedCache($smarty);
return $_cache_resource->clearAll($smarty, $exp_time);
}
}
\ No newline at end of file
......@@ -37,10 +37,7 @@ class Smarty_Internal_Method_ClearCache
{
// load cache resource and call clear
$_cache_resource = Smarty_CacheResource::load($smarty, $type);
if ($smarty->caching_type != 'file' && !isset($template_name)) {
$_cache_resource->invalidLoadedCache($smarty);
}
$_cache_resource->invalidLoadedCache($smarty);
return $_cache_resource->clear($smarty, $template_name, $cache_id, $compile_id, $exp_time);
}
}
\ No newline at end of file
......@@ -107,13 +107,6 @@ class Smarty_Internal_Method_ClearCompiledTemplate
}
if ($unlink && @unlink($_filepath)) {
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if (isset($tpl->compiled) && $tpl->compiled->filepath == $_filepath) {
unset($smarty->_cache['template_objects'][$key]);
}
}
}
$_count ++;
if (function_exists('opcache_invalidate')) {
opcache_invalidate($_filepath);
......@@ -121,11 +114,10 @@ class Smarty_Internal_Method_ClearCompiledTemplate
}
}
}
// clear compiled cache
if (!isset($resource_name) && isset($smarty->_cache['source_objects'])) {
foreach ($smarty->_cache['source_objects'] as $source) {
$source->compileds = array();
}
// clear template objects cache
$smarty->_cache['isCached'] = array();
if (isset($smarty->ext->_subtemplate)) {
$smarty->ext->_subtemplate->tplObjects = array();
}
return $_count;
}
......
......@@ -162,7 +162,7 @@ class Smarty_Internal_Method_ConfigLoad
*
* @return mixed the value of the config variable
*/
public function _getConfigVariable(\Smarty_Internal_Template $tpl, $varName, $errorEnable = true)
public function _getConfigVariable(Smarty_Internal_Template $tpl, $varName, $errorEnable = true)
{
$_ptr = $tpl;
while ($_ptr !== null) {
......
......@@ -44,7 +44,7 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
if ($_s->type == 'php') {
throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
}
$sources[$_s->uid] = $_s;
$sources[ $_s->uid ] = $_s;
$uid .= $_s->filepath;
if ($_template) {
$exists = $exists && $_s->exists;
......@@ -110,4 +110,15 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
{
return str_replace(':', '.', basename($source->filepath));
}
/*
* Disable timestamp checks for extends resource.
* The individual source components will be checked.
*
* @return bool
*/
public function checkTimestamps()
{
return false;
}
}
......@@ -89,6 +89,6 @@ class Smarty_Internal_Runtime_CodeFrame
$output .= $functions;
$output .= "<?php }\n";
// remove unneeded PHP tags
return preg_replace('/\s*\?>[\n]?<\?php\s*/', "\n", $output);
return preg_replace(array('/\s*\?>[\n]?<\?php\s*/', '/\?>\s*$/'), array("\n", ''), $output);
}
}
\ No newline at end of file
......@@ -27,6 +27,9 @@ class Smarty_Internal_Runtime_Foreach
// thus rewind() and valid() methods may not be present
return iterator_count($value->getIterator());
} elseif ($value instanceof Iterator) {
if ($value instanceof Generator) {
return 1;
}
return iterator_count($value);
} elseif ($value instanceof PDOStatement) {
return $value->rowCount();
......
......@@ -127,8 +127,11 @@ class Smarty_Internal_Runtime_Inheritance
* - search in inheritance template hierarchy for child blocks
* if found call it, otherwise ignore
*
* $type 3 = {$smarty.block.parent}:
* - get block id from parent stack and call parent block
* $type 3 = {block append} {block prepend}:
* - call parent block
*
* $type 4 = {$smarty.block.parent}:
* - call parent block
*
* @param \Smarty_Internal_Template $tpl template object of caller
* @param int $type call type see above
......@@ -140,16 +143,22 @@ class Smarty_Internal_Runtime_Inheritance
*/
public function processBlock(Smarty_Internal_Template $tpl, $type = 0, $name, $block, $callStack = array())
{
if (!isset($this->blockParameter[$name])) {
$this->blockParameter[$name] = array();
if (!isset($this->blockParameter[ $name ])) {
$this->blockParameter[ $name ] = array();
}
if ($this->state == 1) {
$block[2] = count($this->blockParameter[$name]);
$block[3] = $this->tplIndex;
$this->blockParameter[$name][] = $block;
$block[ 2 ] = count($this->blockParameter[ $name ]);
$block[ 3 ] = $this->tplIndex;
$this->blockParameter[ $name ][] = $block;
return;
}
if ($type == 3) {
if (!empty($callStack)) {
$block = array_shift($callStack);
} else {
return;
}
} elseif ($type == 4) {
if (!empty($callStack)) {
array_shift($callStack);
if (empty($callStack)) {
......@@ -160,23 +169,23 @@ class Smarty_Internal_Runtime_Inheritance
return;
}
} else {
$blockParameter = &$this->blockParameter[$name];
$index = 0;
$blockParameter = &$this->blockParameter[ $name ];
if ($type == 0) {
$index = $block[2] = count($blockParameter);
$block[3] = $this->tplIndex;
$index = $block[ 2 ] = count($blockParameter);
$block[ 3 ] = $this->tplIndex;
$callStack = array(&$block);
} elseif ($type == 1) {
$block[3] = $callStack[0][3];
$index = 0;
$block[ 3 ] = $callStack[ 0 ][ 3 ];
for ($i = 0; $i < count($blockParameter); $i ++) {
if ($blockParameter[$i][3] <= $block[3]) {
$index = $blockParameter[$i][2];
if ($blockParameter[ $i ][ 3 ] <= $block[ 3 ]) {
$index = $blockParameter[ $i ][ 2 ];
}
}
$block[2] = $index;
$block[ 2 ] = $index;
$callStack = array(&$block);
} else {
$index = $callStack[0][2];
} elseif ($type == 2) {
$index = $callStack[ 0 ][ 2 ];
if ($index == 0) {
return;
}
......@@ -184,29 +193,40 @@ class Smarty_Internal_Runtime_Inheritance
}
$index --;
// find lowest level child block
while ($index >= 0 && ($type || !$block[1])) {
$block = &$blockParameter[$index];
while ($index >= 0 && ($type || !$block[ 1 ])) {
$block = &$blockParameter[ $index ];
array_unshift($callStack, $block);
if ($block[1]) {
if ($block[ 1 ]) {
break;
}
$index --;
}
if (isset($block['hide']) && $index <= 0) {
if (isset($block[ 'hide' ]) && $index <= 0) {
return;
}
}
$this->blockNesting ++;
if (isset($block['append'])) {
$this->processBlock($tpl, 3, $name, null, $callStack);
// {block append} ?
if (isset($block[ 'append' ])) {
$appendStack = $callStack;
if ($type == 0) {
array_shift($appendStack);
}
$this->processBlock($tpl, 3, $name, null, $appendStack);
}
// call block of current stack level
if (isset($block[6])) {
$block[6]($tpl, $callStack);
} else {
$block[0]($tpl, $callStack);
}
if (isset($block['prepend'])) {
$this->processBlock($tpl, 3, $name, null, $callStack);
// {block prepend} ?
if (isset($block[ 'prepend' ])) {
$prependStack = $callStack;
if ($type == 0) {
array_shift($prependStack);
}
$this->processBlock($tpl, 3, $name, null, $prependStack);
}
$this->blockNesting --;
}
......
......@@ -20,7 +20,7 @@ class Smarty_Internal_Runtime_TplFunction
*
* @throws \SmartyException
*/
public function callTemplateFunction(\Smarty_Internal_Template $tpl, $name, $params, $nocache)