-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.php
338 lines (281 loc) · 11.9 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
<?php
if (isset($_GET['u']) && $_GET['u']) {
header("Location: profile.php?id=". $_GET['u']);
die();
} elseif (isset($_GET['p']) && $_GET['p']) {
header("Location: thread.php?pid=". $_GET['p'] ."#". $_GET['p']);
die();
} elseif (isset($_GET['t']) && $_GET['t']) {
header("Location: thread.php?id=". $_GET['t']);
die();
}
/*
if ($_GET["letitsnow"]) {
if (!array_key_exists('snowglobe', $_COOKIE)) {
$_COOKIE['snowglobe'] = 1;
}
if (!is_int($_COOKIE['snowglobe'])) {
die("no.");
}
if ($_COOKIE['snowglobe'] == 0) {
$_COOKIE['snowglobe'] = 1;
} elseif ($_COOKIE['snowglobe'] == 1) {
$_COOKIE['snowglobe'] = 0;
}
header("Location: /index.php");
}
*/
require 'lib/function.php';
require 'lib/layout.php';
if (false && $x_hacks['smallbrowse'] == 1) {
require 'mobile/index.php'; // alternate markup for mobile clients.
} else {
if (filter_string($_GET['action']) == 'markforumread' and $log) {
$sql->query("DELETE FROM forumread WHERE user=$loguserid AND forum='$forumid'");
$sql->query("DELETE FROM `threadsread` WHERE `uid` = '$loguserid' AND `tid` IN (SELECT `id` FROM `threads` WHERE `forum` = '$forumid')");
$sql->query("INSERT INTO forumread (user,forum,readdate) VALUES ($loguserid,$forumid,".ctime().')');
return header("Location: index.php");
}
if (filter_string($_GET['action']) == 'markallforumsread' and $log) {
$sql->query("DELETE FROM forumread WHERE user=$loguserid");
$sql->query("DELETE FROM `threadsread` WHERE `uid` = '$loguserid'");
$sql->query("INSERT INTO forumread (user,forum,readdate) SELECT $loguserid,id,".ctime().' FROM forums');
return header("Location: index.php");
}
$postread = readpostread($loguserid);
$users1 = $sql->query("SELECT id,name,birthday,sex,powerlevel,aka FROM users WHERE FROM_UNIXTIME(birthday,'%m-%d')='".date('m-d',ctime() + $tzoff)."' AND birthday ORDER BY name");
$blist = "";
for ($numbd=0;$user=$sql->fetch($users1);$numbd++) {
if(!$numbd) $blist="<tr>$tccell2s colspan=5>Birthdays for ".date('F j',ctime() + $tzoff).': ';
else $blist.=', ';
$users[$user['id']]=$user;
$y=date('Y',ctime())-date('Y',$user['birthday']);
$userurl = getuserlink($user);
$blist.= "$userurl ($y)";
}
$onlinetime=ctime()-300;
$onusers=$sql->query("SELECT id,name,powerlevel,lastactivity,sex,minipic,aka,birthday FROM users WHERE lastactivity>$onlinetime OR lastposttime>$onlinetime ORDER BY name");
$numonline=mysql_num_rows($onusers);
$numguests=$sql->resultq("SELECT count(*) FROM guests WHERE date>$onlinetime",0,0);
if ($numguests) $guestcount=" | <nobr>$numguests guest".($numguests>1?"s":"");
$onlineusersa = array();
for ($numon=0; $onuser = $sql->fetch($onusers);$numon++) {
//$namecolor=explode("=", getnamecolor($onuser['sex'],$onuser['powerlevel']));
//$namecolor=$namecolor[1];
//$namelink="<a href=profile.php?id=$onuser[id] style='color: #$namecolor'>$onuser[name]</a>";
$namelink = getuserlink($onuser);
if($onuser['minipic']) {
$onuser['minipic']='<img width="16" height="16" src="'.str_replace('"','%22',$onuser['minipic']).'" align="absmiddle"> ';
}
if($onuser['lastactivity']<=$onlinetime) {
$namelink="($namelink)";
}
$onlineusersa[]="$onuser[minipic]$namelink";
}
$onlineusers = "";
if ($onlineusersa) $onlineusers = ': '. implode(", ", $onlineusersa);
$logmsg = "";
if($log){
$headlinks.=' - <a href=index.php?action=markallforumsread>Mark all forums read</a>';
$header=makeheader($header1,$headlinks,$header2);
$myurl = getuserlink($loguser);
$logmsg = "You are logged in as $myurl.";
}
$lastuser = $sql->fetchq('SELECT id,name,sex,powerlevel,aka,birthday FROM users ORDER BY id DESC LIMIT 1');
$lastuserurl = getuserlink($lastuser);
$posts = $sql->fetchq('SELECT (SELECT COUNT( * ) FROM posts WHERE date>'.(ctime()-3600).') AS h, (SELECT COUNT( * ) FROM posts WHERE date>'.(ctime()-86400).') AS d');
$count = $sql->fetchq('SELECT (SELECT COUNT( * ) FROM users) AS u, (SELECT COUNT(*) FROM threads) as t, (SELECT COUNT(*) FROM posts) as p');
$misc = $sql->fetchq('SELECT * FROM misc');
if($posts['d']>$misc['maxpostsday']) $sql->query("UPDATE misc SET maxpostsday=$posts[d],maxpostsdaydate=".ctime());
if($posts['h']>$misc['maxpostshour']) $sql->query("UPDATE misc SET maxpostshour=$posts[h],maxpostshourdate=".ctime());
if($numonline>$misc['maxusers']) $sql->query("UPDATE misc SET maxusers=$numonline,maxusersdate=".ctime().",maxuserstext='".addslashes($onlineusers)."'");
/*// index sparkline
$sprkq = mysql_query('SELECT COUNT(id),date FROM posts WHERE date >="'.(time()-3600).'" GROUP BY (date % 60) ORDER BY date');
$sprk = array();
while ($r = mysql_fetch_row($sprkq)) {
array_push($sprk,$r[0]);
}
// print_r($sprk);
$sprk = implode(",",$sprk); */
if (filter_bool($_GET['oldcounter']))
$statsblip = "$posts[d] posts during the last day, $posts[h] posts during the last hour.";
else {
$nthreads = $sql->resultq("SELECT COUNT(*) FROM `threads` WHERE `lastpostdate` > '". (ctime() - 86400) ."'");
$nusers = $sql->resultq("SELECT COUNT(*) FROM `users` WHERE `lastposttime` > '". (ctime() - 86400) ."'");
$tthreads = ($nthreads === 1) ? "thread" : "threads";
$tusers = ($nusers === 1) ? "user" : "users";
$statsblip = "$nusers $tusers active in $nthreads $tthreads during the last day.";
}
print "$header
<br>
$tblstart
$tccell1s><table width=100%><td>$logmsg</td><td align=right>$count[u] registered users<br>Latest registered user: $lastuserurl</table>
$blist<tr>
$tccell2s>$count[t] threads and $count[p] posts in the board | $statsblip<tr>
$tccell1s>$numonline user".($numonline!=1?'s':'')." currently online$onlineusers$guestcount
";
// Displays total PMs along with unread unlike layout.php
$new = ' ';
if($log) {
$pms = $sql->getresultsbykey("SELECT msgread, COUNT(*) num FROM pmsgs WHERE userto=$loguserid GROUP BY msgread", 'msgread', 'num');
$pms[0] = intval($pms[0] ?? 0); // unread
$pms[1] = intval($pms[1] ?? 0); // read
$totalpms = $pms[0] + $pms[1];
if ($totalpms) {
if ($pms[0]) $new = $statusicons['new'];
$pmsg = $sql->fetchq("SELECT date,u.id uid,name,sex,powerlevel,aka
FROM pmsgs p LEFT JOIN users u ON u.id=p.userfrom
WHERE userto=$loguserid". ($pms[0] ? " AND msgread=0": "") ."
ORDER BY p.id DESC
LIMIT 1");
$namelink = getuserlink($pmsg, array('id'=>'uid'));
$lastmsg = "Last ". (($pms[0]) ? "unread " : "") ."message from $namelink on ".date($dateformat,$pmsg['date']+$tzoff);
}
$privatebox="
$tblstart<tr>
$tccellhs colspan=2>Private messages</tr><tr>
$tccell1>$new</td>
$tccell2l><a href='private.php'>Private messages</a> -- You have $totalpms private messages (".intval($pms[0])." new). $lastmsg</td></tr>
$tblend<br>
";
}
// Display recent active threads
// Part of this was lifted from latestposts.php and tweaked to show threads instead of posts
$data = $sql->query("
SELECT
t.id as id,
t.lastposter,
t.lastpostdate as date,
f.title as ftitle,
t.forum as fid,
t.title as title,
u.id as user,
u.name as uname,
u.sex as usex,
u.powerlevel as upowerlevel
FROM `threads` t
LEFT JOIN `forums` f ON t.forum = f.id
LEFT JOIN `users` u ON t.lastposter = u.id
WHERE f.minpower <= '". $loguser['powerlevel'] ."' AND f.id <> 99 /* heh */
ORDER BY t.lastpostdate DESC
LIMIT 5
");
$recent_threads = "
$tblstart
<tr>
$tccellc colspan='4'><a href='latestposts.php'>Recently active threads</a>
</tr>
<tr>
$tccellh width='25%'>Forum
$tccellh width='45%'>Thread
$tccellh width='20%'>User
$tccellh width='10%'>Time
</tr>
";
while ($in = $sql->fetch($data, MYSQL_ASSOC)) {
$recent_threads .= "<tr>
$tccell2><a href='forum.php?id=". $in['fid'] ."'>". $in['ftitle'] ."</a></td>
$tccell1l><a href='thread.php?id=". $in['id'] ."&end=1'>". $in['title'] ."</a></td>
$tccell1><a href='profile.php?id=". $in['user'] ."'><font ". getnamecolor($in['usex'], $in['upowerlevel']) .">". $in['uname'] ."</font></a></td>
$tccell2>". timeunits(ctime() - $in['date']) ."</td>
</tr>\n";
}
$recent_threads .= "
$tblend<br>";
// Hopefully this version won't break horribly if breathed on wrong
$forumlist="
<tr>
$tccellh> </td>
$tccellh>Forum</td>
$tccellh width=80>Threads</td>
$tccellh width=80>Posts</td>
$tccellh width=15%>Last post</td>
</tr>
";
$forumquery = $sql->query("SELECT f.*,u.id AS uid,name,sex,powerlevel,aka,birthday FROM forums f LEFT JOIN users u ON f.lastpostuser=u.id WHERE (!minpower OR minpower<=$power) AND f.hidden = '0' ORDER BY catid,forder");
$catquery = $sql->query("SELECT id,name FROM categories WHERE (!minpower OR minpower<=$power) ORDER BY id");
$modquery = $sql->query("SELECT u.id id,name,sex,powerlevel,aka,forum,birthday FROM users u INNER JOIN forummods m ON u.id=m.user ORDER BY name");
$categories = array();
$forums = array();
$mods = array();
while ($res = $sql->fetch($catquery))
$categories[] = $res;
while ($res = $sql->fetch($forumquery))
$forums[] = $res;
while ($res = $sql->fetch($modquery))
$mods[] = $res;
// Quicker (?) new posts calculation that's hopefully accurate v.v
if ($log) {
$qadd = array();
foreach ($forums as $forum) $qadd[] = "(lastpostdate > '{$postread[$forum['id']]}' AND forum = '{$forum['id']}')\r\n";
$qadd = implode(' OR ', $qadd);
$forumnew = $sql->getresultsbykey("SELECT forum, COUNT(*) AS unread FROM threads t LEFT JOIN threadsread tr ON (tr.tid = t.id AND tr.uid = $loguser[id])
WHERE (`read` IS NULL OR `read` != 1) AND ($qadd) GROUP BY forum", 'forum', 'unread');
}
$cat = filter_int($_GET['cat']);
foreach ($categories as $category) {
$forumlist.="<tr><td class='tbl tdbgc center font' colspan=5><a href=index.php?cat=$category[id]>$category[name]</a></td></tr>";
if($cat && $cat != $category['id'])
continue;
foreach ($forums as $forumplace => $forum) {
if ($forum['catid'] != $category['id'])
continue;
$m = 0;
$modlist = "";
foreach ($mods as $modplace => $mod) {
if ($mod['forum'] != $forum['id'])
continue;
$namelink = getuserlink($mod);
$modlist.=($m++?', ':'').$namelink;
unset($mods[$modplace]);
}
if ($m)
$modlist="(moderated by: $modlist)";
$namelink = getuserlink($forum, array('id'=>'uid'));
if($forum['numposts']){
$forumlastpost="<nobr>". date($dateformat,$forum['lastpostdate']+$tzoff);
$by="$smallfont<br>by $namelink". ($forum['lastpostid'] ? " <a href='thread.php?pid=". $forum['lastpostid'] ."#". $forum['lastpostid'] ."'>". $statusicons['getlast'] ."</a>" : "") ."</nobr></font>";
} else {
$forumlastpost=getblankdate();
$by='';
}
$new=' ';
if ($forum['numposts']) {
if ($log && intval($forumnew[$forum['id']] ?? 0) > 0) {
$new = $statusicons['new'] ."<br>". generatenumbergfx(intval($forumnew[$forum['id']]));
}
elseif (!$log && $forum['lastpostdate']>ctime()-3600) {
$new = $statusicons['new'];
}
}
/*
if ($log && $forum['lastpostdate'] > $postread[$forum['id']]) {
$newcount = $sql->resultq("SELECT COUNT(*) FROM `threads` WHERE `id` NOT IN (SELECT `tid` FROM `threadsread` WHERE `uid` = '$loguser[id]' AND `read` = 1) AND `lastpostdate` > '". $postread[$forum['id']] ."' AND `forum` = '$forum[id]'");
}
if ((($forum['lastpostdate'] > $postread[$forum['id']] and $log) or (!$log and $forum['lastpostdate']>ctime()-3600)) and $forum['numposts']) {
$new = $statusicons['new'] ."<br>". generatenumbergfx($newcount);
}
*/
$forumlist.="
<tr>
$tccell1>$new</td>
$tccell2l><a href=forum.php?id=$forum[id]>$forum[title]</a><br>
$smallfont$forum[description]<br>$modlist</td>
$tccell1>$forum[numthreads]</td>
$tccell1>$forum[numposts]</td>
$tccell2><span class='lastpost'>$forumlastpost</span> $by
</tr>
";
unset($forums[$forumplace]);
}
}
print "
$tblend
<br>$privatebox
$recent_threads
$tblstart
$forumlist
$tblend
$footer";
printtimedif($startingtime);
}