]> git.mxchange.org Git - friendica.git/blob - library/Smarty/libs/sysplugins/smarty_internal_compile_private_special_variable.php
add smarty engine, remove some obsolete zot1 stuff
[friendica.git] / library / Smarty / libs / 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 /**
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         $_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 '@' . trim($_index[1], "'");
81
82             case 'config':
83                 return "\$_smarty_tpl->getConfigVariable($_index[1])";
84             case 'ldelim':
85                 $_ldelim = $compiler->smarty->left_delimiter;
86                 return "'$_ldelim'";
87
88             case 'rdelim':
89                 $_rdelim = $compiler->smarty->right_delimiter;
90                 return "'$_rdelim'";
91
92             default:
93                 $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
94                 break;
95         }
96         if (isset($_index[1])) {
97             array_shift($_index);
98             foreach ($_index as $_ind) {
99                 $compiled_ref = $compiled_ref . "[$_ind]";
100             }
101         }
102         return $compiled_ref;
103     }
104
105 }
106
107 ?>