From 48dc4c02ae097258f8b4a9c39c38580d29b640f3 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 22 Oct 2014 18:02:43 -0400 Subject: [PATCH 1/3] [ticket/13205] Add a mark all messages read link to PM folders PHPBB3-13205 --- phpBB/includes/functions_privmsgs.php | 17 ++++++++++++ phpBB/includes/ucp/ucp_pm.php | 26 ++++++++++++++++++- phpBB/language/en/ucp.php | 2 ++ .../template/ucp_pm_message_header.html | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index ad142b1cca..79f818caf2 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -914,6 +914,23 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) } } +function mark_folder_read($user_id, $folder_id) +{ + global $db; + + $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . " + WHERE folder_id = $folder_id + AND user_id = $user_id + AND pm_unread = 1"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + update_unread_status(true, $row['msg_id'], $user_id, $folder_id); + } + $db->sql_freeresult($result); +} + /** * Handle all actions possible with marked messages */ diff --git a/phpBB/includes/ucp/ucp_pm.php b/phpBB/includes/ucp/ucp_pm.php index 7a8c694870..02a980c503 100644 --- a/phpBB/includes/ucp/ucp_pm.php +++ b/phpBB/includes/ucp/ucp_pm.php @@ -45,7 +45,7 @@ class ucp_pm function main($id, $mode) { - global $user, $template, $phpbb_root_path, $auth, $phpEx, $db, $config; + global $user, $template, $phpbb_root_path, $auth, $phpEx, $db, $config, $request; if (!$user->data['is_registered']) { @@ -246,6 +246,29 @@ class ucp_pm $folder_id = (int) $row['folder_id']; } + if ($request->variable('mark', '') == 'all' && check_link_hash($request->variable('token', ''), 'mark_all_pms_read')) + { + // mark unread + mark_folder_read($user->data['user_id'], $folder_id); + + meta_refresh(3, $this->u_action); + $message = $user->lang['PM_MARK_ALL_READ_SUCCESS']; + + if ($request->is_ajax()) + { + $json_response = new \phpbb\json_response(); + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'success' => true, + )); + } + $message .= '

' . $user->lang('RETURN_UCP', '', ''); + + trigger_error($message); + } + + $message_row = array(); if ($action == 'view_message' && $msg_id) { @@ -332,6 +355,7 @@ class ucp_pm 'U_SENTBOX' => $this->u_action . '&folder=sentbox', 'U_CREATE_FOLDER' => $this->u_action . '&mode=options', 'U_CURRENT_FOLDER' => $this->u_action . '&folder=' . $folder_id, + 'U_MARK_ALL' => $this->u_action . '&folder=' . $folder_id . '&mark=all&token=' . generate_link_hash('mark_all_pms_read'), 'S_IN_INBOX' => ($folder_id == PRIVMSGS_INBOX) ? true : false, 'S_IN_OUTBOX' => ($folder_id == PRIVMSGS_OUTBOX) ? true : false, diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index ad7063d3f9..07751d1f7f 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -417,6 +417,8 @@ $lang = array_merge($lang, array( 'PM_FROM_REMOVED_AUTHOR' => 'This message was sent by a user no longer registered.', 'PM_ICON' => 'PM icon', 'PM_INBOX' => 'Inbox', + 'PM_MARK_ALL_READ' => 'Mark all messages read', + 'PM_MARK_ALL_READ_SUCCESS' => 'All private messages in this folder have been marked read', 'PM_NO_USERS' => 'The requested users to be added do not exist.', 'PM_OUTBOX' => 'Outbox', 'PM_SENTBOX' => 'Sent messages', diff --git a/phpBB/styles/prosilver/template/ucp_pm_message_header.html b/phpBB/styles/prosilver/template/ucp_pm_message_header.html index d777de908d..7be51e0034 100644 --- a/phpBB/styles/prosilver/template/ucp_pm_message_header.html +++ b/phpBB/styles/prosilver/template/ucp_pm_message_header.html @@ -48,6 +48,7 @@ {L_RETURN_TO_FOLDER} + {L_PM_MARK_ALL_READ} {TOTAL_MESSAGES} From b5594371ab1a31e9b599eb964a3721b2e2614287 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 22 Oct 2014 18:31:29 -0400 Subject: [PATCH 2/3] [ticket/13205] Remove superfluous newline PHPBB3-13205 --- phpBB/includes/ucp/ucp_pm.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/includes/ucp/ucp_pm.php b/phpBB/includes/ucp/ucp_pm.php index 02a980c503..73519764f4 100644 --- a/phpBB/includes/ucp/ucp_pm.php +++ b/phpBB/includes/ucp/ucp_pm.php @@ -268,7 +268,6 @@ class ucp_pm trigger_error($message); } - $message_row = array(); if ($action == 'view_message' && $msg_id) { From df72846b8945224a431558cfc3cc7e12a463444a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 22 Oct 2014 18:35:07 -0400 Subject: [PATCH 3/3] [ticket/13205] Explicitly cast ids to integers and reformat SQL PHPBB3-13205 --- phpBB/includes/functions_privmsgs.php | 9 +++++---- phpBB/includes/ucp/ucp_pm.php | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 79f818caf2..838c6a0fec 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -918,10 +918,11 @@ function mark_folder_read($user_id, $folder_id) { global $db; - $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . " - WHERE folder_id = $folder_id - AND user_id = $user_id - AND pm_unread = 1"; + $sql = 'SELECT msg_id + FROM ' . PRIVMSGS_TO_TABLE . ' + WHERE folder_id = ' . ((int) $folder_id) . ' + AND user_id = ' . ((int) $user_id) . ' + AND pm_unread = 1'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) diff --git a/phpBB/includes/ucp/ucp_pm.php b/phpBB/includes/ucp/ucp_pm.php index 73519764f4..425a56cf6c 100644 --- a/phpBB/includes/ucp/ucp_pm.php +++ b/phpBB/includes/ucp/ucp_pm.php @@ -248,7 +248,6 @@ class ucp_pm if ($request->variable('mark', '') == 'all' && check_link_hash($request->variable('token', ''), 'mark_all_pms_read')) { - // mark unread mark_folder_read($user->data['user_id'], $folder_id); meta_refresh(3, $this->u_action);