23b17ae1410206eb48b570c4cf39ad312f3144a9
[GitHub/Stricted/Domain-Control-Panel.git] / lib / api / smarty / sysplugins / smarty_internal_compile_private_special_variable.php
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 */
17 class 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], "'");
33 switch ($variable) {
34 case 'foreach':
35 return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
36 case 'section':
37 return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
38 case 'capture':
39 return "Smarty::\$_smarty_vars$parameter";
40 case 'now':
41 return 'time()';
42 case 'cookies':
43 if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
44 $compiler->trigger_template_error("(secure mode) super globals not permitted");
45 break;
46 }
47 $compiled_ref = '$_COOKIE';
48 break;
49
50 case 'get':
51 case 'post':
52 case 'env':
53 case 'server':
54 case 'session':
55 case 'request':
56 if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
57 $compiler->trigger_template_error("(secure mode) super globals not permitted");
58 break;
59 }
60 $compiled_ref = '$_' . strtoupper($variable);
61 break;
62
63 case 'template':
64 return 'basename($_smarty_tpl->source->filepath)';
65
66 case 'template_object':
67 return '$_smarty_tpl';
68
69 case 'current_dir':
70 return 'dirname($_smarty_tpl->source->filepath)';
71
72 case 'version':
73 $_version = Smarty::SMARTY_VERSION;
74
75 return "'$_version'";
76
77 case 'const':
78 if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) {
79 $compiler->trigger_template_error("(secure mode) constants not permitted");
80 break;
81 }
82
83 return "@constant({$_index[1]})";
84
85 case 'config':
86 if (isset($_index[2])) {
87 return "(is_array(\$tmp = \$_smarty_tpl->getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)";
88 } else {
89 return "\$_smarty_tpl->getConfigVariable($_index[1])";
90 }
91 case 'ldelim':
92 $_ldelim = $compiler->smarty->left_delimiter;
93
94 return "'$_ldelim'";
95
96 case 'rdelim':
97 $_rdelim = $compiler->smarty->right_delimiter;
98
99 return "'$_rdelim'";
100
101 default:
102 $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
103 break;
104 }
105 if (isset($_index[1])) {
106 array_shift($_index);
107 foreach ($_index as $_ind) {
108 $compiled_ref = $compiled_ref . "[$_ind]";
109 }
110 }
111
112 return $compiled_ref;
113 }
114 }