Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         output_filter
6
 * @copyright       WebsiteBaker Org. e.V.
7
 * @author          Christian Sommer
8
 * @author          Dietmar Wöllbrink
9
 * @author          Manuela v.d.Decken <manuela@isteam.de>
10
 * @link            http://websitebaker.org/
11
 * @license         http://www.gnu.org/licenses/gpl.html
12
 * @platform        WebsiteBaker 2.8.3
13
 * @requirements    PHP 5.3.6 and higher
14
 * @version         $Id: cmdTool.inc 2 2017-07-02 15:14:29Z Manuela $
15
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/branches/main/modules/output_filter/cmd/cmdTool.inc $
16
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
17
 *
18
 */
19

    
20
/* -------------------------------------------------------- */
21
// Must include code to stop this file being accessed directly
22
if(defined('WB_PATH') == false) { die('Illegale file access /'.basename(__DIR__).'/'.basename(__FILE__).''); }
23
/* -------------------------------------------------------- */
24

    
25
        $debugMessage = '';
26
        $js_back = ADMIN_URL.'/admintools/tool.php';
27
        $ToolUrl = ADMIN_URL.'/admintools/tool.php?tool='.$sAddonName;
28
        if( !$admin->get_permission($sAddonName,'module' ) ) {
29
            $admin->print_error($MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES'], $js_back);
30
        }
31

    
32
        $SettingsDenied = array(
33
        'at_replacement',
34
        'dot_replacement',
35
        'email_filter',
36
        'mailto_filter',
37
        'OutputFilterMode',
38
        'WbLink',
39
        'ReplaceSysvar',
40
        'CssToHead',
41
//        'ScriptVars',
42
        );
43
        if ($database->field_exists( TABLE_PREFIX.'mod_output_filter', 'sys_rel')) {
44
            include('cmdUpgrade.inc' );
45
        } else {
46
        }
47
        if (is_readable(dirname(__DIR__).'/info.php')) {require dirname(__DIR__).'/info.php';}
48

    
49
        if (is_readable(dirname(__DIR__).'/OutputFilterApi.php')) {
50
            if (!function_exists('getOutputFilterSettings')) {
51
                require(dirname(__DIR__).'/OutputFilterApi.php');
52
            }
53
// read settings from the database to show
54
        $aFilterSettings = getOutputFilterSettings();
55
// extended defaultSettings for email filter
56
        $aEmailDefaults = array();
57
        if ($aFilterSettings['Email'] ) {
58
            $aEmailSettings = array(  );
59
            $aEmailDefaults = array(
60
                'at_replacement'  => '@',
61
                'dot_replacement' => '.',
62
                'email_filter'    => '0',
63
                'mailto_filter'   => '0'
64
            );
65
        } else {
66
            $aEmailSettings = array(
67
                'at_replacement'  => '@',
68
                'dot_replacement' => '.',
69
                'email_filter'    => '0',
70
                'mailto_filter'   => '0'
71
            );
72
        }
73
        $aDefaultSettings = array_diff_key( $aFilterSettings, $aEmailSettings );
74
        // preset settings as default
75
        $aFiles = glob(WB_PATH.'/modules/'.$sAddonName.'/filters/*');
76
        $getDefaultSettings = (function() use ( $sAddonName, $aDefaultSettings, $aFiles ){
77
            foreach ( $aFiles  as $sFilterFile) {
78
                $key = preg_replace('=^.*?filter([^\.\/\\\\]+)(\.[^\.]+)?$=is', '\1', $sFilterFile);
79
                $aDefaultSettings[$key] = '0';
80
            }
81
          return $aDefaultSettings;
82
        });
83
        $aDefaultSettings = array_merge( $getDefaultSettings(), $aEmailDefaults );
84
        $aAllowedFilters  = array_keys ( $aDefaultSettings );
85
        $aFilterExists    = array_diff ( $aAllowedFilters, $SettingsDenied );
86
        // remove not existing filters from table
87
        foreach ( $aFilterExists  as $sFilterName) {
88
            $sFilterFile = WB_PATH.'/modules/'.$sAddonName.'/filters/filter'.$sFilterName.'.php';
89
            if( !file_exists( $sFilterFile ) ) {
90
                $sql  = 'DELETE FROM `'.TABLE_PREFIX.'mod_output_filter`'
91
                      . 'WHERE `name` = \''.$sFilterName.'\'';
92
                if( $database->query( $sql ) ){
93
                    unset($aDefaultSettings[$sFilterName]);
94
                }
95
            }
96
        }
97
//        $aAllowedFilters  = array_keys ( $aDefaultSettings );
98
// Create new template object
99
        $oTpl = new Template( $sAddonThemePath );
100
//        $oTpl->debug = true;
101
        $oTpl->set_file('page', 'tool.htt');
102
        $oTpl->set_block('page', 'main_block', 'main');
103
        $oTpl->set_block('main_block', 'headline_block', 'headline');
104
        $oTpl->set_var('FTAN', $admin->getFTAN());
105
        $oTpl->set_var($TEXT);
106
        $oTpl->set_var('ADMIN_URL', $oReg->AcpUrl);
107
        $oTpl->set_var('MODULE_NAME', $sAddonName);
108
        $msgTxt = '';
109
        $msgCls = 'msg-box';
110

    
111
        $msgTxt = $module_description;
112
        $msgCls = 'info-box';
113

    
114
        $oTpl->set_var('TOOL_NAME', $toolName);
115
        $oTpl->set_var('REQUEST_URI', $_SERVER['REQUEST_URI']);
116
        $oTpl->set_var('CANCEL_URL', $oReg->AcpUrl.'admintools/index.php');
117
        $oTpl->set_var('TOOL_URL', $oReg->AcpUrl.'admintools/tool.php?tool='.$sAddonName);
118
//        $oTpl->set_var($MESSAGE);
119
        $oTpl->set_var($MOD_MAIL_FILTER);
120
        $oTpl->set_var($HEADING);
121
// check if data was submitted
122
        if($doSave) {
123
    // save changes
124
            $oTpl->parse('headline', 'headline_block', true);
125
            $oTpl->set_var('TOOL_URL', $oReg->AcpUrl.'admintools/tool.php?tool='.$sAddonName);
126
            $oTpl->set_var('CANCEL_URL', $oReg->AcpUrl.'admintools/tool.php?tool='.$sAddonName);
127
            include(__DIR__.'/cmdSave.inc');
128
            $aFilterSettings = getOutputFilterSettings();
129
        } else {
130
            $oTpl->set_block('main_block', 'headline_block', '');
131
            $oTpl->set_var('CANCEL_URL', $oReg->AcpUrl.'admintools/index.php');
132
        }
133
        $oTpl->set_block('main_block', 'core_info_block', 'core_info');
134
        if( $debugMessage != '') {
135
        // write message box if needed
136
//            echo '<div class="'.$msgCls.'">'.$msgTxt.'</div>';
137
            $oTpl->set_var('CORE_MSGCLS', $msgCls);
138
            $oTpl->set_var('CORE_MSGTXT', $print_r);
139
            $oTpl->parse('core_info', 'core_info_block', true);
140
        } else {
141
            $oTpl->set_block('core_info', 'core_info_block', '');
142
        }
143
        $oTpl->set_block('main_block', 'message_block', 'message');
144
        if( $msgTxt != '') {
145
        // write message box if needed
146
//            echo '<div class="'.$msgCls.'">'.$msgTxt.'</div>';
147
            $oTpl->set_var('MSGCLS', $msgCls);
148
            $oTpl->set_var('MSGTXT', $msgTxt);
149
        }
150
        $oTpl->parse('message', 'message_block', true);
151

    
152
        $oTpl->set_var($aFilterSettings);
153
        $oTpl->set_block('main_block', 'filter_block', 'filter_list');
154
        foreach($aFilterSettings as $sFilterName => $sFilterValue)
155
        {
156
            if ( in_array( $sFilterName, $SettingsDenied ) ) { continue; }
157
            $oTpl->set_var('FVALUE', $sFilterValue);
158
            $oTpl->set_var('FNAME', $sFilterName);
159
            $oTpl->set_var('FCHECKED', (($sFilterValue=='1') ? ' checked="checked"' : '') );
160
            $oTpl->parse('filter_list', 'filter_block', true);
161
        }
162
// enable/disable extended email filter settings
163
        $oTpl->set_block('main_block', 'email-filter_block', 'email-filter');
164
        if( $aFilterSettings['Email'] ) {
165
            $oTpl->set_var('EMAIL_FILTER_CHECK',  (($aFilterSettings['email_filter']) ? ' checked="checked"' : '') );
166
            $oTpl->set_var('MAILTO_FILTER_CHECK', (($aFilterSettings['mailto_filter']) ? ' checked="checked"' : '') );
167
            $oTpl->parse('email-filter', 'email-filter_block', true);
168
        } else {
169
            $oTpl->set_block('main_block', 'email-filter_block', '');
170
        }
171
        // write out header if needed
172
        if(!$admin_header) { $admin->print_header(); }
173
    // Parse template objects output
174
            $oTpl->parse('main', 'main_block', true);
175
            $oTpl->pparse('output', 'page');
176
    }
(3-3/5)