xoops_module_update()   F
last analyzed

Complexity

Conditions 78
Paths 6145

Size

Total Lines 547
Code Lines 374

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 78
eloc 374
c 2
b 0
f 0
nc 6145
nop 1
dl 0
loc 547
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 declare(strict_types=1);
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.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu)
16
 * @param mixed $dirname
17
 */
18
19
/*
20
if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
21
    exit("Access Denied");
22
}
23
*/
24
25
/**
26
 * @param $dirname
27
 *
28
 * @return string
29
 */
30
function xoops_module_install($dirname)
31
{
32
    $pieces = null;
33
    global $xoopsUser, $xoopsConfig;
34
    $dirname = trim((string) $dirname);
35
    //    $db = $GLOBALS['xoopsDB'];
36
    $db             = \XoopsDatabaseFactory::getDatabaseConnection();
37
    $reservedTables = [
38
        'avatar',
39
        'avatar_users_link',
40
        'block_module_link',
41
        'xoopscomments',
42
        'config',
43
        'configcategory',
44
        'configoption',
45
        'image',
46
        'imagebody',
47
        'imagecategory',
48
        'imgset',
49
        'imgset_tplset_link',
50
        'imgsetimg',
51
        'groups',
52
        'groups_users_link',
53
        'group_permission',
54
        'online',
55
        'bannerclient',
56
        'banner',
57
        'bannerfinish',
58
        'priv_msgs',
59
        'ranks',
60
        'session',
61
        'smiles',
62
        'users',
63
        'newblocks',
64
        'modules',
65
        'tplfile',
66
        'tplset',
67
        'tplsource',
68
        'xoopsnotifications',
69
        'banner',
70
        'bannerclient',
71
        'bannerfinish',
72
    ];
73
    /** @var \XoopsModuleHandler $moduleHandler */
74
    $moduleHandler = xoops_getHandler('module');
75
    if (0 == $moduleHandler->getCount(new \Criteria('dirname', $dirname))) {
76
        $module = $moduleHandler->create();
77
        $module->loadInfoAsVar($dirname);
78
        $module->setVar('weight', 1);
79
        $module->setVar('isactive', 1);
80
        $module->setVar('last_update', time());
81
        $error = false;
82
        $errs  = [];
83
        $msgs  = [];
84
85
        $msgs[] = '<div id="xo-module-log"><div class="header">';
86
        $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

86
        $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

86
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_INSTALLING . /** @scrutinizer ignore-type */ $module->getInfo('name', 's') . '</h4>';
Loading history...
87
        if (false !== $module->getInfo('image') && '' != trim((string) $module->getInfo('image'))) {
88
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim((string) $module->getInfo('image')) . '" alt=""></a>';
0 ignored issues
show
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

88
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . /** @scrutinizer ignore-type */ $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim((string) $module->getInfo('image')) . '" alt=""></a>';
Loading history...
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

88
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . /** @scrutinizer ignore-type */ $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim((string) $module->getInfo('image')) . '" alt=""></a>';
Loading history...
89
        }
90
        $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

90
        $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

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

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

455
            $blocks = /** @scrutinizer ignore-deprecated */ \XoopsBlock::getByModule($newmid, false);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
456
            $msgs[] = _AM_SYSTEM_MODULES_GROUP_SETTINGS_ADD;
457
            /** @var \XoopsGroupPermHandler $grouppermHandler */
458
            $grouppermHandler = xoops_getHandler('groupperm');
459
            foreach ($groups as $mygroup) {
460
                if ($grouppermHandler->checkRight('module_admin', 0, $mygroup)) {
461
                    $mperm = $grouppermHandler->create();
462
                    $mperm->setVar('gperm_groupid', $mygroup);
463
                    $mperm->setVar('gperm_itemid', $newmid);
464
                    $mperm->setVar('gperm_name', 'module_admin');
465
                    $mperm->setVar('gperm_modid', 1);
466
                    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

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

519
            $msgs[] = '<br><span class="red bold">' . _AM_SYSTEM_MODULES_MODULE . ' ' . /** @scrutinizer ignore-type */ $module->getInfo('name') . ': </span></div>';
Loading history...
520
            if (false !== $blocks) {
0 ignored issues
show
introduced by
The condition false !== $blocks is always true.
Loading history...
521
                $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>';
522
            }
523
524
            $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=preferences&op=showmod&mod=' . $newmid . '">' . _AM_SYSTEM_PREF . '</a>';
525
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a>';
526
527
            $testdataDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata';
528
            if (file_exists($testdataDirectory)) {
529
                $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata/index.php' . '">' . _AM_SYSTEM_MODULES_INSTALL_TESTDATA . '</a></div>';
530
            } else {
531
                $msgs[] = '</div>';
532
            }
533
534
            $ret = implode('<br>', $msgs);
535
            unset($blocks, $msgs, $errs, $module);
536
537
            return $ret;
538
        }
539
        $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . implode('<br>', $errs) . '</p>';
540
        unset($msgs, $errs);
541
542
        return $ret;
543
    }
544
545
    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>';
546
}
547
548
/**
549
 * @param        $dirname
550
 * @param        $template
551
 * @param string $type
552
 *
553
 * @return string
554
 */
555
function &xoops_module_gettemplate($dirname, $template, $type = '')
556
{
557
    global $xoopsConfig;
558
    $ret = '';
559
    switch ($type) {
560
        case 'blocks':
561
        case 'admin':
562
            $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $type . '/' . $template;
563
            break;
564
        default:
565
            $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $template;
566
            break;
567
    }
568
    if (!is_file($path)) {
569
        return $ret;
570
    }
571
    $lines = file($path);
572
573
    if (!$lines) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $lines of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
574
        return $ret;
575
    }
576
    $count = count($lines);
0 ignored issues
show
Unused Code introduced by
The assignment to $count is dead and can be removed.
Loading history...
577
    foreach ($lines as $i => $iValue) {
578
        $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
579
    }
580
581
    return $ret;
582
}
583
584
/**
585
 * @param $dirname
586
 *
587
 * @return string
588
 */
589
function xoops_module_uninstall($dirname)
590
{
591
    $errs = [];
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...
645
    if (false !== $module->getInfo('image') && '' != trim((string) $module->getInfo('image'))) {
646
        $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim((string) $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((string) $module->getInfo('author'))) {
650
        $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim((string) $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((string) $uninstall_script)) {
656
        require_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim((string) $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 $values of sprintf() does only seem to accept double|integer|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         = is_countable($templates) ? count($templates) : 0;
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'));
0 ignored issues
show
Deprecated Code introduced by
The function XoopsBlock::getByModule() has been deprecated: (This also appears, dead, in XoopsBlockHandler) ( Ignorable by Annotation )

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

693
        $block_arr = /** @scrutinizer ignore-deprecated */ \XoopsBlock::getByModule($module->getVar('mid'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
694
        if (is_array($block_arr)) {
0 ignored issues
show
introduced by
The condition is_array($block_arr) is always true.
Loading history...
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   = is_countable($templates) ? count($templates) : 0;
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, true)) {
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     = is_countable($configs) ? count($configs) : 0;
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
    $errs = [];
813
    $config_old = [];
814
    $msgs = [];
815
    global $xoopsUser, $xoopsConfig, $xoopsTpl;
816
    $dirname = trim((string) $dirname);
817
    //    $xoopsDB = $GLOBALS['xoopsDB'];
818
    $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
819
820
    $myts = \MyTextSanitizer::getInstance();
821
822
    $dirname = htmlspecialchars(trim($dirname), ENT_QUOTES | ENT_HTML5);
823
    /** @var \XoopsModuleHandler $moduleHandler */
824
    $moduleHandler = xoops_getHandler('module');
825
    $module        = $moduleHandler->getByDirname($dirname);
826
    // Save current version for use in the update function
827
    $prev_version = $module->getVar('version');
828
    $clearTpl     = new \XoopsTpl();
829
    $clearTpl->clearCache($dirname);
830
831
    // we don't want to change the module name set by admin
832
    $temp_name = $module->getVar('name');
833
    $module->loadInfoAsVar($dirname);
834
    $module->setVar('name', $temp_name);
835
    $module->setVar('last_update', time());
836
    /*
837
        // Call Header
838
        // Define main template
839
        $GLOBALS['xoopsOption']['template_main'] = 'system_header.html';
840
        // Call Header
841
        xoops_cp_header();
842
        // Define Stylesheet
843
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
844
        // Define Breadcrumb and tips
845
        $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath'));
846
        $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_UPDATE);
847
        $xoBreadCrumb->addHelp(system_adminVersion('modulesadmin', 'help') . '#update');https://www.facebook.com/photo.php?v=10154358806675333
848
        $xoBreadCrumb->render();
849
850
        */
851
    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

851
    if (!$moduleHandler->insert(/** @scrutinizer ignore-type */ $module)) {
Loading history...
852
        echo '<p>Could not update ' . $module->getVar('name') . '</p>';
853
        echo "<br><div class='center'><a href='admin.php?fct=modulesadmin'>" . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
854
    } else {
855
        $newmid = $module->getVar('mid');
856
        $msgs   = [];
857
        $msgs[] = '<div id="xo-module-log"><div class="header">';
858
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UPDATING . $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

858
        $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

858
        $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...
859
        if (false !== $module->getInfo('image') && '' != trim((string) $module->getInfo('image'))) {
860
            $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim((string) $module->getInfo('image')) . '" alt="">';
861
        }
862
        $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

862
        $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

862
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . /** @scrutinizer ignore-type */ $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
Loading history...
863
        if (false !== $module->getInfo('author') && '' != trim((string) $module->getInfo('author'))) {
864
            $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim((string) $module->getInfo('author')), ENT_QUOTES | ENT_HTML5);
865
        }
866
        $msgs[] = '</div><div class="logger">';
867
        $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_UPDATE;
868
        /** @var \XoopsTplfileHandler $tplfileHandler */
869
        $tplfileHandler = xoops_getHandler('tplfile');
870
        // irmtfan bug fix: remove codes for delete templates
871
        /*
872
        $deltpl          = $tplfileHandler->find('default', 'module', $module->getVar('mid'));
873
        $delng           = [];
874
        if (is_array($deltpl)) {
875
            // delete template file entry in db
876
            $dcount = count($deltpl);
877
            for ($i = 0; $i < $dcount; ++$i) {
878
                if (!$tplfileHandler->delete($deltpl[$i])) {
879
                    $delng[] = $deltpl[$i]->getVar('tpl_file');
880
                }
881
            }
882
        }
883
        */
884
        // irmtfan bug fix: remove codes for delete templates
885
        $templates = $module->getInfo('templates');
886
        if (false !== $templates) {
0 ignored issues
show
introduced by
The condition false !== $templates is always true.
Loading history...
887
            $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_UPDATE;
888
            foreach ($templates as $tpl) {
889
                $tpl['file'] = trim((string) $tpl['file']);
890
                // START irmtfan solve templates duplicate issue
891
                // if (!in_array($tpl['file'], $delng)) { // irmtfan bug fix: remove codes for delete templates
892
                $type = ($tpl['type'] ?? 'module');
893
                if (preg_match('/\.css$/i', $tpl['file'])) {
894
                    $type = 'css';
895
                }
896
                $criteria = new \CriteriaCompo();
897
                $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

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

1059
                                if (!$grouppermHandler->insert(/** @scrutinizer ignore-type */ $bperm)) {
Loading history...
1060
                                    $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>';
1061
                                } else {
1062
                                    $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>');
1063
                                }
1064
                            }
1065
1066
                            if ('' != $template) {
1067
                                $tplfile = $tplfileHandler->create();
1068
                                $tplfile->setVar('tpl_module', $dirname);
1069
                                $tplfile->setVar('tpl_refid', $newbid);
1070
                                $tplfile->setVar('tpl_source', $content, true);
1071
                                $tplfile->setVar('tpl_tplset', 'default');
1072
                                $tplfile->setVar('tpl_file', $block['template'], true);
1073
                                $tplfile->setVar('tpl_type', 'block');
1074
                                $tplfile->setVar('tpl_lastimported', time());
1075
                                $tplfile->setVar('tpl_lastmodified', time());
1076
                                $tplfile->setVar('tpl_desc', $block['description'], true);
1077
                                if (!$tplfileHandler->insert($tplfile)) {
1078
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
1079
                                } else {
1080
                                    $newid  = $tplfile->getVar('tpl_id');
1081
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>');
1082
                                    if ('default' === $xoopsConfig['template_set']) {
1083
                                        if (!xoops_template_touch($newid)) {
1084
                                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, '<strong>' . $block['template'] . '</strong>') . '</span>';
1085
                                        } else {
1086
                                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>');
1087
                                        }
1088
                                    }
1089
                                }
1090
                            }
1091
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>');
1092
                            $sql    = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
1093
                            $xoopsDB->query($sql);
1094
                        }
1095
                    }
1096
                }
1097
            }
1098
            $block_arr = \XoopsBlock::getByModule($module->getVar('mid'));
0 ignored issues
show
Deprecated Code introduced by
The function XoopsBlock::getByModule() has been deprecated: (This also appears, dead, in XoopsBlockHandler) ( Ignorable by Annotation )

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

1098
            $block_arr = /** @scrutinizer ignore-deprecated */ \XoopsBlock::getByModule($module->getVar('mid'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1099
            foreach ($block_arr as $block) {
1100
                if (!in_array($block->getVar('show_func'), $showfuncs, true)
1101
                    || !in_array($block->getVar('func_file'), $funcfiles, true)) {
1102
                    $sql = sprintf('DELETE FROM `%s` WHERE bid = %u', $xoopsDB->prefix('newblocks'), $block->getVar('bid'));
1103
                    if (!$xoopsDB->query($sql)) {
1104
                        $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>';
1105
                    } else {
1106
                        $msgs[] = '&nbsp;&nbsp;Block <strong>' . $block->getVar('name') . ' deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>';
1107
                        if ('' != $block->getVar('template')) {
1108
                            $tplfiles = $tplfileHandler->find(null, 'block', $block->getVar('bid'));
1109
                            if (is_array($tplfiles)) {
1110
                                $btcount = count($tplfiles);
1111
                                for ($k = 0; $k < $btcount; ++$k) {
1112
                                    if (!$tplfileHandler->delete($tplfiles[$k])) {
1113
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_DEPRECATED_ERROR . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>';
1114
                                    } else {
1115
                                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DEPRECATED, '<strong>' . $tplfiles[$k]->getVar('tpl_file') . '</strong>');
1116
                                    }
1117
                                }
1118
                            }
1119
                        }
1120
                    }
1121
                }
1122
            }
1123
        }
1124
1125
        // reset compile_id
1126
1127
        //        $xoTheme  = $xoopsThemeFactory->createInstance(array('contentTemplate' => @$xoopsOption['template_main']));
1128
        //        $xoopsTpl = $xoTheme->template;
1129
        //        $xoopsTpl->setCompileId();
1130
1131
        $template = $clearTpl;
1132
        $template->setCompileId();
1133
        //        $GLOBALS['xoopsTpl']->setCompileId();
1134
        //        $xoopsTpl->setCompileId();
1135
1136
        // first delete all config entries
1137
        /** @var \XoopsConfigHandler $configHandler */
1138
        $configHandler = xoops_getHandler('config');
1139
        $configs       = $configHandler->getConfigs(new \Criteria('conf_modid', $module->getVar('mid')));
1140
        $confcount     = is_countable($configs) ? count($configs) : 0;
1141
        $config_delng  = [];
1142
        if ($confcount > 0) {
1143
            $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE;
1144
            for ($i = 0; $i < $confcount; ++$i) {
1145
                if (!$configHandler->deleteConfig($configs[$i])) {
1146
                    $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...
1147
                    // save the name of config failed to delete for later use
1148
                    $config_delng[] = $configs[$i]->getvar('conf_name');
1149
                } else {
1150
                    $config_old[$configs[$i]->getvar('conf_name')]['value']     = $configs[$i]->getvar('conf_value', 'N');
1151
                    $config_old[$configs[$i]->getvar('conf_name')]['formtype']  = $configs[$i]->getvar('conf_formtype');
1152
                    $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
1153
                    $msgs[]                                                     = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getVar('conf_id') . '</strong>');
1154
                }
1155
            }
1156
        }
1157
1158
        // now reinsert them with the new settings
1159
        $configs = $module->getInfo('config');
1160
        if (false !== $configs) {
0 ignored issues
show
introduced by
The condition false !== $configs is always true.
Loading history...
1161
            if (0 != $module->getVar('hascomments')) {
1162
                require XOOPS_ROOT_PATH . '/include/comment_constants.php';
1163
                $configs[] = [
1164
                    'name'        => 'com_rule',
1165
                    'title'       => '_CM_COMRULES',
1166
                    'description' => '',
1167
                    'formtype'    => 'select',
1168
                    'valuetype'   => 'int',
1169
                    'default'     => 1,
1170
                    'options'     => [
1171
                        '_CM_COMNOCOM'        => XOOPS_COMMENT_APPROVENONE,
1172
                        '_CM_COMAPPROVEALL'   => XOOPS_COMMENT_APPROVEALL,
1173
                        '_CM_COMAPPROVEUSER'  => XOOPS_COMMENT_APPROVEUSER,
1174
                        '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN,
1175
                    ],
1176
                ];
1177
                $configs[] = [
1178
                    'name'        => 'com_anonpost',
1179
                    'title'       => '_CM_COMANONPOST',
1180
                    'description' => '',
1181
                    'formtype'    => 'yesno',
1182
                    'valuetype'   => 'int',
1183
                    'default'     => 0,
1184
                ];
1185
            }
1186
        } elseif (0 != $module->getVar('hascomments')) {
1187
            $configs = [];
1188
            require XOOPS_ROOT_PATH . '/include/comment_constants.php';
1189
            $configs[] = [
1190
                'name'        => 'com_rule',
1191
                'title'       => '_CM_COMRULES',
1192
                'description' => '',
1193
                'formtype'    => 'select',
1194
                'valuetype'   => 'int',
1195
                'default'     => 1,
1196
                'options'     => [
1197
                    '_CM_COMNOCOM'        => XOOPS_COMMENT_APPROVENONE,
1198
                    '_CM_COMAPPROVEALL'   => XOOPS_COMMENT_APPROVEALL,
1199
                    '_CM_COMAPPROVEUSER'  => XOOPS_COMMENT_APPROVEUSER,
1200
                    '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN,
1201
                ],
1202
            ];
1203
            $configs[] = [
1204
                'name'        => 'com_anonpost',
1205
                'title'       => '_CM_COMANONPOST',
1206
                'description' => '',
1207
                'formtype'    => 'yesno',
1208
                'valuetype'   => 'int',
1209
                'default'     => 0,
1210
            ];
1211
        }
1212
        // RMV-NOTIFY
1213
        if (0 != $module->getVar('hasnotification')) {
1214
            if (empty($configs)) {
1215
                $configs = [];
1216
            }
1217
            // Main notification options
1218
            require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
1219
            require_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
1220
            $options                             = [];
1221
            $options['_NOT_CONFIG_DISABLE']      = XOOPS_NOTIFICATION_DISABLE;
1222
            $options['_NOT_CONFIG_ENABLEBLOCK']  = XOOPS_NOTIFICATION_ENABLEBLOCK;
1223
            $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
1224
            $options['_NOT_CONFIG_ENABLEBOTH']   = XOOPS_NOTIFICATION_ENABLEBOTH;
1225
1226
            //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
1227
            $configs[] = [
1228
                'name'        => 'notification_enabled',
1229
                'title'       => '_NOT_CONFIG_ENABLE',
1230
                'description' => '_NOT_CONFIG_ENABLEDSC',
1231
                'formtype'    => 'select',
1232
                'valuetype'   => 'int',
1233
                'default'     => XOOPS_NOTIFICATION_ENABLEBOTH,
1234
                'options'     => $options,
1235
            ];
1236
            // Event specific notification options
1237
            // FIXME: for some reason the default doesn't come up properly
1238
            //  initially is ok, but not when 'update' module..
1239
            $options    = [];
1240
            $categories = notificationCategoryInfo('', $module->getVar('mid'));
1241
            foreach ($categories as $category) {
1242
                $events = notificationEvents($category['name'], false, $module->getVar('mid'));
1243
                foreach ($events as $event) {
1244
                    if (!empty($event['invisible'])) {
1245
                        continue;
1246
                    }
1247
                    $option_name           = $category['title'] . ' : ' . $event['title'];
1248
                    $option_value          = $category['name'] . '-' . $event['name'];
1249
                    $options[$option_name] = $option_value;
1250
                    //$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);
1251
                }
1252
            }
1253
            $configs[] = [
1254
                'name'        => 'notification_events',
1255
                'title'       => '_NOT_CONFIG_EVENTS',
1256
                'description' => '_NOT_CONFIG_EVENTSDSC',
1257
                'formtype'    => 'select_multi',
1258
                'valuetype'   => 'array',
1259
                'default'     => array_values($options),
1260
                'options'     => $options,
1261
            ];
1262
        }
1263
1264
        if (false !== $configs) {
0 ignored issues
show
introduced by
The condition false !== $configs is always true.
Loading history...
1265
            $msgs[] = 'Adding module config data...';
1266
            /** @var \XoopsConfigHandler $configHandler */
1267
            $configHandler = xoops_getHandler('config');
1268
            $order         = 0;
1269
            foreach ($configs as $config) {
1270
                // only insert ones that have been deleted previously with success
1271
                if (!in_array($config['name'], $config_delng, true)) {
1272
                    $confobj = $configHandler->createConfig();
1273
                    $confobj->setVar('conf_modid', $newmid);
1274
                    $confobj->setVar('conf_catid', 0);
1275
                    $confobj->setVar('conf_name', $config['name']);
1276
                    $confobj->setVar('conf_title', $config['title'], true);
1277
                    $confobj->setVar('conf_desc', $config['description'], true);
1278
                    $confobj->setVar('conf_formtype', $config['formtype']);
1279
                    if (isset($config['valuetype'])) {
1280
                        $confobj->setVar('conf_valuetype', $config['valuetype']);
1281
                    }
1282
                    if (isset($config_old[$config['name']]['value'])
1283
                        && $config_old[$config['name']]['formtype'] == $config['formtype']
1284
                        && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
1285
                        // preserver the old value if any
1286
                        // form type and value type must be the same
1287
                        $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
1288
                    } else {
1289
                        $confobj->setConfValueForInput($config['default'], true);
1290
                        //$confobj->setVar('conf_value', $config['default'], true);
1291
                    }
1292
                    $confobj->setVar('conf_order', $order);
1293
                    $confop_msgs = '';
1294
                    if (isset($config['options']) && is_array($config['options'])) {
1295
                        foreach ($config['options'] as $key => $value) {
1296
                            $confop = $configHandler->createConfigOption();
1297
                            $confop->setVar('confop_name', $key, true);
1298
                            $confop->setVar('confop_value', $value, true);
1299
                            $confobj->setConfOptions($confop);
1300
                            $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> ';
1301
                            unset($confop);
1302
                        }
1303
                    }
1304
                    ++$order;
1305
                    if ($configHandler->insertConfig($confobj)) {
1306
                        //$msgs[] = '&nbsp;&nbsp;Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs;
1307
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs;
1308
                    } else {
1309
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>';
1310
                    }
1311
                    unset($confobj);
1312
                }
1313
            }
1314
            unset($configs);
1315
        }
1316
1317
        // execute module specific update script if any
1318
        $update_script = $module->getInfo('onUpdate');
1319
        if (false !== $update_script && '' != trim((string) $update_script)) {
1320
            require_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim((string) $update_script);
1321
            if (function_exists('xoops_module_update_' . $dirname)) {
1322
                $func = 'xoops_module_update_' . $dirname;
1323
                if (!$func($module, $prev_version)) {
1324
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
1325
                    $msgs   = array_merge($msgs, $module->getErrors());
1326
                } else {
1327
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>';
1328
                    $msgs   += $module->getErrors();
1329
                }
1330
            }
1331
        }
1332
        $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKUPD, '<strong>' . $module->getVar('name', 's') . '</strong>');
1333
        $msgs[] = '</div></div>';
1334
        $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

1334
        $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

1334
        $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...
1335
        //        foreach ($msgs as $msg) {
1336
        //            echo $msg . '<br>';
1337
        //        }
1338
    }
1339
    // Call Footer
1340
    //    xoops_cp_footer();
1341
    // Flush cache files for cpanel GUIs
1342
    //    xoops_load("cpanel", "system");
1343
    //    XoopsSystemCpanel::flush();
1344
    //
1345
    //    require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
1346
    //    $maintenance = new SystemMaintenance();
1347
    //    $folder      = array(1, 3);
1348
    //    $maintenance->CleanCache($folder);
1349
    //Set active modules in cache folder
1350
    //    xoops_setActiveModules();
1351
    //    break;
1352
    //-----------------------------------------------
1353
1354
    $ret = implode('<br>', $msgs);
1355
1356
    return $ret;
1357
}
1358
1359
/**
1360
 * @param $mid
1361
 *
1362
 * @return string
1363
 */
1364
function xoops_module_activate($mid)
1365
{
1366
    $msgs = [];
1367
    // Get module handler
1368
    /** @var \XoopsModuleHandler $moduleHandler */
1369
    $moduleHandler = xoops_getHandler('module');
1370
    $module        = $moduleHandler->get($mid);
1371
    require_once XOOPS_ROOT_PATH . '/class/template.php';
1372
    xoops_template_clear_module_cache($module->getVar('mid'));
1373
    // Display header
1374
    $msgs[] = '<div id="xo-module-log">';
1375
    $msgs   += xoops_module_log_header($module, _AM_SYSTEM_MODULES_ACTIVATE);
1376
    // Change value
1377
    $module->setVar('isactive', 1);
1378
    if (!$moduleHandler->insert($module)) {
1379
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILACT, '<strong>' . $module->getVar('name', 's') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . $module->getHtmlErrors() . '</p>';
1380
    } else {
1381
        $blocks = \XoopsBlock::getByModule($module->getVar('mid'));
0 ignored issues
show
Deprecated Code introduced by
The function XoopsBlock::getByModule() has been deprecated: (This also appears, dead, in XoopsBlockHandler) ( Ignorable by Annotation )

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

1381
        $blocks = /** @scrutinizer ignore-deprecated */ \XoopsBlock::getByModule($module->getVar('mid'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1382
        $bcount = is_countable($blocks) ? count($blocks) : 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $bcount is dead and can be removed.
Loading history...
1383
        foreach ($blocks as $iValue) {
1384
            $iValue->setVar('isactive', 1);
1385
            $iValue->store();
1386
        }
1387
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKACT, '<strong>' . $module->getVar('name', 's') . '</strong>') . '</p></div>';
1388
    }
1389
    //$msgs[] = '</div>';
1390
    $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
1391
    $ret    = implode('<br>', $msgs);
1392
1393
    return $ret;
1394
}
1395
1396
/**
1397
 * @param $mid
1398
 *
1399
 * @return string
1400
 */
1401
function xoops_module_deactivate($mid)
1402
{
1403
    $msgs = [];
1404
    global $xoopsConfig;
1405
    // Get module handler
1406
    /** @var \XoopsModuleHandler $moduleHandler */
1407
    $moduleHandler = xoops_getHandler('module');
1408
    $module        = $moduleHandler->get($mid);
1409
    require_once XOOPS_ROOT_PATH . '/class/template.php';
1410
    xoops_template_clear_module_cache($mid);
1411
    // Display header
1412
    $msgs[] = '<div id="xo-module-log">';
1413
    $msgs   += xoops_module_log_header($module, _AM_SYSTEM_MODULES_DEACTIVATE);
1414
    // Change value
1415
    $module->setVar('isactive', 0);
1416
    if ('system' === $module->getVar('dirname')) {
1417
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
1418
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
1419
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
1420
    } elseif (!$moduleHandler->insert($module)) {
1421
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . $module->getHtmlErrors() . '</p>';
1422
    } else {
1423
        $blocks = \XoopsBlock::getByModule($module->getVar('mid'));
0 ignored issues
show
Deprecated Code introduced by
The function XoopsBlock::getByModule() has been deprecated: (This also appears, dead, in XoopsBlockHandler) ( Ignorable by Annotation )

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

1423
        $blocks = /** @scrutinizer ignore-deprecated */ \XoopsBlock::getByModule($module->getVar('mid'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1424
        $bcount = is_countable($blocks) ? count($blocks) : 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $bcount is dead and can be removed.
Loading history...
1425
        foreach ($blocks as $iValue) {
1426
            $iValue->setVar('isactive', 0);
1427
            $iValue->store();
1428
        }
1429
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
1430
    }
1431
1432
    $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
1433
    $ret    = implode('<br>', $msgs);
1434
1435
    return $ret;
1436
}
1437
1438
/**
1439
 * @param $mid
1440
 * @param $name
1441
 *
1442
 * @return string
1443
 */
1444
function xoops_module_change($mid, $name)
1445
{
1446
    /** @var \XoopsModuleHandler $moduleHandler */
1447
    $moduleHandler = xoops_getHandler('module');
1448
    $module        = $moduleHandler->get($mid);
1449
    $module->setVar('name', $name);
1450
    $myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
1451
    if (!$moduleHandler->insert($module)) {
1452
        $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILORDER, '<strong>' . ($name) . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>';
1453
        $ret .= $module->getHtmlErrors() . '</p>';
1454
1455
        return $ret;
1456
    }
1457
1458
    return '<p>' . sprintf(_AM_SYSTEM_MODULES_OKORDER, '<strong>' . ($name) . '</strong>') . '</p>';
1459
}
1460
1461
/**
1462
 * @param $module
1463
 * @param $title
1464
 *
1465
 * @return array
1466
 */
1467
function xoops_module_log_header($module, $title)
1468
{
1469
    $msgs = [];
1470
    $errs = [];
1471
    $msgs[] = '<div class="header">';
1472
    $msgs[] = $errs[] = '<h4>' . $title . $module->getInfo('name', 's') . '</h4>';
1473
    if (false !== $module->getInfo('image') && '' != trim((string) $module->getInfo('image'))) {
1474
        $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/' . trim((string) $module->getInfo('image')) . '" alt="">';
1475
    }
1476
    $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
1477
    if (false !== $module->getInfo('author') && '' != trim((string) $module->getInfo('author'))) {
1478
        $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim((string) $module->getInfo('author')), ENT_QUOTES | ENT_HTML5);
1479
    }
1480
    $msgs[] = '</div>';
1481
1482
    return $msgs;
1483
}
1484