-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendprivate.php
259 lines (231 loc) · 7.36 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
<?php
// AcmlmBoard XD - Private message sending/previewing page
// Access: user
include("lib/common.php");
$title = __("Private messages");
MakeCrumbs(array(__("Main")=>"./", __("Private messages")=>"private.php", __("New PM")=>""), "");
AssertForbidden("sendPM");
if(!$loguserid) //Not logged in?
Kill(__("You must be logged in to send private messages."));
$pid = (int)$_GET['pid'];
if($pid)
{
$qPM = "select * from pmsgs left join pmsgs_text on pid = pmsgs.id where userto = ".$loguserid." and pmsgs.id = ".$pid;
$rPM = Query($qPM);
if(NumRows($rPM))
{
$sauce = Fetch($rPM);
$qUser = "select * from users where id = ".(int)$sauce['userfrom'];
$rUser = Query($qUser);
if(NumRows($rUser))
$user = Fetch($rUser);
else
Kill(__("Unknown user."));
$prefill = "[reply=\"".$user['name']."\"]".htmlval($sauce['text'])."[/quote]";
$trefill = "Re: ".$sauce['title'];
if(!isset($_POST['to']))
$_POST['to'] = $user['name'];
} else
Kill(__("Unknown PM."));
}
$uid = (int)$_GET['uid'];
if($uid)
{
$qUser = "select * from users where id = ".$uid;
$rUser = Query($qUser);
if(NumRows($rUser))
{
$user = Fetch($rUser);
$_POST['to'] = $user['name'];
} else
Kill(__("Unknown user."));
}
/*
// "Banned users can't send PMs. Bad bad bad, quite often PMs are a good way for them to try and get unbanned." -- Mega-Mario
if($loguser['powerlevel'] < 0)
Kill("You're banned.");
*/
write(
"
<script type=\"text/javascript\">
window.addEventListener(\"load\", hookUpControls, false);
</script>
");
$recipIDs = array();
if($_POST['to'])
{
$firstTo = -1;
$recipients = explode(";", $_POST['to']);
foreach($recipients as $to)
{
$to = mysql_real_escape_string(trim(htmlentities($to)));
if($to == "")
continue;
$qUser = "select id from users where name='".$to."' or displayname='".$to."'";
$rUser = Query($qUser);
if(NumRows($rUser))
{
$user = Fetch($rUser);
$id = $user['id'];
if($firstTo == -1)
$firstTo = $id;
if($id == $loguserid)
$errors .= __("You can't send private messages to yourself.")."<br />";
else if(!in_array($id, $recipIDs))
$recipIDs[] = $id;
}
else
$errors .= format(__("Unknown user \"{0}\""), $to)."<br />";
}
$maxRecips = array(-1 => 1, 3, 3, 3, 10, 100, 1);
$maxRecips = $maxRecips[$loguser['powerlevel']];
//$maxRecips = ($loguser['powerlevel'] > 1) ? 5 : 1;
if(count($recipIDs) > $maxRecips)
$errors .= __("Too many recipients.");
if($errors != "")
{
Alert($errors);
$_POST['action'] = "";
}
}
else
{
if($_POST['action'] == __("Send"))
Alert("Enter a recipient and try again.", "Your PM has no recipient.");
$_POST['action'] = "";
}
if($_POST['action'] == __("Send") || $_POST['action'] == __("Save as Draft"))
{
if($_POST['title'])
{
$_POST['title'] = htmlentities2($_POST['title']);
if($_POST['text'])
{
$wantDraft = (int)($_POST['action'] == __("Save as Draft"));
//$post = justEscape($post);
$post = htmlentities2(deSlashMagic($_POST['text']));
$post = preg_replace("'/me '","[b]* ".$loguser['name']."[/b] ", $post); //to prevent identity confusion
$post = str_replace("\n","##TSURUPETTANYOUJO##", $post);
TidyPost($post);
$post = str_replace("##TSURUPETTANYOUJO##","\n", $post);
if($wantDraft)
$post = "<!-- ###MULTIREP:".$_POST['to']." ### -->".$post;
$post = mysql_real_escape_string($post);
//$pid = FetchResult("SELECT id+1 FROM pmsgs WHERE (SELECT COUNT(*) FROM pmsgs p2 WHERE p2.id=pmsgs.id+1)=0 ORDER BY id ASC LIMIT 1");
//if($pid < 1) $pid = 1;
if($_POST['action'] == __("Save as Draft"))
{
$qPM = "insert into pmsgs (userto, userfrom, date, ip, msgread, drafting) values (".$firstTo.", ".$loguserid.", ".time().", '".$_SERVER['REMOTE_ADDR']."', 0, ".$wantDraft.")";
$rPM = Query($qPM);
$pid = mysql_insert_id();
$qPMT = "insert into pmsgs_text (pid,title,text) values (".$pid.", '".justEscape($_POST['title'])."', '".$post."')";
$rPMT = Query($qPMT);
Redirect(__("Draft saved!"), "private.php?show=2", __("your drafts box"));
}
else
{
foreach($recipIDs as $recipient)
{
$qPM = "insert into pmsgs (userto, userfrom, date, ip, msgread, drafting) values (".$recipient.", ".$loguserid.", ".time().", '".$_SERVER['REMOTE_ADDR']."', 0, ".$wantDraft.")";
$rPM = Query($qPM);
$pid = mysql_insert_id();
$qPMT = "insert into pmsgs_text (pid,title,text) values (".$pid.", '".justEscape($_POST['title'])."', '".$post."')";
$rPMT = Query($qPMT);
}
Redirect(__("PM sent!"),"private.php?show=1", __("your PM outbox"));
}
exit();
} else
{
Alert(__("Enter a message and try again."), __("Your PM is empty."));
}
} else
{
Alert(__("Enter a title and try again."), __("Your PM is untitled."));
}
}
$_POST['title'] = htmlentities2(deSlashMagic($_POST['title']));
$_POST['text'] = htmlentities2(deSlashMagic($_POST['text']));
if($_POST['action']=="Preview")
{
if($_POST['text'])
{
$_POST['realtitle'] = $_POST['title']; //store the real PM title in another field...
$_POST['num'] = "---";
$_POST['posts'] = "---";
$_POST['id'] = "???";
$_POST['uid'] = $loguserid;
$copies = explode(",","title,name,displayname,picture,sex,powerlevel,avatar,postheader,signature,signsep,regdate,lastactivity,lastposttime");
foreach($copies as $toCopy)
$_POST[$toCopy] = $loguser[$toCopy];
$realtext = $_POST['text'];
$_POST['text'] = preg_replace("'/me '","[b]* ".$loguser['name']."[/b] ", $_POST['text']); //to prevent identity confusion
MakePost($_POST, 0, 0);
$_POST['title'] = $_POST['realtitle']; //and put it back for the form.
$_POST['text'] = $realtext;
}
}
//if($_POST['text']) $prefill = htmlval(deSlashMagic($_POST['text']));
//if($_POST['title']) $trefill = htmlval(deSlashMagic($_POST['title']));
if($_POST['text']) $prefill = htmlval($_POST['text']);
if($_POST['title']) $trefill = htmlval($_POST['title']);
if(!isset($_POST['iconid']))
$_POST['iconid'] = 0;
Write(
"
<table style=\"width: 100%;\">
<tr>
<td style=\"vertical-align: top; border: none;\">
<form action=\"sendprivate.php\" method=\"post\">
<table class=\"outline margin width100\">
<tr class=\"header1\">
<th colspan=\"2\">
".__("Send PM")."
</th>
</tr>
<tr class=\"cell0\">
<td>
".__("To")."
</td>
<td>
<input type=\"text\" name=\"to\" style=\"width: 98%;\" maxlength=\"1024\" value=\"{2}\" />
</td>
</tr>
<tr class=\"cell1\">
<td>
".__("Title")."
</td>
<td>
<input type=\"text\" name=\"title\" style=\"width: 98%;\" maxlength=\"60\" value=\"{1}\" />
</td>
<tr class=\"cell0\">
<td>
".__("Message")."
</td>
<td>
<textarea id=\"text\" name=\"text\" rows=\"16\" style=\"width: 98%;\">{0}</textarea>
</td>
</tr>
<tr class=\"cell2\">
<td></td>
<td>
<input type=\"submit\" name=\"action\" value=\"".__("Send")."\" />
<input type=\"submit\" name=\"action\" value=\"".__("Preview")."\" />
<input type=\"submit\" name=\"action\" value=\"".__("Save as Draft")."\" />
</td>
</tr>
</table>
</form>
</td>
<td style=\"width: 200px; vertical-align: top; border: none;\">
", $prefill, $trefill, $_POST['to']);
DoSmileyBar();
DoPostHelp();
Write(
"
</td>
</tr>
</table>
");
MakeCrumbs(array(__("Main")=>"./", __("Private messages")=>"private.php", __("New PM")=>""), "");
?>