-
Notifications
You must be signed in to change notification settings - Fork 0
/
editthread.php
372 lines (330 loc) · 11.9 KB
/
editthread.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
<?php
// AcmlmBoard XD - Thread editing page
// Access: moderators
include("lib/common.php");
$title = __("Edit thread");
AssertForbidden("editThread");
$key = hash('sha256', "{$loguserid},{$loguser['pss']},{$salt}");
if (isset($_REQUEST['action']) && $key != $_REQUEST['key'])
Kill(__("No."));
if(!$loguserid) //Not logged in?
Kill(__("You must be logged in to edit threads."));
if($loguser['powerlevel'] < 0)
Kill(__("You're banned."));
if(isset($_POST['id']))
$_GET['id'] = $_POST['id'];
if(!isset($_GET['id']))
Kill(__("Thread ID unspecified."));
$tid = (int)$_GET['id'];
$qThread = "select * from threads where id=".$tid;
$rThread = Query($qThread);
if(NumRows($rThread))
$thread = Fetch($rThread);
else
Kill(__("Unknown thread ID."));
$canMod = CanMod($loguserid, $thread['forum']);
if(!$canMod && $thread['user'] != $loguserid)
Kill(__("You are not allowed to edit threads."));
$qFora = "select minpower from forums where id=".$thread['forum'];
$rFora = Query($qFora);
if(NumRows($rFora))
$forum = Fetch($rFora);
else
Kill(__("Unknown forum ID."));
$isHidden = (int)($forum['minpower'] > 0);
if($canMod)
{
if($_GET['action']=="close")
{
$qThread = "update threads set closed=1 where id=".$tid;
$rThread = Query($qThread);
Report("[b]".$loguser['name']."[/] closed thread [b]".$thread['title']."[/] -> [g]#HERE#?tid=".$tid, $isHidden);
Redirect(__("Thread closed."), "forum.php?id=".$thread['forum'], __("the forum"));
}
elseif($_GET['action']=="open")
{
$qThread = "update threads set closed=0 where id=".$tid;
$rThread = Query($qThread);
Report("[b]".$loguser['name']."[/] opened thread [b]".$thread['title']."[/] -> [g]#HERE#?tid=".$tid, $isHidden);
Redirect(__("Thread opened."), "forum.php?id=".$thread['forum'], __("the forum"));
}
elseif($_GET['action']=="stick")
{
$qThread = "update threads set sticky=1 where id=".$tid;
$rThread = Query($qThread);
Report("[b]".$loguser['name']."[/] stickied thread [b]".$thread['title']."[/] -> [g]#HERE#?tid=".$tid, $isHidden);
Redirect(__("Thread stickied."), "forum.php?id=".$thread['forum'], __("the forum"));
}
elseif($_GET['action']=="unstick")
{
$qThread = "update threads set sticky=0 where id=".$tid;
$rThread = Query($qThread);
Report("[b]".$loguser['name']."[/] unstuck thread [b]".$thread['title']."[/] -> [g]#HERE#?tid=".$tid, $isHidden);
Redirect(__("Thread unsticked."), "forum.php?id=".$thread['forum'], __("the forum"));
}
elseif($_POST['action']==__("Move"))
{
$moveto = (int)$_POST['moveTo'];
//Tweak forum counters
$qForum = "update forums set numthreads=numthreads-1, numposts=numposts-".($thread['replies']+1)." where id=".$thread['forum'];
$rForum = Query($qForum);
$qForum = "update forums set numthreads=numthreads+1, numposts=numposts+".($thread['replies']+1)." where id=".$moveto;
$rForum = Query($qForum);
$qThread = "update threads set forum=".(int)$_POST['moveTo']." where id=".$tid;
$rThread = Query($qThread);
// Tweak forum counters #2
Query(" UPDATE forums LEFT JOIN threads
ON forums.id=threads.forum AND threads.lastpostdate=(SELECT MAX(nt.lastpostdate) FROM threads nt WHERE nt.forum=forums.id)
SET forums.lastpostdate=IFNULL(threads.lastpostdate,0), forums.lastpostuser=IFNULL(threads.lastposter,0), forums.lastpostid=IFNULL(threads.lastpostid,0)
WHERE forums.id=".$thread['forum']." OR forums.id=".$moveto);
Report("[b]".$loguser['name']."[/] moved thread [b]".$thread['title']."[/] -> [g]#HERE#?tid=".$tid, $isHidden);
Redirect(__("Thread moved."), "forum.php?id=".$moveto, __("the new forum"));
}
elseif($_GET['action']=="delete")
{
$qPosts = "select id,user from posts where thread=".$tid;
$rPosts = Query($qPosts);
//Round up posts in this thread
while($post = Fetch($rPosts))
{
//Delete this post
$qPost = "delete from posts where id=".$post['id'];
$qPostText = "delete from posts_text where pid=".$post['id'];
$rPost = Query($qPost);
$rPostText = Query($qPostText);
//Find and decrease user's postcount
$qUser = "select id from users where id=".$post['user'];
$rUser = Query($qUser);
$qUser = "update users set posts = posts - 1 where id=".$post['user'];
$rUser = Query($qUser);
//Decrease forum postcount
$qForum = "update forums set numposts = numposts - 1 where id=".$thread['forum'];
$rForum = Query($qForum);
}
//Delete the thread
$qThread = "delete from threads where id=".$tid;
$rThread = Query($qThread);
//Decrease forum threadcount
$qForum = "update forums set numthreads = numthreads - 1 where id=".$thread['forum'];
$rForum = Query($qForum);
// Update the forum's lastpost stuff
Query(" UPDATE forums LEFT JOIN threads
ON forums.id=threads.forum AND threads.lastpostdate=(SELECT MAX(nt.lastpostdate) FROM threads nt WHERE nt.forum=forums.id)
SET forums.lastpostdate=IFNULL(threads.lastpostdate,0), forums.lastpostuser=IFNULL(threads.lastposter,0), forums.lastpostid=IFNULL(threads.lastpostid,0)
WHERE forums.id=".$thread['forum']);
if($thread['poll'])
{
//Delete poll things
$qPoll = "delete from poll where id=".$thread['poll'];
$rPoll = Query($qPoll);
$qPollVotes = "delete from pollvotes where poll=".$thread['poll'];
$rPollVotes = Query($qPollVotes);
$qPollChoices = "delete from poll_choices where poll=".$thread['poll'];
$rPollChoices = Query($qPollChoices);
}
Report("[b]".$loguser['name']."[/] deleted thread [b]".$thread['title']."[/]", $isHidden);
Redirect(__("Thread deleted."), "forum.php?id=".$thread['forum'], __("the forum"));
}
elseif($_GET['action'] == "trash")
{
$qForum = "select id from forums where description like '%[trash]%' limit 1";
$trashid = FetchResult($qForum);
if($trashid > 0)
{
$qThread = "update threads set forum=".$trashid.", closed=1 where id=".$tid." limit 1";
$rThread = Query($qThread);
//Tweak forum counters
$qForum = "update forums set numthreads=numthreads-1, numposts=numposts-".($thread['replies']+1)." where id=".$thread['forum'];
$rForum = Query($qForum);
$qForum = "update forums set numthreads=numthreads+1, numposts=numposts+".($thread['replies']+1)." where id=".$trashid;
$rForum = Query($qForum);
// Tweak forum counters #2
Query(" UPDATE forums LEFT JOIN threads
ON forums.id=threads.forum AND threads.lastpostdate=(SELECT MAX(nt.lastpostdate) FROM threads nt WHERE nt.forum=forums.id)
SET forums.lastpostdate=IFNULL(threads.lastpostdate,0), forums.lastpostuser=IFNULL(threads.lastposter,0), forums.lastpostid=IFNULL(threads.lastpostid,0)
WHERE forums.id=".$thread['forum']." OR forums.id=".$trashid);
Report("[b]".$loguser['name']."[/] thrashed thread [b]".$thread['title']."[/] -> [g]#HERE#?tid=".$tid, $isHidden);
Redirect(__("Thread trashed."), "forum.php?id=".$thread['forum'], __("the forum"));
}
else
Kill(__("Could not identify trash forum."));
}
if($_POST['action'] == __("Edit"))
{
$isClosed = (isset($_POST['isClosed']) ? 1 : 0);
$isSticky = (isset($_POST['isSticky']) ? 1 : 0);
$trimmedTitle = trim(str_replace(' ', ' ', $thread['title']));
if($trimmedTitle != "")
{
if($_POST['iconid'])
{
$_POST['iconid'] = (int)$_POST['iconid'];
if($_POST['iconid'] < 255)
$iconurl = "img/icons/icon".$_POST['iconid'].".png";
else
$iconurl = justEscape($_POST['iconurl']);
}
$qThreads = "update threads set title='".justEscape($_POST['title'])."', icon='".$iconurl."', closed=".$isClosed.", sticky=".$isSticky." where id=".$tid." limit 1";
$rThreads = Query($qThreads);
Report("[b]".$loguser['name']."[/] edited thread [b]".$thread['title']."[/] -> [g]#HERE#?tid=".$tid, $isHidden);
Redirect(__("Edited!"), "thread.php?id=".$tid, __("the thread"));
exit();
}
else
Alert(__("Your thread title is empty. Enter a message and try again."));
}
}
else
{
if($_POST['action'] == __("Edit"))
{
if($_POST['title'])
{
$qThreads = "update threads set title='".justEscape($_POST['title'])."' where id=".$tid." limit 1";
$rThreads = Query($qThreads);
Report("[b]".$loguser['name']."[/] renamed thread [b]".$thread['title']."[/] -> [g]#HERE#?tid=".$tid, $isHidden);
Redirect(__("Edited!"), "thread.php?id=".$tid, __("the thread"));
exit();
}
else
Alert(__("Your thread title is empty. Enter a message and try again."));
}
}
if(!$_POST['title']) $_POST['title'] = $thread['title'];
$match = array();
if (preg_match("@^img/icons/icon(\d+)\..{3,}\$@si", $thread['icon'], $match))
$_POST['iconid'] = $match[1];
elseif($thread['icon'] == "") //Has no icon
$_POST['iconid'] = 0;
else //Has custom icon
{
$_POST['iconid'] = 255;
$_POST['iconurl'] = $thread['icon'];
}
if(!isset($_POST['iconid'])) $_POST['iconid'] = 0;
$qFora = "select title, id from forums order by catid, id";
$rFora = Query($qFora);
while($forum = Fetch($rFora))
{
$moveToTargets .= "<option value=\"".$forum['id']."\">".$forum['title']."</option>";
}
if($canMod)
{
$icons = "";
$i = 1;
while(is_file("img/icons/icon".$i.".png"))
{
$check = "";
if($_POST['iconid'] == $i) $check = "checked=\"checked\" ";
$icons .= format(
"
<label>
<input type=\"radio\" {0} name=\"iconid\" value=\"{1}\" />
<img src=\"img/icons/icon{1}.png\" alt=\"Icon {1}\" />
</label>
", $check, $i);
$i++;
}
$check[0] = "";
$check[1] = "";
if($_POST['iconid'] == 0) $check[0] = "checked=\"checked\" ";
if($_POST['iconid'] == 255)
{
$check[1] = "checked=\"checked\" ";
$iconurl = htmlval(deSlashMagic($_POST['iconurl']));
}
write(
"
<form action=\"editthread.php\" method=\"post\">
<table class=\"outline margin\" style=\"width: 100%;\">
<tr class=\"header1\">
<th colspan=\"2\">
".__("Edit Thread")."
</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=\"{0}\" />
</td>
</tr>
<tr class=\"cell1\">
<td>
".__("Icon")."
</td>
<td class=\"threadIcons\">
<label>
<input type=\"radio\" {2} id=\"noicon\" name=\"iconid\" value=\"0\">
".__("None")."
</label>
{1}
<br/>
<label>
<input type=\"radio\" {3} name=\"iconid\" value=\"255\" />
<span>".__("Custom")."</span>
</label>
<input type=\"text\" name=\"iconurl\" style=\"width: 50%;\" maxlength=\"100\" value=\"{4}\" />
</td>
</tr>
<tr class=\"cell2\">
<td>
".__("Extras")."
</td>
<td>
<label>
<input type=\"checkbox\" name=\"isClosed\" {5} />
".__("Closed")."
</label>
<label>
<input type=\"checkbox\" name=\"isSticky\" {6} />
".__("Sticky")."
</label>
</td>
</tr>
<tr class=\"cell2\">
<td></td>
<td>
<input type=\"submit\" name=\"action\" value=\"".__("Edit")."\"></input>
<button onclick=\"window.navigate('editthread.php?id={7}&action=delete');\">".__("Delete")."</button>
<select name=\"moveTo\" size=\"1\">{8}</select>
<input type=\"submit\" name=\"action\" value=\"".__("Move")."\" />
<input type=\"hidden\" name=\"id\" value=\"{7}\" />
<input type=\"hidden\" name=\"key\" value=\"{9}\" />
</td>
</tr>
</table>
</form>
", htmlval(deSlashMagic($_POST['title'])), $icons, $check[0], $check[1], $iconurl,
($thread['closed'] ? " checked=\"checked\"" : ""),
($thread['sticky'] ? " checked=\"checked\"" : ""),
$tid, $moveToTargets, $key);
}
else
{
write(
"
<form action=\"editthread.php\" method=\"post\">
<table class=\"outline margin width50\">
<tr class=\"cell0\">
<td>
<label for=\"tit\">".__("Title")."</label>
</td>
<td>
<input type=\"text\" id=\"tit\" name=\"title\" style=\"width: 98%;\" maxlength=\"60\" value=\"{0}\" />
</td>
</tr>
<tr class=\"cell2\">
<td></td>
<td>
<input type=\"submit\" name=\"action\" value=\"".__("Edit")."\" />
<input type=\"hidden\" name=\"id\" value=\"{1}\" />
<input type=\"hidden\" name=\"key\" value=\"{2}\" />
</td>
</tr>
</table>
</form>
", htmlval(deSlashMagic($_POST['title'])), $tid, $key);
}
?>