1 : <?php
2 : /**
3 : * Smarty Internal Plugin Compile Special Smarty Variable
4 : *
5 : * Compiles the special $smarty variables
6 : *
7 : * @package Smarty
8 : * @subpackage Compiler
9 : * @author Uwe Tews
10 : */
11 :
12 : /**
13 : * Smarty Internal Plugin Compile special Smarty Variable Class
14 : *
15 : * @package Smarty
16 : * @subpackage Compiler
17 : */
18 : class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_CompileBase {
19 :
20 : /**
21 : * Compiles code for the speical $smarty variables
22 : *
23 : * @param array $args array with attributes from parser
24 : * @param object $compiler compiler object
25 : * @return string compiled code
26 : */
27 : public function compile($args, $compiler, $parameter)
28 : {
29 0 : $_index = preg_split("/\]\[/",substr($parameter, 1, strlen($parameter)-2));
30 0 : $compiled_ref = ' ';
31 0 : $variable = trim($_index[0], "'");
32 : switch ($variable) {
33 0 : case 'foreach':
34 0 : return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
35 0 : case 'section':
36 0 : return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
37 0 : case 'capture':
38 0 : return "Smarty::\$_smarty_vars$parameter";
39 0 : case 'now':
40 0 : return 'time()';
41 0 : case 'cookies':
42 0 : if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
43 0 : $compiler->trigger_template_error("(secure mode) super globals not permitted");
44 0 : break;
45 : }
46 0 : $compiled_ref = '$_COOKIE';
47 0 : break;
48 :
49 0 : case 'get':
50 0 : case 'post':
51 0 : case 'env':
52 0 : case 'server':
53 0 : case 'session':
54 0 : case 'request':
55 0 : if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
56 0 : $compiler->trigger_template_error("(secure mode) super globals not permitted");
57 0 : break;
58 : }
59 0 : $compiled_ref = '$_'.strtoupper($variable);
60 0 : break;
61 :
62 0 : case 'template':
63 0 : return 'basename($_smarty_tpl->source->filepath)';
64 :
65 0 : case 'current_dir':
66 0 : return 'dirname($_smarty_tpl->source->filepath)';
67 :
68 0 : case 'version':
69 0 : $_version = Smarty::SMARTY_VERSION;
70 0 : return "'$_version'";
71 :
72 0 : case 'const':
73 0 : if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) {
74 0 : $compiler->trigger_template_error("(secure mode) constants not permitted");
75 0 : break;
76 : }
77 0 : return '@' . trim($_index[1], "'");
78 :
79 0 : case 'config':
80 0 : return "\$_smarty_tpl->getConfigVariable($_index[1])";
81 0 : case 'ldelim':
82 0 : $_ldelim = $compiler->smarty->left_delimiter;
83 0 : return "'$_ldelim'";
84 :
85 0 : case 'rdelim':
86 0 : $_rdelim = $compiler->smarty->right_delimiter;
87 0 : return "'$_rdelim'";
88 :
89 0 : default:
90 0 : $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
91 0 : break;
92 0 : }
93 0 : if (isset($_index[1])) {
94 0 : array_shift($_index);
95 0 : foreach ($_index as $_ind) {
96 0 : $compiled_ref = $compiled_ref . "[$_ind]";
97 0 : }
98 0 : }
99 0 : return $compiled_ref;
100 : }
101 :
102 : }
103 :
|