diff options
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/functions.php | 6 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 16 | ||||
-rw-r--r-- | phpBB/includes/mcp/mcp_queue.php | 2 | ||||
-rw-r--r-- | phpBB/includes/notifications/service.php | 60 | ||||
-rw-r--r-- | phpBB/includes/notifications/type/bookmark.php | 92 | ||||
-rw-r--r-- | phpBB/includes/notifications/type/post.php | 11 | ||||
-rw-r--r-- | phpBB/includes/notifications/type/quote.php | 66 |
7 files changed, 177 insertions, 76 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b996fef292..aec7759f19 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1351,8 +1351,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } $db->sql_freeresult($result); - $notifications->mark_notifications_read_by_parent('post', $topic_ids, $user->data['user_id'], $post_time); - $notifications->mark_notifications_read_by_parent('quote', $topic_ids, $user->data['user_id'], $post_time); + $notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_ids, $user->data['user_id'], $post_time); // Add 0 to forums array to mark global announcements correctly // $forum_id[] = 0; @@ -1450,8 +1449,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark post notifications read for this user in this topic $notifications = $phpbb_container->get('notifications'); - $notifications->mark_notifications_read_by_parent('post', $topic_id, $user->data['user_id'], $post_time); - $notifications->mark_notifications_read_by_parent('quote', $topic_id, $user->data['user_id'], $post_time); + $notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', '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 26d9b81896..56f84562f7 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2227,20 +2227,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post' : - $notifications->add_notifications('topic', array_merge($data, array( - 'post_username' => $username, - ))); - $notifications->add_notifications('quote', array_merge($data, array( + $notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( 'post_username' => $username, ))); break; case 'reply' : case 'quote' : - $notifications->add_notifications('post', array_merge($data, array( - 'post_username' => $username, - ))); - $notifications->add_notifications('quote', array_merge($data, array( + $notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; @@ -2253,10 +2247,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'post_username' => $username, 'topic_title' => $subject, ))); - $notifications->update_notifications('post', array_merge($data, array( - 'post_username' => $username, - ))); - $notifications->update_notifications('quote', array_merge($data, array( + + $notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 1d9a2dfedc..48557192d2 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -646,7 +646,7 @@ function approve_post($post_id_list, $id, $mode) else { // Topic Notifications - $notifications->add_notifications('post', $post_data); + $notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); } } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 8be8ae2a95..4933cf0f9a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -109,13 +109,23 @@ class phpbb_notifications_service /** * Mark notifications read * - * @param string $item_type item type + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) */ public function mark_notifications_read($item_type, $item_id, $user_id, $time = false) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->mark_notifications_read($type, $item_id, $user_id, $time); + } + + return; + } + $time = ($time) ?: time(); $this->get_item_type_class_name($item_type); @@ -132,13 +142,23 @@ class phpbb_notifications_service /** * Mark notifications read from a parent identifier * - * @param string $item_type item type + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) */ public function mark_notifications_read_by_parent($item_type, $item_parent_id, $user_id, $time = false) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->mark_notifications_read($type, $item_id, $user_id, $time); + } + + return; + } + $time = ($time) ?: time(); $item_type_class_name = $this->get_item_type_class_name($item_type); @@ -155,11 +175,21 @@ class phpbb_notifications_service /** * Add a notification * - * @param string $item_type Type identifier + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param array $data Data specific for this type that will be inserted */ public function add_notifications($item_type, $data) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->add_notifications($type, $data); + } + + return; + } + $item_type_class_name = $this->get_item_type_class_name($item_type); $item_id = $item_type_class_name::get_item_id($data); @@ -173,12 +203,22 @@ class phpbb_notifications_service /** * Add a notification for specific users * - * @param string $item_type Type identifier + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param array $data Data specific for this type that will be inserted * @param array $notify_users User list to notify */ public function add_notifications_for_users($item_type, $data, $notify_users) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->add_notifications($type, $data); + } + + return; + } + $item_type_class_name = $this->get_item_type_class_name($item_type); $item_id = $item_type_class_name::get_item_id($data); @@ -255,11 +295,21 @@ class phpbb_notifications_service /** * Update a notification * - * @param string $item_type Type identifier + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param array $data Data specific for this type that will be updated */ public function update_notifications($item_type, $data) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->add_notifications($type, $data); + } + + return; + } + $item_type_class_name = $this->get_item_type_class_name($item_type); // Allow the notifications class to over-ride the update_notifications functionality diff --git a/phpBB/includes/notifications/type/bookmark.php b/phpBB/includes/notifications/type/bookmark.php new file mode 100644 index 0000000000..7896703f00 --- /dev/null +++ b/phpBB/includes/notifications/type/bookmark.php @@ -0,0 +1,92 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +use Symfony\Component\DependencyInjection\ContainerBuilder; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Bookmark updating notifications class +* This class handles notifications for replies to a bookmarked topic +* +* @package notifications +*/ +class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post +{ + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_BOOKMARK'; + + /** + * Get the type of notification this is + * phpbb_notifications_type_ + */ + public static function get_item_type() + { + return 'bookmark'; + } + + /** + * Find the users who want to receive notifications + * + * @param ContainerBuilder $phpbb_container + * @param array $post Data from + * + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) + { + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + + /* todo + * find what type of notification they'd like to receive + */ + $sql = 'SELECT user_id + FROM ' . BOOKMARKS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[$row['user_id']] = array(''); + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->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; + } +} diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 324a40888d..cc72ab8b1f 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -26,6 +26,13 @@ if (!defined('IN_PHPBB')) class phpbb_notifications_type_post extends phpbb_notifications_type_base { /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_POST'; + + /** * Get the type of notification this is * phpbb_notifications_type_ */ @@ -136,7 +143,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_POST', + $this->language_key, $username, censor_text($this->get_data('topic_title')) ); @@ -161,7 +168,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_POST', + $this->language_key, $username, censor_text($this->get_data('topic_title')) ); diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index 11186f3685..86d157631d 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -18,16 +18,28 @@ if (!defined('IN_PHPBB')) } /** -* Post tagging notifications class -* This class handles notifications for tagging users in a post (ex: @EXreaction) +* Post quoting notifications class +* This class handles notifications for quoting users in a post * * @package notifications */ class phpbb_notifications_type_quote extends phpbb_notifications_type_post { + /** + * regular expression to match to find usernames + * + * @var string + */ protected static $regular_expression_match = '#\[quote="(.+?)":#'; /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_QUOTE'; + + /** * Get the type of notification this is * phpbb_notifications_type_ */ @@ -98,56 +110,6 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post } /** - * Get the HTML formatted title of this notification - * - * @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( - 'NOTIFICATION_QUOTE', - $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')) - { - $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_QUOTE', - $username, - censor_text($this->get_data('topic_title')) - ); - } - - /** * Update a notification * * @param ContainerBuilder $phpbb_container |