Passed
Pull Request — master (#1527)
by Michael
10:17
created

checkPendingContent()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
c 1
b 0
f 0
nc 4
nop 8
dl 0
loc 12
rs 9.6111

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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
65
        if (is_object($xoopsModule)) {
66
            $mytotal = $online_handler->getCount(new Criteria('online_module', $xoopsModule->getVar('mid')));
67
            $block['online_total'] .= ' (' . sprintf(_ONLINEPHRASEX, $mytotal, $xoopsModule->getVar('name')) . ')';
68
        }
69
        $block['lang_members']   = _MEMBERS;
70
        $block['lang_guests']    = _GUESTS;
71
        $block['online_names']   = $members;
72
        $block['online_members'] = $total - $guests;
73
        $block['online_guests']  = $guests;
74
        $block['lang_more']      = _MORE;
75
76
        return $block;
77
    } else {
78
        return false;
79
    }
80
}
81
82
/**
83
 * @return array|bool
84
 */
85
function b_system_login_show()
86
{
87
    global $xoopsUser, $xoopsConfig;
88
    if (!$xoopsUser) {
89
        $block                     = [];
90
        $block['lang_username']    = _USERNAME;
91
        $block['unamevalue']       = '';
92
        $block['lang_password']    = _PASSWORD;
93
        $block['lang_login']       = _LOGIN;
94
        $block['lang_lostpass']    = _MB_SYSTEM_LPASS;
95
        $block['lang_registernow'] = _MB_SYSTEM_RNOW;
96
        //$block['lang_rememberme'] = _MB_SYSTEM_REMEMBERME;
97
        if ($xoopsConfig['use_ssl'] == 1 && $xoopsConfig['sslloginlink'] != '') {
98
            $block['sslloginlink'] = "<a href=\"javascript:openWithSelfMain('" . $xoopsConfig['sslloginlink'] . "', 'ssllogin', 300, 200);\">" . _MB_SYSTEM_SECURE . '</a>';
99
        } elseif ($GLOBALS['xoopsConfig']['usercookie']) {
100
            $block['lang_rememberme'] = _MB_SYSTEM_REMEMBERME;
101
        }
102
103
        return $block;
104
    }
105
106
    return false;
107
}
108
109
/**
110
 * @return array
111
 */
112
function b_system_main_show()
113
{
114
    global $xoopsUser, $xoopsModule;
115
    $block               = [];
116
    $block['lang_home']  = _MB_SYSTEM_HOME;
117
    $block['lang_close'] = _CLOSE;
118
    $module_handler      = xoops_getHandler('module');
119
    $criteria            = new CriteriaCompo(new Criteria('hasmain', 1));
120
    $criteria->add(new Criteria('isactive', 1));
121
    $criteria->add(new Criteria('weight', 0, '>'));
122
    $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

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

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

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

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

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

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