forked from Kak2X/jul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendprivate.php
462 lines (397 loc) · 15 KB
/
sendprivate.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
<?php
require 'lib/function.php';
$meta['noindex'] = true;
if (!$loguser['id']) {
errorpage("You need to be logged in to send private messages.", 'login.php', 'log in (then try again)');
}
if($loguser['powerlevel'] <= -2) {
errorpage("You are permabanned and cannot send private messages.",'private.php','your private message box',0);
}
$_GET['id'] = filter_int($_GET['id']);
if ($_GET['id']) {
// Replying to a thread
$_GET['postid'] = filter_int($_GET['postid']);
load_pm_thread($_GET['id']);
if ($forum_error) {
$forum_error = "<table class='table'>{$forum_error}</table>";
}
// Thread permissions for our sanity
$mythread = ($loguser['id'] == $thread['user'] && $config['allow-pmthread-edit']);
$canreply = ($isadmin || $access); // $mythread ||
$closed = (!$isadmin && !$mythread && $thread['closed']);
if ($closed) {
errorpage("Sorry, but this thread is closed, and no more replies can be posted in it.","thread.php?id={$_GET['id']}",$thread['title'],0);
} else if (!$canreply) {
errorpage("You are not allowed to post in this thread.","thread.php?id={$_GET['id']}",$thread['title'],0);
}
$ppp = get_ppp();
$_POST['message'] = filter_string($_POST['message']);
$_POST['moodid'] = filter_int($_POST['moodid']);
$_POST['nosmilies'] = filter_int($_POST['nosmilies']);
$_POST['nolayout'] = filter_int($_POST['nolayout']);
$_POST['nohtml'] = filter_int($_POST['nohtml']);
$_POST['close'] = filter_int($_POST['close']);
// Attachment preview stuff
$input_tid = "";
$attach_key = 'pm'.$_GET['id'];
$loguser['id'] = $loguser['id'];
if (isset($_POST['submit']) || isset($_POST['preview'])) {
$error = NULL;
if (!$_POST['message'])
$error = "You didn't enter anything in the post.";
else if ($loguser['lastpmtime'] > (ctime()-4))
$error = "You are posting too fast.";
if ($error) { // This redirect is so fucking annoying
errorpage("Couldn't enter the post. $error<br/>You can return to the previous page, or refresh to try again."); // "thread.php?id={$_GET['id']}", htmlspecialchars($thread['title']), 0
}
// Process attachments removal
if ($config['allow-attachments']) {
process_attachments($attach_key, $loguser['id'], 0, ATTACH_PM);
}
if (isset($_POST['submit'])) {
check_token($_POST['auth']);
if ($isadmin || $mythread) {
$modq = array(
'closed' => $_POST['close'],
);
} else {
$modq = array();
}
//$modq = ($isadmin || $mythread) ? "`closed` = {$_POST['close']}," : "";
$pid = create_pm_post($loguser, $_GET['id'], $_POST['message'], $_SERVER['REMOTE_ADDR'], $_POST['moodid'], $_POST['nosmilies'], $_POST['nohtml'], $_POST['nolayout'], $modq);
if ($config['allow-attachments']) {
confirm_attachments($attach_key, $loguser['id'], $pid, ATTACH_PM);
}
$sql->commit();
return header("Location: showprivate.php?pid=$pid#$pid");
}
}
/*
Main page
*/
$smilies = readsmilies();
pageheader("Conversation: ".htmlspecialchars($thread['title'])." -- New Reply");
$barlinks .= " - <a href='showprivate.php?id={$_GET['id']}'>".htmlspecialchars($thread['title'])."</a>";
/*
Previous posts in the conversation
*/
$postlist = thread_history($_GET['id'], $ppp + 1, true);
/*
Quoting something?
*/
if ($_GET['postid']) {
$post = $sql->fetchq("
SELECT user, text, thread
FROM pm_posts
WHERE id = {$_GET['postid']} AND (".((int) $isadmin)." OR deleted = 0)
");
if ($post && $post['thread'] == $_GET['id']) { // Make sure the quote is in the same thread
$post['text'] = str_replace('<br>','\n',$post['text']);
$quoteuser = $sql->resultq("SELECT name FROM users WHERE id = {$post['user']}");
$_POST['message'] = "[quote={$quoteuser}]{$post['text']}[/quote]\r\n";
unset($post, $quoteuser);
}
}
if (isset($_POST['preview'])) {
$data = array(
// Text
'message' => $_POST['message'],
#'head' => "",
#'sign' => "",
// Post metadata
#'id' => 0,
'forum' => -1, // PM "Forum"
#'ip' => "",
#'num' => "",
#'date' => "",
// (mod) Options
'nosmilies' => $_POST['nosmilies'],
'nohtml' => $_POST['nohtml'],
'nolayout' => $_POST['nolayout'],
'moodid' => $_POST['moodid'],
'noob' => 0,
// Attachments
'attach_key' => $attach_key,
#'attach_sel' => "",
);
print preview_post($loguser, $data);
} else {
$_POST['close'] = $thread['closed'];
}
$modoptions = "";
if ($isadmin || $mythread) {
$selclosed = $_POST['close'] ? "checked" : "";
$modoptions =
"<tr>
<td class='tdbg1 center b'>Extra Options:</td>
<td class='tdbg2' colspan=2>
<input type='checkbox' name='close' id='close' value=1 $selclosed><label for='close'>Close</label>
</td>
</tr>";
}
$nosmilieschk = $_POST['nosmilies'] ? "checked" : "";
$nolayoutchk = $_POST['nolayout'] ? "checked" : "";
$nohtmlchk = $_POST['nohtml'] ? "checked" : "";
$links = array(
["Private messages" , "private.php"],
[$thread['title'] , "showprivate.php?id={$_GET['id']}"],
["New reply" , NULL],
);
$barlinks = dobreadcrumbs($links);
?>
<?= $barlinks . $forum_error ?>
<form method="POST" action="?id=<?=$_GET['id']?>" enctype="multipart/form-data" autocomplete=off>
<table class='table'>
<tr>
<td class='tdbgh center' style='width: 150px'> </td>
<td class='tdbgh center' colspan=2> </td>
</tr>
<tr>
<td class='tdbg1 center b'>Reply:</td>
<td class='tdbg2' id="msgtd" style='width: 800px' valign=top>
<textarea id="msgtxt" wrap=virtual name=message ROWS=21 COLS=<?=$numcols?> style="width: 100%; max-width: 800px; resize:vertical;" autofocus><?=htmlspecialchars($_POST['message'], ENT_QUOTES)?></textarea>
</td>
<td class='tdbg2' width=*>
<?=mood_layout(0, $loguser['id'], $_POST['moodid'])?>
</td>
</tr>
<tr>
<td class='tdbg1 center'> </td>
<td class='tdbg2' colspan=2>
<?= auth_tag() ?>
<input type='submit' class=submit name=submit VALUE="Submit reply">
<input type='submit' class=submit name=preview VALUE="Preview reply">
</td>
</tr>
<tr>
<td class='tdbg1 center b'>Options:</td>
<td class='tdbg2' colspan=2>
<input type='checkbox' name="nosmilies" id="nosmilies" value="1"<?=$nosmilieschk?>><label for="nosmilies">Disable Smilies</label> -
<input type='checkbox' name="nolayout" id="nolayout" value="1"<?=$nolayoutchk ?>><label for="nolayout" >Disable Layout</label> -
<input type='checkbox' name="nohtml" id="nohtml" value="1"<?=$nohtmlchk ?>><label for="nohtml" >Disable HTML</label> |
<?=mood_layout(1, $loguser['id'], $_POST['moodid'])?>
</td>
</tr>
<?=$modoptions?>
<?=quikattach($_GET['id'], $loguser['id'])?>
</table>
<br>
<?=$postlist?>
</form>
<?=$barlinks?>
<?php
}
else {
// Creating a new thread
pageheader("New Conversation");
$smilies = readsmilies();
/*
Variable initialization (global)
*/
$posticons = file('posticons.dat');
$_POST['iconid'] = (isset($_POST['iconid']) ? (int) $_POST['iconid'] : -1); // 'None' should be the default value
$_POST['custposticon'] = filter_string($_POST['custposticon']);
$iconpreview = $posticon = "";
$_POST['subject'] = filter_string($_POST['subject']);
$_POST['description'] = filter_string($_POST['description']);
$_POST['message'] = filter_string($_POST['message']);
// Sendprivate link support, which I originally forgot to reimplement back (oops)
$_GET['userid'] = filter_int($_GET['userid']);
if ($_GET['userid']) {
$_POST['users'] = $sql->resultq("SELECT name FROM users WHERE id = {$_GET['userid']}");
} else {
$_POST['users'] = filter_string($_POST['users']);
}
$userlist = array_filter(explode(';', $_POST['users']), 'trim');
$destcount = count($userlist);
$_POST['moodid'] = filter_int($_POST['moodid']);
$_POST['nosmilies'] = filter_int($_POST['nosmilies']);
$_POST['nohtml'] = filter_int($_POST['nohtml']);
$_POST['nolayout'] = filter_int($_POST['nolayout']);
$_POST['close'] = filter_int($_POST['close']);
$_POST['folder'] = isset($_GET['dir']) ? ((int) $_GET['dir']) : filter_int($_POST['folder']); // Convenience for links
// Attachment preview stuff
$input_tid = "";
$attach_key = "nk";
if (isset($_POST['preview']) || isset($_POST['submit'])) {
// common threadpost / query requirements
if (!$_POST['message']) {
$error = "You haven't entered a message.";
} else if (!$_POST['subject']) {
$error = "You haven't entered a subject.";
} else if (!$destcount) {
$error = "You haven't entered an existing username to send this conversation to.";
} else if ($destcount > $config['pmthread-dest-limit']) {
$error = "You have entered too many usernames.";
} else if ($loguser['lastpmtime'] > (ctime()-30)) {
$error = "You are trying to post too rapidly.";
} else if (!valid_pm_folder($_POST['folder'], $loguser['id'])) {
$error = "You have selected a nonexisting folder.";
} else if (!($destid = valid_pm_acl($userlist, false, $error))) {
$error = "The partecipants list cannot be processed.<br>{$error}";
}
if ($error) { // This redirect is so fucking annoying
errorpage("Couldn't enter the post. $error<br/>You can return to the previous page, or refresh to try again.");
}
// All OK!
if ($config['allow-attachments']) {
$attach_key = "npmx";
$input_tid = process_attachments($attach_key, $loguser['id'], 0, ATTACH_PM | ATTACH_INCKEY);
}
// Needed for thread preview
if ($_POST['iconid'] != '-1' && isset($posticons[$_POST['iconid']])) {
$posticon = $posticons[$_POST['iconid']];
} else {
$posticon = $_POST['custposticon'];
}
if (isset($_POST['submit'])) {
check_token($_POST['auth']);
if (!$isadmin && !$config['allow-pmthread-edit']) {
$_POST['close'] = 0;
}
$sql->beginTransaction();
$tid = create_pm_thread($loguser, $_POST['subject'], $_POST['description'], $posticon, $_POST['close']);
$pid = create_pm_post($loguser, $tid, $_POST['message'], $_SERVER['REMOTE_ADDR'], $_POST['moodid'], $_POST['nosmilies'], $_POST['nohtml'], $_POST['nolayout']);
set_pm_acl($destid, $tid); // and add yourself automatically
if ($config['allow-attachments']) {
confirm_attachments($attach_key, $loguser['id'], $pid, ATTACH_PM);
}
$sql->commit();
errorpage("Conversation posted successfully!", "showprivate.php?id=$tid", $_POST['subject'], 0);
}
}
/*
Main page below
*/
$nosmilieschk = $_POST['nosmilies'] ? " checked" : "";
$nohtmlchk = $_POST['nohtml'] ? " checked" : "";
$nolayoutchk = $_POST['nolayout'] ? " checked" : "";
if (isset($_POST['preview'])) {
$iconpreview = "";
if ($posticon) {
$iconpreview = "<img src=\"".htmlspecialchars($posticon)."\" height=15 align=absmiddle>";
}
// Threadpost
$data = array(
// Text
'message' => $_POST['message'],
#'head' => "",
#'sign' => "",
// Post metadata
#'id' => 0,
'forum' => -1, // PM "Forum"
#'ip' => "",
#'num' => "",
#'date' => "",
// (mod) Options
'nosmilies' => $_POST['nosmilies'],
'nohtml' => $_POST['nohtml'],
'nolayout' => $_POST['nolayout'],
'moodid' => $_POST['moodid'],
'noob' => 0,
// Attachments
'attach_key' => $attach_key,
#'attach_sel' => "",
);
?>
<table class='table'><tr><td class='tdbgh center'>Conversation preview</td></tr></table>
<table class='table' style='border-top: none !important'>
<tr>
<td class='tdbg2 center' style='width: 4%'><?=$iconpreview?></td>
<td class='tdbg1'>
<b><?=htmlspecialchars($_POST['subject'])?></b>
<span class='fonts'><br><?=htmlspecialchars($_POST['description'])?></span>
</td>
</tr>
</table>
<?= preview_post($loguser, $data, PREVIEW_NEW, NULL) ?>
<?php
$autofocus[1] = 'autofocus'; // for 'message'
} else {
$autofocus[0] = 'autofocus'; // for 'subject'
}
$modoptions = "";
if ($isadmin || $config['allow-pmthread-edit']) {
$selclosed = $_POST['close'] ? "checked" : "";
$modoptions = " - <input type='checkbox' name='close' id='close' value=1 $selclosed><label for='close'>Disable replies</label>";
}
$links = array(
["Private messages" , "private.php"],
["New conversation" , NULL],
);
$barlinks = dobreadcrumbs($links);
?>
<?=$barlinks?>
<form method="POST" action="?" enctype="multipart/form-data" autocomplete=off>
<table class='table'>
<tr>
<td class='tdbgh center' style='width: 150px'> </td>
<td class='tdbgh center' colspan=2> </td>
</tr>
<tr>
<td class='tdbg1 center b'>Thread icon:</td>
<td class='tdbg2' colspan=2>
<?=dothreadiconlist($_POST['iconid'], $_POST['custposticon'])?>
</td>
</tr>
<tr>
<td class='tdbg1 center b'>Thread title:</td>
<td class='tdbg2' colspan=2>
<input type='text' name=subject SIZE=40 MAXLENGTH=100 VALUE="<?=htmlspecialchars($_POST['subject'])?>" <?=filter_string($autofocus[0])?>>
</td>
</tr>
<tr>
<td class='tdbg1 center b'>Thread description:</td>
<td class='tdbg2' colspan=2>
<input type='text' name=description SIZE=100 MAXLENGTH=120 VALUE="<?=htmlspecialchars($_POST['description'])?>">
</td>
</tr>
<tr>
<td class='tdbg1 center b'>Other partecipants:</td>
<td class='tdbg2' colspan=2>
<input type='text' name=users SIZE=60 MAXLENGTH=100 VALUE="<?=htmlspecialchars($_POST['users'])?>">
<span class='fonts'>Max <?= $config['pmthread-dest-limit'] ?> users allowed. Multiple users separated with a semicolon.</span>
</td>
</tr>
<tr>
<td class='tdbg1 center b'>Post:</td>
<td class='tdbg2' id="msgtd" style='width: 800px' valign=top>
<textarea id="msgtxt" wrap=virtual name=message ROWS=21 COLS=<?=$numcols?> style="width: 100%; max-width: 800px; resize:vertical;" <?=filter_string($autofocus[1])?>><?=htmlspecialchars($_POST['message'])?></textarea>
</td>
<td class='tdbg2' width=*>
<?=mood_layout(0, $loguser['id'], $_POST['moodid'])?>
</td>
</tr>
<tr>
<td class='tdbg1 center'> </td>
<td class='tdbg2' colspan=2>
<?= auth_tag() ?>
<?= $input_tid ?>
<input type='submit' class=submit name=submit VALUE="Submit thread">
<input type='submit' class=submit name=preview VALUE="Preview thread">
</td>
</tr>
<tr>
<td class='tdbg1 center b'>Options:</td>
<td class='tdbg2' colspan=2>
<input type='checkbox' name="nosmilies" id="nosmilies" value="1"<?=$nosmilieschk?>><label for="nosmilies">Disable Smilies</label> -
<input type='checkbox' name="nolayout" id="nolayout" value="1"<?=$nolayoutchk ?>><label for="nolayout" >Disable Layout</label> -
<input type='checkbox' name="nohtml" id="nohtml" value="1"<?=$nohtmlchk ?>><label for="nohtml" >Disable HTML</label>
<?= $modoptions ?> |
<?=mood_layout(1, $loguser['id'], $_POST['moodid'])?>
</td>
</tr>
<tr>
<td class='tdbg1 center b'>Save in:</td>
<td class='tdbg2' colspan=2>
<?= pm_folder_select('folder', $loguser['id'], $_POST['folder']) ?>
</td>
</tr>
<?=quikattach($attach_key, $loguser['id'])?>
</table>
</form>
<?=$barlinks?>
<?php
}
replytoolbar('msg', $smilies);
pagefooter();