Conditions | 15 |
Paths | 648 |
Total Lines | 109 |
Code Lines | 82 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
8 | function show_membersonline_block($options) { |
||
9 | global $xoopsConfig, $xoopsUser, $xoopsModule, $xoopsDB, $_SERVER; |
||
10 | |||
11 | /* @var XoopsOnlineHandler $online_handler */ |
||
12 | $online_handler = xoops_getHandler('online'); |
||
13 | // set gc probabillity to 10% for now.. |
||
14 | if (mt_rand(1, 100) < 11) { |
||
15 | $online_handler->gc(300); |
||
16 | } |
||
17 | if (is_object($xoopsUser)) { |
||
18 | $uid = $xoopsUser->getVar('uid'); |
||
19 | $name = $xoopsUser->getVar('name'); |
||
20 | if ($options[4]=='1' && $name!='') |
||
21 | { |
||
22 | $uname = $xoopsUser->getVar('name'); |
||
23 | } |
||
24 | else { |
||
25 | $uname = $xoopsUser->getVar('uname'); |
||
26 | } |
||
27 | |||
28 | } else { |
||
29 | $uid = 0; |
||
30 | $uname = ''; |
||
31 | $name = ''; |
||
|
|||
32 | } |
||
33 | $requestIp = \Xmf\IPAddress::fromRequest()->asReadable(); |
||
34 | $requestIp = (false === $requestIp) ? '0.0.0.0' : $requestIp; |
||
35 | if (is_object($xoopsModule)) { |
||
36 | $online_handler->write($uid, $uname, time(), $xoopsModule->getVar('mid'), $requestIp); |
||
37 | } else { |
||
38 | $online_handler->write($uid, $uname, time(), 0, $requestIp); |
||
39 | } |
||
40 | $onlines = $online_handler->getAll(); |
||
41 | if (!empty($onlines)) { |
||
42 | $total = count($onlines); |
||
43 | $block = array(); |
||
44 | $guests = 0; |
||
45 | $membersname = ''; |
||
46 | $membersavatar = ''; |
||
47 | $avatar = ''; |
||
48 | $uid = ''; |
||
49 | $name = ''; |
||
50 | $onlineUsers = []; |
||
51 | for ($i = 0; $i < $total; ++$i) { |
||
52 | if ($onlines[$i]['online_uid'] == 0) { |
||
53 | $onlineUsers[$i]['user'] = ''; |
||
54 | } else { |
||
55 | $onlineUsers[$i]['user'] = new XoopsUser($onlines[$i]['online_uid']); |
||
56 | } |
||
57 | if (is_object($onlineUsers[$i]['user'])) { |
||
58 | $block['avatar'] = $onlineUsers[$i]['user']->getVar('user_avatar'); |
||
59 | $block['uid']= $onlineUsers[$i]['user']->getVar('uid'); |
||
60 | |||
61 | $realname = $onlineUsers[$i]['user']->getVar('name'); |
||
62 | if ('1' == $options[5] && '' != $realname) { |
||
63 | $block['name'] = $onlineUsers[$i]['user']->getVar('name'); |
||
64 | } else { |
||
65 | $block['name'] = $onlineUsers[$i]['user']->getVar('uname'); |
||
66 | } |
||
67 | } |
||
68 | |||
69 | if ($onlines[$i]['online_uid'] > 0) { |
||
70 | $membersname .= '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $onlines[$i]['online_uid'] . '" title="' . $onlines[$i]['online_uname'] . '">' . $onlines[$i]['online_uname'] . '</a>, '; |
||
71 | } else { |
||
72 | ++$guests; |
||
73 | } |
||
74 | } |
||
75 | $block['online_total'] = sprintf(_ONLINEPHRASE, $total); |
||
76 | if (is_object($xoopsModule)) { |
||
77 | $mytotal = $online_handler->getCount(new Criteria('online_module', $xoopsModule->getVar('mid'))); |
||
78 | $block['online_total'] .= ' (' . sprintf(_ONLINEPHRASEX, $mytotal, $xoopsModule->getVar('name')) . ')'; |
||
79 | } |
||
80 | // Membership Statistic |
||
81 | /** @var \XoopsMemberHandler $member_handler */ |
||
82 | $member_handler =xoops_gethandler('member'); |
||
83 | $today = formatTimestamp(time()); |
||
84 | $level_criteria = new Criteria('level', 0, '>'); |
||
85 | $criteria = new CriteriaCompo($level_criteria); |
||
86 | $criteria24 = new CriteriaCompo($level_criteria); |
||
87 | $criteria48 = new CriteriaCompo($level_criteria); |
||
88 | $total_active_users = $member_handler->getUserCount($level_criteria); |
||
89 | //Fixing stats for last 24 and 48 hours |
||
90 | $users_reg_24 = $member_handler->getUserCount($criteria24->add(new Criteria('user_regdate', (mktime(0,0,0)-(24*3600)), '>=')),'AND'); |
||
91 | $users_reg_48 = $member_handler->getUserCount($criteria48->add(new Criteria('user_regdate', (mktime(0,0,0)-(48*3600)), '>=')),'AND'); |
||
92 | $limit = 1; |
||
93 | $criteria->setOrder('DESC'); |
||
94 | $criteria->setSort('user_regdate'); |
||
95 | $criteria->setLimit($limit); |
||
96 | |||
97 | // data |
||
98 | $block['activeusers'] = $total_active_users; |
||
99 | $block['todayreg'] = $users_reg_24; |
||
100 | $block['yesterdayreg'] = $users_reg_48 - $users_reg_24; |
||
101 | $block['total_online'] = sprintf(_MB_XOOPSMEMBERS_TOTALONLINE, $total); |
||
102 | $block['online_members'] = $total - $guests . ' ' . _MB_XOOPSMEMBERS_MEMBERS . ' ' . _MB_XOOPSMEMBERS_CURRENTONLINE; |
||
103 | $block['online_guests'] = $guests . ' ' . _MB_XOOPSMEMBERS_GUESTS . ' ' . _MB_XOOPSMEMBERS_AND; |
||
104 | |||
105 | |||
106 | $block['showonlinemember'] = $options[0]; |
||
107 | $block['showonlinename'] = $options[1]; |
||
108 | $block['showonlineavatar'] = $options[2]; |
||
109 | $block['showonlinepopup'] = $options[3]; |
||
110 | $block['showtotalonline'] = $options[4]; |
||
111 | $block['userealname'] = $options[5]; |
||
112 | $block['memberdisplay'] = $options[6]; |
||
113 | |||
114 | return $block; |
||
115 | } else { |
||
116 | return false; |
||
117 | } |
||
193 |