smarty_internal_compile_call.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles the calls of user defined tags defined by {function}
  17. *
  18. * @param array $args array with attributes from parser
  19. * @param object $compiler compiler object
  20. * @return string compiled code
  21. */
  22. public function compile($args, $compiler)
  23. {
  24. $this->compiler = $compiler;
  25. $this->smarty = $compiler->smarty;
  26. $this->required_attributes = array('name');
  27. $this->optional_attributes = array('_any');
  28. // check and get attributes
  29. $_attr = $this->_get_attributes($args);
  30. // save posible attributes
  31. if (isset($_attr['assign'])) {
  32. // output will be stored in a smarty variable instead of beind displayed
  33. $_assign = $_attr['assign'];
  34. }
  35. $_name = trim($_attr['name'], "'\"");
  36. unset($_attr['name'], $_attr['assign']);
  37. // set flag (compiled code of {function} must be included in cache file
  38. if ($compiler->nocache || $compiler->tag_nocache) {
  39. $_nocache = 'true';
  40. } else {
  41. $_nocache = 'false';
  42. }
  43. $_paramsArray = array();
  44. foreach ($_attr as $_key => $_value) {
  45. if (is_int($_key)) {
  46. $_paramsArray[] = "$_key=>$_value";
  47. } else {
  48. $_paramsArray[] = "'$_key'=>$_value";
  49. }
  50. }
  51. if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
  52. foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
  53. if (!isset($_attr[$_key])) {
  54. if (is_int($_key)) {
  55. $_paramsArray[] = "$_key=>$_value";
  56. } else {
  57. $_paramsArray[] = "'$_key'=>$_value";
  58. }
  59. }
  60. }
  61. } elseif (isset($this->smarty->template_functions[$_name]['parameter'])) {
  62. foreach ($this->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
  63. if (!isset($_attr[$_key])) {
  64. if (is_int($_key)) {
  65. $_paramsArray[] = "$_key=>$_value";
  66. } else {
  67. $_paramsArray[] = "'$_key'=>$_value";
  68. }
  69. }
  70. }
  71. }
  72. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  73. $_hash = str_replace('-','_',$compiler->template->properties['nocache_hash']);
  74. // was there an assign attribute
  75. if (isset($_assign)) {
  76. if ($compiler->template->caching) {
  77. $_output = "\$_smarty_tpl->assign({$_assign},Smarty_Internal_Function_Call_Handler::call ('{$_name}',\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache}));?>\n";
  78. } else {
  79. $_output = "\$_smarty_tpl->assign({$_assign},smarty_template_function_{$_name}(\$_smarty_tpl,{$_params}));?>\n";
  80. }
  81. } else {
  82. if ($compiler->template->caching) {
  83. $_output = "<?php Smarty_Internal_Function_Call_Handler::call ('{$_name}',\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache});?>\n";
  84. } else {
  85. $_output = "<?php smarty_template_function_{$_name}(\$_smarty_tpl,{$_params});?>\n";
  86. }
  87. }
  88. return $_output;
  89. }
  90. }
  91. ?>