smarty_internal_function_call_handler.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Function Call Handler
  4. *
  5. * @package Smarty
  6. * @subpackage PluginsInternal
  7. * @author Uwe Tews
  8. */
  9. /**
  10. * This class does call function defined with the {function} tag
  11. *
  12. * @package Smarty
  13. * @subpackage PluginsInternal
  14. */
  15. class Smarty_Internal_Function_Call_Handler {
  16. /**
  17. * This function handles calls to template functions defined by {function}
  18. * It does create a PHP function at the first call
  19. *
  20. * @param string $_name template function name
  21. * @param Smarty_Internal_Template $_template template object
  22. * @param array $_params Smarty variables passed as call parameter
  23. * @param string $_hash nocache hash value
  24. * @param bool $_nocache nocache flag
  25. */
  26. public static function call($_name, Smarty_Internal_Template $_template, $_params, $_hash, $_nocache)
  27. {
  28. if ($_nocache) {
  29. $_function = "smarty_template_function_{$_name}_nocache";
  30. } else {
  31. $_function = "smarty_template_function_{$_hash}_{$_name}";
  32. }
  33. if (!is_callable($_function)) {
  34. $_code = "function {$_function}(\$_smarty_tpl,\$params) {
  35. \$saved_tpl_vars = \$_smarty_tpl->tpl_vars;
  36. foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);};
  37. foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
  38. if ($_nocache) {
  39. $_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!",
  40. "!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']);
  41. $_template->smarty->template_functions[$_name]['called_nocache'] = true;
  42. } else {
  43. $_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']);
  44. }
  45. $_code .= "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}";
  46. eval($_code);
  47. }
  48. $_function($_template, $_params);
  49. }
  50. }
  51. ?>