Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
304 | alex-w | 1 | <?php |
2 | /** |
||
3 | * Smarty Internal Plugin Compile Smarty |
||
4 | * |
||
5 | * Compiles the special $smarty variables |
||
6 | * |
||
7 | * @package Smarty |
||
8 | * @subpackage Compiler |
||
9 | * @author Uwe Tews |
||
10 | */ |
||
11 | /** |
||
12 | * Smarty Internal Plugin Compile Smarty Class |
||
13 | */ |
||
14 | class Smarty_Internal_Compile_Internal_Smarty_Var extends Smarty_Internal_CompileBase { |
||
15 | /** |
||
16 | * Compiles code for the speical $smarty variables |
||
17 | * |
||
18 | * @param array $args array with attributes from parser |
||
19 | * @param object $compiler compiler object |
||
20 | * @return string compiled code |
||
21 | */ |
||
22 | public function compile($args, $compiler) |
||
23 | { |
||
24 | $_index = explode(',', str_replace(array('][', '[', ']'), array(',', '', ''), $args)); |
||
25 | $compiled_ref = ' '; |
||
26 | switch (trim($_index[0], "'")) { |
||
27 | case 'foreach': |
||
28 | return "\$_smarty_tpl->getVariable('smarty')->value$args"; |
||
29 | case 'section': |
||
30 | return "\$_smarty_tpl->getVariable('smarty')->value$args"; |
||
31 | case 'capture': |
||
32 | return "\$_smarty_tpl->smarty->_smarty_vars$args"; |
||
33 | case 'now': |
||
34 | return 'time()'; |
||
35 | |||
36 | case 'get': |
||
37 | $compiled_ref = "\$_GET"; |
||
38 | break; |
||
39 | |||
40 | case 'post': |
||
41 | $compiled_ref = "\$_POST"; |
||
42 | break; |
||
43 | |||
44 | case 'cookies': |
||
45 | $compiled_ref = "\$_COOKIE"; |
||
46 | break; |
||
47 | |||
48 | case 'env': |
||
49 | $compiled_ref = "\$_ENV"; |
||
50 | break; |
||
51 | |||
52 | case 'server': |
||
53 | $compiled_ref = "\$_SERVER"; |
||
54 | break; |
||
55 | |||
56 | case 'session': |
||
57 | $compiled_ref = "\$_SESSION"; |
||
58 | break; |
||
59 | |||
60 | case 'request': |
||
61 | $compiled_ref = "\$_REQUEST"; |
||
62 | break; |
||
63 | |||
64 | case 'template': |
||
65 | $_template_name = basename($compiler->template->getTemplateFilepath()); |
||
66 | return "'$_template_name'"; |
||
67 | |||
68 | case 'current_dir': |
||
69 | $_template_dir_name = dirname($compiler->template->getTemplateFilepath()); |
||
70 | return "'$_template_dir_name'"; |
||
71 | |||
72 | case 'version': |
||
73 | $_version = Smarty::$_version; |
||
74 | return "'$_version'"; |
||
75 | |||
76 | case 'const': |
||
77 | if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_constants) { |
||
78 | $compiler->trigger_template_error("(secure mode) constants not permitted"); |
||
79 | break; |
||
80 | } |
||
81 | return '@' . trim($_index[1], "'"); |
||
82 | |||
83 | case 'config': |
||
84 | return "\$_smarty_tpl->getConfigVariable($_index[1])"; |
||
85 | case 'ldelim': |
||
86 | $_ldelim = $compiler->smarty->left_delimiter; |
||
87 | return "'$_ldelim'"; |
||
88 | |||
89 | case 'rdelim': |
||
90 | $_rdelim = $compiler->smarty->right_delimiter; |
||
91 | return "'$_rdelim'"; |
||
92 | |||
93 | default: |
||
94 | $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is an unknown reference'); |
||
95 | break; |
||
96 | } |
||
97 | if (isset($_index[1])) { |
||
98 | array_shift($_index); |
||
99 | foreach ($_index as $_ind) { |
||
100 | $compiled_ref = $compiled_ref . "[$_ind]"; |
||
101 | } |
||
102 | } |
||
103 | return $compiled_ref; |
||
104 | } |
||
105 | } |
||
106 | ?> |