forked from Bigjoos/U-232
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforums.php
More file actions
2695 lines (2278 loc) · 128 KB
/
forums.php
File metadata and controls
2695 lines (2278 loc) · 128 KB
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
/**
* http://btdev.net:1337/svn/test/Installer09_Beta
* Licence Info: GPL
* Copyright (C) 2010 BTDev Installer v.1
* A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
* Project Leaders: Mindless,putyn.
**/
/****
* Credits - Retro-Alex2005-Puytn-pdq-Bigjoos
* Fully updated/Xhtml vaildated For Tbdev 09
* Bigjoos 27/10/2010
******
*/
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
require_once(INCL_DIR.'user_functions.php');
require_once(INCL_DIR.'bbcode_functions.php');
require_once(INCL_DIR.'pager_functions.php');
require_once(INCL_DIR.'html_functions.php');
require_once(INCL_DIR.'mood.php');
dbconn();
$lang = array_merge( load_language('global'), load_language('forums') );
if ($TBDEV['forums_online'] == 0 AND $CURUSER['class'] < UC_MODERATOR)
stderr('Information', 'The forums are currently offline for maintainance work');
if (function_exists('parked'))
parked();
/**
* Configs Start
*/
/**
* The max class, ie: UC_CODER
*
* Is able to delete, edit the forum etc...
*/
define('MAX_CLASS', UC_SYSOP);
/**
* The max file size allowed to be uploaded
*
* Default: 1024*1024 = 1MB
*/
$maxfilesize = 40096 * 1024;
/**
* Set's the max file size in php.ini, no need to change
*/
ini_set("upload_max_filesize", $maxfilesize);
/**
* The path to the attachment dir, no slahses
*/
$attachment_dir = ROOT_DIR . "forum_attachments";
/**
* The width of the forum, in percent, 100% is the full width
*
* Note: the width is also set in the function begin_main_frame()
*/
$forum_width = '100%';
/**
* The extensions that are allowed to be uploaded by the users
*
* Note: you need to have the pics in the $pic_base_url folder, ie zip.gif, rar.gif
*/
$allowed_file_extensions = array('rar', 'zip');
/**
* The max subject lenght in the topic descriptions, forum name etc...
*/
$maxsubjectlength = 80;
/**
* Get's the users posts per page, no need to change
*/
$postsperpage = (empty($CURUSER['postsperpage']) ? 25 : (int)$CURUSER['postsperpage']);
/**
* Set to true if you want to use the flood mod
*/
$use_flood_mod = true;
/**
* If there are more than $limit(default 10) posts in the last $minutes(default 5) minutes, it will give them a error...
*
* Requires the flood mod set to true
*/
$minutes = 5;
$limit = 10;
/**
* Set to true if you want to use the attachment mod
*
* Requires 2 extra tables(attachments, attachmentdownloads), so efore enabling it, make sure you have them...
*/
$use_attachment_mod = true;
/**
* Set to true if you want to use the forum poll mod
*
* Requires 2 extra tables(postpolls, postpollanswers), so efore enabling it, make sure you have them...
*/
$use_poll_mod = true;
/**
* Set to false to disable the forum stats
*/
$use_forum_stats_mod = true;
/**
* Define htmlout and javascripts
*/
$HTMLOUT='';
$HTMLOUT.="<script type='text/javascript' src='./scripts/popup.js'></script>
<script type='text/javascript' src='./scripts/shout.js'></script>";
/**
* Change the pics to the ones you use
*/
$forum_pics = array('default_avatar' => 'default_avatar.gif', 'arrow_up' => 'p_up.gif', 'online_btn' => 'user_online.gif',
'offline_btn' => 'user_offline.gif', 'pm_btn' => 'pm.gif', 'p_report_btn' => 'report.gif',
'p_quote_btn' => 'p_quote.gif', 'p_delete_btn' => 'p_delete.gif', 'p_edit_btn' => 'p_edit.gif');
/**
* Configs End
*/
//== Putyns post icons
function post_icons($s = 0)
{
$body = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"8\" >
<tr><td width=\"20%\" valign=\"top\" align=\"right\"><strong>Post Icons</strong> <br/>
<font class=\"small\">(Optional)</font></td>\n";
$body .= "<td width=\"80%\" align=\"left\">\n";
for($i = 1; $i < 15;$i++) {
$body .= "<input type=\"radio\" value=\"" . $i . "\" name=\"iconid\" " . ($s == $i ? "checked=\"checked\"" : "") . " />\n<img align=\"middle\" alt=\"\" src=\"pic/post_icons/icon" . $i . ".gif\"/>\n";
if ($i == 7)
$body .= "<br/>";
}
$body .= "<br/><input type=\"radio\" value=\"0\" name=\"iconid\" " . ($s == 0 ? "checked=\"checked\"" : "") . " />[Use None]\n";
$body .= "</td></tr></table>\n";
return $body;
}
//==Putyns subforums
function subforums($arr)
{
$sub = "<font class=\"small\"><b>Subforums:</b>";
$i = 0;
foreach($arr as $k) {
$sub .= " <img src=\"pic/bullet_" . ($k["new"] == 1 ? "green.png" : "white.png") . "\" width=\"8\" title=\"" . ($k["new"] == 1 ? "New posts" : "Not new post") . "\" border=\"0\" alt='Subforum' /><a href=\"forums.php?action=viewforum&forumid=" . $k["id"] . "\">" . $k["name"] . "</a>" . ((count($arr)-1) == $i ? "" : ",");
$i++;
}
$sub .= "</font>";
return $sub;
}
function get_count($arr)
{
$topics = 0;
$posts = 0;
foreach($arr as $k) {
$topics += $k["topics"];
$posts += $k["posts"];
}
return array($posts, $topics);
}
//== End subforum
//== Forum moderator by putyn
function showMods($ars)
{
$mods = "<font class=\"small\">Led by: ";
$i = 0;
$count = count($ars);
foreach($ars as $a) {
$mods .= "<a href=\"userdetails.php?id=" . $a["id"] . "\">" . $a["user"] . "</a>" . (($count -1) == $i ? "":" ,");
$i++;
}
$mods .= "</font>";
return $mods;
}
function isMod($fid)
{
GLOBAL $CURUSER;
return (stristr($CURUSER["forums_mod"], "[" . $fid . "]") == true ? true : false) ;
}
//== End forum moderator :)
$action = (isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"]) ? $_POST["action"] : ''));
if (!function_exists('highlight')) {
function highlight($search, $subject, $hlstart = '<b><font color=\"red\">', $hlend = '</font></b>')
{
$srchlen = strlen($search); // length of searched string
if ($srchlen == 0)
return $subject;
$find = $subject;
while ($find = stristr($find, $search)) { // find $search text in $subject -case insensitiv
$srchtxt = substr($find, 0, $srchlen); // get new search text
$find = substr($find, $srchlen);
$subject = str_replace($srchtxt, $hlstart . $srchtxt . $hlend, $subject); // highlight founded case insensitive search text
}
return $subject;
}
}
function catch_up($id = 0)
{
global $CURUSER, $TBDEV;
$userid = (int)$CURUSER['id'];
$res = mysql_query("SELECT t.id, t.lastpost, r.id AS r_id, r.lastpostread " . "FROM topics AS t " . "LEFT JOIN posts AS p ON p.id = t.lastpost " . "LEFT JOIN readposts AS r ON r.userid=" . sqlesc($userid) . " AND r.topicid=t.id " . "WHERE p.added > " . sqlesc(time() - $TBDEV['readpost_expiry']) .
(!empty($id) ? ' AND t.id ' . (is_array($id) ? 'IN (' . implode(', ', $id) . ')' : '= ' . sqlesc($id)) : '')) or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res)) {
$postid = (int)$arr['lastpost'];
if (!is_valid_id($arr['r_id']))
mysql_query("INSERT INTO readposts (userid, topicid, lastpostread) VALUES($userid, " . (int)$arr['id'] . ", $postid)") or sqlerr(__FILE__, __LINE__);
else if ($arr['lastpostread'] < $postid)
mysql_query("UPDATE readposts SET lastpostread = $postid WHERE id = " . $arr['r_id']) or sqlerr(__FILE__, __LINE__);
}
mysql_free_result($res);
}
//==Begin cached online users
function forum_stats()
{
//== 09 Active users in forums
$htmlout ='';
global $TBDEV, $forum_width, $lang, $CURUSER;
$forum3="";
$file = "./cache/forum.txt";
$expire = 30; // 30 seconds
if (file_exists($file) && filemtime($file) > (time() - $expire)) {
$forum3 = unserialize(file_get_contents($file));
} else {
$dt = sqlesc(time() - 180);
$forum1 = mysql_query("SELECT id, username, class, warned, donor, king, pirate, anonymous FROM users WHERE forum_access >= $dt ORDER BY class DESC") or sqlerr(__FILE__, __LINE__);
while ($forum2 = mysql_fetch_assoc($forum1)) {
$forum3[] = $forum2;
}
$OUTPUT = serialize($forum3);
$fp = fopen($file, "w");
fputs($fp, $OUTPUT);
fclose($fp);
} // end else
$forumusers = "";
if (is_array($forum3))
foreach ($forum3 as $arr) {
if ($forumusers) $forumusers .= ",\n";
$forumusers .= "<span style=\"white-space: nowrap;\">";
if ($arr["anonymous"] == "yes")
if ($CURUSER['class'] < UC_MODERATOR && $arr["id"] != $CURUSER["id"])
$arr["username"] = "<i>Anonymous</i>";
else
$arr["username"] = "<font color='#" . get_user_class_color($arr['class']) . "'> " . htmlspecialchars($arr['username']) . "</font>+";
else
$arr["username"] = "<font color='#" . get_user_class_color($arr['class']) . "'> " . htmlspecialchars($arr['username']) . "</font>";
$donator = $arr["donor"] === "yes";
$warned = $arr["warned"] === "yes";
if ($CURUSER)
$forumusers .= "<a href='{$TBDEV['baseurl']}/userdetails.php?id={$arr["id"]}'><b>{$arr["username"]}</b></a>";
else
$forumusers .= "<b>{$arr["username"]}</b>";
if ($arr["anonymous"] == "yes")
if ($CURUSER['class'] < UC_MODERATOR && $arr["id"] != $CURUSER["id"])
$forumusers .= "";
else
if ($donator)
$forumusers .= "<img src='{$TBDEV['pic_base_url']}star.gif' alt='Donated' />";
if ($arr["anonymous"] == "yes")
if ($CURUSER['class'] < UC_MODERATOR && $arr["id"] != $CURUSER["id"])
$forumusers .= "";
else
if ($warned)
$forumusers .= "<img src='{$TBDEV['pic_base_url']}warned.gif' alt='Warned' />";
$forumusers .= "</span>";
}
if (!$forumusers)
$forumusers = "Currently No Active users in the Forum";
$topic_post_res = mysql_query("SELECT SUM(topiccount) AS topics, SUM(postcount) AS posts FROM forums");
$topic_post_arr = mysql_fetch_assoc($topic_post_res);
$htmlout .="<br />
<table width='{$forum_width}' border='0' cellspacing='0' cellpadding='5'>
<tr>
<td class='colhead' align='center'>Now active in Forums:</td>
</tr>
<tr>
<td class='text'>";
if ($CURUSER['anonymous'] == 'yes'){
$htmlout .="<p align='center'>(+) next to your username indicates you are Anonymous !</p>";
}
$htmlout .="{$forumusers}</td>
</tr>
<tr>
<td class='colhead' align='center'><h2>Our members wrote <b>".number_format($topic_post_arr['posts'])."</b> Posts in <b>".number_format($topic_post_arr['topics'])."</b> Threads</h2></td>
</tr>
</table>";
return $htmlout;
}
//== End
function show_forums($forid, $subforums = false, $sfa = "", $mods_array = "", $show_mods = false)
{
global $CURUSER, $TBDEV;
$htmlout='';
$forums_res = mysql_query("SELECT f.id, f.name, f.description, f.postcount, f.topiccount, f.minclassread, p.added, p.topicid, p.anonymous, p.userid, p.id AS pid, u.username, t.subject, t.lastpost, r.lastpostread " . "FROM forums AS f " . "LEFT JOIN posts AS p ON p.id = (SELECT MAX(lastpost) FROM topics WHERE forumid = f.id) " . "LEFT JOIN users AS u ON u.id = p.userid " . "LEFT JOIN topics AS t ON t.id = p.topicid " . "LEFT JOIN readposts AS r ON r.userid = " . sqlesc($CURUSER['id']) . " AND r.topicid = p.topicid " . "WHERE " . ($subforums == false ? "f.forid = $forid AND f.place =-1 ORDER BY f.forid ASC" : "f.place=$forid ORDER BY f.id ASC") . "") or sqlerr(__FILE__, __LINE__);
while ($forums_arr = mysql_fetch_assoc($forums_res)) {
if ($CURUSER['class'] < $forums_arr["minclassread"])
continue;
$forumid = (int)$forums_arr["id"];
$lastpostid = (int)$forums_arr['lastpost'];
if ($subforums == false && !empty($sfa[$forumid])) {
if (($sfa[$forumid]['lastpost']['postid'] > $forums_arr['pid'])) {
if ($sfa[$forumid]['lastpost']["anonymous"] == "yes") {
if($CURUSER['class'] < UC_MODERATOR && $sfa[$forumid]['lastpost']['userid'] != $CURUSER['id'])
$lastpost1 = "Anonymous<br />";
else
$lastpost1 = "Anonymous(<a href='{$TBDEV['baseurl']}/userdetails.php?id=" . (int)$sfa[$forumid]['lastpost']['userid'] . "'><b>" . htmlspecialchars($sfa[$forumid]['lastpost']['user']) . "</b></a>)<br />";
}
elseif ($sfa[$forumid]['lastpost']["anonymous"] == "no") {
$lastpost1 = "<a href='{$TBDEV['baseurl']}/userdetails.php?id=" . (int)$sfa[$forumid]['lastpost']['userid'] . "'><b>" . htmlspecialchars($sfa[$forumid]['lastpost']['user']) . "</b></a><br />";
}
$lastpost = "" . get_date($sfa[$forumid]['lastpost']['added'], 'LONG',1,0) . "<br />" . "by $lastpost1" . "in <a href='" . $_SERVER['PHP_SELF'] . "?action=viewtopic&topicid=" . (int)$sfa[$forumid]['lastpost']['topic'] . "&page=p" . $sfa[$forumid]['lastpost']['postid'] . "#p" . $sfa[$forumid]['lastpost']['postid'] . "'><b>" . htmlspecialchars($sfa[$forumid]['lastpost']['tname']) . "</b></a>";
}
elseif (($sfa[$forumid]['lastpost']['postid'] < $forums_arr['pid'])) {
if ($forums_arr["anonymous"] == "yes") {
if($CURUSER['class'] < UC_MODERATOR && $forums_arr["userid"] != $CURUSER["id"])
$lastpost2 = "Anonymous<br />";
else
$lastpost2 = "Anonymous(<a href='{$TBDEV['baseurl']}/userdetails.php?id=" . (int)$forums_arr["userid"] . "'><b>" . htmlspecialchars($forums_arr['username']) . "</b></a>)<br />";
}
elseif ($forums_arr["anonymous"] == "no") {
$lastpost2 = "<a href='{$TBDEV['baseurl']}/userdetails.php?id=" . (int)$forums_arr["userid"] . "'><b>" . htmlspecialchars($forums_arr['username']) . "</b></a><br />";
}
$lastpost = "" .get_date($forums_arr["added"], 'LONG',1,0) . "<br />" . "by $lastpost2" . "in <a href='" . $_SERVER['PHP_SELF'] . "?action=viewtopic&topicid=" . (int)$forums_arr["topicid"] . "&page=p$lastpostid#p$lastpostid'><b>" . htmlspecialchars($forums_arr['subject']) . "</b></a>";
} else
$lastpost = "N/A";
} else {
if (is_valid_id($forums_arr['pid']))
if ($forums_arr["anonymous"] == "yes") {
if($CURUSER['class'] < UC_MODERATOR && $forums_arr["userid"] != $CURUSER["id"])
$lastpost ="" .get_date($forums_arr["added"], 'LONG',1,0) . "<br />" . "by <i>Anonymous</i><br />" . "in <a href='" . $_SERVER['PHP_SELF'] . "?action=viewtopic&topicid=" . (int)$forums_arr["topicid"] . "&page=p$lastpostid#p$lastpostid'><b>" . htmlspecialchars($forums_arr['subject']) . "</b></a>";
else
$lastpost ="" .get_date($forums_arr["added"], 'LONG',1,0) . "<br />" . "by <i>Anonymous</i>(<a href='{$TBDEV['baseurl']}/userdetails.php?id=" . (int)$forums_arr["userid"] . "'><b>" . htmlspecialchars($forums_arr['username']) . "</b></a>)<br />" . "in <a href='" . $_SERVER['PHP_SELF'] . "?action=viewtopic&topicid=" . (int)$forums_arr["topicid"] . "&page=p$lastpostid#p$lastpostid'><b>" . htmlspecialchars($forums_arr['subject']) . "</b></a>";
}
else
$lastpost = "" .get_date($forums_arr["added"], 'LONG',1,0) . "<br />" . "by <a href='{$TBDEV['baseurl']}/userdetails.php?id=" . (int)$forums_arr["userid"] . "'><b>" . htmlspecialchars($forums_arr['username']) . "</b></a><br />" . "in <a href='" . $_SERVER['PHP_SELF'] . "?action=viewtopic&topicid=" . (int)$forums_arr["topicid"] . "&page=p$lastpostid#p$lastpostid'><b>" . htmlspecialchars($forums_arr['subject']) . "</b></a>";
else
$lastpost = "N/A";
}
if (is_valid_id($forums_arr['pid']))
$img = 'unlocked' . ((($forums_arr['added'] > (time() - $TBDEV['readpost_expiry']))?((int)$forums_arr['pid'] > $forums_arr['lastpostread']):0)?'new':'');
else
$img = "unlocked";
if ($subforums == false && !empty($sfa[$forumid])) {
list($subposts, $subtopics) = get_count($sfa[$forumid]["count"]);
$topics = $forums_arr["topiccount"] + $subtopics;
$posts = $forums_arr["postcount"] + $subposts;
} else {
$topics = $forums_arr["topiccount"];
$posts = $forums_arr["postcount"];
}
$htmlout.="<tr>
<td align='left'>
<table border='0' cellspacing='0' cellpadding='0' style='border:none;'>
<tr>
<td class='embedded' style='padding-right: 5px'><img src='".$TBDEV['pic_base_url'].$img.".gif' alt='' /></td>
<td class='embedded'>
<a href='".$_SERVER['PHP_SELF']."?action=viewforum&forumid=".$forumid."'><b>". htmlspecialchars($forums_arr["name"])."</b></a>";
if ($CURUSER['class'] >= UC_ADMINISTRATOR || isMod($forumid)) {
$htmlout.=" <font class='small'>[<a class='altlink' href='".$_SERVER['PHP_SELF']."?action=editforum&forumid=".$forumid."'>Edit</a>][<a class='altlink' href='".$_SERVER['PHP_SELF']."?action=deleteforum&forumid=".$forumid."'>Delete</a>]</font>";
}
if (!empty($forums_arr["description"])) {
$htmlout.="<br />". htmlspecialchars($forums_arr["description"]);
}
if ($subforums == false && !empty($sfa[$forumid]))
$htmlout.="<br/>" . subforums($sfa[$forumid]["topics"]);
if ($show_mods == true && isset($mods_array[$forumid]))
$htmlout.="<br/>" . showMods($mods_array[$forumid]);
$htmlout.="</td>
</tr>
</table>
</td>
<td align='center'>". number_format($topics)."</td>
<td align='center'>". number_format($posts)."</td>
<td align='left' nowrap='nowrap'>".$lastpost."</td>
</tr>";
}
return $htmlout;
}
// -------- Returns the minimum read/write class levels of a forum
function get_forum_access_levels($forumid)
{
$res = mysql_query("SELECT minclassread, minclasswrite, minclasscreate FROM forums WHERE id = " . sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
return false;
$arr = mysql_fetch_assoc($res);
return array("read" => $arr["minclassread"], "write" => $arr["minclasswrite"], "create" => $arr["minclasscreate"]);
}
// -------- Returns the forum ID of a topic, or false on error
function get_topic_forum($topicid)
{
$res = mysql_query("SELECT forumid FROM topics WHERE id = " . sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
return false;
$arr = mysql_fetch_assoc($res);
return (int)$arr['forumid'];
}
// -------- Returns the ID of the last post of a forum
function update_topic_last_post($topicid)
{
$res = mysql_query("SELECT MAX(id) AS id FROM posts WHERE topicid = " . sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or die("No post found");
mysql_query("UPDATE topics SET lastpost = {$arr['id']} WHERE id = " . sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
}
function get_forum_last_post($forumid)
{
$res = mysql_query("SELECT MAX(lastpost) AS lastpost FROM topics WHERE forumid = " . sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res);
$postid = (int)$arr['lastpost'];
return (is_valid_id($postid) ? $postid : 0);
}
// -------- Inserts a quick jump menu
function insert_quick_jump_menu($currentforum = 0)
{
global $CURUSER, $TBDEV;
$htmlout='';
$htmlout .=
<form method='get' action='".$_SERVER['PHP_SELF']."' name='jump'>
<input type='hidden' name='action' value='viewforum' />
<div align='center'><b>Quick jump:</b>
<select name='forumid' onchange=\"if(this.options[this.selectedIndex].value != -1){ forms['jump'].submit() }\">";
$res = mysql_query("SELECT id, name, minclassread FROM forums ORDER BY name") or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
if ($CURUSER['class'] >= $arr["minclassread"])
$htmlout .="<option value='".$arr["id"].($currentforum == $arr["id"] ? " selected" : "")."'>".$arr["name"]."</option>";
$htmlout .="</select>
<input type='submit' value='Go!' class='gobutton' />
</div>
</form>";
return $htmlout;
}
// -------- Inserts a compose frame
function insert_compose_frame($id, $newtopic = true, $quote = false, $attachment = false)
{
global $maxsubjectlength, $CURUSER, $TBDEV, $maxfilesize, $use_attachment_mod, $forum_pics;
$htmlout='';
if ($newtopic) {
$res = mysql_query("SELECT name FROM forums WHERE id = " . sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or die("Bad forum ID!");
$htmlout .="<h3>New topic in <a href='". $_SERVER['PHP_SELF']."?action=viewforum&forumid=".$id."'>".htmlspecialchars($arr["name"])."</a> forum</h3>";
} else {
$res = mysql_query("SELECT subject, locked FROM topics WHERE id = " . sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or die("Forum error, Topic not found.");
if ($arr['locked'] == 'yes') {
stderr("Sorry", "The topic is locked.");
$htmlout .= end_table();
$htmlout .= end_main_frame();
print stdhead("Compose") . $htmlout . stdfoot();
exit();
}
$htmlout .="<h3 align='center'>Reply to topic: <a href='".$_SERVER['PHP_SELF']."action=viewtopic&topicid=".$id."'>". htmlspecialchars($arr["subject"])."</a></h3>";
}
$htmlout .=
<script type='text/javascript'>
/*<![CDATA[*/
function Preview()
{
document.compose.action = './preview.php'
document.compose.target = '_blank';
document.compose.submit();
return true;
}
/*]]>*/
</script>";
$htmlout .= begin_frame("Compose", true);
$htmlout .="<form method='post' name='compose' action='".$_SERVER['PHP_SELF']."' enctype='multipart/form-data'>
<input type='hidden' name='action' value='post' />
<input type='hidden' name='". ($newtopic ? 'forumid' : 'topicid')."' value='".$id."' />";
$htmlout .= begin_table(true);
if ($newtopic) {
$htmlout .="<tr>
<td class='rowhead' width='10%'>Subject</td>
<td align='left'>
<input type='text' size='100' maxlength='".$maxsubjectlength."' name='subject' style='height: 19px' />
</td>
</tr>";
}
if ($quote) {
$postid = (int)$_GET["postid"];
if (!is_valid_id($postid)) {
stderr("Error", "Invalid ID!");
$htmlout .= end_table();
$htmlout .= end_main_frame();
print stdhead("Compose") . $htmlout . stdfoot();
exit();
}
$res = mysql_query("SELECT posts.*, users.username FROM posts JOIN users ON posts.userid = users.id WHERE posts.id = $postid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0) {
stderr("Error", "No post with this ID");
$htmlout .= end_table();
$htmlout .= end_main_frame();
print stdhead("Error - No post with this ID") . $htmlout . stdfoot();
exit();
}
$arr = mysql_fetch_assoc($res);
}
$htmlout .="<tr>
<td class='rowhead' width='10%'>Body</td>
<td>";
$qbody = ($quote ? "[quote=".htmlspecialchars($arr["username"])."]".htmlspecialchars(unesc($arr["body"]))."[/quote]" : "");
if (function_exists('textbbcode'))
$htmlout .= textbbcode("compose", "body", $qbody);
else
{
$htmlout .="<textarea name='body' style='width:99%' rows='7'>{$qbody}</textarea>";
}
$htmlout .="</td></tr>";
if ($use_attachment_mod && $attachment)
{
$htmlout .="<tr>
<td colspan='2'><fieldset class='fieldset'><legend>Add Attachment</legend>
<input type='checkbox' name='uploadattachment' value='yes' />
<input type='file' name='file' size='60' />
<div class='error'>Allowed Files: rar, zip<br />Size Limit ".mksize($maxfilesize)."</div></fieldset>
</td>
</tr>";
}
$htmlout .="<tr>
<td align='center' colspan='2'>".(post_icons())."</td>
</tr><tr>
<td colspan='2' align='center'>
<input type='submit' value='Submit' /><input type='button' value='Preview' name='button2' onclick='return Preview();' />\n";
if ($newtopic){
$htmlout .= "Anonymous Topic<input type='checkbox' name='anonymous' value='yes'/>\n";
}
else
{
$htmlout .= "Anonymous Post<input type='checkbox' name='anonymous' value='yes'/>\n";
}
$htmlout .= "</td></tr>\n";
$htmlout .= end_table();
$htmlout .="</form>";
$htmlout .= end_frame();
// ------ Get 10 last posts if this is a reply
if (!$newtopic) {
$postres = mysql_query("SELECT p.id, p.added, p.body, p.anonymous, u.id AS uid, u.username, u.avatar, u.offavatar " . "FROM posts AS p " . "LEFT JOIN users AS u ON u.id = p.userid " . "WHERE p.topicid = " . sqlesc($id) . " " . "ORDER BY p.id DESC LIMIT 10") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($postres) > 0) {
$htmlout .="<br />";
$htmlout .= begin_frame("10 last posts, in reverse order");
while ($post = mysql_fetch_assoc($postres)) {
$avatar = ($CURUSER["avatars"] == "all" ? htmlspecialchars($post["avatar"]) : ($CURUSER["avatars"] == "some" && $post["offavatar"] == "no" ? htmlspecialchars($post["avatar"]) : ""));
if ($post['anonymous'] == 'yes') {
$avatar = $TBDEV['pic_base_url'] . $forum_pics['default_avatar'];
}
else {
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($post["avatar"]) : '');
}
if (empty($avatar))
$avatar = $TBDEV['pic_base_url'] . $forum_pics['default_avatar'];
if ($post["anonymous"] == "yes")
if($CURUSER['class'] < UC_MODERATOR && $post["uid"] != $CURUSER["id"]){
$htmlout .= "<p class='sub'>#" . $post["id"] . " by <i>Anonymous</i> at ".get_date($post["added"], 'LONG',1,0)."</p>";
}
else{
$htmlout .= "<p class='sub'>#" . $post["id"] . " by <i>Anonymous</i> (<b>" . $post["username"] . "</b>) at ".get_date($post["added"], 'LONG',1,0)."</p>";
}
else
$htmlout .="<p class='sub'>#".$post["id"]." by ". (!empty($post["username"]) ? $post["username"] : "unknown[{$post['uid']}]")." at ".get_date($post["added"], 'LONG',1,0)."</p>";
$htmlout .= begin_table(true);
$htmlout .="<tr>
<td height='100' width='100' align='center' style='padding: 0px' valign='top'><img height='100' width='100' src='".$avatar."' alt='User avvy' /></td>
<td class='comment' valign='top'>". format_comment($post["body"])."</td>
</tr>";
$htmlout .= end_table();
}
$htmlout .= end_frame();
}
}
$htmlout .= insert_quick_jump_menu();
return $htmlout;
}
if ($action == 'updatetopic') {
$topicid = (isset($_GET['topicid']) ? (int)$_GET['topicid'] : (isset($_POST['topicid']) ? (int)$_POST['topicid'] : 0));
if (!is_valid_id($topicid))
stderr('Error...', 'Invalid topic ID!');
$topic_res = mysql_query('SELECT t.sticky, t.locked, t.subject, t.forumid, f.minclasswrite, ' . '(SELECT COUNT(id) FROM posts WHERE topicid = t.id) As post_count ' . 'FROM topics AS t ' . 'LEFT JOIN forums AS f ON f.id = t.forumid ' . 'WHERE t.id = ' . sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($topic_res) == 0)
stderr('Error...', 'No topic with that ID!');
$topic_arr = mysql_fetch_assoc($topic_res);
if (isMod($topic_arr["forumid"]) || $CURUSER['class'] >= UC_MODERATOR) {
if (($CURUSER['class'] < (int)$topic_arr['minclasswrite']) && !isMod($topic_arr["forumid"]))
stderr('Error...', 'You are not allowed to edit this topic.');
$forumid = (int)$topic_arr['forumid'];
$subject = $topic_arr['subject'];
if ((isset($_GET['delete']) ? $_GET['delete'] : (isset($_POST['delete']) ? $_POST['delete'] : '')) == 'yes') {
if ((isset($_GET['sure']) ? $_GET['sure'] : (isset($_POST['sure']) ? $_POST['sure'] : '')) != 'yes')
stderr("Sanity check...", "You are about to delete this topic: <b>" . htmlspecialchars($subject) . "</b>. Click <a href='" . $_SERVER['PHP_SELF'] . "?action=$action&topicid=$topicid&delete=yes&sure=yes'>here</a> if you are sure.");
write_log("topicdelete","Topic <b>" . $subject . "</b> was deleted by <a href='{$TBDEV['baseurl']}/userdetails.php?id=" . $CURUSER['id'] . "'>" . $CURUSER['username'] . "</a>.");
if ($use_attachment_mod) {
$res = mysql_query("SELECT attachments.filename " . "FROM posts " . "LEFT JOIN attachments ON attachments.postid = posts.id " . "WHERE posts.topicid = " . sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
if (!empty($arr['filename']) && is_file($attachment_dir . "/" . $arr['filename']))
unlink($attachment_dir . "/" . $arr['filename']);
}
mysql_query("DELETE posts, topics " .
($use_attachment_mod ? ", attachments, attachmentdownloads " : "") .
($use_poll_mod ? ", postpolls, postpollanswers " : "") . "FROM topics " . "LEFT JOIN posts ON posts.topicid = topics.id " .
($use_attachment_mod ? "LEFT JOIN attachments ON attachments.postid = posts.id " . "LEFT JOIN attachmentdownloads ON attachmentdownloads.fileid = attachments.id " : "") .
($use_poll_mod ? "LEFT JOIN postpolls ON postpolls.id = topics.pollid " . "LEFT JOIN postpollanswers ON postpollanswers.pollid = postpolls.id " : "") . "WHERE topics.id = " . sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
header('Location: ' . $_SERVER['PHP_SELF'] . '?action=viewforum&forumid=' . $forumid);
exit();
}
$returnto = $_SERVER['PHP_SELF'] . '?action=viewtopic&topicid=' . $topicid;
$updateset = array();
$locked = ($_POST['locked'] == 'yes' ? 'yes' : 'no');
if ($locked != $topic_arr['locked'])
$updateset[] = 'locked = ' . sqlesc($locked);
$sticky = ($_POST['sticky'] == 'yes' ? 'yes' : 'no');
if ($sticky != $topic_arr['sticky'])
$updateset[] = 'sticky = ' . sqlesc($sticky);
$new_subject = $_POST['subject'];
if ($new_subject != $subject) {
if (empty($new_subject))
stderr('Error...', 'Topic name cannot be empty.');
$updateset[] = 'subject = ' . sqlesc($new_subject);
}
$new_forumid = (int)$_POST['new_forumid'];
if (!is_valid_id($new_forumid))
stderr('Error...', 'Invalid forum ID!');
if ($new_forumid != $forumid) {
$post_count = (int)$topic_arr['post_count'];
$res = mysql_query("SELECT minclasswrite FROM forums WHERE id = " . sqlesc($new_forumid)) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
stderr("Error...", "Forum not found!");
$arr = mysql_fetch_assoc($res);
if ($CURUSER['class'] < (int)$arr['minclasswrite'])
stderr('Error...', 'You are not allowed to move this topic into the selected forum.');
$updateset[] = 'forumid = ' . sqlesc($new_forumid);
mysql_query("UPDATE forums SET topiccount = topiccount - 1, postcount = postcount - " . sqlesc($post_count) . " WHERE id = " . sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
mysql_query("UPDATE forums SET topiccount = topiccount + 1, postcount = postcount + " . sqlesc($post_count) . " WHERE id = " . sqlesc($new_forumid)) or sqlerr(__FILE__, __LINE__);
$returnto = $_SERVER['PHP_SELF'] . '?action=viewforum&forumid=' . $new_forumid;
}
if (sizeof($updateset) > 0)
mysql_query("UPDATE topics SET " . implode(', ', $updateset) . " WHERE id = " . sqlesc($topicid));
header('Location: ' . $returnto);
exit();
}
} else if ($action == "editforum") { // -------- Action: Edit Forum
$forumid = (int)$_GET["forumid"];
if ($CURUSER['class'] == MAX_CLASS || isMod($forumid)) {
if (!is_valid_id($forumid))
stderr('Error', 'Invalid ID!');
$res = mysql_query("SELECT name, description, minclassread, minclasswrite, minclasscreate FROM forums WHERE id = $forumid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
stderr('Error', 'No forum found with that ID!');
$forum = mysql_fetch_assoc($res);
if ($TBDEV['forums_online'] == 0)
$HTMLOUT .= stdmsg('Warning', 'Forums are currently in maintainance mode');
$HTMLOUT .= begin_main_frame();
$HTMLOUT .= begin_frame("Edit Forum", "center");
$HTMLOUT .="<form method='post' action='" . $_SERVER['PHP_SELF'] . "?action=updateforum&forumid=$forumid'>\n";
$HTMLOUT .= begin_table();
$HTMLOUT .="<tr><td class='rowhead'>Forum name</td>
<td align='left' style='padding: 0px'><input type='text' size='60' maxlength='$maxsubjectlength' name='name' style='border: 0px; height: 19px' value=\"" . htmlspecialchars($forum['name']) . "\" /></td></tr>
<tr><td class='rowhead'>Description</td><td align='left' style='padding: 0px'><textarea name='description' cols='68' rows='3' style='border: 0px'>" . htmlspecialchars($forum['description']) . "</textarea></td></tr>
<tr><td class='rowhead'></td><td align='left' style='padding: 0px'> Minimum <select name='readclass'>";
for ($i = 0; $i <= MAX_CLASS; ++$i)
$HTMLOUT .="<option value='$i' " . ($i == $forum['minclassread'] ? " selected='selected'" : "") . ">" . get_user_class_name($i) . "</option>\n";
$HTMLOUT .="</select> Class required to View<br />\n Minimum <select name='writeclass'>";
for ($i = 0; $i <= MAX_CLASS; ++$i)
$HTMLOUT .="<option value='$i' " . ($i == $forum['minclasswrite'] ? " selected='selected'" : "") . ">" . get_user_class_name($i) . "</option>\n";
$HTMLOUT .="</select> Class required to Post<br />\n Minimum <select name='createclass'>";
for ($i = 0; $i <= MAX_CLASS; ++$i)
$HTMLOUT .="<option value='$i' " . ($i == $forum['minclasscreate'] ? " selected='selected'" : "") . ">" . get_user_class_name($i) . "</option>\n";
$HTMLOUT .="</select> Class required to Create Topics</td></tr>
<tr><td colspan='2' align='center'><input type='submit' value='Submit' /></td></tr>\n";
$HTMLOUT .= end_table();
$HTMLOUT .="</form>";
$HTMLOUT .= end_frame();
$HTMLOUT .= end_main_frame();
print stdhead("{$lang['forums_title']}") . $HTMLOUT . stdfoot();
exit();
}
} else if ($action == "updateforum") { // -------- Action: Update Forum
$forumid = (int)$_GET["forumid"];
if ($CURUSER['class'] == MAX_CLASS || isMod($forumid)) {
if (!is_valid_id($forumid))
stderr('Error', 'Invalid ID!');
$res = mysql_query('SELECT id FROM forums WHERE id = ' . sqlesc($forumid));
if (mysql_num_rows($res) == 0)
stderr('Error', 'No forum with that ID!');
$name = $_POST['name'];
$description = $_POST['description'];
if (empty($name))
stderr("Error", "You must specify a name for the forum.");
if (empty($description))
stderr("Error", "You must provide a description for the forum.");
mysql_query("UPDATE forums SET name = " . sqlesc($name) . ", description = " . sqlesc($description) . ", minclassread = " . sqlesc((int)$_POST['readclass']) . ", minclasswrite = " . sqlesc((int)$_POST['writeclass']) . ", minclasscreate = " . sqlesc((int)$_POST['createclass']) . " WHERE id = " . sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
header("Location: {$_SERVER['PHP_SELF']}");
exit();
}
} else if ($action == 'deleteforum') { // -------- Action: Delete Forum
$forumid = (int)$_GET['forumid'];
if ($CURUSER['class'] == MAX_CLASS || isMod($forumid)) {
if (!is_valid_id($forumid))
stderr('Error', 'Invalid ID!');
$confirmed = (int)isset($_GET['confirmed']) && (int)$_GET['confirmed'];
if (!$confirmed) {
$rt = mysql_query("SELECT topics.id, forums.name " . "FROM topics " . "LEFT JOIN forums ON forums.id=topics.forumid " . "WHERE topics.forumid = " . sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
$topics = mysql_num_rows($rt);
$posts = 0;
if ($topics > 0) {
while ($topic = mysql_fetch_assoc($rt)) {
$ids[] = $topic['id'];
$forum = $topic['name'];
}
$rp = mysql_query("SELECT COUNT(id) FROM posts WHERE topicid IN (" . join(', ', $ids) . ")");
foreach ($ids as $id)
if ($a = mysql_fetch_row($rp))
$posts += $a[0];
}
if ($use_attachment_mod || $use_poll_mod) {
$res = mysql_query("SELECT " .
($use_attachment_mod ? "COUNT(attachments.id) AS attachments " : "") .
($use_poll_mod ? ($use_attachment_mod ? ', ' : '') . "COUNT(postpolls.id) AS polls " : "") . "FROM topics " . "LEFT JOIN posts ON topics.id=posts.topicid " .
($use_attachment_mod ? "LEFT JOIN attachments ON attachments.postid = posts.id " : "") .
($use_poll_mod ? "LEFT JOIN postpolls ON postpolls.id=topics.pollid " : "") . "WHERE topics.forumid=" . sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
($use_attachment_mod ? $attachments = 0 : null);
($use_poll_mod ? $polls = 0 : null);
if ($arr = mysql_fetch_assoc($res)) {
($use_attachment_mod ? $attachments = $arr['attachments'] : null);
($use_poll_mod ? $polls = $arr['polls'] : null);
}
}
stderr("** WARNING! **", "Deleting forum with id=$forumid (" . $forumid . ") will also delete " . $posts . " post" . ($posts != 1 ? 's' : '') . ($use_attachment_mod ? ", " . $attachments . " attachment" . ($attachments != 1 ? 's' : '') : "") . ($use_poll_mod ? " and " . ($polls - $attachments) . " poll" . (($polls - $attachments) != 1 ? 's' : '') : "") . " in " . $topics . " topic" . ($topics != 1 ? 's' : '') . ". [<a href=" . $_SERVER['PHP_SELF'] . "?action=deleteforum&forumid=$forumid&confirmed=1>ACCEPT</a>] [<a href=" . $_SERVER['PHP_SELF'] . "?action=viewforum&forumid=$forumid>CANCEL</a>]");
}
$rt = mysql_query("SELECT topics.id " . ($use_attachment_mod ? ", attachments.filename " : "") . "FROM topics " . "LEFT JOIN posts ON topics.id = posts.topicid " .
($use_attachment_mod ? "LEFT JOIN attachments ON attachments.postid = posts.id " : "") . "WHERE topics.forumid = " . sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
while ($topic = mysql_fetch_assoc($rt)) {
$tids[] = $topic['id'];
if ($use_attachment_mod && !empty($topic['filename'])) {
$filename = $attachment_dir . "/" . $topic['filename'];
if (is_file($filename))
unlink($filename);
}
}
mysql_query("DELETE posts.*, topics.*, forums.* " . ($use_attachment_mod ? ", attachments.*, attachmentdownloads.* " : "") . ($use_poll_mod ? ", postpolls.*, postpollanswers.* " : "") . "FROM posts " .
($use_attachment_mod ? "LEFT JOIN attachments ON attachments.postid = posts.id " . "LEFT JOIN attachmentdownloads ON attachmentdownloads.fileid = attachments.id " : "") . "LEFT JOIN topics ON topics.id = posts.topicid " . "LEFT JOIN forums ON forums.id = topics.forumid " .
($use_poll_mod ? "LEFT JOIN postpolls ON postpolls.id = topics.pollid " . "LEFT JOIN postpollanswers ON postpollanswers.pollid = postpolls.id " : "") . "WHERE posts.topicid IN (" . join(', ', $tids) . ")") or sqlerr(__FILE__, __LINE__);
header("Location: {$_SERVER['PHP_SELF']}");
exit();
}
} else if ($action == "newtopic") { // -------- Action: New topic
$forumid = (int)$_GET["forumid"];
if (!is_valid_id($forumid))
stderr('Error', 'Invalid ID!');
$HTMLOUT .= begin_main_frame();
if ($TBDEV['forums_online'] == 0)
$HTMLOUT .= stdmsg('Warning', 'Forums are currently in maintainance mode');
$HTMLOUT .= insert_compose_frame($forumid, true, false, true);
$HTMLOUT .= end_main_frame();
print stdhead("New Topic") . $HTMLOUT . stdfoot();
exit();
} else if ($action == "post") { // -------- Action: Post
$forumid = (isset($_POST['forumid']) ? (int)$_POST['forumid'] : null);
if (isset($forumid) && !is_valid_id($forumid))
stderr('Error', 'Invalid forum ID!');
$posticon = (isset($_POST["iconid"]) ? 0 + $_POST["iconid"] : 0);
$topicid = (isset($_POST['topicid']) ? (int)$_POST['topicid'] : null);
if (isset($topicid) && !is_valid_id($topicid))
stderr('Error', 'Invalid topic ID!');
$newtopic = is_valid_id($forumid);
$subject = (isset($_POST["subject"]) ? $_POST["subject"] : '');
if ($newtopic) {
$subject = trim($subject);
if (empty($subject))
stderr("Error", "You must enter a subject.");
if (strlen($subject) > $maxsubjectlength)
stderr("Error", "Subject is limited to " . $maxsubjectlength . " characters.");
} else
$forumid = get_topic_forum($topicid) or die("Bad topic ID");
// ------ Make sure sure user has write access in forum
$arr = get_forum_access_levels($forumid) or die("Bad forum ID");
if ($CURUSER['class'] < $arr["write"] || ($newtopic && $CURUSER['class'] < $arr["create"]) && !isMod($forumid))
stderr("Error", "Permission denied.");
$body = trim($_POST["body"]);
if (empty($body))
stderr("Error", "No body text.");
$userid = (int)$CURUSER["id"];
if ($use_flood_mod && $CURUSER['class'] < UC_MODERATOR && !isMod($forumid)) {
$res = mysql_query("SELECT COUNT(id) AS c FROM posts WHERE userid = " . $CURUSER['id'] . " AND added > '" . (time() - ($minutes * 60)) . "'");
$arr = mysql_fetch_assoc($res);
if ($arr['c'] > $limit)
stderr("Flood", "More than " . $limit . " posts in the last " . $minutes . " minutes.");
}
if ($newtopic)
{
$subject = sqlesc($subject);
$anonymous = (isset($_POST['anonymous']) && $_POST["anonymous"] != "" ? "yes" : "no");
mysql_query("INSERT INTO topics (userid, forumid, subject, anonymous) VALUES($userid, $forumid, $subject, ".sqlesc($anonymous).")") or sqlerr(__FILE__, __LINE__);
$topicid = mysql_insert_id() or stderr("Error", "No topic ID returned!");
$added = sqlesc(time());
$body = sqlesc($body);
$anonymous = (isset($_POST['anonymous']) && $_POST["anonymous"] != "" ? "yes" : "no");
mysql_query("INSERT INTO posts (topicid, userid, added, body, anonymous, posticon) VALUES($topicid, $userid, $added, $body, ".sqlesc($anonymous).",$posticon)") or sqlerr(__FILE__, __LINE__);
$postid = mysql_insert_id() or stderr("Error", "No post ID returned!");
update_topic_last_post($topicid);
if($TBDEV['forums_autoshout_on'] == 1){
if ($anonymous == 'yes')
$message = "(Anonymous) Created a new forum thread [url={$TBDEV['baseurl']}/forums.php?action=viewtopic&topicid=$topicid&page=last]{$subject}[/url]";
else
$message = $CURUSER['username'] . " Created a new forum thread [url={$TBDEV['baseurl']}/forums.php?action=viewtopic&topicid=$topicid&page=last]{$subject}[/url]";
//////remember to edit the ids to your staffforum ids :)
if (!in_array($forumid, array("18","23","24","25"))) {
autoshout($message);
}
}
if($TBDEV['forums_seedbonus_on'] == 1){
mysql_query("UPDATE users SET seedbonus = seedbonus+3.0 WHERE id = ". sqlesc($CURUSER['id']."")) or sqlerr(__FILE__, __LINE__);
}
}
else
{
//---- Make sure topic exists and is unlocked
$res = mysql_query("SELECT locked, subject FROM topics WHERE id = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
stderr('Error', 'Inexistent Topic!');
$arr = mysql_fetch_assoc($res);
$subject = htmlspecialchars($arr["subject"]);
if ($arr["locked"] == 'yes' && $CURUSER['class'] < UC_MODERATOR)
stderr("Error", "This topic is locked; No new posts are allowed.");
// === PM subscribed members
$res_sub = mysql_query("SELECT userid FROM subscriptions WHERE topicid = ".sqlesc($topicid)."") or sqlerr(__FILE__, __LINE__);
while ($row = mysql_fetch_assoc($res_sub)) {
$res_yes = sql_query("SELECT subscription_pm, username FROM users WHERE id = ".sqlesc($row["userid"])."") or sqlerr(__FILE__, __LINE__);
$arr_yes = mysql_fetch_array($res_yes);
$msg = "Hey there!!! \n a thread you subscribed to: " .htmlspecialchars($arr["subject"]) . " has had a new post!\n click [url=" . $TBDEV['baseurl'] . "/forums.php?action=viewtopic&topicid=" . $topicid . "&page=last][b]HERE[/b][/url] to read it!\n\nTo view your subscriptions, or un-subscribe, click [url=" . $TBDEV['baseurl'] . "/subscriptions.php][b]HERE[/b][/url].\n\ncheers.";
if ($arr_yes["subscription_pm"] == 'yes' && $row["userid"] != $CURUSER["id"])
mysql_query("INSERT INTO messages (sender, subject, receiver, added, msg) VALUES(".$TBDEV['bot_id'].", 'New post in subscribed thread!', $row[userid], '" . time() . "', " . sqlesc($msg) . ")") or sqlerr(__FILE__, __LINE__);
}
// ===end
//------ Check double post
$doublepost = mysql_query("SELECT p.id, p.added, p.userid, p.body, t.lastpost, t.id ".
"FROM posts AS p ".
"INNER JOIN topics AS t ON p.id = t.lastpost ".
"WHERE t.id = $topicid AND p.userid = $userid AND p.added > ".(time() - 1*86400)." ".
"ORDER BY p.added asc LIMIT 1") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($doublepost) == 0 || $CURUSER['class'] >= UC_MODERATOR)
{
$added = sqlesc(time());
$body = sqlesc($body);
$anonymous = (isset($_POST['anonymous']) && $_POST["anonymous"] != "" ? "yes" : "no");
mysql_query("INSERT INTO posts (topicid, userid, added, body, anonymous, posticon) VALUES($topicid, $userid, $added, $body, ".sqlesc($anonymous).",$posticon)") or sqlerr(__FILE__, __LINE__);
$postid = mysql_insert_id() or die("Post id n/a");
if($TBDEV['forums_seedbonus_on'] == 1){
mysql_query("UPDATE users SET seedbonus = seedbonus+2.0 WHERE id = ".sqlesc($userid)."") or sqlerr(__FILE__, __LINE__);
}
if($TBDEV['forums_autoshout_on'] == 1){
if ($anonymous == 'yes')
$message = "(Anonymous) replied to the thread [url={$TBDEV['baseurl']}/forums.php?action=viewtopic&topicid=$topicid&page=last]{$subject}[/url]";
else
$message = $CURUSER['username'] . " replied to the thread [url={$TBDEV['baseurl']}/forums.php?action=viewtopic&topicid=$topicid&page=last]{$subject}[/url]";
//////remember to edit the ids to your staffforum ids :)
if (!in_array($forumid, array("18","23","24","25"))) {
autoshout($message);
}
}
$HTMLOUT .= update_topic_last_post($topicid);
} else {
$results = mysql_fetch_assoc($doublepost);
$postid = (int)$results['lastpost'];
mysql_query("UPDATE posts SET body = " . sqlesc(trim($results['body']) . "\n\n" . $body) . ", editedat = " . time(). ", editedby = $userid, posticon=$posticon WHERE id=$postid") or sqlerr(__FILE__, __LINE__);
}
}