Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

smarty_internal_compile_private_registered_function.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // This tag does create output
  38. $compiler->has_output = true;
  39. // check and get attributes
  40. $_attr = $this->getAttributes($compiler, $args);
  41. if ($_attr['nocache']) {
  42. $compiler->tag_nocache = true;
  43. }
  44. unset($_attr['nocache']);
  45. if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) {
  46. $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag];
  47. } else {
  48. $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag];
  49. }
  50. // not cachable?
  51. $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1];
  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. } elseif ($compiler->template->caching && in_array($_key, $tag_info[2])) {
  58. $_value = str_replace("'", "^#^", $_value);
  59. $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
  60. } else {
  61. $_paramsArray[] = "'$_key'=>$_value";
  62. }
  63. }
  64. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  65. $function = $tag_info[0];
  66. // compile code
  67. if (!is_array($function)) {
  68. $output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";
  69. } elseif (is_object($function[0])) {
  70. $output = "<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n";
  71. } else {
  72. $output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n";
  73. }
  74. return $output;
  75. }
  76. }