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-07-02 17:14:29 +0200 (Sun, 02 Jul 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)
41
    {
42
        if (!is_array($mFilters)) {
43
            $mFilters = preg_split('/\s*?[,;| +]\s*?/', $mFilters, -1, PREG_SPLIT_NO_EMPTY);
44
        }
45
        foreach ($mFilters as $sFilter) {
46
            $aTmp = preg_split('/\?/', $sFilter, 2, PREG_SPLIT_NO_EMPTY);
47
            $sFilterName = $aTmp[0];
48
            $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);
55
                }
56
                $sContent = $sFilterFunc($sContent, $sOptions);
57
            }
58
        }
59
        return $sContent;
60
    }
61
/* ************************************************************************** */
62
/**
63
 * function to read the current filter settings
64
 * @global object $database
65
 * @global object $admin
66
 * @param void
67
 * @return array contains all settings
68
 */
69
    function getOutputFilterSettings()
70
    {
71
        global $database;
72
    // set default values
73
        $aSettings = array(
74
            'at_replacement'  => '(at)',
75
            'dot_replacement' => '(dot)'
76
        );
77
    // request settings from database
78
        $sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_output_filter`';
79
        if (($oRes = $database->query($sql))) {
80
            while (($aRec = $oRes->fetchRow(MYSQLI_ASSOC))) {
81
                $aSettings[$aRec['name']] = $aRec['value'];
82
            }
83
        }
84
        $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
87
    // return array with filter settings
88
        return $aSettings;
89
    }
90
/* ************************************************************************** */
91

    
(2-2/14)