Passed
Push — master ( a10285...60a772 )
by Michael
04:04 queued 01:37
created

b_system_waiting_show()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 59
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
cc 4
eloc 30
c 4
b 1
f 0
nc 4
nop 0
dl 0
loc 59
rs 9.44

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2.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
            $sublinks                          = $modules[$i]->subLink();
134
            if ((!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) {
135
                $block['modules'][$i]['highlight'] = true;
136
                $block['nothome']                  = true;
137
            }
138
            if ((!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) {
139
                $block['modules'][$i]['highlight'] = true;
140
                $block['nothome']                  = true;
141
            }
142
            if ((count($sublinks) > 0) && (!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) {
143
                foreach ($sublinks as $sublink) {
144
                    $block['modules'][$i]['sublinks'][] = [
145
                        'name' => $sublink['name'],
146
                        'url'  => XOOPS_URL . '/modules/' . $modules[$i]->getVar('dirname') . '/' . $sublink['url'],
147
                    ];
148
                }
149
            } else {
150
                $block['modules'][$i]['sublinks'] = [];
151
            }
152
        }
153
    }
154
155
    return $block;
156
}
157
158
/**
159
 * @return array
160
 */
161
function b_system_search_show()
162
{
163
    $block                   = [];
164
    $block['lang_search']    = _MB_SYSTEM_SEARCH;
165
    $block['lang_advsearch'] = _MB_SYSTEM_ADVS;
166
167
    return $block;
168
}
169
170
/**
171
 * @return array|bool
172
 */
173
function b_system_user_show()
174
{
175
    global $xoopsUser;
176
    if (!is_object($xoopsUser)) {
177
        return false;
178
    }
179
    $block                       = [];
180
    $block['lang_youraccount']   = _MB_SYSTEM_VACNT;
181
    $block['lang_editaccount']   = _MB_SYSTEM_EACNT;
182
    $block['lang_notifications'] = _MB_SYSTEM_NOTIF;
183
    $block['uid']                = $xoopsUser->getVar('uid');
184
    $block['lang_logout']        = _MB_SYSTEM_LOUT;
185
    $criteria                    = new CriteriaCompo(new Criteria('read_msg', 0));
186
    $criteria->add(new Criteria('to_userid', $xoopsUser->getVar('uid')));
187
188
    $pm_handler = xoops_getHandler('privmessage');
189
190
    $xoopsPreload = XoopsPreload::getInstance();
191
    $xoopsPreload->triggerEvent('system.blocks.system_blocks.usershow', [&$pm_handler]);
192
193
    $block['user_avatar']    = $xoopsUser->getVar('user_avatar');
194
    $block['uname']          = $xoopsUser->getVar('uname');
195
    $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

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

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

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

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

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