-
Notifications
You must be signed in to change notification settings - Fork 0
/
forums.php
1327 lines (1134 loc) · 54.4 KB
/
forums.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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
//
// TorrentTrader v2.x
// $LastChangedDate: 2011-12-05 21:01:28 +0000 (Mon, 05 Dec 2011) $
// $LastChangedBy: nikkbu $
//
// http://www.torrenttrader.org
//
//
require_once("backend/functions.php");
require_once("backend/bbcode.php");
dbconn(false);
if (!$site_config["FORUMS_GUESTREAD"])
loggedinonly();
function showerror($heading = "Error", $text, $sort = "Error") {
stdhead("$sort: $heading");
begin_frame("<span class='error'>$sort: $heading</span>");
echo $text;
end_frame();
stdfoot();
die;
}
$action = strip_tags($_REQUEST["action"]);
if (!$CURUSER && ($action == "newtopic" || $action == "post"))
showerror("Forum error", "No Forum ID");
if ($CURUSER["forumbanned"] == "yes" || $CURUSER["view_forum"] == "no")
showerror("Forum Banned", T_("FORUM_BANNED"));
//Here we decide if the forums is on or off
if ($site_config["FORUMS"]) {
$themedir = "themes/".$THEME."/forums/";
//setup the forum head aread
function forumheader($location){
echo "<div class='f-header'>
<div class='f-logo'>
<table width='100%' border='0'>
<tr>
<td align='left' valign='top'><a href='forums.php'>".T_("FORUM_WELCOME")."</a></td>
<td align='right' valign='top'><img src='images/forum/help.png' alt='' /> <a href='faq.php'>".T_("FORUM_FAQ")."</a> <img src='images/forum/search.png' alt='' /> <a href='forums.php?action=search'>".T_("FORUM_SEARCH")."</a></td>
</tr>
<tr>
<td align='left' valign='bottom'> </td>
<td align='right' valign='bottom'><b>".T_("FORUM_CONTROL")."</b> · <a href='forums.php?action=viewunread'>".T_("FORUM_NEW_POSTS")."</a> · <a href='?catchup'>".T_("FORUM_MARK_READ")."</a></td>
</tr>
</table>
</div>
</div>
<br />";
print ("<div class='f-location'>".T_("FORUM_WHERE").": <a href='forums.php'>".T_("FORUM_FORUM")."</a> <b style='vertical-align:middle'>/ $location</b></div>");
}
// Mark all forums as read
function catch_up(){
global $CURUSER;
if (!$CURUSER)
return;
$userid = $CURUSER["id"];
$res = SQL_Query_exec("SELECT id, lastpost FROM forum_topics");
while ($arr = mysql_fetch_assoc($res)) {
$topicid = $arr["id"];
$postid = $arr["lastpost"];
$r = SQL_Query_exec("SELECT id,lastpostread FROM forum_readposts WHERE userid=$userid and topicid=$topicid");
if (mysql_num_rows($r) == 0){
SQL_Query_exec("INSERT INTO forum_readposts (userid, topicid, lastpostread) VALUES($userid, $topicid, $postid)");
}else{
$a = mysql_fetch_assoc($r);
if ($a["lastpostread"] < $postid)
SQL_Query_exec("UPDATE forum_readposts SET lastpostread=$postid WHERE id=" . $a["id"]);
}
}
}
// Returns the minimum read/write class levels of a forum
function get_forum_access_levels($forumid){
$res = SQL_Query_exec("SELECT minclassread, minclasswrite FROM forum_forums WHERE id=$forumid");
if (mysql_num_rows($res) != 1)
return false;
$arr = mysql_fetch_assoc($res);
return array("read" => $arr["minclassread"], "write" => $arr["minclasswrite"]);
}
// Returns the forum ID of a topic, or false on error
function get_topic_forum($topicid) {
$res = SQL_Query_exec("SELECT forumid FROM forum_topics WHERE id=$topicid");
if (mysql_num_rows($res) != 1)
return false;
$arr = mysql_fetch_row($res);
return $arr[0];
}
// Returns the ID of the last post of a forum
function update_topic_last_post($topicid) {
$res = SQL_Query_exec("SELECT id FROM forum_posts WHERE topicid=$topicid ORDER BY id DESC LIMIT 1");
$arr = mysql_fetch_row($res) or showerror("Forum error", "No post found");
$postid = $arr[0];
SQL_Query_exec("UPDATE forum_topics SET lastpost=$postid WHERE id=$topicid");
}
function get_forum_last_post($forumid) {
$res = SQL_Query_exec("SELECT lastpost FROM forum_topics WHERE forumid=$forumid ORDER BY lastpost DESC LIMIT 1");
$arr = mysql_fetch_row($res);
$postid = $arr[0];
if ($postid)
return $postid;
else
return 0;
}
//Top forum posts
function forumpostertable($res) {
print("<br /><table align='center' width='160'><tr><td>\n");
print("<table cellpadding='3' cellspacing='0' class='ttable_headinner' width='100%'>");
?>
<tr>
<th class='ttable_head' width='10' align='center'>
<font size='1'><?php echo T_("FORUM_RANK"); ?></font>
</th>
<th class='ttable_head' width='130' align='center'>
<font size='1'><?php echo T_("FORUM_USER"); ?></font>
</th>
<th class='ttable_head' width='10' align='center'>
<font size='1'><?php echo T_("FORUM_POST"); ?></font>
</th>
</tr>
<?php
$num = 0;
while ($a = mysql_fetch_assoc($res))
{
++$num;
print("<tr class='t-row'><td align='center' class='ttable_col1'>$num</td><td class='ttable_col2' style='text-align: justify'><a href='account-details.php?id=$a[id]'><b>$a[username]</b></a></td><td align='center' class='ttable_col1'>$a[num]</td></tr>\n");
}
if ($num == 0)
print("<tr class='t-row'><td align='center' class='ttable_col1' colspan='3'><b>No Forum Posters</b></td></tr>");
print("</table>");
print("</td></tr></table>\n");
}
// Inserts a quick jump menu
function insert_quick_jump_menu($currentforum = 0) {
print("<div class='f-form' style='text-align:right'><form class='f-form' method='get' action='?' name='jump'>\n");
print("<input type='hidden' name='action' value='viewforum' />\n");
$res = SQL_Query_exec("SELECT * FROM forum_forums ORDER BY name");
if ( mysql_num_rows($res) > 0 )
{
print( T_("FORUM_JUMP") . ": ");
print("<select class='styled' name='forumid' onchange='if(this.options[this.selectedIndex].value != -1){ forms[jump].submit() }'>\n");
while ($arr = mysql_fetch_assoc($res))
{
if (get_user_class() >= $arr["minclassread"] || (!$CURUSER && $arr["guest_read"] == "yes"))
print("<option value='" . $arr["id"] . "'" . ($currentforum == $arr["id"] ? " selected='selected'>" : ">") . $arr["name"] . "</option>\n");
}
print("</select>\n");
print("<input type='submit' value='".T_("FORUM_GO")."' />\n");
}
// print("<input type='submit' value='Go!'>\n");
print("</form>\n</div>");
}
// Inserts a compose frame
function insert_compose_frame($id, $newtopic = true) {
global $maxsubjectlength;
if ($newtopic) {
$res = SQL_Query_exec("SELECT name FROM forum_forums WHERE id=$id");
$arr = mysql_fetch_assoc($res) or showerror("Forum error", "Bad forum id");
$forumname = stripslashes($arr["name"]);
print("<p align='center'><b>".T_("FORUM_NEW_TOPIC")." <a href='forums.php?action=viewforum&forumid=$id'>$forumname</a></b></p>\n");
}else{
$res = SQL_Query_exec("SELECT * FROM forum_topics WHERE id=$id");
$arr = mysql_fetch_assoc($res) or showerror(T_("FORUM_ERROR"), T_("FORUM_TOPIC_NOT_FOUND"));
$subject = stripslashes($arr["subject"]);
print("<p align='center'>".T_("FORUM_REPLY_TOPIC").": <a href='forums.php?action=viewtopic&topicid=$id'>$subject</a></p>");
}
# Language Marker #
print("<p align='center'>Flaming or other anti-social behavior will not be tolerated.\n");
print("<br />Please do try not to discuss upload/release-specific stuff here, post a torrent comment instead!<br /><br /><b>Please make sure to read the <a href='rules.php'>rules</a> before you post</b><br /></p>\n");
#begin_frame("Compose Message", true);
print("<fieldset class='download'>");
print("<legend><b>Compose Message</b></legend>");
print("<div>");
print("<form class='f-form' name='Form' method='post' action='?action=post'>\n");
if ($newtopic)
print("<input type='hidden' name='forumid' value='$id' />\n");
else
print("<input type='hidden' name='topicid' value='$id' />\n");
if ($newtopic){
print("<center><br /><table cellpadding='3' cellspacing='0'><tr><td><strong>Subject:</strong> <input type='text' size='70' maxlength='$maxsubjectlength' name='subject' /></td></tr>");
print("<tr><td align='center'>");
textbbcode("Form", "body");
print("</td></tr><tr><td align='center'><br /><input type='submit' value='Submit' /><br /><br /></td></tr></table>
");
}
print("<br /></center>");
print("</form>\n");
print("</div>");
print("</fieldset><br />");
#end_frame();
insert_quick_jump_menu();
}
//LASTEST FORUM POSTS
function latestforumposts() {
print("<table cellpadding='3' cellspacing='0' class='f-border' width='100%'><tr class='f-title f-border'>".
"<th align='left' width=''>Latest Topic Title</th>".
"<th align='center' width='47'>Replies</th>".
"<th align='center' width='47'>Views</th>".
"<th align='center' width='85'>Author</th>".
"<th align='right' width='150'>Last Post</th>".
"</tr>");
/// HERE GOES THE QUERY TO RETRIEVE DATA FROM THE DATABASE AND WE START LOOPING ///
$for = SQL_Query_exec("SELECT * FROM forum_topics ORDER BY lastpost DESC LIMIT 5");
if (mysql_num_rows($for) == 0)
print("<tr class='f-row f-border'><td class='alt1 f-border' align='center' colspan='5'><b>No Latest Topics</b></td></tr>");
while ($topicarr = mysql_fetch_assoc($for)) {
// Set minclass
$res = SQL_Query_exec("SELECT name,minclassread,guest_read FROM forum_forums WHERE id=$topicarr[forumid]");
$forum = mysql_fetch_assoc($res);
if ($forum && get_user_class() >= $forum["minclassread"] || $forum["guest_read"] == "yes") {
$forumname = "<a href='?action=viewforum&forumid=$topicarr[forumid]'><b>" . htmlspecialchars($forum["name"]) . "</b></a>";
$topicid = $topicarr["id"];
$topic_title = stripslashes($topicarr["subject"]);
$topic_userid = $topicarr["userid"];
// Topic Views
$views = $topicarr["views"];
// End
/// GETTING TOTAL NUMBER OF POSTS ///
$res = SQL_Query_exec("SELECT COUNT(*) FROM forum_posts WHERE topicid=$topicid");
$arr = mysql_fetch_row($res);
$posts = $arr[0];
$replies = max(0, $posts - 1);
/// GETTING USERID AND DATE OF LAST POST ///
$res = SQL_Query_exec("SELECT * FROM forum_posts WHERE topicid=$topicid ORDER BY id DESC LIMIT 1");
$arr = mysql_fetch_assoc($res);
$postid = 0 + $arr["id"];
$userid = 0 + $arr["userid"];
$added = utc_to_tz($arr["added"]);
/// GET NAME OF LAST POSTER ///
$res = SQL_Query_exec("SELECT id, username FROM users WHERE id=$userid");
if (mysql_num_rows($res) == 1) {
$arr = mysql_fetch_assoc($res);
$username = "<a href='account-details.php?id=$userid'>$arr[username]</a>";
}
else
$username = "Unknown[$topic_userid]";
/// GET NAME OF THE AUTHOR ///
$res = SQL_Query_exec("SELECT username FROM users WHERE id=$topic_userid");
if (mysql_num_rows($res) == 1) {
$arr = mysql_fetch_assoc($res);
$author = "<a href='account-details.php?id=$topic_userid'>$arr[username]</a>";
}
else
$author = "Unknown[$topic_userid]";
/// GETTING THE LAST INFO AND MAKE THE TABLE ROWS ///
$r = SQL_Query_exec("SELECT lastpostread FROM forum_readposts WHERE userid=$userid AND topicid=$topicid");
$a = mysql_fetch_row($r);
$new = !$a || $postid > $a[0];
$subject = "<a href='forums.php?action=viewtopic&topicid=$topicid'><b>" . stripslashes(encodehtml($topicarr["subject"])) . "</b></a>";
print("<tr class='f-row f-border'><td class='f-img f-border' style='padding-right: 5px' width='100%'>$subject</td>".
"<td class='alt2 f-border' align='center'>$replies</td>" .
"<td class='alt3 f-border' align='center'>$views</td>" .
"<td class='alt2 f-border' align='center'>$author</td>" .
"<td class='alt3 f-border' align='right'><span class='small'>by $username<br /><span style='white-space: nowrap'>$added</span></span></td>");
print("</tr>");
} // while
}
print("</table><br />");
} // end function
//Global variables
$postsperpage = 20;
$maxsubjectlength = 50;
//Action: New topic
if ($action == "newtopic") {
$forumid = $_GET["forumid"];
if (!is_valid_id($forumid))
showerror("Forum error", "No Forum ID $forumid");
stdhead("New topic");
begin_frame("New topic");
forumheader("Compose New Thread");
insert_compose_frame($forumid);
end_frame();
stdfoot();
die;
}
///////////////////////////////////////////////////////// Action: POST
if ($action == "post") {
$forumid = $_POST["forumid"];
$topicid = $_POST["topicid"];
if (!is_valid_id($forumid) && !is_valid_id($topicid))
showerror("Forum error", "w00t");
$newtopic = $forumid > 0;
$subject = $_POST["subject"];
if ($newtopic) {
if (!$subject)
showerror("Error", "You must enter a subject.");
$subject = trim($subject);
//if (!$subject)
//showerror("Error", "You must enter a subject.");
//showerror("Error", "Subject is limited to $maxsubjectlength characters.");
}else{
$forumid = get_topic_forum($topicid) or showerror("Forum error","Bad topic ID");
}
////// Make sure sure user has write access in forum
$arr = get_forum_access_levels($forumid) or showerror("Forum error","Bad forum ID");
if (get_user_class() < $arr["write"])
showerror("Forum error","Not permitted");
$body = trim($_POST["body"]);
if (!$body)
showerror("Error", "No body text.");
$userid = $CURUSER["id"];
if ($newtopic) { //Create topic
$subject = sqlesc($subject);
SQL_Query_exec("INSERT INTO forum_topics (userid, forumid, subject) VALUES($userid, $forumid, $subject)");
$topicid = mysql_insert_id() or showerror("Forum error","No topic ID returned");
}else{
//Make sure topic exists and is unlocked
$res = SQL_Query_exec("SELECT * FROM forum_topics WHERE id=$topicid");
$arr = mysql_fetch_assoc($res) or showerror("Forum error","Topic id n/a");
if ($arr["locked"] == 'yes')
showerror("Forum error","Topic locked");
//Get forum ID
$forumid = $arr["forumid"];
}
//Insert the new post
$added = "'" . get_date_time() . "'";
$body = sqlesc($body);
SQL_Query_exec("INSERT INTO forum_posts (topicid, userid, added, body) VALUES($topicid, $userid, $added, $body)");
$postid = mysql_insert_id() or showerror("Forum error","Post id n/a");
//Update topic last post
update_topic_last_post($topicid);
//All done, redirect user to the post
$headerstr = "Location: $site_config[SITEURL]/forums.php?action=viewtopic&topicid=$topicid&page=last";
if ($newtopic)
header($headerstr);
else
header("$headerstr#post$postid");
die;
}
///////////////////////////////////////////////////////// Action: VIEW TOPIC
if ($action == "viewtopic") {
$topicid = $_GET["topicid"];
$page = $_GET["page"];
if (!is_valid_id($topicid))
showerror("Forum error","Topic Not Valid");
$userid = $CURUSER["id"];
//------ Get topic info
$res = SQL_Query_exec("SELECT * FROM forum_topics WHERE id=$topicid");
$arr = mysql_fetch_assoc($res) or showerror("Forum error", "Topic not found");
$locked = ($arr["locked"] == 'yes');
$subject = stripslashes($arr["subject"]);
$sticky = $arr["sticky"] == "yes";
$forumid = $arr["forumid"];
// Check if user has access to this forum
$res2 = SQL_Query_exec("SELECT minclassread, guest_read FROM forum_forums WHERE id=$forumid");
$arr2 = mysql_fetch_assoc($res2);
if (!$arr2 || get_user_class() < $arr2["minclassread"] && $arr2["guest_read"] == "no")
show_error_msg("Error: Access Denied","You do not have access to the forum this topic is in.");
// Update Topic Views
$viewsq = SQL_Query_exec("SELECT views FROM forum_topics WHERE id=$topicid");
$viewsa = mysql_fetch_array($viewsq);
$views = $viewsa[0];
$new_views = $views+1;
$uviews = SQL_Query_exec("UPDATE forum_topics SET views = $new_views WHERE id=$topicid");
// End
//------ Get forum
$res = SQL_Query_exec("SELECT * FROM forum_forums WHERE id=$forumid");
$arr = mysql_fetch_assoc($res) or showerror("Forum error", "Forum is empty");
$forum = stripslashes($arr["name"]);
//------ Get post count
$res = SQL_Query_exec("SELECT COUNT(*) FROM forum_posts WHERE topicid=$topicid");
$arr = mysql_fetch_row($res);
$postcount = $arr[0];
//------ Make page menu
$pagemenu = "<br /><span class='small'>\n";
$perpage = $postsperpage;
$pages = floor($postcount / $perpage);
if ($pages * $perpage != $postcount)
++$pages;
if ($page == "last")
$page = $pages;
else {
if($page < 1)
$page = 1;
elseif ($page > $pages)
$page = $pages;
}
$offset = $page * $perpage - $perpage;
//
if ($page == 1)
$pagemenu .= "<b><< Prev</b>";
else
$pagemenu .= "<a href='forums.php?action=viewtopic&topicid=$topicid&page=" . ($page - 1) . "'><b><< Prev</b></a>";
//
$pagemenu .= " ";
for ($i = 1; $i <= $pages; ++$i) {
if ($i == $page)
$pagemenu .= "<b>$i</b>\n";
else
$pagemenu .= "<a href='forums.php?action=viewtopic&topicid=$topicid&page=$i'><b>$i</b></a>\n";
}
//
$pagemenu .= " ";
if ($page == $pages)
$pagemenu .= "<b>Next >></b><br /><br />\n";
else
$pagemenu .= "<a href='forums.php?action=viewtopic&topicid=$topicid&page=" . ($page + 1) . "'><b>Next >></b></a><br /><br />\n";
$pagemenu .= "</span>";
//Get topic posts
$res = SQL_Query_exec("SELECT * FROM forum_posts WHERE topicid=$topicid ORDER BY id LIMIT $offset,$perpage");
stdhead("View Topic: $subject");
begin_frame("$forum > $subject");
forumheader("<a href='forums.php?action=viewforum&forumid=$forumid'>$forum</a> <b style='font-size:16px; vertical-align:middle'>/</b> $subject");
print ("<div style='padding: 6px'>");
$levels = get_forum_access_levels($forumid) or die;
if (get_user_class() >= $levels["write"])
$maypost = true;
else
$maypost = false;
if (!$locked && $maypost){
print ("<div align='right'><a href='#bottom'><img src='". $themedir ."button_reply.png' border='0' alt='' /></a></div>");
}else{
print ("<div align='right'><img src='" . $themedir . "button_locked.png' alt='Locked' /></div>");
}
print ("</div>");
//------ Print table of posts
$pc = mysql_num_rows($res);
$pn = 0;
if ($CURUSER) {
$r = SQL_Query_exec("SELECT lastpostread FROM forum_readposts WHERE userid=$CURUSER[id] AND topicid=$topicid");
$a = mysql_fetch_row($r);
$lpr = $a[0];
if (!$lpr)
SQL_Query_exec("INSERT INTO forum_readposts (userid, topicid) VALUES($userid, $topicid)");
}
while ($arr = mysql_fetch_assoc($res)) {
++$pn;
$postid = $arr["id"];
$posterid = $arr["userid"];
$added = utc_to_tz($arr["added"])."(" . (get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["added"]))) . " ago)";
//---- Get poster details
$res4 = SQL_Query_exec("SELECT COUNT(*) FROM forum_posts WHERE userid=$posterid");
$arr33 = mysql_fetch_row($res4);
$forumposts = $arr33[0];
$res2 = SQL_Query_exec("SELECT * FROM users WHERE id=$posterid");
$arr2 = mysql_fetch_assoc($res2);
$postername = $arr2["username"];
if ($postername == "") {
$by = "Deluser";
$title = "Deleted Account";
$privacylevel = "strong";
$usersignature = "";
$userdownloaded = "0";
$useruploaded = "0";
$avatar = "";
$nposts = "-";
$tposts = "-";
}else{
$avatar = htmlspecialchars($arr2["avatar"]);
$userdownloaded = mksize($arr2["downloaded"]);
$useruploaded = mksize($arr2["uploaded"]);
$privacylevel = $arr2["privacy"];
$usersignature = stripslashes(format_comment($arr2["signature"]));
if ($arr2["downloaded"] > 0) {
$userratio = number_format($arr2["uploaded"] / $arr2["downloaded"], 2);
}else
if ($arr2["uploaded"] > 0)
$userratio = "Inf.";
else
$userratio = "---";
if(!$arr2["country"]){
$usercountry = "unknown";
}else{
$res4 = SQL_Query_exec("SELECT name,flagpic FROM countries WHERE id=$arr2[country] LIMIT 1");
$arr4 = mysql_fetch_assoc($res4);
$usercountry = $arr4["name"];
}
$title = format_comment($arr2["title"]);
$donated = $arr2['donated'];
$by = "<a href='account-details.php?id=$posterid'>$postername</a>" . ($donated > 0 ? "<img src='".$site_config['SITEURL']."/images/star.png' alt='Donated' />" : "") . "";
}
if (!$avatar)
$avatar = $site_config['SITEURL']."/images/default_avatar.gif";
# print("<a name=$postid>\n");
print("<a id='post$postid'></a>");
if ($pn == $pc) {
print("<a name='last'></a>\n");
if ($postid > $lpr && $CURUSER)
SQL_Query_exec("UPDATE forum_readposts SET lastpostread=$postid WHERE userid=$userid AND topicid=$topicid");
}
//working here
//Post Top
print("<div class='f-post' style='padding-bottom:6px'><table cellpadding='3' cellspacing='0' class='f-border' width='100%' ><tr class='p-title f-border'><th width='150'>$by</th><th align='left'><small>Posted at $added </small></th></tr>");
//Post Middle
$body = stripslashes(format_comment($arr["body"]));
if (is_valid_id($arr['editedby'])) {
$res2 = SQL_Query_exec("SELECT username FROM users WHERE id=$arr[editedby]");
if (mysql_num_rows($res2) == 1) {
$arr2 = mysql_fetch_assoc($res2);
//edited by comment out if needed
$body .= "<br /><br /><span class='small'><i>Last edited by <a href='account-details.php?id=$arr[editedby]'>$arr2[username]</b></a> on ".utc_to_tz($arr["editedat"])."</i></span><br />\n";
$body .= "\n";
}
}
$quote = htmlspecialchars($arr["body"]);
$postcount1 = SQL_Query_exec("SELECT COUNT(forum_posts.userid) FROM forum_posts WHERE id=$posterid") or forumsqlerr();
while($row = mysql_fetch_array($postcount1)) {
if ($privacylevel == "strong" && $CURUSER["control_panel"] != "yes"){//hide stats, but not from staff
$useruploaded = "---";
$userdownloaded = "---";
$userratio = "---";
$nposts = "-";
$tposts = "-";
}
print ("<tr valign='top' class='f-border'><td width='150' align='left' class='f-border comment-details'><center><i>$title</i></center><br /><center><img width='80' height='80' src='$avatar' alt='' /></center><br />Uploaded: $useruploaded<br />Downloaded: $userdownloaded<br />Posts: $forumposts<br /><br />Ratio: $userratio<br />Location: $usercountry<br /><br /></td>");
print ("<td class='comment f-border'><br />$body<br />");
if (!$usersignature){
print("<br /></td></tr>\n");
}else{
print("<br /><hr /><br /><div class='f-sig' align='center'>$usersignature</div></td></tr>\n");
}
}
//Post Bottom
print("<tr class='p-foot f-border'><td width='150' align='center'><a href='account-details.php?id=$posterid'><img src='".$themedir."icon_profile.png' border='0' alt='' /></a> <a href='mailbox.php?compose&id=$posterid'><img src='".$themedir."icon_pm.png' border='0' alt='' /></a></td><td>");
print ("<div style='float: left;'><a href='report.php?forumid=$topicid&forumpost=$postid'><img src='".$themedir."p_report.png' border='0' alt='Report This Post' /></a> <a href='javascript:scroll(0,0);'><img src='".$themedir."p_up.png' alt='Go to the top of the page' /></a></div><div align='right'>");
//define buttons and who can use them
if ($CURUSER["id"] == $posterid || $CURUSER["edit_forum"] == "yes" || $CURUSER["delete_forum"] == "yes"){
print ("<a href='forums.php?action=editpost&postid=$postid'><img src='".$themedir."p_edit.png' border='0' alt='' /></a> ");
}
if ($CURUSER["delete_forum"] == "yes"){
print ("<a href='forums.php?action=deletepost&postid=$postid&sure=0'><img src='".$themedir."p_delete.png' border='0' alt='' /></a> ");
}
if (!$locked && $maypost) {
print ("<a href=\"javascript:SmileIT('[quote] $quote [/quote]', 'Form', 'body');\"><img src='".$themedir."p_quote.png' border='0' alt='' /></a> ");
print ("<a href='#bottom'><img src='".$themedir."p_reply.png' alt='' /></a>");
}
print(" </div></td></tr></table></div>");
}
//-------- end posts table ---------//
print($pagemenu);
//quick reply
if (!$locked && $CURUSER){
//begin_frame("Reply", $newtopic = false);
print ("<fieldset class='download'><legend><b>Post Reply</b></legend>");
$newtopic = false;
print("<a name='bottom'></a>");
print("<form class='f-form' name='Form' method='post' action='?action=post'>\n");
if ($newtopic)
print("<input type='hidden' name='forumid' value='$id' />\n");
else
print("<input type='hidden' name='topicid' value='$topicid' />\n");
print("<table cellspacing='0' cellpadding='0' align='center'>");
if ($newtopic)
print("<tr><td class='alt2 f-border'>Subject</td><td class='alt1 f-border' align='left' style='padding: 0px'><input type='text' size='100' maxlength='$maxsubjectlength' name='subject' style='border: 0px; height: 19px' /></td></tr>\n");
echo "<tr><td align='center' colspan='3'>";
textbbcode("Form", "body");
echo "</td></tr>\n";
print("<tr><td colspan='3' align='center'><br /><input type='image' src='". $themedir ."button_reply.png' alt='' /></td></tr>\n");
print("</table></form>\n");
//end_frame();
print (" </fieldset>");
}else{
print ("<img src='".$themedir."button_locked.png' alt='Locked' /><br />");
}
//end quick reply
if ($locked)
print("This topic is locked; no new posts are allowed.\n");
elseif (!$maypost)
print("<i>You are not permitted to post in this forum.</i>\n");
//insert page numbers and quick jump
// insert_quick_jump_menu($forumid);
// MODERATOR OPTIONS
if ($CURUSER["delete_forum"] == "yes" || $CURUSER["edit_forum"] == "yes") {
print("<br /><div class='f-cat f-border' align='center'>Moderator Options</div>\n");
$res = SQL_Query_exec("SELECT id,name,minclasswrite FROM forum_forums ORDER BY name");
print("<div class='f-border f-form' style='padding:3px'>\n");
print("<form method='post' action='forums.php?action=renametopic'>\n");
print("<input type='hidden' name='topicid' value='$topicid' />\n");
print("<input type='hidden' name='returnto' value='forums.php?action=viewtopic&topicid=$topicid' />\n");
print("<div align='center' style='padding:3px'>Rename topic: <input type='text' name='subject' size='60' maxlength='$maxsubjectlength' value='" . stripslashes(htmlspecialchars($subject)) . "' />\n");
print("<input type='submit' value='Apply' />");
print("</div></form>\n");
print("<form method='post' action='forums.php?action=movetopic&topicid=$topicid'>\n");
print("<div class='f-form' align='center' style='padding:3px'>");
print("Move this thread to: <select name='forumid'>");
while ($arr = mysql_fetch_assoc($res))
if ($arr["id"] != $forumid && get_user_class() >= $arr["minclasswrite"])
print("<option value='" . $arr["id"] . "'>" . $arr["name"] . "</option>\n");
print("</select> <input type='submit' value='Apply' /></div></form>\n");
print("<div align='center'>\n");
if ($locked)
print("Locked: <a href='forums.php?action=unlocktopic&forumid=$forumid&topicid=$topicid&page=$page' title='Unlock'><img src='". $themedir ."topic_unlock.png' alt='UnLock Topic' /></a>\n");
else
print("Locked: <a href='forums.php?action=locktopic&forumid=$forumid&topicid=$topicid&page=$page' title='Lock'><img src='". $themedir ."topic_lock.png' alt='Lock Topic' /></a>\n");
print("Delete Entire Topic: <a href='forums.php?action=deletetopic&topicid=$topicid&sure=0' title='Delete'><img src='". $themedir ."topic_delete.png' alt='Delete Topic' /></a>\n");
if ($sticky)
print("Sticky: <a href='forums.php?action=unsetsticky&forumid=$forumid&topicid=$topicid&page=$page' title='UnStick'><img src='". $themedir ."folder_sticky_new.png' alt='UnStick Topic' /></a>\n");
else
print("Sticky: <a href='forums.php?action=setsticky&forumid=$forumid&topicid=$topicid&page=$page' title='Stick'><img src='". $themedir ."folder_sticky.png' alt='Stick Topic' /></a>\n");
print("</div><br /></div>\n");
}
end_frame();
stdfoot();
die;
}
///////////////////////////////////////////////////////// Action: REPLY
if ($action == "reply") {
$topicid = $_GET["topicid"];
if (!is_valid_id($topicid))
showerror("Forum error", "No Forum Topic ID $topicid");
stdhead("Post reply");
begin_frame("Post reply");
insert_compose_frame($topicid, false);
end_frame();
stdfoot();
die;
}
///////////////////////////////////////////////////////// Action: MOVE TOPIC
if ($action == "movetopic") {
$forumid = $_POST["forumid"];
$topicid = $_GET["topicid"];
if (!is_valid_id($forumid) || !is_valid_id($topicid) || $CURUSER["delete_forum"] != "yes" || $CURUSER["edit_forum"] != "yes")
showerror("Forum error", "Not Valid Forum ID $forumid Or Not Valid Forum Topic ID $topicid");
// Make sure topic and forum is valid
$res = @SQL_Query_exec("SELECT minclasswrite FROM forum_forums WHERE id=$forumid");
if (mysql_num_rows($res) != 1)
showerror("Error", "Forum not found.");
$arr = mysql_fetch_row($res);
if (get_user_class() < $arr[0])
showerror("Forum error", "Not Allowed");
$res = @SQL_Query_exec("SELECT subject,forumid FROM forum_topics WHERE id=$topicid");
if (mysql_num_rows($res) != 1)
showerror("Error", "Topic not found.");
$arr = mysql_fetch_assoc($res);
if ($arr["forumid"] != $forumid)
@SQL_Query_exec("UPDATE forum_topics SET forumid=$forumid, moved='yes' WHERE id=$topicid");
// Redirect to forum page
header("Location: $site_config[SITEURL]/forums.php?action=viewforum&forumid=$forumid");
die;
}
///////////////////////////////////////////////////////// Action: DELETE TOPIC
if ($action == "deletetopic") {
$topicid = $_GET["topicid"];
if (!is_valid_id($topicid) || $CURUSER["delete_forum"] != "yes")
showerror("Error", "Denied!");
$sure = $_GET["sure"];
if ($sure == "0")
showerror("Delete topic", "Sanity check: You are about to delete a topic. Click <a href='forums.php?action=deletetopic&topicid=$topicid&sure=1'>here</a> if you are sure.");
SQL_Query_exec("DELETE FROM forum_topics WHERE id=$topicid");
SQL_Query_exec("DELETE FROM forum_posts WHERE topicid=$topicid");
SQL_Query_exec("DELETE FROM forum_readposts WHERE topicid=$topicid");
header("Location: $site_config[SITEURL]/forums.php");
die;
}
///////////////////////////////////////////////////////// Action: EDIT TOPIC
if ($action == "editpost") {
$postid = $_GET["postid"];
if (!is_valid_id($postid))
showerror("Error", "Denied!");
$res = SQL_Query_exec("SELECT * FROM forum_posts WHERE id=$postid");
if (mysql_num_rows($res) != 1)
showerror("Error", "No post with ID $postid.");
$arr = mysql_fetch_assoc($res);
if ($CURUSER["id"] != $arr["userid"] && $CURUSER["delete_forum"] != "yes" && $CURUSER["edit_forum"] != "yes")
showerror("Error", "Denied!");
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$body = $_POST['body'];
if ($body == "")
showerror("Error", "Body cannot be empty!");
$body = sqlesc($body);
$editedat = sqlesc(get_date_time());
SQL_Query_exec("UPDATE forum_posts SET body=$body, editedat=$editedat, editedby=$CURUSER[id] WHERE id=$postid");
$returnto = $_POST["returnto"];
if ($returnto != "")
header("Location: $returnto");
else
showerror("Success", "Post was edited successfully.");
}
stdhead();
begin_frame("Edit Post");
print("<form class='f-form' name='Form' method='post' action='?action=editpost&postid=$postid'>\n");
print("<input type='hidden' name='returnto' value='" . htmlspecialchars($_SERVER["HTTP_REFERER"]) . "' />\n");
print("<center><table cellspacing='0' cellpadding='5'>\n");
print("<tr><td colspan='2'>\n");
textbbcode("Form", "body", htmlspecialchars($arr["body"]));
print("</td></tr>");
print("<tr><td align='center' colspan='2'><input type='submit' value='Submit' /></td></tr>\n");
print("</table></center>\n");
print("</form>\n");
end_frame();
stdfoot();
die;
}
///////////////////////////////////////////////////////// Action: DELETE POST
if ($action == "deletepost") {
$postid = $_GET["postid"];
$sure = $_GET["sure"];
if ($CURUSER["delete_forum"] != "yes" || !is_valid_id($postid))
showerror("Error", "Denied!");
//SURE?
if ($sure == "0") {
showerror("Delete post", "Sanity check: You are about to delete a post. Click <a href='forums.php?action=deletepost&postid=$postid&sure=1'>here</a> if you are sure.");
}
//------- Get topic id
$res = SQL_Query_exec("SELECT topicid FROM forum_posts WHERE id=$postid");
$arr = mysql_fetch_row($res) or showerror("Error", "Post not found");
$topicid = $arr[0];
//------- We can not delete the post if it is the only one of the topic
$res = SQL_Query_exec("SELECT COUNT(*) FROM forum_posts WHERE topicid=$topicid");
$arr = mysql_fetch_row($res);
if ($arr[0] < 2)
showerror("Error", "Can't delete post; it is the only post of the topic. You should <a href='forums.php?action=deletetopic&topicid=$topicid&sure=1'>delete the topic</a> instead.\n");
//------- Delete post
SQL_Query_exec("DELETE FROM forum_posts WHERE id=$postid");
//------- Update topic
update_topic_last_post($topicid);
header("Location: $site_config[SITEURL]/forums.php?action=viewtopic&topicid=$topicid");
die;
}
///////////////////////////////////////////////////////// Action: LOCK TOPIC
if ($action == "locktopic") {
$forumid = $_GET["forumid"];
$topicid = $_GET["topicid"];
$page = $_GET["page"];
if (!is_valid_id($topicid) || $CURUSER["delete_forum"] != "yes" || $CURUSER["edit_forum"] != "yes")
showerror("Error", "Denied!");
SQL_Query_exec("UPDATE forum_topics SET locked='yes' WHERE id=$topicid");
header("Location: $site_config[SITEURL]/forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
///////////////////////////////////////////////////////// Action: UNLOCK TOPIC
if ($action == "unlocktopic") {
$forumid = $_GET["forumid"];
$topicid = $_GET["topicid"];
$page = $_GET["page"];
if (!is_valid_id($topicid) || $CURUSER["delete_forum"] != "yes" || $CURUSER["edit_forum"] != "yes")
showerror("Error", "Denied!");
SQL_Query_exec("UPDATE forum_topics SET locked='no' WHERE id=$topicid");
header("Location: $site_config[SITEURL]/forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
///////////////////////////////////////////////////////// Action: STICK TOPIC
if ($action == "setsticky") {
$forumid = $_GET["forumid"];
$topicid = $_GET["topicid"];
$page = $_GET["page"];
if (!is_valid_id($topicid) || ($CURUSER["delete_forum"] != "yes" && $CURUSER["edit_forum"] != "yes"))
showerror("Error", "Denied!");
SQL_Query_exec("UPDATE forum_topics SET sticky='yes' WHERE id=$topicid");
header("Location: $site_config[SITEURL]/forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
///////////////////////////////////////////////////////// Action: UNSTICK TOPIC
if ($action == "unsetsticky") {
$forumid = $_GET["forumid"];
$topicid = $_GET["topicid"];
$page = $_GET["page"];
if (!is_valid_id($topicid) || ($CURUSER["delete_forum"] != "yes" && $CURUSER["edit_forum"] != "yes"))
showerror("Error", "Denied!");
SQL_Query_exec("UPDATE forum_topics SET sticky='no' WHERE id=$topicid");
header("Location: $site_config[SITEURL]/forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
///////////////////////////////////////////////////////// Action: RENAME TOPIC
if ($action == 'renametopic') {
if ($CURUSER["delete_forum"] != "yes" && $CURUSER["edit_forum"] != "yes")
showerror("Error", "Denied!");
$topicid = $_POST['topicid'];
if (!is_valid_id($topicid))
showerror("Error", "Denied!");
$subject = $_POST['subject'];
if ($subject == '')
showerror('Error', 'You must enter a new title!');
$subject = sqlesc($subject);
SQL_Query_exec("UPDATE forum_topics SET subject=$subject WHERE id=$topicid");
$returnto = $_POST['returnto'];
if ($returnto)
header("Location: $returnto");
die;
}
///////////////////////////////////////////////////////// Action: VIEW FORUM
if ($action == "viewforum") {
$forumid = $_GET["forumid"];
if (!is_valid_id($forumid))
showerror("Error", "Denied!");
$page = $_GET["page"];
$userid = $CURUSER["id"];
//------ Get forum name
$res = SQL_Query_exec("SELECT name, minclassread, guest_read FROM forum_forums WHERE id=$forumid");
$arr = mysql_fetch_assoc($res);
$forumname = $arr["name"];
if (!$forumname || get_user_class() < $arr["minclassread"] && $arr["guest_read"] == "no")
showerror("Error", "Not permitted");
//------ Get topic count
$perpage = 20;
$res = SQL_Query_exec("SELECT COUNT(*) FROM forum_topics WHERE forumid=$forumid");
$arr = mysql_fetch_row($res);
$num = $arr[0];
if ($page == 0)
$page = 1;
$first = ($page * $perpage) - $perpage + 1;
$last = $first + $perpage - 1;
if ($last > $num)
$last = $num;
$pages = floor($num / $perpage);
if ($perpage * $pages < $num)
++$pages;
//------ Build menu
$menu = "<p align='center'><b>\n";
$lastspace = false;
for ($i = 1; $i <= $pages; ++$i) {
if ($i == $page)
$menu .= "<span class='next-prev'>$i</span>\n";
elseif ($i > 3 && ($i < $pages - 2) && ($page - $i > 3 || $i - $page > 3)) {
if ($lastspace)
continue;
$menu .= "... \n";
$lastspace = true;
}
else {
$menu .= "<a href='forums.php?action=viewforum&forumid=$forumid&page=$i'>$i</a>\n";
$lastspace = false;
}
if ($i < $pages)
$menu .= "</b>|<b>\n";
}
$menu .= "<br />\n";
if ($page == 1)
$menu .= "<span class='next-prev'><< Prev</span>";
else
$menu .= "<a href='forums.php?action=viewforum&forumid=$forumid&page=" . ($page - 1) . "'><< Prev</a>";
$menu .= " ";
if ($last == $num)
$menu .= "<span class='next-prev'>Next >></span>";
else
$menu .= "<a href='forums.php?action=viewforum&forumid=$forumid&page=" . ($page + 1) . "'>Next >></a>";
$menu .= "</b></p>\n";
$offset = $first - 1;
//------ Get topics data and display category
$topicsres = SQL_Query_exec("SELECT * FROM forum_topics WHERE forumid=$forumid ORDER BY sticky, lastpost DESC LIMIT $offset,$perpage");
stdhead("Forum : $forumname");
$numtopics = mysql_num_rows($topicsres);
begin_frame("$forumname");
forumheader("<a href='forums.php?action=viewforum&forumid=$forumid'>$forumname</a>");
if ($CURUSER)
print ("<table cellpadding='0' cellspacing='5' width='100%'><tr><td><div align='right'><a href='forums.php?action=newtopic&forumid=$forumid'><img src='". $themedir. "button_new_post.png' alt='' /></a></div></td></tr></table>");
if ($numtopics > 0) {
print("<table cellpadding='3' cellspacing='0' class='f-border' width='100%'>");
print("<tr class='f-title f-border'><th align='left' colspan='2' width='100%'>Topic</th><th>Replies</th><th>Views</th><th>Author</th><th align='right'>Last post</th>\n");
if ($CURUSER["edit_forum"] == "yes" || $CURUSER["delete_forum"] == "yes")
print("<th>Moderator</th>");
print("</tr>\n");
while ($topicarr = mysql_fetch_assoc($topicsres)) {
$topicid = $topicarr["id"];
$topic_userid = $topicarr["userid"];
$locked = $topicarr["locked"] == "yes";
$moved = $topicarr["moved"] == "yes";
$sticky = $topicarr["sticky"] == "yes";
//---- Get reply count
$res = SQL_Query_exec("SELECT COUNT(*) FROM forum_posts WHERE topicid=$topicid");
$arr = mysql_fetch_row($res);
$posts = $arr[0];
$replies = max(0, $posts - 1);
$tpages = floor($posts / $postsperpage);
if ($tpages * $postsperpage != $posts)
++$tpages;
if ($tpages > 1) {
$topicpages = " (<img src='". $site_config['SITEURL'] ."/images/forum/multipage.png' alt='' />";
for ($i = 1; $i <= $tpages; ++$i)
$topicpages .= " <a href='forums.php?action=viewtopic&topicid=$topicid&page=$i'>$i</a>";
$topicpages .= ")";