Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

smarty_internal_compile_private_registered_function.php 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * @throws \SmartyCompilerException
  35. * @throws \SmartyException
  36. */
  37. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
  38. {
  39. // check and get attributes
  40. $_attr = $this->getAttributes($compiler, $args);
  41. unset($_attr[ 'nocache' ]);
  42. if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) {
  43. $tag_info = $compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
  44. $is_registered = true;
  45. } else {
  46. $tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
  47. $is_registered = false;
  48. }
  49. // not cacheable?
  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. // compile code
  65. if ($is_registered) {
  66. $output =
  67. "call_user_func_array( \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0], array( {$_params},\$_smarty_tpl ) )";
  68. } else {
  69. $function = $tag_info[ 0 ];
  70. if (!is_array($function)) {
  71. $output = "{$function}({$_params},\$_smarty_tpl)";
  72. } else {
  73. $output = "{$function[0]}::{$function[1]}({$_params},\$_smarty_tpl)";
  74. }
  75. }
  76. if (!empty($parameter[ 'modifierlist' ])) {
  77. $output = $compiler->compileTag('private_modifier', array(),
  78. array('modifierlist' => $parameter[ 'modifierlist' ],
  79. 'value' => $output));
  80. }
  81. $output = "<?php echo {$output};?>\n";
  82. return $output;
  83. }
  84. }