You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_runtime_filterhandler.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Filter Handler
  4. * Smarty filter handler class
  5. *
  6. * @package Smarty
  7. * @subpackage PluginsInternal
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Class for filter processing
  12. *
  13. * @package Smarty
  14. * @subpackage PluginsInternal
  15. */
  16. class Smarty_Internal_Runtime_FilterHandler
  17. {
  18. /**
  19. * Run filters over content
  20. * The filters will be lazy loaded if required
  21. * class name format: Smarty_FilterType_FilterName
  22. * plugin filename format: filtertype.filtername.php
  23. * Smarty2 filter plugins could be used
  24. *
  25. * @param string $type the type of filter ('pre','post','output') which shall run
  26. * @param string $content the content which shall be processed by the filters
  27. * @param Smarty_Internal_Template $template template object
  28. *
  29. * @throws SmartyException
  30. * @return string the filtered content
  31. */
  32. public function runFilter($type, $content, Smarty_Internal_Template $template)
  33. {
  34. // loop over autoload filters of specified type
  35. if (!empty($template->smarty->autoload_filters[ $type ])) {
  36. foreach ((array) $template->smarty->autoload_filters[ $type ] as $name) {
  37. $plugin_name = "Smarty_{$type}filter_{$name}";
  38. if (function_exists($plugin_name)) {
  39. $callback = $plugin_name;
  40. } elseif (class_exists($plugin_name, false) && is_callable(array($plugin_name, 'execute'))) {
  41. $callback = array($plugin_name, 'execute');
  42. } elseif ($template->smarty->loadPlugin($plugin_name, false)) {
  43. if (function_exists($plugin_name)) {
  44. // use loaded Smarty2 style plugin
  45. $callback = $plugin_name;
  46. } elseif (class_exists($plugin_name, false) && is_callable(array($plugin_name, 'execute'))) {
  47. // loaded class of filter plugin
  48. $callback = array($plugin_name, 'execute');
  49. } else {
  50. throw new SmartyException("Auto load {$type}-filter plugin method '{$plugin_name}::execute' not callable");
  51. }
  52. } else {
  53. // nothing found, throw exception
  54. throw new SmartyException("Unable to auto load {$type}-filter plugin '{$plugin_name}'");
  55. }
  56. $content = call_user_func($callback, $content, $template);
  57. }
  58. }
  59. // loop over registered filters of specified type
  60. if (!empty($template->smarty->registered_filters[ $type ])) {
  61. foreach ($template->smarty->registered_filters[ $type ] as $key => $name) {
  62. $content = call_user_func($template->smarty->registered_filters[ $type ][ $key ], $content, $template);
  63. }
  64. }
  65. // return filtered output
  66. return $content;
  67. }
  68. }