1
|
|
|
<?php |
2
|
|
|
// Author: SMD & Trabis |
3
|
|
|
// URL: http://www.xoopsmalaysia.org & http://www.xuups.com |
4
|
|
|
// E-Mail: [email protected] & [email protected] |
5
|
|
|
|
6
|
|
|
if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ; |
7
|
|
|
|
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
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
function membersstats_edit($options) { |
130
|
|
|
|
131
|
|
|
$form = _MB_XOOPSMEMBERS_SHOWTOTALPOST." "; |
132
|
|
|
if ( $options[0] == 1 ) { |
133
|
|
|
$chk = " checked='checked'"; |
134
|
|
|
} |
135
|
|
|
$form .= "<input type='radio' name='options[0]' value='1'".$chk." /> "._YES.""; |
|
|
|
|
136
|
|
|
$chk = ""; |
137
|
|
|
if ( $options[0] == 0 ) { |
138
|
|
|
$chk = " checked='checked'"; |
139
|
|
|
} |
140
|
|
|
$form .= " <input type='radio' name='options[0]' value='0'".$chk." />"._NO."<br />"; |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
$form .= _MB_XOOPSMEMBERS_SHOWTOTALONLINE." "; |
144
|
|
|
if ( $options[1] == 1 ) { |
145
|
|
|
$chk = " checked='checked'"; |
146
|
|
|
} |
147
|
|
|
$form .= "<input type='radio' name='options[1]' value='1'".$chk." /> "._YES.""; |
148
|
|
|
$chk = ""; |
149
|
|
|
if ( $options[1] == 0 ) { |
150
|
|
|
$chk = " checked='checked'"; |
151
|
|
|
} |
152
|
|
|
$form .= " <input type='radio' name='options[1]' value='0'".$chk." />"._NO."<br />"; |
153
|
|
|
|
154
|
|
|
$form .= _MB_XOOPSMEMBERS_SHOWREGHISTORY." "; |
155
|
|
|
if ( $options[2] == 1 ) { |
156
|
|
|
$chk = " checked='checked'"; |
157
|
|
|
} |
158
|
|
|
$form .= "<input type='radio' name='options[2]' value='1'".$chk." /> "._YES.""; |
159
|
|
|
$chk = ""; |
160
|
|
|
if ( $options[2] == 0 ) { |
161
|
|
|
$chk = " checked='checked'"; |
162
|
|
|
} |
163
|
|
|
$form .= " <input type='radio' name='options[2]' value='0'".$chk." />"._NO."<br />"; |
164
|
|
|
|
165
|
|
|
$form .= _MB_XOOPSMEMBERS_SHOWNEWMEMBER." "; |
166
|
|
|
if ( $options[3] == 1 ) { |
167
|
|
|
$chk = " checked='checked'"; |
168
|
|
|
} |
169
|
|
|
$form .= "<input type='radio' name='options[3]' value='1'".$chk." /> "._YES.""; |
170
|
|
|
$chk = ""; |
171
|
|
|
if ( $options[3] == 0 ) { |
172
|
|
|
$chk = " checked='checked'"; |
173
|
|
|
} |
174
|
|
|
$form .= " <input type='radio' name='options[3]' value='0'".$chk." />"._NO."<br />"; |
175
|
|
|
|
176
|
|
|
$form .= _MB_XOOPSMEMBERS_USEREALNAME." "; |
177
|
|
|
if ( $options[4] == 1 ) { |
178
|
|
|
$chk = " checked='checked'"; |
179
|
|
|
} |
180
|
|
|
$form .= "<input type='radio' name='options[4]' value='1'".$chk." /> "._YES.""; |
181
|
|
|
$chk = ""; |
182
|
|
|
if ( $options[4] == 0 ) { |
183
|
|
|
$chk = " checked='checked'"; |
184
|
|
|
} |
185
|
|
|
$form .= " <input type='radio' name='options[4]' value='0'".$chk." />"._NO."<br />"; |
186
|
|
|
|
187
|
|
|
return $form; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
?> |
|
|
|
|
191
|
|
|
|