]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_private_special_variable.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_compile_private_special_variable.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile Special Smarty Variable
4  * Compiles the special $smarty variables
5  *
6  * @package    Smarty
7  * @subpackage Compiler
8  * @author     Uwe Tews
9  */
10
11 /**
12  * Smarty Internal Plugin Compile special Smarty Variable Class
13  *
14  * @package    Smarty
15  * @subpackage Compiler
16  */
17 class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_CompileBase
18 {
19     /**
20      * Compiles code for the special $smarty variables
21      *
22      * @param  array                                       $args     array with attributes from parser
23      * @param \Smarty_Internal_TemplateCompilerBase        $compiler compiler object
24      * @param                                              $parameter
25      *
26      * @return string compiled code
27      * @throws \SmartyCompilerException
28      */
29     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
30     {
31         $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
32         $variable = strtolower($compiler->getId($_index[ 0 ]));
33         if ($variable === false) {
34             $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
35         }
36         if (!isset($compiler->smarty->security_policy) ||
37             $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)
38         ) {
39             switch ($variable) {
40                 case 'foreach':
41                 case 'section':
42                     if (!isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ])) {
43                         $class = 'Smarty_Internal_Compile_' . ucfirst($variable);
44                         Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ] = new $class;
45                     }
46                     return Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ]->compileSpecialVariable(array(), $compiler, $_index);
47                 case 'capture':
48                     if (class_exists('Smarty_Internal_Compile_Capture')) {
49                         return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
50                     }
51                     return '';
52                 case 'now':
53                     return 'time()';
54                 case 'cookies':
55                     if (isset($compiler->smarty->security_policy) &&
56                         !$compiler->smarty->security_policy->allow_super_globals
57                     ) {
58                         $compiler->trigger_template_error("(secure mode) super globals not permitted");
59                         break;
60                     }
61                     $compiled_ref = '$_COOKIE';
62                     break;
63                 case 'get':
64                 case 'post':
65                 case 'env':
66                 case 'server':
67                 case 'session':
68                 case 'request':
69                     if (isset($compiler->smarty->security_policy) &&
70                         !$compiler->smarty->security_policy->allow_super_globals
71                     ) {
72                         $compiler->trigger_template_error("(secure mode) super globals not permitted");
73                         break;
74                     }
75                     $compiled_ref = '$_' . strtoupper($variable);
76                     break;
77
78                 case 'template':
79                     return 'basename($_smarty_tpl->source->filepath)';
80
81                 case 'template_object':
82                     return '$_smarty_tpl';
83
84                 case 'current_dir':
85                     return 'dirname($_smarty_tpl->source->filepath)';
86
87                 case 'version':
88                     return "Smarty::SMARTY_VERSION";
89
90                 case 'const':
91                     if (isset($compiler->smarty->security_policy) &&
92                         !$compiler->smarty->security_policy->allow_constants
93                     ) {
94                         $compiler->trigger_template_error("(secure mode) constants not permitted");
95                         break;
96                     }
97                     if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
98                         return "@constant('{$_index[1]}')";
99                     } else {
100                         return "@constant({$_index[1]})";
101                     }
102
103                 case 'config':
104                     if (isset($_index[ 2 ])) {
105                         return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
106                     } else {
107                         return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
108                     }
109                 case 'ldelim':
110                     return "\$_smarty_tpl->smarty->left_delimiter";
111                 case 'rdelim':
112                     return "\$_smarty_tpl->smarty->right_delimiter";
113                 default:
114                     $compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined');
115                     break;
116             }
117             if (isset($_index[ 1 ])) {
118                 array_shift($_index);
119                 foreach ($_index as $_ind) {
120                     $compiled_ref = $compiled_ref . "[$_ind]";
121                 }
122             }
123             return $compiled_ref;
124         }
125     }
126 }