forked from zjutjh/NexusPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forums.php
1537 lines (1344 loc) · 63.7 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
require "include/bittorrent.php";
dbconn();
require_once(get_langfile_path());
loggedinorreturn();
parked();
if ($enableextforum == 'yes') //check whether internal forum is disabled
permissiondenied();
// ------------- start: functions ------------------//
//print forum stats
function forum_stats ()
{
global $lang_forums, $Cache, $today_date;
if (!$activeforumuser_num = $Cache->get_value('active_forum_user_count')){
$secs = 900;
$dt = date("Y-m-d H:i:s",(TIMENOW - $secs));
$activeforumuser_num = get_row_count("users","WHERE forum_access >= ".sqlesc($dt));
$Cache->cache_value('active_forum_user_count', $activeforumuser_num, 300);
}
if ($activeforumuser_num){
$forumusers = $lang_forums['text_there'].is_or_are($activeforumuser_num)."<b>".$activeforumuser_num."</b>".$lang_forums['text_online_user'].add_s($activeforumuser_num).$lang_forums['text_in_forum_now'];
}
else
$forumusers = $lang_forums['text_no_active_users'];
?>
<h2 align="left"><?php echo $lang_forums['text_stats'] ?></h2>
<table width="100%"><tr><td class="text">
<?php
if (!$postcount = $Cache->get_value('total_posts_count')){
$postcount = get_row_count("posts");
$Cache->cache_value('total_posts_count', $postcount, 96400);
}
if (!$topiccount = $Cache->get_value('total_topics_count')){
$topiccount = get_row_count("topics");
$Cache->cache_value('total_topics_count', $topiccount, 96500);
}
if (!$todaypostcount = $Cache->get_value('today_'.$today_date.'_posts_count')) {
$todaypostcount = get_row_count("posts", "WHERE added > ".sqlesc(date("Y-m-d")));
$Cache->cache_value('today_'.$today_date.'_posts_count', $todaypostcount, 700);
}
print($lang_forums['text_our_members_have'] ."<b>".$postcount."</b>". $lang_forums['text_posts_in_topics']."<b>".$topiccount."</b>".$lang_forums['text_in_topics']."<b><font class=\"new\">".$todaypostcount."</font></b>".$lang_forums['text_new_post'].add_s($todaypostcount).$lang_forums['text_posts_today']."<br /><br />");
print($forumusers);
?>
</td></tr></table>
<?php
}
//set all topics as read
function catch_up()
{
global $CURUSER, $Cache;
if (!$CURUSER)
die;
sql_query("DELETE FROM readposts WHERE userid=".sqlesc($CURUSER['id']));
$Cache->delete_value('user_'.$CURUSER['id'].'_last_read_post_list');
$lastpostid=get_single_value("posts","id","ORDER BY id DESC");
if ($lastpostid){
$CURUSER['last_catchup'] = $lastpostid;
sql_query("UPDATE users SET last_catchup = ".sqlesc($lastpostid)." WHERE id=".sqlesc($CURUSER['id']));
}
}
//return image
function get_topic_image($status= "read"){
global $lang_forums;
switch($status){
case "read": {
return "<img class=\"unlocked\" src=\"pic/trans.gif\" alt=\"read\" title=\"".$lang_forums['title_read']."\" />";
break;
}
case "unread": {
return "<img class=\"unlockednew\" src=\"pic/trans.gif\" alt=\"unread\" title=\"".$lang_forums['title_unread']."\" />";
break;
}
case "locked": {
return "<img class=\"locked\" src=\"pic/trans.gif\" alt=\"locked\" title=\"".$lang_forums['title_locked']."\" />";
break;
}
case "lockednew": {
return "<img class=\"lockednew\" src=\"pic/trans.gif\" alt=\"lockednew\" title=\"".$lang_forums['title_locked_new']."\" />";
break;
}
}
}
function highlight_topic($subject, $hlcolor=0)
{
$colorname=get_hl_color($hlcolor);
if ($colorname)
$subject = "<b><font color=\"".$colorname."\">".$subject."</font></b>";
return $subject;
}
function check_whether_exist($id, $place='forum'){
global $lang_forums;
int_check($id,true);
switch ($place){
case 'forum':
{
$count = get_row_count("forums","WHERE id=".sqlesc($id));
if (!$count)
stderr($lang_forums['std_error'],$lang_forums['std_no_forum_id']);
break;
}
case 'topic':
{
$count = get_row_count("topics","WHERE id=".sqlesc($id));
if (!$count)
stderr($lang_forums['std_error'],$lang_forums['std_bad_topic_id']);
$forumid = get_single_value("topics","forumid","WHERE id=".sqlesc($id));
check_whether_exist($forumid, 'forum');
break;
}
case 'post':
{
$count = get_row_count("posts","WHERE id=".sqlesc($id));
if (!$count)
stderr($lang_forums['std_error'],$lang_forums['std_no_post_id']);
$topicid = get_single_value("posts","topicid","WHERE id=".sqlesc($id));
check_whether_exist($topicid, 'topic');
break;
}
}
}
//update the last post of a topic
function update_topic_last_post($topicid)
{
global $lang_forums;
$res = sql_query("SELECT id FROM posts WHERE topicid=".sqlesc($topicid)." ORDER BY id DESC LIMIT 1") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res) or die($lang_forums['std_no_post_found']);
$postid = $arr[0];
sql_query("UPDATE topics SET lastpost=".sqlesc($postid)." WHERE id=".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
}
function get_forum_row($forumid = 0)
{
global $Cache;
if (!$forums = $Cache->get_value('forums_list')){
$forums = array();
$res2 = sql_query("SELECT * FROM forums ORDER BY forid ASC, sort ASC") or sqlerr(__FILE__, __LINE__);
while ($row2 = mysql_fetch_array($res2))
$forums[$row2['id']] = $row2;
$Cache->cache_value('forums_list', $forums, 86400);
}
if (!$forumid)
return $forums;
else return $forums[$forumid];
}
function get_last_read_post_id($topicid) {
global $CURUSER, $Cache;
static $ret;
if (!$ret && !$ret = $Cache->get_value('user_'.$CURUSER['id'].'_last_read_post_list')){
$ret = array();
$res = sql_query("SELECT * FROM readposts WHERE userid=" . sqlesc($CURUSER['id']));
if (mysql_num_rows($res) != 0){
while ($row = mysql_fetch_array($res))
$ret[$row['topicid']] = $row['lastpostread'];
$Cache->cache_value('user_'.$CURUSER['id'].'_last_read_post_list', $ret, 900);
}
else $Cache->cache_value('user_'.$CURUSER['id'].'_last_read_post_list', 'no record', 900);
}
if ($ret != "no record" && $ret[$topicid] && $CURUSER['last_catchup'] < $ret[$topicid]){
return $ret[$topicid];
}
elseif ($CURUSER['last_catchup'])
return $CURUSER['last_catchup'];
else return 0;
}
//-------- Inserts a compose frame
function insert_compose_frame($id, $type = 'new')
{
global $maxsubjectlength, $CURUSER;
global $lang_forums;
$hassubject = false;
$subject = "";
$body = "";
print("<form id=\"compose\" method=\"post\" name=\"compose\" action=\"?action=post\">\n");
switch ($type){
case 'new':
{
$forumname = get_single_value("forums","name","WHERE id=".sqlesc($id));
$title = $lang_forums['text_new_topic_in']." <a href=\"".htmlspecialchars("?action=viewforum&forumid=".$id)."\">".htmlspecialchars($forumname)."</a> ".$lang_forums['text_forum'];
$hassubject = true;
break;
}
case 'reply':
{
$topicname = get_single_value("topics","subject","WHERE id=".sqlesc($id));
$title = $lang_forums['text_reply_to_topic']." <a href=\"".htmlspecialchars("?action=viewtopic&topicid=".$id)."\">".htmlspecialchars($topicname)."</a> ";
break;
}
case 'quote':
{
$topicid=get_single_value("posts","topicid","WHERE id=".sqlesc($id));
$topicname = get_single_value("topics","subject","WHERE id=".sqlesc($topicid));
$title = $lang_forums['text_reply_to_topic']." <a href=\"".htmlspecialchars("?action=viewtopic&topicid=".$topicid)."\">".htmlspecialchars($topicname)."</a> ";
$res = sql_query("SELECT posts.body, users.username FROM posts LEFT JOIN users ON posts.userid = users.id WHERE posts.id=$id") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
stderr($lang_forums['std_error'], $lang_forums['std_no_post_id']);
$arr = mysql_fetch_assoc($res);
$body = "[quote=".htmlspecialchars($arr["username"])."]".htmlspecialchars(unesc($arr["body"]))."[/quote]";
$id = $topicid;
$type = 'reply';
break;
}
case 'edit':
{
$res = sql_query("SELECT topicid, body FROM posts WHERE id=".sqlesc($id)." LIMIT 1") or sqlerr(__FILE__, __LINE__);
$row = mysql_fetch_array($res);
$topicid=$row['topicid'];
$firstpost = get_single_value("posts","MIN(id)", "WHERE topicid=".sqlesc($topicid));
if ($firstpost == $id){
$subject = get_single_value("topics","subject","WHERE id=".sqlesc($topicid));
$hassubject = true;
}
$body = htmlspecialchars(unesc($row["body"]));
$title = $lang_forums['text_edit_post'];
break;
}
default:
{
die;
}
}
print("<input type=\"hidden\" name=\"id\" value=\"".$id."\" />");
print("<input type=\"hidden\" name=\"type\" value=\"".$type."\" />");
begin_compose($title, $type, $body, $hassubject, $subject);
end_compose();
print("</form>");
}
// ------------- end: functions ------------------//
// ------------- start: Global variables ------------------//
$maxsubjectlength = 100;
$postsperpage = $CURUSER["postsperpage"];
if (!$postsperpage){
if (is_numeric($forumpostsperpage))
$postsperpage = $forumpostsperpage;//system-wide setting
else $postsperpage = 10;
}
//get topics per page
$topicsperpage = $CURUSER["topicsperpage"];
if (!$topicsperpage){
if (is_numeric($forumtopicsperpage_main))
$topicsperpage = $forumtopicsperpage_main;//system-wide setting
else $topicsperpage = 20;
}
$today_date = date("Y-m-d",TIMENOW);
// ------------- end: Global variables ------------------//
$action = htmlspecialchars(trim($_GET["action"]));
//-------- Action: New topic
if ($action == "newtopic")
{
$forumid = 0+$_GET["forumid"];
check_whether_exist($forumid, 'forum');
stdhead($lang_forums['head_new_topic']);
begin_main_frame();
insert_compose_frame($forumid,'new');
end_main_frame();
stdfoot();
die;
}
if ($action == "quotepost")
{
$postid = 0+$_GET["postid"];
check_whether_exist($postid, 'post');
stdhead($lang_forums['head_post_reply']);
begin_main_frame();
insert_compose_frame($postid, 'quote');
end_main_frame();
stdfoot();
die;
}
//-------- Action: Reply
if ($action == "reply")
{
$topicid = 0+$_GET["topicid"];
check_whether_exist($topicid, 'topic');
stdhead($lang_forums['head_post_reply']);
begin_main_frame();
insert_compose_frame($topicid, 'reply');
end_main_frame();
stdfoot();
die;
}
//-------- Action: Edit post
if ($action == "editpost")
{
$postid = 0+$_GET["postid"];
check_whether_exist($postid, 'post');
$res = sql_query("SELECT userid, topicid FROM posts WHERE id=".sqlesc($postid)) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res);
$res2 = sql_query("SELECT locked FROM topics WHERE id = " . $arr["topicid"]) or sqlerr(__FILE__, __LINE__);
$arr2 = mysql_fetch_assoc($res2);
$locked = ($arr2["locked"] == 'yes');
$ismod = is_forum_moderator($postid, 'post');
if (($CURUSER["id"] != $arr["userid"] || $locked) && get_user_class() < $postmanage_class && !$ismod)
permissiondenied();
stdhead($lang_forums['text_edit_post']);
begin_main_frame();
insert_compose_frame($postid, 'edit');
end_main_frame();
stdfoot();
die;
}
//-------- Action: Post
if ($action == "post")
{
if ($CURUSER["forumpost"] == 'no')
{
stderr($lang_forums['std_sorry'], $lang_forums['std_unauthorized_to_post'],false);
die;
}
$id = $_POST["id"];
$type = $_POST["type"];
$subject = $_POST["subject"];
$body = trim($_POST["body"]);
$hassubject = false;
switch ($type){
case 'new':
{
check_whether_exist($id, 'forum');
$forumid = $id;
$hassubject = true;
break;
}
case 'reply':
{
check_whether_exist($id, 'topic');
$topicid = $id;
$forumid = get_single_value("topics", "forumid", "WHERE id=".sqlesc($topicid));
break;
}
case 'edit':
{
check_whether_exist($id, 'post');
$res = sql_query("SELECT topicid FROM posts WHERE id=".sqlesc($id)." LIMIT 1") or sqlerr(__FILE__, __LINE__);
$row = mysql_fetch_array($res);
$topicid=$row['topicid'];
$forumid = get_single_value("topics", "forumid", "WHERE id=".sqlesc($topicid));
$firstpost = get_single_value("posts","MIN(id)", "WHERE topicid=".sqlesc($topicid));
if ($firstpost == $id){
$hassubject = true;
}
break;
}
default:
{
die;
}
}
if ($hassubject){
$subject = trim($subject);
if (!$subject)
stderr($lang_forums['std_error'], $lang_forums['std_must_enter_subject']);
if (strlen($subject) > $maxsubjectlength)
stderr($lang_forums['std_error'], $lang_forums['std_subject_limited']);
}
//------ Make sure sure user has write access in forum
$arr = get_forum_row($forumid) or die($lang_forums['std_bad_forum_id']);
if (get_user_class() < $arr["minclasswrite"] || ($type =='new' && get_user_class() < $arr["minclasscreate"]))
permissiondenied();
if ($body == "")
stderr($lang_forums['std_error'], $lang_forums['std_no_body_text']);
$userid = 0+$CURUSER["id"];
$date = date("Y-m-d H:i:s");
if ($type != 'new'){
//---- Make sure topic is unlocked
$res = sql_query("SELECT locked FROM topics WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or die("Topic id n/a");
if ($arr["locked"] == 'yes' && get_user_class() < $postmanage_class && !is_forum_moderator($topicid, 'topic'))
stderr($lang_forums['std_error'], $lang_forums['std_topic_locked']);
}
if ($type == 'edit')
{
if ($hassubject){
sql_query("UPDATE topics SET subject=".sqlesc($subject)." WHERE id=".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
$forum_last_replied_topic_row = $Cache->get_value('forum_'.$forumid.'_last_replied_topic_content');
if ($forum_last_replied_topic_row && $forum_last_replied_topic_row['id'] == $topicid)
$Cache->delete_value('forum_'.$forumid.'_last_replied_topic_content');
}
sql_query("UPDATE posts SET body=".sqlesc($body).", editdate=".sqlesc($date).", editedby=".sqlesc($CURUSER[id])." WHERE id=".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$postid = $id;
$Cache->delete_value('post_'.$postid.'_content');
}
else
{
// Anti Flood Code
// To ensure that posts are not entered within 10 seconds limiting posts
// to a maximum of 360*6 per hour.
if (get_user_class() < $postmanage_class) {
if (strtotime($CURUSER['last_post']) > (TIMENOW - 10))
{
$secs = 10 - (TIMENOW - strtotime($CURUSER['last_post']));
stderr($lang_forums['std_error'],$lang_forums['std_post_flooding'].$secs.$lang_forums['std_seconds_before_making'],false);
}
}
if ($type == 'new'){ //new topic
//add bonus
KPS("+",$starttopic_bonus,$userid);
//---- Create topic
sql_query("INSERT INTO topics (userid, forumid, subject) VALUES($userid, $forumid, ".sqlesc($subject).")") or sqlerr(__FILE__, __LINE__);
$topicid = mysql_insert_id() or stderr($lang_forums['std_error'],$lang_forums['std_no_topic_id_returned']);
sql_query("UPDATE forums SET topiccount=topiccount+1, postcount=postcount+1 WHERE id=".sqlesc($forumid));
}
else // new post
{
//add bonus
KPS("+",$makepost_bonus,$userid);
sql_query("UPDATE forums SET postcount=postcount+1 WHERE id=".sqlesc($forumid));
}
sql_query("INSERT INTO posts (topicid, userid, added, body, ori_body) VALUES ($topicid, $userid, ".sqlesc($date).", ".sqlesc($body).", ".sqlesc($body).")") or sqlerr(__FILE__, __LINE__);
$postid = mysql_insert_id() or die($lang_forums['std_post_id_not_available']);
$Cache->delete_value('forum_'.$forumid.'_post_'.$today_date.'_count');
$Cache->delete_value('today_'.$today_date.'_posts_count');
$Cache->delete_value('forum_'.$forumid.'_last_replied_topic_content');
$Cache->delete_value('topic_'.$topicid.'_post_count');
$Cache->delete_value('user_'.$userid.'_post_count');
if ($type == 'new')
{
// update the first post of topic
sql_query("UPDATE topics SET firstpost=$postid, lastpost=$postid WHERE id=".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
}
else
{
sql_query("UPDATE topics SET lastpost=$postid WHERE id=".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
}
sql_query("UPDATE users SET last_post=".sqlesc($date)." WHERE id=".sqlesc($CURUSER['id'])) or sqlerr(__FILE__, __LINE__);
}
//------ All done, redirect user to the post
$headerstr = "Location: " . get_protocol_prefix() . "$BASEURL/forums.php?action=viewtopic&topicid=$topicid";
if ($type == 'edit')
header($headerstr."&page=p".$postid."#pid".$postid);
else
header($headerstr."&page=last#pid$postid");
die;
}
//-------- Action: View topic
if ($action == "viewtopic")
{
$highlight = htmlspecialchars(trim($_GET["highlight"]));
$topicid = 0+$_GET["topicid"];
int_check($topicid,true);
$page = $_GET["page"];
$authorid = 0+$_GET["authorid"];
if ($authorid)
{
$where = "WHERE topicid=".sqlesc($topicid)." AND userid=".sqlesc($authorid);
$addparam = "action=viewtopic&topicid=".$topicid."&authorid=".$authorid;
}
else
{
$where = "WHERE topicid=".sqlesc($topicid);
$addparam = "action=viewtopic&topicid=".$topicid;
}
$userid = $CURUSER["id"];
//------ Get topic info
$res = sql_query("SELECT * FROM topics WHERE id=".sqlesc($topicid)." LIMIT 1") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or stderr($lang_forums['std_forum_error'], $lang_forums['std_topic_not_found']);
$forumid = $arr['forumid'];
$locked = $arr['locked'] == "yes";
$orgsubject = $arr['subject'];
$subject = htmlspecialchars($arr['subject']);
if ($highlight){
$subject = highlight($highlight,$orgsubject);
}
$sticky = $arr['sticky'] == "yes";
$hlcolor = $arr['hlcolor'];
$views = $arr['views'];
$forumid = $arr["forumid"];
$row = get_forum_row($forumid);
//------ Get forum name, moderators
$forumname = $row['name'];
$is_forummod = is_forum_moderator($forumid,'forum');
if (get_user_class() < $row["minclassread"])
stderr($lang_forums['std_error'], $lang_forums['std_unpermitted_viewing_topic']);
if (((get_user_class() >= $row["minclasswrite"] && !$locked) || get_user_class() >= $postmanage_class || $is_forummod) && $CURUSER["forumpost"] == 'yes')
$maypost = true;
else $maypost = false;
//------ Update hits column
sql_query("UPDATE topics SET views = views + 1 WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
//------ Get post count
$postcount = get_row_count("posts",$where);
if (!$authorid)
$Cache->cache_value('topic_'.$topicid.'_post_count', $postcount, 3600);
//------ Make page menu
$pagerarr = array();
$perpage = $postsperpage;
$pages = ceil($postcount / $perpage);
if ($page[0] == "p")
{
$findpost = substr($page, 1);
$res = sql_query("SELECT id FROM posts $where ORDER BY added") or sqlerr(__FILE__, __LINE__);
$i = 0;
while ($arr = mysql_fetch_row($res))
{
if ($arr[0] == $findpost)
break;
++$i;
}
$page = floor($i / $perpage);
}
if ($page === "last"){
$page = $pages-1;
}
elseif(isset($page))
{
if($page < 0){
$page = 0;
}
elseif ($page > $pages - 1){
$page = $pages - 1;
}
}
else {if ($CURUSER["clicktopic"] == "firstpage")
$page = 0;
else $page = $pages-1;
}
$offset = $page * $perpage;
$dotted = 0;
$dotspace = 3;
$dotend = $pages - $dotspace;
$curdotend = $page - $dotspace;
$curdotstart = $page + $dotspace;
for ($i = 0; $i < $pages; ++$i)
{
if (($i >= $dotspace && $i <= $curdotend) || ($i >= $curdotstart && $i < $dotend)) {
if (!$dotted)
$pagerarr[] = "...";
$dotted = 1;
continue;
}
$dotted = 0;
if ($i != $page)
$pagerarr[] .= "<a href=\"".htmlspecialchars("?".$addparam."&page=".$i)."\"><b>".($i+1)."</b></a>\n";
else
$pagerarr[] .= "<font class=\"gray\"><b>".($i+1)."</b></font>\n";
}
if ($page == 0)
$pager = "<font class=\"gray\"><b><<".$lang_forums['text_prev']."</b></font>";
else
$pager = "<a href=\"".htmlspecialchars("?".$addparam."&page=" . ($page - 1)) .
"\"><b><<".$lang_forums['text_prev']."</b></a>";
$pager .= " ";
if ($page == $pages-1)
$pager .= "<font class=\"gray\"><b>".$lang_forums['text_next']." >></b></font>\n";
else
$pager .= "<a href=\"".htmlspecialchars("?".$addparam."&page=" . ($page + 1)) .
"\"><b>".$lang_forums['text_next']." >></b></a>\n";
$pagerstr = join(" | ", $pagerarr);
$pagertop = "<p align=\"center\">".$pager."<br />".$pagerstr."</p>\n";
$pagerbottom = "<p align=\"center\">".$pagerstr."<br />".$pager."</p>\n";
//------ Get posts
$res = sql_query("SELECT * FROM posts $where ORDER BY id LIMIT $offset,$perpage") or sqlerr(__FILE__, __LINE__);
stdhead($lang_forums['head_view_topic']." \"".$orgsubject."\"");
begin_main_frame("",true);
print("<h1 align=\"center\"><a class=\"faqlink\" href=\"forums.php\">".$SITENAME." ".$lang_forums['text_forums']."</a>--><a class=\"faqlink\" href=\"".htmlspecialchars("?action=viewforum&forumid=".$forumid)."\">".$forumname."</a><b>--></b><span id=\"top\">".$subject.($locked ? " <b>[<font class=\"striking\">".$lang_forums['text_locked']."</font>]</b>" : "")."</span></h1>\n");
end_main_frame();
print($pagertop);
//------ Print table
begin_main_frame();
print("<table border=\"0\" class=\"main\" cellspacing=\"0\" cellpadding=\"5\" width=\"940\"><tr>\n");
print("<td class=\"embedded\" width=\"99%\"> ".$lang_forums['there_is']."<b>".$views."</b>".$lang_forums['hits_on_this_topic']);
print("</td>\n");
print("<td class=\"embedded nowrap\" width=\"1%\" align=\"right\">");
if ($maypost)
{
print("<a href=\"".htmlspecialchars("?action=reply&topicid=".$topicid)."\"><img class=\"f_reply\" src=\"pic/trans.gif\" alt=\"Add Reply\" title=\"".$lang_forums['title_reply_directly']."\" /></a> ");
}
print("</td>");
print("</tr></table>\n");
begin_frame();
$pc = mysql_num_rows($res);
$pn = 0;
$lpr = get_last_read_post_id($topicid);
if ($Advertisement->enable_ad())
$forumpostad=$Advertisement->get_ad('forumpost');
while ($arr = mysql_fetch_assoc($res))
{
if ($pn>=1)
{
if ($Advertisement->enable_ad()){
if ($forumpostad[$pn-1])
echo "<div align=\"center\" style=\"margin-top: 10px\" id=\"ad_forumpost_".$pn."\">".$forumpostad[$pn-1]."</div>";
}
}
++$pn;
$postid = $arr["id"];
$posterid = $arr["userid"];
$added = gettime($arr["added"],true,false);
//---- Get poster details
$arr2 = get_user_row($posterid);
$uploaded = mksize($arr2["uploaded"]);
$downloaded = mksize($arr2["downloaded"]);
$ratio = get_ratio($arr2['id']);
if (!$forumposts = $Cache->get_value('user_'.$posterid.'_post_count')){
$forumposts = get_row_count("posts","WHERE userid=".$posterid);
$Cache->cache_value('user_'.$posterid.'_post_count', $forumposts, 3600);
}
$signature = ($CURUSER["signatures"] == "yes" ? $arr2["signature"] : "");
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($arr2["avatar"]) : "");
$uclass = get_user_class_image($arr2["class"]);
$by = get_username($posterid,false,true,true,false,false,true);
if (!$avatar)
$avatar = "pic/default_avatar.png";
if ($pn == $pc)
{
print("<span id=\"last\"></span>\n");
if ($postid > $lpr){
if ($lpr == $CURUSER['last_catchup']) // There is no record of this topic
sql_query("INSERT INTO readposts(userid, topicid, lastpostread) VALUES (".$userid.", ".$topicid.", ".$postid.")") or sqlerr(__FILE__, __LINE__);
elseif ($lpr > $CURUSER['last_catchup']) //There is record of this topic
sql_query("UPDATE readposts SET lastpostread=$postid WHERE userid=$userid AND topicid=$topicid") or sqlerr(__FILE__, __LINE__);
$Cache->delete_value('user_'.$CURUSER['id'].'_last_read_post_list');
}
}
print("<div style=\"margin-top: 8pt; margin-bottom: 8pt;\"><table id=\"pid".$postid."\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><tr><td class=\"embedded\" width=\"99%\"><a href=\"".htmlspecialchars("forums.php?action=viewtopic&topicid=".$topicid."&page=p".$postid."#pid".$postid)."\">#".$postid."</a> <font color=\"gray\">".$lang_forums['text_by']."</font>".$by." <font color=\"gray\">".$lang_forums['text_at']."</font>".$added);
if (is_valid_id($arr['editedby']))
print("");
print(" <font color=\"gray\">|</font> ");
if ($authorid)
print("<a href=\"?action=viewtopic&topicid=".$topicid."\">".$lang_forums['text_view_all_posts']."</a>");
else
print("<a href=\"".htmlspecialchars("?action=viewtopic&topicid=".$topicid."&authorid=".$posterid)."\">".$lang_forums['text_view_this_author_only']."</a>");
print("</td><td class=\"embedded nowrap\" width=\"1%\"><font class=\"big\">".$lang_forums['text_number']."<b>".($pn+$offset)."</b>".$lang_forums['text_lou']." </font><a href=\"#top\"><img class=\"top\" src=\"pic/trans.gif\" alt=\"Top\" title=\"".$lang_forums['text_back_to_top']."\" /></a> </td></tr>");
print("</table></div>\n");
print("<table class=\"main\" width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n");
$body = "<div id=\"pid".$postid."body\">".format_comment($arr["body"]);
if ($highlight){
$body = highlight($highlight,$body);
}
if (is_valid_id($arr['editedby']))
{
$lastedittime = gettime($arr['editdate'],true,false);
$body .= "<br /><p><font class=\"small\">".$lang_forums['text_last_edited_by'].get_username($arr['editedby']).$lang_forums['text_last_edit_at'].$lastedittime."</font></p>\n";
}
$body .= "</div>";
if ($signature)
$body .= "<p style='vertical-align:bottom'><br />____________________<br />" . format_comment($signature,false,false,false,true,500,true,false, 1,200) . "</p>";
$stats = "<br />"." ".$lang_forums['text_posts']."$forumposts<br />"." ".$lang_forums['text_ul']."$uploaded <br />"." ".$lang_forums['text_dl']."$downloaded<br />"." ".$lang_forums['text_ratio']."$ratio";
print("<tr><td class=\"rowfollow\" width=\"150\" valign=\"top\" align=\"left\" style='padding: 0px'>" .
return_avatar_image($avatar). "<br /><br /><br /> <img alt=\"".get_user_class_name($arr2["class"],false,false,true)."\" title=\"".get_user_class_name($arr2["class"],false,false,true)."\" src=\"".$uclass."\" />".$stats."</td><td class=\"rowfollow\" valign=\"top\"><br />".$body."</td></tr>\n");
$secs = 900;
$dt = sqlesc(date("Y-m-d H:i:s",(TIMENOW - $secs))); // calculate date.
print("<tr><td class=\"rowfollow\" align=\"center\" valign=\"middle\">".("'".$arr2['last_access']."'">$dt?"<img class=\"f_online\" src=\"pic/trans.gif\" alt=\"Online\" title=\"".$lang_forums['title_online']."\" />":"<img class=\"f_offline\" src=\"pic/trans.gif\" alt=\"Offline\" title=\"".$lang_forums['title_offline']."\" />" )."<a href=\"sendmessage.php?receiver=".htmlspecialchars(trim($arr2["id"]))."\"><img class=\"f_pm\" src=\"pic/trans.gif\" alt=\"PM\" title=\"".$lang_forums['title_send_message_to'].htmlspecialchars($arr2["username"])."\" /></a><a href=\"report.php?forumpost=$postid\"><img class=\"f_report\" src=\"pic/trans.gif\" alt=\"Report\" title=\"".$lang_forums['title_report_this_post']."\" /></a></td>");
print("<td class=\"toolbox\" align=\"right\">");
if ($maypost)
print("<a href=\"".htmlspecialchars("?action=quotepost&postid=".$postid)."\"><img class=\"f_quote\" src=\"pic/trans.gif\" alt=\"Quote\" title=\"".$lang_forums['title_reply_with_quote']."\" /></a>");
if (get_user_class() >= $postmanage_class || $is_forummod)
print("<a href=\"".htmlspecialchars("?action=deletepost&postid=".$postid)."\"><img class=\"f_delete\" src=\"pic/trans.gif\" alt=\"Delete\" title=\"".$lang_forums['title_delete_post']."\" /></a>");
if (($CURUSER["id"] == $posterid && !$locked) || get_user_class() >= $postmanage_class || $is_forummod)
print("<a href=\"".htmlspecialchars("?action=editpost&postid=".$postid)."\"><img class=\"f_edit\" src=\"pic/trans.gif\" alt=\"Edit\" title=\"".$lang_forums['title_edit_post']."\" /></a>");
print("</td></tr></table>");
}
//------ Mod options
if (get_user_class() >= $postmanage_class || $is_forummod)
{
print("</td></tr><tr><td class=\"toolbox\" align=\"center\">\n");
print("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"left\">\n");
print("<tr><td class=\"embedded\"><form method=\"post\" action=\"?action=setsticky\">\n");
print("<input type=\"hidden\" name=\"topicid\" value=\"".$topicid."\" />\n");
print("<input type=\"hidden\" name=\"returnto\" value=\"".htmlspecialchars($_SERVER[REQUEST_URI])."\" />\n");
print("<input type=\"hidden\" name=\"sticky\" value=\"".($sticky ? 'no' : 'yes')."\" /><input type=\"submit\" class=\"medium\" value=\"".($sticky ? $lang_forums['submit_unsticky'] : $lang_forums['submit_sticky'])."\" /></form></td>\n");
print("<td class=\"embedded\"><form method=\"post\" action=\"?action=setlocked\">\n");
print("<input type=\"hidden\" name=\"topicid\" value=\"".$topicid."\" />\n");
print("<input type=\"hidden\" name=\"returnto\" value=\"".htmlspecialchars($_SERVER[REQUEST_URI])."\" />\n");
print("<input type=\"hidden\" name=\"locked\" value=\"".($locked ? 'no' : 'yes')."\" /><input type=\"submit\" class=\"medium\" value=\"".($locked ? $lang_forums['submit_unlock'] : $lang_forums['submit_lock'])."\" /></form></td>\n");
print("<td class=\"embedded\"><form method=\"get\" action=\"?\">\n");
print("<input type=\"hidden\" name=\"action\" value=\"deletetopic\" />\n");
print("<input type=\"hidden\" name=\"topicid\" value=\"".$topicid."\" />\n");
print("<input type=\"hidden\" name=\"forumid\" value=\"".$forumid."\" />\n");
print("<input type=\"submit\" class=\"medium\" value=\"".$lang_forums['submit_delete_topic']."\" /></form></td>\n");
print("<td class=\"embedded\"><form method=\"post\" action=\"".htmlspecialchars("?action=movetopic&topicid=".$topicid)."\">\n"." ".$lang_forums['text_move_thread_to']." <select class=\"med\" name=\"forumid\">");
$forums = get_forum_row();
foreach ($forums as $arr){
if ($arr["id"] != $forumid && get_user_class() >= $arr["minclasswrite"])
print("<option value=\"" . $arr["id"] . "\">" . htmlspecialchars($arr["name"]) . "</option>\n");
}
print("</select> <input type=\"submit\" class=\"medium\" value=\"".$lang_forums['submit_move']."\" /></form></td>");
print("<td class=\"embedded\"><form method=\"post\" action=\"".htmlspecialchars("?action=hltopic&topicid=".$topicid)."\">\n"." ".$lang_forums['text_highlight_topic']." <select class=\"med\" name=\"color\">");
print("<option value='0'>".$lang_forums['select_color']."</option>
<option style='background-color: black' value=\"1\">Black</option>
<option style='background-color: sienna' value=\"2\">Sienna</option>
<option style='background-color: darkolivegreen' value=\"3\">Dark Olive Green</option>
<option style='background-color: darkgreen' value=\"4\">Dark Green</option>
<option style='background-color: darkslateblue' value=\"5\">Dark Slate Blue</option>
<option style='background-color: navy' value=\"6\">Navy</option>
<option style='background-color: indigo' value=\"7\">Indigo</option>
<option style='background-color: darkslategray' value=\"8\">Dark Slate Gray</option>
<option style='background-color: darkred' value=\"9\">Dark Red</option>
<option style='background-color: darkorange' value=\"10\">Dark Orange</option>
<option style='background-color: olive' value=\"11\">Olive</option>
<option style='background-color: green' value=\"12\">Green</option>
<option style='background-color: teal' value=\"13\">Teal</option>
<option style='background-color: blue' value=\"14\">Blue</option>
<option style='background-color: slategray' value=\"15\">Slate Gray</option>
<option style='background-color: dimgray' value=\"16\">Dim Gray</option>
<option style='background-color: red' value=\"17\">Red</option>
<option style='background-color: sandybrown' value=\"18\">Sandy Brown</option>
<option style='background-color: yellowgreen' value=\"19\">Yellow Green</option>
<option style='background-color: seagreen' value=\"20\">Sea Green</option>
<option style='background-color: mediumturquoise' value=\"21\">Medium Turquoise</option>
<option style='background-color: royalblue' value=\"22\">Royal Blue</option>
<option style='background-color: purple' value=\"23\">Purple</option>
<option style='background-color: gray' value=\"24\">Gray</option>
<option style='background-color: magenta' value=\"25\">Magenta</option>
<option style='background-color: orange' value=\"26\">Orange</option>
<option style='background-color: yellow' value=\"27\">Yellow</option>
<option style='background-color: lime' value=\"28\">Lime</option>
<option style='background-color: cyan' value=\"29\">Cyan</option>
<option style='background-color: deepskyblue' value=\"30\">Deep Sky Blue</option>
<option style='background-color: darkorchid' value=\"31\">Dark Orchid</option>
<option style='background-color: silver' value=\"32\">Silver</option>
<option style='background-color: pink' value=\"33\">Pink</option>
<option style='background-color: wheat' value=\"34\">Wheat</option>
<option style='background-color: lemonchiffon' value=\"35\">Lemon Chiffon</option>
<option style='background-color: palegreen' value=\"36\">Pale Green</option>
<option style='background-color: paleturquoise' value=\"37\">Pale Turquoise</option>
<option style='background-color: lightblue' value=\"38\">Light Blue</option>
<option style='background-color: plum' value=\"39\">Plum</option>
<option style='background-color: white' value=\"40\">White</option>");
print("</select>");
print("<input type=\"hidden\" name=\"returnto\" value=\"".htmlspecialchars($_SERVER[REQUEST_URI])."\" />\n");
print("<input type=\"submit\" class=\"medium\" value=\"".$lang_forums['submit_change']."\" /></form></td>");
print("</tr>\n");
print("</table>\n");
}
end_frame();
end_main_frame();
print($pagerbottom);
if ($maypost){
print("<br /><table style='border:1px solid #000000;'><tr>".
"<td class=\"text\" align=\"center\"><b>".$lang_forums['text_quick_reply']."</b><br /><br />".
"<form id=\"compose\" name=\"compose\" method=\"post\" action=\"?action=post\" onsubmit=\"return postvalid(this);\">".
"<input type=\"hidden\" name=\"id\" value=\"".$topicid."\" /><input type=\"hidden\" name=\"type\" value=\"reply\" /><br />");
quickreply('compose', 'body',$lang_forums['submit_add_reply']);
print("</form></td></tr></table>");
print("<p align=\"center\"><a class=\"index\" href=\"".htmlspecialchars("?action=reply&topicid=".$topicid)."\">".$lang_forums['text_add_reply']."</a></p>\n");
}
elseif ($locked)
print($lang_forums['text_topic_locked_new_denied']);
else print($lang_forums['text_unpermitted_posting_here']);
print(key_shortcut($page,$pages-1));
stdfoot();
die;
}
//-------- Action: Move topic
if ($action == "movetopic")
{
$forumid = 0+$_POST["forumid"];
$topicid = 0+$_GET["topicid"];
$ismod = is_forum_moderator($topicid,'topic');
if (!is_valid_id($forumid) || !is_valid_id($topicid) || (get_user_class() < $postmanage_class && !$ismod))
permissiondenied();
// Make sure topic and forum is valid
$res = @sql_query("SELECT minclasswrite FROM forums WHERE id=$forumid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
stderr($lang_forums['std_error'], $lang_forums['std_forum_not_found']);
$arr = mysql_fetch_row($res);
if (get_user_class() < $arr[0])
permissiondenied();
$res = @sql_query("SELECT forumid FROM topics WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
stderr($lang_forums['std_error'], $lang_forums['std_topic_not_found']);
$arr = mysql_fetch_row($res);
$old_forumid=$arr[0];
// get posts count
$res = sql_query("SELECT COUNT(id) AS nb_posts FROM posts WHERE topicid=$topicid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
stderr($lang_forums['std_error'], $lang_forums['std_cannot_get_posts_count']);
$arr = mysql_fetch_row($res);
$nb_posts = $arr[0];
// move topic
if ($old_forumid != $forumid)
{
@sql_query("UPDATE topics SET forumid=$forumid WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
// update counts
@sql_query("UPDATE forums SET topiccount=topiccount-1, postcount=postcount-$nb_posts WHERE id=$old_forumid") or sqlerr(__FILE__, __LINE__);
$Cache->delete_value('forum_'.$old_forumid.'_post_'.$today_date.'_count');
$Cache->delete_value('forum_'.$old_forumid.'_last_replied_topic_content');
@sql_query("UPDATE forums SET topiccount=topiccount+1, postcount=postcount+$nb_posts WHERE id=$forumid") or sqlerr(__FILE__, __LINE__);
$Cache->delete_value('forum_'.$forumid.'_post_'.$today_date.'_count');
$Cache->delete_value('forum_'.$forumid.'_last_replied_topic_content');
}
// Redirect to forum page
header("Location: " . get_protocol_prefix() . "$BASEURL/forums.php?action=viewforum&forumid=$forumid");
die;
}
//-------- Action: Delete topic
if ($action == "deletetopic")
{
$topicid = 0+$_GET["topicid"];
$res1 = sql_query("SELECT forumid, userid FROM topics WHERE id=".sqlesc($topicid)." LIMIT 1") or sqlerr(__FILE__, __LINE__);
$row1 = mysql_fetch_array($res1);
if (!$row1){
die;
}
else {
$forumid = $row1['forumid'];
$userid = $row1['userid'];
}
$ismod = is_forum_moderator($topicid,'topic');
if (!is_valid_id($topicid) || (get_user_class() < $postmanage_class && !$ismod))
permissiondenied();
$sure = 0+$_GET["sure"];
if (!$sure)
{
stderr($lang_forums['std_delete_topic'], $lang_forums['std_delete_topic_note'] .
"<a class=altlink href=?action=deletetopic&topicid=$topicid&sure=1>".$lang_forums['std_here_if_sure'],false);
}
$postcount = get_row_count("posts","WHERE topicid=".sqlesc($topicid));
sql_query("DELETE FROM topics WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
sql_query("DELETE FROM posts WHERE topicid=$topicid") or sqlerr(__FILE__, __LINE__);
sql_query("DELETE FROM readposts WHERE topicid=$topicid") or sqlerr(__FILE__, __LINE__);
@sql_query("UPDATE forums SET topiccount=topiccount-1, postcount=postcount-$postcount WHERE id=".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
$Cache->delete_value('forum_'.$forumid.'_post_'.$today_date.'_count');
$forum_last_replied_topic_row = $Cache->get_value('forum_'.$forumid.'_last_replied_topic_content');
if ($forum_last_replied_topic_row && $forum_last_replied_topic_row['id'] == $topicid)
$Cache->delete_value('forum_'.$forumid.'_last_replied_topic_content');
//===remove karma
KPS("-",$starttopic_bonus,$userid);
//===end
header("Location: " . get_protocol_prefix() . "$BASEURL/forums.php?action=viewforum&forumid=$forumid");
die;
}
//-------- Action: Delete post
if ($action == "deletepost")
{
$postid = 0+$_GET["postid"];
$sure = 0+$_GET["sure"];
$ismod = is_forum_moderator($postid, 'post');
if ((get_user_class() < $postmanage_class && !$ismod) || !is_valid_id($postid))
permissiondenied();
//------- Get topic id
$res = sql_query("SELECT topicid, userid FROM posts WHERE id=$postid") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_array($res) or stderr($lang_forums['std_error'], $lang_forums['std_post_not_found']);
$topicid = $arr['topicid'];
$userid = $arr['userid'];
//------- Get the id of the last post before the one we're deleting
$res = sql_query("SELECT id FROM posts WHERE topicid=$topicid AND id < $postid ORDER BY id DESC LIMIT 1") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0) // This is the first post of a topic
stderr($lang_forums['std_error'], $lang_forums['std_cannot_delete_post'] .
"<a class=altlink href=?action=deletetopic&topicid=$topicid&sure=1>".$lang_forums['std_delete_topic_instead'],false);
else
{
$arr = mysql_fetch_row($res);
$redirtopost = "&page=p$arr[0]#pid$arr[0]";
}
//------- Make sure we know what we do :-)
if (!$sure)
{
stderr($lang_forums['std_delete_post'], $lang_forums['std_delete_post_note'] .
"<a class=altlink href=?action=deletepost&postid=$postid&sure=1>".$lang_forums['std_here_if_sure'],false);
}
//------- Delete post
sql_query("DELETE FROM posts WHERE id=$postid") or sqlerr(__FILE__, __LINE__);
$Cache->delete_value('user_'.$userid.'_post_count');
$Cache->delete_value('topic_'.$topicid.'_post_count');
// update forum
$forumid = get_single_value("topics","forumid","WHERE id=".sqlesc($topicid));
if (!$forumid)
die();
else{
sql_query("UPDATE forums SET postcount=postcount-1 WHERE id=".sqlesc($forumid));
}
$forum_last_replied_topic_row = $Cache->get_value('forum_'.$forumid.'_last_replied_topic_content');
if ($forum_last_replied_topic_row && $forum_last_replied_topic_row['lastpost'] == $postid)
$Cache->delete_value('forum_'.$forumid.'_last_replied_topic_content');
//------- Update topic
update_topic_last_post($topicid);
//===remove karma
KPS("-",$makepost_bonus,$userid);
header("Location: " . get_protocol_prefix() . "$BASEURL/forums.php?action=viewtopic&topicid=$topicid$redirtopost");
die;
}
//-------- Action: Set locked on/off
if ($action == "setlocked")
{
$topicid = 0 + $_POST["topicid"];
$ismod = is_forum_moderator($topicid,'topic');
if (!$topicid || (get_user_class() < $postmanage_class && !$ismod))
permissiondenied();
$locked = sqlesc($_POST["locked"]);
sql_query("UPDATE topics SET locked=$locked WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
header("Location: $_POST[returnto]");
die;