Code

Added smarty 3 rc
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_compile_private_special_variable.php
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 * Smarty Internal Plugin Compile special Smarty Variable Class
13 */
14 class Smarty_Internal_Compile_Private_Special_Variable 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(','), substr($args, 1, strlen($args)-2)));
25         $compiled_ref = ' ';
26         $variable = trim($_index[0], "'");
27         switch ($variable) {
28             case 'foreach':
29                 return "\$_smarty_tpl->getVariable('smarty')->value$args";
30             case 'section':
31                 return "\$_smarty_tpl->getVariable('smarty')->value$args";
32             case 'capture':
33                 return "\$_smarty_tpl->smarty->_smarty_vars$args";
34             case 'now':
35                 return 'time()';
36             case 'cookies':
37                 if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_super_globals) {
38                     $compiler->trigger_template_error("(secure mode) super globals not permitted");
39                     break;
40                 } 
41                 $compiled_ref = '$_COOKIE';
42                 break;
44             case 'get':
45             case 'post':
46             case 'env':
47             case 'server':
48             case 'session':
49             case 'request':
50                 if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_super_globals) {
51                     $compiler->trigger_template_error("(secure mode) super globals not permitted");
52                     break;
53                 } 
54                 $compiled_ref = '$_'.strtoupper($variable);
55                 break;
57             case 'template':
58                 $_template_name = basename($compiler->template->getTemplateFilepath());
59                 return "'$_template_name'";
61             case 'current_dir':
62                 $_template_dir_name = dirname($compiler->template->getTemplateFilepath());
63                 return "'$_template_dir_name'";
65             case 'version':
66                 $_version = Smarty::SMARTY_VERSION;
67                 return "'$_version'";
69             case 'const':
70                 if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_constants) {
71                     $compiler->trigger_template_error("(secure mode) constants not permitted");
72                     break;
73                 } 
74                 return '@' . trim($_index[1], "'");
76             case 'config':
77                 return "\$_smarty_tpl->getConfigVariable($_index[1])";
78             case 'ldelim':
79                 $_ldelim = $compiler->smarty->left_delimiter;
80                 return "'$_ldelim'";
82             case 'rdelim':
83                 $_rdelim = $compiler->smarty->right_delimiter;
84                 return "'$_rdelim'";
86             default:
87                 $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
88                 break;
89         } 
90         if (isset($_index[1])) {
91             array_shift($_index);
92             foreach ($_index as $_ind) {
93                 $compiled_ref = $compiled_ref . "[$_ind]";
94             } 
95         } 
96         return $compiled_ref;
97     } 
98
100 ?>