library/smarty/libs/sysplugins/smarty_internal_compile_call.php
changeset 0 4869aea77e21
equal deleted inserted replaced
-1:000000000000 0:4869aea77e21
       
     1 <?php
       
     2 /**
       
     3  * Smarty Internal Plugin Compile Function_Call
       
     4  * Compiles the calls of user defined tags defined by {function}
       
     5  *
       
     6  * @package    Smarty
       
     7  * @subpackage Compiler
       
     8  * @author     Uwe Tews
       
     9  */
       
    10 
       
    11 /**
       
    12  * Smarty Internal Plugin Compile Function_Call Class
       
    13  *
       
    14  * @package    Smarty
       
    15  * @subpackage Compiler
       
    16  */
       
    17 class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
       
    18     /**
       
    19      * Attribute definition: Overwrites base class.
       
    20      *
       
    21      * @var array
       
    22      * @see Smarty_Internal_CompileBase
       
    23      */
       
    24     public $required_attributes = array('name');
       
    25     /**
       
    26      * Attribute definition: Overwrites base class.
       
    27      *
       
    28      * @var array
       
    29      * @see Smarty_Internal_CompileBase
       
    30      */
       
    31     public $shorttag_order = array('name');
       
    32     /**
       
    33      * Attribute definition: Overwrites base class.
       
    34      *
       
    35      * @var array
       
    36      * @see Smarty_Internal_CompileBase
       
    37      */
       
    38     public $optional_attributes = array('_any');
       
    39 
       
    40     /**
       
    41      * Compiles the calls of user defined tags defined by {function}
       
    42      *
       
    43      * @param  array $args array with attributes from parser
       
    44      * @param  object $compiler compiler object
       
    45      *
       
    46      * @return string compiled code
       
    47      */
       
    48     public function compile($args, $compiler) {
       
    49         // check and get attributes
       
    50         $_attr = $this->getAttributes($compiler, $args);
       
    51         // save possible attributes
       
    52         if (isset($_attr['assign'])) {
       
    53             // output will be stored in a smarty variable instead of being displayed
       
    54             $_assign = $_attr['assign'];
       
    55         }
       
    56         //$_name = trim($_attr['name'], "'\"");
       
    57         $_name = $_attr['name'];
       
    58         unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
       
    59         // set flag (compiled code of {function} must be included in cache file
       
    60         if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) {
       
    61             $_nocache = 'true';
       
    62         } else {
       
    63             $_nocache = 'false';
       
    64         }
       
    65         $_paramsArray = array();
       
    66         foreach ($_attr as $_key => $_value) {
       
    67             if (is_int($_key)) {
       
    68                 $_paramsArray[] = "$_key=>$_value";
       
    69             } else {
       
    70                 $_paramsArray[] = "'$_key'=>$_value";
       
    71             }
       
    72         }
       
    73         $_params = 'array(' . implode(",", $_paramsArray) . ')';
       
    74         //$compiler->suppressNocacheProcessing = true;
       
    75         // was there an assign attribute
       
    76         if (isset($_assign)) {
       
    77             $_output = "<?php ob_start();\$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
       
    78         } else {
       
    79             $_output = "<?php \$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});?>\n";
       
    80         }
       
    81         return $_output;
       
    82     }
       
    83 }