-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
415 lines (364 loc) · 11.3 KB
/
index.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<?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', 'index.php');
$templatelist = "index,index_whosonline,index_whosonline_memberbit,forumbit_depth1_cat,forumbit_depth2_cat,forumbit_depth2_forum,forumbit_depth1_forum_lastpost,forumbit_depth2_forum_lastpost,forumbit_moderators";
$templatelist .= ",index_birthdays_birthday,index_birthdays,index_logoutlink,index_statspage,index_stats,forumbit_depth3,forumbit_depth3_statusicon,index_boardstats,forumbit_depth2_forum_lastpost_never,forumbit_depth2_forum_viewers";
$templatelist .= ",forumbit_moderators_group,forumbit_moderators_user,forumbit_depth2_forum_lastpost_hidden,forumbit_subforums,forumbit_depth2_forum_unapproved_posts,forumbit_depth2_forum_unapproved_threads";
require_once './global.php';
require_once MYBB_ROOT.'inc/functions_forumlist.php';
require_once MYBB_ROOT.'inc/class_parser.php';
$parser = new postParser;
$plugins->run_hooks('index_start');
// Load global language phrases
$lang->load('index');
$logoutlink = '';
if($mybb->user['uid'] != 0)
{
eval('$logoutlink = "'.$templates->get('index_logoutlink').'";');
}
$statspage = '';
if($mybb->settings['statsenabled'] != 0)
{
if(!empty($logoutlink))
{
$stats_page_separator = $lang->board_stats_link_separator;
}
eval('$statspage = "'.$templates->get('index_statspage').'";');
}
$whosonline = '';
if($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0)
{
// Get the online users.
if($mybb->settings['wolorder'] == 'username')
{
$order_by = 'u.username ASC';
$order_by2 = 's.time DESC';
}
else
{
$order_by = 's.time DESC';
$order_by2 = 'u.username ASC';
}
$timesearch = TIME_NOW - (int)$mybb->settings['wolcutoff'];
$query = $db->query("
SELECT s.sid, s.ip, s.uid, s.time, s.location, s.location1, u.username, 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 {$order_by}, {$order_by2}
");
$forum_viewers = $doneusers = $onlinemembers = $onlinebots = array();
$membercount = $guestcount = $anoncount = $botcount = 0;
// Fetch spiders
$spiders = $cache->read('spiders');
// Loop through all users.
while($user = $db->fetch_array($query))
{
// Create a key to test if this user is a search bot.
$botkey = my_strtolower(str_replace('bot=', '', $user['sid']));
// Decide what type of user we are dealing with.
if($user['uid'] > 0)
{
// The user is registered.
if(empty($doneusers[$user['uid']]) || $doneusers[$user['uid']] < $user['time'])
{
// If the user is logged in anonymously, update the count for that.
if($user['invisible'] == 1)
{
++$anoncount;
}
++$membercount;
if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
{
// If this usergroup can see anonymously logged-in users, mark them.
if($user['invisible'] == 1)
{
$invisiblemark = '*';
}
else
{
$invisiblemark = '';
}
// Properly format the username and assign the template.
$user['username'] = format_name(htmlspecialchars_uni($user['username']), $user['usergroup'], $user['displaygroup']);
$user['profilelink'] = build_profile_link($user['username'], $user['uid']);
eval('$onlinemembers[] = "'.$templates->get('index_whosonline_memberbit', 1, 0).'";');
}
// This user has been handled.
$doneusers[$user['uid']] = $user['time'];
}
}
elseif(my_strpos($user['sid'], 'bot=') !== false && $spiders[$botkey])
{
if($mybb->settings['wolorder'] == 'username')
{
$key = $spiders[$botkey]['name'];
}
else
{
$key = $user['time'];
}
// The user is a search bot.
$onlinebots[$key] = format_name($spiders[$botkey]['name'], $spiders[$botkey]['usergroup']);
++$botcount;
}
else
{
// The user is a guest.
++$guestcount;
}
if($user['location1'])
{
++$forum_viewers[$user['location1']];
}
}
if($mybb->settings['wolorder'] == 'activity')
{
// activity ordering is DESC, username is ASC
krsort($onlinebots);
}
else
{
ksort($onlinebots);
}
$onlinemembers = array_merge($onlinebots, $onlinemembers);
if(!empty($onlinemembers))
{
$comma = $lang->comma." ";
$onlinemembers = implode($comma, $onlinemembers);
}
else
{
$onlinemembers = "";
}
// Build the who's online bit on the index page.
$onlinecount = $membercount + $guestcount + $botcount;
if($onlinecount != 1)
{
$onlinebit = $lang->online_online_plural;
}
else
{
$onlinebit = $lang->online_online_singular;
}
if($membercount != 1)
{
$memberbit = $lang->online_member_plural;
}
else
{
$memberbit = $lang->online_member_singular;
}
if($anoncount != 1)
{
$anonbit = $lang->online_anon_plural;
}
else
{
$anonbit = $lang->online_anon_singular;
}
if($guestcount != 1)
{
$guestbit = $lang->online_guest_plural;
}
else
{
$guestbit = $lang->online_guest_singular;
}
$lang->online_note = $lang->sprintf($lang->online_note, my_number_format($onlinecount), $onlinebit, $mybb->settings['wolcutoffmins'], my_number_format($membercount), $memberbit, my_number_format($anoncount), $anonbit, my_number_format($guestcount), $guestbit);
eval('$whosonline = "'.$templates->get('index_whosonline').'";');
}
// Build the birthdays for to show on the index page.
$bdays = $birthdays = '';
if($mybb->settings['showbirthdays'] != 0)
{
// First, see what day this is.
$bdaycount = $bdayhidden = 0;
$bdaydate = my_date('j-n', TIME_NOW, '', 0);
$year = my_date('Y', TIME_NOW, '', 0);
$bdaycache = $cache->read('birthdays');
if(!is_array($bdaycache))
{
$cache->update_birthdays();
$bdaycache = $cache->read('birthdays');
}
$hiddencount = $today_bdays = 0;
if(isset($bdaycache[$bdaydate]))
{
$hiddencount = $bdaycache[$bdaydate]['hiddencount'];
$today_bdays = $bdaycache[$bdaydate]['users'];
}
$comma = '';
if(!empty($today_bdays))
{
if((int)$mybb->settings['showbirthdayspostlimit'] > 0)
{
$bdayusers = array();
foreach($today_bdays as $key => $bdayuser_pc)
{
$bdayusers[$bdayuser_pc['uid']] = $key;
}
if(!empty($bdayusers))
{
// Find out if our users have enough posts to be seen on our birthday list
$bday_sql = implode(',', array_keys($bdayusers));
$query = $db->simple_select('users', 'uid, postnum', "uid IN ({$bday_sql})");
while($bdayuser = $db->fetch_array($query))
{
if($bdayuser['postnum'] < $mybb->settings['showbirthdayspostlimit'])
{
unset($today_bdays[$bdayusers[$bdayuser['uid']]]);
}
}
}
}
// We still have birthdays - display them in our list!
if(!empty($today_bdays))
{
foreach($today_bdays as $bdayuser)
{
if($bdayuser['displaygroup'] == 0)
{
$bdayuser['displaygroup'] = $bdayuser['usergroup'];
}
// If this user's display group can't be seen in the birthday list, skip it
if($groupscache[$bdayuser['displaygroup']] && $groupscache[$bdayuser['displaygroup']]['showinbirthdaylist'] != 1)
{
continue;
}
$age = '';
$bday = explode('-', $bdayuser['birthday']);
if($year > $bday['2'] && $bday['2'] != '')
{
$age = ' ('.($year - $bday['2']).')';
}
$bdayuser['username'] = format_name(htmlspecialchars_uni($bdayuser['username']), $bdayuser['usergroup'], $bdayuser['displaygroup']);
$bdayuser['profilelink'] = build_profile_link($bdayuser['username'], $bdayuser['uid']);
eval('$bdays .= "'.$templates->get('index_birthdays_birthday', 1, 0).'";');
++$bdaycount;
$comma = $lang->comma;
}
}
}
if($hiddencount > 0)
{
if($bdaycount > 0)
{
$bdays .= ' - ';
}
$bdays .= "{$hiddencount} {$lang->birthdayhidden}";
}
// If there are one or more birthdays, show them.
if($bdaycount > 0 || $hiddencount > 0)
{
eval('$birthdays = "'.$templates->get('index_birthdays').'";');
}
}
// Build the forum statistics to show on the index page.
$forumstats = '';
if($mybb->settings['showindexstats'] != 0)
{
// First, load the stats cache.
$stats = $cache->read('stats');
// Check who's the newest member.
if(!$stats['lastusername'])
{
$newestmember = $lang->nobody;;
}
else
{
$newestmember = build_profile_link($stats['lastusername'], $stats['lastuid']);
}
// Format the stats language.
$lang->stats_posts_threads = $lang->sprintf($lang->stats_posts_threads, my_number_format($stats['numposts']), my_number_format($stats['numthreads']));
$lang->stats_numusers = $lang->sprintf($lang->stats_numusers, my_number_format($stats['numusers']));
$lang->stats_newestuser = $lang->sprintf($lang->stats_newestuser, $newestmember);
// Find out what the highest users online count is.
$mostonline = $cache->read('mostonline');
if($onlinecount > $mostonline['numusers'])
{
$time = TIME_NOW;
$mostonline['numusers'] = $onlinecount;
$mostonline['time'] = $time;
$cache->update('mostonline', $mostonline);
}
$recordcount = $mostonline['numusers'];
$recorddate = my_date($mybb->settings['dateformat'], $mostonline['time']);
$recordtime = my_date($mybb->settings['timeformat'], $mostonline['time']);
// Then format that language string.
$lang->stats_mostonline = $lang->sprintf($lang->stats_mostonline, my_number_format($recordcount), $recorddate, $recordtime);
eval('$forumstats = "'.$templates->get('index_stats').'";');
}
// Show the board statistics table only if one or more index statistics are enabled.
$boardstats = '';
if(($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0) || $mybb->settings['showindexstats'] != 0 || ($mybb->settings['showbirthdays'] != 0 && $bdaycount > 0))
{
if(!isset($stats) || isset($stats) && !is_array($stats))
{
// Load the stats cache.
$stats = $cache->read('stats');
}
$expaltext = (in_array("boardstats", $collapse)) ? "[+]" : "[-]";
eval('$boardstats = "'.$templates->get('index_boardstats').'";');
}
if($mybb->user['uid'] == 0)
{
// Build a forum cache.
$query = $db->simple_select('forums', '*', 'active!=0', array('order_by' => 'pid, disporder'));
$forumsread = array();
if(isset($mybb->cookies['mybb']['forumread']))
{
$forumsread = my_unserialize($mybb->cookies['mybb']['forumread']);
}
}
else
{
// Build a forum cache.
$query = $db->query("
SELECT f.*, fr.dateline AS lastread
FROM ".TABLE_PREFIX."forums f
LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid = f.fid AND fr.uid = '{$mybb->user['uid']}')
WHERE f.active != 0
ORDER BY pid, disporder
");
}
while($forum = $db->fetch_array($query))
{
if($mybb->user['uid'] == 0)
{
if(!empty($forumsread[$forum['fid']]))
{
$forum['lastread'] = $forumsread[$forum['fid']];
}
}
$fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
}
$forumpermissions = forum_permissions();
// Get the forum moderators if the setting is enabled.
$moderatorcache = array();
if($mybb->settings['modlist'] != 0 && $mybb->settings['modlist'] != 'off')
{
$moderatorcache = $cache->read('moderators');
}
$excols = 'index';
$permissioncache['-1'] = '1';
$bgcolor = 'trow1';
// Decide if we're showing first-level subforums on the index page.
$showdepth = 2;
if($mybb->settings['subforumsindex'] != 0)
{
$showdepth = 3;
}
$forum_list = build_forumbits();
$forums = $forum_list['forum_list'];
$plugins->run_hooks('index_end');
eval('$index = "'.$templates->get('index').'";');
output_page($index);