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 (http://www.gnu.org/licenses/gpl-2.0.html)
15 * @package
16 * @since
17 * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu)
18 */
19
20include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
21
22/**
23 * @return array|bool
24 */
25function 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;
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 */
82function 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 */
109function 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);
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    foreach (array_keys($modules) as $i) {
125        if (in_array($i, $read_allowed)) {
126            $block['modules'][$i]['name']      = $modules[$i]->getVar('name');
127            $block['modules'][$i]['directory'] = $modules[$i]->getVar('dirname');
128            $sublinks                          = $modules[$i]->subLink();
129            if ((!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) {
130                $block['modules'][$i]['highlight'] = true;
131                $block['nothome']                  = true;
132            }
133            if ((!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) {
134                $block['modules'][$i]['highlight'] = true;
135                $block['nothome']                  = true;
136            }
137            if ((count($sublinks) > 0) && (!empty($xoopsModule)) && ($i == $xoopsModule->getVar('mid'))) {
138                foreach ($sublinks as $sublink) {
139                    $block['modules'][$i]['sublinks'][] = array(
140                        'name' => $sublink['name'],
141                        'url'  => XOOPS_URL . '/modules/' . $modules[$i]->getVar('dirname') . '/' . $sublink['url']);
142                }
143            } else {
144                $block['modules'][$i]['sublinks'] = array();
145            }
146        }
147    }
148
149    return $block;
150}
151
152/**
153 * @return array
154 */
155function b_system_search_show()
156{
157    $block                   = array();
158    $block['lang_search']    = _MB_SYSTEM_SEARCH;
159    $block['lang_advsearch'] = _MB_SYSTEM_ADVS;
160
161    return $block;
162}
163
164/**
165 * @return array|bool
166 */
167function b_system_user_show()
168{
169    global $xoopsUser;
170    if (!is_object($xoopsUser)) {
171        return false;
172    }
173    $block                       = array();
174    $block['lang_youraccount']   = _MB_SYSTEM_VACNT;
175    $block['lang_editaccount']   = _MB_SYSTEM_EACNT;
176    $block['lang_notifications'] = _MB_SYSTEM_NOTIF;
177    $block['uid']                = $xoopsUser->getVar('uid');
178    $block['lang_logout']        = _MB_SYSTEM_LOUT;
179    $criteria                    = new CriteriaCompo(new Criteria('read_msg', 0));
180    $criteria->add(new Criteria('to_userid', $xoopsUser->getVar('uid')));
181
182    $pm_handler = xoops_getHandler('privmessage');
183
184    $xoopsPreload = XoopsPreload::getInstance();
185    $xoopsPreload->triggerEvent('system.blocks.system_blocks.usershow', array(&$pm_handler));
186
187    $block['user_avatar']    = $xoopsUser->getVar('user_avatar');
188    $block['uname']          = $xoopsUser->getVar('uname');
189    $block['new_messages']   = $pm_handler->getCount($criteria);
190    $block['lang_inbox']     = _MB_SYSTEM_INBOX;
191    $block['lang_adminmenu'] = _MB_SYSTEM_ADMENU;
192
193    return $block;
194}
195
196// this block is deprecated
197/**
198 * @return array
199 */
200function b_system_waiting_show()
201{
202    global $xoopsUser;
203    $xoopsDB        = XoopsDatabaseFactory::getDatabaseConnection();
204    /* @var XoopsModuleHandler $module_handler */
205    $module_handler = xoops_getHandler('module');
206    $block          = array();
207
208    // waiting content for news
209    if (xoops_isActiveModule('news') && $module_handler->getCount(new Criteria('dirname', 'news'))) {
210        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('stories') . ' WHERE published=0');
211        if ($result) {
212            $block['modules'][0]['adminlink'] = XOOPS_URL . '/modules/news/admin/index.php?op=newarticle';
213            list($block['modules'][0]['pendingnum']) = $xoopsDB->fetchRow($result);
214            $block['modules'][0]['lang_linkname'] = _MB_SYSTEM_SUBMS;
215        }
216    }
217
218    // waiting content for mylinks
219    if (xoops_isActiveModule('mylinks') && $module_handler->getCount(new Criteria('dirname', 'mylinks'))) {
220        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_links') . ' WHERE status=0');
221        if ($result) {
222            $block['modules'][1]['adminlink'] = XOOPS_URL . '/modules/mylinks/admin/index.php?op=listNewLinks';
223            list($block['modules'][1]['pendingnum']) = $xoopsDB->fetchRow($result);
224            $block['modules'][1]['lang_linkname'] = _MB_SYSTEM_WLNKS;
225        }
226        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_broken'));
227        if ($result) {
228            $block['modules'][2]['adminlink'] = XOOPS_URL . '/modules/mylinks/admin/index.php?op=listBrokenLinks';
229            list($block['modules'][2]['pendingnum']) = $xoopsDB->fetchRow($result);
230            $block['modules'][2]['lang_linkname'] = _MB_SYSTEM_BLNK;
231        }
232        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_mod'));
233        if ($result) {
234            $block['modules'][3]['adminlink'] = XOOPS_URL . '/modules/mylinks/admin/index.php?op=listModReq';
235            list($block['modules'][3]['pendingnum']) = $xoopsDB->fetchRow($result);
236            $block['modules'][3]['lang_linkname'] = _MB_SYSTEM_MLNKS;
237        }
238    }
239
240    // waiting content for mydownloads
241    if (xoops_isActiveModule('mydownloads') && $module_handler->getCount(new Criteria('dirname', 'mydownloads'))) {
242        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mydownloads_downloads') . ' WHERE status=0');
243        if ($result) {
244            $block['modules'][4]['adminlink'] = XOOPS_URL . '/modules/mydownloads/admin/index.php?op=listNewDownloads';
245            list($block['modules'][4]['pendingnum']) = $xoopsDB->fetchRow($result);
246            $block['modules'][4]['lang_linkname'] = _MB_SYSTEM_WDLS;
247        }
248        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mydownloads_broken') . '');
249        if ($result) {
250            $block['modules'][5]['adminlink'] = XOOPS_URL . '/modules/mydownloads/admin/index.php?op=listBrokenDownloads';
251            list($block['modules'][5]['pendingnum']) = $xoopsDB->fetchRow($result);
252            $block['modules'][5]['lang_linkname'] = _MB_SYSTEM_BFLS;
253        }
254        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mydownloads_mod') . '');
255        if ($result) {
256            $block['modules'][6]['adminlink'] = XOOPS_URL . '/modules/mydownloads/admin/index.php?op=listModReq';
257            list($block['modules'][6]['pendingnum']) = $xoopsDB->fetchRow($result);
258            $block['modules'][6]['lang_linkname'] = _MB_SYSTEM_MFLS;
259        }
260    }
261
262    // waiting content for xoops comments
263    $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('xoopscomments') . ' WHERE com_status=1');
264    if ($result) {
265        $block['modules'][7]['adminlink'] = XOOPS_URL . '/modules/system/admin.php?module=0&amp;status=1&fct=comments';
266        list($block['modules'][7]['pendingnum']) = $xoopsDB->fetchRow($result);
267        $block['modules'][7]['lang_linkname'] = _MB_SYSTEM_COMPEND;
268    }
269
270    // waiting content for TDMDownloads
271    if (xoops_isActiveModule('TDMdownloads') && $module_handler->getCount(new Criteria('dirname', 'TDMDownloads'))) {
272        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('tdmdownloads_downloads') . ' WHERE status=0');
273        if ($result) {
274            $block['modules'][8]['adminlink'] = XOOPS_URL . '/modules/TDMDownloads/admin/downloads.php?op=list&statut_display=0';
275            list($block['modules'][8]['pendingnum']) = $xoopsDB->fetchRow($result);
276            $block['modules'][8]['lang_linkname'] = _MB_SYSTEM_TDMDOWNLOADS;
277        }
278    }
279
280    // waiting content for extgallery
281    if (xoops_isActiveModule('extgallery') && $module_handler->getCount(new Criteria('dirname', 'extgallery'))) {
282        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('extgallery_publicphoto') . ' WHERE photo_approved=0');
283        if ($result) {
284            $block['modules'][9]['adminlink'] = XOOPS_URL . '/modules/extgallery/admin/photo.php#pending-photo';
285            list($block['modules'][9]['pendingnum']) = $xoopsDB->fetchRow($result);
286            $block['modules'][9]['lang_linkname'] = _MB_SYSTEM_EXTGALLERY;
287        }
288    }
289
290    // waiting content for smartsection
291    if (xoops_isActiveModule('smartsection') && $module_handler->getCount(new Criteria('dirname', 'smartsection'))) {
292        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('smartsection_items') . ' WHERE status=1');
293        if ($result) {
294            $block['modules'][10]['adminlink'] = XOOPS_URL . '/modules/smartsection/admin/item.php';
295            list($block['modules'][10]['pendingnum']) = $xoopsDB->fetchRow($result);
296            $block['modules'][10]['lang_linkname'] = _MB_SYSTEM_SMARTSECTION;
297        }
298    }
299
300    return $block;
301}
302
303/**
304 * @param $options
305 *
306 * @return array
307 */
308function b_system_info_show($options)
309{
310    global $xoopsConfig, $xoopsUser;
311    $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
312    $myts    = MyTextSanitizer::getInstance();
313    $block   = array();
314    if (!empty($options[3])) {
315        $block['showgroups'] = true;
316        $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");
317        if ($xoopsDB->getRowsNum($result) > 0) {
318            $prev_caption = '';
319            $i            = 0;
320            while (false !== ($userinfo = $xoopsDB->fetchArray($result))) {
321                if ($prev_caption != $userinfo['groupname']) {
322                    $prev_caption                = $userinfo['groupname'];
323                    $block['groups'][$i]['name'] = $myts->htmlSpecialChars($userinfo['groupname']);
324                }
325                if (isset($xoopsUser) && is_object($xoopsUser)) {
326                    $block['groups'][$i]['users'][] = array(
327                        'id'      => $userinfo['uid'],
328                        'name'    => $myts->htmlSpecialChars($userinfo['uname']),
329                        '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>",
330                        'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar']);
331                } else {
332                    if ($userinfo['user_viewemail']) {
333                        $block['groups'][$i]['users'][] = array(
334                            'id'      => $userinfo['uid'],
335                            'name'    => $myts->htmlSpecialChars($userinfo['uname']),
336                            'msglink' => '<a href="mailto:' . $userinfo['email'] . '"><img src="' . XOOPS_URL . '/images/icons/em_small.gif" border="0" width="16" height="14" alt="" /></a>',
337                            'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar']);
338                    } else {
339                        $block['groups'][$i]['users'][] = array(
340                            'id'      => $userinfo['uid'],
341                            'name'    => $myts->htmlSpecialChars($userinfo['uname']),
342                            'msglink' => '&nbsp;',
343                            'avatar'  => XOOPS_UPLOAD_URL . '/' . $userinfo['user_avatar']);
344                    }
345                }
346                ++$i;
347            }
348        }
349    } else {
350        $block['showgroups'] = false;
351    }
352    $block['logourl']       = XOOPS_URL . '/images/' . $options[2];
353    $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>';
354
355    return $block;
356}
357
358/**
359 * @param $options
360 *
361 * @return array
362 */
363function b_system_newmembers_show($options)
364{
365    $block    = array();
366    $criteria = new CriteriaCompo(new Criteria('level', 0, '>'));
367    $limit    = (!empty($options[0])) ? $options[0] : 10;
368    $criteria->setOrder('DESC');
369    $criteria->setSort('user_regdate');
370    $criteria->setLimit($limit);
371    /* @var XoopsMemberHandler $member_handler */
372    $member_handler = xoops_getHandler('member');
373    $newmembers     = $member_handler->getUsers($criteria);
374    $count          = count($newmembers);
375    for ($i = 0; $i < $count; ++$i) {
376        if ($options[1] == 1) {
377            $block['users'][$i]['avatar'] = $newmembers[$i]->getVar('user_avatar') !== 'blank.gif' ? XOOPS_UPLOAD_URL . '/' . $newmembers[$i]->getVar('user_avatar') : '';
378        } else {
379            $block['users'][$i]['avatar'] = '';
380        }
381        $block['users'][$i]['id']       = $newmembers[$i]->getVar('uid');
382        $block['users'][$i]['name']     = $newmembers[$i]->getVar('uname');
383        $block['users'][$i]['joindate'] = formatTimestamp($newmembers[$i]->getVar('user_regdate'), 's');
384    }
385
386    return $block;
387}
388
389/**
390 * @param $options
391 *
392 * @return array
393 */
394function b_system_topposters_show($options)
395{
396    $block    = array();
397    $criteria = new CriteriaCompo(new Criteria('level', 0, '>'));
398    $criteria->add(new Criteria('posts', 0, '>'));
399    $limit    = (!empty($options[0])) ? $options[0] : 10;
400    $size     = count($options);
401    for ($i = 2; $i < $size; ++$i) {
402        $criteria->add(new Criteria('rank', $options[$i], '<>'));
403    }
404    $criteria->setOrder('DESC');
405    $criteria->setSort('posts');
406    $criteria->setLimit($limit);
407    /* @var XoopsMemberHandler $member_handler */
408    $member_handler = xoops_getHandler('member');
409    $topposters     = $member_handler->getUsers($criteria);
410    $count          = count($topposters);
411    for ($i = 0; $i < $count; ++$i) {
412        $block['users'][$i]['rank'] = $i + 1;
413        if ($options[1] == 1) {
414            $block['users'][$i]['avatar'] = $topposters[$i]->getVar('user_avatar') !== 'blank.gif' ? XOOPS_UPLOAD_URL . '/' . $topposters[$i]->getVar('user_avatar') : '';
415        } else {
416            $block['users'][$i]['avatar'] = '';
417        }
418        $block['users'][$i]['id']    = $topposters[$i]->getVar('uid');
419        $block['users'][$i]['name']  = $topposters[$i]->getVar('uname');
420        $block['users'][$i]['posts'] = $topposters[$i]->getVar('posts');
421    }
422
423    return $block;
424}
425
426/**
427 * @param $options
428 *
429 * @return array
430 */
431function b_system_comments_show($options)
432{
433    $block = array();
434    include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
435    $comment_handler = xoops_getHandler('comment');
436    $criteria        = new CriteriaCompo(new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
437    $criteria->setLimit((int)$options[0]);
438    $criteria->setSort('com_created');
439    $criteria->setOrder('DESC');
440
441    // Check modules permissions
442    global $xoopsUser;
443    $moduleperm_handler = xoops_getHandler('groupperm');
444    $gperm_groupid      = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
445    $criteria1          = new CriteriaCompo(new Criteria('gperm_name', 'module_read', '='));
446    $criteria1->add(new Criteria('gperm_groupid', '(' . implode(',', $gperm_groupid) . ')', 'IN'));
447    $perms  = $moduleperm_handler->getObjects($criteria1, true);
448    $modIds = array();
449    foreach ($perms as $item) {
450        $modIds[] = $item->getVar('gperm_itemid');
451    }
452    if (count($modIds) > 0) {
453        $modIds = array_unique($modIds);
454        $criteria->add(new Criteria('com_modid', '(' . implode(',', $modIds) . ')', 'IN'));
455    }
456    // Check modules permissions
457
458    $comments       = $comment_handler->getObjects($criteria, true);
459    /* @var XoopsMemberHandler $member_handler */
460    $member_handler = xoops_getHandler('member');
461    /* @var XoopsModuleHandler $module_handler */
462    $module_handler = xoops_getHandler('module');
463    $modules        = $module_handler->getObjects(new Criteria('hascomments', 1), true);
464    $comment_config = array();
465    foreach (array_keys($comments) as $i) {
466        $mid           = $comments[$i]->getVar('com_modid');
467        $com['module'] = '<a href="' . XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname') . '/">' . $modules[$mid]->getVar('name') . '</a>';
468        if (!isset($comment_config[$mid])) {
469            $comment_config[$mid] = $modules[$mid]->getInfo('comments');
470        }
471        $com['id']    = $i;
472        $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>';
473        $com['icon']  = htmlspecialchars($comments[$i]->getVar('com_icon'), ENT_QUOTES);
474        $com['icon']  = ($com['icon'] != '') ? $com['icon'] : 'icon1.gif';
475        $com['time']  = formatTimestamp($comments[$i]->getVar('com_created'), 'm');
476        if ($comments[$i]->getVar('com_uid') > 0) {
477            $poster = $member_handler->getUser($comments[$i]->getVar('com_uid'));
478            if (is_object($poster)) {
479                $com['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $comments[$i]->getVar('com_uid') . '">' . $poster->getVar('uname') . '</a>';
480            } else {
481                $com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
482            }
483        } else {
484            $com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
485        }
486        $block['comments'][] =& $com;
487        unset($com);
488    }
489
490    return $block;
491}
492
493// RMV-NOTIFY
494/**
495 * @return array|bool
496 */
497function b_system_notification_show()
498{
499    global $xoopsConfig, $xoopsUser, $xoopsModule;
500    include_once XOOPS_ROOT_PATH . '/include/notification_functions.php';
501    include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/notification.php';
502    // Notification must be enabled, and user must be logged in
503    if (empty($xoopsUser) || !notificationEnabled('block')) {
504        return false; // do not display block
505    }
506    $notification_handler = xoops_getHandler('notification');
507    // Now build the a nested associative array of info to pass
508    // to the block template.
509    $block      = array();
510    $categories =& notificationSubscribableCategoryInfo();
511    if (empty($categories)) {
512        return false;
513    }
514    foreach ($categories as $category) {
515        $section['name']        = $category['name'];
516        $section['title']       = $category['title'];
517        $section['description'] = $category['description'];
518        $section['itemid']      = $category['item_id'];
519        $section['events']      = array();
520        $subscribed_events      = $notification_handler->getSubscribedEvents($category['name'], $category['item_id'], $xoopsModule->getVar('mid'), $xoopsUser->getVar('uid'));
521        foreach (notificationEvents($category['name'], true) as $event) {
522            if (!empty($event['admin_only']) && !$xoopsUser->isAdmin($xoopsModule->getVar('mid'))) {
523                continue;
524            }
525            $subscribed                        = in_array($event['name'], $subscribed_events) ? 1 : 0;
526            $section['events'][$event['name']] = array(
527                'name'        => $event['name'],
528                'title'       => $event['title'],
529                'caption'     => $event['caption'],
530                'description' => $event['description'],
531                'subscribed'  => $subscribed);
532        }
533        $block['categories'][$category['name']] = $section;
534    }
535    // Additional form data
536    $block['target_page'] = 'notification_update.php';
537    // FIXME: better or more standardized way to do this?
538    $script_url                  = explode('/', $_SERVER['PHP_SELF']);
539    $script_name                 = $script_url[count($script_url) - 1];
540    $block['redirect_script']    = $script_name;
541    $block['submit_button']      = _NOT_UPDATENOW;
542    $block['notification_token'] = $GLOBALS['xoopsSecurity']->createToken();
543
544    return $block;
545}
546
547/**
548 * @param $options
549 *
550 * @return string
551 */
552function b_system_comments_edit($options)
553{
554    $inputtag = "<input type='text' name='options[]' value='" . (int)$options[0] . "' />";
555    $form     = sprintf(_MB_SYSTEM_DISPLAYC, $inputtag);
556
557    return $form;
558}
559
560/**
561 * @param $options
562 *
563 * @return string
564 */
565function b_system_topposters_edit($options)
566{
567    include_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
568    $inputtag = "<input type='text' name='options[]' value='" . (int)$options[0] . "' />";
569    $form     = sprintf(_MB_SYSTEM_DISPLAY, $inputtag);
570    $form .= '<br>' . _MB_SYSTEM_DISPLAYA . "&nbsp;<input type='radio' id='options[]' name='options[]' value='1'";
571    if ($options[1] == 1) {
572        $form .= " checked";
573    }
574    $form .= ' />&nbsp;' . _YES . "<input type='radio' id='options[]' name='options[]' value='0'";
575    if ($options[1] == 0) {
576        $form .= " checked";
577    }
578    $form .= ' />&nbsp;' . _NO . '';
579    $form .= '<br>' . _MB_SYSTEM_NODISPGR . "<br><select id='options[]' name='options[]' multiple='multiple'>";
580    $ranks = XoopsLists::getUserRankList();
581    $size  = count($options);
582    foreach ($ranks as $k => $v) {
583        $sel = '';
584        for ($i = 2; $i < $size; ++$i) {
585            if ($k == $options[$i]) {
586                $sel = " selected";
587            }
588        }
589        $form .= "<option value='$k'$sel>$v</option>";
590    }
591    $form .= '</select>';
592
593    return $form;
594}
595
596/**
597 * @param $options
598 *
599 * @return string
600 */
601function b_system_newmembers_edit($options)
602{
603    $inputtag = "<input type='text' name='options[]' value='" . $options[0] . "' />";
604    $form     = sprintf(_MB_SYSTEM_DISPLAY, $inputtag);
605    $form .= '<br>' . _MB_SYSTEM_DISPLAYA . "&nbsp;<input type='radio' id='options[]' name='options[]' value='1'";
606    if ($options[1] == 1) {
607        $form .= " checked";
608    }
609    $form .= ' />&nbsp;' . _YES . "<input type='radio' id='options[]' name='options[]' value='0'";
610    if ($options[1] == 0) {
611        $form .= " checked";
612    }
613    $form .= ' />&nbsp;' . _NO . '';
614
615    return $form;
616}
617
618/**
619 * @param $options
620 *
621 * @return string
622 */
623function b_system_info_edit($options)
624{
625    $form = _MB_SYSTEM_PWWIDTH . '&nbsp;';
626    $form .= "<input type='text' name='options[]' value='" . $options[0] . "' />";
627    $form .= '<br>' . _MB_SYSTEM_PWHEIGHT . '&nbsp;';
628    $form .= "<input type='text' name='options[]' value='" . $options[1] . "' />";
629    $form .= '<br>' . sprintf(_MB_SYSTEM_LOGO, XOOPS_URL . '/images/') . '&nbsp;';
630    $form .= "<input type='text' name='options[]' value='" . $options[2] . "' />";
631    $chk = '';
632    $form .= '<br>' . _MB_SYSTEM_SADMIN . '&nbsp;';
633    if ($options[3] == 1) {
634        $chk = " checked";
635    }
636    $form .= "<input type='radio' name='options[3]' value='1'" . $chk . ' />&nbsp;' . _YES . '';
637    $chk = '';
638    if ($options[3] == 0) {
639        $chk = " checked";
640    }
641    $form .= "&nbsp;<input type='radio' name='options[3]' value='0'" . $chk . ' />' . _NO . '';
642
643    return $form;
644}
645
646/**
647 * @param $options
648 *
649 * @return array
650 */
651function b_system_themes_show($options)
652{
653    global $xoopsConfig;
654    $block = array();
655
656    if (!isset($options[2])) {
657        $options[2] = 3; // this was the fixed value pre 2.5.8
658    }
659    $selectSize = ($options[0] == 1) ? 1 : (int) $options[2];
660    $select = new XoopsFormSelect('', 'xoops_theme_select', $xoopsConfig['theme_set'], $selectSize);
661    foreach ($xoopsConfig['theme_set_allowed'] as $theme) {
662        $select->addOption($theme, $theme);
663    }
664
665    if ($options[0] == 1) {
666        $themeSelect = '<img vspace="2" id="xoops_theme_img" src="'
667            . XOOPS_THEME_URL . '/' . $xoopsConfig['theme_set'] . '/shot.gif" '
668            . ' alt="screenshot" width="' . (int)$options[1] . '" />'
669            . '<br>';
670        $select->setExtra(' onchange="showImgSelected(\'xoops_theme_img\', \'xoops_theme_select\', \'themes\', \'/shot.gif\', '
671            .  '\'' . XOOPS_URL . '\');" ');
672        $selectTray = new XoopsFormElementTray('');
673        $selectTray->addElement($select);
674        $selectTray->addElement(new XoopsFormButton('', 'submit', _GO, 'submit'));
675        $themeSelect .= '<div class="form-inline">';
676        $themeSelect .= $selectTray->render();
677        $themeSelect .= '</div>';
678    } else {
679        $select->setExtra(' onchange="submit();" ');
680        $themeSelect = $select->render();
681    }
682
683    $block['theme_select'] = $themeSelect . '<br>(' . sprintf(_MB_SYSTEM_NUMTHEME, '<strong>'
684            . count($xoopsConfig['theme_set_allowed']) . '</strong>') . ')<br>';
685
686    return $block;
687}
688
689/**
690 * @param $options
691 *
692 * @return string
693 */
694function b_system_themes_edit($options)
695{
696    $chk  = '';
697    $form = _MB_SYSTEM_THSHOW . '&nbsp;';
698    if (!isset($options[2])) {
699        $options[2] = 3; // this was the fixed value pre 2.5.8
700    }
701    if ($options[0] == 1) {
702        $chk = " checked";
703    }
704    $form .= "<input type='radio' name='options[0]' value='1'" . $chk . ' />&nbsp;' . _YES;
705    $chk = '';
706    if ($options[0] == 0) {
707        $chk = ' checked';
708    }
709    $form .= '&nbsp;<input type="radio" name="options[0]" value="0"' . $chk . ' />' . _NO;
710    $form .= '<br>' . _MB_SYSTEM_THWIDTH . '&nbsp;';
711    $form .= "<input type='text' name='options[1]' value='" . $options[1] . "' />";
712    $form .= '<br>' . _MB_SYSTEM_BLOCK_HEIGHT . '&nbsp;';
713    $form .= "<input type='text' name='options[2]' value='" . $options[2] . "' />";
714
715    return $form;
716}
717