diff options
| author | uwetews <uwe.tews@googlemail.com> | 2016-01-26 20:49:46 +0100 |
|---|---|---|
| committer | uwetews <uwe.tews@googlemail.com> | 2016-01-26 20:49:46 +0100 |
| commit | 8a0c783b71d59dc088f38c7dca0df4bc568daac4 (patch) | |
| tree | b237a53ee72ed6ed8a3fcd46ad4d6133b6a4b983 | |
| parent | ccbc4303edcb9625ea4f8143326720a90df79248 (diff) | |
| download | smarty-8a0c783b71d59dc088f38c7dca0df4bc568daac4.tar.gz smarty-8a0c783b71d59dc088f38c7dca0df4bc568daac4.tar.bz2 smarty-8a0c783b71d59dc088f38c7dca0df4bc568daac4.zip | |
- revert bugfix compiling {section} did create warning
| -rw-r--r-- | change_log.txt | 3 | ||||
| -rw-r--r-- | libs/Smarty.class.php | 2 | ||||
| -rw-r--r-- | libs/sysplugins/smarty_internal_compile_private_foreachsection.php | 164 |
3 files changed, 106 insertions, 63 deletions
diff --git a/change_log.txt b/change_log.txt index bc437353..1a89fc5e 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== 3.1.30-dev ===== (xx.xx.xx) + 27.01.2016 + - revert bugfix compiling {section} did create warning + 26.01.2016 - improvement observe Smarty::$_CHARSET in debugging console https://github.com/smarty-php/smarty/issues/169 - bugfix compiling {section} did create warning diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 02e7b035..34e8c08a 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.30-dev/19'; + const SMARTY_VERSION = '3.1.30-dev/20'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_private_foreachsection.php b/libs/sysplugins/smarty_internal_compile_private_foreachsection.php index b9043040..16f23335 100644 --- a/libs/sysplugins/smarty_internal_compile_private_foreachsection.php +++ b/libs/sysplugins/smarty_internal_compile_private_foreachsection.php @@ -14,95 +14,70 @@ * @package Smarty * @subpackage Compiler */ -abstract class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase +class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase { /** - * Valid properties of $smarty.xxx variable - * - * @var array - */ - public $nameProperties = array(); - - /** - * Name of this tag + * Preg search pattern * * @var string */ - public $tagName = ''; + private $propertyPreg = ''; /** - * {section} tag has no item properties + * Offsets in preg match result * * @var array */ - public $itemProperties = null; + private $resultOffsets = array(); /** - * {section} tag has always name attribute + * Start offset * - * @var bool + * @var int */ - public $isNamed = true; + private $startOffset = 0; /** - * @var array + * Name of this tag + * + * @var string */ - public $matchResults = array(); + public $tagName = ''; /** - * Preg search pattern + * Valid properties of $smarty.xxx variable * - * @var string + * @var array */ - private $propertyPreg = ''; + public $nameProperties = array(); /** - * Offsets in preg match result + * {section} tag has no item properties * * @var array */ - private $resultOffsets = array(); + public $itemProperties = null; /** - * Start offset + * {section} tag has always name attribute * - * @var int + * @var bool */ - private $startOffset = 0; + public $isNamed = true; /** - * Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag - * - * @param array $args array with attributes from parser - * @param \Smarty_Internal_TemplateCompiler $compiler compiler object - * @param array $parameter array with compilation parameter - * - * @return string compiled code - * @throws \SmartyCompilerException + * @var array */ - public function compileSpecialVariable($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null) - { - $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); - } - $property = isset($parameter[ 2 ]) ? strtolower($compiler->getId($parameter[ 2 ])) : false; - if (!$property || !in_array($property, $this->nameProperties)) { - $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true); - } - $tagVar = "'__smarty_{$tag}_{$name}'"; - return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)"; - } + public $matchResults = array(); /** * Scan sources for used tag attributes * - * @param array $attributes - * @param \Smarty_Internal_TemplateCompiler $compiler + * @param array $attributes + * @param \Smarty_Internal_TemplateCompilerBase $compiler */ - public function scanForProperties($attributes, Smarty_Internal_TemplateCompiler $compiler) + public function scanForProperties($attributes, Smarty_Internal_TemplateCompilerBase $compiler) { $this->propertyPreg = '~('; $this->startOffset = 0; @@ -120,6 +95,10 @@ abstract class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Int $this->propertyPreg .= ')\W~i'; // Template source $this->matchTemplateSource($compiler); + // Parent template source + $this->matchParentTemplateSource($compiler); + // {block} source + $this->matchBlockSource($compiler); } /** @@ -131,11 +110,11 @@ abstract class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Int public function buildPropertyPreg($named, $attributes) { if ($named) { - $this->resultOffsets[ 'named' ] = $this->startOffset + 3; + $this->resultOffsets['named'] = $this->startOffset + 3; $this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.]("; $properties = $this->nameProperties; } else { - $this->resultOffsets[ 'item' ] = $this->startOffset + 3; + $this->resultOffsets['item'] = $this->startOffset + 3; $this->propertyPreg .= "([\$]{$attributes['item']}[@]("; $properties = $this->itemProperties; } @@ -152,29 +131,90 @@ abstract class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Int } /** + * Find matches in source string + * + * @param string $source + */ + public function matchProperty($source) + { + preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER); + foreach ($this->resultOffsets as $key => $offset) { + foreach ($match as $m) { + if (isset($m[$offset]) && !empty($m[$offset])) { + $this->matchResults[$key][strtolower($m[$offset])] = true; + } + } + } + } + + /** * Find matches in template source * - * @param \Smarty_Internal_TemplateCompiler $compiler + * @param \Smarty_Internal_TemplateCompilerBase $compiler */ - public function matchTemplateSource(Smarty_Internal_TemplateCompiler $compiler) + public function matchTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) { $this->matchProperty($compiler->parser->lex->data); } /** - * Find matches in source string + * Find matches in all parent template source * - * @param string $source + * @param \Smarty_Internal_TemplateCompilerBase $compiler */ - public function matchProperty($source) + public function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) { - preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER); - foreach ($this->resultOffsets as $key => $offset) { - foreach ($match as $m) { - if (isset($m[ $offset ]) && !empty($m[ $offset ])) { - $this->matchResults[ $key ][ strtolower($m[ $offset ]) ] = true; + // search parent compiler template source + $nextCompiler = $compiler; + while ($nextCompiler !== $nextCompiler->parent_compiler) { + $nextCompiler = $nextCompiler->parent_compiler; + if ($compiler !== $nextCompiler) { + // get template source + $_content = $nextCompiler->template->source->getContent(); + if ($_content != '') { + // run pre filter if required + if ((isset($nextCompiler->smarty->autoload_filters['pre']) || + isset($nextCompiler->smarty->registered_filters['pre']))) { + $_content = $nextCompiler->smarty->ext->_filter_Handler->runFilter('pre', $_content, $nextCompiler->template); + } + $this->matchProperty($_content); } } } } + + /** + * Find matches in {block} tag source + * + * @param \Smarty_Internal_TemplateCompilerBase $compiler + */ + public function matchBlockSource(Smarty_Internal_TemplateCompilerBase $compiler) + { + + } + + /** + * Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag + * + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * @param array $parameter array with compilation parameter + * + * @return string compiled code + * @throws \SmartyCompilerException + */ + 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); + } + $property = isset($parameter[ 2 ]) ? strtolower($compiler->getId($parameter[ 2 ])) : false; + if (!$property || !in_array($property, $this->nameProperties)) { + $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true); + } + $tagVar = "'__smarty_{$tag}_{$name}'"; + return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)"; + } }
\ No newline at end of file |
