diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index cb8dddd5f8..e9d673455c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1295,7 +1295,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark all topic notifications read for this user $phpbb_notifications = $phpbb_container->get('notifications'); - $phpbb_notifications->mark_notifications_read('topic', false, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read(array('topic', 'quote', 'bookmark', 'post', 'approve_topic', 'approve_post'), false, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) { @@ -1337,7 +1337,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark topic notifications read for this user in this forum $phpbb_notifications = $phpbb_container->get('notifications'); - $phpbb_notifications->mark_notifications_read_by_parent('topic', $forum_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array('topic', 'approve_topic'), $forum_id, $user->data['user_id'], $post_time); // Mark all post/quote notifications read for this user in this forum $topic_ids = array(); @@ -1351,7 +1351,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } $db->sql_freeresult($result); - $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_ids, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_ids, $user->data['user_id'], $post_time); // Add 0 to forums array to mark global announcements correctly // $forum_id[] = 0; @@ -1449,7 +1449,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark post notifications read for this user in this topic $phpbb_notifications = $phpbb_container->get('notifications'); - $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read(array('topic', 'approve_topic'), $topic_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_id, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) { diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index fc2c5a47b6..6089ef0014 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2238,6 +2238,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], + 'post_text' => $data['message'], ))); break; @@ -2252,6 +2253,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, + 'post_text' => $data['message'], ))); break; } diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index df99e34576..bd2092e4bb 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -597,39 +597,34 @@ function approve_post($post_id_list, $id, $mode) sync('forum', 'forum_id', array_keys($forum_id_list), true, true); unset($topic_id_list, $forum_id_list); - $phpbb_notifications = $phpbb_container->get('notifications'); - - // Notify Poster? - if ($notify_poster) - { - // Forum Notifications - foreach ($post_info as $post_id => $post_data) - { - if ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) - { - $phpbb_notifications->add_notifications('approve_topic', $post_data); - } - else - { - $phpbb_notifications->add_notifications('approve_post', $post_data); - } - } - } - // Send out normal user notifications $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + // Handle notifications + $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']) { // Forum Notifications $phpbb_notifications->add_notifications('topic', $post_data); + + // Notify poster? + if ($notify_poster) + { + $phpbb_notifications->add_notifications('approve_topic', $post_data); + } } else { // Topic Notifications $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); + + // Notify poster? + if ($notify_poster) + { + $phpbb_notifications->add_notifications('approve_post', $post_data); + } } } @@ -719,7 +714,7 @@ function disapprove_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request; + global $request, $phpbb_container; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -852,20 +847,16 @@ function disapprove_post($post_id_list, $id, $mode) } } - $messenger = new messenger(); - // Notify Poster? if ($notify_poster) { $lang_reasons = array(); + // Handle notifications + $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($post_info as $post_id => $post_data) { - if ($post_data['poster_id'] == ANONYMOUS) - { - continue; - } - + $post_data['disapprove_reason'] = ''; if (isset($disapprove_reason_lang)) { // Okay we need to get the reason from the posters language @@ -891,33 +882,32 @@ function disapprove_post($post_id_list, $id, $mode) } } - $email_disapprove_reason = $lang_reasons[$post_data['user_lang']]; - $email_disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; + $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']]; + $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : ''; } - $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved'; - - $messenger->template($email_template, $post_data['user_lang']); - - $messenger->to($post_data['user_email'], $post_data['username']); - $messenger->im($post_data['user_jabber'], $post_data['username']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($post_data['username']), - 'REASON' => htmlspecialchars_decode($email_disapprove_reason), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title']))) - ); - - $messenger->send($post_data['user_notify_type']); + if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + { + // Notify poster? + if ($notify_poster) + { + $phpbb_notifications->add_notifications('disapprove_topic', $post_data); + } + } + else + { + // Notify poster? + if ($notify_poster) + { + $phpbb_notifications->add_notifications('disapprove_post', $post_data); + } + } } unset($lang_reasons); } unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang); - $messenger->save_queue(); - if ($num_disapproved_topics) { $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS'; diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 7fdba5e48a..6e7b160e0f 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -69,7 +69,10 @@ class phpbb_notifications_service // Anonymous users and bots never receive notifications if ($options['user_id'] == $user->data['user_id'] && ($user->data['user_id'] == ANONYMOUS || $user->data['user_type'] == USER_IGNORE)) { - return; + return array( + 'notifications' => array(), + 'unread_count' => 0, + ); } $notifications = $user_ids = array(); @@ -273,8 +276,8 @@ class phpbb_notifications_service $notification_objects = $notification_methods = array(); $new_rows = array(); - // Never send notifications to the anonymous user or the current user! - unset($notify_users[ANONYMOUS], $notify_users[$this->phpbb_container->get('user')->data['user_id']]); + // Never send notifications to the anonymous user! + unset($notify_users[ANONYMOUS]); // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item @@ -457,7 +460,7 @@ class phpbb_notifications_service { if (!$safe) { - $item_type = preg_replace('#[^a-z]#', '', $item_type); + $item_type = preg_replace('#[^a-z_]#', '', $item_type); } return 'phpbb_notifications_type_' . $item_type; diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index 9724916a0e..4a310db389 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -37,7 +37,7 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos * * @var string */ - protected $language_key = 'NOTIFICATION_POST'; + protected $language_key = 'NOTIFICATION_POST_APPROVED'; /** * Get the type of notification this is @@ -109,6 +109,8 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos { $this->set_data('post_subject', $post['post_subject']); + $this->time = time(); + return parent::create_insert_array($post); } } diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php new file mode 100644 index 0000000000..426c4e374a --- /dev/null +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -0,0 +1,113 @@ +get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + { + $notify_users[$user_id] = $users[$user_id]; + } + + 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) + * + * @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) + { + $this->time = time(); + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 4958e27919..fb75e19cad 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -114,8 +114,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return array( 'AVATAR' => $this->get_avatar(), - 'FORMATTED_TITLE' => $this->get_formatted_title(), - 'TITLE' => $this->get_title(), + 'FORMATTED_TITLE' => $this->get_title(), 'URL' => $this->get_url(), 'TIME' => $user->format_date($this->time), @@ -201,16 +200,6 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * -------------- Fall back functions ------------------- */ - /** - * Get the formatted title of this notification (fall-back) - * - * @return string - */ - public function get_formatted_title() - { - return $this->get_title(); - } - /** * URL to unsubscribe to this notification (fall-back) * diff --git a/phpBB/includes/notifications/type/bookmark.php b/phpBB/includes/notifications/type/bookmark.php index 86a99e4ff5..9f2c2e26dc 100644 --- a/phpBB/includes/notifications/type/bookmark.php +++ b/phpBB/includes/notifications/type/bookmark.php @@ -75,6 +75,9 @@ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post } $db->sql_freeresult($result); + // Never notify the poster + unset($users[$post['poster_id']]); + if (empty($users)) { return array(); diff --git a/phpBB/includes/notifications/type/disapprove_post.php b/phpBB/includes/notifications/type/disapprove_post.php new file mode 100644 index 0000000000..9ef32349b3 --- /dev/null +++ b/phpBB/includes/notifications/type/disapprove_post.php @@ -0,0 +1,105 @@ +phpbb_container->get('user')->lang( + $this->language_key, + censor_text($this->get_data('topic_title')), + $this->get_data('disapprove_reason') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * 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'))), + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + ); + } + + /** + * 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) + { + $this->set_data('post_subject', $post['post_subject']); + $this->set_data('disapprove_reason', $post['disapprove_reason']); + + $this->time = time(); + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notifications/type/disapprove_topic.php b/phpBB/includes/notifications/type/disapprove_topic.php new file mode 100644 index 0000000000..eba82d2548 --- /dev/null +++ b/phpBB/includes/notifications/type/disapprove_topic.php @@ -0,0 +1,104 @@ +phpbb_container->get('user')->lang( + $this->language_key, + censor_text($this->get_data('topic_title')), + $this->get_data('disapprove_reason') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * 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'))), + + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + ); + } + + /** + * 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) + { + $this->set_data('disapprove_reason', $post['disapprove_reason']); + $this->time = time(); + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index a8c6e4869b..de08576a38 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -29,8 +29,6 @@ interface phpbb_notifications_type_interface public function get_title(); - public function get_formatted_title(); - public function get_email_template_variables(); public function get_url(); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 816383949b..df7b42564c 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -121,7 +121,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base * * @return string */ - public function get_formatted_title() + public function get_title() { $user_data = $this->service->get_user($this->get_data('from_user_id')); @@ -130,18 +130,6 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } - /** - * Get the plain text title of this notification - * - * @return string - */ - public function get_title() - { - $user_data = $this->service->get_user($this->get_data('from_user_id')); - - return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $user_data['username'], $this->get_data('message_subject')); - } - /** * Get email template variables * diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 13742ee78b..0ad2c4893f 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -101,6 +101,9 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } $db->sql_freeresult($result); + // Never notify the poster + unset($users[$post['poster_id']]); + if (empty($users)) { return array(); @@ -136,31 +139,6 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base * * @return string */ - public function get_formatted_title() - { - if ($this->get_data('post_username')) - { - $username = $this->get_data('post_username'); - } - else - { - $user_data = $this->service->get_user($this->get_data('poster_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - } - - return $this->phpbb_container->get('user')->lang( - $this->language_key, - $username, - censor_text($this->get_data('topic_title')) - ); - } - - /** - * Get the title of this notification - * - * @return string - */ public function get_title() { if ($this->get_data('post_username')) @@ -171,7 +149,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base { $user_data = $this->service->get_user($this->get_data('poster_id')); - $username = $user_data['username']; + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } return $this->phpbb_container->get('user')->lang( @@ -238,6 +216,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('forum_name', $post['forum_name']); + $this->time = $post['post_time']; + return parent::create_insert_array($post); } } diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index 48d63003dd..647f81041d 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -68,7 +68,7 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post $db = $phpbb_container->get('dbal.conn'); $usernames = false; - preg_match_all(self::$regular_expression_match, $post['message'], $usernames); + preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames); if (empty($usernames[1])) { @@ -94,6 +94,9 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post } $db->sql_freeresult($result); + // Never notify the poster + unset($users[$post['poster_id']]); + if (empty($users)) { return array(); diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index e31c8d792b..cfc629430b 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -32,6 +32,13 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public $email_template = 'newtopic_notify'; + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_TOPIC'; + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -94,6 +101,9 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base } $db->sql_freeresult($result); + // Never notify the poster + unset($users[$topic['poster_id']]); + if (empty($users)) { return array(); @@ -129,7 +139,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base * * @return string */ - public function get_formatted_title() + public function get_title() { if ($this->get_data('post_username')) { @@ -143,33 +153,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base } return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_TOPIC', - $username, - censor_text($this->get_data('topic_title')), - $this->get_data('forum_name') - ); - } - - /** - * Get the title of this notification - * - * @return string - */ - public function get_title() - { - if ($this->get_data('post_username')) - { - $username = $this->get_data('post_username'); - } - else - { - $user_data = $this->service->get_user($this->get_data('poster_id')); - - $username = $user_data['username']; - } - - return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_TOPIC', + $this->language_key, $username, censor_text($this->get_data('topic_title')), $this->get_data('forum_name') @@ -230,6 +214,8 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base $this->set_data('forum_name', $post['forum_name']); + $this->time = $post['post_time']; + return parent::create_insert_array($post); } } diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 3e69c6bb03..4229b41fb8 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -385,12 +385,16 @@ $lang = array_merge($lang, array( 'NOT_AUTHORISED' => 'You are not authorised to access this area.', 'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.', 'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.', - 'NOTIFICATIONS' => '[ Notifications ]', - 'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.', - 'NOTIFICATION_PM' => '%1$s sent you a Private Message "%2$s".', - 'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".', - '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".', + 'NOTIFICATIONS' => '[ Notifications ]', + 'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.', + 'NOTIFICATION_PM' => '%1$s sent you a Private Message "%2$s".', + '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_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".', '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/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index e217ceb449..87e0a2fa92 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -137,13 +137,13 @@