Passed
Pull Request — master (#1545)
by Michael
18:27 queued 07:19
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
    $module_handler      = xoops_getHandler('module');
120
    $criteria            = new CriteriaCompo(new Criteria('hasmain', 1));
121
    $criteria->add(new Criteria('isactive', 1));
122
    $criteria->add(new Criteria('weight', 0, '>'));
123
    $modules            = $module_handler->getObjects($criteria, 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

123
    /** @scrutinizer ignore-call */ 
124
    $modules            = $module_handler->getObjects($criteria, true);
Loading history...
124
    /** @var XoopsGroupPermHandler $moduleperm_handler */
125
    $moduleperm_handler = xoops_getHandler('groupperm');
126
    $groups             = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
127
    $read_allowed       = $moduleperm_handler->getItemIds('module_read', $groups);
128
    $block['modules'] = [];
129
    foreach (array_keys($modules) as $i) {
130
        if (in_array($i, $read_allowed)) {
131
            $block['modules'][$i]['name']      = $modules[$i]->getVar('name');
132
            $block['modules'][$i]['directory'] = $modules[$i]->getVar('dirname');
133
134
            $icon = $module_handler->getByDirname($modules[$i]->getVar('dirname'))->getInfo('icon');
0 ignored issues
show
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler 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

134
            $icon = $module_handler->/** @scrutinizer ignore-call */ getByDirname($modules[$i]->getVar('dirname'))->getInfo('icon');
Loading history...
135
            $block['modules'][$i]['icon'] = $icon ? $icon : 'fa-solid fa-caret-right';
136
137
            $sublinks                          = $modules[$i]->subLink();
138
            if ((!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) {
139
                $block['modules'][$i]['highlight'] = true;
140
                $block['nothome']                  = true;
141
            }
142
            if ((!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) {
143
                $block['modules'][$i]['highlight'] = true;
144
                $block['nothome']                  = true;
145
            }
146
            if ((count($sublinks) > 0) && (!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) {
147
                foreach ($sublinks as $sublink) {
148
                    $block['modules'][$i]['sublinks'][] = [
149
                        'name' => $sublink['name'],
150
                        'url'  => XOOPS_URL . '/modules/' . $modules[$i]->getVar('dirname') . '/' . $sublink['url'],
151
152
                        'icon' => $sublink['icon'] !== '' ? $sublink['icon'] : 'fa-solid fa-caret-right'
153
                    ];
154
                }
155
            } else {
156
                $block['modules'][$i]['sublinks'] = [];
157
            }
158
        }
159
    }
160
161
    return $block;
162
}
163
164
/**
165
 * @return array
166
 */
167
function b_system_search_show()
168
{
169
    $block                   = [];
170
    $block['lang_search']    = _MB_SYSTEM_SEARCH;
171
    $block['lang_advsearch'] = _MB_SYSTEM_ADVS;
172
173
    return $block;
174
}
175
176
/**
177
 * @return array|bool
178
 */
179
function b_system_user_show()
180
{
181
    global $xoopsUser;
182
    if (!is_object($xoopsUser)) {
183
        return false;
184
    }
185
    $block                       = [];
186
    $block['lang_youraccount']   = _MB_SYSTEM_VACNT;
187
    $block['lang_editaccount']   = _MB_SYSTEM_EACNT;
188
    $block['lang_notifications'] = _MB_SYSTEM_NOTIF;
189
    $block['uid']                = $xoopsUser->getVar('uid');
190
    $block['lang_logout']        = _MB_SYSTEM_LOUT;
191
    $criteria                    = new CriteriaCompo(new Criteria('read_msg', 0));
192
    $criteria->add(new Criteria('to_userid', $xoopsUser->getVar('uid')));
193
194
    $pm_handler = xoops_getHandler('privmessage');
195
196
    $xoopsPreload = XoopsPreload::getInstance();
197
    $xoopsPreload->triggerEvent('system.blocks.system_blocks.usershow', [&$pm_handler]);
198
199
    $block['user_avatar']    = $xoopsUser->getVar('user_avatar');
200
    $block['uname']          = $xoopsUser->getVar('uname');
201
    $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

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

309
        /** @scrutinizer ignore-call */ 
310
        $result = $xoopsDB->query($sql);
Loading history...
310
        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

310
        if ($xoopsDB->isResultSet($result) && $xoopsDB->/** @scrutinizer ignore-call */ getRowsNum($result) > 0) {
Loading history...
311
            $prev_caption = '';
312
            $i            = 0;
313
            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

313
            while (false !== ($userinfo = $xoopsDB->/** @scrutinizer ignore-call */ fetchArray($result))) {
Loading history...
314
                if ($prev_caption != $userinfo['groupname']) {
315
                    $prev_caption                = $userinfo['groupname'];
316
                    $block['groups'][$i]['name'] = $myts->htmlSpecialChars($userinfo['groupname']);
317
                }
318
                if (isset($xoopsUser) && is_object($xoopsUser)) {
319
                    $block['groups'][$i]['users'][] = [
320
                        'id'      => $userinfo['uid'],
321
                        'name'    => $myts->htmlSpecialChars($userinfo['uname']),
322
                        '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>",
323
                        'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar'],
324
                    ];
325
                } else {
326
                    if ($userinfo['user_viewemail']) {
327
                        $block['groups'][$i]['users'][] = [
328
                            'id'      => $userinfo['uid'],
329
                            'name'    => $myts->htmlSpecialChars($userinfo['uname']),
330
                            'msglink' => '<a href="mailto:' . $userinfo['email'] . '"><img src="' . XOOPS_URL . '/images/icons/em_small.gif" border="0" width="16" height="14" alt="" /></a>',
331
                            'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar'],
332
                        ];
333
                    } else {
334
                        $block['groups'][$i]['users'][] = [
335
                            'id'      => $userinfo['uid'],
336
                            'name'    => $myts->htmlSpecialChars($userinfo['uname']),
337
                            'msglink' => '&nbsp;',
338
                            'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar'],
339
                        ];
340
                    }
341
                }
342
                ++$i;
343
            }
344
        }
345
    } else {
346
        $block['showgroups'] = false;
347
    }
348
    $block['logourl']       = XOOPS_URL . '/images/' . $options[2];
349
    $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>';
350
351
    return $block;
352
}
353
354
/**
355
 * @param $options
356
 *
357
 * @return array
358
 */
359
function b_system_newmembers_show($options)
360
{
361
    $block    = [];
362
    $criteria = new CriteriaCompo(new Criteria('level', 0, '>'));
363
    $limit    = (!empty($options[0])) ? $options[0] : 10;
364
    $criteria->setOrder('DESC');
365
    $criteria->setSort('user_regdate');
366
    $criteria->setLimit($limit);
367
    /** @var XoopsMemberHandler $member_handler */
368
    $member_handler = xoops_getHandler('member');
369
    $newmembers     = $member_handler->getUsers($criteria);
370
    $count          = count($newmembers);
371
    for ($i = 0; $i < $count; ++$i) {
372
        if ($options[1] == 1) {
373
            $block['users'][$i]['avatar'] = $newmembers[$i]->getVar('user_avatar') !== 'blank.gif' ? XOOPS_UPLOAD_URL . '/' . $newmembers[$i]->getVar('user_avatar') : '';
374
        } else {
375
            $block['users'][$i]['avatar'] = '';
376
        }
377
        $block['users'][$i]['id']       = $newmembers[$i]->getVar('uid');
378
        $block['users'][$i]['name']     = $newmembers[$i]->getVar('uname');
379
        $block['users'][$i]['joindate'] = formatTimestamp($newmembers[$i]->getVar('user_regdate'), 's');
380
    }
381
382
    return $block;
383
}
384
385
/**
386
 * @param $options
387
 *
388
 * @return array
389
 */
390
function b_system_topposters_show($options)
391
{
392
    $block    = [];
393
    $criteria = new CriteriaCompo(new Criteria('level', 0, '>'));
394
    $criteria->add(new Criteria('posts', 0, '>'));
395
    $limit    = (!empty($options[0])) ? $options[0] : 10;
396
    $size     = count($options);
397
    for ($i = 2; $i < $size; ++$i) {
398
        $criteria->add(new Criteria('rank', $options[$i], '<>'));
399
    }
400
    $criteria->setOrder('DESC');
401
    $criteria->setSort('posts');
402
    $criteria->setLimit($limit);
403
    /** @var XoopsMemberHandler $member_handler */
404
    $member_handler = xoops_getHandler('member');
405
    $topposters     = $member_handler->getUsers($criteria);
406
    $count          = count($topposters);
407
    for ($i = 0; $i < $count; ++$i) {
408
        $block['users'][$i]['rank'] = $i + 1;
409
        if ($options[1] == 1) {
410
            $block['users'][$i]['avatar'] = $topposters[$i]->getVar('user_avatar') !== 'blank.gif' ? XOOPS_UPLOAD_URL . '/' . $topposters[$i]->getVar('user_avatar') : '';
411
        } else {
412
            $block['users'][$i]['avatar'] = '';
413
        }
414
        $block['users'][$i]['id']    = $topposters[$i]->getVar('uid');
415
        $block['users'][$i]['name']  = $topposters[$i]->getVar('uname');
416
        $block['users'][$i]['posts'] = $topposters[$i]->getVar('posts');
417
    }
418
419
    return $block;
420
}
421
422
/**
423
 * @param $options
424
 *
425
 * @return array
426
 */
427
function b_system_comments_show($options)
428
{
429
    $block = [];
430
    include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
431
    $comment_handler = xoops_getHandler('comment');
432
    $criteria        = new CriteriaCompo(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
433
    $criteria->setLimit((int)$options[0]);
434
    $criteria->setSort('com_created');
435
    $criteria->setOrder('DESC');
436
437
    // Check modules permissions
438
    global $xoopsUser;
439
    $moduleperm_handler = xoops_getHandler('groupperm');
440
    $gperm_groupid      = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS];
441
    $criteria1          = new CriteriaCompo(new Criteria('gperm_name', 'module_read', '='));
442
    $criteria1->add(new Criteria('gperm_groupid', '(' . implode(',', $gperm_groupid) . ')', 'IN'));
443
    $perms  = $moduleperm_handler->getObjects($criteria1, true);
444
    $modIds = [];
445
    foreach ($perms as $item) {
446
        $modIds[] = $item->getVar('gperm_itemid');
447
    }
448
    if (count($modIds) > 0) {
449
        $modIds = array_unique($modIds);
450
        $criteria->add(new Criteria('com_modid', '(' . implode(',', $modIds) . ')', 'IN'));
451
    }
452
    // Check modules permissions
453
454
    $comments       = $comment_handler->getObjects($criteria, true);
455
    /** @var XoopsMemberHandler $member_handler */
456
    $member_handler = xoops_getHandler('member');
457
    /** @var XoopsModuleHandler $module_handler */
458
    $module_handler = xoops_getHandler('module');
459
    $modules        = $module_handler->getObjects(new Criteria('hascomments', 1), true);
460
    $comment_config = [];
461
    foreach (array_keys($comments) as $i) {
462
        $mid           = $comments[$i]->getVar('com_modid');
463
        $com['module'] = '<a href="' . XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname') . '/">' . $modules[$mid]->getVar('name') . '</a>';
464
        if (!isset($comment_config[$mid])) {
465
            $comment_config[$mid] = $modules[$mid]->getInfo('comments');
466
        }
467
        $com['id']    = $i;
468
        $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>';
469
        $com['icon']  = htmlspecialchars((string) $comments[$i]->getVar('com_icon'), ENT_QUOTES | ENT_HTML5);
470
        $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 463. Are you sure it is defined here?
Loading history...
471
        $com['time']  = formatTimestamp($comments[$i]->getVar('com_created'), 'm');
472
        if ($comments[$i]->getVar('com_uid') > 0) {
473
            $poster = $member_handler->getUser($comments[$i]->getVar('com_uid'));
474
            if (is_object($poster)) {
475
                $com['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $comments[$i]->getVar('com_uid') . '">' . $poster->getVar('uname') . '</a>';
476
            } else {
477
                $com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
478
            }
479
        } else {
480
            $com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
481
        }
482
        $block['comments'][] =& $com;
483
        unset($com);
484
    }
485
486
    return $block;
487
}
488
489
// RMV-NOTIFY
490
/**
491
 * @return array|bool
492
 */
493
function b_system_notification_show()
494
{
495
    global $xoopsConfig, $xoopsUser, $xoopsModule;
496
    include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
497
    include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/notification.php';
498
    // Notification must be enabled, and user must be logged in
499
    if (empty($xoopsUser) || !notificationEnabled('block')) {
500
        return false; // do not display block
501
    }
502
    $notification_handler = xoops_getHandler('notification');
503
    // Now build the nested associative array of info to pass
504
    // to the block template.
505
    $block      = [];
506
    $categories =& notificationSubscribableCategoryInfo();
507
    if (empty($categories)) {
508
        return false;
509
    }
510
    foreach ($categories as $category) {
511
        $section['name']        = $category['name'];
512
        $section['title']       = $category['title'];
513
        $section['description'] = $category['description'];
514
        $section['itemid']      = $category['item_id'];
515
        $section['events']      = [];
516
        $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

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