Adjusted time.php to honor note on separate row option.
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_filter.php
1 <?php
2
3 /**
4  * Smarty Internal Plugin Filter
5  * 
6  * External Smarty filter methods
7  * 
8  * @package Smarty
9  * @author Uwe Tews 
10  */
11
12 /**
13  * Class for filter methods
14  */
15 class Smarty_Internal_Filter {
16
17     function __construct($smarty)
18     {
19         $this->smarty = $smarty;
20     } 
21     /**
22      * Registers a filter function
23      * 
24      * @param string $type filter type
25      * @param callback $callback 
26      */
27         public function registerFilter($type, $callback)
28         {
29                 $this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
30         }
31
32     /**
33      * Unregisters a filter function
34      * 
35      * @param string $type filter type
36      * @param callback $callback 
37      */
38         public function unregisterFilter($type, $callback)
39         {
40                 $name = $this->_get_filter_name($callback);
41                 if(isset($this->smarty->registered_filters[$type][$name])) {
42                 unset($this->smarty->registered_filters[$type][$name]);
43                 }
44         }
45
46
47     /**
48      * Return internal filter name
49      * 
50      * @param callback $function_name 
51      */
52     public function _get_filter_name($function_name)
53     {
54         if (is_array($function_name)) {
55             $_class_name = (is_object($function_name[0]) ?
56                 get_class($function_name[0]) : $function_name[0]);
57             return $_class_name . '_' . $function_name[1];
58         } else {
59             return $function_name;
60         } 
61     } 
62
63
64     /**
65      * load a filter of specified type and name
66      * 
67      * @param string $type filter type
68      * @param string $name filter name
69      * @return bool 
70      */
71     function loadFilter($type, $name)
72     {
73         $_plugin = "smarty_{$type}filter_{$name}";
74         $_filter_name = $_plugin;
75         if ($this->smarty->loadPlugin($_plugin)) {
76             if (class_exists($_plugin, false)) {
77                 $_plugin = array($_plugin, 'execute');
78             } 
79             if (is_callable($_plugin)) {
80                 return $this->smarty->registered_filters[$type][$_filter_name] = $_plugin;
81             } 
82         } 
83         throw new SmartyException("{$type}filter \"{$name}\" not callable");
84         return false;
85     } 
86
87
88 }
89 ?>