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