update to smarty v3.1.24
[GitHub/Stricted/Domain-Control-Panel.git] / lib / api / smarty / sysplugins / smarty_internal_compile_private_special_variable.php
CommitLineData
2aa91ff2
S
1<?php
2/**
3 * Smarty Internal Plugin Compile Special Smarty Variable
4 * Compiles the special $smarty variables
5 *
6 * @package Smarty
7 * @subpackage Compiler
8 * @author Uwe Tews
9 */
10
11/**
12 * Smarty Internal Plugin Compile special Smarty Variable Class
13 *
14 * @package Smarty
15 * @subpackage Compiler
16 */
17class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_CompileBase
18{
19 /**
20 * Compiles code for the special $smarty variables
21 *
22 * @param array $args array with attributes from parser
23 * @param object $compiler compiler object
24 * @param $parameter
25 *
26 * @return string compiled code
27 */
28 public function compile($args, $compiler, $parameter)
29 {
30 $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
31 $compiled_ref = ' ';
32 $variable = trim($_index[0], "'");
ccd27f54
S
33 if (!isset($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)) {
34 switch ($variable) {
35 case 'foreach':
36 $name = trim($_index[1], "'");
37 $foreachVar = "'__foreach_{$name}'";
cd8826ea 38 return "(isset(\$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}]) ? \$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}] : null)";
ccd27f54
S
39 case 'section':
40 return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
41 case 'capture':
42 return "Smarty::\$_smarty_vars$parameter";
43 case 'now':
44 return 'time()';
45 case 'cookies':
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");
48 break;
49 }
50 $compiled_ref = '$_COOKIE';
2aa91ff2 51 break;
2aa91ff2 52
ccd27f54
S
53 case 'get':
54 case 'post':
55 case 'env':
56 case 'server':
57 case 'session':
58 case 'request':
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");
61 break;
62 }
63 $compiled_ref = '$_' . strtoupper($variable);
2aa91ff2 64 break;
2aa91ff2 65
ccd27f54
S
66 case 'template':
67 return 'basename($_smarty_tpl->source->filepath)';
2aa91ff2 68
ccd27f54
S
69 case 'template_object':
70 return '$_smarty_tpl';
2aa91ff2 71
ccd27f54
S
72 case 'current_dir':
73 return 'dirname($_smarty_tpl->source->filepath)';
2aa91ff2 74
ccd27f54
S
75 case 'version':
76 $_version = Smarty::SMARTY_VERSION;
2aa91ff2 77
ccd27f54 78 return "'$_version'";
2aa91ff2 79
ccd27f54
S
80 case 'const':
81 if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) {
82 $compiler->trigger_template_error("(secure mode) constants not permitted");
83 break;
84 }
cd8826ea 85 if (strpos($_index[1], '$') === false && strpos($_index[1], '\'') === false ) {
ccd27f54
S
86 return "@constant('{$_index[1]}')";
87 } else {
88 return "@constant({$_index[1]})";
89 }
2aa91ff2 90
ccd27f54
S
91 case 'config':
92 if (isset($_index[2])) {
93 return "(is_array(\$tmp = \$_smarty_tpl->getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)";
94 } else {
95 return "\$_smarty_tpl->getConfigVariable($_index[1])";
96 }
97 case 'ldelim':
98 $_ldelim = $compiler->smarty->left_delimiter;
2aa91ff2 99
ccd27f54 100 return "'$_ldelim'";
2aa91ff2 101
ccd27f54
S
102 case 'rdelim':
103 $_rdelim = $compiler->smarty->right_delimiter;
2aa91ff2 104
ccd27f54 105 return "'$_rdelim'";
2aa91ff2 106
ccd27f54
S
107 default:
108 $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
109 break;
110 }
111 if (isset($_index[1])) {
112 array_shift($_index);
113 foreach ($_index as $_ind) {
114 $compiled_ref = $compiled_ref . "[$_ind]";
115 }
2aa91ff2
S
116 }
117 }
2aa91ff2
S
118 return $compiled_ref;
119 }
120}