Project

General

Profile

1
<?php
2
/**
3
 *  Copyright (C) 2013 Werner v.d. Decken <wkl@isteam.de>
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation, either version 3 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
/**
19
 * OutputFilterApi.php
20
 *
21
 * @category     Addons
22
 * @package      Addons_OutputFilter
23
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
24
 * @author       Manuela v.d.Decken <manuela@isteam.de>
25
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
26
 * @version      0.0.1
27
 * @lastmodified $Date: 2017-10-10 00:03:30 +0200 (Tue, 10 Oct 2017) $
28
 * @since        File available since 25.12.2013
29
 * @description  can apply one ore more filters to $content
30
 *      Example: $sContent = OutputFilterApi('WbLink', $sContent);
31
 *      or..     $sContent = OutputFilterApi('WbLink|Relurl', $sContent);
32
 *      or..     $sContent = OutputFilterApi(array('WbLink', 'RelUrl'), $sContent);
33
 */
34
/**
35
 * OutputFilterApi
36
 * @param   string|array $mFilters  list of one or more filters
37
 * @param   string $sContent  content to apply filters
38
 * @return  string
39
 */
40
    function OutputFilterApi($mFilters, $sContent, array $aOptions = [])
41
    {
42
        if (!is_array($mFilters)) {
43
            $mFilters = preg_split('/\s*?[,;| +]\s*?/', $mFilters, -1, PREG_SPLIT_NO_EMPTY);
44
        }
45
        $oDb = $GLOBALS['database'];
46
        $aFilterSettings = getOutputFilterSettings();
47
        foreach ($mFilters as $sFilter) {
48
            $aTmp = preg_split('/\?/', $sFilter, 2, PREG_SPLIT_NO_EMPTY);
49
            $sFilterName = $aTmp[0];
50
            if (!preg_match('/^[A-Z][A-Za-z0-9]+$/s', $sFilterName)) { continue; }
51
            $sOptions = (isset($aTmp[1])) ? $aTmp[1] : '';
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);
61
                }
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
                }
71
            }
72
        }
73
        return $sContent;
74
    }
75
/* ************************************************************************** */
76
/**
77
 * function to read the current filter settings
78
 * @global object $database
79
 * @global object $admin
80
 * @param void
81
 * @return array contains all settings
82
 */
83
    function getOutputFilterSettings()
84
    {
85
        global $database;
86
    // set default values
87
        $aSettings = array(
88
            'at_replacement'  => '(at)',
89
            'dot_replacement' => '(dot)'
90
        );
91
    // request settings from database
92
        $sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_output_filter`';
93
        if (($oRes = $database->query($sql))) {
94
            while (($aRec = $oRes->fetchRow(MYSQLI_ASSOC))) {
95
                $aSettings[$aRec['name']] = $aRec['value'];
96
            }
97
        }
98
        $aSettings['OutputFilterMode'] = 0;
99
        $aSettings['OutputFilterMode'] |= ((int)$aSettings['email_filter'] * (2**0));  // n | 2^0
100
        $aSettings['OutputFilterMode'] |= ((int)$aSettings['mailto_filter'] * (2**1)); // n | 2^1
101
    // return array with filter settings
102
        return $aSettings;
103
    }
104
/* ************************************************************************** */
105

    
(2-2/14)