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