From ab5d8d4e07bb3c8230d0285ef8902ef1979fce51 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 18 Oct 2018 02:39:34 +0200 Subject: Updating Smarty --- ...rty_internal_compile_private_foreachsection.php | 228 +++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 lib/smarty/sysplugins/smarty_internal_compile_private_foreachsection.php (limited to 'lib/smarty/sysplugins/smarty_internal_compile_private_foreachsection.php') diff --git a/lib/smarty/sysplugins/smarty_internal_compile_private_foreachsection.php b/lib/smarty/sysplugins/smarty_internal_compile_private_foreachsection.php new file mode 100644 index 0000000..d3aab24 --- /dev/null +++ b/lib/smarty/sysplugins/smarty_internal_compile_private_foreachsection.php @@ -0,0 +1,228 @@ +propertyPreg = '~('; + $this->startOffset = 1; + $this->resultOffsets = array(); + $this->matchResults = array('named' => array(), 'item' => array()); + if (isset($attributes[ 'name' ])) { + $this->buildPropertyPreg(true, $attributes); + } + if (isset($this->itemProperties)) { + if ($this->isNamed) { + $this->propertyPreg .= '|'; + } + $this->buildPropertyPreg(false, $attributes); + } + $this->propertyPreg .= ')\W~i'; + // Template source + $this->matchTemplateSource($compiler); + // Parent template source + $this->matchParentTemplateSource($compiler); + // {block} source + $this->matchBlockSource($compiler); + } + + /** + * Build property preg string + * + * @param bool $named + * @param array $attributes + */ + public function buildPropertyPreg($named, $attributes) + { + if ($named) { + $this->resultOffsets[ 'named' ] = $this->startOffset = $this->startOffset + 3; + $this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" . + ($this->tagName === 'section' ? "|[\[]\s*" : '') . + "){$attributes['name']}[.]("; + $properties = $this->nameProperties; + } else { + $this->resultOffsets[ 'item' ] = $this->startOffset = $this->startOffset + 2; + $this->propertyPreg .= "([\$]{$attributes['item']}[@]("; + $properties = $this->itemProperties; + } + $propName = reset($properties); + while ($propName) { + $this->propertyPreg .= "{$propName}"; + $propName = next($properties); + if ($propName) { + $this->propertyPreg .= '|'; + } + } + $this->propertyPreg .= '))'; + } + + /** + * Find matches in source string + * + * @param string $source + */ + public function matchProperty($source) + { + preg_match_all($this->propertyPreg, $source, $match); + foreach ($this->resultOffsets as $key => $offset) { + foreach ($match[ $offset ] as $m) { + if (!empty($m)) { + $this->matchResults[ $key ][ strtolower($m) ] = true; + } + } + } + } + + /** + * Find matches in template source + * + * @param \Smarty_Internal_TemplateCompilerBase $compiler + */ + public function matchTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) + { + $this->matchProperty($compiler->parser->lex->data); + } + + /** + * Find matches in all parent template source + * + * @param \Smarty_Internal_TemplateCompilerBase $compiler + * + * @throws \SmartyException + */ + public function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) + { + // 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->_filterHandler->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)"; + } +} -- cgit v1.2.3