From 7454d5c2d526f237bf24825b80edf6c9f1750fc6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 14:33:15 -0500 Subject: [PATCH] [ticket/11103] Topic/Post in queue notification Also, bug fixes and cleanup PHPBB3-11103 --- phpBB/includes/functions_posting.php | 31 +++++- phpBB/includes/mcp/mcp_queue.php | 21 +++- phpBB/includes/notifications/service.php | 18 +++- .../notifications/type/approve_post.php | 21 +--- .../notifications/type/approve_topic.php | 20 +--- .../notifications/type/disapprove_post.php | 14 +-- .../notifications/type/disapprove_topic.php | 13 +-- phpBB/includes/notifications/type/post.php | 5 + .../notifications/type/post_in_queue.php | 97 +++++++++++++++++++ phpBB/includes/notifications/type/quote.php | 2 - phpBB/includes/notifications/type/topic.php | 4 +- .../notifications/type/topic_in_queue.php | 97 +++++++++++++++++++ phpBB/language/en/common.php | 2 + .../en/email/notifications/post_in_queue.txt | 17 ++++ .../language/en/email/notifications/quote.txt | 2 +- .../en/email/notifications/topic_in_queue.txt | 17 ++++ 16 files changed, 325 insertions(+), 56 deletions(-) create mode 100644 phpBB/includes/notifications/type/post_in_queue.php create mode 100644 phpBB/includes/notifications/type/topic_in_queue.php create mode 100644 phpBB/language/en/email/notifications/post_in_queue.txt create mode 100644 phpBB/language/en/email/notifications/topic_in_queue.txt diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6089ef0014..4dd840ad53 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2220,10 +2220,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications + $phpbb_notifications = $phpbb_container->get('notifications'); if ($post_approval) { - $phpbb_notifications = $phpbb_container->get('notifications'); - switch ($mode) { case 'post' : @@ -2258,6 +2257,34 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } } + else + { + switch ($mode) + { + case 'post' : + $phpbb_notifications->add_notifications(array('topic_in_queue'), array_merge($data, array( + 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], + ))); + break; + + case 'reply' : + case 'quote' : + $phpbb_notifications->add_notifications(array('post_in_queue'), array_merge($data, array( + 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], + ))); + break; + + case 'edit_topic' : + case 'edit_first_post' : + case 'edit' : + case 'edit_last_post' : + $phpbb_notifications->delete_notifications('topic', $data['topic_id']); + $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']); + break; + } + } $params = $add_anchor = ''; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index bd2092e4bb..1d2caa38d5 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -606,6 +606,9 @@ function approve_post($post_id_list, $id, $mode) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) { + // Delete topic in queue notifications + $phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']); + // Forum Notifications $phpbb_notifications->add_notifications('topic', $post_data); @@ -617,6 +620,9 @@ function approve_post($post_id_list, $id, $mode) } else { + // Delete post in queue notification + $phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id); + // Topic Notifications $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); @@ -847,13 +853,26 @@ function disapprove_post($post_id_list, $id, $mode) } } + // Handle notifications (topic/post in queue) + $phpbb_notifications = $phpbb_container->get('notifications'); + foreach ($post_info as $post_id => $post_data) + { + if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + { + $phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']); + } + else + { + $phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id); + } + } + // Notify Poster? if ($notify_poster) { $lang_reasons = array(); // Handle notifications - $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($post_info as $post_id => $post_data) { $post_data['disapprove_reason'] = ''; diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 6e7b160e0f..777fa9a42f 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -262,7 +262,7 @@ class phpbb_notifications_service { foreach ($item_type as $type) { - $this->add_notifications($type, $data); + $this->add_notifications_for_users($type, $data, $notify_users); } return; @@ -353,7 +353,7 @@ class phpbb_notifications_service { foreach ($item_type as $type) { - $this->add_notifications($type, $data); + $this->update_notifications($type, $data); } return; @@ -386,12 +386,22 @@ class phpbb_notifications_service /** * Delete a notification * - * @param string $item_type Type identifier + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types) * @param int|array $item_id Identifier within the type (or array of ids) * @param array $data Data specific for this type that will be updated */ public function delete_notifications($item_type, $item_id) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->delete_notifications($type, $item_id); + } + + return; + } + $this->get_item_type_class_name($item_type); $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " @@ -400,6 +410,7 @@ class phpbb_notifications_service $this->db->sql_query($sql); } +/* public function add_subscription($item_type, $item_id, $method = '') { $this->get_item_type_class_name($item_type); @@ -413,6 +424,7 @@ class phpbb_notifications_service )); $this->db->sql_query($sql); } +*/ /** * Load user helper diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index 4a310db389..b5e5cfd337 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -82,21 +82,6 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos return $notify_users; } - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - return array( - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), - - 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - ); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -109,8 +94,10 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos { $this->set_data('post_subject', $post['post_subject']); - $this->time = time(); + $data = parent::create_insert_array($post); - return parent::create_insert_array($post); + $this->time = $data['time'] = time(); + + return $data; } } diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php index 426c4e374a..3ba871599e 100644 --- a/phpBB/includes/notifications/type/approve_topic.php +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -82,20 +82,6 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to return $notify_users; } - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - return array( - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", - ); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -106,8 +92,10 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to */ public function create_insert_array($post) { - $this->time = time(); + $data = parent::create_insert_array($post); - return parent::create_insert_array($post); + $this->time = $data['time'] = time(); + + return $data; } } diff --git a/phpBB/includes/notifications/type/disapprove_post.php b/phpBB/includes/notifications/type/disapprove_post.php index 9ef32349b3..e0b7bfb178 100644 --- a/phpBB/includes/notifications/type/disapprove_post.php +++ b/phpBB/includes/notifications/type/disapprove_post.php @@ -79,10 +79,9 @@ class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_ */ public function get_email_template_variables() { - return array( - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), - 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), - ); + return array_merge(parent::get_email_template_variables(), array( + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + )); } /** @@ -95,11 +94,12 @@ class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_ */ public function create_insert_array($post) { - $this->set_data('post_subject', $post['post_subject']); $this->set_data('disapprove_reason', $post['disapprove_reason']); - $this->time = time(); + $data = parent::create_insert_array($post); - return parent::create_insert_array($post); + $this->time = $data['time'] = time(); + + return $data; } } diff --git a/phpBB/includes/notifications/type/disapprove_topic.php b/phpBB/includes/notifications/type/disapprove_topic.php index eba82d2548..7ad4c4edb8 100644 --- a/phpBB/includes/notifications/type/disapprove_topic.php +++ b/phpBB/includes/notifications/type/disapprove_topic.php @@ -79,11 +79,9 @@ class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type */ public function get_email_template_variables() { - return array( - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - + return array_merge(parent::get_email_template_variables(), array( 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), - ); + )); } /** @@ -97,8 +95,11 @@ class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type public function create_insert_array($post) { $this->set_data('disapprove_reason', $post['disapprove_reason']); - $this->time = time(); - return parent::create_insert_array($post); + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; } } diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 0ad2c4893f..8e801a2595 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -167,10 +167,13 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base public function get_email_template_variables() { return array( + '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}", 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic", ); @@ -210,6 +213,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('topic_title', $post['topic_title']); + $this->set_data('post_subject', $post['post_subject']); + $this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : '')); $this->set_data('forum_id', $post['forum_id']); diff --git a/phpBB/includes/notifications/type/post_in_queue.php b/phpBB/includes/notifications/type/post_in_queue.php new file mode 100644 index 0000000000..cd3a452856 --- /dev/null +++ b/phpBB/includes/notifications/type/post_in_queue.php @@ -0,0 +1,97 @@ +get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_approve[$post['forum_id']]['m_approve'] as $user_id) + { + $notify_users[$user_id] = array(''); + } + + return $notify_users; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index 647f81041d..d116a40e4d 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -183,8 +183,6 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post return array_merge(parent::get_email_template_variables(), array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), - - 'U_QUOTED_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", )); } } diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index cfc629430b..cf56451214 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -72,7 +72,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base * Find the users who want to receive notifications * * @param ContainerBuilder $phpbb_container - * @param array $post Data from + * @param array $topic Data from the topic * * @return array */ @@ -171,6 +171,8 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base 'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->item_parent_id}", 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum", ); diff --git a/phpBB/includes/notifications/type/topic_in_queue.php b/phpBB/includes/notifications/type/topic_in_queue.php new file mode 100644 index 0000000000..583ab5d8b3 --- /dev/null +++ b/phpBB/includes/notifications/type/topic_in_queue.php @@ -0,0 +1,97 @@ +get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_approve[$topic['forum_id']]['m_approve'] as $user_id) + { + $notify_users[$user_id] = array(''); + } + + return $notify_users; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $topic Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($topic) + { + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 4229b41fb8..90acd0854b 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -391,10 +391,12 @@ $lang = array_merge($lang, array( 'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".', 'NOTIFICATION_POST_APPROVED' => 'Your post was approved "%2$s".', 'NOTIFICATION_POST_DISAPPROVED' => 'Your post "%1$s" was disapproved because "%2$s".', + 'NOTIFICATION_POST_IN_QUEUE' => 'A new post titled "%2$s" was posted by "%1$s" and needs approval.', 'NOTIFICATION_QUOTE' => '%1$s quoted you in the post "%2$s".', 'NOTIFICATION_TOPIC' => '%1$s posted a new topic "%2$s" in the forum "%3$s".', 'NOTIFICATION_TOPIC_APPROVED' => 'Your topic "%2$s" in the forum "%3$s" was approved.', 'NOTIFICATION_TOPIC_DISAPPROVED' => 'Your topic "%1$s" was disapproved because "%2$s".', + 'NOTIFICATION_TOPIC_IN_QUEUE' => 'A new topic titled "%2$s" was posted by "%1$s" and needs approval.', 'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.', 'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: %1$s', 'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.', diff --git a/phpBB/language/en/email/notifications/post_in_queue.txt b/phpBB/language/en/email/notifications/post_in_queue.txt new file mode 100644 index 0000000000..5ce2b8fe09 --- /dev/null +++ b/phpBB/language/en/email/notifications/post_in_queue.txt @@ -0,0 +1,17 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because the post, "{POST_SUBJECT}" at "{SITENAME}" needs approval. + +If you want to view the post, click the following link: +{U_VIEW_POST} + +If you want to view the topic, click the following link: +{U_TOPIC} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} \ No newline at end of file diff --git a/phpBB/language/en/email/notifications/quote.txt b/phpBB/language/en/email/notifications/quote.txt index 96fd527c8f..8b8584a794 100644 --- a/phpBB/language/en/email/notifications/quote.txt +++ b/phpBB/language/en/email/notifications/quote.txt @@ -5,7 +5,7 @@ Hello {USERNAME}, You are receiving this notification because "{AUTHOR_NAME}" quoted you in the topic, "{TOPIC_TITLE}" at "{SITENAME}". You can use the following link to view the reply made. If you want to view the quoted post, click the following link: -{U_QUOTED_POST} +{U_VIEW_POST} If you want to view the topic, click the following link: {U_TOPIC} diff --git a/phpBB/language/en/email/notifications/topic_in_queue.txt b/phpBB/language/en/email/notifications/topic_in_queue.txt new file mode 100644 index 0000000000..17c8b15880 --- /dev/null +++ b/phpBB/language/en/email/notifications/topic_in_queue.txt @@ -0,0 +1,17 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because the topic , "{TOPIC_TITLE}" at "{SITENAME}" needs approval. + +If you want to view the topic, click the following link: +{U_VIEW_TOPIC} + +If you want to view the forum, click the following link: +{U_FORUM} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} \ No newline at end of file