Line 208 | Line 208 |
---|
); }
|
); }
|
if ($folder_id !== false && !isset($folder[$folder_id]))
| if ($folder_id !== false && $folder_id !== PRIVMSGS_HOLD_BOX && !isset($folder[$folder_id]))
|
{ trigger_error('UNKNOWN_FOLDER'); }
| { trigger_error('UNKNOWN_FOLDER'); }
|
Line 1077 | Line 1077 |
---|
WHERE ' . $db->sql_in_set('msg_id', $delete_ids); $db->sql_query($sql); }
|
WHERE ' . $db->sql_in_set('msg_id', $delete_ids); $db->sql_query($sql); }
|
| $db->sql_transaction('commit');
return true; }
/** * Delete all PM(s) for a given user and delete the ones without references * * @param int $user_id ID of the user whose private messages we want to delete * * @return boolean False if there were no pms found, true otherwise. */ function phpbb_delete_user_pms($user_id) { global $db, $user, $phpbb_root_path, $phpEx;
$user_id = (int) $user_id;
if (!$user_id) { return false; }
// Get PM Information for later deleting // The two queries where split, so we can use our indexes $undelivered_msg = $delete_ids = array();
// Part 1: get PMs the user received $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . ' WHERE user_id = ' . $user_id; $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) { $msg_id = (int) $row['msg_id']; $delete_ids[$msg_id] = $msg_id; } $db->sql_freeresult($result);
// Part 2: get PMs the user sent, but have yet to be received // We cannot simply delete them. First we have to check, // whether another user already received and read the message. $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . ' WHERE author_id = ' . $user_id . ' AND folder_id = ' . PRIVMSGS_NO_BOX; $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) { $msg_id = (int) $row['msg_id']; $undelivered_msg[$msg_id] = $msg_id; } $db->sql_freeresult($result);
if (empty($delete_ids) && empty($undelivered_msg)) { return false; }
$db->sql_transaction('begin');
if (!empty($undelivered_msg)) { // A pm is delivered, if for any recipient the message was moved // from their NO_BOX to another folder. We do not delete such // messages, but only delete them for users, who have not yet // received them. $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . ' WHERE author_id = ' . $user_id . ' AND folder_id <> ' . PRIVMSGS_NO_BOX . ' AND folder_id <> ' . PRIVMSGS_OUTBOX . ' AND folder_id <> ' . PRIVMSGS_SENTBOX; $result = $db->sql_query($sql);
$delivered_msg = array(); while ($row = $db->sql_fetchrow($result)) { $msg_id = (int) $row['msg_id']; $delivered_msg[$msg_id] = $msg_id; unset($undelivered_msg[$msg_id]); } $db->sql_freeresult($result);
$undelivered_user = array();
// Count the messages we delete, so we can correct the user pm data $sql = 'SELECT user_id, COUNT(msg_id) as num_undelivered_privmsgs FROM ' . PRIVMSGS_TO_TABLE . ' WHERE author_id = ' . $user_id . ' AND folder_id = ' . PRIVMSGS_NO_BOX . ' AND ' . $db->sql_in_set('msg_id', array_merge($undelivered_msg, $delivered_msg)) . ' GROUP BY user_id'; $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) { $num_pms = (int) $row['num_undelivered_privmsgs']; $undelivered_user[$num_pms][] = (int) $row['user_id'];
if (sizeof($undelivered_user[$num_pms]) > 50) { // If there are too many users affected the query might get // too long, so we update the value for the first bunch here. $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new_privmsg = user_new_privmsg - ' . $num_pms . ', user_unread_privmsg = user_unread_privmsg - ' . $num_pms . ' WHERE ' . $db->sql_in_set('user_id', $undelivered_user[$num_pms]); $db->sql_query($sql); unset($undelivered_user[$num_pms]); } } $db->sql_freeresult($result);
foreach ($undelivered_user as $num_pms => $undelivered_user_set) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new_privmsg = user_new_privmsg - ' . $num_pms . ', user_unread_privmsg = user_unread_privmsg - ' . $num_pms . ' WHERE ' . $db->sql_in_set('user_id', $undelivered_user_set); $db->sql_query($sql); }
if (!empty($delivered_msg)) { $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' WHERE folder_id = ' . PRIVMSGS_NO_BOX . ' AND ' . $db->sql_in_set('msg_id', $delivered_msg); $db->sql_query($sql); }
if (!empty($undelivered_msg)) { $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); $db->sql_query($sql);
$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); $db->sql_query($sql); } }
// Reset the user's pm count to 0 $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new_privmsg = 0, user_unread_privmsg = 0 WHERE user_id = ' . $user_id; $db->sql_query($sql);
// Delete private message data of the user $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' WHERE user_id = ' . (int) $user_id; $db->sql_query($sql);
if (!empty($delete_ids)) { // Now we have to check which messages we can delete completely $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . ' WHERE ' . $db->sql_in_set('msg_id', $delete_ids); $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) { unset($delete_ids[$row['msg_id']]); } $db->sql_freeresult($result);
if (!empty($delete_ids)) { // Check if there are any attachments we need to remove if (!function_exists('delete_attachments')) { include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); }
delete_attachments('message', $delete_ids, false);
$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' WHERE ' . $db->sql_in_set('msg_id', $delete_ids); $db->sql_query($sql); } }
// Set the remaining author id to anonymous // This way users are still able to read messages from users being removed $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' SET author_id = ' . ANONYMOUS . ' WHERE author_id = ' . $user_id; $db->sql_query($sql);
$sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET author_id = ' . ANONYMOUS . ' WHERE author_id = ' . $user_id; $db->sql_query($sql);
|
$db->sql_transaction('commit');
| $db->sql_transaction('commit');
|
Line 1362 | Line 1561 |
---|
while ($row = $db->sql_fetchrow($result)) {
|
while ($row = $db->sql_fetchrow($result)) {
|
// Additionally, do not include the sender if he is in the group he wants to send to. ;) if ($row['user_id'] === $user->data['user_id']) { continue; }
| |
$field = ($data['address_list']['g'][$row['group_id']] == 'to') ? 'to' : 'bcc'; $recipients[$row['user_id']] = $field; }
| $field = ($data['address_list']['g'][$row['group_id']] == 'to') ? 'to' : 'bcc'; $recipients[$row['user_id']] = $field; }
|
Line 1607 | Line 1800 |
---|
// Send Notifications if ($mode != 'edit') {
|
// Send Notifications if ($mode != 'edit') {
|
pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message']);
| pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message'], $data['msg_id']);
|
}
return $data['msg_id'];
| }
return $data['msg_id'];
|
Line 1616 | Line 1809 |
---|
/** * PM Notification */
|
/** * PM Notification */
|
function pm_notification($mode, $author, $recipients, $subject, $message)
| function pm_notification($mode, $author, $recipients, $subject, $message, $msg_id)
|
{ global $db, $user, $config, $phpbb_root_path, $phpEx, $auth;
$subject = censor_text($subject);
|
{ global $db, $user, $config, $phpbb_root_path, $phpEx, $auth;
$subject = censor_text($subject);
|
| // Exclude guests, current user and banned users from notifications
|
unset($recipients[ANONYMOUS], $recipients[$user->data['user_id']]);
if (!sizeof($recipients))
| unset($recipients[ANONYMOUS], $recipients[$user->data['user_id']]);
if (!sizeof($recipients))
|
Line 1629 | Line 1823 |
---|
return; }
|
return; }
|
// Get banned User ID's $sql = 'SELECT ban_userid FROM ' . BANLIST_TABLE . ' WHERE ' . $db->sql_in_set('ban_userid', array_map('intval', array_keys($recipients))) . ' AND ban_exclude = 0'; $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
| if (!function_exists('phpbb_get_banned_user_ids'))
|
{
|
{
|
unset($recipients[$row['ban_userid']]);
| include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
}
|
}
|
$db->sql_freeresult($result);
| $banned_users = phpbb_get_banned_user_ids(array_keys($recipients)); $recipients = array_diff(array_keys($recipients), $banned_users);
|
if (!sizeof($recipients)) {
| if (!sizeof($recipients)) {
|
Line 1649 | Line 1837 |
---|
$sql = 'SELECT user_id, username, user_email, user_lang, user_notify_pm, user_notify_type, user_jabber FROM ' . USERS_TABLE . '
|
$sql = 'SELECT user_id, username, user_email, user_lang, user_notify_pm, user_notify_type, user_jabber FROM ' . USERS_TABLE . '
|
WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($recipients)));
| WHERE ' . $db->sql_in_set('user_id', $recipients);
|
$result = $db->sql_query($sql);
$msg_list_ary = array();
| $result = $db->sql_query($sql);
$msg_list_ary = array();
|
Line 1688 | Line 1876 |
---|
'AUTHOR_NAME' => htmlspecialchars_decode($author), 'USERNAME' => htmlspecialchars_decode($addr['name']),
|
'AUTHOR_NAME' => htmlspecialchars_decode($author), 'USERNAME' => htmlspecialchars_decode($addr['name']),
|
'U_INBOX' => generate_board_url() . "/ucp.$phpEx?i=pm&folder=inbox") );
| 'U_INBOX' => generate_board_url() . "/ucp.$phpEx?i=pm&folder=inbox", 'U_VIEW_MESSAGE' => generate_board_url() . "/ucp.$phpEx?i=pm&mode=view&p=$msg_id", ));
|
$messenger->send($addr['method']); }
| $messenger->send($addr['method']); }
|