4  * Smarty Internal Plugin Compile Function_Call
 
   6  * Compiles the calls of user defined tags defined by {function}
 
  14  * Smarty Internal Plugin Compile Function_Call Class
 
  16 class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
 
  17         // attribute definitions
 
  18     public $required_attributes = array('name');
 
  19     public $shorttag_order = array('name');
 
  20     public $optional_attributes = array('_any'); 
 
  23      * Compiles the calls of user defined tags defined by {function}
 
  25      * @param array $args array with attributes from parser
 
  26      * @param object $compiler compiler object
 
  27      * @param array $parameter array with compilation parameter
 
  28      * @return string compiled code
 
  30     public function compile($args, $compiler)
 
  32         $this->compiler = $compiler;
 
  33         $this->smarty = $compiler->smarty;
 
  34         // check and get attributes
 
  35         $_attr = $this->_get_attributes($args); 
 
  36         // save possible attributes
 
  37         if (isset($_attr['assign'])) {
 
  38             // output will be stored in a smarty variable instead of beind displayed
 
  39             $_assign = $_attr['assign'];
 
  41         $_name = $_attr['name'];
 
  42         unset($_attr['name'], $_attr['assign'], $_attr['nocache']); 
 
  43         // set flag (compiled code of {function} must be included in cache file
 
  44         if ($compiler->nocache || $compiler->tag_nocache) {
 
  49         $_paramsArray = array();
 
  50         foreach ($_attr as $_key => $_value) {
 
  52                 $_paramsArray[] = "$_key=>$_value";
 
  54                 $_paramsArray[] = "'$_key'=>$_value";
 
  57         if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
 
  58             foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
 
  59                 if (!isset($_attr[$_key])) {
 
  61                         $_paramsArray[] = "$_key=>$_value";
 
  63                         $_paramsArray[] = "'$_key'=>$_value";
 
  67         } elseif (isset($this->smarty->template_functions[$_name]['parameter'])) {
 
  68            foreach ($this->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
 
  69                 if (!isset($_attr[$_key])) {
 
  71                         $_paramsArray[] = "$_key=>$_value";
 
  73                         $_paramsArray[] = "'$_key'=>$_value";
 
  79         if (!(strpos($_name,'$')===false)) {
 
  81                 $call_function = '$tmp = "smarty_template_function_".'.$_name.'; $tmp';
 
  83                 $_name = trim($_name, "'\"");
 
  84                 $call_cache = "'{$_name}'";
 
  85                 $call_function = 'smarty_template_function_'.$_name;
 
  88         $_params = 'array(' . implode(",", $_paramsArray) . ')';
 
  89         $_hash = str_replace('-','_',$compiler->template->properties['nocache_hash']);
 
  90         // was there an assign attribute
 
  91         if (isset($_assign)) {
 
  92             if ($compiler->template->caching) {
 
  93                 $_output = "<?php ob_start(); Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
 
  95                 $_output = "<?php ob_start(); {$call_function}(\$_smarty_tpl,{$_params}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
 
  98             if ($compiler->template->caching) {
 
  99                 $_output = "<?php Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache});?>\n";
 
 101                 $_output = "<?php {$call_function}(\$_smarty_tpl,{$_params});?>\n";