smarty_internal_function_call_handler.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. class Smarty_Internal_Function_Call_Handler extends Smarty_Internal_Template {
  13. static function call ($_name, $_template, $_params, $_hash, $_nocache)
  14. {
  15. if ($_nocache) {
  16. $_function = "smarty_template_function_{$_name}_nocache";
  17. $_template->smarty->template_functions[$_name]['called_nocache'] = true;
  18. } else {
  19. $_function = "smarty_template_function_{$_hash}_{$_name}";
  20. }
  21. if (!is_callable($_function)) {
  22. $_code = "function {$_function}(\$_smarty_tpl,\$params) {
  23. \$saved_tpl_vars = \$_smarty_tpl->tpl_vars;
  24. foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
  25. if ($_nocache) {
  26. $_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!",
  27. "!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']);
  28. } else {
  29. $_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']);
  30. }
  31. $_code .= "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}";
  32. eval($_code);
  33. }
  34. $_function($_template, $_params);
  35. }
  36. }
  37. ?>