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_modifier.php (7378B)


      1 <?php
      2 
      3 /**
      4  * Smarty Internal Plugin Compile Modifier
      5  * Compiles code for modifier execution
      6  *
      7  * @package    Smarty
      8  * @subpackage Compiler
      9  * @author     Uwe Tews
     10  */
     11 
     12 /**
     13  * Smarty Internal Plugin Compile Modifier Class
     14  *
     15  * @package    Smarty
     16  * @subpackage Compiler
     17  */
     18 class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase
     19 {
     20     /**
     21      * Compiles code for modifier execution
     22      *
     23      * @param  array  $args      array with attributes from parser
     24      * @param  object $compiler  compiler object
     25      * @param  array  $parameter array with compilation parameter
     26      *
     27      * @return string compiled code
     28      */
     29     public function compile($args, $compiler, $parameter)
     30     {
     31         // check and get attributes
     32         $_attr = $this->getAttributes($compiler, $args);
     33         $output = $parameter['value'];
     34         // loop over list of modifiers
     35         foreach ($parameter['modifierlist'] as $single_modifier) {
     36             $modifier = $single_modifier[0];
     37             $single_modifier[0] = $output;
     38             $params = implode(',', $single_modifier);
     39             // check if we know already the type of modifier
     40             if (isset($compiler->known_modifier_type[$modifier])) {
     41                 $modifier_types = array($compiler->known_modifier_type[$modifier]);
     42             } else {
     43                 $modifier_types = array(1, 2, 3, 4, 5, 6);
     44             }
     45             foreach ($modifier_types as $type) {
     46                 switch ($type) {
     47                     case 1:
     48                         // registered modifier
     49                         if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) {
     50                             $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
     51                             if (!is_array($function)) {
     52                                 $output = "{$function}({$params})";
     53                             } else {
     54                                 if (is_object($function[0])) {
     55                                     $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
     56                                 } else {
     57                                     $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
     58                                 }
     59                             }
     60                             $compiler->known_modifier_type[$modifier] = $type;
     61                             break 2;
     62                         }
     63                         break;
     64                     case 2:
     65                         // registered modifier compiler
     66                         if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) {
     67                             $output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty);
     68                             $compiler->known_modifier_type[$modifier] = $type;
     69                             break 2;
     70                         }
     71                         break;
     72                     case 3:
     73                         // modifiercompiler plugin
     74                         if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
     75                             // check if modifier allowed
     76                             if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
     77                                 $plugin = 'smarty_modifiercompiler_' . $modifier;
     78                                 $output = $plugin($single_modifier, $compiler);
     79                             }
     80                             $compiler->known_modifier_type[$modifier] = $type;
     81                             break 2;
     82                         }
     83                         break;
     84                     case 4:
     85                         // modifier plugin
     86                         if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
     87                             // check if modifier allowed
     88                             if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
     89                                 $output = "{$function}({$params})";
     90                             }
     91                             $compiler->known_modifier_type[$modifier] = $type;
     92                             break 2;
     93                         }
     94                         break;
     95                     case 5:
     96                         // PHP function
     97                         if (is_callable($modifier)) {
     98                             // check if modifier allowed
     99                             if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) {
    100                                 $output = "{$modifier}({$params})";
    101                             }
    102                             $compiler->known_modifier_type[$modifier] = $type;
    103                             break 2;
    104                         }
    105                         break;
    106                     case 6:
    107                         // default plugin handler
    108                         if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) {
    109                             $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
    110                             // check if modifier allowed
    111                             if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
    112                                 if (!is_array($function)) {
    113                                     $output = "{$function}({$params})";
    114                                 } else {
    115                                     if (is_object($function[0])) {
    116                                         $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
    117                                     } else {
    118                                         $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
    119                                     }
    120                                 }
    121                             }
    122                             if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) {
    123                                 // was a plugin
    124                                 $compiler->known_modifier_type[$modifier] = 4;
    125                             } else {
    126                                 $compiler->known_modifier_type[$modifier] = $type;
    127                             }
    128                             break 2;
    129                         }
    130                 }
    131             }
    132             if (!isset($compiler->known_modifier_type[$modifier])) {
    133                 $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno);
    134             }
    135         }
    136 
    137         return $output;
    138     }
    139 }