smarty_internal_compile_private_modifier.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Modifier
  4. *
  5. * Compiles code for modifier execution
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Modifier Class
  13. */
  14. class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles code for modifier execution
  17. *
  18. * @param array $args array with attributes from parser
  19. * @param object $compiler compiler object
  20. * @return string compiled code
  21. */
  22. public function compile($args, $compiler)
  23. {
  24. $this->compiler = $compiler;
  25. $this->smarty = $this->compiler->smarty;
  26. $this->required_attributes = array('modifier', 'params');
  27. // check and get attributes
  28. $_attr = $this->_get_attributes($args);
  29. // check for registered modifier
  30. if (isset($compiler->smarty->registered_plugins['modifier'][$_attr['modifier']])) {
  31. $function = $compiler->smarty->registered_plugins['modifier'][$_attr['modifier']][0];
  32. if (!is_array($function)) {
  33. $output = "{$function}({$_attr['params']})";
  34. } else {
  35. if (is_object($function[0])) {
  36. $output = '$_smarty_tpl->smarty->registered_plugins[\'modifier\'][\'' . $_attr['modifier'] . '\'][0][0]->' . $function[1] . '(' . $_attr['params'] . ')';
  37. } else {
  38. $output = $function[0] . '::' . $function[1] . '(' . $_attr['params'] . ')';
  39. }
  40. }
  41. // check for plugin modifier
  42. } else if ($function = $this->compiler->getPlugin($_attr['modifier'], 'modifier')) {
  43. $output = "{$function}({$_attr['params']})";
  44. // check if trusted PHP function
  45. } else if (is_callable($_attr['modifier'])) {
  46. // check if modifier allowed
  47. if (!$this->compiler->template->security || $this->smarty->security_handler->isTrustedModifier($_attr['modifier'], $this->compiler)) {
  48. $output = "{$_attr['modifier']}({$_attr['params']})";
  49. }
  50. } else {
  51. $this->compiler->trigger_template_error ("unknown modifier \"" . $_attr['modifier'] . "\"");
  52. }
  53. return $output;
  54. }
  55. }
  56. ?>