From 242476c29014367e8923e8f7e431ae543f08d69a Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 5 Jul 2020 16:52:42 +0700 Subject: [PATCH] [ticket/16208] Fix closed post report notifications PHPBB3-16208 --- phpBB/language/en/email/report_closed.txt | 8 ++- phpBB/language/en/ucp.php | 1 + .../notification/type/report_pm_closed.php | 4 +- .../notification/type/report_post_closed.php | 54 +++++++++++++++---- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/phpBB/language/en/email/report_closed.txt b/phpBB/language/en/email/report_closed.txt index f248018f9a..35b3e67f9e 100644 --- a/phpBB/language/en/email/report_closed.txt +++ b/phpBB/language/en/email/report_closed.txt @@ -2,6 +2,12 @@ Subject: Report closed - "{POST_SUBJECT}" Hello {USERNAME}, -You are receiving this notification because the report you filed on the post "{POST_SUBJECT}" in "{TOPIC_TITLE}" at "{SITENAME}" was handled by a moderator or by an administrator. The report was afterwards closed. If you have further questions contact {CLOSER_NAME} with a personal message. +You are receiving this notification because the report you filed on the post "{POST_SUBJECT}" by "{AUTHOR_NAME}" in "{TOPIC_TITLE}" topic at "{SITENAME}" was handled by a moderator or by an administrator. The report was afterwards closed. If you have further questions contact {CLOSER_NAME} with a personal message. + +You can view your reported post by clicking on the following link: + +{U_VIEW_POST} + +You have requested that you be notified on this event, remember that you can always choose not to be notified of closed post reports by changing the appropriate setting in your profile. {EMAIL_SIG} diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 97986783fe..8d91f00c5a 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -343,6 +343,7 @@ $lang = array_merge($lang, array( 'NOTIFICATION_TYPE_POST' => 'Someone replies to a topic to which you are subscribed', 'NOTIFICATION_TYPE_QUOTE' => 'Someone quotes you in a post', 'NOTIFICATION_TYPE_REPORT' => 'Someone reports a post', + 'NOTIFICATION_TYPE_REPORT_CLOSED' => 'Your report on a post is closed by a moderator', 'NOTIFICATION_TYPE_REPORT_PM' => 'Someone reports a private message', 'NOTIFICATION_TYPE_REPORT_PM_CLOSED' => 'Your report on a private message is closed by a moderator', 'NOTIFICATION_TYPE_TOPIC' => 'Someone creates a topic in a forum to which you are subscribed', diff --git a/phpBB/phpbb/notification/type/report_pm_closed.php b/phpBB/phpbb/notification/type/report_pm_closed.php index 1d281c3821..1901a3b2d5 100644 --- a/phpBB/phpbb/notification/type/report_pm_closed.php +++ b/phpBB/phpbb/notification/type/report_pm_closed.php @@ -100,8 +100,8 @@ class report_pm_closed extends \phpbb\notification\type\pm */ public function get_email_template_variables() { - $sender_data = $this->user_loader->get_user($this->get_data('from_user_id')); - $closer_data = $this->user_loader->get_user($this->get_data('closer_id')); + $sender_data = $this->user_loader->get_username($this->get_data('from_user_id'), 'username'); + $closer_data = $this->user_loader->get_username($this->get_data('closer_id'), 'username'); return [ 'AUTHOR_NAME' => htmlspecialchars_decode($sender_data['username']), diff --git a/phpBB/phpbb/notification/type/report_post_closed.php b/phpBB/phpbb/notification/type/report_post_closed.php index 165034d57e..9344aa1fb7 100644 --- a/phpBB/phpbb/notification/type/report_post_closed.php +++ b/phpBB/phpbb/notification/type/report_post_closed.php @@ -35,7 +35,7 @@ class report_post_closed extends \phpbb\notification\type\post * * @var string */ - public $email_template = ''; + public $email_template = 'report_closed'; /** * Language key used to output the text @@ -44,6 +44,18 @@ class report_post_closed extends \phpbb\notification\type\post */ protected $language_key = 'NOTIFICATION_REPORT_CLOSED'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + static public $notification_option = [ + 'id' => 'notification.type.report_post_closed', + 'lang' => 'NOTIFICATION_TYPE_REPORT_CLOSED', + 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', + ]; + /** * Inherit notification read status from post. * @@ -53,7 +65,7 @@ class report_post_closed extends \phpbb\notification\type\post public function is_available() { - return false; + return $this->auth->acl_getf_global('f_report'); } /** @@ -64,14 +76,18 @@ class report_post_closed extends \phpbb\notification\type\post * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($post, $options = []) { + $options = array_merge([ + 'ignore_users' => [], + ], $options); + if ($post['reporter'] == $this->user->data['user_id']) { - return array(); + return []; } - return array($post['reporter'] => $this->notification_manager->get_default_methods()); + return $this->check_user_notification_options([$post['reporter']], $options); } /** @@ -81,7 +97,7 @@ class report_post_closed extends \phpbb\notification\type\post */ public function get_email_template() { - return false; + return $this->email_template; } /** @@ -91,7 +107,17 @@ class report_post_closed extends \phpbb\notification\type\post */ public function get_email_template_variables() { - return array(); + $post_username = $this->get_data('post_username') ?: $this->user_loader->get_username($this->get_data('poster_id'), 'username'); + $closer_username = $this->user_loader->get_username($this->get_data('closer_id'), 'username'); + + return [ + 'AUTHOR_NAME' => htmlspecialchars_decode($post_username), + 'CLOSER_NAME' => htmlspecialchars_decode($closer_username), + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + ]; } /** @@ -101,7 +127,15 @@ class report_post_closed extends \phpbb\notification\type\post */ public function get_url() { - return ''; + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); + } + + /** + * {inheritDoc} + */ + public function get_redirect_url() + { + return $this->get_url(); } /** @@ -147,13 +181,13 @@ class report_post_closed extends \phpbb\notification\type\post */ public function users_to_query() { - return array($this->get_data('closer_id')); + return [$this->get_data('closer_id')]; } /** * {@inheritdoc} */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($post, $pre_create_data = []) { $this->set_data('closer_id', $post['closer_id']);