smarty_internal_compile_private_function_plugin.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Function Plugin
  4. *
  5. * Compiles code for the execution of function plugin
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Function Plugin Class
  13. *
  14. * @package Smarty
  15. * @subpackage Compiler
  16. */
  17. class Smarty_Internal_Compile_Private_Function_Plugin 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();
  25. /**
  26. * Attribute definition: Overwrites base class.
  27. *
  28. * @var array
  29. * @see Smarty_Internal_CompileBase
  30. */
  31. public $optional_attributes = array('_any');
  32. /**
  33. * Compiles code for the execution of function plugin
  34. *
  35. * @param array $args array with attributes from parser
  36. * @param object $compiler compiler object
  37. * @param array $parameter array with compilation parameter
  38. * @param string $tag name of function plugin
  39. * @param string $function PHP function name
  40. * @return string compiled code
  41. */
  42. public function compile($args, $compiler, $parameter, $tag, $function)
  43. {
  44. // This tag does create output
  45. $compiler->has_output = true;
  46. // check and get attributes
  47. $_attr = $this->getAttributes($compiler, $args);
  48. if ($_attr['nocache'] === true) {
  49. $compiler->tag_nocache = true;
  50. }
  51. unset($_attr['nocache']);
  52. // convert attributes into parameter array string
  53. $_paramsArray = array();
  54. foreach ($_attr as $_key => $_value) {
  55. if (is_int($_key)) {
  56. $_paramsArray[] = "$_key=>$_value";
  57. } else {
  58. $_paramsArray[] = "'$_key'=>$_value";
  59. }
  60. }
  61. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  62. // compile code
  63. $output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";
  64. return $output;
  65. }
  66. }
  67. ?>