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 object $compiler compiler object
26 * @return string compiled code
28 public function compile($args, $compiler, $parameter)
30 $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
32 $variable = trim($_index[0], "'");
33 if (!isset($compiler->smarty
->security_policy
) ||
$compiler->smarty
->security_policy
->isTrustedSpecialSmartyVar($variable, $compiler)) {
36 $name = trim($_index[1], "'");
37 $foreachVar = "'__foreach_{$name}'";
38 return "isset(\$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}]) ? \$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}] : null";
40 return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
42 return "Smarty::\$_smarty_vars$parameter";
46 if (isset($compiler->smarty
->security_policy
) && !$compiler->smarty
->security_policy
->allow_super_globals
) {
47 $compiler->trigger_template_error("(secure mode) super globals not permitted");
50 $compiled_ref = '$_COOKIE';
59 if (isset($compiler->smarty
->security_policy
) && !$compiler->smarty
->security_policy
->allow_super_globals
) {
60 $compiler->trigger_template_error("(secure mode) super globals not permitted");
63 $compiled_ref = '$_' . strtoupper($variable);
67 return 'basename($_smarty_tpl->source->filepath)';
69 case 'template_object':
70 return '$_smarty_tpl';
73 return 'dirname($_smarty_tpl->source->filepath)';
76 $_version = Smarty
::SMARTY_VERSION
;
81 if (isset($compiler->smarty
->security_policy
) && !$compiler->smarty
->security_policy
->allow_constants
) {
82 $compiler->trigger_template_error("(secure mode) constants not permitted");
85 if (strpos($_index[1], '$') === false) {
86 return "@constant('{$_index[1]}')";
88 return "@constant({$_index[1]})";
92 if (isset($_index[2])) {
93 return "(is_array(\$tmp = \$_smarty_tpl->getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)";
95 return "\$_smarty_tpl->getConfigVariable($_index[1])";
98 $_ldelim = $compiler->smarty
->left_delimiter
;
103 $_rdelim = $compiler->smarty
->right_delimiter
;
108 $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
111 if (isset($_index[1])) {
112 array_shift($_index);
113 foreach ($_index as $_ind) {
114 $compiled_ref = $compiled_ref . "[$_ind]";
118 return $compiled_ref;