-
Notifications
You must be signed in to change notification settings - Fork 0
/
newthread.php
437 lines (370 loc) · 15.9 KB
/
newthread.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
<?php
error_reporting(7);
$templatesused = "newpost_postpreview,error_nosubject,redirect_postthanks,email_moderator,emailsubject_moderator,newthread_postpoll,newpost_attachment,newpost_disablesmiliesoption,forumrules,newthread,posticons,posticonbit";
$templatesused.=",vbcode_smilies,vbcode_smiliebit,vbcode_smilies_getmore,vbcode_buttons,vbcode_sizebits,vbcode_fontbits,vbcode_colorbits";
require("./global.php");
// get decent textarea size for user's browser
$textareacols = gettextareawidth();
$action = trim($action);
if (!isset($action) or $action=="") {
$action="newthread";
}
unset ($postpreview);
unset ($parseurlchecked);
unset ($emailchecked);
unset ($disablesmilieschecked);
unset ($signaturechecked);
unset ($previewchecked);
$forumid=verifyid("forum",$forumid);
$foruminfo=getforuminfo($forumid);
if ($foruminfo['allowposting']==0) {
eval("standarderror(\"".gettemplate("error_forumclosed")."\");");
}
if ($foruminfo[allowposting]==0) {
eval("standarderror(\"".gettemplate("error_forumnoreply")."\");");
exit;
}
$permissions=getpermissions($forumid);
if (!$permissions[canview] or !$permissions[canpostnew]) {
show_nopermission();
}
updateuserforum($foruminfo['forumid']);
// ############################### start post thread ###############################
if ($HTTP_POST_VARS['action']=="postthread") {
// decode check boxes
$parseurl=iif(trim($parseurl)=="yes",1,0);
$email=iif(trim($email)=="yes",1,0);
$allowsmilie=iif(trim($disablesmilies)=="yes",0,1);
$signature=iif(trim($signature)=="yes",1,0);
$preview=iif(trim($preview)!="",1,0);
$postpoll=iif(trim($postpoll)=="yes",1,0);
$visible=iif($foruminfo[moderatenew],0,1);
// auto bypass queueing for admins/mods
if (ismoderator($foruminfo[forumid])) {
$visible=1;
}
$message=trim($message);
if ($parseurl) {
$message=parseurl($message);
}
// remove sessionhash from urls:
$message = stripsession($message);
if (strlen($message)>$postmaxchars and $postmaxchars!=0) {
eval("standarderror(\"".gettemplate("error_toolong")."\");");
}
if ($preview) {
// preview? yes:
$previewpost=1;
$previewmessage=bbcodeparse($message,$foruminfo[forumid],$allowsmilie);
$toomanyimages = '';
if ($maximages!=0) {
if (countchar($previewmessage,"<img")>$maximages) {
//too many images
eval("\$toomanyimages = \"".gettemplate("error_previewtoomanyimages")."\";");
}
}
if ($signature) {
$post['signature'] = bbcodeparse($bbuserinfo['signature'],0,$allowsmilie);
eval("\$post[signature] = \"".gettemplate("postbit_signature")."\";");
$previewmessage.=$post['signature'];
}
eval("\$postpreview=\"".gettemplate("newpost_postpreview")."\";");
$parseurlchecked=iif($parseurl,"checked","");
$emailchecked=iif($email,"checked","");
$disablesmilieschecked=iif(!$allowsmilie,"checked","");
$signaturechecked=iif($signature,"checked","");
$previewchecked=0;
$action="newthread";
} else {
// check for subject and message
if (trim($subject)=="" or trim($message)=="") {
eval("standarderror(\"".gettemplate("error_nosubject")."\");");
exit;
}
$username = $HTTP_POST_VARS['username'];
$password = $HTTP_POST_VARS['password'];
if ($bbuserinfo['userid'] == 0) {
$password = $HTTP_POST_VARS['password'];
$username = trim($HTTP_POST_VARS['username']);
$username = eregi_replace("( ){2,}", " ", $username);
if (empty($username)) {
eval("standarderror(\"".gettemplate("error_nousername")."\");");
} else if (strlen($username) < $minuserlength) {
eval("standarderror(\"".gettemplate("error_usernametooshort")."\");");
} else if (strlen($username) > $maxuserlength) {
eval("standarderror(\"".gettemplate("error_usernametoolong")."\");");
} else if ($username != censortext($username)) {
eval("standarderror(\"".gettemplate("error_usernametaken")."\");");
} else if ($illegalusernames != '') {
$usernames = preg_split('/( )+/', trim(strtolower($illegalusernames)), -1, PREG_SPLIT_NO_EMPTY);
$tempusername = strtolower($username);
while ( list( , $val ) = each( $usernames ) ) {
if (strstr($tempusername, $val) != '') {
eval("standarderror(\"".gettemplate("error_usernametaken")."\");");
}
}
}
if ($userinfo=$DB_site->query_first("
SELECT user.*,userfield.*
FROM user,userfield
WHERE (username='".addslashes(htmlspecialchars($username))."' OR
username='".addslashes(eregi_replace("[^A-Za-z0-9]","",$username))."') AND
user.userid=userfield.userid")) {
if (!$password) {
eval("standarderror(\"".gettemplate("error_usernametaken")."\");");
} elseif (md5($password)!=$userinfo['password']) {
eval("standarderror(\"".gettemplate("error_wrongpassword")."\");");
} else {
$bbuserinfo = $userinfo;
$postusername = $bbuserinfo['username'];
if ($user['cookieuser']==1) {
vbsetcookie("bbuserid",$user['userid'], true, true);
vbsetcookie("bbpassword",$user['password'], true, true);
}
$DB_site->query("UPDATE session SET userid='$bbuserinfo[userid]' WHERE sessionhash='".addslashes($session['dbsessionhash'])."'");
}
} else {
$postusername = htmlspecialchars($username);
}
} else {
$postusername = $bbuserinfo['username'];
}
// not previewing:
if ($enablefloodcheck) {
if ($bbuserinfo[userid]!=0 and time()-$bbuserinfo[lastpost]<=$floodchecktime and !ismoderator($foruminfo[forumid])) {
// check whether admin
eval("standarderror(\"".gettemplate("error_floodcheck")."\");");
exit;
}
}
if (!isset($iconid) or $iconid=="") {
$iconid=0;
}
$iconid = intval($iconid);
$permissions=getpermissions($forumid);
if (!$permissions[canview] or !$permissions[canpostnew]) {
show_nopermission();
}
if ($logip==1 or $logip==2) {
if ($temp = $HTTP_SERVER_VARS['REMOTE_ADDR']) {
$ipaddress = $temp;
} else if ($temp = $REMOTE_ADDR) {
$ipaddress = $temp;
} else {
$ipaddress = $HTTP_HOST;
}
} else {
$ipaddress="";
}
// check max images
if ($maximages!=0) {
$parsedmessage=bbcodeparse($message,$foruminfo[forumid],$allowsmilie);
if (countchar($parsedmessage,"<img")>$maximages) {
eval("standarderror(\"".gettemplate("error_toomanyimages")."\");");
exit;
}
}
$subject=censortext($subject);
$message=censortext($message);
// remove all caps subjects
if ($stopshouting and $subject==strtoupper($subject)) {
$subject=ucwords(strtolower($subject));
}
// sort attachement
if (is_array($HTTP_POST_FILES)) {
$attachment = $HTTP_POST_FILES['attachment']['tmp_name'];
$attachment_name = $HTTP_POST_FILES['attachment']['name'];
$attachment_size = $HTTP_POST_FILES['attachment']['size'];
}
if ($permissions[canpostattachment] and trim($attachment)!="none" and trim($attachment)!="" and trim($attachment_name)!="") {
$attachmentid=acceptupload($foruminfo[moderateattach]);
if (!$foruminfo[moderateattach]) {
$attachcount = 1;
} else {
$attachcount = 0;
}
} else {
$attachmentid=0;
$attachcount=0;
}
// see if there has been a post identical to this in the last 5 mins.
// If so, update that one, as user has probably done a double post
$datecut=time()-300;
if ($prevpost=$DB_site->query_first("SELECT threadid,visible FROM thread WHERE forumid='$forumid' AND postuserid='$bbuserinfo[userid]' AND title='".addslashes(htmlspecialchars($subject))."' AND dateline>$datecut AND replycount=0")) {
$threadid=$prevpost[threadid];
// subscribe to thread
if ($email) {
if (!$checkid=$DB_site->query_first("SELECT subscribethreadid FROM subscribethread WHERE userid=$bbuserinfo[userid] AND threadid=$threadid")) {
$DB_site->query("INSERT INTO subscribethread (subscribethreadid,userid,threadid) VALUES (NULL,$bbuserinfo[userid],$threadid)");
}
}
$DB_site->query("UPDATE thread SET title='".addslashes(htmlspecialchars($subject))."',iconid='$iconid' WHERE threadid='$threadid'");
$posts=$DB_site->query_first("SELECT MIN(post.postid) AS minpost,attachmentid FROM post,thread WHERE thread.threadid=post.threadid AND thread.threadid='$threadid' GROUP BY thread.threadid");
if ($posts[attachmentid]!=0) {
$DB_site->query("DELETE FROM attachment WHERE attachmentid = '$posts[attachmentid]'");
if ($attachmentid==0) {
$DB_site->query("UPDATE thread SET attach = attach - 1 WHERE threadid = '$threadid'");
}
}
$DB_site->query("UPDATE post SET pagetext='".addslashes($message)."',allowsmilie='$allowsmilie',showsignature='$signature',iconid='$iconid',attachmentid='$attachmentid' WHERE postid='$posts[minpost]'");
// redirect
if ($prevpost[visible]) {
$goto="showthread.php?s=$session[sessionhash]&threadid=$threadid";
} else {
$goto="forumdisplay.php?s=$session[sessionhash]&forumid=$forumid";
}
eval("standardredirect(\"".gettemplate("redirect_postthanks")."\",\"$goto\");");
} else {
//create new thread
if ($postpoll) {
$visible = 0;
}
$DB_site->query("INSERT INTO thread (threadid,title,lastpost,forumid,open,replycount,postusername,postuserid,lastposter,dateline,iconid,visible,attach) VALUES (NULL,'".addslashes(htmlspecialchars($subject))."','".time()."','$forumid','1','0','".addslashes($postusername)."','$bbuserinfo[userid]','".addslashes($postusername)."','".time()."','$iconid','$visible','$attachcount')");
$threadid=$DB_site->insert_id();
// subscribe to thread
if ($email and $bbuserinfo['userid']!=0) {
if (!$checkid=$DB_site->query_first("SELECT subscribethreadid FROM subscribethread WHERE userid=$bbuserinfo[userid] AND threadid=$threadid")) {
$DB_site->query("INSERT INTO subscribethread (subscribethreadid,userid,threadid) VALUES (NULL,$bbuserinfo[userid],$threadid)");
}
}
/*if ($bbuserinfo[userid]==0) {
$postusername=$bbuserinfo[username];
} else {
$postusername="";
}*/
// create first post
$DB_site->query("INSERT INTO post (postid,threadid,title,username,userid,dateline,attachmentid,pagetext,allowsmilie,showsignature,ipaddress,iconid,visible) VALUES (NULL,'$threadid','".addslashes(htmlspecialchars($subject))."','".addslashes($postusername)."','$bbuserinfo[userid]','".time()."','$attachmentid','".addslashes($message)."','$allowsmilie','$signature','$ipaddress','$iconid','1')");
$postid=$DB_site->insert_id();
indexpost($postid,1);
// update forum stuff
if ($visible==1) {
$DB_site->query("UPDATE forum SET replycount=replycount+1,threadcount=threadcount+1,lastpost='".time()."',lastposter='".addslashes($postusername)."' WHERE forumid IN ($foruminfo[parentlist])");
}
// update user stuff
$dotitle="";
if ($bbuserinfo[userid]!=0)
{
if ($bbuserinfo[customtitle]==0 && $foruminfo[countposts])
{
$usergroup=$DB_site->query_first("SELECT usertitle FROM usergroup WHERE usergroupid='$bbuserinfo[usergroupid]'");
if ($usergroup[usertitle]=="") {
$gettitle=$DB_site->query_first("SELECT title FROM usertitle WHERE minposts<=$bbuserinfo[posts]".iif ($foruminfo['countposts'],"+1","")." ORDER BY minposts DESC LIMIT 1");
$usertitle=$gettitle[title];
} else {
$usertitle=$usergroup[usertitle];
}
$dotitle="usertitle='".addslashes($usertitle)."',";
}
$DB_site->query("UPDATE user SET
".iif ($foruminfo[countposts],"posts=posts+1,","")."
$dotitle"."lastpost='".time()."' WHERE userid='$bbuserinfo[userid]'");
}
// send email to moderators
if ($enableemail) {
$moderators=$DB_site->query_first("SELECT CONCAT(newthreademail,' ',newpostemail) AS newthreademail FROM forum WHERE forumid='$forumid'");
$modtable=$DB_site->query("SELECT DISTINCT user.email FROM moderator,user WHERE moderator.userid=user.userid AND forumid IN ($foruminfo[parentlist]) AND (newthreademail=1 OR newpostemail=1)");
while($thismod=$DB_site->fetch_array($modtable)) {
$moderators['newthreademail'].=" $thismod[email]";
}
if ($moderators['newthreademail']!="") {
$forumtitle = $foruminfo['title'];
$threadinfo['title'] = $subject;
$bbuserinfo['username'] = unhtmlspecialchars($bbuserinfo['username']);
$mods = explode(" ",trim($moderators['newthreademail']));
while (list($key,$val)=each($mods)) {
if (trim($val)!="") {
eval("\$emailmsg = \"".gettemplate("email_moderator",1,0)."\";");
eval("\$emailsubject = \"".gettemplate("emailsubject_moderator",1,0)."\";");
vbmail($val, $emailsubject, $emailmsg);
}
}
$bbuserinfo['username'] = htmlspecialchars($bbuserinfo['username']);
}
}
// redirect
if ($postpoll) {
$goto="poll.php?s=$session[sessionhash]&threadid=$threadid&polloptions=".intval($polloptions);
} elseif ($visible) {
$goto="showthread.php?s=$session[sessionhash]&threadid=$threadid";
} else {
$goto="forumdisplay.php?s=$session[sessionhash]&forumid=$forumid";
}
eval("standardredirect(\"".gettemplate("redirect_postthanks")."\",\"$goto\");");
}
}
}
// ############################### start new thread ###############################
if ($action=="newthread") {
// $foruminfo=getforuminfo($forumid);
$message = htmlspecialchars($message); // Without this, a </textarea> in the message breaks the form on preview
$subject = htmlspecialchars($subject);
$bbcodeon=iif($foruminfo[allowbbcode],$ontext,$offtext);
$imgcodeon=iif($foruminfo[allowimages],$ontext,$offtext);
$htmlcodeon=iif($foruminfo[allowhtml],$ontext,$offtext);
$smilieson=iif($foruminfo[allowsmilies],$ontext,$offtext);
// draw nav bar
$navbar=makenavbar($forumid,"forum",1);
if ($foruminfo[allowicons]) {
$posticons=chooseicons($iconid);
} else {
$posticons="";
}
if (!isset($parseurl)) {
$parseurlchecked="CHECKED";
}
if ($postpoll) {
$postpollchecked="CHECKED";
} else {
$postpollchecked = '';
}
if (!isset($polloptions)) {
$polloptions=4;
} else {
$polloptions = intval($polloptions);
}
// check to see if signature required
if ($bbuserinfo[userid]!=0 and !$previewpost) {
if ($bbuserinfo[signature]!="") {
$signaturechecked="CHECKED";
} else {
$signaturechecked='';
}
if ($bbuserinfo[emailnotification]) {
$emailchecked="checked";
} else {
$emailchecked='';
}
}
if ($permissions['canpostpoll']) {
eval("\$postpolloption = \"".gettemplate("newthread_postpoll")."\";");
} else {
$postpolloption = '';
}
$maxattachsize_temp = getmaxattachsize();
if (phpversion() < '4.0.3') {
$enctype = 'enctype="multipart/form-data"';
} else if (ini_get('file_uploads')) {
$enctype = 'enctype="multipart/form-data"';
} else {
$enctype = '';
}
if ($permissions[canpostattachment] and (!$safeupload or function_exists("is_uploaded_file"))) {
eval("\$attachmentoption = \"".gettemplate("newpost_attachment")."\";");
} else {
$attachmentoption="";
}
$vbcode_smilies = '';
$vbcode_buttons = '';
if ($foruminfo[allowsmilies]) {
if ($bbuserinfo[showvbcode] && $allowvbcodebuttons)
$vbcode_smilies = getclickysmilies();
eval("\$disablesmiliesoption = \"".gettemplate("newpost_disablesmiliesoption")."\";");
} else {
$disablesmiliesoption="";
}
if ($bbuserinfo[showvbcode] && $allowvbcodebuttons)
$vbcode_buttons = getcodebuttons();
getforumrules($foruminfo,$permissions);
eval("dooutput(\"".gettemplate("newthread")."\");");
}
?>