b_system_waiting_show()   F
last analyzed

Complexity

Conditions 24
Paths 13122

Size

Total Lines 101
Code Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 24
eloc 67
nc 13122
nop 0
dl 0
loc 101
rs 0
c 0
b 0
f 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 http://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
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 geekwright
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   = array();
52
        $guests  = 0;
53
        $members = '';
54
        for ($i = 0; $i < $total; ++$i) {
55
            if ($onlines[$i]['online_uid'] > 0) {
56
                $members .= ' <a href="' . XOOPS_URL . '/userinfo.php?uid=' . $onlines[$i]['online_uid'] . '" title="' . $onlines[$i]['online_uname'] . '">' . $onlines[$i]['online_uname'] . '</a>,';
57
            } else {
58
                ++$guests;
59
            }
60
        }
61
        $block['online_total'] = sprintf(_ONLINEPHRASE, $total);
62
        if (is_object($xoopsModule)) {
63
            $mytotal = $online_handler->getCount(new Criteria('online_module', $xoopsModule->getVar('mid')));
64
            $block['online_total'] .= ' (' . sprintf(_ONLINEPHRASEX, $mytotal, $xoopsModule->getVar('name')) . ')';
65
        }
66
        $block['lang_members']   = _MEMBERS;
67
        $block['lang_guests']    = _GUESTS;
68
        $block['online_names']   = $members;
69
        $block['online_members'] = $total - $guests;
70
        $block['online_guests']  = $guests;
71
        $block['lang_more']      = _MORE;
72
73
        return $block;
74
    } else {
75
        return false;
76
    }
77
}
78
79
/**
80
 * @return array|bool
81
 */
82
function b_system_login_show()
83
{
84
    global $xoopsUser, $xoopsConfig;
85
    if (!$xoopsUser) {
86
        $block                     = array();
87
        $block['lang_username']    = _USERNAME;
88
        $block['unamevalue']       = '';
89
        $block['lang_password']    = _PASSWORD;
90
        $block['lang_login']       = _LOGIN;
91
        $block['lang_lostpass']    = _MB_SYSTEM_LPASS;
92
        $block['lang_registernow'] = _MB_SYSTEM_RNOW;
93
        //$block['lang_rememberme'] = _MB_SYSTEM_REMEMBERME;
94
        if ($xoopsConfig['use_ssl'] == 1 && $xoopsConfig['sslloginlink'] != '') {
95
            $block['sslloginlink'] = "<a href=\"javascript:openWithSelfMain('" . $xoopsConfig['sslloginlink'] . "', 'ssllogin', 300, 200);\">" . _MB_SYSTEM_SECURE . '</a>';
96
        } elseif ($GLOBALS['xoopsConfig']['usercookie']) {
97
            $block['lang_rememberme'] = _MB_SYSTEM_REMEMBERME;
98
        }
99
100
        return $block;
101
    }
102
103
    return false;
104
}
105
106
/**
107
 * @return array
108
 */
109
function b_system_main_show()
110
{
111
    global $xoopsUser, $xoopsModule;
112
    $block               = array();
113
    $block['lang_home']  = _MB_SYSTEM_HOME;
114
    $block['lang_close'] = _CLOSE;
115
    $module_handler      = xoops_getHandler('module');
116
    $criteria            = new CriteriaCompo(new Criteria('hasmain', 1));
117
    $criteria->add(new Criteria('isactive', 1));
118
    $criteria->add(new Criteria('weight', 0, '>'));
119
    $modules            = $module_handler->getObjects($criteria, true);
0 ignored issues
show
Bug introduced by mambax7
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

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

190
    /** @scrutinizer ignore-call */ 
191
    $block['new_messages']   = $pm_handler->getCount($criteria);
Loading history...
191
    $block['lang_inbox']     = _MB_SYSTEM_INBOX;
192
    $block['lang_adminmenu'] = _MB_SYSTEM_ADMENU;
193
194
    return $block;
195
}
196
197
// this block is deprecated
198
/**
199
 * @return array
200
 */
201
function b_system_waiting_show()
202
{
203
    global $xoopsUser;
204
    $xoopsDB        = XoopsDatabaseFactory::getDatabaseConnection();
205
    /* @var XoopsModuleHandler $module_handler */
206
    $module_handler = xoops_getHandler('module');
207
    $block          = array();
208
209
    // waiting content for news
210
    if (xoops_isActiveModule('news') && $module_handler->getCount(new Criteria('dirname', 'news'))) {
211
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('stories') . ' WHERE published=0');
0 ignored issues
show
Bug introduced by mambax7
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

211
        /** @scrutinizer ignore-call */ 
212
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('stories') . ' WHERE published=0');
Loading history...
212
        if ($result) {
213
            $block['modules'][0]['adminlink'] = XOOPS_URL . '/modules/news/admin/index.php?op=newarticle';
214
            list($block['modules'][0]['pendingnum']) = $xoopsDB->fetchRow($result);
0 ignored issues
show
Bug introduced by beckmi
The method fetchRow() 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

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

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

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

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