Passed
Push — master ( cb3365...b7acf2 )
by Michael
03:44
created

xoops_module_install()   F

Complexity

Conditions 70
Paths > 20000

Size

Total Lines 515
Code Lines 406

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 70
eloc 406
c 1
b 0
f 0
nc 23115049
nop 1
dl 0
loc 515
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu)
18
 * @param mixed $dirname
19
 */
20
21
/*
22
if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
23
    exit("Access Denied");
24
}
25
*/
26
27
/**
28
 * @param $dirname
29
 *
30
 * @return string
31
 */
32
function xoops_module_install($dirname)
33
{
34
    global $xoopsUser, $xoopsConfig;
35
    $dirname = trim($dirname);
36
    //    $db = $GLOBALS['xoopsDB'];
37
    $db             = \XoopsDatabaseFactory::getDatabaseConnection();
38
    $reservedTables = [
39
        'avatar',
40
        'avatar_users_link',
41
        'block_module_link',
42
        'xoopscomments',
43
        'config',
44
        'configcategory',
45
        'configoption',
46
        'image',
47
        'imagebody',
48
        'imagecategory',
49
        'imgset',
50
        'imgset_tplset_link',
51
        'imgsetimg',
52
        'groups',
53
        'groups_users_link',
54
        'group_permission',
55
        'online',
56
        'bannerclient',
57
        'banner',
58
        'bannerfinish',
59
        'priv_msgs',
60
        'ranks',
61
        'session',
62
        'smiles',
63
        'users',
64
        'newblocks',
65
        'modules',
66
        'tplfile',
67
        'tplset',
68
        'tplsource',
69
        'xoopsnotifications',
70
        'banner',
71
        'bannerclient',
72
        'bannerfinish',
73
    ];
74
    /** @var \XoopsModuleHandler $moduleHandler */
75
    $moduleHandler = xoops_getHandler('module');
76
    if (0 == $moduleHandler->getCount(new \Criteria('dirname', $dirname))) {
77
        $module = $moduleHandler->create();
78
        $module->loadInfoAsVar($dirname);
79
        $module->setVar('weight', 1);
80
        $module->setVar('isactive', 1);
81
        $module->setVar('last_update', time());
82
        $error = false;
83
        $errs  = [];
84
        $msgs  = [];
85
86
        $msgs[] = '<div id="xo-module-log"><div class="header">';
87
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_INSTALLING . $module->getInfo('name', 's') . '</h4>';
0 ignored issues
show
Unused Code introduced by
The call to XoopsModule::getInfo() has too many arguments starting with 's'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_INSTALLING . $module->/** @scrutinizer ignore-call */ getInfo('name', 's') . '</h4>';

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
Are you sure $module->getInfo('name', 's') of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_INSTALLING . /** @scrutinizer ignore-type */ $module->getInfo('name', 's') . '</h4>';
Loading history...
88
        if (false !== $module->getInfo('image') && '' != trim($module->getInfo('image'))) {
0 ignored issues
show
Bug introduced by
It seems like $module->getInfo('image') can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

88
        if (false !== $module->getInfo('image') && '' != trim(/** @scrutinizer ignore-type */ $module->getInfo('image'))) {
Loading history...
89
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt=""></a>';
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('adminindex') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . /** @scrutinizer ignore-type */ $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt=""></a>';
Loading history...
Bug introduced by
Are you sure $module->getInfo('dirname', 'e') of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . /** @scrutinizer ignore-type */ $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt=""></a>';
Loading history...
90
        }
91
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('version') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

91
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . /** @scrutinizer ignore-type */ $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
Loading history...
Bug introduced by
Are you sure $module->getInfo('module_status') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

91
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . /** @scrutinizer ignore-type */ $module->getInfo('module_status');
Loading history...
92
        if (false !== $module->getInfo('author') && '' != trim($module->getInfo('author'))) {
93
            $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')), ENT_QUOTES | ENT_HTML5);
94
        }
95
        $msgs[] = '</div><div class="logger">';
96
        // Load module specific install script if any
97
        $install_script = $module->getInfo('onInstall');
98
        if ($install_script && '' != trim($install_script)) {
99
            require_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script);
100
        }
101
        $func = "xoops_module_pre_install_{$dirname}";
102
        // If pre install function is defined, execute
103
        if (function_exists($func)) {
104
            $result = $func($module);
105
            if (!$result) {
106
                $error  = true;
107
                $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
108
                $errs   = array_merge($errs, $module->getErrors());
109
            } else {
110
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
111
                $msgs   += $module->getErrors();
112
            }
113
        }
114
115
        if (false === $error) {
116
            $sqlfile = $module->getInfo('sqlfile');
117
            if (is_array($sqlfile) && !empty($sqlfile[XOOPS_DB_TYPE])) {
118
                $sql_file_path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . $sqlfile[XOOPS_DB_TYPE];
119
                if (!is_file($sql_file_path)) {
120
                    $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
121
                    $error  = true;
122
                } else {
123
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_SQL_FOUND, "<strong>{$sql_file_path}</strong>") . '<br >' . _AM_SYSTEM_MODULES_CREATE_TABLES;
124
                    require_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
125
                    $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
0 ignored issues
show
Bug introduced by
It seems like fopen($sql_file_path, 'r') can also be of type false; however, parameter $handle of fread() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

125
                    $sql_query = fread(/** @scrutinizer ignore-type */ fopen($sql_file_path, 'r'), filesize($sql_file_path));
Loading history...
126
                    $sql_query = trim($sql_query);
127
                    SqlUtility::splitMySqlFile($pieces, $sql_query);
128
                    $created_tables = [];
129
                    foreach ($pieces as $piece) {
130
                        // [0] contains the prefixed query
131
                        // [4] contains unprefixed table name
132
                        $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
133
                        if (!$prefixed_query) {
134
                            $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_VALID, '<strong>' . $piece . '</strong>');
135
                            $error  = true;
136
                            break;
137
                        }
138
                        // check if the table name is reserved
139
                        if (!in_array($prefixed_query[4], $reservedTables)) {
140
                            // not reserved, so try to create one
141
                            if (!$db->query($prefixed_query[0])) {
142
                                $errs[] = $db->error();
143
                                $error  = true;
144
                                break;
145
                            }
146
                            if (!in_array($prefixed_query[4], $created_tables)) {
147
                                $msgs[]           = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TABLE_CREATED, '<strong>' . $db->prefix($prefixed_query[4]) . '</strong>');
148
                                $created_tables[] = $prefixed_query[4];
149
                            } else {
150
                                $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_INSERT_DATA, '<strong>' . $db->prefix($prefixed_query[4]) . '</strong>');
151
                            }
152
                        } else {
153
                            // the table name is reserved, so halt the installation
154
                            $errs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TABLE_RESERVED, '<strong>' . $prefixed_query[4] . '</strong>');
155
                            $error  = true;
156
                            break;
157
                        }
158
                    }
159
                    // if there was an error, delete the tables created so far, so the next installation will not fail
160
                    if (true === $error) {
161
                        foreach ($created_tables as $ct) {
162
                            $db->query('DROP TABLE ' . $db->prefix($ct));
163
                        }
164
                    }
165
                }
166
            }
167
        }
168
        // if no error, save the module info and blocks info associated with it
169
        if (false === $error) {
170
            if (!$moduleHandler->insert($module)) {
171
                $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_INSERT_DATA_FAILD, '<strong>' . $module->getVar('name') . '</strong>');
172
                foreach ($created_tables as $ct) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $created_tables does not seem to be defined for all execution paths leading up to this point.
Loading history...
173
                    $db->query('DROP TABLE ' . $db->prefix($ct));
174
                }
175
                $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $module->name() . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>';
176
                foreach ($errs as $err) {
177
                    $ret .= ' - ' . $err . '<br>';
178
                }
179
                $ret .= '</p>';
180
                unset($module, $created_tables, $errs, $msgs);
181
182
                return $ret;
183
            }
184
            $newmid = $module->getVar('mid');
185
            unset($created_tables);
186
            $msgs[] = '<p>' . _AM_SYSTEM_MODULES_INSERT_DATA_DONE . sprintf(_AM_SYSTEM_MODULES_MODULEID, '<strong>' . $newmid . '</strong>');
187
            /** @var \XoopsTplfileHandler $tplfileHandler */
188
            $tplfileHandler = xoops_getHandler('tplfile');
189
            $templates      = $module->getInfo('templates');
190
            if (false !== $templates) {
0 ignored issues
show
introduced by
The condition false !== $templates is always true.
Loading history...
191
                $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_ADD;
192
                foreach ($templates as $tpl) {
193
                    $tplfile = $tplfileHandler->create();
194
                    $type    = ($tpl['type'] ?? 'module');
195
                    $tpldata = xoops_module_gettemplate($dirname, $tpl['file'], $type);
196
                    $tplfile->setVar('tpl_source', $tpldata, true);
197
                    $tplfile->setVar('tpl_refid', $newmid);
198
199
                    $tplfile->setVar('tpl_tplset', 'default');
200
                    $tplfile->setVar('tpl_file', $tpl['file']);
201
                    $tplfile->setVar('tpl_desc', $tpl['description'], true);
202
                    $tplfile->setVar('tpl_module', $dirname);
203
                    $tplfile->setVar('tpl_lastmodified', time());
204
                    $tplfile->setVar('tpl_lastimported', time());
205
                    $tplfile->setVar('tpl_type', $type);
206
                    if (!$tplfileHandler->insert($tplfile)) {
207
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
208
                    } else {
209
                        $newtplid = $tplfile->getVar('tpl_id');
210
                        $msgs[]   = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $tpl['file'] . '</strong>') . '(ID: <strong>' . $newtplid . '</strong>)';
211
                        // generate compiled file
212
                        require_once XOOPS_ROOT_PATH . '/class/template.php';
213
                        if (!xoops_template_touch($newtplid)) {
214
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
215
                        } else {
216
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED, '<strong>' . $tpl['file'] . '</strong>');
217
                        }
218
                    }
219
                    unset($tplfile, $tpldata);
220
                }
221
            }
222
            require_once XOOPS_ROOT_PATH . '/class/template.php';
223
            xoops_template_clear_module_cache($newmid);
224
            $blocks = $module->getInfo('blocks');
225
            if (false !== $blocks) {
0 ignored issues
show
introduced by
The condition false !== $blocks is always true.
Loading history...
226
                $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_ADD;
227
                foreach ($blocks as $blockkey => $block) {
228
                    // break the loop if missing block config
229
                    if (!isset($block['file']) || !isset($block['show_func'])) {
230
                        break;
231
                    }
232
                    $options = '';
233
                    if (!empty($block['options'])) {
234
                        $options = trim($block['options']);
235
                    }
236
                    $newbid    = $db->genId($db->prefix('newblocks') . '_bid_seq');
237
                    $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : '';
238
                    $template  = '';
239
                    if (isset($block['template']) && '' != trim($block['template'])) {
240
                        $content = xoops_module_gettemplate($dirname, $block['template'], 'blocks');
241
                    }
242
                    if (empty($content)) {
243
                        $content = '';
244
                    } else {
245
                        $template = trim($block['template']);
246
                    }
247
                    $block_name = addslashes(trim($block['name']));
248
                    $sql        = 'INSERT INTO '
249
                                  . $db->prefix('newblocks')
250
                                  . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ($newbid, $newmid, "
251
                                  . (int)$blockkey
252
                                  . ", '$options', '"
253
                                  . $block_name
254
                                  . "','"
255
                                  . $block_name
256
                                  . "', '', 0, 0, 0, 'M', 'H', 1, '"
257
                                  . addslashes($dirname)
258
                                  . "', '"
259
                                  . addslashes(trim($block['file']))
260
                                  . "', '"
261
                                  . addslashes(trim($block['show_func']))
262
                                  . "', '"
263
                                  . addslashes($edit_func)
264
                                  . "', '"
265
                                  . $template
266
                                  . "', 0, "
267
                                  . time()
268
                                  . ')';
269
                    if (!$db->query($sql)) {
270
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR_DATABASE, '<strong>' . $db->error() . '</strong>') . '</span>';
271
                    } else {
272
                        if (empty($newbid)) {
273
                            $newbid = $db->getInsertId();
274
                        }
275
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>');
276
                        $sql    = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
277
                        $db->query($sql);
278
                        if ('' != $template) {
279
                            $tplfile = $tplfileHandler->create();
280
                            $tplfile->setVar('tpl_refid', $newbid);
281
                            $tplfile->setVar('tpl_source', $content, true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $content does not seem to be defined for all execution paths leading up to this point.
Loading history...
282
                            $tplfile->setVar('tpl_tplset', 'default');
283
                            $tplfile->setVar('tpl_file', $block['template']);
284
                            $tplfile->setVar('tpl_module', $dirname);
285
                            $tplfile->setVar('tpl_type', 'block');
286
                            $tplfile->setVar('tpl_desc', $block['description'], true);
287
                            $tplfile->setVar('tpl_lastimported', 0);
288
                            $tplfile->setVar('tpl_lastmodified', time());
289
                            if (!$tplfileHandler->insert($tplfile)) {
290
                                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
291
                            } else {
292
                                $newtplid = $tplfile->getVar('tpl_id');
293
                                $msgs[]   = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>') . ' (ID: <strong>' . $newtplid . '</strong>)';
294
                                // generate compiled file
295
                                require_once XOOPS_ROOT_PATH . '/class/template.php';
296
                                if (!xoops_template_touch($newtplid)) {
297
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, '<strong>' . $block['template'] . '</strong>') . '</span>';
298
                                } else {
299
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED, '<strong>' . $block['template'] . '</strong>');
300
                                }
301
                            }
302
                            unset($tplfile);
303
                        }
304
                    }
305
                    unset($content);
306
                }
307
                unset($blocks);
308
            }
309
            $configs = $module->getInfo('config');
310
            if (false !== $configs) {
0 ignored issues
show
introduced by
The condition false !== $configs is always true.
Loading history...
311
                if (0 != $module->getVar('hascomments')) {
312
                    require_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
313
                    $configs[] = [
314
                        'name'        => 'com_rule',
315
                        'title'       => '_CM_COMRULES',
316
                        'description' => '',
317
                        'formtype'    => 'select',
318
                        'valuetype'   => 'int',
319
                        'default'     => 1,
320
                        'options'     => [
321
                            '_CM_COMNOCOM'        => XOOPS_COMMENT_APPROVENONE,
322
                            '_CM_COMAPPROVEALL'   => XOOPS_COMMENT_APPROVEALL,
323
                            '_CM_COMAPPROVEUSER'  => XOOPS_COMMENT_APPROVEUSER,
324
                            '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN,
325
                        ],
326
                    ];
327
                    $configs[] = [
328
                        'name'        => 'com_anonpost',
329
                        'title'       => '_CM_COMANONPOST',
330
                        'description' => '',
331
                        'formtype'    => 'yesno',
332
                        'valuetype'   => 'int',
333
                        'default'     => 0,
334
                    ];
335
                }
336
            } elseif (0 != $module->getVar('hascomments')) {
337
                $configs = [];
338
                require_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
339
                $configs[] = [
340
                    'name'        => 'com_rule',
341
                    'title'       => '_CM_COMRULES',
342
                    'description' => '',
343
                    'formtype'    => 'select',
344
                    'valuetype'   => 'int',
345
                    'default'     => 1,
346
                    'options'     => [
347
                        '_CM_COMNOCOM'        => XOOPS_COMMENT_APPROVENONE,
348
                        '_CM_COMAPPROVEALL'   => XOOPS_COMMENT_APPROVEALL,
349
                        '_CM_COMAPPROVEUSER'  => XOOPS_COMMENT_APPROVEUSER,
350
                        '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN,
351
                    ],
352
                ];
353
                $configs[] = [
354
                    'name'        => 'com_anonpost',
355
                    'title'       => '_CM_COMANONPOST',
356
                    'description' => '',
357
                    'formtype'    => 'yesno',
358
                    'valuetype'   => 'int',
359
                    'default'     => 0,
360
                ];
361
            }
362
            // RMV-NOTIFY
363
            if (0 != $module->getVar('hasnotification')) {
364
                if (empty($configs)) {
365
                    $configs = [];
366
                }
367
                // Main notification options
368
                require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
369
                require_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
370
                $options                             = [];
371
                $options['_NOT_CONFIG_DISABLE']      = XOOPS_NOTIFICATION_DISABLE;
372
                $options['_NOT_CONFIG_ENABLEBLOCK']  = XOOPS_NOTIFICATION_ENABLEBLOCK;
373
                $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
374
                $options['_NOT_CONFIG_ENABLEBOTH']   = XOOPS_NOTIFICATION_ENABLEBOTH;
375
376
                $configs[] = [
377
                    'name'        => 'notification_enabled',
378
                    'title'       => '_NOT_CONFIG_ENABLE',
379
                    'description' => '_NOT_CONFIG_ENABLEDSC',
380
                    'formtype'    => 'select',
381
                    'valuetype'   => 'int',
382
                    'default'     => XOOPS_NOTIFICATION_ENABLEBOTH,
383
                    'options'     => $options,
384
                ];
385
                // Event-specific notification options
386
                // FIXME: doesn't work when update module... can't read back the array of options properly...  " changing to &quot;
387
                $options    = [];
388
                $categories = notificationCategoryInfo('', $module->getVar('mid'));
389
                foreach ($categories as $category) {
390
                    $events = notificationEvents($category['name'], false, $module->getVar('mid'));
391
                    foreach ($events as $event) {
392
                        if (!empty($event['invisible'])) {
393
                            continue;
394
                        }
395
                        $option_name           = $category['title'] . ' : ' . $event['title'];
396
                        $option_value          = $category['name'] . '-' . $event['name'];
397
                        $options[$option_name] = $option_value;
398
                    }
399
                    unset($events);
400
                }
401
                unset($categories);
402
                $configs[] = [
403
                    'name'        => 'notification_events',
404
                    'title'       => '_NOT_CONFIG_EVENTS',
405
                    'description' => '_NOT_CONFIG_EVENTSDSC',
406
                    'formtype'    => 'select_multi',
407
                    'valuetype'   => 'array',
408
                    'default'     => array_values($options),
409
                    'options'     => $options,
410
                ];
411
            }
412
413
            if (false !== $configs) {
0 ignored issues
show
introduced by
The condition false !== $configs is always true.
Loading history...
414
                $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_ADD;
415
                /** @var \XoopsConfigHandler $configHandler */
416
                $configHandler = xoops_getHandler('config');
417
                $order         = 0;
418
                foreach ($configs as $config) {
419
                    $confobj = $configHandler->createConfig();
420
                    $confobj->setVar('conf_modid', $newmid);
421
                    $confobj->setVar('conf_catid', 0);
422
                    $confobj->setVar('conf_name', $config['name']);
423
                    $confobj->setVar('conf_title', $config['title'], true);
424
                    $confobj->setVar('conf_desc', $config['description'] ?? '', true);
425
                    $confobj->setVar('conf_formtype', $config['formtype']);
426
                    $confobj->setVar('conf_valuetype', $config['valuetype']);
427
                    $confobj->setConfValueForInput($config['default'], true);
428
                    $confobj->setVar('conf_order', $order);
429
                    $confop_msgs = '';
430
                    if (isset($config['options']) && is_array($config['options'])) {
431
                        foreach ($config['options'] as $key => $value) {
432
                            $confop = $configHandler->createConfigOption();
433
                            $confop->setVar('confop_name', $key, true);
434
                            $confop->setVar('confop_value', $value, true);
435
                            $confobj->setConfOptions($confop);
436
                            $confop_msgs .= '<br>&nbsp;&nbsp;&nbsp;&nbsp; ' . _AM_SYSTEM_MODULES_CONFIG_ADD . _AM_SYSTEM_MODULES_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _AM_SYSTEM_MODULES_VALUE . ' <strong>' . $value . '</strong> ';
437
                            unset($confop);
438
                        }
439
                    }
440
                    ++$order;
441
                    if ($configHandler->insertConfig($confobj)) {
442
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs;
443
                    } else {
444
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>';
445
                    }
446
                    unset($confobj);
447
                }
448
                unset($configs);
449
            }
450
451
            $groups = [XOOPS_GROUP_ADMIN];
452
            if ($module->getInfo('hasMain')) {
453
                $groups = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS];
454
            }
455
            // retrieve all block ids for this module
456
            $blocks = \XoopsBlock::getByModule($newmid, false);
0 ignored issues
show
Bug introduced by
The method getByModule() does not exist on XoopsBlock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

456
            /** @scrutinizer ignore-call */ 
457
            $blocks = \XoopsBlock::getByModule($newmid, false);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
457
            $msgs[] = _AM_SYSTEM_MODULES_GROUP_SETTINGS_ADD;
458
            /** @var \XoopsGroupPermHandler $grouppermHandler */
459
            $grouppermHandler = xoops_getHandler('groupperm');
460
            foreach ($groups as $mygroup) {
461
                if ($grouppermHandler->checkRight('module_admin', 0, $mygroup)) {
462
                    $mperm = $grouppermHandler->create();
463
                    $mperm->setVar('gperm_groupid', $mygroup);
464
                    $mperm->setVar('gperm_itemid', $newmid);
465
                    $mperm->setVar('gperm_name', 'module_admin');
466
                    $mperm->setVar('gperm_modid', 1);
467
                    if (!$grouppermHandler->insert($mperm)) {
0 ignored issues
show
Bug introduced by
$mperm of type boolean is incompatible with the type XoopsObject expected by parameter $perm of XoopsGroupPermHandler::insert(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

467
                    if (!$grouppermHandler->insert(/** @scrutinizer ignore-type */ $mperm)) {
Loading history...
468
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD_ERROR, '<strong>' . $mygroup . '</strong>') . '</span>';
469
                    } else {
470
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD, '<strong>' . $mygroup . '</strong>');
471
                    }
472
                    unset($mperm);
473
                }
474
                $mperm = $grouppermHandler->create();
475
                $mperm->setVar('gperm_groupid', $mygroup);
476
                $mperm->setVar('gperm_itemid', $newmid);
477
                $mperm->setVar('gperm_name', 'module_read');
478
                $mperm->setVar('gperm_modid', 1);
479
                if (!$grouppermHandler->insert($mperm)) {
480
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, '<strong>' . $mygroup . '</strong>') . '</span>';
481
                } else {
482
                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, '<strong>' . $mygroup . '</strong>');
483
                }
484
                unset($mperm);
485
                foreach ($blocks as $blc) {
486
                    $bperm = $grouppermHandler->create();
487
                    $bperm->setVar('gperm_groupid', $mygroup);
488
                    $bperm->setVar('gperm_itemid', $blc);
489
                    $bperm->setVar('gperm_name', 'block_read');
490
                    $bperm->setVar('gperm_modid', 1);
491
                    if (!$grouppermHandler->insert($bperm)) {
492
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>';
493
                    } else {
494
                        $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $blc . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>');
495
                    }
496
                    unset($bperm);
497
                }
498
            }
499
            unset($blocks, $groups);
500
501
            // execute module specific install script if any
502
            $func = "xoops_module_install_{$dirname}";
503
            if (function_exists($func)) {
504
                if (!$lastmsg = $func($module)) {
505
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
506
                } else {
507
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
508
                    if (is_string($lastmsg)) {
509
                        $msgs[] = $lastmsg;
510
                    }
511
                }
512
            }
513
514
            $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKINS, '<strong>' . $module->getVar('name', 's') . '</strong>');
515
            $msgs[] = '</div></div>';
516
517
            $blocks = $module->getInfo('blocks');
518
            $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a> |
519
                        <a href="admin.php?fct=modulesadmin&op=installlist">' . _AM_SYSTEM_MODULES_TOINSTALL . '</a> | ';
520
            $msgs[] = '<br><span class="red bold">' . _AM_SYSTEM_MODULES_MODULE . ' ' . $module->getInfo('name') . ': </span></div>';
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('name') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

520
            $msgs[] = '<br><span class="red bold">' . _AM_SYSTEM_MODULES_MODULE . ' ' . /** @scrutinizer ignore-type */ $module->getInfo('name') . ': </span></div>';
Loading history...
521
            if (false !== $blocks) {
0 ignored issues
show
introduced by
The condition false !== $blocks is always true.
Loading history...
522
                $msgs[] = '<div class="center"><a href="admin.php?fct=blocksadmin&op=list&filter=1&selgen=' . $newmid . '&selmod=-2&selgrp=-1&selvis=-1&filsave=1">' . _AM_SYSTEM_BLOCKS . '</a></div>';
523
            }
524
525
            $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=preferences&op=showmod&mod=' . $newmid . '">' . _AM_SYSTEM_PREF . '</a>';
526
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a>';
527
528
            $testdataDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata';
529
            if (file_exists($testdataDirectory)) {
530
                $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata/index.php' . '">' . _AM_SYSTEM_MODULES_INSTALL_TESTDATA . '</a></div>';
531
            } else {
532
                $msgs[] = '</div>';
533
            }
534
535
            $ret = implode('<br>', $msgs);
536
            unset($blocks, $msgs, $errs, $module);
537
538
            return $ret;
539
        }
540
        $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . implode('<br>', $errs) . '</p>';
541
        unset($msgs, $errs);
542
543
        return $ret;
544
    }
545
546
    return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_ALEXISTS, $dirname) . '</p>';
547
}
548
549
/**
550
 * @param        $dirname
551
 * @param        $template
552
 * @param string $type
553
 *
554
 * @return string
555
 */
556
function &xoops_module_gettemplate($dirname, $template, $type = '')
557
{
558
    global $xoopsConfig;
559
    $ret = '';
560
    switch ($type) {
561
        case 'blocks':
562
        case 'admin':
563
            $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $type . '/' . $template;
564
            break;
565
        default:
566
            $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $template;
567
            break;
568
    }
569
    if (!is_file($path)) {
570
        return $ret;
571
    }
572
    $lines = file($path);
573
574
    if (!$lines) {
575
        return $ret;
576
    }
577
    $count = count($lines);
0 ignored issues
show
Unused Code introduced by
The assignment to $count is dead and can be removed.
Loading history...
578
    foreach ($lines as $i => $iValue) {
579
        $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
580
    }
581
582
    return $ret;
583
}
584
585
/**
586
 * @param $dirname
587
 *
588
 * @return string
589
 */
590
function xoops_module_uninstall($dirname)
591
{
592
    global $xoopsConfig;
593
    $reservedTables = [
594
        'avatar',
595
        'avatar_users_link',
596
        'block_module_link',
597
        'xoopscomments',
598
        'config',
599
        'configcategory',
600
        'configoption',
601
        'image',
602
        'imagebody',
603
        'imagecategory',
604
        'imgset',
605
        'imgset_tplset_link',
606
        'imgsetimg',
607
        'groups',
608
        'groups_users_link',
609
        'group_permission',
610
        'online',
611
        'bannerclient',
612
        'banner',
613
        'bannerfinish',
614
        'priv_msgs',
615
        'ranks',
616
        'session',
617
        'smiles',
618
        'users',
619
        'newblocks',
620
        'modules',
621
        'tplfile',
622
        'tplset',
623
        'tplsource',
624
        'xoopsnotifications',
625
        'banner',
626
        'bannerclient',
627
        'bannerfinish',
628
    ];
629
    $db             = \XoopsDatabaseFactory::getDatabaseConnection();
630
    /** @var \XoopsModuleHandler $moduleHandler */
631
    $moduleHandler = xoops_getHandler('module');
632
    $module        = $moduleHandler->getByDirname($dirname);
633
    require_once XOOPS_ROOT_PATH . '/class/template.php';
634
    xoops_template_clear_module_cache($module->getVar('mid'));
635
    if ('system' === $module->getVar('dirname')) {
636
        return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
637
    }
638
639
    if ($module->getVar('dirname') == $xoopsConfig['startpage']) {
640
        return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
641
    }
642
    $msgs   = [];
643
    $msgs[] = '<div id="xo-module-log"><div class="header">';
644
    $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UNINSTALL . $module->getInfo('name', 's') . '</h4>';
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('name', 's') of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

644
    $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UNINSTALL . /** @scrutinizer ignore-type */ $module->getInfo('name', 's') . '</h4>';
Loading history...
Unused Code introduced by
The call to XoopsModule::getInfo() has too many arguments starting with 's'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

644
    $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UNINSTALL . $module->/** @scrutinizer ignore-call */ getInfo('name', 's') . '</h4>';

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Comprehensibility Best Practice introduced by
$errs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $errs = array(); before regardless.
Loading history...
645
    if (false !== $module->getInfo('image') && '' != trim($module->getInfo('image'))) {
0 ignored issues
show
Bug introduced by
It seems like $module->getInfo('image') can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

645
    if (false !== $module->getInfo('image') && '' != trim(/** @scrutinizer ignore-type */ $module->getInfo('image'))) {
Loading history...
646
        $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="">';
647
    }
648
    $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('module_status') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

648
    $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . /** @scrutinizer ignore-type */ $module->getInfo('module_status');
Loading history...
Bug introduced by
Are you sure $module->getInfo('version') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

648
    $msgs[] = '<strong>' . _VERSION . ':</strong> ' . /** @scrutinizer ignore-type */ $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
Loading history...
649
    if (false !== $module->getInfo('author') && '' != trim($module->getInfo('author'))) {
650
        $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')), ENT_QUOTES | ENT_HTML5);
651
    }
652
    $msgs[] = '</div><div class="logger">';
653
    // Load module specific install script if any
654
    $uninstall_script = $module->getInfo('onUninstall');
655
    if ($uninstall_script && '' != trim($uninstall_script)) {
656
        require_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($uninstall_script);
657
    }
658
    $func = "xoops_module_pre_uninstall_{$dirname}";
659
    // If pre uninstall function is defined, execute
660
    if (function_exists($func)) {
661
        $result = $func($module);
662
        if (false === $result) {
663
            $errs   = $module->getErrors();
664
            $errs[] = sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func);
665
666
            return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . implode('<br>', $errs) . '</p>';
667
        }
668
        $msgs = $module->getErrors();
669
        array_unshift($msgs, '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>');
670
    }
671
672
    if (!$moduleHandler->delete($module)) {
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of XoopsModuleHandler::delete() does only seem to accept XoopsObject, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

672
    if (!$moduleHandler->delete(/** @scrutinizer ignore-type */ $module)) {
Loading history...
673
        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_DELETE_ERROR, $module->getVar('name')) . '</span>';
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('name') can also be of type array and array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

673
        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_DELETE_ERROR, /** @scrutinizer ignore-type */ $module->getVar('name')) . '</span>';
Loading history...
674
    } else {
675
        // delete template files
676
        /** @var \XoopsTplfileHandler $tplfileHandler */
677
        $tplfileHandler = xoops_getHandler('tplfile');
678
        $templates      = $tplfileHandler->find(null, 'module', $module->getVar('mid'));
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('mid') can also be of type array and array; however, parameter $refid of XoopsTplfileHandler::find() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

678
        $templates      = $tplfileHandler->find(null, 'module', /** @scrutinizer ignore-type */ $module->getVar('mid'));
Loading history...
679
        $tcount         = count($templates);
680
        if ($tcount > 0) {
681
            $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_DELETE;
682
            for ($i = 0; $i < $tcount; ++$i) {
683
                if (!$tplfileHandler->delete($templates[$i])) {
684
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_DATA_FAILD, $templates[$i]->getVar('tpl_file')) . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$i]->getVar('tpl_id') . '</strong>') . '</span>';
685
                } else {
686
                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_DATA, '<strong>' . $templates[$i]->getVar('tpl_file') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$i]->getVar('tpl_id') . '</strong>');
687
                }
688
            }
689
        }
690
        unset($templates);
691
692
        // delete blocks and block tempalte files
693
        $block_arr = \XoopsBlock::getByModule($module->getVar('mid'));
694
        if (is_array($block_arr)) {
695
            $bcount = count($block_arr);
0 ignored issues
show
Unused Code introduced by
The assignment to $bcount is dead and can be removed.
Loading history...
696
            $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_DELETE;
697
            foreach ($block_arr as $iValue) {
698
                if (false === $iValue->delete()) {
699
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, '<strong>' . $iValue->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $iValue->getVar('bid') . '</strong>') . '</span>';
700
                } else {
701
                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE, '<strong>' . $iValue->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $iValue->getVar('bid') . '</strong>');
702
                }
703
                if ('' != $iValue->getVar('template')) {
704
                    $templates = $tplfileHandler->find(null, 'block', $iValue->getVar('bid'));
705
                    $btcount   = count($templates);
706
                    if ($btcount > 0) {
707
                        for ($j = 0; $j < $btcount; ++$j) {
708
                            if (!$tplfileHandler->delete($templates[$j])) {
709
                                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_TEMPLATE_ERROR, $templates[$j]->getVar('tpl_file')) . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$j]->getVar('tpl_id') . '</strong>') . '</span>';
710
                            } else {
711
                                $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_DATA, '<strong>' . $templates[$j]->getVar('tpl_file') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ID, '<strong>' . $templates[$j]->getVar('tpl_id') . '</strong>');
712
                            }
713
                        }
714
                    }
715
                    unset($templates);
716
                }
717
            }
718
        }
719
720
        // delete tables used by this module
721
        $modtables = $module->getInfo('tables');
722
        if (false !== $modtables && is_array($modtables)) {
723
            $msgs[] = _AM_SYSTEM_MODULES_DELETE_MOD_TABLES;
724
            foreach ($modtables as $table) {
725
                // prevent deletion of reserved core tables!
726
                if (!in_array($table, $reservedTables)) {
727
                    $sql = 'DROP TABLE ' . $db->prefix($table);
728
                    if (!$db->query($sql)) {
729
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_ERROR, '<strong>' . $db->prefix($table) . '<strong>') . '</span>';
730
                    } else {
731
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED, '<strong>' . $db->prefix($table) . '</strong>');
732
                    }
733
                } else {
734
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_FAILDED, '<strong>' . $db->prefix($table) . '</strong>') . '</span>';
735
                }
736
            }
737
        }
738
739
        // delete comments if any
740
        if (0 != $module->getVar('hascomments')) {
741
            $msgs[]         = _AM_SYSTEM_MODULES_COMMENTS_DELETE;
742
            $commentHandler = xoops_getHandler('comment');
743
            if (false === $commentHandler->deleteByModule($module->getVar('mid'))) {
0 ignored issues
show
Bug introduced by
The method deleteByModule() does not exist on XoopsObjectHandler. Did you maybe mean delete()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

743
            if (false === $commentHandler->/** @scrutinizer ignore-call */ deleteByModule($module->getVar('mid'))) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
744
                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_COMMENTS_DELETE_ERROR . '</span>';
745
            } else {
746
                $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_COMMENTS_DELETED;
747
            }
748
        }
749
750
        // RMV-NOTIFY
751
        // delete notifications if any
752
        if (0 != $module->getVar('hasnotification')) {
753
            $msgs[] = _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETE;
754
            if (false === xoops_notification_deletebymodule($module->getVar('mid'))) {
755
                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETE_ERROR . '</span>';
756
            } else {
757
                $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETED;
758
            }
759
        }
760
761
        // delete permissions if any
762
        /** @var \XoopsGroupPermHandler $grouppermHandler */
763
        $grouppermHandler = xoops_getHandler('groupperm');
764
        if (!$grouppermHandler->deleteByModule($module->getVar('mid'))) {
765
            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETE_ERROR . '</span>';
766
        } else {
767
            $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETED;
768
        }
769
770
        // delete module config options if any
771
        if (0 != $module->getVar('hasconfig') || 0 != $module->getVar('hascomments')) {
772
            /** @var \XoopsConfigHandler $configHandler */
773
            $configHandler = xoops_getHandler('config');
774
            $configs       = $configHandler->getConfigs(new \Criteria('conf_modid', $module->getVar('mid')));
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('mid') can also be of type array and array; however, parameter $value of Criteria::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

774
            $configs       = $configHandler->getConfigs(new \Criteria('conf_modid', /** @scrutinizer ignore-type */ $module->getVar('mid')));
Loading history...
775
            $confcount     = count($configs);
776
            if ($confcount > 0) {
777
                $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE;
778
                for ($i = 0; $i < $confcount; ++$i) {
779
                    if (!$configHandler->deleteConfig($configs[$i])) {
780
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_CONFIG_DATA_DELETE_ERROR . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>') . '</span>';
781
                    } else {
782
                        $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>');
783
                    }
784
                }
785
            }
786
        }
787
788
        // execute module specific install script if any
789
        $func = 'xoops_module_uninstall_' . $dirname;
790
        if (function_exists($func)) {
791
            if (!$func($module)) {
792
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
793
            } else {
794
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
795
            }
796
        }
797
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
798
    }
799
    $msgs[] = '</div></div>';
800
    $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
801
    $ret    = implode('<br>', $msgs);
802
803
    return $ret;
804
}
805
806
/**
807
 * @param $dirname
808
 * @return string
809
 */
810
function xoops_module_update($dirname)
811
{
812
    global $xoopsUser, $xoopsConfig, $xoopsTpl;
813
    $dirname = trim($dirname);
814
    //    $xoopsDB = $GLOBALS['xoopsDB'];
815
    $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
816
817
    $myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
818
819
    $dirname = htmlspecialchars(trim($dirname));
820
    /** @var \XoopsModuleHandler $moduleHandler */
821
    $moduleHandler = xoops_getHandler('module');
822
    $module        = $moduleHandler->getByDirname($dirname);
823
    // Save current version for use in the update function
824
    $prev_version = $module->getVar('version');
825
    $clearTpl     = new \XoopsTpl();
826
    $clearTpl->clearCache($dirname);
827
828
    // we don't want to change the module name set by admin
829
    $temp_name = $module->getVar('name');
830
    $module->loadInfoAsVar($dirname);
831
    $module->setVar('name', $temp_name);
832
    $module->setVar('last_update', time());
833
    /*
834
        // Call Header
835
        // Define main template
836
        $GLOBALS['xoopsOption']['template_main'] = 'system_header.html';
837
        // Call Header
838
        xoops_cp_header();
839
        // Define Stylesheet
840
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
841
        // Define Breadcrumb and tips
842
        $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath'));
843
        $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_UPDATE);
844
        $xoBreadCrumb->addHelp(system_adminVersion('modulesadmin', 'help') . '#update');https://www.facebook.com/photo.php?v=10154358806675333
845
        $xoBreadCrumb->render();
846
847
        */
848
    if (!$moduleHandler->insert($module)) {
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of XoopsModuleHandler::insert() does only seem to accept XoopsObject, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

848
    if (!$moduleHandler->insert(/** @scrutinizer ignore-type */ $module)) {
Loading history...
849
        echo '<p>Could not update ' . $module->getVar('name') . '</p>';
850
        echo "<br><div class='center'><a href='admin.php?fct=modulesadmin'>" . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
851
    } else {
852
        $newmid = $module->getVar('mid');
853
        $msgs   = [];
854
        $msgs[] = '<div id="xo-module-log"><div class="header">';
855
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UPDATING . $module->getInfo('name', 's') . '</h4>';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$errs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $errs = array(); before regardless.
Loading history...
Bug introduced by
Are you sure $module->getInfo('name', 's') of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

855
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UPDATING . /** @scrutinizer ignore-type */ $module->getInfo('name', 's') . '</h4>';
Loading history...
Unused Code introduced by
The call to XoopsModule::getInfo() has too many arguments starting with 's'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

855
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UPDATING . $module->/** @scrutinizer ignore-call */ getInfo('name', 's') . '</h4>';

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
856
        if (false !== $module->getInfo('image') && '' != trim($module->getInfo('image'))) {
0 ignored issues
show
Bug introduced by
It seems like $module->getInfo('image') can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

856
        if (false !== $module->getInfo('image') && '' != trim(/** @scrutinizer ignore-type */ $module->getInfo('image'))) {
Loading history...
857
            $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="">';
858
        }
859
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('module_status') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

859
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . /** @scrutinizer ignore-type */ $module->getInfo('module_status');
Loading history...
Bug introduced by
Are you sure $module->getInfo('version') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

859
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . /** @scrutinizer ignore-type */ $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
Loading history...
860
        if (false !== $module->getInfo('author') && '' != trim($module->getInfo('author'))) {
861
            $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')));
862
        }
863
        $msgs[] = '</div><div class="logger">';
864
        $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_UPDATE;
865
        /** @var \XoopsTplfileHandler $tplfileHandler */
866
        $tplfileHandler = xoops_getHandler('tplfile');
867
        // irmtfan bug fix: remove codes for delete templates
868
        /*
869
        $deltpl          = $tplfileHandler->find('default', 'module', $module->getVar('mid'));
870
        $delng           = [];
871
        if (is_array($deltpl)) {
872
            // delete template file entry in db
873
            $dcount = count($deltpl);
874
            for ($i = 0; $i < $dcount; ++$i) {
875
                if (!$tplfileHandler->delete($deltpl[$i])) {
876
                    $delng[] = $deltpl[$i]->getVar('tpl_file');
877
                }
878
            }
879
        }
880
        */
881
        // irmtfan bug fix: remove codes for delete templates
882
        $templates = $module->getInfo('templates');
883
        if (false !== $templates) {
0 ignored issues
show
introduced by
The condition false !== $templates is always true.
Loading history...
884
            $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_UPDATE;
885
            foreach ($templates as $tpl) {
886
                $tpl['file'] = trim($tpl['file']);
887
                // START irmtfan solve templates duplicate issue
888
                // if (!in_array($tpl['file'], $delng)) { // irmtfan bug fix: remove codes for delete templates
889
                $type = ($tpl['type'] ?? 'module');
890
                if (preg_match("/\.css$/i", $tpl['file'])) {
891
                    $type = 'css';
892
                }
893
                $criteria = new \CriteriaCompo();
894
                $criteria->add(new \Criteria('tpl_refid', $newmid), 'AND');
0 ignored issues
show
Bug introduced by
It seems like $newmid can also be of type array and array; however, parameter $value of Criteria::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

894
                $criteria->add(new \Criteria('tpl_refid', /** @scrutinizer ignore-type */ $newmid), 'AND');
Loading history...
895
                $criteria->add(new \Criteria('tpl_module', $dirname), 'AND');
896
                $criteria->add(new \Criteria('tpl_tplset', 'default'), 'AND');
897
                $criteria->add(new \Criteria('tpl_file', $tpl['file']), 'AND');
898
                $criteria->add(new \Criteria('tpl_type', $type), 'AND');
899
                $tplfiles = $tplfileHandler->getObjects($criteria);
900
901
                $tpldata = xoops_module_gettemplate($dirname, $tpl['file'], $type);
902
                $tplfile = empty($tplfiles) ? $tplfileHandler->create() : $tplfiles[0];
903
                // END irmtfan solve templates duplicate issue
904
                $tplfile->setVar('tpl_refid', $newmid);
905
                $tplfile->setVar('tpl_lastimported', 0);
906
                $tplfile->setVar('tpl_lastmodified', time());
907
                $tplfile->setVar('tpl_type', $type);
908
                $tplfile->setVar('tpl_source', $tpldata, true);
909
                $tplfile->setVar('tpl_module', $dirname);
910
                $tplfile->setVar('tpl_tplset', 'default');
911
                $tplfile->setVar('tpl_file', $tpl['file'], true);
912
                $tplfile->setVar('tpl_desc', $tpl['description'], true);
913
                if (!$tplfileHandler->insert($tplfile)) {
914
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
915
                } else {
916
                    $newid  = $tplfile->getVar('tpl_id');
917
                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_INSERT_DATA, '<strong>' . $tpl['file'] . '</strong>');
918
                    if ('default' === $xoopsConfig['template_set']) {
919
                        if (!xoops_template_touch($newid)) {
920
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
921
                        } else {
922
                            $msgs[] = '&nbsp;&nbsp;<span>' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
923
                        }
924
                    }
925
                }
926
                unset($tpldata);
927
                // irmtfan bug fix: remove codes for delete templates
928
                /*
929
                } else {
930
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_OLD_ERROR, "<strong>".$tpl['file']."</strong>").'</span>';
931
                }
932
                */
933
                // irmtfan bug fix: remove codes for delete templates
934
            }
935
        }
936
        $blocks = $module->getInfo('blocks');
937
        $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_REBUILD;
938
        if (false !== $blocks) {
0 ignored issues
show
introduced by
The condition false !== $blocks is always true.
Loading history...
939
            $showfuncs = [];
940
            $funcfiles = [];
941
            foreach ($blocks as $i => $block) {
942
                if (isset($block['show_func']) && '' != $block['show_func'] && isset($block['file'])
943
                    && '' != $block['file']) {
944
                    $editfunc    = $block['edit_func'] ?? '';
945
                    $showfuncs[] = $block['show_func'];
946
                    $funcfiles[] = $block['file'];
947
                    $template    = '';
948
                    if (isset($block['template']) && '' != trim($block['template'])) {
949
                        $content = xoops_module_gettemplate($dirname, $block['template'], 'blocks');
950
                    }
951
                    if (!$content) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $content does not seem to be defined for all execution paths leading up to this point.
Loading history...
952
                        $content = '';
953
                    } else {
954
                        $template = $block['template'];
955
                    }
956
                    $options = '';
957
                    if (!empty($block['options'])) {
958
                        $options = $block['options'];
959
                    }
960
                    $sql     = 'SELECT bid, name FROM ' . $xoopsDB->prefix('newblocks') . ' WHERE mid=' . $module->getVar('mid') . ' AND func_num=' . $i . " AND show_func='" . addslashes($block['show_func']) . "' AND func_file='" . addslashes($block['file']) . "'";
961
                    $fresult = $xoopsDB->query($sql);
962
                    $fcount  = 0;
963
                    while (false !== ($fblock = $xoopsDB->fetchArray($fresult))) {
964
                        ++$fcount;
965
                        $sql    = 'UPDATE ' . $xoopsDB->prefix('newblocks') . " SET name='" . addslashes($block['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . ' WHERE bid=' . $fblock['bid'];
966
                        $result = $xoopsDB->query($sql);
967
                        if (!$result) {
968
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_UPDATE_ERROR, $fblock['name']);
969
                        } else {
970
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_UPDATE, $fblock['name']) . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $fblock['bid'] . '</strong>');
971
                            if ('' != $template) {
972
                                $tplfile = $tplfileHandler->find('default', 'block', $fblock['bid']);
973
                                if (0 == count($tplfile)) {
974
                                    $tplfile_new = $tplfileHandler->create();
975
                                    $tplfile_new->setVar('tpl_module', $dirname);
976
                                    $tplfile_new->setVar('tpl_refid', $fblock['bid']);
977
                                    $tplfile_new->setVar('tpl_tplset', 'default');
978
                                    $tplfile_new->setVar('tpl_file', $block['template'], true);
979
                                    $tplfile_new->setVar('tpl_type', 'block');
980
                                } else {
981
                                    $tplfile_new = $tplfile[0];
982
                                }
983
                                $tplfile_new->setVar('tpl_source', $content, true);
984
                                $tplfile_new->setVar('tpl_desc', $block['description'], true);
985
                                $tplfile_new->setVar('tpl_lastmodified', time());
986
                                $tplfile_new->setVar('tpl_lastimported', 0);
987
                                $tplfile_new->setVar('tpl_file', $block['template'], true); // irmtfan bug fix:  block template file will not updated after update the module
988
                                if (!$tplfileHandler->insert($tplfile_new)) {
989
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
990
                                } else {
991
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE, '<strong>' . $block['template'] . '</strong>');
992
                                    if ('default' === $xoopsConfig['template_set']) {
993
                                        if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) {
994
                                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
995
                                        } else {
996
                                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>');
997
                                        }
998
                                    }
999
                                }
1000
                            }
1001
                        }
1002
                    }
1003
                    if (0 == $fcount) {
1004
                        $newbid     = $xoopsDB->genId($xoopsDB->prefix('newblocks') . '_bid_seq');
1005
                        $block_name = addslashes($block['name']);
1006
                        $block_type = ('system' === $module->getVar('dirname')) ? 'S' : 'M';
1007
                        $sql        = 'INSERT INTO '
1008
                                      . $xoopsDB->prefix('newblocks')
1009
                                      . ' (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES ('
1010
                                      . $newbid
1011
                                      . ', '
1012
                                      . $module->getVar(
1013
                                'mid'
1014
                            )
1015
                                      . ', '
1016
                                      . $i
1017
                                      . ",'"
1018
                                      . addslashes($options)
1019
                                      . "','"
1020
                                      . $block_name
1021
                                      . "', '"
1022
                                      . $block_name
1023
                                      . "', '', 0, 0, 0, '{$block_type}', 1, '"
1024
                                      . addslashes($dirname)
1025
                                      . "', '"
1026
                                      . addslashes($block['file'])
1027
                                      . "', '"
1028
                                      . addslashes($block['show_func'])
1029
                                      . "', '"
1030
                                      . addslashes($editfunc)
1031
                                      . "', '"
1032
                                      . $template
1033
                                      . "', "
1034
                                      . time()
1035
                                      . ')';
1036
                        $result     = $xoopsDB->query($sql);
1037
                        if (!$result) {
1038
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_CREATE, $block['name']);
1039
                            echo $sql;
1040
                        } else {
1041
                            if (empty($newbid)) {
1042
                                $newbid = $xoopsDB->getInsertId();
1043
                            }
1044
                            $groups = [XOOPS_GROUP_ADMIN];
1045
                            if ($module->getInfo('hasMain')) {
1046
                                $groups = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS];
1047
                            }
1048
                            /** @var \XoopsGroupPermHandler $grouppermHandler */
1049
                            $grouppermHandler = xoops_getHandler('groupperm');
1050
                            foreach ($groups as $mygroup) {
1051
                                $bperm = $grouppermHandler->create();
1052
                                $bperm->setVar('gperm_groupid', $mygroup);
1053
                                $bperm->setVar('gperm_itemid', $newbid);
1054
                                $bperm->setVar('gperm_name', 'block_read');
1055
                                $bperm->setVar('gperm_modid', 1);
1056
                                if (!$grouppermHandler->insert($bperm)) {
0 ignored issues
show
Bug introduced by
$bperm of type boolean is incompatible with the type XoopsObject expected by parameter $perm of XoopsGroupPermHandler::insert(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1056
                                if (!$grouppermHandler->insert(/** @scrutinizer ignore-type */ $bperm)) {
Loading history...
1057
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>') . '</span>';
1058
                                } else {
1059
                                    $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>');
1060
                                }
1061
                            }
1062
1063
                            if ('' != $template) {
1064
                                $tplfile = $tplfileHandler->create();
1065
                                $tplfile->setVar('tpl_module', $dirname);
1066
                                $tplfile->setVar('tpl_refid', $newbid);
1067
                                $tplfile->setVar('tpl_source', $content, true);
1068
                                $tplfile->setVar('tpl_tplset', 'default');
1069
                                $tplfile->setVar('tpl_file', $block['template'], true);
1070
                                $tplfile->setVar('tpl_type', 'block');
1071
                                $tplfile->setVar('tpl_lastimported', time());
1072
                                $tplfile->setVar('tpl_lastmodified', time());
1073
                                $tplfile->setVar('tpl_desc', $block['description'], true);
1074
                                if (!$tplfileHandler->insert($tplfile)) {
1075
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
1076
                                } else {
1077
                                    $newid  = $tplfile->getVar('tpl_id');
1078
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>');
1079
                                    if ('default' === $xoopsConfig['template_set']) {
1080
                                        if (!xoops_template_touch($newid)) {
1081
                                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, '<strong>' . $block['template'] . '</strong>') . '</span>';
1082
                                        } else {
1083
                                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>');
1084
                                        }
1085
                                    }
1086
                                }
1087
                            }
1088
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>');
1089
                            $sql    = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
1090
                            $xoopsDB->query($sql);
1091
                        }
1092
                    }
1093
                }
1094
            }
1095
            $block_arr = \XoopsBlock::getByModule($module->getVar('mid'));
1096
            foreach ($block_arr as $block) {
1097
                if (!in_array($block->getVar('show_func'), $showfuncs)
1098
                    || !in_array($block->getVar('func_file'), $funcfiles)) {
1099
                    $sql = sprintf('DELETE FROM `%s` WHERE bid = %u', $xoopsDB->prefix('newblocks'), $block->getVar('bid'));
1100
                    if (!$xoopsDB->query($sql)) {
1101
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, '<strong>' . $block->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block->getVar('bid') . '</strong>') . '</span>';
1102
                    } else {
1103
                        $msgs[] = '&nbsp;&nbsp;Block <strong>' . $block->getVar('name') . ' deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>';
1104
                        if ('' != $block->getVar('template')) {
1105
                            $tplfiles = $tplfileHandler->find(null, 'block', $block->getVar('bid'));
1106
                            if (is_array($tplfiles)) {
1107
                                $btcount = count($tplfiles);
1108
                                for ($k = 0; $k < $btcount; ++$k) {
1109
                                    if (!$tplfileHandler->delete($tplfiles[$k])) {
1110
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_DEPRECATED_ERROR . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>';
1111
                                    } else {
1112
                                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DEPRECATED, '<strong>' . $tplfiles[$k]->getVar('tpl_file') . '</strong>');
1113
                                    }
1114
                                }
1115
                            }
1116
                        }
1117
                    }
1118
                }
1119
            }
1120
        }
1121
1122
        // reset compile_id
1123
1124
        //        $xoTheme  = $xoopsThemeFactory->createInstance(array('contentTemplate' => @$xoopsOption['template_main']));
1125
        //        $xoopsTpl = $xoTheme->template;
1126
        //        $xoopsTpl->setCompileId();
1127
1128
        $template = $clearTpl;
1129
        $template->setCompileId();
1130
        //        $GLOBALS['xoopsTpl']->setCompileId();
1131
        //        $xoopsTpl->setCompileId();
1132
1133
        // first delete all config entries
1134
        /** @var \XoopsConfigHandler $configHandler */
1135
        $configHandler = xoops_getHandler('config');
1136
        $configs       = $configHandler->getConfigs(new \Criteria('conf_modid', $module->getVar('mid')));
1137
        $confcount     = count($configs);
1138
        $config_delng  = [];
1139
        if ($confcount > 0) {
1140
            $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE;
1141
            for ($i = 0; $i < $confcount; ++$i) {
1142
                if (!$configHandler->deleteConfig($configs[$i])) {
1143
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE_ERROR . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>') . '</span>';
0 ignored issues
show
Bug introduced by
The constant _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE_ERROR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1144
                    // save the name of config failed to delete for later use
1145
                    $config_delng[] = $configs[$i]->getvar('conf_name');
1146
                } else {
1147
                    $config_old[$configs[$i]->getvar('conf_name')]['value']     = $configs[$i]->getvar('conf_value', 'N');
1148
                    $config_old[$configs[$i]->getvar('conf_name')]['formtype']  = $configs[$i]->getvar('conf_formtype');
1149
                    $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
1150
                    $msgs[]                                                     = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getVar('conf_id') . '</strong>');
1151
                }
1152
            }
1153
        }
1154
1155
        // now reinsert them with the new settings
1156
        $configs = $module->getInfo('config');
1157
        if (false !== $configs) {
0 ignored issues
show
introduced by
The condition false !== $configs is always true.
Loading history...
1158
            if (0 != $module->getVar('hascomments')) {
1159
                require_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
1160
                $configs[] = [
1161
                    'name'        => 'com_rule',
1162
                    'title'       => '_CM_COMRULES',
1163
                    'description' => '',
1164
                    'formtype'    => 'select',
1165
                    'valuetype'   => 'int',
1166
                    'default'     => 1,
1167
                    'options'     => [
1168
                        '_CM_COMNOCOM'        => XOOPS_COMMENT_APPROVENONE,
1169
                        '_CM_COMAPPROVEALL'   => XOOPS_COMMENT_APPROVEALL,
1170
                        '_CM_COMAPPROVEUSER'  => XOOPS_COMMENT_APPROVEUSER,
1171
                        '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN,
1172
                    ],
1173
                ];
1174
                $configs[] = [
1175
                    'name'        => 'com_anonpost',
1176
                    'title'       => '_CM_COMANONPOST',
1177
                    'description' => '',
1178
                    'formtype'    => 'yesno',
1179
                    'valuetype'   => 'int',
1180
                    'default'     => 0,
1181
                ];
1182
            }
1183
        } elseif (0 != $module->getVar('hascomments')) {
1184
            $configs = [];
1185
            require_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
1186
            $configs[] = [
1187
                'name'        => 'com_rule',
1188
                'title'       => '_CM_COMRULES',
1189
                'description' => '',
1190
                'formtype'    => 'select',
1191
                'valuetype'   => 'int',
1192
                'default'     => 1,
1193
                'options'     => [
1194
                    '_CM_COMNOCOM'        => XOOPS_COMMENT_APPROVENONE,
1195
                    '_CM_COMAPPROVEALL'   => XOOPS_COMMENT_APPROVEALL,
1196
                    '_CM_COMAPPROVEUSER'  => XOOPS_COMMENT_APPROVEUSER,
1197
                    '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN,
1198
                ],
1199
            ];
1200
            $configs[] = [
1201
                'name'        => 'com_anonpost',
1202
                'title'       => '_CM_COMANONPOST',
1203
                'description' => '',
1204
                'formtype'    => 'yesno',
1205
                'valuetype'   => 'int',
1206
                'default'     => 0,
1207
            ];
1208
        }
1209
        // RMV-NOTIFY
1210
        if (0 != $module->getVar('hasnotification')) {
1211
            if (empty($configs)) {
1212
                $configs = [];
1213
            }
1214
            // Main notification options
1215
            require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
1216
            require_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
1217
            $options                             = [];
1218
            $options['_NOT_CONFIG_DISABLE']      = XOOPS_NOTIFICATION_DISABLE;
1219
            $options['_NOT_CONFIG_ENABLEBLOCK']  = XOOPS_NOTIFICATION_ENABLEBLOCK;
1220
            $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
1221
            $options['_NOT_CONFIG_ENABLEBOTH']   = XOOPS_NOTIFICATION_ENABLEBOTH;
1222
1223
            //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
1224
            $configs[] = [
1225
                'name'        => 'notification_enabled',
1226
                'title'       => '_NOT_CONFIG_ENABLE',
1227
                'description' => '_NOT_CONFIG_ENABLEDSC',
1228
                'formtype'    => 'select',
1229
                'valuetype'   => 'int',
1230
                'default'     => XOOPS_NOTIFICATION_ENABLEBOTH,
1231
                'options'     => $options,
1232
            ];
1233
            // Event specific notification options
1234
            // FIXME: for some reason the default doesn't come up properly
1235
            //  initially is ok, but not when 'update' module..
1236
            $options    = [];
1237
            $categories = notificationCategoryInfo('', $module->getVar('mid'));
1238
            foreach ($categories as $category) {
1239
                $events = notificationEvents($category['name'], false, $module->getVar('mid'));
1240
                foreach ($events as $event) {
1241
                    if (!empty($event['invisible'])) {
1242
                        continue;
1243
                    }
1244
                    $option_name           = $category['title'] . ' : ' . $event['title'];
1245
                    $option_value          = $category['name'] . '-' . $event['name'];
1246
                    $options[$option_name] = $option_value;
1247
                    //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
1248
                }
1249
            }
1250
            $configs[] = [
1251
                'name'        => 'notification_events',
1252
                'title'       => '_NOT_CONFIG_EVENTS',
1253
                'description' => '_NOT_CONFIG_EVENTSDSC',
1254
                'formtype'    => 'select_multi',
1255
                'valuetype'   => 'array',
1256
                'default'     => array_values($options),
1257
                'options'     => $options,
1258
            ];
1259
        }
1260
1261
        if (false !== $configs) {
0 ignored issues
show
introduced by
The condition false !== $configs is always true.
Loading history...
1262
            $msgs[] = 'Adding module config data...';
1263
            /** @var \XoopsConfigHandler $configHandler */
1264
            $configHandler = xoops_getHandler('config');
1265
            $order         = 0;
1266
            foreach ($configs as $config) {
1267
                // only insert ones that have been deleted previously with success
1268
                if (!in_array($config['name'], $config_delng)) {
1269
                    $confobj = $configHandler->createConfig();
1270
                    $confobj->setVar('conf_modid', $newmid);
1271
                    $confobj->setVar('conf_catid', 0);
1272
                    $confobj->setVar('conf_name', $config['name']);
1273
                    $confobj->setVar('conf_title', $config['title'], true);
1274
                    $confobj->setVar('conf_desc', $config['description'], true);
1275
                    $confobj->setVar('conf_formtype', $config['formtype']);
1276
                    if (isset($config['valuetype'])) {
1277
                        $confobj->setVar('conf_valuetype', $config['valuetype']);
1278
                    }
1279
                    if (isset($config_old[$config['name']]['value'])
1280
                        && $config_old[$config['name']]['formtype'] == $config['formtype']
1281
                        && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
1282
                        // preserver the old value if any
1283
                        // form type and value type must be the same
1284
                        $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
1285
                    } else {
1286
                        $confobj->setConfValueForInput($config['default'], true);
1287
                        //$confobj->setVar('conf_value', $config['default'], true);
1288
                    }
1289
                    $confobj->setVar('conf_order', $order);
1290
                    $confop_msgs = '';
1291
                    if (isset($config['options']) && is_array($config['options'])) {
1292
                        foreach ($config['options'] as $key => $value) {
1293
                            $confop = $configHandler->createConfigOption();
1294
                            $confop->setVar('confop_name', $key, true);
1295
                            $confop->setVar('confop_value', $value, true);
1296
                            $confobj->setConfOptions($confop);
1297
                            $confop_msgs .= '<br>&nbsp;&nbsp;&nbsp;&nbsp; ' . _AM_SYSTEM_MODULES_CONFIG_ADD . _AM_SYSTEM_MODULES_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _AM_SYSTEM_MODULES_VALUE . ' <strong>' . $value . '</strong> ';
1298
                            unset($confop);
1299
                        }
1300
                    }
1301
                    ++$order;
1302
                    if ($configHandler->insertConfig($confobj)) {
1303
                        //$msgs[] = '&nbsp;&nbsp;Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs;
1304
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs;
1305
                    } else {
1306
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>';
1307
                    }
1308
                    unset($confobj);
1309
                }
1310
            }
1311
            unset($configs);
1312
        }
1313
1314
        // execute module specific update script if any
1315
        $update_script = $module->getInfo('onUpdate');
1316
        if (false !== $update_script && '' != trim($update_script)) {
1317
            require_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script);
1318
            if (function_exists('xoops_module_update_' . $dirname)) {
1319
                $func = 'xoops_module_update_' . $dirname;
1320
                if (!$func($module, $prev_version)) {
1321
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
1322
                    $msgs   = array_merge($msgs, $module->getErrors());
1323
                } else {
1324
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>';
1325
                    $msgs   += $module->getErrors();
1326
                }
1327
            }
1328
        }
1329
        $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKUPD, '<strong>' . $module->getVar('name', 's') . '</strong>');
1330
        $msgs[] = '</div></div>';
1331
        $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a>  | <a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a></div>';
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('adminindex') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1331
        $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a>  | <a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . /** @scrutinizer ignore-type */ $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a></div>';
Loading history...
Bug introduced by
Are you sure $module->getInfo('dirname', 'e') of type false|mixed|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1331
        $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a>  | <a href="' . XOOPS_URL . '/modules/' . /** @scrutinizer ignore-type */ $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a></div>';
Loading history...
1332
        //        foreach ($msgs as $msg) {
1333
        //            echo $msg . '<br>';
1334
        //        }
1335
    }
1336
    // Call Footer
1337
    //    xoops_cp_footer();
1338
    // Flush cache files for cpanel GUIs
1339
    //    xoops_load("cpanel", "system");
1340
    //    XoopsSystemCpanel::flush();
1341
    //
1342
    //    require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
1343
    //    $maintenance = new SystemMaintenance();
1344
    //    $folder      = array(1, 3);
1345
    //    $maintenance->CleanCache($folder);
1346
    //Set active modules in cache folder
1347
    //    xoops_setActiveModules();
1348
    //    break;
1349
    //-----------------------------------------------
1350
1351
    $ret = implode('<br>', $msgs);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $msgs does not seem to be defined for all execution paths leading up to this point.
Loading history...
1352
1353
    return $ret;
1354
}
1355
1356
/**
1357
 * @param $mid
1358
 *
1359
 * @return string
1360
 */
1361
function xoops_module_activate($mid)
1362
{
1363
    // Get module handler
1364
    /** @var \XoopsModuleHandler $moduleHandler */
1365
    $moduleHandler = xoops_getHandler('module');
1366
    $module        = $moduleHandler->get($mid);
1367
    require_once XOOPS_ROOT_PATH . '/class/template.php';
1368
    xoops_template_clear_module_cache($module->getVar('mid'));
1369
    // Display header
1370
    $msgs[] = '<div id="xo-module-log">';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$msgs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $msgs = array(); before regardless.
Loading history...
1371
    $msgs   += xoops_module_log_header($module, _AM_SYSTEM_MODULES_ACTIVATE);
1372
    // Change value
1373
    $module->setVar('isactive', 1);
1374
    if (!$moduleHandler->insert($module)) {
1375
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILACT, '<strong>' . $module->getVar('name', 's') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . $module->getHtmlErrors() . '</p>';
1376
    } else {
1377
        $blocks = \XoopsBlock::getByModule($module->getVar('mid'));
1378
        $bcount = count($blocks);
0 ignored issues
show
Unused Code introduced by
The assignment to $bcount is dead and can be removed.
Loading history...
1379
        foreach ($blocks as $iValue) {
1380
            $iValue->setVar('isactive', 1);
1381
            $iValue->store();
1382
        }
1383
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKACT, '<strong>' . $module->getVar('name', 's') . '</strong>') . '</p></div>';
1384
    }
1385
    //$msgs[] = '</div>';
1386
    $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
1387
    $ret    = implode('<br>', $msgs);
1388
1389
    return $ret;
1390
}
1391
1392
/**
1393
 * @param $mid
1394
 *
1395
 * @return string
1396
 */
1397
function xoops_module_deactivate($mid)
1398
{
1399
    global $xoopsConfig;
1400
    // Get module handler
1401
    /** @var \XoopsModuleHandler $moduleHandler */
1402
    $moduleHandler = xoops_getHandler('module');
1403
    $module        = $moduleHandler->get($mid);
1404
    require_once XOOPS_ROOT_PATH . '/class/template.php';
1405
    xoops_template_clear_module_cache($mid);
1406
    // Display header
1407
    $msgs[] = '<div id="xo-module-log">';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$msgs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $msgs = array(); before regardless.
Loading history...
1408
    $msgs   += xoops_module_log_header($module, _AM_SYSTEM_MODULES_DEACTIVATE);
1409
    // Change value
1410
    $module->setVar('isactive', 0);
1411
    if ('system' === $module->getVar('dirname')) {
1412
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
1413
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
1414
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
1415
    } elseif (!$moduleHandler->insert($module)) {
1416
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . $module->getHtmlErrors() . '</p>';
1417
    } else {
1418
        $blocks = \XoopsBlock::getByModule($module->getVar('mid'));
1419
        $bcount = count($blocks);
0 ignored issues
show
Unused Code introduced by
The assignment to $bcount is dead and can be removed.
Loading history...
1420
        foreach ($blocks as $iValue) {
1421
            $iValue->setVar('isactive', 0);
1422
            $iValue->store();
1423
        }
1424
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
1425
    }
1426
1427
    $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
1428
    $ret    = implode('<br>', $msgs);
1429
1430
    return $ret;
1431
}
1432
1433
/**
1434
 * @param $mid
1435
 * @param $name
1436
 *
1437
 * @return string
1438
 */
1439
function xoops_module_change($mid, $name)
1440
{
1441
    /** @var \XoopsModuleHandler $moduleHandler */
1442
    $moduleHandler = xoops_getHandler('module');
1443
    $module        = $moduleHandler->get($mid);
1444
    $module->setVar('name', $name);
1445
    $myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
1446
    if (!$moduleHandler->insert($module)) {
1447
        $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILORDER, '<strong>' . ($name) . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>';
1448
        $ret .= $module->getHtmlErrors() . '</p>';
1449
1450
        return $ret;
1451
    }
1452
1453
    return '<p>' . sprintf(_AM_SYSTEM_MODULES_OKORDER, '<strong>' . ($name) . '</strong>') . '</p>';
1454
}
1455
1456
/**
1457
 * @param $module
1458
 * @param $title
1459
 *
1460
 * @return array
1461
 */
1462
function xoops_module_log_header($module, $title)
1463
{
1464
    $msgs[] = '<div class="header">';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$msgs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $msgs = array(); before regardless.
Loading history...
1465
    $msgs[] = $errs[] = '<h4>' . $title . $module->getInfo('name', 's') . '</h4>';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$errs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $errs = array(); before regardless.
Loading history...
1466
    if (false !== $module->getInfo('image') && '' != trim($module->getInfo('image'))) {
1467
        $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/' . trim($module->getInfo('image')) . '" alt="">';
1468
    }
1469
    $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
1470
    if (false !== $module->getInfo('author') && '' != trim($module->getInfo('author'))) {
1471
        $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')), ENT_QUOTES | ENT_HTML5);
1472
    }
1473
    $msgs[] = '</div>';
1474
1475
    return $msgs;
1476
}
1477