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)"; } /** * Scan sources for used tag attributes * * @param array $attributes * @param \Smarty_Internal_TemplateCompiler $compiler */ public function scanForProperties($attributes, Smarty_Internal_TemplateCompiler $compiler) { $this->propertyPreg = '~('; $this->startOffset = 0; $this->resultOffsets = array(); $this->matchResults = array('named' => array(), 'item' => array()); if ($this->isNamed) { $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); } /** * Build property preg string * * @param bool $named * @param array $attributes */ public function buildPropertyPreg($named, $attributes) { if ($named) { $this->resultOffsets[ 'named' ] = $this->startOffset + 3; $this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.]("; $properties = $this->nameProperties; } else { $this->resultOffsets[ 'item' ] = $this->startOffset + 3; $this->propertyPreg .= "([\$]{$attributes['item']}[@]("; $properties = $this->itemProperties; } $this->startOffset += count($properties) + 2; $propName = reset($properties); while ($propName) { $this->propertyPreg .= "({$propName})"; $propName = next($properties); if ($propName) { $this->propertyPreg .= '|'; } } $this->propertyPreg .= '))'; } /** * Find matches in template source * * @param \Smarty_Internal_TemplateCompiler $compiler */ public function matchTemplateSource(Smarty_Internal_TemplateCompiler $compiler) { $this->matchProperty($compiler->parser->lex->data); } /** * 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; } } } } }