smarty_internal_compile_private_registered_function.php 3.3 KB

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