Passed
Pull Request — master (#9)
by Michael
03:24
created

b_system_waiting_show()   F

Complexity

Conditions 25
Paths > 20000

Size

Total Lines 104
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 69
dl 0
loc 104
rs 0
c 0
b 0
f 0
cc 25
nc 24786
nop 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2 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
/**
21
 * @return array|bool
22
 */
23
function b_system_online_show()
24
{
25
    global $xoopsUser, $xoopsModule;
26
    $onlineHandler = xoops_getHandler('online');
27
28
    // set gc probabillity to 10% for now..
29
    if (mt_rand(1, 100) < 11) {
30
        $onlineHandler->gc(300);
0 ignored issues
show
Bug introduced by
The method gc() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

30
        $onlineHandler->/** @scrutinizer ignore-call */ 
31
                        gc(300);
Loading history...
31
    }
32
    if (is_object($xoopsUser)) {
33
        $uid   = $xoopsUser->getVar('uid');
34
        $uname = $xoopsUser->getVar('uname');
35
    } else {
36
        $uid   = 0;
37
        $uname = '';
38
    }
39
    if (is_object($xoopsModule)) {
40
        $onlineHandler->write($uid, $uname, time(), $xoopsModule->getVar('mid'), $_SERVER['REMOTE_ADDR']);
0 ignored issues
show
Bug introduced by
The method write() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

40
        $onlineHandler->/** @scrutinizer ignore-call */ 
41
                        write($uid, $uname, time(), $xoopsModule->getVar('mid'), $_SERVER['REMOTE_ADDR']);
Loading history...
41
    } else {
42
        $onlineHandler->write($uid, $uname, time(), 0, $_SERVER['REMOTE_ADDR']);
43
    }
44
    $onlines = $onlineHandler->getAll();
0 ignored issues
show
Bug introduced by
The method getAll() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoUserHandler 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

44
    /** @scrutinizer ignore-call */ 
45
    $onlines = $onlineHandler->getAll();
Loading history...
45
    if (false !== $onlines) {
46
        $total   = count($onlines);
47
        $block   = [];
48
        $guests  = 0;
49
        $members = '';
50
        for ($i = 0; $i < $total; ++$i) {
51
            if ($onlines[$i]['online_uid'] > 0) {
52
                $members .= ' <a href="' . XOOPS_URL . '/userinfo.php?uid=' . $onlines[$i]['online_uid'] . '" title="' . $onlines[$i]['online_uname'] . '">' . $onlines[$i]['online_uname'] . '</a>,';
53
            } else {
54
                ++$guests;
55
            }
56
        }
57
        $block['online_total'] = sprintf(_ONLINEPHRASE, $total);
58
        if (is_object($xoopsModule)) {
59
            $mytotal               = $onlineHandler->getCount(new \Criteria('online_module', $xoopsModule->getVar('mid')));
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 XoopsConfigOptionHandler 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

59
            /** @scrutinizer ignore-call */ 
60
            $mytotal               = $onlineHandler->getCount(new \Criteria('online_module', $xoopsModule->getVar('mid')));
Loading history...
60
            $block['online_total'] .= ' (' . sprintf(_ONLINEPHRASEX, $mytotal, $xoopsModule->getVar('name')) . ')';
61
        }
62
        $block['lang_members']   = _MEMBERS;
63
        $block['lang_guests']    = _GUESTS;
64
        $block['online_names']   = $members;
65
        $block['online_members'] = $total - $guests;
66
        $block['online_guests']  = $guests;
67
        $block['lang_more']      = _MORE;
68
69
        return $block;
70
    }
71
72
    return false;
73
}
74
75
/**
76
 * @return array|bool
77
 */
78
function b_system_login_show()
79
{
80
    global $xoopsUser, $xoopsConfig;
81
    if (!$xoopsUser) {
82
        $block                     = [];
83
        $block['lang_username']    = _USERNAME;
84
        $block['unamevalue']       = '';
85
        $block['lang_password']    = _PASSWORD;
86
        $block['lang_login']       = _LOGIN;
87
        $block['lang_lostpass']    = _MB_SYSTEM_LPASS;
88
        $block['lang_registernow'] = _MB_SYSTEM_RNOW;
89
        //$block['lang_rememberme'] = _MB_SYSTEM_REMEMBERME;
90
        if (1 == $xoopsConfig['use_ssl'] && '' != $xoopsConfig['sslloginlink']) {
91
            $block['sslloginlink'] = "<a href=\"javascript:openWithSelfMain('" . $xoopsConfig['sslloginlink'] . "', 'ssllogin', 300, 200);\">" . _MB_SYSTEM_SECURE . '</a>';
92
        } elseif ($xoopsConfig['usercookie']) {
93
            $block['lang_rememberme'] = _MB_SYSTEM_REMEMBERME;
94
        }
95
96
        return $block;
97
    }
98
99
    return false;
100
}
101
102
/**
103
 * @return array
104
 */
105
function b_system_main_show()
106
{
107
    global $xoopsUser, $xoopsModule;
108
    $block               = [];
109
    $block['lang_home']  = _MB_SYSTEM_HOME;
110
    $block['lang_close'] = _CLOSE;
111
    /** @var \XoopsModuleHandler $moduleHandler */
112
    $moduleHandler = xoops_getHandler('module');
113
    $criteria      = new \CriteriaCompo(new \Criteria('hasmain', 1));
114
    $criteria->add(new \Criteria('isactive', 1));
115
    $criteria->add(new \Criteria('weight', 0, '>'));
116
    $modules          = $moduleHandler->getObjects($criteria, true);
117
    $grouppermHandler = xoops_getHandler('groupperm');
118
    $groups           = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
119
    $read_allowed     = $grouppermHandler->getItemIds('module_read', $groups);
0 ignored issues
show
Bug introduced by
The method getItemIds() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler 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

119
    /** @scrutinizer ignore-call */ 
120
    $read_allowed     = $grouppermHandler->getItemIds('module_read', $groups);
Loading history...
120
    foreach (array_keys($modules) as $i) {
121
        if (in_array($i, $read_allowed)) {
122
            $block['modules'][$i]['name']      = $modules[$i]->getVar('name');
123
            $block['modules'][$i]['directory'] = $modules[$i]->getVar('dirname');
124
            $sublinks                          = $modules[$i]->subLink();
125
            if (!empty($xoopsModule) && ($i == $xoopsModule->getVar('mid'))) {
126
                $block['modules'][$i]['highlight'] = true;
127
                $block['nothome']                  = true;
128
            }
129
            if (!empty($xoopsModule) && ($i == $xoopsModule->getVar('mid'))) {
130
                $block['modules'][$i]['highlight'] = true;
131
                $block['nothome']                  = true;
132
            }
133
            if ((count($sublinks) > 0) && !empty($xoopsModule) && ($i == $xoopsModule->getVar('mid'))) {
134
                foreach ($sublinks as $sublink) {
135
                    $block['modules'][$i]['sublinks'][] = [
136
                        'name' => $sublink['name'],
137
                        'url'  => XOOPS_URL . '/modules/' . $modules[$i]->getVar('dirname') . '/' . $sublink['url'],
138
                    ];
139
                }
140
            } else {
141
                $block['modules'][$i]['sublinks'] = [];
142
            }
143
        }
144
    }
145
146
    return $block;
147
}
148
149
/**
150
 * @return array
151
 */
152
function b_system_search_show()
153
{
154
    $block                   = [];
155
    $block['lang_search']    = _MB_SYSTEM_SEARCH;
156
    $block['lang_advsearch'] = _MB_SYSTEM_ADVS;
157
158
    return $block;
159
}
160
161
/**
162
 * @return array|bool
163
 */
164
function b_system_user_show()
165
{
166
    global $xoopsUser;
167
    if (!is_object($xoopsUser)) {
168
        return false;
169
    }
170
    $block                       = [];
171
    $block['lang_youraccount']   = _MB_SYSTEM_VACNT;
172
    $block['lang_editaccount']   = _MB_SYSTEM_EACNT;
173
    $block['lang_notifications'] = _MB_SYSTEM_NOTIF;
174
    $block['uid']                = $xoopsUser->getVar('uid');
175
    $block['lang_logout']        = _MB_SYSTEM_LOUT;
176
    $criteria                    = new \CriteriaCompo(new \Criteria('read_msg', 0));
177
    $criteria->add(new \Criteria('to_userid', $xoopsUser->getVar('uid')));
178
179
    $pmHandler = xoops_getHandler('privmessage');
180
181
    $xoopsPreload = XoopsPreload::getInstance();
182
    $xoopsPreload->triggerEvent('system.blocks.system_blocks.usershow', [&$pmHandler]);
183
184
    $block['new_messages']   = $pmHandler->getCount($criteria);
185
    $block['lang_inbox']     = _MB_SYSTEM_INBOX;
186
    $block['lang_adminmenu'] = _MB_SYSTEM_ADMENU;
187
188
    return $block;
189
}
190
191
// this block is deprecated
192
/**
193
 * @return array
194
 */
195
function b_system_waiting_show()
196
{
197
    global $xoopsUser;
198
    $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
199
    /** @var \XoopsModuleHandler $moduleHandler */
200
    $moduleHandler = xoops_getHandler('module');
201
    $block         = [];
202
203
    // waiting content for news
204
    if (xoops_isActiveModule('news') && $moduleHandler->getCount(new \Criteria('dirname', 'news'))) {
205
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('news_stories') . ' WHERE published=0');
206
        if ($result) {
207
            $block['modules'][0]['adminlink'] = XOOPS_URL . '/modules/news/admin/index.php?op=newarticle';
208
            list($block['modules'][0]['pendingnum']) = $xoopsDB->fetchRow($result);
209
            $block['modules'][0]['lang_linkname'] = _MB_SYSTEM_SUBMS;
210
        }
211
    }
212
213
    // waiting content for mylinks
214
    if (xoops_isActiveModule('mylinks') && $moduleHandler->getCount(new \Criteria('dirname', 'mylinks'))) {
215
        $mlMod      = $moduleHandler->getByDirname('mylinks');
216
        $tbl_prefix = ($mlMod->version() < 312) ? '' : 'mod_';
0 ignored issues
show
Unused Code introduced by
The assignment to $tbl_prefix is dead and can be removed.
Loading history...
217
        $result     = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix("{$table_prefix}mylinks_links") . ' WHERE STATUS=0');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $table_prefix seems to be never defined.
Loading history...
218
        if ($result) {
219
            $block['modules'][1]['adminlink'] = XOOPS_URL . '/modules/mylinks/admin/main.php?op=listNewLinks';
220
            list($block['modules'][1]['pendingnum']) = $xoopsDB->fetchRow($result);
221
            $block['modules'][1]['lang_linkname'] = _MB_SYSTEM_WLNKS;
222
        }
223
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix("{$table_prefix}mylinks_broken"));
224
        if ($result) {
225
            $block['modules'][2]['adminlink'] = XOOPS_URL . '/modules/mylinks/admin/main.php?op=listBrokenLinks';
226
            list($block['modules'][2]['pendingnum']) = $xoopsDB->fetchRow($result);
227
            $block['modules'][2]['lang_linkname'] = _MB_SYSTEM_BLNK;
228
        }
229
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix("{$table_prefix}mylinks_mod"));
230
        if ($result) {
231
            $block['modules'][3]['adminlink'] = XOOPS_URL . '/modules/mylinks/admin/main.php?op=listModReq';
232
            list($block['modules'][3]['pendingnum']) = $xoopsDB->fetchRow($result);
233
            $block['modules'][3]['lang_linkname'] = _MB_SYSTEM_MLNKS;
234
        }
235
        unset($mlMod, $result);
236
    }
237
238
    // waiting content for mydownloads
239
    if (xoops_isActiveModule('mydownloads') && $moduleHandler->getCount(new \Criteria('dirname', 'mydownloads'))) {
240
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mydownloads_downloads') . ' WHERE status=0');
241
        if ($result) {
242
            $block['modules'][4]['adminlink'] = XOOPS_URL . '/modules/mydownloads/admin/index.php?op=listNewDownloads';
243
            list($block['modules'][4]['pendingnum']) = $xoopsDB->fetchRow($result);
244
            $block['modules'][4]['lang_linkname'] = _MB_SYSTEM_WDLS;
245
        }
246
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mydownloads_broken') . '');
247
        if ($result) {
248
            $block['modules'][5]['adminlink'] = XOOPS_URL . '/modules/mydownloads/admin/index.php?op=listBrokenDownloads';
249
            list($block['modules'][5]['pendingnum']) = $xoopsDB->fetchRow($result);
250
            $block['modules'][5]['lang_linkname'] = _MB_SYSTEM_BFLS;
251
        }
252
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mydownloads_mod') . '');
253
        if ($result) {
254
            $block['modules'][6]['adminlink'] = XOOPS_URL . '/modules/mydownloads/admin/index.php?op=listModReq';
255
            list($block['modules'][6]['pendingnum']) = $xoopsDB->fetchRow($result);
256
            $block['modules'][6]['lang_linkname'] = _MB_SYSTEM_MFLS;
257
        }
258
    }
259
260
    // waiting content for xoops comments
261
    $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('xoopscomments') . ' WHERE com_status=1');
262
    if ($result) {
263
        $block['modules'][7]['adminlink'] = XOOPS_URL . '/modules/system/admin.php?module=0&amp;status=1&amp;fct=comments';
264
        list($block['modules'][7]['pendingnum']) = $xoopsDB->fetchRow($result);
265
        $block['modules'][7]['lang_linkname'] = _MB_SYSTEM_COMPEND;
266
    }
267
268
    // waiting content for TDMDownloads
269
    if (xoops_isActiveModule('TDMdownloads') && $moduleHandler->getCount(new \Criteria('dirname', 'TDMDownloads'))) {
270
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE status=0');
271
        if ($result) {
272
            $block['modules'][8]['adminlink'] = XOOPS_URL . '/modules/TDMDownloads/admin/downloads.php?op=list&statut_display=0';
273
            list($block['modules'][8]['pendingnum']) = $xoopsDB->fetchRow($result);
274
            $block['modules'][8]['lang_linkname'] = _MB_SYSTEM_TDMDOWNLOADS;
275
        }
276
    }
277
278
    // waiting content for extgallery
279
    if (xoops_isActiveModule('extgallery') && $moduleHandler->getCount(new \Criteria('dirname', 'extgallery'))) {
280
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('extgallery_publicphoto') . ' WHERE photo_approved=0');
281
        if ($result) {
282
            $block['modules'][9]['adminlink'] = XOOPS_URL . '/modules/extgallery/admin/photo.php#pending-photo';
283
            list($block['modules'][9]['pendingnum']) = $xoopsDB->fetchRow($result);
284
            $block['modules'][9]['lang_linkname'] = _MB_SYSTEM_EXTGALLERY;
285
        }
286
    }
287
288
    // waiting content for smartsection
289
    if (xoops_isActiveModule('smartsection') && $moduleHandler->getCount(new \Criteria('dirname', 'smartsection'))) {
290
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('smartsection_items') . ' WHERE status=1');
291
        if ($result) {
292
            $block['modules'][10]['adminlink'] = XOOPS_URL . '/modules/smartsection/admin/item.php';
293
            list($block['modules'][10]['pendingnum']) = $xoopsDB->fetchRow($result);
294
            $block['modules'][10]['lang_linkname'] = _MB_SYSTEM_SMARTSECTION;
295
        }
296
    }
297
298
    return $block;
299
}
300
301
/**
302
 * @param $options
303
 * @return array
304
 */
305
function b_system_info_show($options)
306
{
307
    global $xoopsConfig, $xoopsUser;
308
    $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();
309
    $myts    = \MyTextSanitizer::getInstance();
310
    $block   = [];
311
    if (!empty($options[3])) {
312
        $block['showgroups'] = true;
313
        $result              = $xoopsDB->query(
314
            'SELECT u.uid, u.uname, u.email, u.user_viewemail, u.user_avatar, g.name AS groupname FROM '
315
            . $xoopsDB->prefix('groups_users_link')
316
            . ' l LEFT JOIN '
317
            . $xoopsDB->prefix('users')
318
            . ' u ON l.uid=u.uid LEFT JOIN '
319
            . $xoopsDB->prefix('groups')
320
            . " g ON l.groupid=g.groupid WHERE g.group_type='Admin' ORDER BY l.groupid, u.uid"
321
        );
322
        if ($xoopsDB->getRowsNum($result) > 0) {
323
            $prev_caption = '';
324
            $i            = 0;
325
            while (false !== ($userinfo = $xoopsDB->fetchArray($result))) {
326
                if ($prev_caption != $userinfo['groupname']) {
327
                    $prev_caption                = $userinfo['groupname'];
328
                    $block['groups'][$i]['name'] = $myts->htmlSpecialChars($userinfo['groupname']);
329
                }
330
                if (isset($xoopsUser) && is_object($xoopsUser)) {
331
                    $block['groups'][$i]['users'][] = [
332
                        'id'      => $userinfo['uid'],
333
                        'name'    => $myts->htmlSpecialChars($userinfo['uname']),
334
                        'msglink' => "<a href=\"javascript:openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&amp;to_userid=' . $userinfo['uid'] . "','pmlite',450,370);\"><img src=\"" . XOOPS_URL . '/images/icons/pm_small.gif" border="0" width="27" height="17" alt=""></a>',
335
                        'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar'],
336
                    ];
337
                } else {
338
                    if ($userinfo['user_viewemail']) {
339
                        $block['groups'][$i]['users'][] = [
340
                            'id'      => $userinfo['uid'],
341
                            'name'    => $myts->htmlSpecialChars($userinfo['uname']),
342
                            'msglink' => '<a href="mailto:' . $userinfo['email'] . '"><img src="' . XOOPS_URL . '/images/icons/em_small.gif" border="0" width="16" height="14" alt=""></a>',
343
                            'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar'],
344
                        ];
345
                    } else {
346
                        $block['groups'][$i]['users'][] = [
347
                            'id'      => $userinfo['uid'],
348
                            'name'    => $myts->htmlSpecialChars($userinfo['uname']),
349
                            'msglink' => '&nbsp;',
350
                            'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar'],
351
                        ];
352
                    }
353
                }
354
                ++$i;
355
            }
356
        }
357
    } else {
358
        $block['showgroups'] = false;
359
    }
360
    $block['logourl']       = XOOPS_URL . '/images/' . $options[2];
361
    $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>';
362
363
    return $block;
364
}
365
366
/**
367
 * @param $options
368
 * @return array
369
 */
370
function b_system_newmembers_show($options)
371
{
372
    $block    = [];
373
    $criteria = new \CriteriaCompo(new \Criteria('level', 0, '>'));
374
    $limit    = !empty($options[0]) ? $options[0] : 10;
375
    $criteria->setOrder('DESC');
376
    $criteria->setSort('user_regdate');
377
    $criteria->setLimit($limit);
378
    $memberHandler = xoops_getHandler('member');
379
    $newmembers    = $memberHandler->getUsers($criteria);
0 ignored issues
show
Bug introduced by
The method getUsers() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

379
    /** @scrutinizer ignore-call */ 
380
    $newmembers    = $memberHandler->getUsers($criteria);
Loading history...
380
    $count         = count($newmembers);
381
    for ($i = 0; $i < $count; ++$i) {
382
        if (1 == $options[1]) {
383
            $block['users'][$i]['avatar'] = 'blank.gif' !== $newmembers[$i]->getVar('user_avatar') ? XOOPS_UPLOAD_URL . '/' . $newmembers[$i]->getVar('user_avatar') : '';
384
        } else {
385
            $block['users'][$i]['avatar'] = '';
386
        }
387
        $block['users'][$i]['id']       = $newmembers[$i]->getVar('uid');
388
        $block['users'][$i]['name']     = $newmembers[$i]->getVar('uname');
389
        $block['users'][$i]['joindate'] = formatTimestamp($newmembers[$i]->getVar('user_regdate'), 's');
390
    }
391
392
    return $block;
393
}
394
395
/**
396
 * @param $options
397
 * @return array
398
 */
399
function b_system_topposters_show($options)
400
{
401
    $block    = [];
402
    $criteria = new \CriteriaCompo(new \Criteria('level', 0, '>'));
403
    $limit    = !empty($options[0]) ? $options[0] : 10;
404
    $size     = count($options);
405
    for ($i = 2; $i < $size; ++$i) {
406
        $criteria->add(new \Criteria('rank', $options[$i], '<>'));
407
    }
408
    $criteria->setOrder('DESC');
409
    $criteria->setSort('posts');
410
    $criteria->setLimit($limit);
411
    $memberHandler = xoops_getHandler('member');
412
    $topposters    = $memberHandler->getUsers($criteria);
413
    $count         = count($topposters);
414
    for ($i = 0; $i < $count; ++$i) {
415
        $block['users'][$i]['rank'] = $i + 1;
416
        if (1 == $options[1]) {
417
            $block['users'][$i]['avatar'] = 'blank.gif' !== $topposters[$i]->getVar('user_avatar') ? XOOPS_UPLOAD_URL . '/' . $topposters[$i]->getVar('user_avatar') : '';
418
        } else {
419
            $block['users'][$i]['avatar'] = '';
420
        }
421
        $block['users'][$i]['id']    = $topposters[$i]->getVar('uid');
422
        $block['users'][$i]['name']  = $topposters[$i]->getVar('uname');
423
        $block['users'][$i]['posts'] = $topposters[$i]->getVar('posts');
424
    }
425
426
    return $block;
427
}
428
429
/**
430
 * @param $options
431
 * @return array
432
 */
433
function b_system_comments_show($options)
434
{
435
    $block = [];
436
    require_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
437
    $commentHandler = xoops_getHandler('comment');
438
    $criteria       = new \CriteriaCompo(new \Criteria('com_status', XOOPS_COMMENT_ACTIVE));
439
    $criteria->setLimit((int)$options[0]);
440
    $criteria->setSort('com_created');
441
    $criteria->setOrder('DESC');
442
443
    // Check modules permissions
444
    global $xoopsUser;
445
    $grouppermHandler = xoops_getHandler('groupperm');
446
    $gperm_groupid    = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS];
447
    $criteria1        = new \CriteriaCompo(new \Criteria('gperm_name', 'module_read', '='));
448
    $criteria1->add(new \Criteria('gperm_groupid', '(' . implode(',', $gperm_groupid) . ')', 'IN'));
449
    $perms  = $grouppermHandler->getObjects($criteria1, true);
0 ignored issues
show
Bug introduced by
The method getObjects() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsRankHandler or XoUserHandler. Are you sure you never get one of those? ( Ignorable by Annotation )

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

449
    /** @scrutinizer ignore-call */ 
450
    $perms  = $grouppermHandler->getObjects($criteria1, true);
Loading history...
450
    $modIds = [];
451
    foreach ($perms as $item) {
452
        $modIds[] = $item->getVar('gperm_itemid');
453
    }
454
    if (count($modIds) > 0) {
455
        $modIds = array_unique($modIds);
456
        $criteria->add(new \Criteria('com_modid', '(' . implode(',', $modIds) . ')', 'IN'));
457
    }
458
    // Check modules permissions
459
460
    $comments      = $commentHandler->getObjects($criteria, true);
461
    $memberHandler = xoops_getHandler('member');
462
    /** @var \XoopsModuleHandler $moduleHandler */
463
    $moduleHandler  = xoops_getHandler('module');
464
    $modules        = $moduleHandler->getObjects(new \Criteria('hascomments', 1), true);
465
    $comment_config = [];
466
    foreach (array_keys($comments) as $i) {
467
        $mid           = $comments[$i]->getVar('com_modid');
468
        $com['module'] = '<a href="' . XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname') . '/">' . $modules[$mid]->getVar('name') . '</a>';
469
        if (!isset($comment_config[$mid])) {
470
            $comment_config[$mid] = $modules[$mid]->getInfo('comments');
471
        }
472
        $com['id']    = $i;
473
        $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(
474
                'com_rootid'
475
            ) . '&amp;' . htmlspecialchars($comments[$i]->getVar('com_exparams'), ENT_QUOTES | ENT_HTML5) . '#comment' . $i . '">' . $comments[$i]->getVar('com_title') . '</a>';
476
        $com['icon']  = htmlspecialchars($comments[$i]->getVar('com_icon'), ENT_QUOTES);
477
        $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 468. Are you sure it is defined here?
Loading history...
478
        $com['time']  = formatTimestamp($comments[$i]->getVar('com_created'), 'm');
479
        if ($comments[$i]->getVar('com_uid') > 0) {
480
            $poster = $memberHandler->getUser($comments[$i]->getVar('com_uid'));
0 ignored issues
show
Bug introduced by
The method getUser() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsAvatarHandler 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

480
            /** @scrutinizer ignore-call */ 
481
            $poster = $memberHandler->getUser($comments[$i]->getVar('com_uid'));
Loading history...
481
            if (is_object($poster)) {
482
                $com['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $comments[$i]->getVar('com_uid') . '">' . $poster->getVar('uname') . '</a>';
483
            } else {
484
                $com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
485
            }
486
        } else {
487
            $com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
488
        }
489
        $block['comments'][] = &$com;
490
        unset($com);
491
    }
492
493
    return $block;
494
}
495
496
// RMV-NOTIFY
497
/**
498
 * @return array|bool
499
 */
500
function b_system_notification_show()
501
{
502
    global $xoopsConfig, $xoopsUser, $xoopsModule;
503
    require_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
504
    require_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/notification.php';
505
    // Notification must be enabled, and user must be logged in
506
    if (empty($xoopsUser) || !notificationEnabled('block')) {
507
        return false; // do not display block
508
    }
509
    /** @var \XoopsNotificationHandler $notificationHandler */
510
    $notificationHandler = xoops_getHandler('notification');
511
    // Now build the a nested associative array of info to pass
512
    // to the block template.
513
    $block      = [];
514
    $categories = &notificationSubscribableCategoryInfo();
515
    if (empty($categories)) {
516
        return false;
517
    }
518
    foreach ($categories as $category) {
519
        $section['name']        = $category['name'];
520
        $section['title']       = $category['title'];
521
        $section['description'] = $category['description'];
522
        $section['itemid']      = $category['item_id'];
523
        $section['events']      = [];
524
        $subscribed_events      = $notificationHandler->getSubscribedEvents($category['name'], $category['item_id'], $xoopsModule->getVar('mid'), $xoopsUser->getVar('uid'));
525
        foreach (notificationEvents($category['name'], true) as $event) {
526
            if (!empty($event['admin_only']) && !$xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
527
                continue;
528
            }
529
            $subscribed                        = in_array($event['name'], $subscribed_events) ? 1 : 0;
530
            $section['events'][$event['name']] = [
531
                'name'        => $event['name'],
532
                'title'       => $event['title'],
533
                'caption'     => $event['caption'],
534
                'description' => $event['description'],
535
                'subscribed'  => $subscribed,
536
            ];
537
        }
538
        $block['categories'][$category['name']] = $section;
539
    }
540
    // Additional form data
541
    $block['target_page'] = 'notification_update.php';
542
    // FIXME: better or more standardized way to do this?
543
    $script_url                  = explode('/', $_SERVER['SCRIPT_NAME']);
544
    $script_name                 = $script_url[count($script_url) - 1];
545
    $block['redirect_script']    = $script_name;
546
    $block['submit_button']      = _NOT_UPDATENOW;
547
    $block['notification_token'] = $GLOBALS['xoopsSecurity']->createToken();
548
549
    return $block;
550
}
551
552
/**
553
 * @param $options
554
 * @return string
555
 */
556
function b_system_comments_edit($options)
557
{
558
    $inputtag = "<input type='text' name='options[]' value='" . (int)$options[0] . "'>";
559
    $form     = sprintf(_MB_SYSTEM_DISPLAYC, $inputtag);
560
561
    return $form;
562
}
563
564
/**
565
 * @param $options
566
 * @return string
567
 */
568
function b_system_topposters_edit($options)
569
{
570
    require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
571
    $inputtag = "<input type='text' name='options[]' value='" . (int)$options[0] . "'>";
572
    $form     = sprintf(_MB_SYSTEM_DISPLAY, $inputtag);
573
    $form     .= '<br>' . _MB_SYSTEM_DISPLAYA . "&nbsp;<input type='radio' id='options[]' name='options[]' value='1'";
574
    if (1 == $options[1]) {
575
        $form .= ' checked';
576
    }
577
    $form .= '>&nbsp;' . _YES . "<input type='radio' id='options[]' name='options[]' value='0'";
578
    if (0 == $options[1]) {
579
        $form .= ' checked';
580
    }
581
    $form  .= '>&nbsp;' . _NO . '';
582
    $form  .= '<br>' . _MB_SYSTEM_NODISPGR . "<br><select id='options[]' name='options[]' multiple='multiple'>";
583
    $ranks = \XoopsLists::getUserRankList();
584
    $size  = count($options);
585
    foreach ($ranks as $k => $v) {
586
        $sel = '';
587
        for ($i = 2; $i < $size; ++$i) {
588
            if ($k == $options[$i]) {
589
                $sel = ' selected';
590
            }
591
        }
592
        $form .= "<option value='$k'$sel>$v</option>";
593
    }
594
    $form .= '</select>';
595
596
    return $form;
597
}
598
599
/**
600
 * @param $options
601
 * @return string
602
 */
603
function b_system_newmembers_edit($options)
604
{
605
    $inputtag = "<input type='text' name='options[]' value='" . $options[0] . "'>";
606
    $form     = sprintf(_MB_SYSTEM_DISPLAY, $inputtag);
607
    $form     .= '<br>' . _MB_SYSTEM_DISPLAYA . "&nbsp;<input type='radio' id='options[]' name='options[]' value='1'";
608
    if (1 == $options[1]) {
609
        $form .= ' checked';
610
    }
611
    $form .= '>&nbsp;' . _YES . "<input type='radio' id='options[]' name='options[]' value='0'";
612
    if (0 == $options[1]) {
613
        $form .= ' checked';
614
    }
615
    $form .= '>&nbsp;' . _NO . '';
616
617
    return $form;
618
}
619
620
/**
621
 * @param $options
622
 * @return string
623
 */
624
function b_system_info_edit($options)
625
{
626
    $form = _MB_SYSTEM_PWWIDTH . '&nbsp;';
627
    $form .= "<input type='text' name='options[]' value='" . $options[0] . "'>";
628
    $form .= '<br>' . _MB_SYSTEM_PWHEIGHT . '&nbsp;';
629
    $form .= "<input type='text' name='options[]' value='" . $options[1] . "'>";
630
    $form .= '<br>' . sprintf(_MB_SYSTEM_LOGO, XOOPS_URL . '/images/') . '&nbsp;';
631
    $form .= "<input type='text' name='options[]' value='" . $options[2] . "'>";
632
    $chk  = '';
633
    $form .= '<br>' . _MB_SYSTEM_SADMIN . '&nbsp;';
634
    if (1 == $options[3]) {
635
        $chk = ' checked';
636
    }
637
    $form .= "<input type='radio' name='options[3]' value='1'" . $chk . '>&nbsp;' . _YES . '';
638
    $chk  = '';
639
    if (0 == $options[3]) {
640
        $chk = ' checked';
641
    }
642
    $form .= "&nbsp;<input type='radio' name='options[3]' value='0'" . $chk . '>' . _NO . '';
643
644
    return $form;
645
}
646
647
/**
648
 * @param $options
649
 * @return array
650
 */
651
function b_system_themes_show($options)
652
{
653
    global $xoopsConfig;
654
    $theme_options = '';
655
    foreach ($xoopsConfig['theme_set_allowed'] as $theme) {
656
        $theme_options .= '<option value="' . $theme . '"';
657
        if ($theme == $xoopsConfig['theme_set']) {
658
            $theme_options .= ' selected';
659
        }
660
        $theme_options .= '>' . $theme . '</option>';
661
    }
662
    $block = [];
663
    if (1 == $options[0]) {
664
        $block['theme_select'] = '<img vspace="2" id="xoops_theme_img" src="'
665
                                 . XOOPS_THEME_URL
666
                                 . '/'
667
                                 . $xoopsConfig['theme_set']
668
                                 . '/shot.gif" alt="screenshot" width="'
669
                                 . (int)$options[1]
670
                                 . "\"><br><select id=\"xoops_theme_select\" name=\"xoops_theme_select\" onchange=\"showImgSelected('xoops_theme_img', 'xoops_theme_select', 'themes', '/shot.gif', '"
671
                                 . XOOPS_URL
672
                                 . "');\">"
673
                                 . $theme_options
674
                                 . '</select><input type="submit" value="'
675
                                 . _GO
676
                                 . '">';
677
    } else {
678
        $block['theme_select'] = '<select name="xoops_theme_select" onchange="submit();" size="3">' . $theme_options . '</select>';
679
    }
680
681
    $block['theme_select'] .= '<br>(' . sprintf(_MB_SYSTEM_NUMTHEME, '<strong>' . count($xoopsConfig['theme_set_allowed']) . '</strong>') . ')<br>';
682
683
    return $block;
684
}
685
686
/**
687
 * @param $options
688
 * @return string
689
 */
690
function b_system_themes_edit($options)
691
{
692
    $chk  = '';
693
    $form = _MB_SYSTEM_THSHOW . '&nbsp;';
694
    if (1 == $options[0]) {
695
        $chk = ' checked';
696
    }
697
    $form .= "<input type='radio' name='options[0]' value='1'" . $chk . '>&nbsp;' . _YES;
698
    $chk  = '';
699
    if (0 == $options[0]) {
700
        $chk = ' checked';
701
    }
702
    $form .= '&nbsp;<input type="radio" name="options[0]" value="0"' . $chk . '>' . _NO;
703
    $form .= '<br>' . _MB_SYSTEM_THWIDTH . '&nbsp;';
704
    $form .= "<input type='text' name='options[1]' value='" . $options[1] . "'>";
705
706
    return $form;
707
}
708