3 * Smarty Internal Plugin Compile Special Smarty Variable
4 * Compiles the special $smarty variables
12 * Smarty Internal Plugin Compile special Smarty Variable Class
15 * @subpackage Compiler
17 class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_CompileBase
20 * Compiles code for the special $smarty variables
22 * @param array $args array with attributes from parser
23 * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
26 * @return string compiled code
27 * @throws \SmartyCompilerException
29 public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
31 $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
32 $variable = strtolower($compiler->getId($_index[ 0 ]));
33 if ($variable === false) {
34 $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
36 if (!isset($compiler->smarty->security_policy) ||
37 $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)
42 if (!isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ])) {
43 $class = 'Smarty_Internal_Compile_' . ucfirst($variable);
44 Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ] = new $class;
46 return Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ]->compileSpecialVariable(array(), $compiler, $_index);
48 if (class_exists('Smarty_Internal_Compile_Capture')) {
49 return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
55 if (isset($compiler->smarty->security_policy) &&
56 !$compiler->smarty->security_policy->allow_super_globals
58 $compiler->trigger_template_error("(secure mode) super globals not permitted");
61 $compiled_ref = '$_COOKIE';
69 if (isset($compiler->smarty->security_policy) &&
70 !$compiler->smarty->security_policy->allow_super_globals
72 $compiler->trigger_template_error("(secure mode) super globals not permitted");
75 $compiled_ref = '$_' . strtoupper($variable);
79 return 'basename($_smarty_tpl->source->filepath)';
81 case 'template_object':
82 return '$_smarty_tpl';
85 return 'dirname($_smarty_tpl->source->filepath)';
88 return "Smarty::SMARTY_VERSION";
91 if (isset($compiler->smarty->security_policy) &&
92 !$compiler->smarty->security_policy->allow_constants
94 $compiler->trigger_template_error("(secure mode) constants not permitted");
97 if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
98 return "@constant('{$_index[1]}')";
100 return "@constant({$_index[1]})";
104 if (isset($_index[ 2 ])) {
105 return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
107 return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
110 return "\$_smarty_tpl->smarty->left_delimiter";
112 return "\$_smarty_tpl->smarty->right_delimiter";
114 $compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined');
117 if (isset($_index[ 1 ])) {
118 array_shift($_index);
119 foreach ($_index as $_ind) {
120 $compiled_ref = $compiled_ref . "[$_ind]";
123 return $compiled_ref;