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

http://zoop.googlecode.com/ · PHP · 67 lines · 34 code · 3 blank · 30 comment · 12 complexity · 73824b65bcb72c1a19b1f82612b6ae15 MD5 · raw file

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