Project

General

Profile

« Previous | Next » 

Revision 21

Added by Manuela about 7 years ago

OutputFilterApi: modified for new filter structure

View differences:

OutputFilterApi.php
37 37
 * @param   string $sContent  content to apply filters
38 38
 * @return  string
39 39
 */
40
    function OutputFilterApi($mFilters, $sContent)
40
    function OutputFilterApi($mFilters, $sContent, array $aOptions = [])
41 41
    {
42 42
        if (!is_array($mFilters)) {
43 43
            $mFilters = preg_split('/\s*?[,;| +]\s*?/', $mFilters, -1, PREG_SPLIT_NO_EMPTY);
44 44
        }
45
        $oDb = $GLOBALS['database'];
46
        $aFilterSettings = getOutputFilterSettings();
45 47
        foreach ($mFilters as $sFilter) {
46 48
            $aTmp = preg_split('/\?/', $sFilter, 2, PREG_SPLIT_NO_EMPTY);
47 49
            $sFilterName = $aTmp[0];
50
            if (!preg_match('/^[A-Z][A-Za-z0-9]+$/s', $sFilterName)) { continue; }
48 51
            $sOptions = (isset($aTmp[1])) ? $aTmp[1] : '';
49
            if (!preg_match('/^[A-Z][A-Za-z0-9]+$/s', $sFilterName)) { continue; }
50
            $sFilterFile = __DIR__.'/filters/'.'filter'.$sFilterName.'.php';
51
            $sFilterFunc = 'doFilter'.$sFilterName;
52
            if (is_readable($sFilterFile)) {
53
                if (!function_exists($sFilterFunc)) {
54
                    require($sFilterFile);
52
            $sFilterClass = 'addon\\'.basename(__DIR__).'\\filters\\'.$sFilterName.'\\Filter';
53
            if (class_exists($sFilterClass)) {
54
                if ($aFilterSettings[$sFilterName]) {
55
                    if ($sOptions) {
56
                        parse_str($sOptions, $aTmp);
57
                        $aOptions = array_merge($aTmp, $aOptions);
58
                    }
59
                    $sContent = (new $sFilterClass($oDb, $aFilterSettings, $aOptions))
60
                                ->execute($sContent);
55 61
                }
56
                $sContent = $sFilterFunc($sContent, $sOptions);
62
            } else {
63
                $sFilterFile = __DIR__.'/filters/'.'filter'.$sFilterName.'.php';
64
                $sFilterFunc = 'doFilter'.$sFilterName;
65
                if (is_readable($sFilterFile)) {
66
                    if (!function_exists($sFilterFunc)) {
67
                        require($sFilterFile);
68
                    }
69
                    $sContent = $sFilterFunc($sContent, $sOptions);
70
                }
57 71
            }
58 72
        }
59 73
        return $sContent;
......
82 96
            }
83 97
        }
84 98
        $aSettings['OutputFilterMode'] = 0;
85
        $aSettings['OutputFilterMode'] |= ((int)$aSettings['email_filter'] * pow(2, 0));  // n | 2^0
86
        $aSettings['OutputFilterMode'] |= ((int)$aSettings['mailto_filter'] * pow(2, 1)); // n | 2^1
99
        $aSettings['OutputFilterMode'] |= ((int)$aSettings['email_filter'] * (2**0));  // n | 2^0
100
        $aSettings['OutputFilterMode'] |= ((int)$aSettings['mailto_filter'] * (2**1)); // n | 2^1
87 101
    // return array with filter settings
88 102
        return $aSettings;
89 103
    }

Also available in: Unified diff