/** * Compiles code for the {$smarty.capture.xxx} * * @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 static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null) { $tag = 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 "\$_smarty_tpl->smarty->ext->_capture->getBuffer(\$_smarty_tpl, '{$name}')"; }
/** * Compiles code for the {$MVC.capture.xxx} * * @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 static 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 \$MVC.{$tag} name attribute", null, true); } return "(isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null)"; }
/** * Compiles code for the {$smarty.capture.xxx} * * @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 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]))) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", $compiler->lex->taglineno); } return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null"; }
/** * Compiles code for the {block_parent} tag * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param array $parameter array with compilation parameter * * @return bool true */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { if (!isset($compiler->_cache['blockNesting'])) { $compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ', $compiler->parser->lex->taglineno); } $compiler->has_code = true; $compiler->suppressNocacheProcessing = true; $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']]['callsChild'] = 'true'; $output = "<?php \n\$_smarty_tpl->inheritance->callChild(\$_smarty_tpl, \$this);\n?>\n"; return $output; }
function yy_r8_3() { $to = strlen($this->data); preg_match("~{$this->ldel}[/]?literal\\s*{$this->rdel}~i", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); if (isset($match[0][1])) { $to = $match[0][1]; } else { $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); } $this->value = substr($this->data, $this->counter, $to - $this->counter); $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; }
/** * 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 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]))) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); } $className = 'Smarty_Internal_Compile_' . ucfirst($tag); if (!isset($parameter[2]) || false === ($property = $compiler->getId($parameter[2])) || !in_array($property, $className::$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)"; }
/** * Compiles code for the special $smarty variables * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param $parameter * * @return string compiled code * @throws \SmartyCompilerException */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { $_index = preg_split("/\\]\\[/", substr($parameter, 1, strlen($parameter) - 2)); $variable = strtolower($compiler->getId($_index[0])); if ($variable === false) { $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true); } if (!isset($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)) { switch ($variable) { case 'foreach': case 'section': return Smarty_Internal_Compile_Private_ForeachSection::compileSpecialVariable(array(), $compiler, $_index); case 'capture': if (class_exists('Smarty_Internal_Compile_Capture')) { return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); } return ''; case 'now': return 'time()'; case 'cookies': if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) { $compiler->trigger_template_error("(secure mode) super globals not permitted"); break; } return '$_COOKIE'; case 'get': case 'post': case 'env': case 'server': case 'session': case 'request': if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) { $compiler->trigger_template_error("(secure mode) super globals not permitted"); break; } $compiled_ref = '$_' . strtoupper($variable); break; case 'template': return 'basename($_smarty_tpl->source->filepath)'; case 'template_object': return '$_smarty_tpl'; case 'current_dir': return 'dirname($_smarty_tpl->source->filepath)'; case 'version': $_version = Smarty::SMARTY_VERSION; return "'{$_version}'"; case 'const': if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) { $compiler->trigger_template_error("(secure mode) constants not permitted"); break; } 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->_getConfigVariable({$_index['1']})) ? \$tmp[{$_index['2']}] : null)"; } else { return "\$_smarty_tpl->_getConfigVariable({$_index['1']})"; } case 'ldelim': $_ldelim = $compiler->smarty->left_delimiter; return "'{$_ldelim}'"; case 'rdelim': $_rdelim = $compiler->smarty->right_delimiter; return "'{$_rdelim}'"; default: $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid'); break; } if (isset($_index[1])) { array_shift($_index); foreach ($_index as $_ind) { $compiled_ref = $compiled_ref . "[{$_ind}]"; } } return $compiled_ref; } }
public function yy_syntax_error($yymajor, $TOKEN) { #line 200 "../smarty/lexer/smarty_internal_templateparser.y" $this->internalError = true; $this->yymajor = $yymajor; $this->compiler->trigger_template_error(); }
function yy_r3_3($yy_subpatterns) { $to = strlen($this->data); preg_match("/{$this->ldel}\\/?literal{$this->rdel}/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); if (isset($match[0][1])) { $to = $match[0][1]; } else { $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); } $this->value = substr($this->data, $this->counter, $to - $this->counter); $this->token = Smarty_Internal_Templateparser::TP_LITERAL; }
/** * Compiles code for the {$smarty.foreach} 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 static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { if (!isset($parameter[1]) || false === ($name = $compiler->getId($parameter[1]))) { $compiler->trigger_template_error("missing or illegal \$Smarty.foreach name attribute", $compiler->lex->taglineno); } if (!isset($parameter[2]) || false === ($property = $compiler->getId($parameter[2])) || !in_array(strtolower($property), array('first', 'last', 'index', 'iteration', 'show', 'total'))) { $compiler->trigger_template_error("missing or illegal \$Smarty.foreach property attribute", $compiler->lex->taglineno); } $property = strtolower($property); $foreachVar = "'__foreach_{$name}'"; return "(isset(\$_smarty_tpl->tpl_vars[{$foreachVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$foreachVar}]->value['{$property}'] : null)"; }
/** * Compile $smarty.block.parent * * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param string $_name optional name of child block * * @return string compiled code of child block */ static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null) { if (!isset($compiler->_cache['blockNesting'])) { $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->parser->lex->taglineno); } $compiler->suppressNocacheProcessing = true; $compiler->has_code = true; $output = "<?php \n\$_smarty_tpl->_inheritance->processBlock(\$_smarty_tpl, 3, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n"; return $output; }
/** * 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)"; }
/** * Compile $smarty.block.parent * * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param string $_name optional name of child block * * @return string compiled code of child block * @throws \SmartyCompilerException */ static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null) { // if called by {$smarty.block.parent} we must search the name of enclosing {block} if ($_name == null) { $stack_count = count($compiler->_tag_stack); while (--$stack_count >= 0) { if ($compiler->_tag_stack[$stack_count][0] == 'block') { $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'"); break; } } } if ($_name == null) { $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->lex->taglineno); } if (empty(Smarty_Internal_Compile_Block::$nested_block_names)) { $compiler->trigger_template_error(' illegal {$smarty.block.parent} in parent template ', $compiler->lex->taglineno); } Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= Smarty_Internal_Compile_Block::parent; $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); $compiler->has_code = false; return; }
/** * Compile $smarty.block.parent * * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param string $_name optional name of child block * * @return string compiled code of child block */ static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null) { if (!$compiler->inheritanceChild) { $compiler->trigger_template_error(' tag {$smarty.block.parent} used in parent template ', $compiler->parser->lex->taglineno); } if (!$compiler->blockTagNestingLevel) { $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->parser->lex->taglineno); } $compiler->suppressNocacheProcessing = true; $compiler->has_code = true; $_output = "<?php \n\$_smarty_tpl->_Block->callParentBlock(\$_smarty_tpl, \$block);?>"; return $_output; }