PageRenderTime 28ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_compile_private_modifier.php

http://zoop.googlecode.com/
PHP | 59 lines | 34 code | 1 blank | 24 comment | 14 complexity | e56769348b405c08026a4cf0e6dc32ba MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  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 if (is_object($function[0])) {
  35. $output = 'call_user_func_array($_smarty_tpl->smarty->registered_plugins[\'modifier\'][\'' . $_attr['modifier'] . '\'][0],array(' . $_attr['params'] . '))';
  36. } else {
  37. $output = 'call_user_func_array(array(\'' . $function[0] . '\',\'' . $function[1] . '\'),array(' . $_attr['params'] . '))';
  38. }
  39. // check for plugin modifier
  40. } else if ($function = $this->compiler->getPlugin($_attr['modifier'], 'modifier')) {
  41. if (!is_array($function)) {
  42. $output = "{$function}({$_attr['params']})";
  43. } else {
  44. $output = 'call_user_func_array(array(\'' . $function[0] . '\',\'' . $function[1] . '\'),array(' . $_attr['params'] . '))';
  45. }
  46. // check if trusted PHP function
  47. } else if (is_callable($_attr['modifier'])) {
  48. // check if modifier allowed
  49. if (!$this->compiler->template->security || $this->smarty->security_handler->isTrustedModifier($_attr['modifier'], $this->compiler)) {
  50. $output = "{$_attr['modifier']}({$_attr['params']})";
  51. }
  52. } else {
  53. $this->compiler->trigger_template_error ("unknown modifier \"" . $_attr['modifier'] . "\"");
  54. }
  55. return $output;
  56. }
  57. }
  58. ?>