library/smarty/libs/sysplugins/smarty_internal_compile_private_registered_function.php
changeset 46 f11c31f7fa3e
parent 45 a56e7f9a0463
child 47 03388ec805b4
equal deleted inserted replaced
45:a56e7f9a0463 46:f11c31f7fa3e
     1 <?php
       
     2 /**
       
     3  * Smarty Internal Plugin Compile Registered Function
       
     4  * Compiles code for the execution of a registered function
       
     5  *
       
     6  * @package    Smarty
       
     7  * @subpackage Compiler
       
     8  * @author     Uwe Tews
       
     9  */
       
    10 
       
    11 /**
       
    12  * Smarty Internal Plugin Compile Registered Function Class
       
    13  *
       
    14  * @package    Smarty
       
    15  * @subpackage Compiler
       
    16  */
       
    17 class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase {
       
    18     /**
       
    19      * Attribute definition: Overwrites base class.
       
    20      *
       
    21      * @var array
       
    22      * @see Smarty_Internal_CompileBase
       
    23      */
       
    24     public $optional_attributes = array('_any');
       
    25 
       
    26     /**
       
    27      * Compiles code for the execution of a registered function
       
    28      *
       
    29      * @param  array $args array with attributes from parser
       
    30      * @param  object $compiler compiler object
       
    31      * @param  array $parameter array with compilation parameter
       
    32      * @param  string $tag name of function
       
    33      *
       
    34      * @return string compiled code
       
    35      */
       
    36     public function compile($args, $compiler, $parameter, $tag) {
       
    37         // This tag does create output
       
    38         $compiler->has_output = true;
       
    39         // check and get attributes
       
    40         $_attr = $this->getAttributes($compiler, $args);
       
    41         if ($_attr['nocache']) {
       
    42             $compiler->tag_nocache = true;
       
    43         }
       
    44         unset($_attr['nocache']);
       
    45         if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) {
       
    46             $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag];
       
    47         } else {
       
    48             $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag];
       
    49         }
       
    50         // not cachable?
       
    51         $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1];
       
    52         // convert attributes into parameter array string
       
    53         $_paramsArray = array();
       
    54         foreach ($_attr as $_key => $_value) {
       
    55             if (is_int($_key)) {
       
    56                 $_paramsArray[] = "$_key=>$_value";
       
    57             } elseif ($compiler->template->caching && in_array($_key, $tag_info[2])) {
       
    58                 $_value = str_replace("'", "^#^", $_value);
       
    59                 $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
       
    60             } else {
       
    61                 $_paramsArray[] = "'$_key'=>$_value";
       
    62             }
       
    63         }
       
    64         $_params = 'array(' . implode(",", $_paramsArray) . ')';
       
    65         $function = $tag_info[0];
       
    66         // compile code
       
    67         if (!is_array($function)) {
       
    68             $output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";
       
    69         } elseif (is_object($function[0])) {
       
    70             $output = "<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n";
       
    71         } else {
       
    72             $output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n";
       
    73         }
       
    74 
       
    75         return $output;
       
    76     }
       
    77 }