smarty_internal_compile_private_registered_function.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Registered Function
  4. *
  5. * Compiles code for the execution of a registered function
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Registered Function Class
  13. *
  14. * @package Smarty
  15. * @subpackage Compiler
  16. */
  17. class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase {
  18. /**
  19. * Attribute definition: Overwrites base class.
  20. *
  21. * @var array
  22. * @see Smarty_Internal_CompileBase
  23. */
  24. public $optional_attributes = array('_any');
  25. /**
  26. * Compiles code for the execution of a registered function
  27. *
  28. * @param array $args array with attributes from parser
  29. * @param object $compiler compiler object
  30. * @param array $parameter array with compilation parameter
  31. * @param string $tag name of function
  32. * @return string compiled code
  33. */
  34. public function compile($args, $compiler, $parameter, $tag)
  35. {
  36. // This tag does create output
  37. $compiler->has_output = true;
  38. // check and get attributes
  39. $_attr = $this->getAttributes($compiler, $args);
  40. if ($_attr['nocache']) {
  41. $compiler->tag_nocache = true;
  42. }
  43. unset($_attr['nocache']);
  44. if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) {
  45. $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag];
  46. } else {
  47. $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag];
  48. }
  49. // not cachable?
  50. $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1];
  51. // convert attributes into parameter array string
  52. $_paramsArray = array();
  53. foreach ($_attr as $_key => $_value) {
  54. if (is_int($_key)) {
  55. $_paramsArray[] = "$_key=>$_value";
  56. } elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) {
  57. $_value = str_replace("'","^#^",$_value);
  58. $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
  59. } else {
  60. $_paramsArray[] = "'$_key'=>$_value";
  61. }
  62. }
  63. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  64. $function = $tag_info[0];
  65. // compile code
  66. if (!is_array($function)) {
  67. $output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";
  68. } else if (is_object($function[0])) {
  69. $output = "<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n";
  70. } else {
  71. $output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n";
  72. }
  73. return $output;
  74. }
  75. }
  76. ?>