PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_filter_handler.php

http://zoop.googlecode.com/
PHP | 67 lines | 34 code | 3 blank | 30 comment | 12 complexity | 73824b65bcb72c1a19b1f82612b6ae15 MD5 | raw file
 1<?php
 2
 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 */
12
13/**
14 * Class for filter processing
15 */
16class 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, $smarty, $flag = null)
30    {
31        $output = $content;
32        if ($type != 'variable' || ($smarty->variable_filter && $flag !== false) || $flag === true) {
33            // loop over autoload filters of specified type
34            if (!empty($smarty->autoload_filters[$type])) {
35                foreach ((array)$smarty->autoload_filters[$type] as $name) {
36                    $plugin_name = "Smarty_{$type}filter_{$name}";
37                    if ($smarty->loadPlugin($plugin_name)) {
38                        if (function_exists($plugin_name)) {
39                            // use loaded Smarty2 style plugin
40                            $output = $plugin_name($output, $smarty);
41                        } elseif (class_exists($plugin_name, false)) {
42                            // loaded class of filter plugin
43                            $output = call_user_func(array($plugin_name, 'execute'), $output, $smarty);
44                        } 
45                    } else {
46                        // nothing found, throw exception
47                        throw new Exception("Unable to load filter {$plugin_name}");
48                    } 
49                } 
50            } 
51            // loop over registerd filters of specified type
52            if (!empty($smarty->registered_filters[$type])) {
53                foreach ($smarty->registered_filters[$type] as $key => $name) {
54                    if (is_array($smarty->registered_filters[$type][$key])) {
55                        $output = call_user_func($smarty->registered_filters[$type][$key], $output, $smarty);
56                    } else {
57                        $output = $smarty->registered_filters[$type][$key]($output, $smarty);
58                    } 
59                } 
60            } 
61        } 
62        // return filtered output
63        return $output;
64    } 
65} 
66
67?>