-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathforum.php
367 lines (315 loc) · 13.6 KB
/
forum.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
<?php
require_once 'lib/function.php';
$id = intval($_GET['id'] ?? null);
$user = intval($_GET['user'] ?? null);
$thread = intval($_GET['thread'] ?? null);
$fav = intval($_GET['fav'] ?? null);
$act = $_GET['act'] ?? null;
if ($log)
$postread = $sql->getresultsbykey("SELECT forum,readdate FROM forumread WHERE user=$loguserid", 'forum', 'readdate');
$forumlist="";
$fonline="";
// Add/remove favorites
if ($act == 'add' || $act == 'rem') {
$meta['noindex'] = true; // prevent search engines from indexing
$t = $sql->fetchq("SELECT title,forum FROM threads WHERE id=$thread");
if (!$log) {
require_once 'lib/layout.php';
errorpage("You need to be logged in to edit your favorites!",'return to the forum',"forum.php?id=$t[forum]");
}
$sql->query("DELETE FROM favorites WHERE user=$loguserid AND thread=$thread");
if ($act == 'add') {
$tx = "\"$t[title]\" has been added to your favorites.";
$minpower = $sql->resultq("SELECT minpower FROM forums WHERE id=$t[forum]");
if($minpower < 1 || $minpower <= $power)
$sql->query("INSERT INTO favorites (user,thread) VALUES ($loguserid,$thread)");
else
$tx = "You can't favorite a thread you don't have access to!";
}
else
$tx = "\"$t[title]\" has been removed from your favorites.";
require_once 'lib/layout.php';
errorpage($tx,'return to the forum',"forum.php?id=$t[forum]");
}
// Forum Setup
if ($fav) {
if (!$log) {
$meta['noindex'] = true; // prevent search engines from indexing what they can't access
require_once 'lib/layout.php';
errorpage("You need to be logged in to view your favorites.",'log in (then try again)','login.php');
}
$forum['title'] = 'Favorites';
if ($user && $user != $loguserid && $isadmin)
$forum['title'] .= ' of '.$sql->resultq("SELECT name FROM users WHERE id={$user}");
else
$user = $loguserid;
$threadcount = $sql->resultq("SELECT COUNT(*) FROM favorites where user={$user}");
}
elseif ($user) {
$user1=$sql->fetchq("SELECT name,sex,powerlevel,aka,birthday FROM users WHERE id={$user}");
if (!$user1) {
$meta['noindex'] = true; // prevent search engines from indexing what they can't access
require_once 'lib/layout.php';
errorpage("No user with that ID exists.",'the index page','index.php');
}
$forum['title']="Threads by $user1[name]";
$threadcount = $sql->resultq("SELECT COUNT(*) FROM threads where user=$user");
}
elseif ($id) { # Default case, show forum with id
$id = intval($id);
$forum = $sql->fetchq("SELECT title,minpower,numthreads,specialscheme,pollstyle FROM forums WHERE id=$id");
if (!$forum) {
trigger_error("Attempted to access invalid forum $id", E_USER_NOTICE);
$meta['noindex'] = true; // prevent search engines from indexing what they can't access
require_once 'lib/layout.php';
notAuthorizedError();
}
elseif ($forum['minpower'] > max(0,$power)) {
if ($log)
trigger_error("Attempted to access level-$forum[minpower] restricted forum $id (user's powerlevel: ".intval($loguser['powerlevel']).")", E_USER_NOTICE);
$meta['noindex'] = true; // prevent search engines from indexing what they can't access
require_once 'lib/layout.php';
notAuthorizedError();
}
else
$specialscheme=$forum['specialscheme'];
global $fourmid;
$forumid=$id;
$threadcount = $forum['numthreads'];
}
else {
$meta['noindex'] = true; // prevent search engines from indexing what they can't access
require_once 'lib/layout.php';
errorpage("No forum specified.",'the index page',"index.php");
}
$windowtitle = "$boardname -- $forum[title]";
require 'lib/layout.php';
$hotcount = $sql->resultq('SELECT hotcount FROM misc',0,0);
if ($hotcount <= 0) $hotcount = 0xFFFF;
$ppp = intval($_GET['ppp'] ?? ($loguser['postsperpage'] ?? 20));
$ppp = max(min($ppp, 500), 1);
$tpp = intval($_GET['tpp'] ?? ($loguser['threadsperpage'] ?? 50));
$tpp = max(min($tpp, 500), 1);
$page = intval($_GET['page'] ?? 0);
$min = $page * $tpp;
$newthreadbar = $forumlist = '';
if ($id) {
$forumlist = doforumlist($id);
$fonline = fonlineusers($id);
if($log) {
$headlinks.=" - <a href=index.php?action=markforumread&forumid=$id>Mark forum read</a>";
$header = makeheader($header1,$headlinks,$header2 .(($fonline) ? "$tblstart$tccell1s>$fonline$tblend" : ""));
}
$newthreadbar =
"<td align=right class=fonts>".
(($forum['pollstyle'] != -2) ? "<a href=newthread.php?poll=1&id=$id>$newpollpic</a>" : "<img src=\"images/nopolls.png\" align=\"absmiddle\">")
." - <a href=newthread.php?id=$id>$newthreadpic</a></td>";
}
$infotable =
"<table width=100%><tr>
<td align=left class='font'><a href=index.php>$boardname</a> - $forum[title]</td>
$newthreadbar
</tr></table>";
$forumpagelinks = '';
if($threadcount > $tpp){
$query = ($id ? "id=$id" : ($user ? "user=$user" : "fav=1"));
if ($_GET['tpp'] ?? null) $query .= "&tpp=$tpp";
$forumpagelinks = "<table width=100%><tr>
<td align=left class='fonts'>Pages:";
for($k=0;$k<($threadcount/$tpp);$k++)
$forumpagelinks .= ($k!=$page ? " <a href='?$query&page=$k'>".($k+1).'</a>':' '.($k+1));
$forumpagelinks .= "</td></tr></table>";
}
$threadlist = "{$tblstart}";
// Announcements
if ($id) {
if($annc = $sql->fetchq('SELECT announcements.id aid,user id,date,announcements.title,name,sex,powerlevel FROM announcements,users WHERE forum=0 AND user=users.id ORDER BY date DESC LIMIT 1')) {
$userlink = getuserlink($annc);
$threadlist .= "<tr>
<td colspan=7 class='tbl tdbgh center fonts'>Announcements</td>
</tr><tr>
$tccell2>". ($loguser['lastannouncement'] < $annc['aid'] && $loguser['id'] ? $newpic : " ") ."</td>
$tccell1l colspan=6><a href=announcement.php>$annc[title]</a> -- Posted by {$userlink} on ".date($dateformat,$annc['date']+$tzoff)."</td>
</tr>";
}
if($annc = $sql->fetchq("SELECT user id,date,announcements.title,name,sex,powerlevel FROM announcements,users WHERE forum=$id AND user=users.id ORDER BY date DESC LIMIT 1")) {
$userlink = getuserlink($annc);
$threadlist .= "<tr>
$tccellhs colspan=7>Forum announcements</td>
</tr><tr>
$tccell2> </td>
$tccell1l colspan=6><a href=announcement.php?f=$id>$annc[title]</a> -- Posted by {$userlink} on ".date($dateformat,$annc['date']+$tzoff)."</td>
</tr>";
}
}
// Forum names
else
$forumnames = $sql->getresultsbykey("SELECT id,title FROM forums WHERE minpower <= ".intval($loguser['powerlevel']), 'id', 'title');
// Get threads
if($fav)
$threads = $sql->query("SELECT t.*, minpower,f.id as forumid, "
."u1.name AS name1, u1.sex AS sex1, u1.powerlevel AS pwr1, u1.aka as aka1, u1.birthday as bd1,"
."u2.name AS name2, u2.sex AS sex2, u2.powerlevel AS pwr2, u2.aka as aka2, u2.birthday as bd2 "
.($log ? ", r.read AS tread, r.time as treadtime " : " ")
."FROM threads t "
.($log ? "LEFT JOIN threadsread r ON (t.id=r.tid AND r.uid=$loguserid) " : "")
.",users u1,users u2,forums f,favorites fav "
."WHERE u1.id=t.user "
."AND u2.id=t.lastposter "
."AND fav.thread=t.id "
."AND fav.user={$user} "
."AND f.id=t.forum "
."ORDER BY sticky DESC,lastpostdate DESC "
."LIMIT $min,$tpp");
elseif($user)
$threads = $sql->query("SELECT t.*, minpower, f.id as forumid, "
."'".addslashes($user1['name'])."' AS name1, {$user1['sex']} AS sex1, {$user1['powerlevel']} AS pwr1, '"
.addslashes($user1['aka'])."' as aka1, {$user1['birthday']} as bd1, "
."name AS name2, sex AS sex2, powerlevel AS pwr2, aka as aka2, birthday as bd2"
.($log ? ", r.read AS tread, r.time as treadtime " : " ")
."FROM threads t "
.($log ? "LEFT JOIN threadsread r ON (t.id=r.tid AND r.uid=$loguserid) " : "")
.",users u,forums f "
."WHERE t.user=$user "
."AND u.id=t.lastposter "
."AND f.id=t.forum "
."ORDER BY sticky DESC,lastpostdate DESC "
."LIMIT $min,$tpp");
else
$threads = $sql->query("SELECT t.*,"
."u1.name AS name1, u1.sex AS sex1, u1.powerlevel AS pwr1, u1.aka as aka1, u1.birthday as bd1,"
."u2.name AS name2, u2.sex AS sex2, u2.powerlevel AS pwr2, u2.aka as aka2, u2.birthday as bd2 "
.($log ? ", r.read AS tread, r.time as treadtime " : " ")
."FROM threads t "
.($log ? "LEFT JOIN threadsread r ON (t.id=r.tid AND r.uid=$loguserid) " : "")
.",users u1,users u2 "
."WHERE forum=$id "
."AND u1.id=t.user "
."AND u2.id=t.lastposter "
."ORDER BY sticky DESC,lastpostdate DESC "
."LIMIT $min,$tpp");
$threadlist .= "<tr>
$tccellh width=30></td>
$tccellh colspan=2 width=*> Thread</td>
$tccellh width=14%>Started by</td>
$tccellh width=60> Replies</td>
$tccellh width=60> Views</td>
$tccellh width=150> Last post</td>
</tr>";
$sticklast = 0;
if (mysql_num_rows($threads) <= 0) {
$threadlist .= "<tr>
$tccell1 style='font-style:italic;' colspan=7>There are no threads to display.</td>
</td></tr>";
}
else for($i=1; $thread=@$sql->fetch($threads, MYSQL_ASSOC); ++$i) {
if($sticklast && !$thread['sticky'])
$threadlist .= "<tr>$tccellh colspan=7><img src='images/_.gif' height=6 width=6>";
$sticklast = $thread['sticky'];
if(!$id && $thread['minpower'] > max(0,$power)) {
$threadlist .= "<tr>$tccell2s colspan=7>(restricted)</td></tr>";
continue;
}
// Disabled polls
if (($forum['pollstyle'] ?? 0) == -2)
$thread['poll'] = 0;
$new = " ";
$newpost = false;
$threadstatus = "";
// Forum, logged in
if ($log && $id && $thread['lastpostdate']>$postread[$id] && !$thread['tread']) {
$threadstatus .= "new";
$newpost = true;
$newpostt = ($thread['treadtime'] ? $thread['treadtime'] : $postread[$id]);
}
// User's thread list / Favorites, logged in
elseif ($log && !$id && $thread['lastpostdate']>$postread[$thread['forumid']] && !$thread['tread']) {
$threadstatus .= "new";
$newpost = true;
$newpostt = ($thread['treadtime'] ? $thread['treadtime'] : $postread[$thread['forumid']]);
}
// Not logged in
elseif (!$log && $thread['lastpostdate']>ctime()-3600) {
$threadstatus .= "new";
$newpost = true;
$newpostt = ctime() - 3600;
}
if ($thread['replies'] >= $hotcount) $threadstatus .= "hot";
if ($thread['closed']) $threadstatus .= "off";
if ($threadstatus) $new = $statusicons[$threadstatus];
$posticon="<img src='$thread[icon]'>";
if (trim($thread['title']) == "")
$thread['title'] = "<i>hurr durr i'm an idiot who made a blank thread</i>";
else
$thread['title'] = str_replace(array('<', '>'), array('<', '>'), trim($thread['title']));
$threadtitle = "<a href='thread.php?id=$thread[id]'>$thread[title]</a>";
$belowtitle = array(); // An extra line below the title in certain circumstances
$sicon = "";
if ($thread['sticky']) {
$threadtitle = "<i>". $threadtitle ."</i>";
$sicon .= "sticky";
}
if ($thread['poll']) $sicon .= "poll";
if ($sicon)
$threadtitle = $statusicons[$sicon] ." ". $threadtitle;
// Show forum name if not in a forum
if (!$id)
$belowtitle[] = "In <a href='forum.php?id=$thread[forumid]'>".$forumnames[$thread['forumid']]."</a>";
// Extra pages
if($thread['replies']>=$ppp) {
$pagelinks='';
$maxfromstart = (($loguser['pagestyle']) ? 9 : 4);
$maxfromend = (($loguser['pagestyle']) ? 20 : 10);
$totalpages = ceil(($thread['replies']+1)/$ppp);
for($k=0; $k < $totalpages; $k++) {
if ($totalpages >= ($maxfromstart+$maxfromend+1) && $k > $maxfromstart && $k < ($totalpages - $maxfromend)) {
$k = ($totalpages - $maxfromend);
$pagelinks .= " ...";
}
$pagelinks.=" <a href='thread.php?id=$thread[id]&page=$k'>".($k+1).'</a>';
}
if ($loguser['pagestyle'])
$belowtitle[] = "Page:{$pagelinks}";
else
$threadtitle .= " <span class='pagelinks fonts'>(Pages:{$pagelinks})</span>";
}
if (!empty($belowtitle))
$secondline = '<br><span class="fonts" style="position: relative; top: -1px;"> ' . implode(' - ', $belowtitle) . '</span>';
else
$secondline = '';
if(!$thread['icon']) $posticon=' ';
$userlink1 = getuserlink($thread,
array('sex'=>'sex1', 'powerlevel'=>'pwr1', 'id'=>'user', 'aka'=>'aka1', 'name'=>'name1', 'birthday'=>'bd1'));
$userlink2 = getuserlink($thread,
array('sex'=>'sex2', 'powerlevel'=>'pwr2', 'id'=>'lastposter', 'aka'=>'aka2', 'name'=>'name2', 'birthday'=>'bd2'));
$threadlist .= "<tr>
$tccell1>$new</td>
$tccell2 width=40px><div style=\"max-width:60px;max-height:30px;overflow:hidden;\">$posticon</div></td>
$tccell2l>". ($newpost ? "<a href='thread.php?id=$thread[id]&lpt=". $newpostt ."'>". $statusicons['getnew'] ."</a> " : "") ."$threadtitle$secondline</td>
$tccell2>{$userlink1}</td>
$tccell1>$thread[replies]</td>
$tccell1>$thread[views]</td>
$tccell2><div class='lastpost'>".date($dateformat,$thread['lastpostdate']+$tzoff)."<br>
by {$userlink2}
<a href='thread.php?id=$thread[id]&end=1'>$statusicons[getlast]</a>
</div></td></tr>";
}
$threadlist .= "{$tblend}";
print "
{$header}
{$infotable}
{$forumpagelinks}
{$threadlist}
{$forumpagelinks}
{$infotable}
{$forumlist}
{$footer}
";
printtimedif($startingtime);
function notAuthorizedError() {
global $log;
$rreason = (($log) ? 'don\'t have access to it' : 'are not logged in');
$redir = (($log) ? 'index.php' : 'login.php');
$rtext = (($log) ? 'the index page' : 'log in (then try again)');
errorpage("Couldn't enter this restricted forum, as you {$rreason}.", $rtext, $redir);
}