Code

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