Conditions | 11 |
Paths | 208 |
Total Lines | 99 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
16 | function show_membersstats_block($options) |
||
17 | { |
||
18 | global $xoopsConfig, $xoopsUser, $xoopsModule, $xoopsDB, $_SERVER; |
||
19 | /* @var XoopsOnlineHandler $onlineHandler */ |
||
20 | $onlineHandler = xoops_getHandler('online'); |
||
21 | // set gc probabillity to 10% for now.. |
||
22 | if (mt_rand(1, 100) < 11) { |
||
23 | $onlineHandler->gc(300); |
||
24 | } |
||
25 | if (is_object($xoopsUser)) { |
||
26 | $uid = $xoopsUser->getVar('uid'); |
||
27 | $uname = $xoopsUser->getVar('uname'); |
||
28 | } else { |
||
29 | $uid = 0; |
||
30 | $uname = ''; |
||
31 | } |
||
32 | $requestIp = IPAddress::fromRequest()->asReadable(); |
||
33 | $requestIp = (false === $requestIp) ? '0.0.0.0' : $requestIp; |
||
|
|||
34 | if (is_object($xoopsModule)) { |
||
35 | $onlineHandler->write($uid, $uname, time(), $xoopsModule->getVar('mid'), $requestIp); |
||
36 | } else { |
||
37 | $onlineHandler->write($uid, $uname, time(), 0, $requestIp); |
||
38 | } |
||
39 | $onlines = $onlineHandler->getAll(); |
||
40 | if (!empty($onlines)) { |
||
41 | $total = count($onlines); |
||
42 | $block = []; |
||
43 | $guests = 0; |
||
44 | $members = ''; |
||
45 | for ($i = 0; $i < $total; ++$i) { |
||
46 | if ($onlines[$i]['online_uid'] > 0) { |
||
47 | $members .= ' <a href="' . XOOPS_URL . '/userinfo.php?uid=' . $onlines[$i]['online_uid'] . '" title="' . $onlines[$i]['online_uname'] . '">' . $onlines[$i]['online_uname'] . '</a>,'; |
||
48 | } else { |
||
49 | ++$guests; |
||
50 | } |
||
51 | } |
||
52 | $block['online_total'] = sprintf(_ONLINEPHRASE, $total); |
||
53 | if (is_object($xoopsModule)) { |
||
54 | $mytotal = $onlineHandler->getCount(new \Criteria('online_module', $xoopsModule->getVar('mid'))); |
||
55 | $block['online_total'] .= ' (' . sprintf(_ONLINEPHRASEX, $mytotal, $xoopsModule->getVar('name')) . ')'; |
||
56 | } |
||
57 | // Membership Statistic |
||
58 | /** @var \XoopsMemberHandler $memberHandler */ |
||
59 | $memberHandler = xoops_getHandler('member'); |
||
60 | $today = formatTimestamp(time()); |
||
61 | $level_criteria = new \Criteria('level', 0, '>'); |
||
62 | $criteria = new \CriteriaCompo($level_criteria); |
||
63 | $criteria24 = new \CriteriaCompo($level_criteria); |
||
64 | $criteria48 = new \CriteriaCompo($level_criteria); |
||
65 | $total_active_users = $memberHandler->getUserCount($level_criteria); |
||
66 | //Fixing stats for last 24 and 48 hours |
||
67 | $users_reg_24 = $memberHandler->getUserCount($criteria24->add(new \Criteria('user_regdate', (mktime(0, 0, 0) - (24 * 3600)), '>=')), 'AND'); |
||
68 | $users_reg_48 = $memberHandler->getUserCount($criteria48->add(new \Criteria('user_regdate', (mktime(0, 0, 0) - (48 * 3600)), '>=')), 'AND'); |
||
69 | $limit = 1; |
||
70 | $criteria->setOrder('DESC'); |
||
71 | $criteria->setSort('user_regdate'); |
||
72 | $criteria->setLimit($limit); |
||
73 | $lastmembers = $memberHandler->getUsers($criteria); |
||
74 | $lastusername = $lastmembers[0]->getVar('uname'); |
||
75 | $lastrealname = $lastmembers[0]->getVar('name'); |
||
76 | $lastid = $lastmembers[0]->getVar('uid'); |
||
77 | |||
78 | //Total Post Count |
||
79 | $sql = 'SELECT SUM(posts) AS totalposts FROM ' . $GLOBALS['xoopsDB']->prefix('users') . ' WHERE level > 0'; |
||
80 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
81 | $myrow = $GLOBALS['xoopsDB']->fetchArray($result); |
||
82 | $block['totalposts'] = $myrow['totalposts']. ' ' . _MB_XOOPSMEMBERS_TOTALPOSTS; |
||
83 | |||
84 | |||
85 | // data |
||
86 | $block['activeusers'] = $total_active_users. ' ' . _MB_XOOPSMEMBERS_REGISTEREDMEMBERS; |
||
87 | $block['todayreg'] = $users_reg_24 . ' ' . _MB_XOOPSMEMBERS_REGISTEREDTODAY . ' ' . _MB_XOOPSMEMBERS_AND; |
||
88 | $block['yesterdayreg'] = $users_reg_48 - $users_reg_24 . ' ' . _MB_XOOPSMEMBERS_REGISTEREDYESTERDAY; |
||
89 | $block['online_names'] = $members; |
||
90 | $block['online_members'] = $total - $guests . ' ' . _MB_XOOPSMEMBERS_MEMBERS . ' ' . _MB_XOOPSMEMBERS_CURRENTONLINE; |
||
91 | $block['online_guests'] = $guests . ' ' . _MB_XOOPSMEMBERS_GUESTS . ' ' . _MB_XOOPSMEMBERS_AND; |
||
92 | $block['lang_more'] = _MB_XOOPSMEMBERS_MORE; |
||
93 | |||
94 | $block['total_online'] = $total; |
||
95 | |||
96 | if ('1' == $options[4] && '' != $lastrealname) { |
||
97 | $block['latestmember'] = $lastrealname; |
||
98 | } else { |
||
99 | $block['latestmember'] = $lastusername; |
||
100 | } |
||
101 | $block['latest_id'] = $lastid; |
||
102 | |||
103 | // Language Definition |
||
104 | $block['membership_lang'] = _MB_XOOPSMEMBERS_MEMBERSHIP; |
||
105 | $block['newestmember_lang'] = _MB_XOOPSMEMBERS_NEWESTMEMBER; |
||
106 | $block['showtotalpost'] = $options[0]; |
||
107 | $block['showtotalonline'] = $options[1]; |
||
108 | $block['showreghistory'] = $options[2]; |
||
109 | $block['shownewmember'] = $options[3]; |
||
110 | $block['userealname'] = $options[4]; |
||
111 | |||
112 | return $block; |
||
113 | } else { |
||
114 | return false; |
||
115 | } |
||
181 |