Passed
Push — master ( b7eab9...5d55c4 )
by Michael
08:30 queued 06:05
created

hasSublinkPermission()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu)
18
 */
19
20
include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
21
22
/**
23
 * @return array|bool
24
 */
25
function b_system_online_show()
26
{
27
    global $xoopsUser, $xoopsModule;
28
    /** @var XoopsOnlineHandler $online_handler */
29
    $online_handler = xoops_getHandler('online');
30
    // set gc probabillity to 10% for now..
31
    if (mt_rand(1, 100) < 11) {
32
        $online_handler->gc(300);
33
    }
34
    if (is_object($xoopsUser)) {
35
        $uid   = $xoopsUser->getVar('uid');
36
        $uname = $xoopsUser->getVar('uname');
37
    } else {
38
        $uid   = 0;
39
        $uname = '';
40
    }
41
    $requestIp = \Xmf\IPAddress::fromRequest()->asReadable();
42
    $requestIp = (false === $requestIp) ? '0.0.0.0' : $requestIp;
0 ignored issues
show
introduced by
The condition false === $requestIp is always false.
Loading history...
43
    if (is_object($xoopsModule)) {
44
        $online_handler->write($uid, $uname, time(), $xoopsModule->getVar('mid'), $requestIp);
45
    } else {
46
        $online_handler->write($uid, $uname, time(), 0, $requestIp);
47
    }
48
    $onlines = $online_handler->getAll();
49
    if (!empty($onlines)) {
50
        $total   = count($onlines);
51
        $block   = [];
52
        $guests  = 0;
53
54
        $member_links = [];
55
        for ($i = 0; $i < $total; ++$i) {
56
            if ($onlines[$i]['online_uid'] > 0) {
57
                $member_links[] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $onlines[$i]['online_uid'] . '" title="' . $onlines[$i]['online_uname'] . '">' . $onlines[$i]['online_uname'] . '</a>';
58
            } else {
59
                ++$guests;
60
            }
61
        }
62
        $members = implode(', ', $member_links);
63
        $block['online_names'] = $members;
64
        $block['online_total'] = sprintf(_ONLINEPHRASE, $total);
65
66
        if (is_object($xoopsModule)) {
67
            $mytotal = $online_handler->getCount(new Criteria('online_module', $xoopsModule->getVar('mid')));
68
            $block['online_total'] .= ' (' . sprintf(_ONLINEPHRASEX, $mytotal, $xoopsModule->getVar('name')) . ')';
69
        }
70
        $block['lang_members']   = _MEMBERS;
71
        $block['lang_guests']    = _GUESTS;
72
        $block['online_names']   = $members;
73
        $block['online_members'] = $total - $guests;
74
        $block['online_guests']  = $guests;
75
        $block['lang_more']      = _MORE;
76
77
        return $block;
78
    } else {
79
        return false;
80
    }
81
}
82
83
/**
84
 * @return array|bool
85
 */
86
function b_system_login_show()
87
{
88
    global $xoopsUser, $xoopsConfig;
89
    if (!$xoopsUser) {
90
        $block                     = [];
91
        $block['lang_username']    = _USERNAME;
92
        $block['unamevalue']       = '';
93
        $block['lang_password']    = _PASSWORD;
94
        $block['lang_login']       = _LOGIN;
95
        $block['lang_lostpass']    = _MB_SYSTEM_LPASS;
96
        $block['lang_registernow'] = _MB_SYSTEM_RNOW;
97
        //$block['lang_rememberme'] = _MB_SYSTEM_REMEMBERME;
98
        if ($xoopsConfig['use_ssl'] == 1 && $xoopsConfig['sslloginlink'] != '') {
99
            $block['sslloginlink'] = "<a href=\"javascript:openWithSelfMain('" . $xoopsConfig['sslloginlink'] . "', 'ssllogin', 300, 200);\">" . _MB_SYSTEM_SECURE . '</a>';
100
        } elseif ($GLOBALS['xoopsConfig']['usercookie']) {
101
            $block['lang_rememberme'] = _MB_SYSTEM_REMEMBERME;
102
        }
103
104
        return $block;
105
    }
106
107
    return false;
108
}
109
110
/**
111
 * @return array
112
 */
113
function b_system_main_show()
114
{
115
    global $xoopsUser, $xoopsModule;
116
    $block               = [];
117
    $block['lang_home']  = _MB_SYSTEM_HOME;
118
    $block['lang_close'] = _CLOSE;
119
120
    /** @var XoopsModuleHandler $module_handler */
121
    $module_handler      = xoops_getHandler('module');
122
    $criteria            = new CriteriaCompo(new Criteria('hasmain', 1));
123
    $criteria->add(new Criteria('isactive', 1));
124
    $criteria->add(new Criteria('weight', 0, '>'));
125
    $modules            = $module_handler->getObjects($criteria, true);
126
127
    /** @var XoopsGroupPermHandler $moduleperm_handler */
128
    $moduleperm_handler = xoops_getHandler('groupperm');
129
    $groups             = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
130
    $read_allowed       = $moduleperm_handler->getItemIds('module_read', $groups);
131
132
    $block['modules'] = [];
133
    foreach (array_keys($modules) as $i) {
134
        if (in_array($i, $read_allowed)) {
135
            $moduleDirname = $modules[$i]->getVar('dirname');
136
            $block['modules'][$i]['name']      = $modules[$i]->getVar('name');
137
            $block['modules'][$i]['directory'] = $moduleDirname;
138
            $block['modules'][$i]['icon'] = $module_handler->getByDirname($moduleDirname)->getInfo('icon') ?: 'fa-solid fa-caret-right';
139
140
            $sublinks                          = $modules[$i]->subLink();
141
            if (!empty($xoopsModule) && $i == $xoopsModule->getVar('mid')) {
142
                $block['modules'][$i]['highlight'] = true;
143
                $block['nothome']                  = true;
144
            }
145
146
            $block['modules'][$i]['sublinks'] = [];
147
            if (count($sublinks) > 0 && !empty($xoopsModule) && $i == $xoopsModule->getVar('mid')) {
148
                foreach ($sublinks as $sublink) {
149
                    if (hasSublinkPermission($sublink, $groups)) {
150
                        // Normalize URL for backward compatibility
151
                        $url = parse_url($sublink['url'], PHP_URL_PATH) ?: $sublink['url'];
152
                    $block['modules'][$i]['sublinks'][] = [
153
                            'id'       => !empty($sublink['id']) ? $sublink['id'] : basename($url), // Fallback
154
                        'name' => $sublink['name'],
155
                            'url'      => $sublink['url'],
156
                            'full_url' => XOOPS_URL . '/modules/' . $moduleDirname . '/' . $sublink['url'],
157
                            'icon'     => !empty($sublink['icon']) ? $sublink['icon'] : 'fa-solid fa-caret-right',
158
                    ];
159
                }
160
                }
161
            }
162
        }
163
    }
164
165
    return $block;
166
}
167
168
function hasSublinkPermission($sublink, $groups)
0 ignored issues
show
Unused Code introduced by
The parameter $sublink is not used and could be removed. ( Ignorable by Annotation )

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

168
function hasSublinkPermission(/** @scrutinizer ignore-unused */ $sublink, $groups)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $groups is not used and could be removed. ( Ignorable by Annotation )

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

168
function hasSublinkPermission($sublink, /** @scrutinizer ignore-unused */ $groups)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
169
{
170
    return true; // Placeholder
171
}
172
173
/**
174
 * @return array
175
 */
176
function b_system_search_show()
177
{
178
    $block                   = [];
179
    $block['lang_search']    = _MB_SYSTEM_SEARCH;
180
    $block['lang_advsearch'] = _MB_SYSTEM_ADVS;
181
182
    return $block;
183
}
184
185
/**
186
 * @return array|bool
187
 */
188
function b_system_user_show()
189
{
190
    global $xoopsUser;
191
    if (!is_object($xoopsUser)) {
192
        return false;
193
    }
194
    $block                       = [];
195
    $block['lang_youraccount']   = _MB_SYSTEM_VACNT;
196
    $block['lang_editaccount']   = _MB_SYSTEM_EACNT;
197
    $block['lang_notifications'] = _MB_SYSTEM_NOTIF;
198
    $block['uid']                = $xoopsUser->getVar('uid');
199
    $block['lang_logout']        = _MB_SYSTEM_LOUT;
200
    $criteria                    = new CriteriaCompo(new Criteria('read_msg', 0));
201
    $criteria->add(new Criteria('to_userid', $xoopsUser->getVar('uid')));
202
203
    $pm_handler = xoops_getHandler('privmessage');
204
205
    $xoopsPreload = XoopsPreload::getInstance();
206
    $xoopsPreload->triggerEvent('system.blocks.system_blocks.usershow', [&$pm_handler]);
207
208
    $block['user_avatar']    = $xoopsUser->getVar('user_avatar');
209
    $block['uname']          = $xoopsUser->getVar('uname');
210
    $block['new_messages']   = $pm_handler->getCount($criteria);
0 ignored issues
show
Bug introduced by
The method getCount() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsGroupHandler or XoopsConfigCategoryHandler or XoopsRankHandler or XoopsBlockHandler or XoopsImageSetHandler. Are you sure you never get one of those? ( Ignorable by Annotation )

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

210
    /** @scrutinizer ignore-call */ 
211
    $block['new_messages']   = $pm_handler->getCount($criteria);
Loading history...
211
    $block['lang_inbox']     = _MB_SYSTEM_INBOX;
212
    $block['lang_adminmenu'] = _MB_SYSTEM_ADMENU;
213
214
    return $block;
215
}
216
217
218
function checkPendingContent($module, $table, $condition, $adminlink, $lang_linkname, &$block, $xoopsDB) {
219
    $module_handler = xoops_getHandler('module');
220
    if (xoops_isActiveModule($module) && $module_handler->getCount(new Criteria('dirname', $module))) {
221
        $sql = "SELECT COUNT(*) FROM " . $xoopsDB->prefix($table);
222
        if ('' !== $condition) {
223
            $sql .= " WHERE $condition";
224
        }
225
        $result = $xoopsDB->query($sql);
226
        if ($xoopsDB->isResultSet($result)) {
227
            [$count] = $xoopsDB->fetchRow($result);
228
            if ((int)$count > 0) {
229
                $block['modules'][] = [
230
                    'adminlink' => XOOPS_URL . $adminlink,
231
                    'pendingnum' => $count, // Use $count directly, no second fetch
232
                    'lang_linkname' => $lang_linkname,
233
                ];
234
            }
235
        }
236
    }
237
}
238
239
// this block is deprecated
240
/**
241
 * @return array
242
 */
243
function b_system_waiting_show()
244
{
245
    global $xoopsUser;
246
    $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
247
    /** @var XoopsModuleHandler $module_handler */
248
    $module_handler = xoops_getHandler('module');
249
    $block = [];
250
251
    // waiting content for news
252
    checkPendingContent('news', 'news_stories', 'published=0',
253
        '/modules/news/admin/index.php?op=newarticle', _MB_SYSTEM_SUBMS, $block, $xoopsDB);
254
255
    // waiting content for mylinks
256
    checkPendingContent('mylinks', 'mylinks_links', 'status=0',
257
        '/modules/mylinks/admin/index.php?op=listNewLinks', _MB_SYSTEM_WLNKS, $block, $xoopsDB);
258
259
    checkPendingContent('mylinks', 'mylinks_broken', '',
260
        '/modules/mylinks/admin/index.php?op=listBrokenLinks', _MB_SYSTEM_BLNK, $block, $xoopsDB);
261
262
    checkPendingContent('mylinks', 'mylinks_mod', '',
263
        '/modules/mylinks/admin/index.php?op=listModReq', _MB_SYSTEM_MLNKS, $block, $xoopsDB);
264
265
    // waiting content for mydownloads
266
    if (xoops_isActiveModule('mydownloads') && $module_handler->getCount(new Criteria('dirname', 'mydownloads'))) {
267
268
        checkPendingContent('mydownloads', 'mydownloads_downloads', 'status=0',
269
            '/modules/mydownloads/admin/index.php?op=listNewDownloads', _MB_SYSTEM_WDLS, $block, $xoopsDB);
270
271
        checkPendingContent('mydownloads', 'mydownloads_broken', '',
272
            '/modules/mydownloads/admin/index.php?op=listBrokenDownloads', _MB_SYSTEM_BFLS, $block, $xoopsDB);
273
274
        checkPendingContent('mydownloads', 'mydownloads_mod', '',
275
            '/modules/mydownloads/admin/index.php?op=listModReq', _MB_SYSTEM_MFLS, $block, $xoopsDB);
276
    }
277
278
    // waiting content for xoops comments
279
    checkPendingContent('system', 'xoopscomments', 'com_status=1',
280
        '/modules/system/admin.php?module=0&amp;status=1&fct=comments', _MB_SYSTEM_COMPEND, $block, $xoopsDB);
281
282
283
    // waiting content for TDMDownloads
284
    checkPendingContent('tdmdownloads', 'tdmdownloads_downloads', 'status=0',
285
        '/modules/tdmdownloads/admin/downloads.php?op=list&statut_display=0', _MB_SYSTEM_TDMDOWNLOADS, $block, $xoopsDB);
286
287
288
    // waiting content for extgallery
289
    checkPendingContent('extgallery', 'extgallery_publicphoto', 'photo_approved=0',
290
        '/modules/extgallery/admin/photo.php#pending-photo', _MB_SYSTEM_EXTGALLERY, $block, $xoopsDB);
291
292
293
    // waiting content for smartsection
294
    checkPendingContent('smartsection', 'smartsection_items', 'status=1',
295
        '/modules/smartsection/admin/item.php', _MB_SYSTEM_SMARTSECTION, $block, $xoopsDB);
296
297
298
    if (count($block) > 0) {
299
        $GLOBALS['xoopsLogger']->addDeprecated(_MB_SYSTEM_WAITING_CONTENT_DEPRECATED);
300
    }
301
    return $block;
302
}
303
304
/**
305
 * @param $options
306
 *
307
 * @return array
308
 */
309
function b_system_info_show($options)
310
{
311
    global $xoopsConfig, $xoopsUser;
312
    $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
313
    $myts    = \MyTextSanitizer::getInstance();
314
    $block   = [];
315
    if (!empty($options[3])) {
316
        $block['showgroups'] = true;
317
        $sql = 'SELECT u.uid, u.uname, u.email, u.user_viewemail, u.user_avatar, g.name AS groupname FROM ' . $xoopsDB->prefix('groups_users_link') . ' l LEFT JOIN ' . $xoopsDB->prefix('users') . ' u ON l.uid=u.uid LEFT JOIN ' . $xoopsDB->prefix('groups') . " g ON l.groupid=g.groupid WHERE g.group_type='Admin' ORDER BY l.groupid, u.uid";
318
        $result = $xoopsDB->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

318
        /** @scrutinizer ignore-call */ 
319
        $result = $xoopsDB->query($sql);
Loading history...
319
        if ($xoopsDB->isResultSet($result) && $xoopsDB->getRowsNum($result) > 0) {
0 ignored issues
show
Bug introduced by
The method getRowsNum() 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

319
        if ($xoopsDB->isResultSet($result) && $xoopsDB->/** @scrutinizer ignore-call */ getRowsNum($result) > 0) {
Loading history...
320
            $prev_caption = '';
321
            $i            = 0;
322
            while (false !== ($userinfo = $xoopsDB->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
The method fetchArray() 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

322
            while (false !== ($userinfo = $xoopsDB->/** @scrutinizer ignore-call */ fetchArray($result))) {
Loading history...
323
                if ($prev_caption != $userinfo['groupname']) {
324
                    $prev_caption                = $userinfo['groupname'];
325
                    $block['groups'][$i]['name'] = $myts->htmlSpecialChars($userinfo['groupname']);
326
                }
327
                if (isset($xoopsUser) && is_object($xoopsUser)) {
328
                    $block['groups'][$i]['users'][] = [
329
                        'id'      => $userinfo['uid'],
330
                        'name'    => $myts->htmlSpecialChars($userinfo['uname']),
331
                        'msglink' => "<a href=\"javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&amp;to_userid=' . $userinfo['uid'] . "','pmlite',565,500);\"><img src=\"" . XOOPS_URL . "/images/icons/pm_small.gif\" border=\"0\" width=\"27\" height=\"17\" alt=\"\" /></a>",
332
                        'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar'],
333
                    ];
334
                } else {
335
                    if ($userinfo['user_viewemail']) {
336
                        $block['groups'][$i]['users'][] = [
337
                            'id'      => $userinfo['uid'],
338
                            'name'    => $myts->htmlSpecialChars($userinfo['uname']),
339
                            'msglink' => '<a href="mailto:' . $userinfo['email'] . '"><img src="' . XOOPS_URL . '/images/icons/em_small.gif" border="0" width="16" height="14" alt="" /></a>',
340
                            'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar'],
341
                        ];
342
                    } else {
343
                        $block['groups'][$i]['users'][] = [
344
                            'id'      => $userinfo['uid'],
345
                            'name'    => $myts->htmlSpecialChars($userinfo['uname']),
346
                            'msglink' => '&nbsp;',
347
                            'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar'],
348
                        ];
349
                    }
350
                }
351
                ++$i;
352
            }
353
        }
354
    } else {
355
        $block['showgroups'] = false;
356
    }
357
    $block['logourl']       = XOOPS_URL . '/images/' . $options[2];
358
    $block['recommendlink'] = "<a href=\"javascript:openWithSelfMain('" . XOOPS_URL . '/misc.php?action=showpopups&amp;type=friend&amp;op=sendform&amp;t=' . time() . "','friend'," . $options[0] . ',' . $options[1] . ")\">" . _MB_SYSTEM_RECO . '</a>';
359
360
    return $block;
361
}
362
363
/**
364
 * @param $options
365
 *
366
 * @return array
367
 */
368
function b_system_newmembers_show($options)
369
{
370
    $block    = [];
371
    $criteria = new CriteriaCompo(new Criteria('level', 0, '>'));
372
    $limit    = (!empty($options[0])) ? $options[0] : 10;
373
    $criteria->setOrder('DESC');
374
    $criteria->setSort('user_regdate');
375
    $criteria->setLimit($limit);
376
    /** @var XoopsMemberHandler $member_handler */
377
    $member_handler = xoops_getHandler('member');
378
    $newmembers     = $member_handler->getUsers($criteria);
379
    $count          = count($newmembers);
380
    for ($i = 0; $i < $count; ++$i) {
381
        if ($options[1] == 1) {
382
            $block['users'][$i]['avatar'] = $newmembers[$i]->getVar('user_avatar') !== 'blank.gif' ? XOOPS_UPLOAD_URL . '/' . $newmembers[$i]->getVar('user_avatar') : '';
383
        } else {
384
            $block['users'][$i]['avatar'] = '';
385
        }
386
        $block['users'][$i]['id']       = $newmembers[$i]->getVar('uid');
387
        $block['users'][$i]['name']     = $newmembers[$i]->getVar('uname');
388
        $block['users'][$i]['joindate'] = formatTimestamp($newmembers[$i]->getVar('user_regdate'), 's');
389
    }
390
391
    return $block;
392
}
393
394
/**
395
 * @param $options
396
 *
397
 * @return array
398
 */
399
function b_system_topposters_show($options)
400
{
401
    $block    = [];
402
    $criteria = new CriteriaCompo(new Criteria('level', 0, '>'));
403
    $criteria->add(new Criteria('posts', 0, '>'));
404
    $limit    = (!empty($options[0])) ? $options[0] : 10;
405
    $size     = count($options);
406
    for ($i = 2; $i < $size; ++$i) {
407
        $criteria->add(new Criteria('rank', $options[$i], '<>'));
408
    }
409
    $criteria->setOrder('DESC');
410
    $criteria->setSort('posts');
411
    $criteria->setLimit($limit);
412
    /** @var XoopsMemberHandler $member_handler */
413
    $member_handler = xoops_getHandler('member');
414
    $topposters     = $member_handler->getUsers($criteria);
415
    $count          = count($topposters);
416
    for ($i = 0; $i < $count; ++$i) {
417
        $block['users'][$i]['rank'] = $i + 1;
418
        if ($options[1] == 1) {
419
            $block['users'][$i]['avatar'] = $topposters[$i]->getVar('user_avatar') !== 'blank.gif' ? XOOPS_UPLOAD_URL . '/' . $topposters[$i]->getVar('user_avatar') : '';
420
        } else {
421
            $block['users'][$i]['avatar'] = '';
422
        }
423
        $block['users'][$i]['id']    = $topposters[$i]->getVar('uid');
424
        $block['users'][$i]['name']  = $topposters[$i]->getVar('uname');
425
        $block['users'][$i]['posts'] = $topposters[$i]->getVar('posts');
426
    }
427
428
    return $block;
429
}
430
431
/**
432
 * @param $options
433
 *
434
 * @return array
435
 */
436
function b_system_comments_show($options)
437
{
438
    $block = [];
439
    include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
440
    $comment_handler = xoops_getHandler('comment');
441
    $criteria        = new CriteriaCompo(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
442
    $criteria->setLimit((int)$options[0]);
443
    $criteria->setSort('com_created');
444
    $criteria->setOrder('DESC');
445
446
    // Check modules permissions
447
    global $xoopsUser;
448
    $moduleperm_handler = xoops_getHandler('groupperm');
449
    $gperm_groupid      = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS];
450
    $criteria1          = new CriteriaCompo(new Criteria('gperm_name', 'module_read', '='));
451
    $criteria1->add(new Criteria('gperm_groupid', '(' . implode(',', $gperm_groupid) . ')', 'IN'));
452
    $perms  = $moduleperm_handler->getObjects($criteria1, true);
0 ignored issues
show
Bug introduced by
The method getObjects() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsRankHandler or XoUserHandler. Are you sure you never get one of those? ( Ignorable by Annotation )

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

452
    /** @scrutinizer ignore-call */ 
453
    $perms  = $moduleperm_handler->getObjects($criteria1, true);
Loading history...
453
    $modIds = [];
454
    foreach ($perms as $item) {
455
        $modIds[] = $item->getVar('gperm_itemid');
456
    }
457
    if (count($modIds) > 0) {
458
        $modIds = array_unique($modIds);
459
        $criteria->add(new Criteria('com_modid', '(' . implode(',', $modIds) . ')', 'IN'));
460
    }
461
    // Check modules permissions
462
463
    $comments       = $comment_handler->getObjects($criteria, true);
464
    /** @var XoopsMemberHandler $member_handler */
465
    $member_handler = xoops_getHandler('member');
466
    /** @var XoopsModuleHandler $module_handler */
467
    $module_handler = xoops_getHandler('module');
468
    $modules        = $module_handler->getObjects(new Criteria('hascomments', 1), true);
469
    $comment_config = [];
470
    foreach (array_keys($comments) as $i) {
471
        $mid           = $comments[$i]->getVar('com_modid');
472
        $com['module'] = '<a href="' . XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname') . '/">' . $modules[$mid]->getVar('name') . '</a>';
473
        if (!isset($comment_config[$mid])) {
474
            $comment_config[$mid] = $modules[$mid]->getInfo('comments');
475
        }
476
        $com['id']    = $i;
477
        $com['title'] = '<a href="' . XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname') . '/' . $comment_config[$mid]['pageName'] . '?' . $comment_config[$mid]['itemName'] . '=' . $comments[$i]->getVar('com_itemid') . '&amp;com_id=' . $i . '&amp;com_rootid=' . $comments[$i]->getVar('com_rootid') . '&amp;' . htmlspecialchars((string) $comments[$i]->getVar('com_exparams'), ENT_QUOTES | ENT_HTML5) . '#comment' . $i . '">' . $comments[$i]->getVar('com_title') . '</a>';
478
        $com['icon']  = htmlspecialchars((string) $comments[$i]->getVar('com_icon'), ENT_QUOTES | ENT_HTML5);
479
        $com['icon']  = ($com['icon'] != '') ? $com['icon'] : 'icon1.gif';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $com seems to be defined later in this foreach loop on line 472. Are you sure it is defined here?
Loading history...
480
        $com['time']  = formatTimestamp($comments[$i]->getVar('com_created'), 'm');
481
        if ($comments[$i]->getVar('com_uid') > 0) {
482
            $poster = $member_handler->getUser($comments[$i]->getVar('com_uid'));
483
            if (is_object($poster)) {
484
                $com['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $comments[$i]->getVar('com_uid') . '">' . $poster->getVar('uname') . '</a>';
485
            } else {
486
                $com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
487
            }
488
        } else {
489
            $com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
490
        }
491
        $block['comments'][] =& $com;
492
        unset($com);
493
    }
494
495
    return $block;
496
}
497
498
// RMV-NOTIFY
499
/**
500
 * @return array|bool
501
 */
502
function b_system_notification_show()
503
{
504
    global $xoopsConfig, $xoopsUser, $xoopsModule;
505
    include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
506
    include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/notification.php';
507
    // Notification must be enabled, and user must be logged in
508
    if (empty($xoopsUser) || !notificationEnabled('block')) {
509
        return false; // do not display block
510
    }
511
    $notification_handler = xoops_getHandler('notification');
512
    // Now build the nested associative array of info to pass
513
    // to the block template.
514
    $block      = [];
515
    $categories =& notificationSubscribableCategoryInfo();
516
    if (empty($categories)) {
517
        return false;
518
    }
519
    foreach ($categories as $category) {
520
        $section['name']        = $category['name'];
521
        $section['title']       = $category['title'];
522
        $section['description'] = $category['description'];
523
        $section['itemid']      = $category['item_id'];
524
        $section['events']      = [];
525
        $subscribed_events      = $notification_handler->getSubscribedEvents($category['name'], $category['item_id'], $xoopsModule->getVar('mid'), $xoopsUser->getVar('uid'));
0 ignored issues
show
Bug introduced by
The method getSubscribedEvents() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsNotificationHandler 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

525
        /** @scrutinizer ignore-call */ 
526
        $subscribed_events      = $notification_handler->getSubscribedEvents($category['name'], $category['item_id'], $xoopsModule->getVar('mid'), $xoopsUser->getVar('uid'));
Loading history...
526
        foreach (notificationEvents($category['name'], true) as $event) {
527
            if (!empty($event['admin_only']) && !$xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
528
                continue;
529
            }
530
            $subscribed                        = in_array($event['name'], $subscribed_events) ? 1 : 0;
531
            $section['events'][$event['name']] = [
532
                'name'        => $event['name'],
533
                'title'       => $event['title'],
534
                'caption'     => $event['caption'],
535
                'description' => $event['description'],
536
                'subscribed'  => $subscribed,
537
            ];
538
        }
539
        $block['categories'][$category['name']] = $section;
540
    }
541
    // Additional form data
542
    $block['target_page'] = 'notification_update.php';
543
    // FIXME: better or more standardized way to do this?
544
    $script_url                  = explode('/', (string) $_SERVER['PHP_SELF']);
545
    $script_name                 = $script_url[count($script_url) - 1];
546
    $block['redirect_script']    = $script_name;
547
    $block['submit_button']      = _NOT_UPDATENOW;
548
    $block['notification_token'] = $GLOBALS['xoopsSecurity']->createToken();
549
550
    return $block;
551
}
552
553
/**
554
 * @param $options
555
 *
556
 * @return string
557
 */
558
function b_system_comments_edit($options)
559
{
560
    $inputtag = "<input type='text' name='options[]' value='" . (int)$options[0] . "' />";
561
    $form     = sprintf(_MB_SYSTEM_DISPLAYC, $inputtag);
562
563
    return $form;
564
}
565
566
/**
567
 * @param $options
568
 *
569
 * @return string
570
 */
571
function b_system_topposters_edit($options)
572
{
573
    include_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
574
    $inputtag = "<input type='text' name='options[]' value='" . (int)$options[0] . "' />";
575
    $form     = sprintf(_MB_SYSTEM_DISPLAY, $inputtag);
576
    $form .= '<br>' . _MB_SYSTEM_DISPLAYA . "&nbsp;<input type='radio' id='options[]' name='options[]' value='1'";
577
    if ($options[1] == 1) {
578
        $form .= " checked";
579
    }
580
    $form .= ' />&nbsp;' . _YES . "<input type='radio' id='options[]' name='options[]' value='0'";
581
    if ($options[1] == 0) {
582
        $form .= " checked";
583
    }
584
    $form .= ' />&nbsp;' . _NO . '';
585
    $form .= '<br>' . _MB_SYSTEM_NODISPGR . "<br><select id='options[]' name='options[]' multiple='multiple'>";
586
    $ranks = XoopsLists::getUserRankList();
587
    $size  = count($options);
588
    foreach ($ranks as $k => $v) {
589
        $sel = '';
590
        for ($i = 2; $i < $size; ++$i) {
591
            if ($k == $options[$i]) {
592
                $sel = " selected";
593
            }
594
        }
595
        $form .= "<option value='$k'$sel>$v</option>";
596
    }
597
    $form .= '</select>';
598
599
    return $form;
600
}
601
602
/**
603
 * @param $options
604
 *
605
 * @return string
606
 */
607
function b_system_newmembers_edit($options)
608
{
609
    $inputtag = "<input type='text' name='options[]' value='" . $options[0] . "' />";
610
    $form     = sprintf(_MB_SYSTEM_DISPLAY, $inputtag);
611
    $form .= '<br>' . _MB_SYSTEM_DISPLAYA . "&nbsp;<input type='radio' id='options[]' name='options[]' value='1'";
612
    if ($options[1] == 1) {
613
        $form .= " checked";
614
    }
615
    $form .= ' />&nbsp;' . _YES . "<input type='radio' id='options[]' name='options[]' value='0'";
616
    if ($options[1] == 0) {
617
        $form .= " checked";
618
    }
619
    $form .= ' />&nbsp;' . _NO . '';
620
621
    return $form;
622
}
623
624
/**
625
 * @param $options
626
 *
627
 * @return string
628
 */
629
function b_system_info_edit($options)
630
{
631
    $form = _MB_SYSTEM_PWWIDTH . '&nbsp;';
632
    $form .= "<input type='text' name='options[]' value='" . $options[0] . "' />";
633
    $form .= '<br>' . _MB_SYSTEM_PWHEIGHT . '&nbsp;';
634
    $form .= "<input type='text' name='options[]' value='" . $options[1] . "' />";
635
    $form .= '<br>' . sprintf(_MB_SYSTEM_LOGO, XOOPS_URL . '/images/') . '&nbsp;';
636
    $form .= "<input type='text' name='options[]' value='" . $options[2] . "' />";
637
    $chk = '';
638
    $form .= '<br>' . _MB_SYSTEM_SADMIN . '&nbsp;';
639
    if ($options[3] == 1) {
640
        $chk = " checked";
641
    }
642
    $form .= "<input type='radio' name='options[3]' value='1'" . $chk . ' />&nbsp;' . _YES . '';
643
    $chk = '';
644
    if ($options[3] == 0) {
645
        $chk = " checked";
646
    }
647
    $form .= "&nbsp;<input type='radio' name='options[3]' value='0'" . $chk . ' />' . _NO . '';
648
649
    return $form;
650
}
651
652
/**
653
 * @param $options
654
 *
655
 * @return array
656
 */
657
function b_system_themes_show($options)
658
{
659
    global $xoopsConfig;
660
    $block = [];
661
662
    if (!isset($options[2])) {
663
        $options[2] = 3; // this was the fixed value pre 2.5.8
664
    }
665
    $selectSize = ($options[0] == 1) ? 1 : (int) $options[2];
666
    $select = new XoopsFormSelect('', 'xoops_theme_select', $xoopsConfig['theme_set'], $selectSize);
667
    foreach ($xoopsConfig['theme_set_allowed'] as $theme) {
668
        $select->addOption($theme, $theme);
669
    }
670
671
    if ($options[0] == 1) {
672
        $themeSelect = '<img vspace="2" id="xoops_theme_img" src="'
673
            . XOOPS_THEME_URL . '/' . $xoopsConfig['theme_set'] . '/shot.gif" '
674
            . ' alt="screenshot" width="' . (int)$options[1] . '" />'
675
            . '<br>';
676
        $select->setExtra(' onchange="showImgSelected(\'xoops_theme_img\', \'xoops_theme_select\', \'themes\', \'/shot.gif\', '
677
            .  '\'' . XOOPS_URL . '\');" ');
678
        $selectTray = new XoopsFormElementTray('');
679
        $selectTray->addElement($select);
680
        $selectTray->addElement(new XoopsFormButton('', 'submit', _GO, 'submit'));
681
        $themeSelect .= '<div class="form-inline">';
682
        $themeSelect .= $selectTray->render();
683
        $themeSelect .= '</div>';
684
    } else {
685
        $select->setExtra(' onchange="submit();" ');
686
        $themeSelect = $select->render();
687
    }
688
689
    $block['theme_select'] = $themeSelect . '<br>(' . sprintf(_MB_SYSTEM_NUMTHEME, '<strong>'
690
            . count($xoopsConfig['theme_set_allowed']) . '</strong>') . ')<br>';
691
692
    return $block;
693
}
694
695
/**
696
 * @param $options
697
 *
698
 * @return string
699
 */
700
function b_system_themes_edit($options)
701
{
702
    $chk  = '';
703
    $form = _MB_SYSTEM_THSHOW . '&nbsp;';
704
    if (!isset($options[2])) {
705
        $options[2] = 3; // this was the fixed value pre 2.5.8
706
    }
707
    if ($options[0] == 1) {
708
        $chk = " checked";
709
    }
710
    $form .= "<input type='radio' name='options[0]' value='1'" . $chk . ' />&nbsp;' . _YES;
711
    $chk = '';
712
    if ($options[0] == 0) {
713
        $chk = ' checked';
714
    }
715
    $form .= '&nbsp;<input type="radio" name="options[0]" value="0"' . $chk . ' />' . _NO;
716
    $form .= '<br>' . _MB_SYSTEM_THWIDTH . '&nbsp;';
717
    $form .= "<input type='text' name='options[1]' value='" . $options[1] . "' />";
718
    $form .= '<br>' . _MB_SYSTEM_BLOCK_HEIGHT . '&nbsp;';
719
    $form .= "<input type='text' name='options[2]' value='" . $options[2] . "' />";
720
721
    return $form;
722
}
723