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_method_loadfilter.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Smarty Method LoadFilter
  4. *
  5. * Smarty::loadFilter() method
  6. *
  7. * @package Smarty
  8. * @subpackage PluginsInternal
  9. * @author Uwe Tews
  10. */
  11. class Smarty_Internal_Method_LoadFilter
  12. {
  13. /**
  14. * Valid for Smarty and template object
  15. *
  16. * @var int
  17. */
  18. public $objMap = 3;
  19. /**
  20. * Valid filter types
  21. *
  22. * @var array
  23. */
  24. private $filterTypes = array('pre' => true, 'post' => true, 'output' => true, 'variable' => true);
  25. /**
  26. * load a filter of specified type and name
  27. *
  28. * @api Smarty::loadFilter()
  29. *
  30. * @link http://www.smarty.net/docs/en/api.load.filter.tpl
  31. *
  32. * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
  33. * @param string $type filter type
  34. * @param string $name filter name
  35. *
  36. * @return bool
  37. * @throws SmartyException if filter could not be loaded
  38. */
  39. public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name)
  40. {
  41. $smarty = isset($obj->smarty) ? $obj->smarty : $obj;
  42. $this->_checkFilterType($type);
  43. $_plugin = "smarty_{$type}filter_{$name}";
  44. $_filter_name = $_plugin;
  45. if (is_callable($_plugin)) {
  46. $smarty->registered_filters[$type][$_filter_name] = $_plugin;
  47. return true;
  48. }
  49. if ($smarty->loadPlugin($_plugin)) {
  50. if (class_exists($_plugin, false)) {
  51. $_plugin = array($_plugin, 'execute');
  52. }
  53. if (is_callable($_plugin)) {
  54. $smarty->registered_filters[$type][$_filter_name] = $_plugin;
  55. return true;
  56. }
  57. }
  58. throw new SmartyException("{$type}filter \"{$name}\" not found or callable");
  59. }
  60. /**
  61. * Check if filter type is valid
  62. *
  63. * @param string $type
  64. *
  65. * @throws \SmartyException
  66. */
  67. public function _checkFilterType($type)
  68. {
  69. if (!isset($this->filterTypes[$type])) {
  70. throw new SmartyException("Illegal filter type \"{$type}\"");
  71. }
  72. }
  73. }