-
Notifications
You must be signed in to change notification settings - Fork 0
/
pm.inc
277 lines (248 loc) · 8.89 KB
/
pm.inc
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
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/boinc_db.inc");
require_once("../inc/sanitize_html.inc");
require_once("../inc/notification.inc");
function pm_header() {
echo "<div>\n";
echo " <a href=\"pm.php?action=inbox\">".tra("Inbox")."</a>\n";
echo " · <a href=\"pm.php?action=new\">".tra("Write")."</a>\n";
echo "</div>\n";
}
function pm_rules() {
$x = "<table><tr><td align=left><small>";
$x .= tra("
<ul>
<li> No commercial advertisements or other spam.
<li> No hostile, threatening, or insulting messages.
<li> If you violate these rules, your account may be deleted.
</ul>
");
$x .= "</small></td></tr></table>\n";
return $x;
}
// either:
// $replyto: message being replied to.
// $userids: list of user IDs
// post "to": comma-separated list of user IDs
function pm_form($replyto, $to_ids, $error = null) {
global $bbcode_html, $bbcode_js;
global $g_logged_in_user;
page_head(tra("Send private message"),'','','', $bbcode_js);
if (post_str("preview", true) == tra("Preview")) {
$content = post_str("content", true);
panel(tra('Preview'),
function() use($content) {
echo output_transform($content, null);
}
);
}
// compute:
// $to_ids (if not given)
// $to_str: list of recipient names
//
$subject = null;
$content = null;
if ($replyto) {
$message = BoincPrivateMessage::lookup_id($replyto);
if (!$message || $message->userid != $g_logged_in_user->id) {
error_page(tra("no such message"));
}
$content = "[quote]".$message->content."[/quote]\n";
$userid = $message->senderid;
$user = BoincUser::lookup_id($userid);
if (!$user) {
error_page("Sender no longer exists");
}
$to_ids = [$user->id];
$subject = $message->subject;
if (substr($subject, 0, 3) != "re:") {
$subject = "re: ".$subject;
}
} elseif ($to_ids) {
$subject = post_str("subject", true);
$content = post_str("content", true);
} else {
$x = sanitize_tags(post_str("to_ids", true));
$y = explode(',', $x);
$to_ids = [];
foreach ($y as $id) {
$to_ids = intval($id);
}
$subject = post_str("subject", true);
$content = post_str("content", true);
}
$to_str = [];
foreach ($to_ids as $userid) {
$user = BoincUser::lookup_id($userid);
if (!$user) {
error_page("Sender no longer exists");
}
$to_str[] = $user->name;
}
$content = htmlspecialchars($content);
$subject = htmlspecialchars($subject);
if ($error != null) {
echo "<p class=\"text-danger\">".$error."</p>\n";
}
echo "<form action=\"pm.php\" method=\"post\" name=\"post\" onsubmit=\"return checkForm(this)\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"send\">\n";
form_input_hidden('to_ids', implode($to_ids, ','));
echo form_tokens($g_logged_in_user->authenticator);
start_table();
row2("To", implode($to_str,', '));
row2(
tra("Subject"),
"<input type=\"text\" class=\"form-control\" name=\"subject\" value=\"$subject\">",
null, '20%'
);
form_focus("post", "subject");
row2_init(
tra("Message")."<small>".bbcode_info().pm_rules()."</small>",
"",
'20%'
);
start_table();
echo $bbcode_html;
echo "<tr><td>\n";
echo "<textarea name=\"content\" class=\"form-control\" rows=\"18\">$content</textarea>";
echo "</td></tr>\n";
end_table();
echo "<tr><td></td><td><input class=\"btn btn-primary\" type=\"submit\" name=\"preview\" value=\"".tra("Preview")."\"> <input class=\"btn btn-success\" type=\"submit\" value=\"".tra("Send message")."\"></td></tr>\n";
end_table();
page_tail();
exit();
}
function send_pm_notification_email(
$logged_in_user, $to_user, $subject, $content
) {
$message = "
You have received a new private message at ".PROJECT.".
From: $logged_in_user->name (ID $logged_in_user->id)
Subject: $subject
$content
--------------------------
To delete or respond to this message, visit:
".secure_url_base()."pm.php
To change email preferences, visit:
".secure_url_base()."edit_forum_preferences_form.php
Do not reply to this message.
" ;
send_email($to_user, "[".PROJECT."] - private message", $message);
}
function pm_email_line($notify) {
$pm = BoincPrivateMessage::lookup_id($notify->opaque);
$from_user = BoincUser::lookup_id($pm->senderid);
if (!$pm || !$from_user) return null;
return "$from_user->name ".tra("sent you a private message; subject:")." '$pm->subject'";
}
function pm_web_line($notify) {
$pm = BoincPrivateMessage::lookup_id($notify->opaque);
$from_user = BoincUser::lookup_id($pm->senderid);
if (!$pm || !$from_user) return null;
return "<a href=pm.php>".tra("Private message%1 from %2, subject:" , "</a>", $from_user->name )." $pm->subject";
}
function pm_send_msg($from_user, $to_user, $subject, $content, $send_email) {
$sql_subject = BoincDb::escape_string(sanitize_tags($subject));
$sql_content = BoincDb::escape_string($content);
$mid = BoincPrivateMessage::insert("(userid, senderid, date, subject, content) VALUES ($to_user->id, $from_user->id, UNIX_TIMESTAMP(), '$sql_subject', '$sql_content')");
if (!$mid) {
error_page(tra("Couldn't create message"));
}
// send email notification if needed
//
if ($send_email) {
BoincForumPrefs::lookup($to_user);
switch ($to_user->prefs->pm_notification) {
case 0:
case 2:
break;
case 1:
send_pm_notification_email(
$from_user, $to_user, $subject, $content
);
break;
}
}
// create notification in any case
//
BoincNotify::replace(
sprintf(
"userid=%d, create_time=%d, type=%d, opaque=%d, sent_by_email=0",
$to_user->id, time(), NOTIFY_PM, $mid
)
);
email_if_immediate($to_user);
}
function pm_count($userid, $duration) {
$time = time() - $duration;
// we don't want to include team messages in this count.
// Kludge for excluding them based on subject.
// Should add a flag to private_message to distinguish them.
//
return BoincPrivateMessage::count(
"senderid=$userid AND date>$time AND subject not like 'Message from team%'"
);
}
function check_pm_count($userid) {
if ((pm_count($userid, 60) >= 2) || (pm_count($userid, 600) >= 5) ||
(pm_count($userid, 3600) >= 15) || (pm_count($userid, 86400) >= 50)) {
error_page(tra("You are not allowed to send privates messages so often. Please wait some time before sending more messages."));
}
}
function pm_notification($user) {
$output = "";
$unread = BoincPrivateMessage::count("userid=$user->id AND opened=0");
$output .= "<a href=\"pm.php?action=inbox\">".tra("Inbox")."</a>";
if ($unread) {
$output .= "<span class=\"inboxunread\"> ($unread ".tra("unread").")</span>\n";
}
$output .= " · <a href=\"pm.php?action=new\">".tra("Write")."</a>\n";
return $output;
}
function pm_email_remind($user) {
if (!$user->prefs->pm_notification) {
return "<br><small>" .
tra(
"For email notification, %1 edit community prefs %2",
'<a href="edit_forum_preferences_form.php">', '</a>'
) .
"</small>"
;
}
return "";
}
function pm_rss($notify, &$title, &$msg, &$url) {
$pm = BoincPrivateMessage::lookup_id($notify->opaque);
$from_user = BoincUser::lookup_id($pm->senderid);
if (!$pm || !$from_user) {
$msg = null;
return;
}
$title = tra("Private message");
$msg = "You have received a <a href=".secure_url_base()."pm.php>private message</a>.";
$url = secure_url_base()."pm.php";
}
function pm_delete_user($user) {
$mm = BoincPrivateMessage::enum("userid=$user->id or senderid=$user->id");
foreach ($mm as $m) {
$m->delete();
}
}
$cvs_version_tracker[]="\$Id: pm.inc 14019 2007-11-01 23:04:39Z davea $";
?>