-
Notifications
You must be signed in to change notification settings - Fork 0
/
online.php
284 lines (241 loc) · 7.09 KB
/
online.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
define("IN_MYBB", 1);
define('THIS_SCRIPT', 'online.php');
$templatelist = "online,online_row,online_row_ip,online_today,online_today_row,online_row_ip_lookup,multipage,multipage_end,multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage,multipage_start";
require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_online.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
// Load global language phrases
$lang->load("online");
if($mybb->usergroup['canviewonline'] == 0)
{
error_no_permission();
}
// Make navigation
add_breadcrumb($lang->nav_online, "online.php");
if($mybb->get_input('action') == "today")
{
add_breadcrumb($lang->nav_onlinetoday);
$plugins->run_hooks("online_today_start");
$threshold = TIME_NOW-(60*60*24);
$query = $db->simple_select("users", "COUNT(uid) AS users", "lastactive > '{$threshold}'");
$todaycount = $db->fetch_field($query, "users");
$query = $db->simple_select("users", "COUNT(uid) AS users", "lastactive > '{$threshold}' AND invisible = '1'");
$invis_count = $db->fetch_field($query, "users");
if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
{
$mybb->settings['threadsperpage'] = 20;
}
// Add pagination
$perpage = $mybb->settings['threadsperpage'];
if($mybb->get_input('page', MyBB::INPUT_INT) > 0)
{
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$start = ($page-1) * $perpage;
$pages = ceil($todaycount / $perpage);
if($page > $pages)
{
$start = 0;
$page = 1;
}
}
else
{
$start = 0;
$page = 1;
}
$query = $db->simple_select("users", "*", "lastactive > '{$threshold}'", array("order_by" => "lastactive", "order_dir" => "desc", "limit" => $perpage, "limit_start" => $start));
$todayrows = '';
while($online = $db->fetch_array($query))
{
$invisiblemark = '';
if($online['invisible'] == 1)
{
$invisiblemark = "*";
}
if($online['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $online['uid'] == $mybb->user['uid'])
{
$username = $online['username'];
$username = format_name($username, $online['usergroup'], $online['displaygroup']);
$online['profilelink'] = build_profile_link($username, $online['uid']);
$onlinetime = my_date($mybb->settings['timeformat'], $online['lastactive']);
eval("\$todayrows .= \"".$templates->get("online_today_row")."\";");
}
}
$todaycount = my_number_format($todaycount);
$invis_count = my_number_format($invis_count);
if($todaycount == 1)
{
$onlinetoday = $lang->member_online_today;
}
else
{
$onlinetoday = $lang->sprintf($lang->members_were_online_today, $todaycount);
}
if($invis_count)
{
$string = $lang->members_online_hidden;
if($invis_count == 1)
{
$string = $lang->member_online_hidden;
}
$onlinetoday .= $lang->sprintf($string, $invis_count);
}
$multipage = multipage($todaycount, $perpage, $page, "online.php?action=today");
$plugins->run_hooks("online_today_end");
eval("\$today = \"".$templates->get("online_today")."\";");
output_page($today);
}
else
{
$plugins->run_hooks("online_start");
// Custom sorting options
if($mybb->get_input('sortby') == "username")
{
$sql = "u.username ASC, s.time DESC";
$refresh_string = "?sortby=username";
}
elseif($mybb->get_input('sortby') == "location")
{
$sql = "s.location, s.time DESC";
$refresh_string = "?sortby=location";
}
// Otherwise sort by last refresh
else
{
switch($db->type)
{
case "sqlite":
case "pgsql":
$sql = "s.time DESC";
break;
default:
$sql = "IF( s.uid >0, 1, 0 ) DESC, s.time DESC";
break;
}
$refresh_string = '';
}
$timesearch = TIME_NOW - $mybb->settings['wolcutoffmins']*60;
// Exactly how many users are currently online?
switch($db->type)
{
case "sqlite":
$sessions = array();
$query = $db->simple_select("sessions", "sid", "time > {$timesearch}");
while($sid = $db->fetch_field($query, "sid"))
{
$sessions[$sid] = 1;
}
$online_count = count($sessions);
unset($sessions);
break;
case "pgsql":
default:
$query = $db->simple_select("sessions", "COUNT(sid) as online", "time > {$timesearch}");
$online_count = $db->fetch_field($query, "online");
break;
}
if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
{
$mybb->settings['threadsperpage'] = 20;
}
// How many pages are there?
$perpage = $mybb->settings['threadsperpage'];
if($mybb->get_input('page', MyBB::INPUT_INT) > 0)
{
$page = $mybb->get_input('page', MyBB::INPUT_INT);
$start = ($page-1) * $perpage;
$pages = ceil($online_count / $perpage);
if($page > $pages)
{
$start = 0;
$page = 1;
}
}
else
{
$start = 0;
$page = 1;
}
// Assemble page URL
$multipage = multipage($online_count, $perpage, $page, "online.php".$refresh_string);
// Query for active sessions
$query = $db->query("
SELECT DISTINCT s.sid, s.ip, s.uid, s.time, s.location, u.username, s.nopermission, u.invisible, u.usergroup, u.displaygroup
FROM ".TABLE_PREFIX."sessions s
LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
WHERE s.time>'$timesearch'
ORDER BY $sql
LIMIT {$start}, {$perpage}
");
// Fetch spiders
$spiders = $cache->read("spiders");
while($user = $db->fetch_array($query))
{
$plugins->run_hooks("online_user");
// Fetch the WOL activity
$user['activity'] = fetch_wol_activity($user['location'], $user['nopermission']);
$botkey = my_strtolower(str_replace("bot=", '', $user['sid']));
// Have a registered user
if($user['uid'] > 0)
{
if(empty($users[$user['uid']]) || $users[$user['uid']]['time'] < $user['time'])
{
$users[$user['uid']] = $user;
}
}
// Otherwise this session is a bot
else if(my_strpos($user['sid'], "bot=") !== false && $spiders[$botkey])
{
$user['bot'] = $spiders[$botkey]['name'];
$user['usergroup'] = $spiders[$botkey]['usergroup'];
$guests[] = $user;
}
// Or a guest
else
{
$guests[] = $user;
}
}
// Now we build the actual online rows - we do this separately because we need to query all of the specific activity and location information
$online_rows = '';
if(isset($users) && is_array($users))
{
reset($users);
foreach($users as $user)
{
$online_rows .= build_wol_row($user);
}
}
if(isset($guests) && is_array($guests))
{
reset($guests);
foreach($guests as $user)
{
$online_rows .= build_wol_row($user);
}
}
// Fetch the most online information
$most_online = $cache->read("mostonline");
$record_count = $most_online['numusers'];
$record_date = my_date('relative', $most_online['time']);
// Set automatic refreshing if enabled
if($mybb->settings['refreshwol'] > 0)
{
$refresh_time = $mybb->settings['refreshwol'] * 60;
$refresh = "<meta http-equiv=\"refresh\" content=\"{$refresh_time};URL=online.php{$refresh_string}\" />";
}
$plugins->run_hooks("online_end");
eval("\$online = \"".$templates->get("online")."\";");
output_page($online);
}