Passed
Push — master ( b5dddf...91d417 )
by Richard
09:12
created

xoops_module_update()   F

Complexity

Conditions 80
Paths 13825

Size

Total Lines 520
Code Lines 351

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 351
dl 0
loc 520
rs 0
c 1
b 0
f 0
cc 80
nc 13825
nop 1

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

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

84
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_INSTALLING . /** @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

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

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

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

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

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

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

427
            /** @scrutinizer ignore-call */ 
428
            $blocks        = XoopsBlock::getByModule($newmid, false);

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

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

Loading history...
428
            $msgs[]        = _AM_SYSTEM_MODULES_GROUP_SETTINGS_ADD;
429
            /* @var  $gperm_handler XoopsGroupPermHandler */
430
            $gperm_handler = xoops_getHandler('groupperm');
431
            foreach ($groups as $mygroup) {
432
                if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) {
433
                    /* @var $mperm XoopsGroupPerm */
434
                    $mperm = $gperm_handler->create();
435
                    $mperm->setVar('gperm_groupid', $mygroup);
436
                    $mperm->setVar('gperm_itemid', $newmid);
437
                    $mperm->setVar('gperm_name', 'module_admin');
438
                    $mperm->setVar('gperm_modid', 1);
439
                    if (!$gperm_handler->insert($mperm)) {
440
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD_ERROR, '<strong>' . $mygroup . '</strong>') . '</span>';
441
                    } else {
442
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD, '<strong>' . $mygroup . '</strong>');
443
                    }
444
                    unset($mperm);
445
                }
446
                $mperm = $gperm_handler->create();
447
                $mperm->setVar('gperm_groupid', $mygroup);
448
                $mperm->setVar('gperm_itemid', $newmid);
449
                $mperm->setVar('gperm_name', 'module_read');
450
                $mperm->setVar('gperm_modid', 1);
451
                if (!$gperm_handler->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

451
                if (!$gperm_handler->insert(/** @scrutinizer ignore-type */ $mperm)) {
Loading history...
452
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, '<strong>' . $mygroup . '</strong>') . '</span>';
453
                } else {
454
                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, '<strong>' . $mygroup . '</strong>');
455
                }
456
                unset($mperm);
457
                foreach ($blocks as $blc) {
458
                    /* @var $bperm XoopsGroupPerm */
459
                    $bperm = $gperm_handler->create();
460
                    $bperm->setVar('gperm_groupid', $mygroup);
461
                    $bperm->setVar('gperm_itemid', $blc);
462
                    $bperm->setVar('gperm_name', 'block_read');
463
                    $bperm->setVar('gperm_modid', 1);
464
                    if (!$gperm_handler->insert($bperm)) {
465
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>';
466
                    } else {
467
                        $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>');
468
                    }
469
                    unset($bperm);
470
                }
471
            }
472
            unset($blocks, $groups);
473
474
            // execute module specific install script if any
475
            $func = "xoops_module_install_{$dirname}";
476
            if (function_exists($func)) {
477
                if (!$lastmsg = $func($module)) {
478
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
479
                } else {
480
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
481
                    if (is_string($lastmsg)) {
482
                        $msgs[] = $lastmsg;
483
                    }
484
                }
485
            }
486
487
            $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKINS, '<strong>' . $module->getVar('name', 's') . '</strong>');
488
            $msgs[] = '</div></div>';
489
490
            $blocks = $module->getInfo('blocks');
491
            $redDevider = '<span class="red bold">  |  </span>';
0 ignored issues
show
Unused Code introduced by
The assignment to $redDevider is dead and can be removed.
Loading history...
492
            $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a> |
493
                        <a href="admin.php?fct=modulesadmin&op=installlist">' . _AM_SYSTEM_MODULES_TOINSTALL . '</a> | ';
494
            $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 string|array 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

494
            $msgs[] = '<br><span class="red bold">' . _AM_SYSTEM_MODULES_MODULE . ' ' . /** @scrutinizer ignore-type */ $module->getInfo('name') . ': </span></div>';
Loading history...
495
            if ($blocks !== false) {
0 ignored issues
show
introduced by
The condition $blocks !== false is always true.
Loading history...
496
                $msgs[] = '<div class="noininstall 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>';
497
            }
498
            $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=preferences&op=showmod&mod=' . $newmid . '">' . _AM_SYSTEM_PREF . '</a>';
499
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a>';
500
501
            $testdataDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata';
502
            if (file_exists($testdataDirectory)) {
503
                $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata/index.php?op=load' . '">' . _AM_SYSTEM_MODULES_INSTALL_TESTDATA . '</a></div>';
504
            } else {
505
                $msgs[] = '</div>';
506
            }
507
508
            $ret = implode('<br>', $msgs);
509
            unset($blocks, $msgs, $errs, $module);
510
511
            return $ret;
512
        } else {
513
            $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . implode('<br>', $errs) . '</p>';
514
            unset($msgs, $errs);
515
516
            return $ret;
517
        }
518
    } else {
519
        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>';
520
    }
521
}
522
523
/**
524
 * @param        $dirname
525
 * @param        $template
526
 * @param string $type
527
 *
528
 * @return string
529
 */
530
function &xoops_module_gettemplate($dirname, $template, $type = '')
531
{
532
    global $xoopsConfig;
533
    $ret = '';
534
    switch ($type) {
535
        case 'blocks':
536
        case 'admin':
537
            $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $type . '/' . $template;
538
            break;
539
        default:
540
            $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $template;
541
            break;
542
    }
543
    if (!file_exists($path)) {
544
        return $ret;
545
    } else {
546
        $lines = file($path);
547
    }
548
    if (!$lines) {
549
        return $ret;
550
    }
551
    $count = count($lines);
552
    for ($i = 0; $i < $count; ++$i) {
553
        $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
554
    }
555
556
    return $ret;
557
}
558
559
/**
560
 * @param $dirname
561
 *
562
 * @return string
563
 */
564
function xoops_module_uninstall($dirname)
565
{
566
    global $xoopsConfig;
567
    $reservedTables = array(
568
        'avatar',
569
        'avatar_users_link',
570
        'block_module_link',
571
        'xoopscomments',
572
        'config',
573
        'configcategory',
574
        'configoption',
575
        'image',
576
        'imagebody',
577
        'imagecategory',
578
        'imgset',
579
        'imgset_tplset_link',
580
        'imgsetimg',
581
        'groups',
582
        'groups_users_link',
583
        'group_permission',
584
        'online',
585
        'bannerclient',
586
        'banner',
587
        'bannerfinish',
588
        'priv_msgs',
589
        'ranks',
590
        'session',
591
        'smiles',
592
        'users',
593
        'newblocks',
594
        'modules',
595
        'tplfile',
596
        'tplset',
597
        'tplsource',
598
        'xoopsnotifications',
599
        'banner',
600
        'bannerclient',
601
        'bannerfinish');
602
    $db             = XoopsDatabaseFactory::getDatabaseConnection();
603
    /* @var $module_handler XoopsModuleHandler */
604
    $module_handler = xoops_getHandler('module');
605
    $module         = $module_handler->getByDirname($dirname);
606
    include_once XOOPS_ROOT_PATH . '/class/template.php';
607
    xoops_template_clear_module_cache($module->getVar('mid'));
608
    if ($module->getVar('dirname') === 'system') {
609
        return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
610
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
611
        return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
612
    } else {
613
        $msgs   = array();
614
        $msgs[] = '<div id="xo-module-log"><div class="header">';
615
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UNINSTALL . $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

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

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

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

Loading history...
Comprehensibility Best Practice introduced by
$errs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $errs = array(); before regardless.
Loading history...
Bug introduced by
Are you sure $module->getInfo('name', 's') of type mixed|false|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

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

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

616
        if ($module->getInfo('image') !== false && trim(/** @scrutinizer ignore-type */ $module->getInfo('image')) != '') {
Loading history...
617
            $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
618
        }
619
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('version') of type string|array 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

619
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . /** @scrutinizer ignore-type */ $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
Loading history...
Bug introduced by
Are you sure $module->getInfo('module_status') of type string|array 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

619
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . /** @scrutinizer ignore-type */ $module->getInfo('module_status');
Loading history...
620
        if ($module->getInfo('author') !== false && trim($module->getInfo('author')) != '') {
621
            $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')));
622
        }
623
        $msgs[] = '</div><div class="logger">';
624
        // Load module specific install script if any
625
        $uninstall_script = $module->getInfo('onUninstall');
626
        if ($uninstall_script && trim($uninstall_script) != '') {
627
            include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($uninstall_script);
628
        }
629
        $func = "xoops_module_pre_uninstall_{$dirname}";
630
        // If pre uninstall function is defined, execute
631
        if (function_exists($func)) {
632
            $result = $func($module);
633
            if (false === $result) {
634
                $errs   = $module->getErrors();
635
                $errs[] = sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func);
636
637
                return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . implode('<br>', $errs) . '</p>';
638
            } else {
639
                $prevErrs = $module->getErrors();
640
                array_unshift($prevErrs, '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>');
641
                $msgs = array_merge($msgs, $prevErrs);
642
            }
643
        }
644
645
        if (false === $module_handler->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

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

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

646
            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_DELETE_ERROR, /** @scrutinizer ignore-type */ $module->getVar('name')) . '</span>';
Loading history...
647
        } else {
648
649
            // delete template files
650
            $tplfile_handler = xoops_getHandler('tplfile');
651
            $templates       = $tplfile_handler->find(null, 'module', $module->getVar('mid'));
0 ignored issues
show
Bug introduced by
The method find() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsTplfileHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

651
            /** @scrutinizer ignore-call */ 
652
            $templates       = $tplfile_handler->find(null, 'module', $module->getVar('mid'));
Loading history...
652
            $tcount          = count($templates);
653
            if ($tcount > 0) {
654
                $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_DELETE;
655
                for ($i = 0; $i < $tcount; ++$i) {
656
                    if (false === $tplfile_handler->delete($templates[$i])) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $tplfile_handler->delete($templates[$i]) targeting XoopsObjectHandler::delete() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
657
                        $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>';
658
                    } else {
659
                        $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>');
660
                    }
661
                }
662
            }
663
            unset($templates);
664
665
            // delete blocks and block tempalte files
666
            $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
667
            if (is_array($block_arr)) {
668
                $bcount = count($block_arr);
669
                $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_DELETE;
670
                for ($i = 0; $i < $bcount; ++$i) {
671
                    if (false === $block_arr[$i]->delete()) {
672
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, '<strong>' . $block_arr[$i]->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block_arr[$i]->getVar('bid') . '</strong>') . '</span>';
673
                    } else {
674
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE, '<strong>' . $block_arr[$i]->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block_arr[$i]->getVar('bid') . '</strong>');
675
                    }
676
                    if ($block_arr[$i]->getVar('template') != '') {
677
                        $templates = $tplfile_handler->find(null, 'block', $block_arr[$i]->getVar('bid'));
678
                        $btcount   = count($templates);
679
                        if ($btcount > 0) {
680
                            for ($j = 0; $j < $btcount; ++$j) {
681
                                if (!$tplfile_handler->delete($templates[$j])) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $tplfile_handler->delete($templates[$j]) targeting XoopsObjectHandler::delete() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
682
                                    $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>';
683
                                } else {
684
                                    $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>');
685
                                }
686
                            }
687
                        }
688
                        unset($templates);
689
                    }
690
                }
691
            }
692
693
            // delete tables used by this module
694
            $modtables = $module->getInfo('tables');
695
            if ($modtables !== false && is_array($modtables)) {
696
                $msgs[] = _AM_SYSTEM_MODULES_DELETE_MOD_TABLES;
697
                foreach ($modtables as $table) {
698
                    // prevent deletion of reserved core tables!
699
                    if (!in_array($table, $reservedTables)) {
700
                        $sql = 'DROP TABLE ' . $db->prefix($table);
701
                        if (!$db->query($sql)) {
0 ignored issues
show
Bug introduced by
The method query() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

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

701
                        if (!$db->/** @scrutinizer ignore-call */ query($sql)) {
Loading history...
702
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_ERROR, '<strong>' . $db->prefix($table) . '</strong>') . '</span>';
703
                        } else {
704
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED, '<strong>' . $db->prefix($table) . '</strong>');
705
                        }
706
                    } else {
707
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TABLE_DROPPED_FAILDED, '<strong>' . $db->prefix($table) . '</strong>') . '</span>';
708
                    }
709
                }
710
            }
711
712
            // delete comments if any
713
            if ($module->getVar('hascomments') != 0) {
714
                $msgs[]          = _AM_SYSTEM_MODULES_COMMENTS_DELETE;
715
                $comment_handler = xoops_getHandler('comment');
716
                if (false === $comment_handler->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

716
                if (false === $comment_handler->/** @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...
717
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_COMMENTS_DELETE_ERROR . '</span>';
718
                } else {
719
                    $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_COMMENTS_DELETED;
720
                }
721
            }
722
723
            // RMV-NOTIFY
724
            // delete notifications if any
725
            if ($module->getVar('hasnotification') != 0) {
726
                $msgs[] = _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETE;
727
                if (false === xoops_notification_deletebymodule($module->getVar('mid'))) {
728
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETE_ERROR . '</span>';
729
                } else {
730
                    $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_NOTIFICATIONS_DELETED;
731
                }
732
            }
733
734
            // delete permissions if any
735
            $gperm_handler = xoops_getHandler('groupperm');
736
            if (false === $gperm_handler->deleteByModule($module->getVar('mid'))) {
737
                $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETE_ERROR . '</span>';
738
            } else {
739
                $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GROUP_PERMS_DELETED;
740
            }
741
742
            // delete module config options if any
743
            if ($module->getVar('hasconfig') != 0 || $module->getVar('hascomments') != 0) {
744
                /* @var $config_handler XoopsConfigHandler  */
745
                $config_handler = xoops_getHandler('config');
746
                $configs        = $config_handler->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

746
                $configs        = $config_handler->getConfigs(new Criteria('conf_modid', /** @scrutinizer ignore-type */ $module->getVar('mid')));
Loading history...
747
                $confcount      = count($configs);
748
                if ($confcount > 0) {
749
                    $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE;
750
                    for ($i = 0; $i < $confcount; ++$i) {
751
                        if (false === $config_handler->deleteConfig($configs[$i])) {
752
                            $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>';
753
                        } else {
754
                            $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>');
755
                        }
756
                    }
757
                }
758
            }
759
760
            // execute module specific install script if any
761
            $func = 'xoops_module_uninstall_' . $dirname;
762
            if (function_exists($func)) {
763
                if (!$func($module)) {
764
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
765
                } else {
766
                    $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>';
767
                }
768
            }
769
            $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKUNINS, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
770
        }
771
        $msgs[] = '</div></div>';
772
        $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
773
        $ret    = implode('<br>', $msgs);
774
775
        return $ret;
776
    }
777
}
778
779
/**
780
 * @param $dirname
781
 * @return string
782
 */
783
function xoops_module_update($dirname)
784
{
785
    global $xoopsUser, $xoopsConfig, $xoopsTpl;
786
    $dirname = trim($dirname);
787
    $xoopsDB =& $GLOBALS['xoopsDB'];
788
789
    $myts = MyTextSanitizer::getInstance();
790
791
    $dirname        = $myts->htmlspecialchars(trim($dirname));
792
    /* @var $module_handler XoopsModuleHandler */
793
    $module_handler = xoops_getHandler('module');
794
    $module         = $module_handler->getByDirname($dirname);
795
    // Save current version for use in the update function
796
    $prev_version = $module->getVar('version');
797
    $clearTpl     = new XoopsTpl();
798
    $clearTpl->clearCache($dirname);
799
800
    // we don't want to change the module name set by admin
801
    $temp_name = $module->getVar('name');
802
    $module->loadInfoAsVar($dirname);
803
    $module->setVar('name', $temp_name);
804
    $module->setVar('last_update', time());
805
    /*
806
        // Call Header
807
        // Define main template
808
        $GLOBALS['xoopsOption']['template_main'] = 'system_header.html';
809
        // Call Header
810
        xoops_cp_header();
811
        // Define Stylesheet
812
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
813
        // Define Breadcrumb and tips
814
        $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath'));
815
        $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_UPDATE);
816
        $xoBreadCrumb->addHelp(system_adminVersion('modulesadmin', 'help') . '#update');https://www.facebook.com/photo.php?v=10154358806675333
817
        $xoBreadCrumb->render();
818
819
        */
820
    if (!$module_handler->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

820
    if (!$module_handler->insert(/** @scrutinizer ignore-type */ $module)) {
Loading history...
821
        echo '<p>Could not update ' . $module->getVar('name') . '</p>';
822
        echo "<br><div class='center'><a href='admin.php?fct=modulesadmin'>" . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
823
    } else {
824
        $newmid = $module->getVar('mid');
825
        $msgs   = array();
826
        $msgs[] = '<div id="xo-module-log"><div class="header">';
827
        $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 mixed|false|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

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

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

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

828
        if ($module->getInfo('image') !== false && trim(/** @scrutinizer ignore-type */ $module->getInfo('image')) != '') {
Loading history...
829
            $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
830
        }
831
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
0 ignored issues
show
Bug introduced by
Are you sure $module->getInfo('version') of type string|array 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

831
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . /** @scrutinizer ignore-type */ $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
Loading history...
Bug introduced by
Are you sure $module->getInfo('module_status') of type string|array 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

831
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . /** @scrutinizer ignore-type */ $module->getInfo('module_status');
Loading history...
832
        if ($module->getInfo('author') !== false && trim($module->getInfo('author')) != '') {
833
            $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . $myts->htmlspecialchars(trim($module->getInfo('author')));
834
        }
835
        $msgs[]          = '</div><div class="logger">';
836
837
        $update_script = $module->getInfo('onUpdate');
838
        if (!empty($update_script) && trim($update_script) != '') {
839
            include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script);
840
        }
841
        // execute module specific update script if any
842
        if (function_exists('xoops_module_pre_update_' . $dirname)) {
843
            $func = 'xoops_module_pre_update_' . $dirname;
844
            if (!$func($module, $prev_version)) {
845
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
846
                $msgs = array_merge($msgs, $module->getErrors());
847
            } else {
848
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>';
849
                $msgs += $module->getErrors();
850
            }
851
        }
852
        $msgs[]          = _AM_SYSTEM_MODULES_MODULE_DATA_UPDATE;
853
        /* @var $tplfile_handler XoopsTplfileHandler */
854
        $tplfile_handler = xoops_getHandler('tplfile');
855
        // irmtfan bug fix: remove codes for delete templates
856
        /*
857
        $deltpl          = $tplfile_handler->find('default', 'module', $module->getVar('mid'));
858
        $delng           = array();
859
        if (is_array($deltpl)) {
860
            // delete template file entry in db
861
            $dcount = count($deltpl);
862
            for ($i = 0; $i < $dcount; $i++) {
863
                if (!$tplfile_handler->delete($deltpl[$i])) {
864
                    $delng[] = $deltpl[$i]->getVar('tpl_file');
865
                }
866
            }
867
        }
868
        */
869
        // irmtfan bug fix: remove codes for delete templates
870
        $templates = $module->getInfo('templates');
871
        if ($templates !== false) {
0 ignored issues
show
introduced by
The condition $templates !== false is always true.
Loading history...
872
            $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_UPDATE;
873
            foreach ($templates as $tpl) {
874
                $tpl['file'] = trim($tpl['file']);
875
                // START irmtfan solve templates duplicate issue
876
                // if (!in_array($tpl['file'], $delng)) { // irmtfan bug fix: remove codes for delete templates
877
                $type = (isset($tpl['type']) ? $tpl['type'] : 'module');
878
                if (preg_match("/\.css$/i", $tpl['file'])) {
879
                    $type = 'css';
880
                }
881
                $criteria = new CriteriaCompo();
882
                $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

882
                $criteria->add(new Criteria('tpl_refid', /** @scrutinizer ignore-type */ $newmid), 'AND');
Loading history...
883
                $criteria->add(new Criteria('tpl_module', $dirname), 'AND');
884
                $criteria->add(new Criteria('tpl_tplset', 'default'), 'AND');
885
                $criteria->add(new Criteria('tpl_file', $tpl['file']), 'AND');
886
                $criteria->add(new Criteria('tpl_type', $type), 'AND');
887
                $tplfiles = $tplfile_handler->getObjects($criteria);
888
889
                $tpldata =& xoops_module_gettemplate($dirname, $tpl['file'], $type);
890
                $tplfile = empty($tplfiles) ? $tplfile_handler->create() : $tplfiles[0];
891
                // END irmtfan solve templates duplicate issue
892
                $tplfile->setVar('tpl_refid', $newmid);
893
                $tplfile->setVar('tpl_lastimported', 0);
894
                $tplfile->setVar('tpl_lastmodified', time());
895
                $tplfile->setVar('tpl_type', $type);
896
                $tplfile->setVar('tpl_source', $tpldata, true);
897
                $tplfile->setVar('tpl_module', $dirname);
898
                $tplfile->setVar('tpl_tplset', 'default');
899
                $tplfile->setVar('tpl_file', $tpl['file'], true);
900
                $tplfile->setVar('tpl_desc', $tpl['description'], true);
901
                if (!$tplfile_handler->insert($tplfile)) {
902
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
903
                } else {
904
                    $newid  = $tplfile->getVar('tpl_id');
905
                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_INSERT_DATA, '<strong>' . $tpl['file'] . '</strong>');
906
                    if ($xoopsConfig['template_set'] === 'default') {
907
                        if (!xoops_template_touch($newid)) {
908
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
909
                        } else {
910
                            $msgs[] = '&nbsp;&nbsp;<span>' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $tpl['file'] . '</strong>') . '</span>';
911
                        }
912
                    }
913
                }
914
                unset($tpldata);
915
                // irmtfan bug fix: remove codes for delete templates
916
                /*
917
                } else {
918
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_OLD_ERROR, "<strong>".$tpl['file']."</strong>").'</span>';
919
                }
920
                */
921
                // irmtfan bug fix: remove codes for delete templates
922
            }
923
        }
924
        $blocks = $module->getInfo('blocks');
925
        $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_REBUILD;
926
        if ($blocks !== false) {
0 ignored issues
show
introduced by
The condition $blocks !== false is always true.
Loading history...
927
            $showfuncs = array();
928
            $funcfiles = array();
929
            foreach ($blocks as $i => $block) {
930
                if (isset($block['show_func']) && $block['show_func'] != '' && isset($block['file']) && $block['file'] != '') {
931
                    $editfunc    = isset($block['edit_func']) ? $block['edit_func'] : '';
932
                    $showfuncs[] = $block['show_func'];
933
                    $funcfiles[] = $block['file'];
934
                    $content = '';
935
                    $template = '';
936
                    if (isset($block['template']) && trim($block['template']) != '') {
937
                        $content =& xoops_module_gettemplate($dirname, $block['template'], 'blocks');
938
                    }
939
                    if (!$content) {
940
                        $content = '';
941
                    } else {
942
                        $template = $block['template'];
943
                    }
944
                    $options = '';
945
                    if (!empty($block['options'])) {
946
                        $options = $block['options'];
947
                    }
948
                    $sql     = 'SELECT bid, name FROM ' . $xoopsDB->prefix('newblocks') . ' WHERE mid=' . $module->getVar('mid') . ' AND func_num=' . $i . " AND show_func='" . addslashes($block['show_func']) . "' AND func_file='" . addslashes($block['file']) . "'";
949
                    $fresult = $xoopsDB->query($sql);
950
                    $fcount  = 0;
951
                    while (false !== ($fblock = $xoopsDB->fetchArray($fresult))) {
952
                        ++$fcount;
953
                        $sql    = 'UPDATE ' . $xoopsDB->prefix('newblocks') . " SET name='" . addslashes($block['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . ' WHERE bid=' . $fblock['bid'];
954
                        $result = $xoopsDB->query($sql);
955
                        if (!$result) {
956
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_UPDATE_ERROR, $fblock['name']);
957
                        } else {
958
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_UPDATE, $fblock['name']) . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $fblock['bid'] . '</strong>');
959
                            if ($template != '') {
960
                                $tplfile = $tplfile_handler->find('default', 'block', $fblock['bid']);
961
                                if (count($tplfile) == 0) {
962
                                    $tplfile_new = $tplfile_handler->create();
963
                                    $tplfile_new->setVar('tpl_module', $dirname);
964
                                    $tplfile_new->setVar('tpl_refid', $fblock['bid']);
965
                                    $tplfile_new->setVar('tpl_tplset', 'default');
966
                                    $tplfile_new->setVar('tpl_file', $block['template'], true);
967
                                    $tplfile_new->setVar('tpl_type', 'block');
968
                                } else {
969
                                    $tplfile_new = $tplfile[0];
970
                                }
971
                                $tplfile_new->setVar('tpl_source', $content, true);
972
                                $tplfile_new->setVar('tpl_desc', $block['description'], true);
973
                                $tplfile_new->setVar('tpl_lastmodified', time());
974
                                $tplfile_new->setVar('tpl_lastimported', 0);
975
                                $tplfile_new->setVar('tpl_file', $block['template'], true); // irmtfan bug fix:  block template file will not updated after update the module
976
                                if (!$tplfile_handler->insert($tplfile_new)) {
977
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
978
                                } else {
979
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE, '<strong>' . $block['template'] . '</strong>');
980
                                    if ($xoopsConfig['template_set'] === 'default') {
981
                                        if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) {
982
                                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
983
                                        } else {
984
                                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>');
985
                                        }
986
                                    }
987
                                }
988
                            }
989
                        }
990
                    }
991
                    if ($fcount == 0) {
992
                        $newbid     = $xoopsDB->genId($xoopsDB->prefix('newblocks') . '_bid_seq');
993
                        $block_name = addslashes($block['name']);
994
                        $block_type = ($module->getVar('dirname') === 'system') ? 'S' : 'M';
995
                        $sql        = 'INSERT INTO ' . $xoopsDB->prefix('newblocks') . ' (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 (' . $newbid . ', ' . $module->getVar('mid') . ', ' . $i . ",'" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', 0, 0, 0, '{$block_type}', 1, '" . addslashes($dirname) . "', '" . addslashes($block['file']) . "', '" . addslashes($block['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', " . time() . ')';
996
                        $result     = $xoopsDB->query($sql);
997
                        if (!$result) {
998
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_CREATE, $block['name']);
999
                            echo $sql;
1000
                        } else {
1001
                            if (empty($newbid)) {
1002
                                $newbid = $xoopsDB->getInsertId();
1003
                            }
1004
                            if ($module->getInfo('hasMain')) {
1005
                                $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS);
1006
                            } else {
1007
                                $groups = array(XOOPS_GROUP_ADMIN);
1008
                            }
1009
                            $gperm_handler = xoops_getHandler('groupperm');
1010
                            foreach ($groups as $mygroup) {
1011
                                $bperm = $gperm_handler->create();
1012
                                $bperm->setVar('gperm_groupid', $mygroup);
1013
                                $bperm->setVar('gperm_itemid', $newbid);
1014
                                $bperm->setVar('gperm_name', 'block_read');
1015
                                $bperm->setVar('gperm_modid', 1);
1016
                                if (!$gperm_handler->insert($bperm)) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $gperm_handler->insert($bperm) targeting XoopsObjectHandler::insert() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1017
                                    $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>';
1018
                                } else {
1019
                                    $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>');
1020
                                }
1021
                            }
1022
1023
                            if ($template != '') {
1024
                                $tplfile = $tplfile_handler->create();
1025
                                $tplfile->setVar('tpl_module', $dirname);
1026
                                $tplfile->setVar('tpl_refid', $newbid);
1027
                                $tplfile->setVar('tpl_source', $content, true);
1028
                                $tplfile->setVar('tpl_tplset', 'default');
1029
                                $tplfile->setVar('tpl_file', $block['template'], true);
1030
                                $tplfile->setVar('tpl_type', 'block');
1031
                                $tplfile->setVar('tpl_lastimported', time());
1032
                                $tplfile->setVar('tpl_lastmodified', time());
1033
                                $tplfile->setVar('tpl_desc', $block['description'], true);
1034
                                if (!$tplfile_handler->insert($tplfile)) {
1035
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>';
1036
                                } else {
1037
                                    $newid  = $tplfile->getVar('tpl_id');
1038
                                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>');
1039
                                    if ($xoopsConfig['template_set'] === 'default') {
1040
                                        if (!xoops_template_touch($newid)) {
1041
                                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, '<strong>' . $block['template'] . '</strong>') . '</span>';
1042
                                        } else {
1043
                                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>');
1044
                                        }
1045
                                    }
1046
                                }
1047
                            }
1048
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>');
1049
                            $sql    = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)';
1050
                            $xoopsDB->query($sql);
1051
                        }
1052
                    }
1053
                }
1054
            }
1055
            $block_arr = XoopsBlock::getByModule($module->getVar('mid'));
1056
            /* @var $block XoopsBlock */
1057
            foreach ($block_arr as $block) {
1058
                if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
1059
                    $sql = sprintf('DELETE FROM %s WHERE bid = %u', $xoopsDB->prefix('newblocks'), $block->getVar('bid'));
1060
                    if (!$xoopsDB->query($sql)) {
1061
                        $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>';
1062
                    } else {
1063
                        $msgs[] = '&nbsp;&nbsp;Block <strong>' . $block->getVar('name') . '</strong> deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>';
1064
                        if ($block->getVar('template') != '') {
1065
                            $tplfiles = $tplfile_handler->find(null, 'block', $block->getVar('bid'));
1066
                            if (is_array($tplfiles)) {
1067
                                $btcount = count($tplfiles);
1068
                                for ($k = 0; $k < $btcount; $k++) {
1069
                                    if (!$tplfile_handler->delete($tplfiles[$k])) {
1070
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_DEPRECATED_ERROR . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>';
1071
                                    } else {
1072
                                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DEPRECATED, '<strong>' . $tplfiles[$k]->getVar('tpl_file') . '</strong>');
1073
                                    }
1074
                                }
1075
                            }
1076
                        }
1077
                    }
1078
                }
1079
            }
1080
        }
1081
1082
        // reset compile_id
1083
1084
        //        $xoTheme  =& $xoopsThemeFactory->createInstance(array('contentTemplate' => @$GLOBALS['xoopsOption']['template_main']));
1085
        //        $xoopsTpl =& $xoTheme->template;
1086
        //        $xoopsTpl->setCompileId();
1087
1088
        $template = $clearTpl;
1089
        $template->setCompileId();
1090
        //        $GLOBALS['xoopsTpl']->setCompileId();
1091
        //        $xoopsTpl->setCompileId();
1092
1093
        // first delete all config entries
1094
        /* @var $config_handler XoopsConfigHandler  */
1095
        $config_handler = xoops_getHandler('config');
1096
        $configs        = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
1097
        $confcount      = count($configs);
1098
        $config_delng   = array();
1099
        if ($confcount > 0) {
1100
            $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE;
1101
            for ($i = 0; $i < $confcount; $i++) {
1102
                if (!$config_handler->deleteConfig($configs[$i])) {
1103
                    $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>';
1104
                    // save the name of config failed to delete for later use
1105
                    $config_delng[] = $configs[$i]->getvar('conf_name');
1106
                } else {
1107
                    $config_old[$configs[$i]->getvar('conf_name')]['value']     = $configs[$i]->getvar('conf_value', 'N');
1108
                    $config_old[$configs[$i]->getvar('conf_name')]['formtype']  = $configs[$i]->getvar('conf_formtype');
1109
                    $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
1110
                    $msgs[]                                                     = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getVar('conf_id') . '</strong>');
1111
                }
1112
            }
1113
        }
1114
1115
        // now reinsert them with the new settings
1116
        $configs = $module->getInfo('config');
1117
        if ($configs !== false) {
0 ignored issues
show
introduced by
The condition $configs !== false is always true.
Loading history...
1118
            if ($module->getVar('hascomments') != 0) {
1119
                include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
1120
                array_push($configs, array(
0 ignored issues
show
Bug introduced by
It seems like $configs can also be of type string; however, parameter $array of array_push() does only seem to accept array, 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

1120
                array_push(/** @scrutinizer ignore-type */ $configs, array(
Loading history...
1121
                    'name'        => 'com_rule',
1122
                    'title'       => '_CM_COMRULES',
1123
                    'description' => '',
1124
                    'formtype'    => 'select',
1125
                    'valuetype'   => 'int',
1126
                    'default'     => 1,
1127
                    'options'     => array(
1128
                        '_CM_COMNOCOM'        => XOOPS_COMMENT_APPROVENONE,
1129
                        '_CM_COMAPPROVEALL'   => XOOPS_COMMENT_APPROVEALL,
1130
                        '_CM_COMAPPROVEUSER'  => XOOPS_COMMENT_APPROVEUSER,
1131
                        '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)));
1132
                array_push($configs, array(
1133
                    'name'        => 'com_anonpost',
1134
                    'title'       => '_CM_COMANONPOST',
1135
                    'description' => '',
1136
                    'formtype'    => 'yesno',
1137
                    'valuetype'   => 'int',
1138
                    'default'     => 0));
1139
            }
1140
        } else {
1141
            if ($module->getVar('hascomments') != 0) {
1142
                $configs = array();
1143
                include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
1144
                $configs[] = array(
1145
                    'name'        => 'com_rule',
1146
                    'title'       => '_CM_COMRULES',
1147
                    'description' => '',
1148
                    'formtype'    => 'select',
1149
                    'valuetype'   => 'int',
1150
                    'default'     => 1,
1151
                    'options'     => array(
1152
                        '_CM_COMNOCOM'        => XOOPS_COMMENT_APPROVENONE,
1153
                        '_CM_COMAPPROVEALL'   => XOOPS_COMMENT_APPROVEALL,
1154
                        '_CM_COMAPPROVEUSER'  => XOOPS_COMMENT_APPROVEUSER,
1155
                        '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN));
1156
                $configs[] = array(
1157
                    'name'        => 'com_anonpost',
1158
                    'title'       => '_CM_COMANONPOST',
1159
                    'description' => '',
1160
                    'formtype'    => 'yesno',
1161
                    'valuetype'   => 'int',
1162
                    'default'     => 0);
1163
            }
1164
        }
1165
        // RMV-NOTIFY
1166
        if ($module->getVar('hasnotification') != 0) {
1167
            if (empty($configs)) {
1168
                $configs = array();
1169
            }
1170
            // Main notification options
1171
            include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
1172
            include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
1173
            $options                             = array();
1174
            $options['_NOT_CONFIG_DISABLE']      = XOOPS_NOTIFICATION_DISABLE;
1175
            $options['_NOT_CONFIG_ENABLEBLOCK']  = XOOPS_NOTIFICATION_ENABLEBLOCK;
1176
            $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE;
1177
            $options['_NOT_CONFIG_ENABLEBOTH']   = XOOPS_NOTIFICATION_ENABLEBOTH;
1178
1179
            //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
1180
            $configs[] = array(
1181
                'name'        => 'notification_enabled',
1182
                'title'       => '_NOT_CONFIG_ENABLE',
1183
                'description' => '_NOT_CONFIG_ENABLEDSC',
1184
                'formtype'    => 'select',
1185
                'valuetype'   => 'int',
1186
                'default'     => XOOPS_NOTIFICATION_ENABLEBOTH,
1187
                'options'     => $options);
1188
            // Event specific notification options
1189
            // FIXME: for some reason the default doesn't come up properly
1190
            //  initially is ok, but not when 'update' module..
1191
            $options    = array();
1192
            $categories =& notificationCategoryInfo('', $module->getVar('mid'));
1193
            foreach ($categories as $category) {
1194
                $events =& notificationEvents($category['name'], false, $module->getVar('mid'));
1195
                foreach ($events as $event) {
1196
                    if (!empty($event['invisible'])) {
1197
                        continue;
1198
                    }
1199
                    $option_name           = $category['title'] . ' : ' . $event['title'];
1200
                    $option_value          = $category['name'] . '-' . $event['name'];
1201
                    $options[$option_name] = $option_value;
1202
                    //$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);
1203
                }
1204
            }
1205
            $configs[] = array(
1206
                'name'        => 'notification_events',
1207
                'title'       => '_NOT_CONFIG_EVENTS',
1208
                'description' => '_NOT_CONFIG_EVENTSDSC',
1209
                'formtype'    => 'select_multi',
1210
                'valuetype'   => 'array',
1211
                'default'     => array_values($options),
1212
                'options'     => $options);
1213
        }
1214
1215
        if ($configs !== false) {
1216
            $msgs[]         = 'Adding module config data...';
1217
            /* @var $config_handler XoopsConfigHandler  */
1218
            $config_handler = xoops_getHandler('config');
1219
            $order          = 0;
1220
            foreach ($configs as $config) {
1221
                // only insert ones that have been deleted previously with success
1222
                if (!in_array($config['name'], $config_delng)) {
1223
                    $confobj = $config_handler->createConfig();
1224
                    $confobj->setVar('conf_modid', $newmid);
1225
                    $confobj->setVar('conf_catid', 0);
1226
                    $confobj->setVar('conf_name', $config['name']);
1227
                    $confobj->setVar('conf_title', $config['title'], true);
1228
                    $confobj->setVar('conf_desc', $config['description'], true);
1229
                    $confobj->setVar('conf_formtype', $config['formtype']);
1230
                    if (isset($config['valuetype'])) {
1231
                        $confobj->setVar('conf_valuetype', $config['valuetype']);
1232
                    }
1233
                    if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
1234
                        // preserver the old value if any
1235
                        // form type and value type must be the same
1236
                        $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
1237
                    } else {
1238
                        $confobj->setConfValueForInput($config['default'], true);
1239
1240
                        //$confobj->setVar('conf_value', $config['default'], true);
1241
                    }
1242
                    $confobj->setVar('conf_order', $order);
1243
                    $confop_msgs = '';
1244
                    if (isset($config['options']) && is_array($config['options'])) {
1245
                        foreach ($config['options'] as $key => $value) {
1246
                            $confop = $config_handler->createConfigOption();
1247
                            $confop->setVar('confop_name', $key, true);
1248
                            $confop->setVar('confop_value', $value, true);
1249
                            $confobj->setConfOptions($confop);
1250
                            $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> ';
1251
                            unset($confop);
1252
                        }
1253
                    }
1254
                    $order++;
1255
                    if (false !== $config_handler->insertConfig($confobj)) {
1256
                        //$msgs[] = '&nbsp;&nbsp;Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs;
1257
                        $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs;
1258
                    } else {
1259
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>';
1260
                    }
1261
                    unset($confobj);
1262
                }
1263
            }
1264
            unset($configs);
1265
        }
1266
1267
        // execute module specific update script if any
1268
        if (function_exists('xoops_module_update_' . $dirname)) {
1269
            $func = 'xoops_module_update_' . $dirname;
1270
            if (!$func($module, $prev_version)) {
1271
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
1272
                $msgs = array_merge($msgs, $module->getErrors());
1273
            } else {
1274
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>';
1275
                $msgs += $module->getErrors();
1276
            }
1277
        }
1278
        $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKUPD, '<strong>' . $module->getVar('name', 's') . '</strong>');
1279
        $msgs[] = '</div></div>';
1280
        $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 string|array 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

1280
        $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 mixed|false|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

1280
        $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...
1281
        //        foreach ($msgs as $msg) {
1282
        //            echo $msg . '<br>';
1283
        //        }
1284
    }
1285
    // Call Footer
1286
    //    xoops_cp_footer();
1287
    // Flush cache files for cpanel GUIs
1288
    //    xoops_load("cpanel", "system");
1289
    //    XoopsSystemCpanel::flush();
1290
    //
1291
    //    require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
1292
    //    $maintenance = new SystemMaintenance();
1293
    //    $folder      = array(1, 3);
1294
    //    $maintenance->CleanCache($folder);
1295
    //Set active modules in cache folder
1296
    //    xoops_setActiveModules();
1297
    //    break;
1298
    //-----------------------------------------------
1299
1300
    $ret = implode('<br>', $msgs);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $msgs does not seem to be defined for all execution paths leading up to this point.
Loading history...
1301
1302
    return $ret;
1303
}
1304
1305
/**
1306
 * @param $mid
1307
 *
1308
 * @return string
1309
 */
1310
function xoops_module_activate($mid)
1311
{
1312
    // Get module handler
1313
1314
    $module_handler = xoops_getHandler('module');
1315
    $module         = $module_handler->get($mid);
1316
    include_once XOOPS_ROOT_PATH . '/class/template.php';
1317
    xoops_template_clear_module_cache($module->getVar('mid'));
1318
    // Display header
1319
    $msgs[] = '<div id="xo-module-log">';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$msgs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $msgs = array(); before regardless.
Loading history...
1320
    $msgs .= xoops_module_log_header($module, _AM_SYSTEM_MODULES_ACTIVATE);
1321
    // Change value
1322
    $module->setVar('isactive', 1);
1323
    if (!$module_handler->insert($module)) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $module_handler->insert($module) targeting XoopsObjectHandler::insert() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1324
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILACT, '<strong>' . $module->getVar('name', 's') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . $module->getHtmlErrors() . '</p>';
1325
    } else {
1326
        $blocks = XoopsBlock::getByModule($module->getVar('mid'));
1327
        $bcount = count($blocks);
1328
        for ($i = 0; $i < $bcount; ++$i) {
1329
            $blocks[$i]->setVar('isactive', 1);
1330
            $blocks[$i]->store();
1331
        }
1332
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKACT, '<strong>' . $module->getVar('name', 's') . '</strong>') . '</p></div>';
1333
    }
1334
    //$msgs[] = '</div>';
1335
    $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
1336
    $ret    = implode('<br>', $msgs);
0 ignored issues
show
Bug introduced by
$msgs of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

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

1336
    $ret    = implode('<br>', /** @scrutinizer ignore-type */ $msgs);
Loading history...
1337
1338
    return $ret;
1339
}
1340
1341
/**
1342
 * @param $mid
1343
 *
1344
 * @return string
1345
 */
1346
function xoops_module_deactivate($mid)
1347
{
1348
    global $xoopsConfig;
1349
    // Get module handler
1350
1351
    $module_handler = xoops_getHandler('module');
1352
    $module         = $module_handler->get($mid);
1353
    include_once XOOPS_ROOT_PATH . '/class/template.php';
1354
    xoops_template_clear_module_cache($mid);
1355
    // Display header
1356
    $msgs[] = '<div id="xo-module-log">';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$msgs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $msgs = array(); before regardless.
Loading history...
1357
    $msgs .= xoops_module_log_header($module, _AM_SYSTEM_MODULES_DEACTIVATE);
1358
    // Change value
1359
    $module->setVar('isactive', 0);
1360
    if ($module->getVar('dirname') === 'system') {
1361
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
1362
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
1363
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
1364
    } else {
1365
        if (!$module_handler->insert($module)) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $module_handler->insert($module) targeting XoopsObjectHandler::insert() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1366
            $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . $module->getHtmlErrors() . '</p>';
1367
        } else {
1368
            $blocks = XoopsBlock::getByModule($module->getVar('mid'));
1369
            $bcount = count($blocks);
1370
            for ($i = 0; $i < $bcount; ++$i) {
1371
                $blocks[$i]->setVar('isactive', 0);
1372
                $blocks[$i]->store();
1373
            }
1374
            $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
1375
        }
1376
    }
1377
    $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
1378
    $ret    = implode('<br>', $msgs);
0 ignored issues
show
Bug introduced by
$msgs of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

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

1378
    $ret    = implode('<br>', /** @scrutinizer ignore-type */ $msgs);
Loading history...
1379
1380
    return $ret;
1381
}
1382
1383
/**
1384
 * @param $mid
1385
 * @param $name
1386
 *
1387
 * @return string
1388
 */
1389
function xoops_module_change($mid, $name)
1390
{
1391
1392
    $module_handler = xoops_getHandler('module');
1393
    $module         = $module_handler->get($mid);
1394
    $module->setVar('name', $name);
1395
    $myts = MyTextSanitizer::getInstance();
1396
    if (!$module_handler->insert($module)) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $module_handler->insert($module) targeting XoopsObjectHandler::insert() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
1397
        $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILORDER, '<strong>' . $myts->stripSlashesGPC($name) . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>';
1398
        $ret .= $module->getHtmlErrors() . '</p>';
1399
1400
        return $ret;
1401
    }
1402
1403
    return '<p>' . sprintf(_AM_SYSTEM_MODULES_OKORDER, '<strong>' . $myts->stripSlashesGPC($name) . '</strong>') . '</p>';
1404
}
1405
1406
/**
1407
 * @param $module
1408
 * @param $title
1409
 *
1410
 * @return array
1411
 */
1412
function xoops_module_log_header($module, $title)
1413
{
1414
    $msgs[] = '<div class="header">';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$msgs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $msgs = array(); before regardless.
Loading history...
1415
    $msgs[] = $errs[] = '<h4>' . $title . $module->getInfo('name', 's') . '</h4>';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$errs was never initialized. Although not strictly required by PHP, it is generally a good practice to add $errs = array(); before regardless.
Loading history...
1416
    if ($module->getInfo('image') !== false && trim($module->getInfo('image')) != '') {
1417
        $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/' . trim($module->getInfo('image')) . '" alt="" />';
1418
    }
1419
    $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
1420
    if ($module->getInfo('author') !== false && trim($module->getInfo('author')) != '') {
1421
        $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')));
1422
    }
1423
    $msgs[] = '</div>';
1424
1425
    return $msgs;
1426
}
1427
1428
/**
1429
 * Clean cache 'xoops_data/caches/smarty_cache'
1430
 *
1431
 * @param array|null $cacheList int[] of cache "ids"
1432
 *                              1 = smarty cache
1433
 *                              2 = smarty compile
1434
 *                              3 = xoops cache
1435
 *                              or null to clear all
1436
 * @return bool
1437
 */
1438
function xoops_module_delayed_clean_cache($cacheList = null)
1439
{
1440
    if (empty($cacheList)) {
1441
        $cacheList = array (1,2,3);
1442
    }
1443
    require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php';
1444
    $maintenance = new SystemMaintenance();
1445
    register_shutdown_function(array($maintenance, 'CleanCache'), $cacheList);
1446
}
1447