gluon-web-remote

Web remote Administration for big size of gluon routers
git clone git://archive.git.mtrnord.blog/MTRNord/gluon-web-remote.git
Log | Files | Refs | README

smarty_internal_compile_private_special_variable.php (4660B)


      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  object $compiler compiler object
     24      * @param         $parameter
     25      *
     26      * @return string compiled code
     27      */
     28     public function compile($args, $compiler, $parameter)
     29     {
     30         $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
     31         $compiled_ref = ' ';
     32         $variable = trim($_index[0], "'");
     33         if (!isset($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)) {
     34             switch ($variable) {
     35                 case 'foreach':
     36                     $name = trim($_index[1], "'");
     37                     $foreachVar = "'__foreach_{$name}'";
     38                     return "(isset(\$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}]) ? \$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}] : null)";
     39                 case 'section':
     40                     return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
     41                 case 'capture':
     42                     return "Smarty::\$_smarty_vars$parameter";
     43                 case 'now':
     44                     return 'time()';
     45                 case 'cookies':
     46                     if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
     47                         $compiler->trigger_template_error("(secure mode) super globals not permitted");
     48                         break;
     49                     }
     50                     $compiled_ref = '$_COOKIE';
     51                     break;
     52 
     53                 case 'get':
     54                 case 'post':
     55                 case 'env':
     56                 case 'server':
     57                 case 'session':
     58                 case 'request':
     59                     if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
     60                         $compiler->trigger_template_error("(secure mode) super globals not permitted");
     61                         break;
     62                     }
     63                     $compiled_ref = '$_' . strtoupper($variable);
     64                     break;
     65 
     66                 case 'template':
     67                     return 'basename($_smarty_tpl->source->filepath)';
     68 
     69                 case 'template_object':
     70                     return '$_smarty_tpl';
     71 
     72                 case 'current_dir':
     73                     return 'dirname($_smarty_tpl->source->filepath)';
     74 
     75                 case 'version':
     76                     $_version = Smarty::SMARTY_VERSION;
     77 
     78                     return "'$_version'";
     79 
     80                 case 'const':
     81                     if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) {
     82                         $compiler->trigger_template_error("(secure mode) constants not permitted");
     83                         break;
     84                     }
     85                     if (strpos($_index[1], '$') === false && strpos($_index[1], '\'') === false ) {
     86                         return "@constant('{$_index[1]}')";
     87                     } else {
     88                         return "@constant({$_index[1]})";
     89                     }
     90 
     91                 case 'config':
     92                     if (isset($_index[2])) {
     93                         return "(is_array(\$tmp = \$_smarty_tpl->getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)";
     94                     } else {
     95                         return "\$_smarty_tpl->getConfigVariable($_index[1])";
     96                     }
     97                 case 'ldelim':
     98                     $_ldelim = $compiler->smarty->left_delimiter;
     99 
    100                     return "'$_ldelim'";
    101 
    102                 case 'rdelim':
    103                     $_rdelim = $compiler->smarty->right_delimiter;
    104 
    105                     return "'$_rdelim'";
    106 
    107                 default:
    108                     $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
    109                     break;
    110             }
    111             if (isset($_index[1])) {
    112                 array_shift($_index);
    113                 foreach ($_index as $_ind) {
    114                     $compiled_ref = $compiled_ref . "[$_ind]";
    115                 }
    116             }
    117         }
    118         return $compiled_ref;
    119     }
    120 }