smarty_internal_compile_call.php (2772B)
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 /** 20 * Attribute definition: Overwrites base class. 21 * 22 * @var array 23 * @see Smarty_Internal_CompileBase 24 */ 25 public $required_attributes = array('name'); 26 /** 27 * Attribute definition: Overwrites base class. 28 * 29 * @var array 30 * @see Smarty_Internal_CompileBase 31 */ 32 public $shorttag_order = array('name'); 33 /** 34 * Attribute definition: Overwrites base class. 35 * 36 * @var array 37 * @see Smarty_Internal_CompileBase 38 */ 39 public $optional_attributes = array('_any'); 40 41 /** 42 * Compiles the calls of user defined tags defined by {function} 43 * 44 * @param array $args array with attributes from parser 45 * @param object $compiler compiler object 46 * 47 * @return string compiled code 48 */ 49 public function compile($args, $compiler) 50 { 51 // check and get attributes 52 $_attr = $this->getAttributes($compiler, $args); 53 // save possible attributes 54 if (isset($_attr['assign'])) { 55 // output will be stored in a smarty variable instead of being displayed 56 $_assign = $_attr['assign']; 57 } 58 //$_name = trim($_attr['name'], "'\""); 59 $_name = $_attr['name']; 60 unset($_attr['name'], $_attr['assign'], $_attr['nocache']); 61 // set flag (compiled code of {function} must be included in cache file 62 if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) { 63 $_nocache = 'true'; 64 } else { 65 $_nocache = 'false'; 66 } 67 $_paramsArray = array(); 68 foreach ($_attr as $_key => $_value) { 69 if (is_int($_key)) { 70 $_paramsArray[] = "$_key=>$_value"; 71 } else { 72 $_paramsArray[] = "'$_key'=>$_value"; 73 } 74 } 75 $_params = 'array(' . implode(",", $_paramsArray) . ')'; 76 //$compiler->suppressNocacheProcessing = true; 77 // was there an assign attribute 78 if (isset($_assign)) { 79 $_output = "<?php ob_start();\$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; 80 } else { 81 $_output = "<?php \$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});?>\n"; 82 } 83 return $_output; 84 } 85 }