/** * 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 = 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 {$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 {$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; } }
/** * 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)"; }
/** * 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)"; }