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