smarty_internal_compile_call.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Function_Call
  4. *
  5. * Compiles the calls of user defined tags defined by {function}
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  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. * Compiles the calls of user defined tags defined by {function}
  41. *
  42. * @param array $args array with attributes from parser
  43. * @param object $compiler compiler object
  44. * @param array $parameter array with compilation parameter
  45. * @return string compiled code
  46. */
  47. public function compile($args, $compiler)
  48. {
  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 beind displayed
  54. $_assign = $_attr['assign'];
  55. }
  56. $_name = $_attr['name'];
  57. if ($compiler->compiles_template_function) {
  58. $compiler->called_functions[] = trim($_name, "'\"");
  59. }
  60. unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
  61. // set flag (compiled code of {function} must be included in cache file
  62. if ($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. if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
  76. foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
  77. if (!isset($_attr[$_key])) {
  78. if (is_int($_key)) {
  79. $_paramsArray[] = "$_key=>$_value";
  80. } else {
  81. $_paramsArray[] = "'$_key'=>$_value";
  82. }
  83. }
  84. }
  85. } elseif (isset($compiler->smarty->template_functions[$_name]['parameter'])) {
  86. foreach ($compiler->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
  87. if (!isset($_attr[$_key])) {
  88. if (is_int($_key)) {
  89. $_paramsArray[] = "$_key=>$_value";
  90. } else {
  91. $_paramsArray[] = "'$_key'=>$_value";
  92. }
  93. }
  94. }
  95. }
  96. //varibale name?
  97. if (!(strpos($_name, '$') === false)) {
  98. $call_cache = $_name;
  99. $call_function = '$tmp = "smarty_template_function_".' . $_name . '; $tmp';
  100. } else {
  101. $_name = trim($_name, "'\"");
  102. $call_cache = "'{$_name}'";
  103. $call_function = 'smarty_template_function_' . $_name;
  104. }
  105. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  106. $_hash = str_replace('-', '_', $compiler->template->properties['nocache_hash']);
  107. // was there an assign attribute
  108. if (isset($_assign)) {
  109. if ($compiler->template->caching) {
  110. $_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";
  111. } else {
  112. $_output = "<?php ob_start(); {$call_function}(\$_smarty_tpl,{$_params}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
  113. }
  114. } else {
  115. if ($compiler->template->caching) {
  116. $_output = "<?php Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache});?>\n";
  117. } else {
  118. $_output = "<?php {$call_function}(\$_smarty_tpl,{$_params});?>\n";
  119. }
  120. }
  121. return $_output;
  122. }
  123. }
  124. ?>