source: trunk/include/smarty/libs/sysplugins/smarty_internal_compile_private_special_variable.php @ 23384

Last change on this file since 23384 was 23384, checked in by rvelices, 11 years ago

smarty 3 - first pass for tests

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