This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
/
newthread.php
507 lines (452 loc) · 15.6 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
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
<?php
// AcmlmBoard XD - Thread submission/preview page
// Access: users
include("lib/common.php");
$title = __("New thread");
AssertForbidden("makeThread");
if(!$loguserid) //Not logged in?
Kill(__("You must be logged in to post."));
if(isset($_POST['id']))
$_GET['id'] = $_POST['id'];
if(!isset($_GET['id']))
Kill(__("Forum ID unspecified."));
$fid = (int)$_GET['id'];
if($loguser['powerlevel'] < 0)
Kill(__("You're banned."));
$qFora = "select * from forums where id=".$fid;
$rFora = Query($qFora);
if(NumRows($rFora))
$forum = Fetch($rFora);
else
Kill(__("Unknown forum ID."));
if($forum['locked'])
Kill(__("This forum is locked."));
if($forum['minpowerthread'] > $loguser['powerlevel'])
Kill(__("You are not allowed to post threads in this forum."));
if(!isset($_POST['poll']) || isset($_GET['poll']))
$_POST['poll'] = $_GET['poll'];
$isHidden = (int)($forum['minpower'] > 0);
$onlineUsers = OnlineUsers($fid);
write(
"
<script type=\"text/javascript\" src=\"lib/jscolor/jscolor.js\"></script>
<script type=\"text/javascript\">
window.addEventListener(\"load\", hookUpControls, false);
</script>
");
if(!$noAjax)
write(
"
<script type=\"text/javascript\">
onlineFID = {0};
window.addEventListener(\"load\", startOnlineUsers, false);
</script>
<div class=\"header0 cell1 center outline smallFonts\" style=\"overflow: auto;\">
<span id=\"onlineUsers\">
{1}
</span>
</div>
", $fid, $onlineUsers);
if($_POST['poll'])
MakeCrumbs(array(__("Main")=>"./", $forum['title']=>"forum.php?id=".$fid, __("New poll")=>""), $links);
else
MakeCrumbs(array(__("Main")=>"./", $forum['title']=>"forum.php?id=".$fid, __("New thread")=>""), $links);
if(isset($_POST['title']))
$_POST['title'] = htmlentities2($_POST['title']);
if(isset($_POST['pollQuestion']))
$_POST['pollQuestion'] = htmlentities2($_POST['pollQuestion']);
//$_POST['pollQuestion'] = htmlentities2(stripslashes($_POST['pollQuestion']));
if($_POST['text'] && CheckTableBreaks($_POST['text']))
{
$_POST['action'] = "";
Alert(__("This post would break the board layout."), __("I'm sorry, Dave."));
}
if($_POST['text'] && $_POST['action'] != __("Preview"))
{
$words = explode(" ", $_POST['text']);
$wordCount = count($words);
if($wordCount < 2)
{
$_POST['action'] = "";
Alert(__("Your post is too short to have any real meaning. Try a little harder."), __("I'm sorry, Dave."));
}
}
if($_POST['text'] && $_POST['action'] == __("Post"))
{
$lastPost = time() - $loguser['lastposttime'];
if($lastPost < 30)
{
$_POST['action'] = "";
Alert(__("You're going too damn fast! Slow down a little."), __("Hold your horses."));
}
}
if($_POST['action'] == __("Post"))
{
$trimmedTitle = trim(str_replace(' ', ' ', $_POST['title']));
if($_POST['text'] && $trimmedTitle != "")
{
$post = htmlentities2(deSlashMagic($_POST['text']));
$post = str_replace("\n","##TSURUPETTANYOUJO##", $post);
TidyPost($post);
$post = str_replace("##TSURUPETTANYOUJO##","\n", $post);
$post = mysql_real_escape_string($post);
$options = 0;
if($_POST['nopl']) $options |= 1;
if($_POST['nosm']) $options |= 2;
if($_POST['nobr']) $options |= 4;
if($_POST['iconid'])
{
$_POST['iconid'] = (int)$_POST['iconid'];
if($_POST['iconid'] < 255)
$iconurl = "img/icons/icon".$_POST['iconid'].".png";
else
$iconurl = justEscape($_POST['iconurl']);
}
$mod = '0, 0';
if(CanMod($loguserid, $forum['id']))
$mod = (($_POST['lock'] == 'on') ? '1':'0').', '.(($_POST['stick'] == 'on') ? '1':'0');
// Guess who forgot to make sure not every thread was a poll? XD -- Arbe
if($_POST['poll'])
{
$doubleVote = ($_POST['multivote']) ? 1 : 0;
$qPoll = "insert into poll (question, doublevote) values ('".justEscape($_POST['pollQuestion'])."', ".$doubleVote.")";
$rPoll = Query($qPoll);
$pod = mysql_insert_id();
for($pops = 0; $pops < $_POST['pollOptions']; $pops++)
{
if($_POST['pollOption'.$pops])
{
$pollColor = filterPollColors($_POST['pollColor'.$pops]);
$newID = FetchResult("SELECT id+1 FROM poll_choices WHERE (SELECT COUNT(*) FROM poll_choices p2 WHERE p2.id=poll_choices.id+1)=0 ORDER BY id ASC LIMIT 1");
if($newID < 1) $newID = 1;
$qPollOption = "insert into poll_choices (id, poll, choice, color) values (".$newID.", ".$pod.", '".justEscape($_POST['pollOption'.$pops])."', '".$pollColor."')";
$rPollOption = Query($qPollOption);
}
}
}
else
$pod = 0;
//Yeah, that was me ^^; -- Kawa
$newID = FetchResult("SELECT id+1 FROM threads WHERE (SELECT COUNT(*) FROM threads t2 WHERE t2.id=threads.id+1)=0 ORDER BY id ASC LIMIT 1");
if($newID < 1) $newID = 1;
$qThreads = "insert into threads (id, forum, user, title, icon, lastpostdate, lastposter, closed, sticky, poll) values (".$newID.",".$fid.",".$loguserid.",'".justEscape($_POST['title'])."','".$iconurl."',".time().",".$loguserid.", ".$mod.", ".$pod.")";
$rThreads = Query($qThreads);
$tid = mysql_insert_id();
$qUsers = "update users set posts=".($loguser['posts']+1).", lastposttime=".time()." where id=".$loguserid." limit 1";
$rUsers = Query($qUsers);
$qPosts = "insert into posts (thread, user, date, ip, num, options, mood) values (".$tid.",".$loguserid.",".time().",'".$_SERVER['REMOTE_ADDR']."',".($loguser['posts']+1).", ".$options.", ".(int)$_POST['mood'].")";
$rPosts = Query($qPosts);
$pid = mysql_insert_id();
$qPostsText = "insert into posts_text (pid,text) values (".$pid.",'".$post."')";
$rPostsText = Query($qPostsText);
$qFora = "update forums set numthreads=".($forum['numthreads']+1).", numposts=".($forum['numposts']+1).", lastpostdate=".time().", lastpostuser=".$loguserid.", lastpostid=".$pid." where id=".$fid." limit 1";
$rFora = Query($qFora);
Query("update threads set lastpostid = ".$pid." where id = ".$tid);
Report("New ".($_POST['poll'] ? "poll" : "thread")." by [b]".$loguser['name']."[/]: [b]".$_POST['title']."[/] (".$forum['title'].") -> [g]#HERE#?tid=".$tid, $isHidden);
Redirect(__("Posted!"), "thread.php?id=".$tid, __("the thread"));
exit();
}
else
{
if($trimmedTitle)
Alert(__("Enter a message and try again."), __("Your post is empty."));
else if($_POST['text'])
Alert(__("Enter a thread title and try again."), __("Your thread is unnamed."));
else
Alert(__("Enter a message and a thread title and try again."), __("Your post is empty."));
}
}
if($_POST['text'])
{
//$prefill = htmlentities2(stripslashes($_POST['text']));
$prefill = htmlentities2(deSlashMagic($_POST['text']));
$prefill = str_replace("\n","##TSURUPETTANYOUJO##", $prefill);
TidyPost($prefill);
$prefill = str_replace("##TSURUPETTANYOUJO##","\n", $prefill);
}
if($_POST['title'])
$trefill = htmlentities2(deSlashMagic($_POST['title']));
//$trefill = htmlentities2(stripslashes($_POST['title']));
if($_POST['action'] == __("Preview"))
{
if($_POST['text'] && $_POST['title'])
{
if($_POST['poll'])
{
$options = array();
$noColors = 0;
$defaultColors = array(
"#000000","#0000B6","#00B600","#00B6B6","#B60000","#B600B6","#B66700","#B6B6B6",
"#676767","#6767FF","#67FF67","#67FFFF","#FF6767","#FF67FF","#FFFF67","#FFFFFF",);
for($i = 0; $i < $_POST['pollOptions']; $i++)
{
$options[] = array("choice"=>$_POST['pollOption'.$i], "color"=>$_POST['pollColor'.$i]);
}
$totalVotes = count($options);
foreach($options as $option)
{
if($option['color'] == "")
$option['color'] = $defaultColors[($pops + 9) % 16];
$votes = 1;
$cellClass = ($cellClass+1) % 2;
$label = format("{1}", $pc[$pops], $option['choice']);
$bar = "";
if($totalVotes > 0)
{
$width = 100 * ($votes / $totalVotes);
$alt = format("{0} of {1}, {2}%", $votes, $totalVotes, $width);
$bar = format("<div class=\"pollbar\" style=\"background: {0}; width: {1}%;\" title=\"{2}\"> {3}</div>", $option['color'], $width, $alt, $votes);
if($width == 0)
$bar = " ".$votes;
}
$pollLines .= format(
"
<tr class=\"cell{0}\">
<td>
{1}
</td>
<td class=\"width75\">
<div class=\"pollbarContainer\">
{2}
</div>
</td>
</tr>
", $cellClass, $label, $bar);
$pops++;
}
write(
"
<table class=\"outline margin\">
<tr class=\"header0\">
<th colspan=\"2\">
".__("Poll")."
</th>
</tr>
<tr class=\"cell0\">
<td colspan=\"2\">
{1}
</td>
</tr>
{2}
</table>
", $cellClass, $_POST['pollQuestion'], $pollLines);
}
$previewPost['text'] = $prefill;
$previewPost['num'] = $loguser['posts']+1;
$previewPost['posts'] = $loguser['posts']+1;
$previewPost['id'] = "???";
$previewPost['options'] = 0;
if($_POST['nopl']) $previewPost['options'] |= 1;
if($_POST['nosm']) $previewPost['options'] |= 2;
if($_POST['nobr']) $previewPost['options'] |= 4;
$previewPost['mood'] = (int)$_POST['mood'];
$previewPost['uid'] = $loguserid;
$copies = explode(",","title,name,displayname,picture,sex,powerlevel,avatar,postheader,signature,signsep,regdate,lastactivity,lastposttime");
foreach($copies as $toCopy)
$previewPost[$toCopy] = $loguser[$toCopy];
MakePost($previewPost, 0, $fid);
} else
{
if($_POST['title'])
Alert(__("Enter a message and try again."), __("Your post is empty."));
else if($_POST['text'])
Alert(__("Enter a thread title and try again."), __("Your thread is unnamed."));
else
Alert(__("Enter a message and a thread title and try again."), __("Your post is empty."));
}
}
if(!$_POST['text']) $_POST['text'] = $post['text'];
if($_POST['text']) $prefill = htmlval(deSlashMagic($_POST['text']));
if($_POST['title']) $trefill = htmlval(deSlashMagic($_POST['title']));
if(!isset($_POST['iconid']))
$_POST['iconid'] = 0;
if($_POST['nopl'])
$nopl = "checked=\"checked\"";
if($_POST['nosm'])
$nosm = "checked=\"checked\"";
if($_POST['nobr'])
$nobr = "checked=\"checked\"";
$iconNoneChecked = ($_POST['iconid'] == 0) ? "checked=\"checked\"" : "";
$iconCustomChecked = ($_POST['iconid'] == 255) ? "checked=\"checked\"" : "";
$i = 1;
$icons = "";
while(is_file("img/icons/icon".$i.".png"))
{
$checked = ($_POST['iconid'] == $i) ? "checked=\"checked\" " : "";
$icons .= format(
"
<label>
<input type=\"radio\" {0} name=\"iconid\" value=\"{1}\" />
<img src=\"img/icons/icon{1}.png\" alt=\"Icon {1}\" onclick=\"javascript:void()\" />
</label>
", $checked, $i);
$i++;
}
write(
"
<table style=\"width: 100%;\">
<tr>
<td style=\"vertical-align: top; border: none;\">
<form action=\"newthread.php\" method=\"post\">
<table class=\"outline margin width100\">
<tr class=\"header1\">
<th colspan=\"2\">
{0}
</th>
</tr>
<tr class=\"cell0\">
<td>
<label for=\"tit\">
".__("Title")."
</label>
</td>
<td>
<input type=\"text\" id=\"tit\" name=\"title\" style=\"width: 98%;\" maxlength=\"60\" value=\"{1}\" />
</td>
</tr>
<tr class=\"cell1\">
<td>
".__("Icon")."
</td>
<td class=\"threadIcons\">
<label>
<input type=\"radio\" {2} name=\"iconid\" value=\"0\" />
<span>".__("None")."</span>
</label>
{3}
<br />
<label>
<input type=\"radio\" {4} name=\"iconid\" value=\"255\" />
<span>".__("Custom")."</span>
</label>
<input type=\"text\" id=\"iconurl\" name=\"iconurl\" style=\"width: 50%;\" maxlength=\"100\" value=\"{5}\" />
</td>
</tr>
", ($_POST['poll'] ? __("New poll") : __("New thread")), $trefill, $iconNoneChecked, $icons, $iconCustomChecked,
htmlval(deSlashMagic($_POST['iconurl'])));
if($_POST['poll'])
{
$first = true;
$pollOptions = "";
for($pops = 0; $pops < $_POST['pollOptions']; $pops++)
{
$cellClass = ($cellClass+1) % 2;
$fixed = htmlval(deSlashMagic($_POST['pollOption'.$pops]));
$pollOptions .= format(
"
<tr class=\"cell{0}\">
<td>
<label for=\"p{1}\">".__("Option {2}")."</label>
</td>
<td>
<input type=\"text\" id=\"p{1}\" name=\"pollOption{1}\" value=\"{3}\" style=\"width: 50%;\" maxlength=\"40\" >
<label>
".__("Color", 1)."
<input type=\"text\" name=\"pollColor{1}\" value=\"{4}\" size=\"10\" maxlength=\"7\" class=\"color {hash:true,required:false,pickerFaceColor:'black',pickerFace:3,pickerBorder:0,pickerInsetColor:'black',pickerPosition:'left',pickerMode:'HVS'}\" />
</label>
{5}
</td>
</tr>
", $cellClass, $pops, $pops + 1, $fixed,
filterPollColors($_POST['pollColor'.$pops]), ($first ? " (#rrggbb)" : ""));
$first = false;
}
write(
"
<tr class=\"cell0\">
<td>
<label for=\"pq\">
".__("Poll question")."
</label>
</td>
<td>
<input type=\"text\" id=\"pq\" name=\"pollQuestion\" value=\"{0}\" style=\"width: 98%;\" maxlength=\"100\" />
</td>
</tr>
<tr class=\"cell1\">
<td>
<label for=\"pn\">
".__("Number of options")."
</label>
</td>
<td>
<input type=\"text\" id=\"pn\" name=\"pollOptions\" value=\"{1}\" size=\"2\" maxlength=\"2\" />
</td>
</tr>
{2}
", htmlval(deSlashMagic($_POST['pollQuestion'])), $_POST['pollOptions'], $pollOptions);
}
if($_POST['mood'])
$moodSelects[(int)$_POST['mood']] = "selected=\"selected\" ";
$moodOptions = "<option ".$moodSelects[0]."value=\"0\">".__("[Default avatar]")."</option>\n";
$rMoods = Query("select mid, name from moodavatars where uid=".$loguserid." order by mid asc");
while($mood = Fetch($rMoods))
$moodOptions .= format(
"
<option {0} value=\"{1}\">{2}</option>
", $moodSelects[$mood['mid']], $mood['mid'], htmlval($mood['name']));
if(CanMod($loguserid, $forum['id']))
{
$mod = "\n\n<!-- Mod options -->\n";
$mod .= "<label><input type=\"checkbox\" name=\"lock\"> ".__("Close thread", 1)."</label>\n";
$mod .= "<label><input type=\"checkbox\" name=\"stick\"> ".__("Sticky", 1)."</label>\n";
$mod .= "<!-- More could follow -->\n\n";
}
if(!$_POST['poll'] || $_POST['pollOptions'])
$postButton = "<input type=\"submit\" name=\"action\" value=\"".__("Post")."\" /> ";
if($_POST['poll'])
$multivote = "<label><input type=\"checkbox\" ".($_POST['multivote'] ? "checked=\"checked\"" : "")." name=\"multivote\" /> ".__("Multivote", 1)."</label>";
write(
"
<tr class=\"cell0\">
<td>
<label for=\"post\">
Post
</label>
</td>
<td>
<textarea id=\"text\" name=\"text\" rows=\"16\" style=\"width: 98%;\">{0}</textarea>
</td>
</tr>
<tr class=\"cell2\">
<td></td>
<td>
{1}
<input type=\"submit\" name=\"action\" value=\"".__("Preview")."\" />
<select size=\"1\" name=\"mood\">
{2}
</select>
<label>
<input type=\"checkbox\" name=\"nopl\" {3} /> ".__("Disable post layout", 1)."
</label>
<label>
<input type=\"checkbox\" name=\"nosm\" {4} /> ".__("Disable smilies", 1)."
</label>
<label>
<input type=\"checkbox\" name=\"nobr\" {8} /> ".__("Disable auto-<br>", 1)."
</label>
<input type=\"hidden\" name=\"id\" value=\"{5}\" />
<input type=\"hidden\" name=\"poll\" value=\"{6}\" />
{7}
{9}
</td>
</tr>
</table>
</form>
</td>
<td style=\"width: 200px; vertical-align: top; border: none;\">
", $prefill, $postButton, $moodOptions, $nopl, $nosm, $fid, stripslashes($_POST['poll']), $multivote, $nobr, $mod);
DoSmileyBar();
DoPostHelp();
write("
</td>
</tr>
</table>
");
if($_POST['poll'])
MakeCrumbs(array(__("Main")=>"./", $forum['title']=>"forum.php?id=".$fid, __("New poll")=>""), $links);
else
MakeCrumbs(array(__("Main")=>"./", $forum['title']=>"forum.php?id=".$fid, __("New thread")=>""), $links);
?>