From 64820546d758b34720888311d0abffcf95609436 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 13:40:40 -0500 Subject: [ticket/11103] Move notification files to includes/notification/ PHPBB3-11103 --- phpBB/includes/notification/manager.php | 688 +++++++++++++++++++++ phpBB/includes/notification/method/base.php | 92 +++ phpBB/includes/notification/method/email.php | 104 ++++ phpBB/includes/notification/method/interface.php | 27 + phpBB/includes/notification/method/jabber.php | 62 ++ phpBB/includes/notification/type/approve_post.php | 132 ++++ phpBB/includes/notification/type/approve_topic.php | 130 ++++ phpBB/includes/notification/type/base.php | 345 +++++++++++ phpBB/includes/notification/type/bookmark.php | 117 ++++ .../includes/notification/type/disapprove_post.php | 116 ++++ .../notification/type/disapprove_topic.php | 116 ++++ phpBB/includes/notification/type/interface.php | 49 ++ phpBB/includes/notification/type/pm.php | 191 ++++++ phpBB/includes/notification/type/post.php | 242 ++++++++ phpBB/includes/notification/type/post_in_queue.php | 137 ++++ phpBB/includes/notification/type/quote.php | 209 +++++++ phpBB/includes/notification/type/topic.php | 237 +++++++ .../includes/notification/type/topic_in_queue.php | 137 ++++ 18 files changed, 3131 insertions(+) create mode 100644 phpBB/includes/notification/manager.php create mode 100644 phpBB/includes/notification/method/base.php create mode 100644 phpBB/includes/notification/method/email.php create mode 100644 phpBB/includes/notification/method/interface.php create mode 100644 phpBB/includes/notification/method/jabber.php create mode 100644 phpBB/includes/notification/type/approve_post.php create mode 100644 phpBB/includes/notification/type/approve_topic.php create mode 100644 phpBB/includes/notification/type/base.php create mode 100644 phpBB/includes/notification/type/bookmark.php create mode 100644 phpBB/includes/notification/type/disapprove_post.php create mode 100644 phpBB/includes/notification/type/disapprove_topic.php create mode 100644 phpBB/includes/notification/type/interface.php create mode 100644 phpBB/includes/notification/type/pm.php create mode 100644 phpBB/includes/notification/type/post.php create mode 100644 phpBB/includes/notification/type/post_in_queue.php create mode 100644 phpBB/includes/notification/type/quote.php create mode 100644 phpBB/includes/notification/type/topic.php create mode 100644 phpBB/includes/notification/type/topic_in_queue.php (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php new file mode 100644 index 0000000000..15db3f89fd --- /dev/null +++ b/phpBB/includes/notification/manager.php @@ -0,0 +1,688 @@ +phpbb_container = $phpbb_container; + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + } + + /** + * Load the user's notifications + * + * @param array $options Optional options to control what notifications are loaded + * notification_id Notification id to load (or array of notification ids) + * user_id User id to load notifications for (Default: $user->data['user_id']) + * order_by Order by (Default: time) + * order_dir Order direction (Default: DESC) + * limit Number of notifications to load (Default: 5) + * start Notifications offset (Default: 0) + * all_unread Load all unread messages? If set to true, count_unread is set to true (Default: false) + * count_unread Count all unread messages? (Default: false) + */ + public function load_notifications($options = array()) + { + $user = $this->phpbb_container->get('user'); + + // Merge default options + $options = array_merge(array( + 'notification_id' => false, + 'user_id' => $user->data['user_id'], + 'order_by' => 'time', + 'order_dir' => 'DESC', + 'limit' => 0, + 'start' => 0, + 'all_unread' => false, + 'count_unread' => false, + ), $options); + + // If all_unread, count_unread mus be true + $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; + + // 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 array( + 'notifications' => array(), + 'unread_count' => 0, + ); + } + + $notifications = $user_ids = array(); + $load_special = array(); + $count = 0; + + if ($options['count_unread']) + { + // Get the total number of unread notifications + $sql = 'SELECT COUNT(*) AS count + FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id'] . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + $count = (int) $this->db->sql_fetchfield('count', $result); + $this->db->sql_freeresult($result); + } + + $rowset = array(); + + // Get the main notifications + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id'] . + (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . ' + ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); + $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); + + while ($row = $this->db->sql_fetchrow($result)) + { + $rowset[$row['notification_id']] = $row; + } + $this->db->sql_freeresult($result); + + // Get all unread notifications + if ($count && $options['all_unread'] && !empty($rowset)) + { + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id'] . ' + AND unread = 1 + AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' + ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); + $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); + + while ($row = $this->db->sql_fetchrow($result)) + { + $rowset[$row['notification_id']] = $row; + } + $this->db->sql_freeresult($result); + } + + foreach ($rowset as $row) + { + $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); + + $notification = new $item_type_class_name($this->phpbb_container, $row); + + // Array of user_ids to query all at once + $user_ids = array_merge($user_ids, $notification->users_to_query()); + + // Some notification types also require querying additional tables themselves + if (!isset($load_special[$row['item_type']])) + { + $load_special[$row['item_type']] = array(); + } + $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); + + $notifications[] = $notification; + } + + $this->load_users($user_ids); + + // Allow each type to load it's own special items + foreach ($load_special as $item_type => $data) + { + $item_type_class_name = $this->get_item_type_class_name($item_type, true); + + $item_type_class_name::load_special($this->phpbb_container, $data, $notifications); + } + + return array( + 'notifications' => $notifications, + 'unread_count' => $count, + ); + } + + /** + * Mark notifications read + * + * @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); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET unread = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND time <= " . $time . + (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . + (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); + $this->db->sql_query($sql); + } + + /** + * Mark notifications read from a parent 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 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_by_parent($type, $item_parent_id, $user_id, $time); + } + + return; + } + + $time = ($time) ?: time(); + + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET unread = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND time <= " . $time . + (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . + (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); + $this->db->sql_query($sql); + } + + /** + * Mark notifications read + * + * @param int|array $notification_id Notification id or array of notification 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_id($notification_id, $time = false) + { + $time = ($time) ?: time(); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET unread = 0 + WHERE time <= " . $time . ' + AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); + $this->db->sql_query($sql); + } + + /** + * Add a notification + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive + * a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array + * @param array $data Data specific for this type that will be inserted + */ + public function add_notifications($item_type, $data, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + if (is_array($item_type)) + { + $notified_users = array(); + $temp_options = $options; + + foreach ($item_type as $type) + { + $temp_options['ignore_users'] = $options['ignore_users'] + $notified_users; + $notified_users += $this->add_notifications($type, $data, $temp_options); + } + + return $notified_users; + } + + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $item_id = $item_type_class_name::get_item_id($data); + + // find out which users want to receive this type of notification + $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data, $options); + + $this->add_notifications_for_users($item_type, $data, $notify_users); + + return $notify_users; + } + + /** + * Add a notification for specific users + * + * @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_for_users($type, $data, $notify_users); + } + + return; + } + + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $item_id = $item_type_class_name::get_item_id($data); + + $user_ids = array(); + $notification_objects = $notification_methods = array(); + $new_rows = array(); + + // 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 + // todo Users should not receive notifications from multiple events from the same item (ex: for a topic reply with a quote including your username) + // Probably should be handled within each type? + $sql = 'SELECT user_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + unset($notify_users[$row['user_id']]); + } + $this->db->sql_freeresult($result); + + if (!sizeof($notify_users)) + { + return; + } + + // Go through each user so we can insert a row in the DB and then notify them by their desired means + foreach ($notify_users as $user => $methods) + { + $notification = new $item_type_class_name($this->phpbb_container); + + $notification->user_id = (int) $user; + + // Store the creation array in our new rows that will be inserted later + $new_rows[] = $notification->create_insert_array($data); + + // Users are needed to send notifications + $user_ids = array_merge($user_ids, $notification->users_to_query()); + + foreach ($methods as $method) + { + // setup the notification methods and add the notification to the queue + if ($method) // blank means we just insert it as a notification, but do not notify them by any other means + { + if (!isset($notification_methods[$method])) + { + $method_class_name = 'phpbb_notification_method_' . $method; + $notification_methods[$method] = new $method_class_name($this->phpbb_container); + } + + $notification_methods[$method]->add_to_queue($notification); + } + } + } + + // insert into the db + $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); + + // We need to load all of the users to send notifications + $this->load_users($user_ids); + + // run the queue for each method to send notifications + foreach ($notification_methods as $method) + { + $method->notify(); + } + } + + /** + * Update a notification + * + * @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->update_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 + if (method_exists($item_type_class_name, 'update_notifications')) + { + // Return False to over-ride the rest of the update + if ($item_type_class_name::update_notifications($this->phpbb_container, $data) === false) + { + return; + } + } + + $item_id = $item_type_class_name::get_item_id($data); + + $notification = new $item_type_class_name($this->phpbb_container); + $update_array = $notification->create_update_array($data); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; + $this->db->sql_query($sql); + } + + /** + * Delete a notification + * + * @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 . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id); + $this->db->sql_query($sql); + } + + /** + * Get all of the subscription types + * + * @return array Array of item types + */ + public function get_subscription_types() + { + $subscription_types = array(); + + foreach ($this->get_subscription_files('notifications/type/') as $class => $file) + { + $class = $this->get_item_type_class_name($class); + + if (!class_exists($class)) + { + include($file); + } + + if ($class::is_available($this->phpbb_container) && method_exists($class, 'get_item_type')) + { + if ($class::$notification_option === false) + { + $subscription_types[$class::get_item_type()] = $class::get_item_type(); + } + else + { + $subscription_types[$class::$notification_option['id']] = $class::$notification_option; + } + } + } + + return $subscription_types; + } + + /** + * Get all of the subscription methods + * + * @return array Array of methods + */ + public function get_subscription_methods() + { + $subscription_methods = array(); + + foreach ($this->get_subscription_files('notifications/method/') as $method_name => $file) + { + $class_name = 'phpbb_notification_method_' . $method_name; + + if (!class_exists($class_name)) + { + include($file); + } + + $method = new $class_name($this->phpbb_container); + + if ($method->is_available()) + { + $subscription_methods[] = $method_name; + } + } + + return $subscription_methods; + } + + /** + * Get subscriptions + * + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + * @param bool $only_global True to select only global subscription options (item_id = 0) + * + * @return array Subscriptions + */ + public function get_subscriptions($user_id = false, $only_global = false) + { + $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + + $subscriptions = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $user_id . + (($only_global) ? ' AND item_id = 0' : ''); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if ($only_global) + { + if (!isset($subscriptions[$row['item_type']])) + { + $subscriptions[$row['item_type']] = array(); + } + + $subscriptions[$row['item_type']][] = $row['method']; + } + else + { + $subscriptions[] = $row; + } + } + $this->db->sql_freeresult($result); + + return $subscriptions; + } + + /** + * Add a subscription + * + * @param string $item_type Type identifier of the subscription + * @param int $item_id The id of the item + * @param string $method The method of the notification e.g. '', 'email', or 'jabber' + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + */ + public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false) + { + $this->get_item_type_class_name($item_type); + + $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + + $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => (int) $user_id, + 'method' => $method, + )); + $this->db->sql_query($sql); + } + + /** + * Delete a subscription + * + * @param string $item_type Type identifier of the subscription + * @param int $item_id The id of the item + * @param string $method The method of the notification e.g. '', 'email', or 'jabber' + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + */ + public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false) + { + $this->get_item_type_class_name($item_type); + + $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + + $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; + $this->db->sql_query($sql); + } + + /** + * Load user helper + * + * @param array $user_ids + */ + public function load_users($user_ids) + { + $user_ids[] = ANONYMOUS; + + // Load the users + $user_ids = array_unique($user_ids); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + } + } + + /** + * Get a user row from our users cache + * + * @param int $user_id + * @return array + */ + public function get_user($user_id) + { + return (isset($this->users[$user_id])) ? $this->users[$user_id] : $this->users[ANONYMOUS]; + } + + /** + * Helper to get the notifications item type class name and clean it if unsafe + */ + private function get_item_type_class_name(&$item_type, $safe = false) + { + if (!$safe) + { + $item_type = preg_replace('#[^a-z_]#', '', $item_type); + } + + return 'phpbb_notification_type_' . $item_type; + } + + /** + * Helper to get subscription related files with the finder + */ + private function get_subscription_files($path) + { + $ext_manager = $this->phpbb_container->get('ext.manager'); + $php_ext = $this->phpbb_container->getParameter('core.php_ext'); + + $finder = $ext_manager->get_finder(); + + $subscription_files = array(); + + $files = $finder + ->core_path('includes/' . $path) + ->extension_directory($path) + ->get_files(); + foreach ($files as $file) + { + $class = substr($file, strrpos($file, '/')); + $class = substr($class, 1, (strpos($class, '.' . $php_ext) - 1)); + + if ($class == 'interface' || $class == 'base') + { + continue; + } + + $subscription_files[$class] = $file; + } + + return $subscription_files; + } +} diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php new file mode 100644 index 0000000000..b502d3afd0 --- /dev/null +++ b/phpBB/includes/notification/method/base.php @@ -0,0 +1,92 @@ +phpbb_container = $phpbb_container; + + // Service + $this->service = $phpbb_container->get('notifications'); + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + $this->user = $phpbb_container->get('user'); + + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); + $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + } + + /** + * Add a notification to the queue + * + * @param phpbb_notification_type_interface $notification + */ + public function add_to_queue(phpbb_notification_type_interface $notification) + { + $this->queue[] = $notification; + } + + /** + * Empty the queue + */ + protected function empty_queue() + { + $this->queue = array(); + } +} diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php new file mode 100644 index 0000000000..1b6b44d137 --- /dev/null +++ b/phpBB/includes/notification/method/email.php @@ -0,0 +1,104 @@ +queue)) + { + return; + } + + // Load all users we want to notify (we need their email address) + $user_ids = $users = array(); + foreach ($this->queue as $notification) + { + $user_ids[] = $notification->user_id; + } + + // We do not send emails to banned users + if (!function_exists('phpbb_get_banned_user_ids')) + { + include($this->phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $this->phpbb_container->getParameter('core.php_ext')); + } + $banned_users = phpbb_get_banned_user_ids($user_ids); + + // Load all the users we need + $this->service->load_users($user_ids); + + // Load the messenger + if (!class_exists('messenger')) + { + include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); + } + $messenger = new messenger(); + $board_url = generate_board_url(); + + // Time to go through the queue and send emails + foreach ($this->queue as $notification) + { + $user = $this->service->get_user($notification->user_id); + + if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) + { + continue; + } + + $messenger->template($notification->email_template, $user['user_lang']); + + $messenger->to($user['user_email'], $user['username']); + + $messenger->assign_vars(array_merge(array( + 'USERNAME' => $user['username'], + + 'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications', + ), $notification->get_email_template_variables())); + + $messenger->send($this->notify_method); + } + + // Save the queue in the messenger class (has to be called or these emails could be lost?) + $messenger->save_queue(); + + // We're done, empty the queue + $this->empty_queue(); + } +} diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/includes/notification/method/interface.php new file mode 100644 index 0000000000..4b990ec9fa --- /dev/null +++ b/phpBB/includes/notification/method/interface.php @@ -0,0 +1,27 @@ +global_available() && $this->phpbb_container->get('user')->data['jabber']); + } + + /** + * Is this method available at all? + * This is checked before notifications are sent + */ + public function global_available() + { + $config = $this->phpbb_container->get('config'); + + return ($config['jab_enable'] && @extension_loaded('xml')); + } + + public function notify() + { + if (!$this->global_available()) + { + return; + } + + return parent::notify(); + } +} diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php new file mode 100644 index 0000000000..9a3def6217 --- /dev/null +++ b/phpBB/includes/notification/type/approve_post.php @@ -0,0 +1,132 @@ + 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'approve_post'; + } + + /** + * 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, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + $users[$post['poster_id']] = 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(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + 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) + { + $this->set_data('post_subject', $post['post_subject']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php new file mode 100644 index 0000000000..00af312018 --- /dev/null +++ b/phpBB/includes/notification/type/approve_topic.php @@ -0,0 +1,130 @@ + 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'approve_topic'; + } + + /** + * 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, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + $users[$post['poster_id']] = 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(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + 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/notification/type/base.php b/phpBB/includes/notification/type/base.php new file mode 100644 index 0000000000..40462bccfb --- /dev/null +++ b/phpBB/includes/notification/type/base.php @@ -0,0 +1,345 @@ + forum_id, for post => topic_id, etc) + * user_id + * unread + * + * time + * data (special serialized field that each notification type can use to store stuff) + * + * @var array $data Notification row from the database + * This must be private, all interaction should use __get(), __set(), get_data(), set_data() + */ + private $data = array(); + + public function __construct(ContainerBuilder $phpbb_container, $data = array()) + { + // phpBB Container + $this->phpbb_container = $phpbb_container; + + // Service + $this->service = $phpbb_container->get('notifications'); + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); + $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + + // The row from the database (unless this is a new notification we're going to add) + $this->data = $data; + $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); + } + + public function __get($name) + { + return $this->data[$name]; + } + + public function __set($name, $value) + { + $this->data[$name] = $value; + } + + /** + * Get special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to get + * + * @return mixed + */ + protected function get_data($name) + { + return (isset($this->data['data'][$name])) ? $this->data['data'][$name] : null; + } + + /** + * Set special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to set + * @param mixed $value Value to set to the variable + */ + protected function set_data($name, $value) + { + $this->data['data'][$name] = $value; + } + + /** + * Prepare to output the notification to the template + */ + public function prepare_for_display() + { + $user = $this->phpbb_container->get('user'); + + return array( + 'AVATAR' => $this->get_avatar(), + + 'FORMATTED_TITLE' => $this->get_title(), + + 'URL' => $this->get_url(), + 'TIME' => $user->format_date($this->time), + + 'UNREAD' => $this->unread, + + 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification[]=' . $this->notification_id), + ); + } + + /** + * Mark this item read + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_read($return = true) + { + return $this->mark(false, $return); + } + + /** + * Mark this item unread + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_unread($return = true) + { + return $this->mark(true, $return); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $type_data Data unique to this notification type + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($type_data) + { + // Defaults + $this->data = array_merge(array( + 'item_id' => static::get_item_id($type_data), + 'item_type' => $this->get_item_type(), + 'item_parent_id' => static::get_item_parent_id($type_data), + + 'time' => time(), + 'unread' => true, + + 'data' => array(), + ), $this->data); + + $data = $this->data; + + $data['data'] = serialize($data['data']); + + return $data; + } + + /** + * Function for preparing the data for update in an SQL query + * (The service handles insertion) + * + * @param array $type_data Data unique to this notification type + * + * @return array Array of data ready to be updated in the database + */ + public function create_update_array($type_data) + { + $data = $this->create_insert_array($type_data); + + // Unset data unique to each row + unset( + $data['notification_id'], + $data['unread'], + $data['user_id'] + ); + + return $data; + } + + /** + * -------------- Fall back functions ------------------- + */ + + /** + * URL to unsubscribe to this notification (fall-back) + * + * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item + */ + public function get_unsubscribe_url($method = false) + { + return false; + } + + /** + * Get the user's avatar (fall-back) + */ + public function get_avatar() + { + return ''; + } + + /** + * Get the special items to load (fall-back) + */ + public function get_load_special() + { + return array(); + } + + /** + * Load the special items (fall-back) + */ + public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) + { + return; + } + + /** + * Is available (fall-back) + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + return true; + } + + /** + * -------------- Helper functions ------------------- + */ + + /** + * Find the users who want to receive notifications (helper) + * + * @param ContainerBuilder $phpbb_container + * @param array $item_id The item_id to search for + * + * @return array + */ + protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id, $options) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $rowset = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . static::get_item_type() . "' + AND item_id = " . (int) $item_id; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $rowset[$row['user_id']] = array(); + } + + $rowset[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $rowset; + } + + /** + * Get avatar helper + * + * @param int $user_id + * @return string + */ + protected function _get_avatar($user_id) + { + $user = $this->service->get_user($user_id); + + if (!function_exists('get_user_avatar')) + { + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); + } + + return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar'); + } + + /** + * Mark this item read/unread helper + * + * @param bool $unread Unread (True/False) (Default: False) + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + protected function mark($unread = true, $return = false) + { + $where = array( + 'item_type = ' . $this->db->sql_escape($this->item_type), + 'item_id = ' . (int) $this->item_id, + 'user_id = ' . (int) $this->user_id, + ); + $where = implode(' AND ' . $where); + + if ($return) + { + return $where; + } + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET unread = ' . (bool) $unread . ' + WHERE ' . $where; + $this->db->sql_query($sql); + } +} diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php new file mode 100644 index 0000000000..51f23bc294 --- /dev/null +++ b/phpBB/includes/notification/type/bookmark.php @@ -0,0 +1,117 @@ + array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . BOOKMARKS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']) . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } +} diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php new file mode 100644 index 0000000000..8fa0102e3d --- /dev/null +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -0,0 +1,116 @@ + 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'disapprove_post'; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + return $this->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_merge(parent::get_email_template_variables(), array( + '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']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php new file mode 100644 index 0000000000..186c42d2b6 --- /dev/null +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -0,0 +1,116 @@ + 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'disapprove_topic'; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + return $this->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_merge(parent::get_email_template_variables(), array( + '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']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php new file mode 100644 index 0000000000..aa54c62a97 --- /dev/null +++ b/phpBB/includes/notification/type/interface.php @@ -0,0 +1,49 @@ + array(), + ), $options); + + $service = $phpbb_container->get('notifications'); + $db = $phpbb_container->get('dbal.conn'); + $user = $phpbb_container->get('user'); + + if (!sizeof($pm['recipients'])) + { + return array(); + } + + $service->load_users(array_keys($pm['recipients'])); + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', array_keys($pm['recipients'])); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('from_user_id')); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->service->get_user($this->get_data('from_user_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_PM', $username, $this->get_data('message_subject')); + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $user_data = $this->service->get_user($this->get_data('from_user_id')); + + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), + + 'U_VIEW_MESSAGE' => generate_board_url() . '/ucp.' . $this->php_ext . "?i=pm&mode=view&p={$this->item_id}", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['from_user_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($pm) + { + $this->set_data('from_user_id', $pm['from_user_id']); + + $this->set_data('message_subject', $pm['message_subject']); + + return parent::create_insert_array($pm); + } +} diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php new file mode 100644 index 0000000000..1e654ef51b --- /dev/null +++ b/phpBB/includes/notification/type/post.php @@ -0,0 +1,242 @@ + array(), + ), $options); + + // Let's continue to use the phpBB subscriptions system, at least for now. + // It may not be the nicest thing, but it is already working and it would be significant work to replace it + //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND notify_status = ' . NOTIFY_YES . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('poster_id')); + } + + /** + * Get the HTML formatted 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 = 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 email template variables + * + * @return array + */ + 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", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['poster_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->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_subject', $post['post_subject']); + + $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); + + $this->set_data('forum_id', $post['forum_id']); + + $this->set_data('forum_name', $post['forum_name']); + + $this->time = $post['post_time']; + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php new file mode 100644 index 0000000000..f0a5e0baec --- /dev/null +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -0,0 +1,137 @@ + 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'post_in_queue'; + } + + /** + * Is available + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + + return (!empty($m_approve)); + } + + /** + * Find the users who want to receive notifications + * + * @param ContainerBuilder $phpbb_container + * @param array $post Data from the post + * + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + 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/notification/type/quote.php b/phpBB/includes/notification/type/quote.php new file mode 100644 index 0000000000..dd3cbedee2 --- /dev/null +++ b/phpBB/includes/notification/type/quote.php @@ -0,0 +1,209 @@ + array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $usernames = false; + preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames); + + if (empty($usernames[1])) + { + return array(); + } + + $usernames[1] = array_unique($usernames[1]); + + $usernames = array_map('utf8_clean_string', $usernames[1]); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('username_clean', $usernames) . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Update a notification + * + * @param ContainerBuilder $phpbb_container + * @param array $data Data specific for this type that will be updated + */ + public static function update_notifications(ContainerBuilder $phpbb_container, $post) + { + $service = $phpbb_container->get('notifications'); + $db = $phpbb_container->get('dbal.conn'); + + $old_notifications = array(); + $sql = 'SELECT user_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_id = " . self::get_item_id($post); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $old_notifications[] = $row['user_id']; + } + $db->sql_freeresult($result); + + // Find the new users to notify + $notifications = self::find_users_for_notification($phpbb_container, $post); + + // Find the notifications we must delete + $remove_notifications = array_diff($old_notifications, array_keys($notifications)); + + // Find the notifications we must add + $add_notifications = array(); + foreach (array_diff(array_keys($notifications), $old_notifications) as $user_id) + { + $add_notifications[$user_id] = $notifications[$user_id]; + } + + // todo Adding notifications while editing a post can be funky. + // If the user has read the topic/post already, and the user is newly quoted it an edit, + // The notification will be stuck as unread until another post is made and the user visits + // the topic again because the posts will not be marked as read since the topic is already + // marked as read + + // Add the necessary notifications + $service->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); + + // Remove the necessary notifications + if (!empty($remove_notifications)) + { + $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_id = " . self::get_item_id($post) . ' + AND ' . $db->sql_in_set('user_id', $remove_notifications); + $db->sql_query($sql); + } + + // return true to continue with the update code in the notifications service (this will update the rest of the notifications) + return true; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + return array_merge(parent::get_email_template_variables(), array( + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + )); + } +} diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php new file mode 100644 index 0000000000..7753b196e8 --- /dev/null +++ b/phpBB/includes/notification/type/topic.php @@ -0,0 +1,237 @@ + array(), + ), $options); + + // Let's continue to use the phpBB subscriptions system, at least for now. + // It may not be the nicest thing, but it is already working and it would be significant work to replace it + //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . FORUMS_WATCH_TABLE . ' + WHERE forum_id = ' . (int) $topic['forum_id'] . ' + AND notify_status = ' . NOTIFY_YES . ' + AND user_id <> ' . (int) $topic['poster_id']; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $topic['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('poster_id')); + } + + /** + * Get the HTML formatted 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 = 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')), + $this->get_data('forum_name') + ); + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array( + '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", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->item_parent_id}&t={$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['poster_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->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); + + $this->set_data('forum_name', $post['forum_name']); + + $this->time = $post['post_time']; + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php new file mode 100644 index 0000000000..385578cec8 --- /dev/null +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -0,0 +1,137 @@ + 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + ); + + /** + * Is available + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + + return (!empty($m_approve)); + } + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'topic_in_queue'; + } + + /** + * Find the users who want to receive notifications + * + * @param ContainerBuilder $phpbb_container + * @param array $topic Data from the topic + * + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + 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($topic); + + $this->time = $data['time'] = time(); + + return $data; + } +} -- cgit v1.2.1 From cea94d89848a806f449610ddb2a7df7b7eec1328 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 14:27:43 -0500 Subject: [ticket/11103] Use dependency injection instead of phpbb_container PHPBB3-11103 --- phpBB/includes/notification/manager.php | 93 ++++++++++++++-------- phpBB/includes/notification/method/base.php | 30 +++---- phpBB/includes/notification/method/email.php | 6 +- phpBB/includes/notification/method/jabber.php | 6 +- phpBB/includes/notification/type/approve_post.php | 15 ++-- phpBB/includes/notification/type/approve_topic.php | 15 ++-- phpBB/includes/notification/type/base.php | 60 +++++++------- phpBB/includes/notification/type/bookmark.php | 23 +++--- .../includes/notification/type/disapprove_post.php | 2 +- .../notification/type/disapprove_topic.php | 2 +- phpBB/includes/notification/type/interface.php | 6 +- phpBB/includes/notification/type/pm.php | 23 +++--- phpBB/includes/notification/type/post.php | 25 +++--- phpBB/includes/notification/type/post_in_queue.php | 19 ++--- phpBB/includes/notification/type/quote.php | 43 +++++----- phpBB/includes/notification/type/topic.php | 25 +++--- .../includes/notification/type/topic_in_queue.php | 19 ++--- 17 files changed, 195 insertions(+), 217 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 15db3f89fd..e2c6c9d0f4 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -23,8 +23,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_manager { - protected $phpbb_container; - protected $db; + protected $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; /** * Users loaded from the DB @@ -33,12 +32,17 @@ class phpbb_notification_manager */ protected $users = array(); - public function __construct(ContainerBuilder $phpbb_container) + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - $this->phpbb_container = $phpbb_container; - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); + $this->db = $db; + $this->cache = $cache; + $this->template = $template; + $this->extension_manager = $extension_manager; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; } /** @@ -56,12 +60,10 @@ class phpbb_notification_manager */ public function load_notifications($options = array()) { - $user = $this->phpbb_container->get('user'); - // Merge default options $options = array_merge(array( 'notification_id' => false, - 'user_id' => $user->data['user_id'], + 'user_id' => $this->user->data['user_id'], 'order_by' => 'time', 'order_dir' => 'DESC', 'limit' => 0, @@ -74,7 +76,7 @@ class phpbb_notification_manager $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; // 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)) + if ($options['user_id'] == $this->user->data['user_id'] && ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['user_type'] == USER_IGNORE)) { return array( 'notifications' => array(), @@ -136,7 +138,7 @@ class phpbb_notification_manager { $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); - $notification = new $item_type_class_name($this->phpbb_container, $row); + $notification = $this->get_item_type_class($item_type_class_name, $row); // Array of user_ids to query all at once $user_ids = array_merge($user_ids, $notification->users_to_query()); @@ -153,12 +155,14 @@ class phpbb_notification_manager $this->load_users($user_ids); - // Allow each type to load it's own special items + // Allow each type to load its own special items foreach ($load_special as $item_type => $data) { $item_type_class_name = $this->get_item_type_class_name($item_type, true); - $item_type_class_name::load_special($this->phpbb_container, $data, $notifications); + $item_class = $this->get_item_type_class($item_type_class_name); + + $item_class->load_special($data, $notifications); } return array( @@ -283,7 +287,7 @@ class phpbb_notification_manager $item_id = $item_type_class_name::get_item_id($data); // find out which users want to receive this type of notification - $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data, $options); + $notify_users = $this->get_item_type_class($item_type_class_name)->find_users_for_notification($data, $options); $this->add_notifications_for_users($item_type, $data, $notify_users); @@ -343,7 +347,7 @@ class phpbb_notification_manager // Go through each user so we can insert a row in the DB and then notify them by their desired means foreach ($notify_users as $user => $methods) { - $notification = new $item_type_class_name($this->phpbb_container); + $notification = $this->get_item_type_class($item_type_class_name); $notification->user_id = (int) $user; @@ -361,7 +365,7 @@ class phpbb_notification_manager if (!isset($notification_methods[$method])) { $method_class_name = 'phpbb_notification_method_' . $method; - $notification_methods[$method] = new $method_class_name($this->phpbb_container); + $notification_methods[$method] = $this->get_method_class($method_class_name); } $notification_methods[$method]->add_to_queue($notification); @@ -406,7 +410,7 @@ class phpbb_notification_manager if (method_exists($item_type_class_name, 'update_notifications')) { // Return False to over-ride the rest of the update - if ($item_type_class_name::update_notifications($this->phpbb_container, $data) === false) + if ($this->get_item_type_class($item_type_class_name)->update_notifications($data) === false) { return; } @@ -414,7 +418,7 @@ class phpbb_notification_manager $item_id = $item_type_class_name::get_item_id($data); - $notification = new $item_type_class_name($this->phpbb_container); + $notification = $this->get_item_type_class($item_type_class_name); $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' @@ -460,24 +464,26 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->get_subscription_files('notifications/type/') as $class => $file) + foreach ($this->get_subscription_files('notifications/type/') as $class_name => $file) { - $class = $this->get_item_type_class_name($class); + $class_name = $this->get_item_type_class_name($class_name); - if (!class_exists($class)) + if (!class_exists($class_name)) { include($file); } - if ($class::is_available($this->phpbb_container) && method_exists($class, 'get_item_type')) + $class = $this->get_item_type_class($class_name); + + if ($class->is_available() && method_exists($class_name, 'get_item_type')) { - if ($class::$notification_option === false) + if ($class_name::$notification_option === false) { - $subscription_types[$class::get_item_type()] = $class::get_item_type(); + $subscription_types[$class_name::get_item_type()] = $class_name::get_item_type(); } else { - $subscription_types[$class::$notification_option['id']] = $class::$notification_option; + $subscription_types[$class_name::$notification_option['id']] = $class_name::$notification_option; } } } @@ -503,7 +509,7 @@ class phpbb_notification_manager include($file); } - $method = new $class_name($this->phpbb_container); + $method = $this->get_method_class($class_name); if ($method->is_available()) { @@ -524,7 +530,7 @@ class phpbb_notification_manager */ public function get_subscriptions($user_id = false, $only_global = false) { - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $subscriptions = array(); @@ -566,7 +572,7 @@ class phpbb_notification_manager { $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( @@ -590,7 +596,7 @@ class phpbb_notification_manager { $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' @@ -654,15 +660,32 @@ class phpbb_notification_manager return 'phpbb_notification_type_' . $item_type; } + /** + * Helper to get the notifications item type class and set it up + */ + private function get_item_type_class($item_type, $data = array()) + { + $item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); + + $item->set_initial_data($data); + + return $item; + } + + /** + * Helper to get the notifications method class and set it up + */ + private function get_method_class($method_name) + { + return new $method_name($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); + } + /** * Helper to get subscription related files with the finder */ private function get_subscription_files($path) { - $ext_manager = $this->phpbb_container->get('ext.manager'); - $php_ext = $this->phpbb_container->getParameter('core.php_ext'); - - $finder = $ext_manager->get_finder(); + $finder = $this->extension_manager->get_finder(); $subscription_files = array(); @@ -673,7 +696,7 @@ class phpbb_notification_manager foreach ($files as $file) { $class = substr($file, strrpos($file, '/')); - $class = substr($class, 1, (strpos($class, '.' . $php_ext) - 1)); + $class = substr($class, 1, (strpos($class, '.' . $this->php_ext) - 1)); if ($class == 'interface' || $class == 'base') { diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index b502d3afd0..ced85e2582 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -23,12 +23,7 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_method_base implements phpbb_notification_method_interface { - protected $phpbb_container; - protected $service; - protected $db; - protected $user; - protected $phpbb_root_path; - protected $php_ext; + protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; /** * Desired notifications @@ -56,20 +51,17 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(ContainerBuilder $phpbb_container) + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - // phpBB Container - $this->phpbb_container = $phpbb_container; - - // Service - $this->service = $phpbb_container->get('notifications'); - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); - $this->user = $phpbb_container->get('user'); - - $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); - $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + $this->db = $db; + $this->cache = $cache; + $this->template = $template; + $this->extension_manager = $extension_manager; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; } /** diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index 1b6b44d137..c2e272aca1 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -57,12 +57,12 @@ class phpbb_notification_method_email extends phpbb_notification_method_base // We do not send emails to banned users if (!function_exists('phpbb_get_banned_user_ids')) { - include($this->phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $this->phpbb_container->getParameter('core.php_ext')); + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); } $banned_users = phpbb_get_banned_user_ids($user_ids); // Load all the users we need - $this->service->load_users($user_ids); + $this->notification_manager->load_users($user_ids); // Load the messenger if (!class_exists('messenger')) @@ -75,7 +75,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base // Time to go through the queue and send emails foreach ($this->queue as $notification) { - $user = $this->service->get_user($notification->user_id); + $user = $this->notification_manager->get_user($notification->user_id); if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) { diff --git a/phpBB/includes/notification/method/jabber.php b/phpBB/includes/notification/method/jabber.php index 9232d8fc45..664e387d61 100644 --- a/phpBB/includes/notification/method/jabber.php +++ b/phpBB/includes/notification/method/jabber.php @@ -36,7 +36,7 @@ class phpbb_notification_method_jabber extends phpbb_notification_method_email */ public function is_available() { - return ($this->global_available() && $this->phpbb_container->get('user')->data['jabber']); + return ($this->global_available() && $this->user->data['jabber']); } /** @@ -45,9 +45,7 @@ class phpbb_notification_method_jabber extends phpbb_notification_method_email */ public function global_available() { - $config = $this->phpbb_container->get('config'); - - return ($config['jab_enable'] && @extension_loaded('xml')); + return ($this->config['jab_enable'] && @extension_loaded('xml')); } public function notify() diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 9a3def6217..3a88d9f54a 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -62,23 +62,20 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post /** * 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, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -90,9 +87,9 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -106,7 +103,7 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 00af312018..0a6ca14a84 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -62,23 +62,20 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi /** * 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, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -90,9 +87,9 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -106,7 +103,7 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 40462bccfb..626fe821e6 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -23,11 +23,7 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_type_base implements phpbb_notification_type_interface { - protected $phpbb_container; - protected $service; - protected $db; - protected $phpbb_root_path; - protected $php_ext; + protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; /** * Array of user data containing information needed to output the notifications to the template @@ -39,7 +35,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Notification option data (for outputting to the user) * - * @var bool|array False if the service should use it's default data + * @var bool|array False if the service should use its default data * Array of data (including keys 'id' and 'lang') */ public static $notification_option = false; @@ -60,20 +56,27 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(ContainerBuilder $phpbb_container, $data = array()) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - // phpBB Container - $this->phpbb_container = $phpbb_container; - - // Service - $this->service = $phpbb_container->get('notifications'); - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); - - $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); - $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + $this->notification_manager = $notification_manager; + $this->db = $db; + $this->cache = $cache; + $this->template = $template; + $this->extension_manager = $extension_manager; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + /** + * Set initial data from the database + * + * @param array $data Row directly from the database + */ + public function set_initial_data($data = array()) + { // The row from the database (unless this is a new notification we're going to add) $this->data = $data; $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); @@ -117,15 +120,13 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ public function prepare_for_display() { - $user = $this->phpbb_container->get('user'); - return array( 'AVATAR' => $this->get_avatar(), 'FORMATTED_TITLE' => $this->get_title(), 'URL' => $this->get_url(), - 'TIME' => $user->format_date($this->time), + 'TIME' => $this->user->format_date($this->time), 'UNREAD' => $this->unread, @@ -239,7 +240,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Load the special items (fall-back) */ - public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) + public function load_special($data, $notifications) { return; } @@ -247,7 +248,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Is available (fall-back) */ - public static function is_available(ContainerBuilder $phpbb_container) + public function is_available() { return true; } @@ -259,27 +260,24 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Find the users who want to receive notifications (helper) * - * @param ContainerBuilder $phpbb_container * @param array $item_id The item_id to search for * * @return array */ - protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id, $options) + protected function _find_users_for_notification($item_id, $options) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $rowset = array(); $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . static::get_item_type() . "' AND item_id = " . (int) $item_id; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -293,7 +291,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $rowset[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $rowset; } @@ -306,7 +304,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function _get_avatar($user_id) { - $user = $this->service->get_user($user_id); + $user = $this->notification_manager->get_user($user_id); if (!function_exists('get_user_avatar')) { diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 51f23bc294..5ff39821dc 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -51,38 +51,35 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post /** * 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, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $sql = 'SELECT user_id FROM ' . BOOKMARKS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']) . ' + WHERE ' . $this->db->sql_in_set('topic_id', $post['topic_id']) . ' AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -94,9 +91,9 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -110,7 +107,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 8fa0102e3d..3ef45fb8e3 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -66,7 +66,7 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap */ public function get_title() { - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, censor_text($this->get_data('topic_title')), $this->get_data('disapprove_reason') diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 186c42d2b6..afd293a94f 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -66,7 +66,7 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a */ public function get_title() { - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, censor_text($this->get_data('topic_title')), $this->get_data('disapprove_reason') diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index aa54c62a97..c17f248080 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -25,9 +25,9 @@ interface phpbb_notification_type_interface public static function get_item_id($type_data); - public static function is_available(ContainerBuilder $phpbb_container); + public function is_available(); - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data, $options); + public function find_users_for_notification($type_data, $options); public function get_title(); @@ -45,5 +45,5 @@ interface phpbb_notification_type_interface public function get_load_special(); - public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications); + public function load_special($data, $notifications); } diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 8252a8577b..9c1f353514 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -65,36 +65,31 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $pm Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm, $options = array()) + public function find_users_for_notification($pm, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $service = $phpbb_container->get('notifications'); - $db = $phpbb_container->get('dbal.conn'); - $user = $phpbb_container->get('user'); - if (!sizeof($pm['recipients'])) { return array(); } - $service->load_users(array_keys($pm['recipients'])); + $this->notification_manager->load_users(array_keys($pm['recipients'])); $notify_users = array(); $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', array_keys($pm['recipients'])); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -108,7 +103,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -128,11 +123,11 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_title() { - $user_data = $this->service->get_user($this->get_data('from_user_id')); + $user_data = $this->notification_manager->get_user($this->get_data('from_user_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_PM', $username, $this->get_data('message_subject')); + return $this->user->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } /** @@ -142,7 +137,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_email_template_variables() { - $user_data = $this->service->get_user($this->get_data('from_user_id')); + $user_data = $this->notification_manager->get_user($this->get_data('from_user_id')); return array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 1e654ef51b..37020825d3 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -71,12 +71,11 @@ class phpbb_notification_type_post extends phpbb_notification_type_base /** * 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, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -86,8 +85,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // It may not be the nicest thing, but it is already working and it would be significant work to replace it //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $sql = 'SELECT user_id @@ -95,19 +92,19 @@ class phpbb_notification_type_post extends phpbb_notification_type_base WHERE topic_id = ' . (int) $post['topic_id'] . ' AND notify_status = ' . NOTIFY_YES . ' AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -119,9 +116,9 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -135,7 +132,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -161,12 +158,12 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->service->get_user($this->get_data('poster_id')); + $user_data = $this->notification_manager->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( + return $this->user->lang( $this->language_key, $username, censor_text($this->get_data('topic_title')) diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index f0a5e0baec..44f4f9391c 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -62,9 +62,9 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post /** * Is available */ - public static function is_available(ContainerBuilder $phpbb_container) + public function is_available() { - $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + $m_approve = $this->auth->acl_getf('m_approve', true); return (!empty($m_approve)); } @@ -72,20 +72,17 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from the post * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - - $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $post['forum_id']); if (empty($auth_approve)) { @@ -97,9 +94,9 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -113,7 +110,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index dd3cbedee2..32ee06787c 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -58,19 +58,16 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post /** * 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, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $usernames = false; preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames); @@ -87,21 +84,21 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('username_clean', $usernames) . ' + WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . ' AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -113,9 +110,9 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -129,7 +126,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -137,28 +134,24 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post /** * Update a notification * - * @param ContainerBuilder $phpbb_container * @param array $data Data specific for this type that will be updated */ - public static function update_notifications(ContainerBuilder $phpbb_container, $post) + public function update_notifications($post) { - $service = $phpbb_container->get('notifications'); - $db = $phpbb_container->get('dbal.conn'); - $old_notifications = array(); $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_id = " . self::get_item_id($post); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $old_notifications[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // Find the new users to notify - $notifications = self::find_users_for_notification($phpbb_container, $post); + $notifications = $this->find_users_for_notification($post); // Find the notifications we must delete $remove_notifications = array_diff($old_notifications, array_keys($notifications)); @@ -185,8 +178,8 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_id = " . self::get_item_id($post) . ' - AND ' . $db->sql_in_set('user_id', $remove_notifications); - $db->sql_query($sql); + AND ' . $this->db->sql_in_set('user_id', $remove_notifications); + $this->db->sql_query($sql); } // return true to continue with the update code in the notifications service (this will update the rest of the notifications) @@ -200,7 +193,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post */ public function get_email_template_variables() { - $user_data = $this->service->get_user($this->get_data('poster_id')); + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); return array_merge(parent::get_email_template_variables(), array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 7753b196e8..01f394ccd2 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -71,12 +71,11 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $topic Data from the topic * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) + public function find_users_for_notification($topic, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -86,8 +85,6 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base // It may not be the nicest thing, but it is already working and it would be significant work to replace it //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $sql = 'SELECT user_id @@ -95,19 +92,19 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base WHERE forum_id = ' . (int) $topic['forum_id'] . ' AND notify_status = ' . NOTIFY_YES . ' AND user_id <> ' . (int) $topic['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $topic['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $topic['forum_id']); if (empty($auth_read)) { @@ -119,9 +116,9 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -135,7 +132,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -161,12 +158,12 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->service->get_user($this->get_data('poster_id')); + $user_data = $this->notification_manager->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( + return $this->user->lang( $this->language_key, $username, censor_text($this->get_data('topic_title')), diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 385578cec8..d931168013 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -53,9 +53,9 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top /** * Is available */ - public static function is_available(ContainerBuilder $phpbb_container) + public function is_available() { - $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + $m_approve = $this->auth->acl_getf('m_approve', true); return (!empty($m_approve)); } @@ -72,20 +72,17 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $topic Data from the topic * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) + public function find_users_for_notification($topic, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - - $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $topic['forum_id']); if (empty($auth_approve)) { @@ -97,9 +94,9 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -113,7 +110,7 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } -- cgit v1.2.1 From ff136cc96a62147bc7468b716b86a30f12754e77 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 15:21:07 -0500 Subject: [ticket/11103] Do not use Symfony\...\ContainerBuilder; It's no longer needed PHPBB3-11103 --- phpBB/includes/notification/manager.php | 2 -- phpBB/includes/notification/method/base.php | 1 - phpBB/includes/notification/type/approve_post.php | 1 - phpBB/includes/notification/type/approve_topic.php | 1 - phpBB/includes/notification/type/base.php | 1 - phpBB/includes/notification/type/bookmark.php | 1 - phpBB/includes/notification/type/disapprove_post.php | 1 - phpBB/includes/notification/type/disapprove_topic.php | 1 - phpBB/includes/notification/type/pm.php | 1 - phpBB/includes/notification/type/post.php | 1 - phpBB/includes/notification/type/post_in_queue.php | 1 - phpBB/includes/notification/type/quote.php | 1 - phpBB/includes/notification/type/topic.php | 1 - phpBB/includes/notification/type/topic_in_queue.php | 1 - 14 files changed, 15 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index e2c6c9d0f4..be29f37a3e 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -7,8 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; - /** * @ignore */ diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index ced85e2582..d95a65fa72 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 3a88d9f54a..bbd2bccfc0 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 0a6ca14a84..5006e3bbb8 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 626fe821e6..31150477bb 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 5ff39821dc..ee06a6d33b 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 3ef45fb8e3..6ef4de5cd9 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index afd293a94f..6f92c1de77 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 9c1f353514..a647106a53 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 37020825d3..de224776db 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 44f4f9391c..19c3ed9fc9 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 32ee06787c..0920cea428 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 01f394ccd2..621c0f484b 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index d931168013..c549cb12a1 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore -- cgit v1.2.1 From ceb56da965f12245bca6b735cb71f3bbaf505307 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 21:39:17 -0500 Subject: [ticket/11103] Fixing a few bugs from the previous changes PHPBB3-11103 --- phpBB/includes/notification/manager.php | 6 +++--- phpBB/includes/notification/method/base.php | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index be29f37a3e..854d72009e 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -30,7 +30,7 @@ class phpbb_notification_manager */ protected $users = array(); - public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->db = $db; $this->cache = $cache; @@ -462,7 +462,7 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->get_subscription_files('notifications/type/') as $class_name => $file) + foreach ($this->get_subscription_files('notification/type/') as $class_name => $file) { $class_name = $this->get_item_type_class_name($class_name); @@ -498,7 +498,7 @@ class phpbb_notification_manager { $subscription_methods = array(); - foreach ($this->get_subscription_files('notifications/method/') as $method_name => $file) + foreach ($this->get_subscription_files('notification/method/') as $method_name => $file) { $class_name = 'phpbb_notification_method_' . $method_name; diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index d95a65fa72..9f1db6d9f5 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -50,8 +50,9 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { + $this->notification_manager = $notification_manager; $this->db = $db; $this->cache = $cache; $this->template = $template; -- cgit v1.2.1 From 3f2e3ad633930744e1ed92cc529ca473ccfa09e0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 00:07:48 -0500 Subject: [ticket/11103] Working on test case Fixing extension type/method naming scheme so they can be autoloaded. Other bugs PHPBB3-11103 --- phpBB/includes/notification/manager.php | 39 +++++++++++++++----------- phpBB/includes/notification/method/base.php | 2 +- phpBB/includes/notification/type/base.php | 7 ++++- phpBB/includes/notification/type/interface.php | 2 ++ 4 files changed, 31 insertions(+), 19 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 854d72009e..c1ae61e08a 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -466,11 +466,6 @@ class phpbb_notification_manager { $class_name = $this->get_item_type_class_name($class_name); - if (!class_exists($class_name)) - { - include($file); - } - $class = $this->get_item_type_class($class_name); if ($class->is_available() && method_exists($class_name, 'get_item_type')) @@ -502,11 +497,6 @@ class phpbb_notification_manager { $class_name = 'phpbb_notification_method_' . $method_name; - if (!class_exists($class_name)) - { - include($file); - } - $method = $this->get_method_class($class_name); if ($method->is_available()) @@ -652,7 +642,14 @@ class phpbb_notification_manager { if (!$safe) { - $item_type = preg_replace('#[^a-z_]#', '', $item_type); + $item_type = preg_replace('#[^a-z_-]#', '', $item_type); + } + + if (strpos($item_type, 'ext_') === 0) + { + $item_type_ary = explode('-', substr($item_type, 4), 2); + + return 'phpbb_ext_' . $item_type_ary[0] . '_notification_type_' . $item_type_ary[1]; } return 'phpbb_notification_type_' . $item_type; @@ -661,7 +658,7 @@ class phpbb_notification_manager /** * Helper to get the notifications item type class and set it up */ - private function get_item_type_class($item_type, $data = array()) + public function get_item_type_class($item_type, $data = array()) { $item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); @@ -673,7 +670,7 @@ class phpbb_notification_manager /** * Helper to get the notifications method class and set it up */ - private function get_method_class($method_name) + public function get_method_class($method_name) { return new $method_name($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); } @@ -693,15 +690,23 @@ class phpbb_notification_manager ->get_files(); foreach ($files as $file) { - $class = substr($file, strrpos($file, '/')); - $class = substr($class, 1, (strpos($class, '.' . $this->php_ext) - 1)); + $name = substr($file, strrpos($file, '/')); + $name = substr($name, 1, (strpos($name, '.' . $this->php_ext) - 1)); - if ($class == 'interface' || $class == 'base') + if ($name == 'interface' || $name == 'base') { continue; } - $subscription_files[$class] = $file; + if (!strpos($file, 'includes/')) // is an extension + { + $ext_name = substr($file, (strpos($file, 'ext/') + 4)); + $ext_name = substr($ext_name, 0, strpos($ext_name, '/')); + + $name = 'ext_' . $ext_name . '-' . $name; + } + + $subscription_files[$name] = $file; } return $subscription_files; diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 9f1db6d9f5..6410b1f519 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -50,7 +50,7 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->notification_manager = $notification_manager; $this->db = $db; diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 31150477bb..9e31d57108 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -55,7 +55,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->notification_manager = $notification_manager; $this->db = $db; @@ -91,6 +91,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->data[$name] = $value; } + public function __toString() + { + return (!empty($this->data)) ? var_export($this->data, true) : static::get_item_type(); + } + /** * Get special data (only important for the classes that extend this) * diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index c17f248080..56fad9fd80 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -43,6 +43,8 @@ interface phpbb_notification_type_interface public function create_insert_array($type_data); + public function users_to_query(); + public function get_load_special(); public function load_special($data, $notifications); -- cgit v1.2.1 From 2d69707a88fdb618730243cbe65ebc055cf68bae Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 00:23:14 -0500 Subject: [ticket/11103] Remove extra line break in the header Was introduced with ff136cc96a62147bc7468b716b86a30f12754e77 PHPBB3-11103 --- phpBB/includes/notification/method/base.php | 1 - phpBB/includes/notification/type/approve_post.php | 1 - phpBB/includes/notification/type/approve_topic.php | 1 - phpBB/includes/notification/type/base.php | 1 - phpBB/includes/notification/type/bookmark.php | 1 - phpBB/includes/notification/type/disapprove_post.php | 1 - phpBB/includes/notification/type/disapprove_topic.php | 1 - phpBB/includes/notification/type/pm.php | 1 - phpBB/includes/notification/type/post.php | 1 - phpBB/includes/notification/type/post_in_queue.php | 1 - phpBB/includes/notification/type/quote.php | 1 - phpBB/includes/notification/type/topic.php | 1 - phpBB/includes/notification/type/topic_in_queue.php | 1 - 13 files changed, 13 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 6410b1f519..5457ca99b2 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index bbd2bccfc0..98dfe678c2 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 5006e3bbb8..496dc688ad 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 9e31d57108..2ba0dd3bf7 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index ee06a6d33b..6c42f1d860 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 6ef4de5cd9..d1f7dfa85d 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 6f92c1de77..89c06b344f 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index a647106a53..9f9a3e2892 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index de224776db..d83ecf4fae 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 19c3ed9fc9..9c4f0ab8d3 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 0920cea428..48d8f24a25 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 621c0f484b..1c3d216b18 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index c549cb12a1..bee0ebbb22 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ -- cgit v1.2.1 From 54629aa87d3ef6f6fcb8ce8708e85ac039b98fa3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 13:46:52 -0500 Subject: [ticket/11103] Bug fixing PHPBB3-11103 --- phpBB/includes/notification/type/quote.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 48d8f24a25..1eea8f1066 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -168,7 +168,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // marked as read // Add the necessary notifications - $service->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); + $this->notification_manager->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); // Remove the necessary notifications if (!empty($remove_notifications)) -- cgit v1.2.1 From bafb5b0ecad7266c9641624bae2de2f3c7efe500 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 18:12:48 -0500 Subject: [ticket/11103] Starting work on combining notifications Just for posts currently and not yet outputted. PHPBB3-11103 --- phpBB/includes/notification/manager.php | 6 ++++ phpBB/includes/notification/type/base.php | 2 +- phpBB/includes/notification/type/post.php | 58 +++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index c1ae61e08a..c5fd41c901 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -660,6 +660,12 @@ class phpbb_notification_manager */ public function get_item_type_class($item_type, $data = array()) { + if (!strpos($item_type, 'notification_type_')) + { + $item_class = $this->get_item_type_class_name($item_type); + $item_type = $item_class; + } + $item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); $item->set_initial_data($data); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 2ba0dd3bf7..b72875fb85 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -104,7 +104,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function get_data($name) { - return (isset($this->data['data'][$name])) ? $this->data['data'][$name] : null; + return ($name === false) ? $this->data['data'] : ((isset($this->data['data'][$name])) ? $this->data['data'][$name] : null); } /** diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index d83ecf4fae..65b0c1adf2 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -132,6 +132,28 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } $this->db->sql_freeresult($result); + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + echo $sql; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + return $notify_users; } @@ -234,4 +256,40 @@ class phpbb_notification_type_post extends phpbb_notification_type_base return parent::create_insert_array($post); } + + /** + * Add responders to the notification + * + * @param mixed $post + */ + public function add_responders($post) + { + // Do not add them as a responder if they were the original poster that created the notification + if ($this->get_data('poster_id') == $post['poster_id']) + { + return array('data' => serialize($this->get_data(false))); + } + + $responders = $this->get_data('responders'); + + $responders = ($responders === null) ? array() : $responders; + + foreach ($responders as $responder) + { + // Do not add them as a responder multiple times + if ($responder['poster_id'] == $post['poster_id']) + { + return array('data' => serialize($this->get_data(false))); + } + } + + $responders[] = array( + 'poster_id' => $post['poster_id'], + 'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''), + ); + + $this->set_data('responders', $responders); + + return array('data' => serialize($this->get_data(false))); + } } -- cgit v1.2.1 From 7a92594bc0b2985019559e85c7d6067c7e9cd1b1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 9 Oct 2012 10:09:10 -0500 Subject: [ticket/11103] Fix the issue of time changing when editing items PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index b72875fb85..a41a5a8ac3 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -82,7 +82,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i public function __get($name) { - return $this->data[$name]; + return (!isset($this->data[$name])) ? null : $this->data[$name]; } public function __set($name, $value) @@ -202,6 +202,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i // Unset data unique to each row unset( + $data['time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function) $data['notification_id'], $data['unread'], $data['user_id'] -- cgit v1.2.1 From 7411d1d1bdb2e6cc61d5e97d15e184351ea67c64 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 9 Oct 2012 10:30:55 -0500 Subject: [ticket/11103] Starting work on the reported posts notification PHPBB3-11103 --- phpBB/includes/notification/type/post_in_queue.php | 11 ++- phpBB/includes/notification/type/report.php | 85 ++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 phpBB/includes/notification/type/report.php (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 9c4f0ab8d3..60b4bb4937 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -48,6 +48,13 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', ); + /** + * Permission to check for (in find_users_for_notification) + * + * @var string Permission name + */ + protected $permission = 'm_approve'; + /** * Get the type of notification this is * phpbb_notification_type_ @@ -62,7 +69,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post */ public function is_available() { - $m_approve = $this->auth->acl_getf('m_approve', true); + $m_approve = $this->auth->acl_getf($this->permission, true); return (!empty($m_approve)); } @@ -80,7 +87,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post 'ignore_users' => array(), ), $options); - $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $post['forum_id']); + $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); if (empty($auth_approve)) { diff --git a/phpBB/includes/notification/type/report.php b/phpBB/includes/notification/type/report.php new file mode 100644 index 0000000000..76c37c99f0 --- /dev/null +++ b/phpBB/includes/notification/type/report.php @@ -0,0 +1,85 @@ + 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", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); + } +} -- cgit v1.2.1 From b33e5273942c4f67e8168763eec224fd61edaa8f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 9 Oct 2012 22:02:49 -0500 Subject: [ticket/11103] Working on report notifications (post/pm) PHPBB3-11103 --- phpBB/includes/notification/type/post_in_queue.php | 2 +- phpBB/includes/notification/type/report.php | 85 ---------- phpBB/includes/notification/type/report_pm.php | 178 +++++++++++++++++++++ phpBB/includes/notification/type/report_post.php | 139 ++++++++++++++++ 4 files changed, 318 insertions(+), 86 deletions(-) delete mode 100644 phpBB/includes/notification/type/report.php create mode 100644 phpBB/includes/notification/type/report_pm.php create mode 100644 phpBB/includes/notification/type/report_post.php (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 60b4bb4937..1d75ca4dc9 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -99,7 +99,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); + AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/report.php b/phpBB/includes/notification/type/report.php deleted file mode 100644 index 76c37c99f0..0000000000 --- a/phpBB/includes/notification/type/report.php +++ /dev/null @@ -1,85 +0,0 @@ - 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", - ); - } - - /** - * Get the url to this item - * - * @return string URL - */ - public function get_url() - { - return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); - } -} diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php new file mode 100644 index 0000000000..9c680ce6a9 --- /dev/null +++ b/phpBB/includes/notification/type/report_pm.php @@ -0,0 +1,178 @@ + 'report', + 'lang' => 'NOTIFICATION_TYPE_REPORT', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'report_pm'; + } + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from the post + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $this->db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $board_url = generate_board_url(); + + 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_REPORT' => "{$board_url}mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", + 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", + 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $this->user->add_lang('mcp'); + + if (isset($this->user->lang[$this->get_data('reason_title')])) + { + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('post_subject')), + $this->user->lang[$this->get_data('reason_title')] + ); + } + + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('post_subject')), + $this->get_data('reason_description') + ); + } + + /** + * 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('reason_title', strtoupper($post['reason_title'])); + $this->set_data('reason_description', $post['reason_description']); + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php new file mode 100644 index 0000000000..70d3a4c114 --- /dev/null +++ b/phpBB/includes/notification/type/report_post.php @@ -0,0 +1,139 @@ + 'report', + 'lang' => 'NOTIFICATION_TYPE_REPORT', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'report_post'; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $board_url = generate_board_url(); + + 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_REPORT' => "{$board_url}mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", + 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", + 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $this->user->add_lang('mcp'); + + if (isset($this->user->lang[$this->get_data('reason_title')])) + { + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('post_subject')), + $this->user->lang[$this->get_data('reason_title')] + ); + } + + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('post_subject')), + $this->get_data('reason_description') + ); + } + + /** + * 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('reason_title', strtoupper($post['reason_title'])); + $this->set_data('reason_description', $post['reason_description']); + + return parent::create_insert_array($post); + } +} -- cgit v1.2.1 From 6d53bd4675e00419bcfcf476b03166b9774bebca Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 9 Oct 2012 22:28:41 -0500 Subject: [ticket/11103] Finishing up PM Report notifications PHPBB3-11103 --- phpBB/includes/notification/type/report_pm.php | 44 ++++++++++++++++-------- phpBB/includes/notification/type/report_post.php | 2 +- 2 files changed, 30 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 9c680ce6a9..e9fa4c0f11 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -28,7 +28,14 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm * * @var string */ - public $email_template = 'notifications/report_post'; + public $email_template = 'notifications/report_pm'; + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_REPORT_PM'; /** * Permission to check for (in find_users_for_notification) @@ -57,8 +64,19 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return 'report_pm'; } + /** + * Get the id of the parent + * + * @param array $pm The data from the pm + */ + public static function get_item_parent_id($pm) + { + return (int) $pm['report_id']; + } + /** * Find the users who want to receive notifications + * (copied from post_in_queue) * * @param array $post Data from the post * @@ -70,6 +88,9 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm 'ignore_users' => array(), ), $options); + // Global + $post['forum_id'] = 0; + $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); if (empty($auth_approve)) @@ -110,18 +131,11 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_email_template_variables() { - $board_url = generate_board_url(); - 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_REPORT' => "{$board_url}mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", - 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", - 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", - 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), + + 'U_VIEW_REPORT' => generate_board_url() . "mcp.{$this->php_ext}?r={$this->item_parent_id}&i=pm_reports&mode=pm_report_details", ); } @@ -132,7 +146,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_url() { - return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "r={$this->item_parent_id}&i=pm_reports&mode=pm_report_details"); } /** @@ -148,14 +162,14 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { return $this->user->lang( $this->language_key, - censor_text($this->get_data('post_subject')), + censor_text($this->get_data('message_subject')), $this->user->lang[$this->get_data('reason_title')] ); } return $this->user->lang( $this->language_key, - censor_text($this->get_data('post_subject')), + censor_text($this->get_data('message_subject')), $this->get_data('reason_description') ); } diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 70d3a4c114..df67a8e338 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -35,7 +35,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i * * @var string */ - protected $language_key = 'NOTIFICATION_REPORT'; + protected $language_key = 'NOTIFICATION_REPORT_POST'; /** * Permission to check for (in find_users_for_notification) -- cgit v1.2.1 From 1b56a1d6be12afb851a158a5e09965a6528d1435 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 11 Oct 2012 22:36:48 -0500 Subject: [ticket/11103] Finishing up report post/pm and adding report closed PHPBB3-11103 --- phpBB/includes/notification/type/report_pm.php | 25 ++++ .../notification/type/report_pm_closed.php | 140 +++++++++++++++++++++ phpBB/includes/notification/type/report_post.php | 25 ++++ .../notification/type/report_post_closed.php | 140 +++++++++++++++++++++ 4 files changed, 330 insertions(+) create mode 100644 phpBB/includes/notification/type/report_pm_closed.php create mode 100644 phpBB/includes/notification/type/report_post_closed.php (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index e9fa4c0f11..af1f71433c 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -158,10 +158,15 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { $this->user->add_lang('mcp'); + $user_data = $this->notification_manager->get_user($this->get_data('reporter_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + if (isset($this->user->lang[$this->get_data('reason_title')])) { return $this->user->lang( $this->language_key, + $username, censor_text($this->get_data('message_subject')), $this->user->lang[$this->get_data('reason_title')] ); @@ -169,11 +174,30 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return $this->user->lang( $this->language_key, + $username, censor_text($this->get_data('message_subject')), $this->get_data('reason_description') ); } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('reporter_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['reporter_id']); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -184,6 +208,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function create_insert_array($post) { + $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php new file mode 100644 index 0000000000..534e1288a6 --- /dev/null +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -0,0 +1,140 @@ + array('')); + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array(); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->notification_manager->get_user($this->get_data('closer_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('message_subject')) + ); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('closer_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['closer_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->set_data('closer_id', $post['closer_id']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index df67a8e338..2346e4e57c 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -105,10 +105,15 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i { $this->user->add_lang('mcp'); + $user_data = $this->notification_manager->get_user($this->get_data('reporter_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + if (isset($this->user->lang[$this->get_data('reason_title')])) { return $this->user->lang( $this->language_key, + $username, censor_text($this->get_data('post_subject')), $this->user->lang[$this->get_data('reason_title')] ); @@ -116,11 +121,30 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i return $this->user->lang( $this->language_key, + $username, censor_text($this->get_data('post_subject')), $this->get_data('reason_description') ); } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('reporter_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['reporter_id']); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -131,6 +155,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function create_insert_array($post) { + $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php new file mode 100644 index 0000000000..d8537a8152 --- /dev/null +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -0,0 +1,140 @@ + array('')); + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array(); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->notification_manager->get_user($this->get_data('closer_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('post_subject')) + ); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('closer_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['closer_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->set_data('closer_id', $post['closer_id']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} -- cgit v1.2.1 From 1e3abdc49fa1d51703127033b0d8f2cd45da9741 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 11 Oct 2012 22:40:48 -0500 Subject: [ticket/11103] Remove debug code PHPBB3-11103 --- phpBB/includes/notification/type/post.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 65b0c1adf2..a2b1fbf82a 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -149,7 +149,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; - echo $sql; $this->db->sql_query($sql); } $this->db->sql_freeresult($result); -- cgit v1.2.1 From 43e3af4b46bdfe0935c766489a66c5c0f8786e3f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 12 Oct 2012 11:37:51 -0500 Subject: [ticket/11103] Notification grouping output for posts. PHPBB3-11103 --- phpBB/includes/notification/type/post.php | 48 ++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index a2b1fbf82a..d6f6c16e59 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -171,20 +171,36 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function get_title() { - if ($this->get_data('post_username')) + $responders = $this->get_data('responders'); + $usernames = array(); + + if (!is_array($responders)) { - $username = $this->get_data('post_username'); + $responders = array(); } - else + + $responders = array_merge(array(array( + 'poster_id' => $this->get_data('poster_id'), + 'username' => $this->get_data('post_username'), + )), $responders); + + foreach ($responders as $responder) { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + if ($responder['username']) + { + $usernames[] = $responder['username']; + } + else + { + $user_data = $this->notification_manager->get_user($responder['poster_id']); - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $usernames[] = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } } return $this->user->lang( $this->language_key, - $username, + implode(', ', $usernames), censor_text($this->get_data('topic_title')) ); } @@ -226,7 +242,25 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function users_to_query() { - return array($this->data['poster_id']); + /*$responders[] = array( + 'poster_id' => $post['poster_id'], + 'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''), + );*/ + + $responders = $this->get_data('responders'); + $users = array( + $this->get_data('poster_id'), + ); + + if (is_array($responders)) + { + foreach ($responders as $responder) + { + $users[] = $responder['poster_id']; + } + } + + return $users; } /** -- cgit v1.2.1 From 8b2f1127e4167e241c41f8709964c203e401de94 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 12 Oct 2012 11:40:13 -0500 Subject: [ticket/11103] Notification grouping output for bookmark/quote PHPBB3-11103 --- phpBB/includes/notification/type/bookmark.php | 21 +++++++++++++++++++++ phpBB/includes/notification/type/quote.php | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 6c42f1d860..8a23859d05 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -107,6 +107,27 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post } $this->db->sql_freeresult($result); + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + return $notify_users; } } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 1eea8f1066..34907ef8d6 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -126,6 +126,27 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post } $this->db->sql_freeresult($result); + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + return $notify_users; } -- cgit v1.2.1 From 3d79ce28031b4c85ee34bd4d43f0c64b18b1a80b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 12 Oct 2012 16:54:42 -0500 Subject: [ticket/11103] Ability to query data before running create_insert_array() Mark post/topic in queue notifications read when visiting mcp Change post/topic in queue notification url to use MCP. Fix the bug: Approving a topic marks the topic as read, but before the notification is created for the user approving the topic (if they would get a notification that the topic has been made). This causes it to be stuck "unread". PHPBB3-11103 --- phpBB/includes/notification/manager.php | 9 ++-- phpBB/includes/notification/type/approve_post.php | 5 ++- phpBB/includes/notification/type/approve_topic.php | 5 ++- phpBB/includes/notification/type/base.php | 19 ++++++++- .../includes/notification/type/disapprove_post.php | 3 +- .../notification/type/disapprove_topic.php | 5 ++- phpBB/includes/notification/type/interface.php | 4 +- phpBB/includes/notification/type/pm.php | 5 ++- phpBB/includes/notification/type/post.php | 48 ++++++++++++++++++---- phpBB/includes/notification/type/post_in_queue.php | 15 ++++++- phpBB/includes/notification/type/report_pm.php | 5 ++- .../notification/type/report_pm_closed.php | 5 ++- phpBB/includes/notification/type/report_post.php | 5 ++- .../notification/type/report_post_closed.php | 5 ++- phpBB/includes/notification/type/topic.php | 45 ++++++++++++++++++-- .../includes/notification/type/topic_in_queue.php | 15 ++++++- 16 files changed, 162 insertions(+), 36 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index c5fd41c901..6c74fa965e 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -324,8 +324,6 @@ class phpbb_notification_manager // 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 - // todo Users should not receive notifications from multiple events from the same item (ex: for a topic reply with a quote including your username) - // Probably should be handled within each type? $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' @@ -342,6 +340,11 @@ class phpbb_notification_manager return; } + // Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications) + $notification = $this->get_item_type_class($item_type_class_name); + $pre_create_data = $notification->pre_create_insert_array($data, $notify_users); + unset($notification); + // Go through each user so we can insert a row in the DB and then notify them by their desired means foreach ($notify_users as $user => $methods) { @@ -350,7 +353,7 @@ class phpbb_notification_manager $notification->user_id = (int) $user; // Store the creation array in our new rows that will be inserted later - $new_rows[] = $notification->create_insert_array($data); + $new_rows[] = $notification->create_insert_array($data, $pre_create_data); // Users are needed to send notifications $user_ids = array_merge($user_ids, $notification->users_to_query()); diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 98dfe678c2..9275ec2f6d 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -111,14 +111,15 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('post_subject', $post['post_subject']); - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 496dc688ad..325ccd0eab 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -111,12 +111,13 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index a41a5a8ac3..45dc463061 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -164,10 +164,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * (The service handles insertion) * * @param array $type_data Data unique to this notification type + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($type_data) + public function create_insert_array($type_data, $pre_create_data = array()) { // Defaults $this->data = array_merge(array( @@ -257,6 +258,22 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i return true; } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $type_data Data unique to this notification type + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($type_data, $notify_users) + { + return array(); + } + /** * -------------- Helper functions ------------------- */ diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index d1f7dfa85d..1bf9242c52 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -98,10 +98,11 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('disapprove_reason', $post['disapprove_reason']); diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 89c06b344f..f3e0be4883 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -98,14 +98,15 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('disapprove_reason', $post['disapprove_reason']); - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 56fad9fd80..084a819af7 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -41,7 +41,9 @@ interface phpbb_notification_type_interface public function mark_unread($return); - public function create_insert_array($type_data); + public function pre_create_insert_array($type_data, $notify_users); + + public function create_insert_array($type_data, $pre_create_data); public function users_to_query(); diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 9f9a3e2892..c2065fef99 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -170,15 +170,16 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($pm) + public function create_insert_array($pm, $pre_create_data = array()) { $this->set_data('from_user_id', $pm['from_user_id']); $this->set_data('message_subject', $pm['message_subject']); - return parent::create_insert_array($pm); + return parent::create_insert_array($pm, $pre_create_data); } } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index d6f6c16e59..76a7846f30 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -242,11 +242,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function users_to_query() { - /*$responders[] = array( - 'poster_id' => $post['poster_id'], - 'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''), - );*/ - $responders = $this->get_data('responders'); $users = array( $this->get_data('poster_id'), @@ -263,15 +258,47 @@ class phpbb_notification_type_post extends phpbb_notification_type_base return $users; } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + if (!sizeof($notify_users)) + { + return array(); + } + + $tracking_data = array(); + $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $tracking_data[$row['user_id']] = $row['mark_time']; + } + + return $tracking_data; + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('poster_id', $post['poster_id']); @@ -287,7 +314,14 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $this->time = $post['post_time']; - return parent::create_insert_array($post); + // Topics can be "read" before they are public (while awaiting approval). + // Make sure that if the user has read the topic, it's marked as read in the notification + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + { + $this->unread = false; + } + + return parent::create_insert_array($post, $pre_create_data); } /** diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 1d75ca4dc9..f00a83de36 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -120,17 +120,28 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post return $notify_users; } + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "i=queue&mode=approve_details&f={$this->get_data('forum_id')}&p={$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 + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index af1f71433c..db0ad6ac6e 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -203,15 +203,16 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); - return parent::create_insert_array($post); + return parent::create_insert_array($post, $pre_create_data); } } diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 534e1288a6..f5790ba449 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -124,14 +124,15 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('closer_id', $post['closer_id']); - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 2346e4e57c..d7a0d58167 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -150,15 +150,16 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); - return parent::create_insert_array($post); + return parent::create_insert_array($post, $pre_create_data); } } diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index d8537a8152..0d5c5b292e 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -124,14 +124,15 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('closer_id', $post['closer_id']); - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 1c3d216b18..cb38b0274e 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -76,7 +76,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base public function find_users_for_notification($topic, $options = array()) { $options = array_merge(array( - 'ignore_users' => array(), + 'ignore_users' => array(), ), $options); // Let's continue to use the phpBB subscriptions system, at least for now. @@ -207,15 +207,47 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base return array($this->data['poster_id']); } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + if (!sizeof($notify_users)) + { + return array(); + } + + $tracking_data = array(); + $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $tracking_data[$row['user_id']] = $row['mark_time']; + } + + return $tracking_data; + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('poster_id', $post['poster_id']); @@ -227,6 +259,13 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $this->time = $post['post_time']; - return parent::create_insert_array($post); + // Topics can be "read" before they are public (while awaiting approval). + // Make sure that if the user has read the topic, it's marked as read in the notification + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + { + $this->unread = false; + } + + return parent::create_insert_array($post, $pre_create_data); } } diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index bee0ebbb22..176ec0b901 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -113,17 +113,28 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top return $notify_users; } + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "i=queue&mode=approve_details&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 $topic Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($topic) + public function create_insert_array($topic, $pre_create_data = array()) { - $data = parent::create_insert_array($topic); + $data = parent::create_insert_array($topic, $pre_create_data); $this->time = $data['time'] = time(); -- cgit v1.2.1 From 4392054044d3bf63481098cca9e27e17ae306fa0 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 13 Oct 2012 17:06:01 -0500 Subject: [ticket/11103] Reported pm notifications require m_report permissions PHPBB3-11103 --- phpBB/includes/notification/type/report_pm.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index db0ad6ac6e..3619c5510c 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -74,6 +74,17 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return (int) $pm['report_id']; } + /** + * Is available + */ + public function is_available() + { + $m_approve = $this->auth->acl_getf($this->permission, true); + + return (!empty($m_approve)); + } + + /** * Find the users who want to receive notifications * (copied from post_in_queue) -- cgit v1.2.1 From 397d039ce5c7b61145b4ff8daa41e511a75122c6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 13 Oct 2012 17:37:59 -0500 Subject: [ticket/11103] Allow global moderators to receive moderator notifications PHPBB3-11103 --- phpBB/includes/notification/type/post_in_queue.php | 5 ++++- phpBB/includes/notification/type/topic_in_queue.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index f00a83de36..4f92eb157a 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -87,13 +87,16 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post 'ignore_users' => array(), ), $options); - $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); + // 0 is for global + $auth_approve = $this->auth->acl_get_list(false, $this->permission, array($post['forum_id'], 0)); if (empty($auth_approve)) { return array(); } + $auth_approve[$post['forum_id']] = array_unique(array_merge($auth_approve[$post['forum_id']], $auth_approve[0])); + $notify_users = array(); $sql = 'SELECT * diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 176ec0b901..96f09cef9e 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -80,13 +80,16 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top 'ignore_users' => array(), ), $options); - $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $topic['forum_id']); + // 0 is for global + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($topic['forum_id'], 0)); if (empty($auth_approve)) { return array(); } + $auth_approve[$topic['forum_id']] = array_unique(array_merge($auth_approve[$topic['forum_id']], $auth_approve[0])); + $notify_users = array(); $sql = 'SELECT * -- cgit v1.2.1 From c60b15294a72d5a2be8e7d23fd1b4052ec944ec8 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 13 Oct 2012 17:49:12 -0500 Subject: [ticket/11103] Global moderators with m_approve permission never need approval They do not need to receive notifications if their post/topic is approved or disapproved PHPBB3-11103 --- phpBB/includes/notification/type/approve_post.php | 8 ++++++++ phpBB/includes/notification/type/approve_topic.php | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 9275ec2f6d..dbd2e4417f 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -57,6 +57,14 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post return 'approve_post'; } + /** + * Is available + */ + public function is_available() + { + return !$this->auth->acl_get('m_approve'); + } + /** * Find the users who want to receive notifications * diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 325ccd0eab..3608bfba85 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -57,6 +57,14 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi return 'approve_topic'; } + /** + * Is available + */ + public function is_available() + { + return !$this->auth->acl_get('m_approve'); + } + /** * Find the users who want to receive notifications * -- cgit v1.2.1 From 39fd31d3aedd5d583041b1ee76bed3e7d0edcf36 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 13 Oct 2012 18:12:33 -0500 Subject: [ticket/11103] Trying to fix an odd issue with unread status on approved posts From a recent change, when your posts/topics are approved, they will be marked read automatically because you've read the topic/post already. To change that I've forced the notification to be marked unread and attempted to reset the read status on the post/topic to be unread before the post that was approved. This does not seem to work so well and I don't know of any way this can really be properly fixed, so the code I was working on I've commented out. For now, users will just need to manually mark these types of notifications as read. I cannot think of a way for this to be fixed without running two additional queries on every viewtopic. PHPBB3-11103 --- phpBB/includes/notification/type/approve_post.php | 32 ++++++++++++++++++++++ phpBB/includes/notification/type/approve_topic.php | 30 ++++++++++++++++++++ 2 files changed, 62 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index dbd2e4417f..68e8352a13 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -114,6 +114,38 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post return $notify_users; } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + /*if (!sizeof($notify_users)) + { + return array(); + } + + // Mark the topic unread before the post + $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . ' + SET mark_time = ' . (int) ($post['post_time'] - 1) . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $this->db->sql_query($sql);*/ + + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + // (and also saves a query) + return array(); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 3608bfba85..f3a94e44b8 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -114,6 +114,36 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi return $notify_users; } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + /*if (!sizeof($notify_users)) + { + return array(); + } + + // Mark the topic unread + $sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $this->db->sql_query($sql*/ + + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + return array(); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) -- cgit v1.2.1 From cb937841269017d13058208378e4c9ad79718c6e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 13 Oct 2012 20:02:38 -0500 Subject: [ticket/11103] UCP Notification List PHPBB3-11103 --- phpBB/includes/notification/manager.php | 33 +++++++++++++++++++++++-------- phpBB/includes/notification/type/base.php | 6 +++++- 2 files changed, 30 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 6c74fa965e..22fa12967a 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -68,6 +68,7 @@ class phpbb_notification_manager 'start' => 0, 'all_unread' => false, 'count_unread' => false, + 'count_total' => false, ), $options); // If all_unread, count_unread mus be true @@ -79,12 +80,13 @@ class phpbb_notification_manager return array( 'notifications' => array(), 'unread_count' => 0, + 'total_count' => 0, ); } $notifications = $user_ids = array(); $load_special = array(); - $count = 0; + $total_count = $unread_count = 0; if ($options['count_unread']) { @@ -94,7 +96,18 @@ class phpbb_notification_manager WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1'; $result = $this->db->sql_query($sql); - $count = (int) $this->db->sql_fetchfield('count', $result); + $unread_count = (int) $this->db->sql_fetchfield('count', $result); + $this->db->sql_freeresult($result); + } + + if ($options['count_total']) + { + // Get the total number of notifications + $sql = 'SELECT COUNT(*) AS count + FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id']; + $result = $this->db->sql_query($sql); + $total_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); } @@ -115,7 +128,7 @@ class phpbb_notification_manager $this->db->sql_freeresult($result); // Get all unread notifications - if ($count && $options['all_unread'] && !empty($rowset)) + if ($unread_count && $options['all_unread'] && !empty($rowset)) { $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' @@ -165,14 +178,15 @@ class phpbb_notification_manager return array( 'notifications' => $notifications, - 'unread_count' => $count, + 'unread_count' => $unread_count, + 'total_count' => $total_count, ); } /** * Mark notifications read * - * @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|string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to mark read for all item 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) @@ -191,12 +205,15 @@ class phpbb_notification_manager $time = ($time) ?: time(); - $this->get_item_type_class_name($item_type); + if ($item_type !== false) + { + $this->get_item_type_class_name($item_type); + } $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 - WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND time <= " . $time . + WHERE time <= " . $time . + (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 45dc463061..f6b61aee49 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -124,6 +124,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i public function prepare_for_display() { return array( + 'NOTIFICATION_ID' => $this->notification_id, + 'AVATAR' => $this->get_avatar(), 'FORMATTED_TITLE' => $this->get_title(), @@ -344,6 +346,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function mark($unread = true, $return = false) { + $this->unread = (bool) $unread; + $where = array( 'item_type = ' . $this->db->sql_escape($this->item_type), 'item_id = ' . (int) $this->item_id, @@ -357,7 +361,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' - SET unread = ' . (bool) $unread . ' + SET unread = ' . $this->unread . ' WHERE ' . $where; $this->db->sql_query($sql); } -- cgit v1.2.1 From 94ffbb4050b2985ee62be0ecc0c6a244532e43ca Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 13 Oct 2012 23:24:30 -0500 Subject: [ticket/11103] Add is_disabled column to notifications table EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! Set is_disabled to 1 for all your notifications when your extension is disabled so they are ignored and do not cause errors. When your extension is enabled again, set is_disabled to 0 and your notifications will be working again. PHPBB3-11103 --- phpBB/includes/notification/manager.php | 15 ++++++++++----- phpBB/includes/notification/type/base.php | 5 ++++- phpBB/includes/notification/type/bookmark.php | 3 ++- phpBB/includes/notification/type/post.php | 3 ++- phpBB/includes/notification/type/quote.php | 6 ++++-- 5 files changed, 22 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 22fa12967a..16fdae6dd0 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -94,7 +94,8 @@ class phpbb_notification_manager $sql = 'SELECT COUNT(*) AS count FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' - AND unread = 1'; + AND unread = 1 + AND is_disabled = 0'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); @@ -105,7 +106,8 @@ class phpbb_notification_manager // Get the total number of notifications $sql = 'SELECT COUNT(*) AS count FROM ' . NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $options['user_id']; + WHERE user_id = ' . (int) $options['user_id'] . ' + AND is_disabled = 0'; $result = $this->db->sql_query($sql); $total_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); @@ -118,7 +120,8 @@ class phpbb_notification_manager FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . ' - ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); + AND is_disabled = 0 + ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); while ($row = $this->db->sql_fetchrow($result)) @@ -135,7 +138,8 @@ class phpbb_notification_manager WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' - ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); + AND is_disabled = 0 + ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); while ($row = $this->db->sql_fetchrow($result)) @@ -344,7 +348,8 @@ class phpbb_notification_manager $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND item_id = " . (int) $item_id; + AND item_id = " . (int) $item_id . ' + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index f6b61aee49..3aac8a7dd3 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -42,9 +42,12 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Indentification data * item_type * item_id - * item_parent_id // Parent item id (ex: for topic => forum_id, for post => topic_id, etc) + * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * user_id * unread + * is_disabled - EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! + * - Set is_disabled to 1 for all your notifications when your extension is disabled so they are ignored and do not cause errors. + * - When your extension is enabled again, set is_disabled to 0 and your notifications will be working again. * * time * data (special serialized field that each notification type can use to store stuff) diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 8a23859d05..e5435b5829 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -113,7 +113,8 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1'; + AND unread = 1 + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 76a7846f30..a4792cd7f2 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -138,7 +138,8 @@ class phpbb_notification_type_post extends phpbb_notification_type_base FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1'; + AND unread = 1 + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 34907ef8d6..4d1e637820 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -132,7 +132,8 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1'; + AND unread = 1 + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -161,7 +162,8 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND item_id = " . self::get_item_id($post); + AND item_id = " . self::get_item_id($post) . ' + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { -- cgit v1.2.1 From c5f280351a96aaebd90c27da095c9b1ff28624a5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 13 Oct 2012 23:52:49 -0500 Subject: [ticket/11103] UCP Notification option grouping Also add the ability to specify an _EXPLAIN text for the notification option PHPBB3-11103 --- phpBB/includes/notification/manager.php | 23 ++++++++++++++-------- phpBB/includes/notification/type/approve_post.php | 3 ++- phpBB/includes/notification/type/approve_topic.php | 3 ++- phpBB/includes/notification/type/base.php | 2 +- .../includes/notification/type/disapprove_post.php | 3 ++- .../notification/type/disapprove_topic.php | 3 ++- phpBB/includes/notification/type/post.php | 10 ++++++++++ phpBB/includes/notification/type/post_in_queue.php | 3 ++- phpBB/includes/notification/type/report_pm.php | 3 ++- phpBB/includes/notification/type/report_post.php | 1 + phpBB/includes/notification/type/topic.php | 10 ++++++++++ .../includes/notification/type/topic_in_queue.php | 3 ++- 12 files changed, 51 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 16fdae6dd0..fc9b48c624 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -495,17 +495,24 @@ class phpbb_notification_manager if ($class->is_available() && method_exists($class_name, 'get_item_type')) { - if ($class_name::$notification_option === false) - { - $subscription_types[$class_name::get_item_type()] = $class_name::get_item_type(); - } - else - { - $subscription_types[$class_name::$notification_option['id']] = $class_name::$notification_option; - } + $options = array_merge(array( + 'id' => $class_name::get_item_type(), + 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name::get_item_type()), + 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', + ), (($class_name::$notification_option !== false) ? $class_name::$notification_option : array())); + + $subscription_types[$options['group']][$options['id']] = $options; } } + // Move Miscellaneous to the very last section + if (isset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'])) + { + $miscellaneous = $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']; + unset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); + $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous; + } + return $subscription_types; } diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 68e8352a13..6ed9b6c67c 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -41,11 +41,12 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post * 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' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', ); /** diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index f3a94e44b8..1ff5ae43bd 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -41,11 +41,12 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi * 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' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', ); /** diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 3aac8a7dd3..e8959d1352 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -34,7 +34,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Notification option data (for outputting to the user) * * @var bool|array False if the service should use its default data - * Array of data (including keys 'id' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = false; diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 1bf9242c52..8044a3e0ea 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -41,11 +41,12 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap * 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' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', ); /** diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index f3e0be4883..04fec87014 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -41,11 +41,12 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a * 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' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', ); /** diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index a4792cd7f2..ee26a8c33e 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -37,6 +37,16 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ protected $language_key = 'NOTIFICATION_POST'; + /** + * 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') + */ + public static $notification_option = array( + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + /** * Get the type of notification this is * phpbb_notification_type_ diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 4f92eb157a..499fd1e8ed 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -41,11 +41,12 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post * 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' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'needs_approval', 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_MODERATION', ); /** diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 3619c5510c..440092afdc 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -48,11 +48,12 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm * 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' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'report', 'lang' => 'NOTIFICATION_TYPE_REPORT', + 'group' => 'NOTIFICATION_GROUP_MODERATION', ); /** diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index d7a0d58167..d860fb1b38 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -53,6 +53,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i public static $notification_option = array( 'id' => 'report', 'lang' => 'NOTIFICATION_TYPE_REPORT', + 'group' => 'NOTIFICATION_GROUP_MODERATION', ); /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index cb38b0274e..237f430003 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -37,6 +37,16 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ protected $language_key = 'NOTIFICATION_TOPIC'; + /** + * 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') + */ + public static $notification_option = array( + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + /** * Get the type of notification this is * phpbb_notification_type_ diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 96f09cef9e..eb14c098e1 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -41,11 +41,12 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top * 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' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'needs_approval', 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_MODERATION', ); /** -- cgit v1.2.1 From a48f09033810148fd9b2d5a0b6a683f14ac73a6a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 14 Oct 2012 12:35:35 -0500 Subject: [ticket/11103] Make sure notifications are marked read when clicking them How do we do this? If an item is unread, the URL to view that item will be the URL to mark it as read (index.php?mark_notification=$id). When the URL is visited it marks the item as read and redirects them to the correct URL for the item. If the item is read, the URL is directly to the item. Prettify the html output PHPBB-11103 --- phpBB/includes/notification/manager.php | 2 +- phpBB/includes/notification/type/base.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index fc9b48c624..03776de2b4 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -165,7 +165,7 @@ class phpbb_notification_manager } $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); - $notifications[] = $notification; + $notifications[$row['notification_id']] = $notification; } $this->load_users($user_ids); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index e8959d1352..9ef0e71009 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -138,7 +138,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'UNREAD' => $this->unread, - 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification[]=' . $this->notification_id), + 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id), ); } @@ -148,7 +148,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) * @return string */ - public function mark_read($return = true) + public function mark_read($return = false) { return $this->mark(false, $return); } @@ -159,7 +159,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) * @return string */ - public function mark_unread($return = true) + public function mark_unread($return = false) { return $this->mark(true, $return); } @@ -352,11 +352,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->unread = (bool) $unread; $where = array( - 'item_type = ' . $this->db->sql_escape($this->item_type), + "item_type = '" . $this->db->sql_escape($this->item_type) . "'", 'item_id = ' . (int) $this->item_id, 'user_id = ' . (int) $this->user_id, ); - $where = implode(' AND ' . $where); + $where = implode(' AND ', $where); if ($return) { @@ -364,7 +364,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' - SET unread = ' . $this->unread . ' + SET unread = ' . (int) $this->unread . ' WHERE ' . $where; $this->db->sql_query($sql); } -- cgit v1.2.1 From fa6d60401656ee875ef18b35dc7ce43bd270ff4e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 14 Oct 2012 12:49:09 -0500 Subject: [ticket/11103] Remove todo comments that are no longer todo PHPBB3-11103 --- phpBB/includes/notification/type/quote.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 4d1e637820..0cc183346f 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -184,12 +184,6 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $add_notifications[$user_id] = $notifications[$user_id]; } - // todo Adding notifications while editing a post can be funky. - // If the user has read the topic/post already, and the user is newly quoted it an edit, - // The notification will be stuck as unread until another post is made and the user visits - // the topic again because the posts will not be marked as read since the topic is already - // marked as read - // Add the necessary notifications $this->notification_manager->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); -- cgit v1.2.1 From c8b66a26ef4f6ac2a71980c75a13356dcda72dd6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 16 Oct 2012 10:51:07 -0500 Subject: [ticket/11103] Mark read link if notification has no URL to view it Other style stuff PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 9ef0e71009..afd6a9fc9b 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -126,6 +126,17 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ public function prepare_for_display() { + if ($this->get_url()) + { + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id); + } + else + { + $redirect = (($this->user->page['page_dir']) ? $this->user->page['page_dir'] . '/' : '') . $this->user->page['page_name'] . (($this->user->page['query_string']) ? '?' . $this->user->page['query_string'] : ''); + + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&redirect=' . urlencode($redirect)); + } + return array( 'NOTIFICATION_ID' => $this->notification_id, @@ -138,7 +149,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'UNREAD' => $this->unread, - 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id), + 'U_MARK_READ' => ($this->unread) ? $u_mark_read : '', ); } -- cgit v1.2.1 From 3839fe69027836d0c9083095208e4ed548a7ea38 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 16 Oct 2012 17:44:46 -0500 Subject: [ticket/11103] Use report text for report notification, never notify reporter PHPBB3-11103 --- phpBB/includes/notification/type/report_pm.php | 14 +++++++++++- phpBB/includes/notification/type/report_post.php | 28 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 440092afdc..3327dbe734 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -115,7 +115,8 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]); + AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]) . ' + AND user_id <> ' . $this->user->data['user_id']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -174,6 +175,16 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + if ($this->get_data('report_text')) + { + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('message_subject')), + $this->get_data('report_text') + ); + } + if (isset($this->user->lang[$this->get_data('reason_title')])) { return $this->user->lang( @@ -224,6 +235,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); + $this->set_data('report_text', $post['report_text']); return parent::create_insert_array($post, $pre_create_data); } diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index d860fb1b38..151841ef02 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -65,6 +65,23 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i return 'report_post'; } + /** + * Find the users who want to receive notifications + * + * @param array $post Data from the post + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $notify_users = parent::find_users_for_notification($post, $options); + + // never notify reporter + unset($notify_users[$this->user->data['user_id']]); + + return $notify_users; + } + /** * Get email template variables * @@ -110,6 +127,16 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + if ($this->get_data('report_text')) + { + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('post_subject')), + $this->get_data('report_text') + ); + } + if (isset($this->user->lang[$this->get_data('reason_title')])) { return $this->user->lang( @@ -160,6 +187,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); + $this->set_data('report_text', $post['report_text']); return parent::create_insert_array($post, $pre_create_data); } -- cgit v1.2.1 From 230e9d2e322e707c46c6d99c18a0591fb56b6f74 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 16 Oct 2012 17:47:27 -0500 Subject: [ticket/11103] Do not send PM received notifications to the author (you won't be notified if you PM yourself) PHPBB3-11103 --- phpBB/includes/notification/type/pm.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index c2065fef99..dc4bd3b3a5 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -85,7 +85,8 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])); + AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])) . ' + AND user_id <> ' . $pm['from_user_id']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { -- cgit v1.2.1 From 92b533aad381ae1da8ccb1cd33fa19f31d8a0e98 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 16 Oct 2012 17:49:54 -0500 Subject: [ticket/11103] Do not notify yourself when you close your own report PHPBB3-11103 --- .../includes/notification/type/report_pm_closed.php | 21 +++++++++++++-------- .../notification/type/report_post_closed.php | 5 +++++ 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index f5790ba449..8d79c8446b 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -16,7 +16,7 @@ if (!defined('IN_PHPBB')) } /** -* Reported post notifications class +* Reported pm notifications class * This class handles notifications for reported pms * * @package notifications @@ -54,13 +54,18 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p /** * Find the users who want to receive notifications * - * @param array $post Data from + * @param array $pm Data from * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($pm, $options = array()) { - return array($post['reporter'] => array('')); + if ($pm['reporter'] == $this->user->data['user_id']) + { + return array(); + } + + return array($pm['reporter'] => array('')); } /** @@ -123,16 +128,16 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * - * @param array $post Data from submit_post + * @param array $pm PM Data * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($pm, $pre_create_data = array()) { - $this->set_data('closer_id', $post['closer_id']); + $this->set_data('closer_id', $pm['closer_id']); - $data = parent::create_insert_array($post, $pre_create_data); + $data = parent::create_insert_array($pm, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 0d5c5b292e..3e66bde9bc 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -60,6 +60,11 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function find_users_for_notification($post, $options = array()) { + if ($post['reporter'] == $this->user->data['user_id']) + { + return array(); + } + return array($post['reporter'] => array('')); } -- cgit v1.2.1 From 77bc12d334167ec5d1c7e3bc7c2b582218df32f6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 16 Oct 2012 23:27:49 -0500 Subject: [ticket/11103] Add author name output to post/topic email templates For a recent merge: https://github.com/phpbb/phpbb3/pull/624 PHPBB3-11103 --- phpBB/includes/notification/type/post.php | 12 ++++++++++++ phpBB/includes/notification/type/topic.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index ee26a8c33e..0681b4418c 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -223,7 +223,19 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function get_email_template_variables() { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + + $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($username), 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 237f430003..a9beb469c3 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -186,7 +186,19 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function get_email_template_variables() { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + + $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($username), 'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), -- cgit v1.2.1 From eb07b3ad9cfb37fd2943088170e380bff2db94a3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 18 Oct 2012 18:45:43 -0500 Subject: [ticket/11103] Expand class vars and use docblocks for phpBB classes PHPBB3-11103 --- phpBB/includes/notification/manager.php | 29 ++++++++++++++++-- phpBB/includes/notification/method/base.php | 47 +++++++++++++++++------------ phpBB/includes/notification/type/base.php | 30 +++++++++++++++++- 3 files changed, 84 insertions(+), 22 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 03776de2b4..a98e1f7af3 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -21,7 +21,32 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_manager { - protected $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; + /** @var dbal */ + protected $db = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var phpbb_template */ + protected $template = null; + + /** @var phpbb_extension_manager */ + protected $extension_manager = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_config */ + protected $config = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; /** * Users loaded from the DB @@ -71,7 +96,7 @@ class phpbb_notification_manager 'count_total' => false, ), $options); - // If all_unread, count_unread mus be true + // If all_unread, count_unread must be true $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; // Anonymous users and bots never receive notifications diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 5457ca99b2..88ec2674be 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -21,26 +21,35 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_method_base implements phpbb_notification_method_interface { - protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; + /** @var phpbb_notification_manager */ + protected $notification_manager = null; - /** - * Desired notifications - * unique by (type, type_id, user_id, method) - * if multiple methods are desired, multiple rows will exist. - * - * method of "none" will over-ride any other options - * - * item_type - * item_id - * user_id - * method - * none (will never receive notifications) - * standard (listed in notifications window - * popup? - * email - * jabber - * sms? - */ + /** @var dbal */ + protected $db = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var phpbb_template */ + protected $template = null; + + /** @var phpbb_extension_manager */ + protected $extension_manager = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_config */ + protected $config = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; /** * Queue of messages to be sent diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index afd6a9fc9b..39a21a1054 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -21,7 +21,35 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_type_base implements phpbb_notification_type_interface { - protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; + /** @var phpbb_notification_manager */ + protected $notification_manager = null; + + /** @var dbal */ + protected $db = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var phpbb_template */ + protected $template = null; + + /** @var phpbb_extension_manager */ + protected $extension_manager = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_config */ + protected $config = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; /** * Array of user data containing information needed to output the notifications to the template -- cgit v1.2.1 From f96dac335287f2fd51ff6628facbc8b6af6a517f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 18 Oct 2012 19:13:47 -0500 Subject: [ticket/11103] Interface docblocks PHPBB3-11103 --- phpBB/includes/notification/method/email.php | 3 + phpBB/includes/notification/method/interface.php | 19 +++ phpBB/includes/notification/type/base.php | 128 ++++++++++---------- phpBB/includes/notification/type/interface.php | 146 +++++++++++++++++++++-- phpBB/includes/notification/type/post.php | 4 - phpBB/includes/notification/type/report_pm.php | 4 +- 6 files changed, 222 insertions(+), 82 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index c2e272aca1..e902ea1e85 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -40,6 +40,9 @@ class phpbb_notification_method_email extends phpbb_notification_method_base return true; } + /** + * Parse the queue and notify the users + */ public function notify() { if (!sizeof($this->queue)) diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/includes/notification/method/interface.php index 4b990ec9fa..f5c210a2fc 100644 --- a/phpBB/includes/notification/method/interface.php +++ b/phpBB/includes/notification/method/interface.php @@ -21,7 +21,26 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notification_method_interface { + /** + * Is this method available for the user? + * This is checked on the notifications options + */ public function is_available(); + /** + * Add a notification to the queue + * + * @param phpbb_notification_type_interface $notification + */ + public function add_to_queue(phpbb_notification_type_interface $notification); + + /** + * Empty the queue + */ + protected function empty_queue(); + + /** + * Parse the queue and notify the users + */ public function notify(); } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 39a21a1054..22824dc2ed 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -149,60 +149,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->data['data'][$name] = $value; } - /** - * Prepare to output the notification to the template - */ - public function prepare_for_display() - { - if ($this->get_url()) - { - $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id); - } - else - { - $redirect = (($this->user->page['page_dir']) ? $this->user->page['page_dir'] . '/' : '') . $this->user->page['page_name'] . (($this->user->page['query_string']) ? '?' . $this->user->page['query_string'] : ''); - - $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&redirect=' . urlencode($redirect)); - } - - return array( - 'NOTIFICATION_ID' => $this->notification_id, - - 'AVATAR' => $this->get_avatar(), - - 'FORMATTED_TITLE' => $this->get_title(), - - 'URL' => $this->get_url(), - 'TIME' => $this->user->format_date($this->time), - - 'UNREAD' => $this->unread, - - 'U_MARK_READ' => ($this->unread) ? $u_mark_read : '', - ); - } - - /** - * Mark this item read - * - * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string - */ - public function mark_read($return = false) - { - return $this->mark(false, $return); - } - - /** - * Mark this item unread - * - * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string - */ - public function mark_unread($return = false) - { - return $this->mark(true, $return); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -256,12 +202,66 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i return $data; } + /** + * Mark this item read + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_read($return = false) + { + return $this->mark(false, $return); + } + + /** + * Mark this item unread + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_unread($return = false) + { + return $this->mark(true, $return); + } + + /** + * Prepare to output the notification to the template + */ + public function prepare_for_display() + { + if ($this->get_url()) + { + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id); + } + else + { + $redirect = (($this->user->page['page_dir']) ? $this->user->page['page_dir'] . '/' : '') . $this->user->page['page_name'] . (($this->user->page['query_string']) ? '?' . $this->user->page['query_string'] : ''); + + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&redirect=' . urlencode($redirect)); + } + + return array( + 'NOTIFICATION_ID' => $this->notification_id, + + 'AVATAR' => $this->get_avatar(), + + 'FORMATTED_TITLE' => $this->get_title(), + + 'URL' => $this->get_url(), + 'TIME' => $this->user->format_date($this->time), + + 'UNREAD' => $this->unread, + + 'U_MARK_READ' => ($this->unread) ? $u_mark_read : '', + ); + } + /** * -------------- Fall back functions ------------------- */ /** - * URL to unsubscribe to this notification (fall-back) + * URL to unsubscribe to this notification (fall back) * * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item */ @@ -271,7 +271,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Get the user's avatar (fall-back) + * Get the user's avatar (fall back) */ public function get_avatar() { @@ -279,7 +279,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Get the special items to load (fall-back) + * Get the special items to load (fall back) */ public function get_load_special() { @@ -287,7 +287,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Load the special items (fall-back) + * Load the special items (fall back) */ public function load_special($data, $notifications) { @@ -295,7 +295,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Is available (fall-back) + * Is available (fall back) */ public function is_available() { @@ -303,15 +303,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Pre create insert array function - * This allows you to perform certain actions, like run a query - * and load data, before create_insert_array() is run. The data - * returned from this function will be sent to create_insert_array(). - * - * @param array $type_data Data unique to this notification type - * @param array $notify_users Notify users list - * Formated from find_users_for_notification() - * @return array Whatever you want to send to create_insert_array(). + * Pre create insert array function (fall back) */ public function pre_create_insert_array($type_data, $notify_users) { diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 084a819af7..1d79a2c8d8 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -21,33 +21,161 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notification_type_interface { + /** + * Set initial data from the database + * + * @param array $data Row directly from the database + */ + public function set_initial_data($data); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ public static function get_item_type(); + /** + * Get the id of the item + * + * @param array $type_data The type specific data + */ public static function get_item_id($type_data); + /** + * Get the id of the parent + * + * @param array $type_data The type specific data + */ + public static function get_item_parent_id($type_data); + + /** + * Is this type available to the current user (defines whether or not it will be shown in the UCP Edit notification options) + * + * @return bool True/False whether or not this is available to the user + */ public function is_available(); + /** + * Find the users who want to receive notifications + * + * @param array $type_data The type specific data + * @param array $options Options for finding users for notification + * ignore_users => array of users and user types that should not receive notifications from this type because they've already been notified + * e.g.: array(2 => array(''), 3 => array('', 'email'), ...) + * + * @return array + */ public function find_users_for_notification($type_data, $options); - public function get_title(); + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query(); - public function get_email_template_variables(); + /** + * Get the special items to load + * + * @return array Data will be combined sent to load_special() so you can run a single query and get data required for this notification type + */ + public function get_load_special(); + /** + * Load the special items + * + * @param array $data Data from get_load_special() + * @param array $notifications Array of notifications (key is notification_id, value is the notification objects) + */ + public function load_special($data, $notifications); + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title(); + + /** + * Get the url to this item + * + * @return string URL + */ public function get_url(); + /** + * URL to unsubscribe to this notification + * + * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item + */ public function get_unsubscribe_url($method); - public function mark_read($return); - - public function mark_unread($return); + /** + * Get the user's avatar (the user who caused the notification typically) + * + * @return string + */ + public function get_avatar(); + + /** + * Prepare to output the notification to the template + */ + public function prepare_for_display(); + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables(); + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $type_data The type specific data + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ public function pre_create_insert_array($type_data, $notify_users); + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $type_data The type specific data + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ public function create_insert_array($type_data, $pre_create_data); - public function users_to_query(); - - public function get_load_special(); + /** + * Function for preparing the data for update in an SQL query + * (The service handles insertion) + * + * @param array $type_data Data unique to this notification type + * + * @return array Array of data ready to be updated in the database + */ + public function create_update_array($type_data); + + /** + * Mark this item read + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_read($return); - public function load_special($data, $notifications); + /** + * Mark this item unread + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_unread($return); } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 0681b4418c..f5f3936c63 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -89,10 +89,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base 'ignore_users' => array(), ), $options); - // Let's continue to use the phpBB subscriptions system, at least for now. - // It may not be the nicest thing, but it is already working and it would be significant work to replace it - //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); - $users = array(); $sql = 'SELECT user_id diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 3327dbe734..d78c108f56 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -76,7 +76,9 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm } /** - * Is available + * Is this type available to the current user (defines whether or not it will be shown in the UCP Edit notification options) + * + * @return bool True/False whether or not this is available to the user */ public function is_available() { -- cgit v1.2.1 From 2c06c2bd3646585a5b02e6269be655287352a667 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 18 Oct 2012 19:20:54 -0500 Subject: [ticket/11103] Declare $ for jQuery, check for instance of, newlines at eof PHPBB3-11103 --- phpBB/includes/notification/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index a98e1f7af3..38c72ad755 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -518,7 +518,7 @@ class phpbb_notification_manager $class = $this->get_item_type_class($class_name); - if ($class->is_available() && method_exists($class_name, 'get_item_type')) + if ($class instanceof phpbb_notification_type_interface && $class->is_available() && method_exists($class_name, 'get_item_type')) { $options = array_merge(array( 'id' => $class_name::get_item_type(), @@ -556,7 +556,7 @@ class phpbb_notification_manager $method = $this->get_method_class($class_name); - if ($method->is_available()) + if ($method instanceof phpbb_notification_method_interface && $method->is_available()) { $subscription_methods[] = $method_name; } -- cgit v1.2.1 From 471ca5e7dc8276e80e790e05a2ae36dfe35cfe10 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 19 Oct 2012 15:49:49 -0500 Subject: [ticket/11103] Change is_disabled to is_enabled If you're following along and would like to update your DB, you can run the following queries to do so: ALTER TABLE phpbb_notifications CHANGE `is_disabled` `is_enabled` TINYINT( 1 ) NOT NULL DEFAULT '1'; UPDATE `phpbb_notifications` SET is_enabled = 1; PHPBB3-11103 --- phpBB/includes/notification/manager.php | 10 +++++----- phpBB/includes/notification/type/base.php | 12 ++++++------ phpBB/includes/notification/type/bookmark.php | 2 +- phpBB/includes/notification/type/post.php | 2 +- phpBB/includes/notification/type/quote.php | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 38c72ad755..3a4c4cd696 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -120,7 +120,7 @@ class phpbb_notification_manager FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); @@ -132,7 +132,7 @@ class phpbb_notification_manager $sql = 'SELECT COUNT(*) AS count FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); $total_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); @@ -145,7 +145,7 @@ class phpbb_notification_manager FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . ' - AND is_disabled = 0 + AND is_enabled = 1 ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); @@ -163,7 +163,7 @@ class phpbb_notification_manager WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' - AND is_disabled = 0 + AND is_is_enabled = 1 ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); @@ -374,7 +374,7 @@ class phpbb_notification_manager FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 22824dc2ed..ab2f76c650 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -68,14 +68,14 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Indentification data - * item_type - * item_id - * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) + * item_type - Type of the item (translates to the notification type) + * item_id - ID of the item (e.g. post_id, msg_id) + * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * user_id * unread - * is_disabled - EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! - * - Set is_disabled to 1 for all your notifications when your extension is disabled so they are ignored and do not cause errors. - * - When your extension is enabled again, set is_disabled to 0 and your notifications will be working again. + * is_enabled - EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! + * - Set is_enabled to 0 for all your notifications when your extension is disabled so they are ignored and do not cause errors. + * - When your extension is enabled again, set is_enabled to 1 and your notifications will be working again. * * time * data (special serialized field that each notification type can use to store stuff) diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index e5435b5829..dff7ac4c7d 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -114,7 +114,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index f5f3936c63..a5e822336d 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -145,7 +145,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 0cc183346f..4c615d8dc6 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -133,7 +133,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -163,7 +163,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_id = " . self::get_item_id($post) . ' - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { -- cgit v1.2.1 From 0ac9079d1c4e32ae04bb7b5da55fa030279ec9b5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 18:55:13 -0500 Subject: [ticket/11103] Replace $email_template with get_email_template() PHPBB3-11103 --- phpBB/includes/notification/method/email.php | 7 ++++++- phpBB/includes/notification/type/approve_post.php | 17 ++++++++++------- phpBB/includes/notification/type/approve_topic.php | 17 ++++++++++------- phpBB/includes/notification/type/base.php | 7 ------- phpBB/includes/notification/type/bookmark.php | 17 ++++++++++------- phpBB/includes/notification/type/disapprove_post.php | 17 ++++++++++------- phpBB/includes/notification/type/disapprove_topic.php | 17 ++++++++++------- phpBB/includes/notification/type/interface.php | 7 +++++++ phpBB/includes/notification/type/pm.php | 17 ++++++++++------- phpBB/includes/notification/type/post.php | 17 ++++++++++------- phpBB/includes/notification/type/post_in_queue.php | 17 ++++++++++------- phpBB/includes/notification/type/quote.php | 17 ++++++++++------- phpBB/includes/notification/type/report_pm.php | 17 ++++++++++------- phpBB/includes/notification/type/report_pm_closed.php | 10 ++++++++++ phpBB/includes/notification/type/report_post.php | 17 ++++++++++------- phpBB/includes/notification/type/report_post_closed.php | 10 ++++++++++ phpBB/includes/notification/type/topic.php | 17 ++++++++++------- phpBB/includes/notification/type/topic_in_queue.php | 17 ++++++++++------- 18 files changed, 163 insertions(+), 99 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index e902ea1e85..df7edb13e7 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -78,6 +78,11 @@ class phpbb_notification_method_email extends phpbb_notification_method_base // Time to go through the queue and send emails foreach ($this->queue as $notification) { + if ($notification->get_email_template() === false) + { + continue; + } + $user = $this->notification_manager->get_user($notification->user_id); if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) @@ -85,7 +90,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base continue; } - $messenger->template($notification->email_template, $user['user_lang']); + $messenger->template($notification->get_email_template(), $user['user_lang']); $messenger->to($user['user_email'], $user['username']); diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 6ed9b6c67c..4ed5124415 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_approve_post extends phpbb_notification_type_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'post_approved'; - /** * Language key used to output the text * @@ -166,4 +159,14 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'post_approved'; + } } diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 1ff5ae43bd..32a1de8cf8 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topic { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'topic_approved'; - /** * Language key used to output the text * @@ -162,4 +155,14 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_approved'; + } } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index ab2f76c650..4c496f0a22 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -51,13 +51,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var string */ protected $php_ext = null; - /** - * Array of user data containing information needed to output the notifications to the template - * - * @var array - */ - protected $users = array(); - /** * Notification option data (for outputting to the user) * diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index dff7ac4c7d..eb1a735249 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_bookmark extends phpbb_notification_type_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/bookmark'; - /** * Language key used to output the text * @@ -131,4 +124,14 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post return $notify_users; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/bookmark'; + } } diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 8044a3e0ea..d4e659c5f3 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_approve_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'post_disapproved'; - /** * Language key used to output the text * @@ -113,4 +106,14 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'post_disapproved'; + } } diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 04fec87014..4bbf458d4a 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_approve_topic { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'topic_disapproved'; - /** * Language key used to output the text * @@ -113,4 +106,14 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_disapproved'; + } } diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 1d79a2c8d8..25dc24d922 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -122,6 +122,13 @@ interface phpbb_notification_type_interface */ public function prepare_for_display(); + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template(); + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index dc4bd3b3a5..721af4bce5 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_pm extends phpbb_notification_type_base { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'privmsg_notify'; - /** * Get the type of notification this is * phpbb_notification_type_ @@ -129,6 +122,16 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base return $this->user->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'privmsg_notify'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index a5e822336d..9bb06e3620 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_post extends phpbb_notification_type_base { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'topic_notify'; - /** * Language key used to output the text * @@ -212,6 +205,16 @@ class phpbb_notification_type_post extends phpbb_notification_type_base ); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_notify'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 499fd1e8ed..0bf8685660 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/post_in_queue'; - /** * Language key used to output the text * @@ -151,4 +144,14 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/post_in_queue'; + } } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 4c615d8dc6..f700821353 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_quote extends phpbb_notification_type_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/quote'; - /** * regular expression to match to find usernames * @@ -201,6 +194,16 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post return true; } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/quote'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index d78c108f56..b18493ff29 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/report_pm'; - /** * Language key used to output the text * @@ -139,6 +132,16 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return $notify_users; } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/report_pm'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 8d79c8446b..0bde7dfe48 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -68,6 +68,16 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p return array($pm['reporter'] => array('')); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return false; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 151841ef02..f1ee073a4d 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_post extends phpbb_notification_type_post_in_queue { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/report_post'; - /** * Language key used to output the text * @@ -82,6 +75,16 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i return $notify_users; } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/report_post'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 3e66bde9bc..52bdadc547 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -68,6 +68,16 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type return array($post['reporter'] => array('')); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return false; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index a9beb469c3..4737031e87 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_topic extends phpbb_notification_type_base { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'newtopic_notify'; - /** * Language key used to output the text * @@ -179,6 +172,16 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base ); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'newtopic_notify'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index eb14c098e1..ee565ab6e6 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_topic { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/topic_in_queue'; - /** * Language key used to output the text * @@ -144,4 +137,14 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/topic_in_queue'; + } } -- cgit v1.2.1 From 52bb4a1bd60dfcaad99d1ac181d8a0372db9cc2b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 19:00:37 -0500 Subject: [ticket/11103] Do not have empty queue in the interface This is not needed as it is not public. PHPBB3-11103 --- phpBB/includes/notification/method/interface.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/includes/notification/method/interface.php index f5c210a2fc..3c6c757d5c 100644 --- a/phpBB/includes/notification/method/interface.php +++ b/phpBB/includes/notification/method/interface.php @@ -34,11 +34,6 @@ interface phpbb_notification_method_interface */ public function add_to_queue(phpbb_notification_type_interface $notification); - /** - * Empty the queue - */ - protected function empty_queue(); - /** * Parse the queue and notify the users */ -- cgit v1.2.1 From 94d682f77431add84867bb0b196ad0719b293606 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 20:54:18 -0500 Subject: [ticket/11103] Use the full class name as the item_type/method This is going to require you recreate the db tables. PHPBB3-11103 --- phpBB/includes/notification/manager.php | 200 +++++++-------------- phpBB/includes/notification/type/approve_post.php | 9 - phpBB/includes/notification/type/approve_topic.php | 9 - phpBB/includes/notification/type/base.php | 6 +- phpBB/includes/notification/type/bookmark.php | 20 ++- .../includes/notification/type/disapprove_post.php | 9 - .../notification/type/disapprove_topic.php | 9 - phpBB/includes/notification/type/interface.php | 6 - phpBB/includes/notification/type/pm.php | 15 +- phpBB/includes/notification/type/post.php | 16 +- phpBB/includes/notification/type/post_in_queue.php | 9 - phpBB/includes/notification/type/quote.php | 26 +-- phpBB/includes/notification/type/report_pm.php | 9 - .../notification/type/report_pm_closed.php | 9 - phpBB/includes/notification/type/report_post.php | 9 - .../notification/type/report_post_closed.php | 9 - phpBB/includes/notification/type/topic.php | 12 +- .../includes/notification/type/topic_in_queue.php | 9 - 18 files changed, 109 insertions(+), 282 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 3a4c4cd696..06ebaf24c4 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -138,32 +138,16 @@ class phpbb_notification_manager $this->db->sql_freeresult($result); } - $rowset = array(); - - // Get the main notifications - $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $options['user_id'] . - (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . ' - AND is_enabled = 1 - ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); - $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); - - while ($row = $this->db->sql_fetchrow($result)) + if (!$options['count_total'] || $total_count) { - $rowset[$row['notification_id']] = $row; - } - $this->db->sql_freeresult($result); + $rowset = array(); - // Get all unread notifications - if ($unread_count && $options['all_unread'] && !empty($rowset)) - { + // Get the main notifications $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $options['user_id'] . ' - AND unread = 1 - AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' - AND is_is_enabled = 1 + WHERE user_id = ' . (int) $options['user_id'] . + (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . ' + AND is_enabled = 1 ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); @@ -172,37 +156,52 @@ class phpbb_notification_manager $rowset[$row['notification_id']] = $row; } $this->db->sql_freeresult($result); - } - - foreach ($rowset as $row) - { - $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); - $notification = $this->get_item_type_class($item_type_class_name, $row); - - // Array of user_ids to query all at once - $user_ids = array_merge($user_ids, $notification->users_to_query()); - - // Some notification types also require querying additional tables themselves - if (!isset($load_special[$row['item_type']])) + // Get all unread notifications + if ($unread_count && $options['all_unread'] && !empty($rowset)) { - $load_special[$row['item_type']] = array(); + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id'] . ' + AND unread = 1 + AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' + AND is_enabled = 1 + ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); + $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); + + while ($row = $this->db->sql_fetchrow($result)) + { + $rowset[$row['notification_id']] = $row; + } + $this->db->sql_freeresult($result); } - $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); - $notifications[$row['notification_id']] = $notification; - } + foreach ($rowset as $row) + { + $notification = $this->get_item_type_class($row['item_type'], $row); - $this->load_users($user_ids); + // Array of user_ids to query all at once + $user_ids = array_merge($user_ids, $notification->users_to_query()); - // Allow each type to load its own special items - foreach ($load_special as $item_type => $data) - { - $item_type_class_name = $this->get_item_type_class_name($item_type, true); + // Some notification types also require querying additional tables themselves + if (!isset($load_special[$row['item_type']])) + { + $load_special[$row['item_type']] = array(); + } + $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); + + $notifications[$row['notification_id']] = $notification; + } + + $this->load_users($user_ids); - $item_class = $this->get_item_type_class($item_type_class_name); + // Allow each type to load its own special items + foreach ($load_special as $item_type => $data) + { + $item_class = $this->get_item_type_class($item_type); - $item_class->load_special($data, $notifications); + $item_class->load_special($data, $notifications); + } } return array( @@ -234,11 +233,6 @@ class phpbb_notification_manager $time = ($time) ?: time(); - if ($item_type !== false) - { - $this->get_item_type_class_name($item_type); - } - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 WHERE time <= " . $time . @@ -270,8 +264,6 @@ class phpbb_notification_manager $time = ($time) ?: time(); - $item_type_class_name = $this->get_item_type_class_name($item_type); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' @@ -326,12 +318,10 @@ class phpbb_notification_manager return $notified_users; } - $item_type_class_name = $this->get_item_type_class_name($item_type); - - $item_id = $item_type_class_name::get_item_id($data); + $item_id = $item_type::get_item_id($data); // find out which users want to receive this type of notification - $notify_users = $this->get_item_type_class($item_type_class_name)->find_users_for_notification($data, $options); + $notify_users = $this->get_item_type_class($item_type)->find_users_for_notification($data, $options); $this->add_notifications_for_users($item_type, $data, $notify_users); @@ -357,9 +347,7 @@ class phpbb_notification_manager return; } - $item_type_class_name = $this->get_item_type_class_name($item_type); - - $item_id = $item_type_class_name::get_item_id($data); + $item_id = $item_type::get_item_id($data); $user_ids = array(); $notification_objects = $notification_methods = array(); @@ -388,14 +376,14 @@ class phpbb_notification_manager } // Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications) - $notification = $this->get_item_type_class($item_type_class_name); + $notification = $this->get_item_type_class($item_type); $pre_create_data = $notification->pre_create_insert_array($data, $notify_users); unset($notification); // Go through each user so we can insert a row in the DB and then notify them by their desired means foreach ($notify_users as $user => $methods) { - $notification = $this->get_item_type_class($item_type_class_name); + $notification = $this->get_item_type_class($item_type); $notification->user_id = (int) $user; @@ -412,8 +400,7 @@ class phpbb_notification_manager { if (!isset($notification_methods[$method])) { - $method_class_name = 'phpbb_notification_method_' . $method; - $notification_methods[$method] = $this->get_method_class($method_class_name); + $notification_methods[$method] = $this->get_method_class($method); } $notification_methods[$method]->add_to_queue($notification); @@ -452,21 +439,19 @@ class phpbb_notification_manager return; } - $item_type_class_name = $this->get_item_type_class_name($item_type); + $notification = $this->get_item_type_class($item_type); // Allow the notifications class to over-ride the update_notifications functionality - if (method_exists($item_type_class_name, 'update_notifications')) + if (method_exists($notification, 'update_notifications')) { // Return False to over-ride the rest of the update - if ($this->get_item_type_class($item_type_class_name)->update_notifications($data) === false) + if ($notification->update_notifications($data) === false) { return; } } - $item_id = $item_type_class_name::get_item_id($data); - - $notification = $this->get_item_type_class($item_type_class_name); + $item_id = $item_type::get_item_id($data); $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' @@ -495,8 +480,6 @@ class phpbb_notification_manager return; } - $this->get_item_type_class_name($item_type); - $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id); @@ -512,17 +495,15 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->get_subscription_files('notification/type/') as $class_name => $file) + foreach ($this->get_subscription_files('notification/type/') as $class_name) { - $class_name = $this->get_item_type_class_name($class_name); - $class = $this->get_item_type_class($class_name); - if ($class instanceof phpbb_notification_type_interface && $class->is_available() && method_exists($class_name, 'get_item_type')) + if ($class instanceof phpbb_notification_type_interface && $class->is_available()) { $options = array_merge(array( - 'id' => $class_name::get_item_type(), - 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name::get_item_type()), + 'id' => $class_name, + 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name), 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', ), (($class_name::$notification_option !== false) ? $class_name::$notification_option : array())); @@ -550,15 +531,13 @@ class phpbb_notification_manager { $subscription_methods = array(); - foreach ($this->get_subscription_files('notification/method/') as $method_name => $file) + foreach ($this->get_subscription_files('notification/method/') as $class_name) { - $class_name = 'phpbb_notification_method_' . $method_name; - $method = $this->get_method_class($class_name); if ($method instanceof phpbb_notification_method_interface && $method->is_available()) { - $subscription_methods[] = $method_name; + $subscription_methods[] = $class_name; } } @@ -615,8 +594,6 @@ class phpbb_notification_manager */ public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false) { - $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . @@ -639,8 +616,6 @@ class phpbb_notification_manager */ public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false) { - $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " @@ -692,37 +667,11 @@ class phpbb_notification_manager return (isset($this->users[$user_id])) ? $this->users[$user_id] : $this->users[ANONYMOUS]; } - /** - * Helper to get the notifications item type class name and clean it if unsafe - */ - private function get_item_type_class_name(&$item_type, $safe = false) - { - if (!$safe) - { - $item_type = preg_replace('#[^a-z_-]#', '', $item_type); - } - - if (strpos($item_type, 'ext_') === 0) - { - $item_type_ary = explode('-', substr($item_type, 4), 2); - - return 'phpbb_ext_' . $item_type_ary[0] . '_notification_type_' . $item_type_ary[1]; - } - - return 'phpbb_notification_type_' . $item_type; - } - /** * Helper to get the notifications item type class and set it up */ public function get_item_type_class($item_type, $data = array()) { - if (!strpos($item_type, 'notification_type_')) - { - $item_class = $this->get_item_type_class_name($item_type); - $item_type = $item_class; - } - $item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); $item->set_initial_data($data); @@ -747,31 +696,16 @@ class phpbb_notification_manager $subscription_files = array(); - $files = $finder + $classes = $finder ->core_path('includes/' . $path) ->extension_directory($path) - ->get_files(); - foreach ($files as $file) - { - $name = substr($file, strrpos($file, '/')); - $name = substr($name, 1, (strpos($name, '.' . $this->php_ext) - 1)); + ->get_classes(); - if ($name == 'interface' || $name == 'base') - { - continue; - } - - if (!strpos($file, 'includes/')) // is an extension - { - $ext_name = substr($file, (strpos($file, 'ext/') + 4)); - $ext_name = substr($ext_name, 0, strpos($ext_name, '/')); - - $name = 'ext_' . $ext_name . '-' . $name; - } - - $subscription_files[$name] = $file; - } + unset($classes[array_search('phpbb_notification_type_interface', $classes)]); + unset($classes[array_search('phpbb_notification_type_base', $classes)]); + unset($classes[array_search('phpbb_notification_method_interface', $classes)]); + unset($classes[array_search('phpbb_notification_method_base', $classes)]); - return $subscription_files; + return $classes; } } diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 4ed5124415..46f2c16c14 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -42,15 +42,6 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post 'group' => 'NOTIFICATION_GROUP_POSTING', ); - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'approve_post'; - } - /** * Is available */ diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 32a1de8cf8..0015858c2e 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -42,15 +42,6 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi 'group' => 'NOTIFICATION_GROUP_POSTING', ); - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'approve_topic'; - } - /** * Is available */ diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 4c496f0a22..df04dc2a49 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -116,7 +116,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i public function __toString() { - return (!empty($this->data)) ? var_export($this->data, true) : static::get_item_type(); + return (!empty($this->data)) ? var_export($this->data, true) : get_class($this); } /** @@ -156,7 +156,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i // Defaults $this->data = array_merge(array( 'item_id' => static::get_item_id($type_data), - 'item_type' => $this->get_item_type(), + 'item_type' => get_class($this), 'item_parent_id' => static::get_item_parent_id($type_data), 'time' => time(), @@ -324,7 +324,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . static::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND item_id = " . (int) $item_id; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index eb1a735249..4d5a1fd299 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -31,13 +31,15 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post protected $language_key = 'NOTIFICATION_BOOKMARK'; /** - * Get the type of notification this is - * phpbb_notification_type_ + * 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') */ - public static function get_item_type() - { - return 'bookmark'; - } + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_BOOKMARK', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); /** * Find the users who want to receive notifications @@ -81,7 +83,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) @@ -104,7 +106,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $update_notifications = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 AND is_enabled = 1'; @@ -114,7 +116,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post // Do not create a new notification unset($notify_users[$row['user_id']]); - $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $notification = $this->notification_manager->get_item_type_class(get_class($this), $row); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index d4e659c5f3..3b5719c3fe 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -42,15 +42,6 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap 'group' => 'NOTIFICATION_GROUP_POSTING', ); - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'disapprove_post'; - } - /** * Get the HTML formatted title of this notification * diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 4bbf458d4a..7369fd64bd 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -42,15 +42,6 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a 'group' => 'NOTIFICATION_GROUP_POSTING', ); - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'disapprove_topic'; - } - /** * Get the HTML formatted title of this notification * diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 25dc24d922..9d9965261e 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -28,12 +28,6 @@ interface phpbb_notification_type_interface */ public function set_initial_data($data); - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type(); - /** * Get the id of the item * diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 721af4bce5..adb03ab1a3 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -24,13 +24,14 @@ if (!defined('IN_PHPBB')) class phpbb_notification_type_pm extends phpbb_notification_type_base { /** - * Get the type of notification this is - * phpbb_notification_type_ + * 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') */ - public static function get_item_type() - { - return 'pm'; - } + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_PM', + ); /** * Get the id of the @@ -77,7 +78,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])) . ' AND user_id <> ' . $pm['from_user_id']; $result = $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 9bb06e3620..9317669e57 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -37,18 +37,10 @@ class phpbb_notification_type_post extends phpbb_notification_type_base * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_POST', 'group' => 'NOTIFICATION_GROUP_POSTING', ); - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'post'; - } - /** * Get the id of the item * @@ -112,7 +104,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) @@ -135,7 +127,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $update_notifications = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 AND is_enabled = 1'; @@ -145,7 +137,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Do not create a new notification unset($notify_users[$row['user_id']]); - $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $notification = $this->notification_manager->get_item_type_class(get_class($this), $row); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 0bf8685660..5771b60df7 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -49,15 +49,6 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post */ protected $permission = 'm_approve'; - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'post_in_queue'; - } - /** * Is available */ diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index f700821353..e4b40e0aec 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -38,13 +38,15 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post protected $language_key = 'NOTIFICATION_QUOTE'; /** - * Get the type of notification this is - * phpbb_notification_type_ + * 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') */ - public static function get_item_type() - { - return 'quote'; - } + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_QUOTE', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); /** * Find the users who want to receive notifications @@ -100,7 +102,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) @@ -123,7 +125,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $update_notifications = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 AND is_enabled = 1'; @@ -133,7 +135,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // Do not create a new notification unset($notify_users[$row['user_id']]); - $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $notification = $this->notification_manager->get_item_type_class(get_class($this), $row); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; @@ -154,7 +156,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $old_notifications = array(); $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND item_id = " . self::get_item_id($post) . ' AND is_enabled = 1'; $result = $this->db->sql_query($sql); @@ -178,13 +180,13 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post } // Add the necessary notifications - $this->notification_manager->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); + $this->notification_manager->add_notifications_for_users(get_class($this), $post, $add_notifications); // Remove the necessary notifications if (!empty($remove_notifications)) { $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND item_id = " . self::get_item_id($post) . ' AND ' . $this->db->sql_in_set('user_id', $remove_notifications); $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index b18493ff29..42631ca97a 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -49,15 +49,6 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm 'group' => 'NOTIFICATION_GROUP_MODERATION', ); - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'report_pm'; - } - /** * Get the id of the parent * diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 0bde7dfe48..a7dd341d1d 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -42,15 +42,6 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p return false; } - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'report_pm_closed'; - } - /** * Find the users who want to receive notifications * diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index f1ee073a4d..2a493d7f2a 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -49,15 +49,6 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i 'group' => 'NOTIFICATION_GROUP_MODERATION', ); - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'report_post'; - } - /** * Find the users who want to receive notifications * diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 52bdadc547..38be1d9fee 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -42,15 +42,6 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type return false; } - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'report_post_closed'; - } - /** * Find the users who want to receive notifications * diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 4737031e87..db1d4028f0 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -37,18 +37,10 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_TOPIC', 'group' => 'NOTIFICATION_GROUP_POSTING', ); - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'topic'; - } - /** * Get the id of the item * @@ -116,7 +108,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND " . $this->db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index ee565ab6e6..91e12fcfbf 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -52,15 +52,6 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top return (!empty($m_approve)); } - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'topic_in_queue'; - } - /** * Find the users who want to receive notifications * -- cgit v1.2.1 From de7e17b7321feebbefb5249febbbfe173e275ada Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 21:22:06 -0500 Subject: [ticket/11103] Notifications for subscriptions/bookmarks must obey ACP options If bookmarks/subscriptions are disabled, they should not be listed in the UCP PHPBB3-11103 --- phpBB/includes/notification/type/bookmark.php | 8 ++++++++ phpBB/includes/notification/type/post.php | 8 ++++++++ phpBB/includes/notification/type/quote.php | 8 ++++++++ phpBB/includes/notification/type/topic.php | 8 ++++++++ 4 files changed, 32 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 4d5a1fd299..4bbe9bbbf4 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -41,6 +41,14 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** + * Is available + */ + public function is_available() + { + return $this->config['allow_bookmarks']; + } + /** * Find the users who want to receive notifications * diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 9317669e57..11202ee6e9 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -41,6 +41,14 @@ class phpbb_notification_type_post extends phpbb_notification_type_base 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** + * Is available + */ + public function is_available() + { + return $this->config['allow_topic_notify']; + } + /** * Get the id of the item * diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index e4b40e0aec..47337b1cda 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -48,6 +48,14 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** + * Is available + */ + public function is_available() + { + return true; + } + /** * Find the users who want to receive notifications * diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index db1d4028f0..99f7b5bee4 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -41,6 +41,14 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** + * Is available + */ + public function is_available() + { + return $this->config['allow_forum_notify']; + } + /** * Get the id of the item * -- cgit v1.2.1 From f62e55091aac6aa62c56dde172f2f2bb0371f7fd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 21:26:39 -0500 Subject: [ticket/11103] PM notifications are not available if users cannot read them PHPBB3-11103 --- phpBB/includes/notification/type/pm.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index adb03ab1a3..697feca962 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -33,6 +33,14 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base 'lang' => 'NOTIFICATION_TYPE_PM', ); + /** + * Is available + */ + public function is_available() + { + return ($this->config['allow_privmsg'] && $this->auth->acl_get('u_readpm')); + } + /** * Get the id of the * -- cgit v1.2.1 From 7e6f31b51d51b1ea6416ed15c425acbb669c463d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 21:45:15 -0500 Subject: [ticket/11103] Correct the comments on the notification classes PHPBB3-11103 --- phpBB/includes/notification/type/approve_post.php | 4 ++-- phpBB/includes/notification/type/approve_topic.php | 4 ++-- phpBB/includes/notification/type/disapprove_post.php | 4 ++-- phpBB/includes/notification/type/disapprove_topic.php | 4 ++-- phpBB/includes/notification/type/post_in_queue.php | 4 ++-- phpBB/includes/notification/type/report_pm.php | 4 ++-- phpBB/includes/notification/type/report_pm_closed.php | 4 ++-- phpBB/includes/notification/type/report_post_closed.php | 4 ++-- phpBB/includes/notification/type/topic_in_queue.php | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 46f2c16c14..e08039baa9 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Post notifications class -* This class handles notifications for replies to a topic +* Post approved notifications class +* This class handles notifications for posts when they are approved (to their authors) * * @package notifications */ diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 0015858c2e..6d3f8e60ae 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Post notifications class -* This class handles notifications for replies to a topic +* Topic approved notifications class +* This class handles notifications for topics when they are approved (for authors) * * @package notifications */ diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 3b5719c3fe..ddacd4d367 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Post notifications class -* This class handles notifications for replies to a topic +* Post disapproved notifications class +* This class handles notifications for posts when they are disapproved (for authors) * * @package notifications */ diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 7369fd64bd..dfda4f8371 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Post notifications class -* This class handles notifications for replies to a topic +* Topic disapproved notifications class +* This class handles notifications for topics when they are disapproved (for authors) * * @package notifications */ diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 5771b60df7..d0f5f22e0f 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Topic notifications class -* This class handles notifications for new topics +* Post in queue notifications class +* This class handles notifications for posts that are put in the moderation queue (for moderators) * * @package notifications */ diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 42631ca97a..b2f514d483 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Private message notifications class -* This class handles notifications for reporting private messages +* Private message reproted notifications class +* This class handles notifications for private messages when they are reported * * @package notifications */ diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index a7dd341d1d..46bca8d831 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Reported pm notifications class -* This class handles notifications for reported pms +* PM report closed notifications class +* This class handles notifications for when reports are closed on PMs (for the one who reported the PM) * * @package notifications */ diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 38be1d9fee..34b69dbe47 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Reported post notifications class -* This class handles notifications for reported posts +* Post report closed notifications class +* This class handles notifications for when reports are closed on posts (for the one who reported the post) * * @package notifications */ diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 91e12fcfbf..f99fde4c75 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Topic notifications class -* This class handles notifications for new topics +* Topic in queue notifications class +* This class handles notifications for topics when they are put in the moderation queue (for moderators) * * @package notifications */ -- cgit v1.2.1 From bc18e368c36af90b2e998913e827dc7be71f3bd0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 21:55:58 -0500 Subject: [ticket/11103] Correct the test case Fix a bug that broke it and make sure to set the needed config/auth settings PHPBB3-11103 --- phpBB/includes/notification/manager.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 06ebaf24c4..75155c5dc3 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -701,10 +701,25 @@ class phpbb_notification_manager ->extension_directory($path) ->get_classes(); - unset($classes[array_search('phpbb_notification_type_interface', $classes)]); - unset($classes[array_search('phpbb_notification_type_base', $classes)]); - unset($classes[array_search('phpbb_notification_method_interface', $classes)]); - unset($classes[array_search('phpbb_notification_method_base', $classes)]); + if (array_search('phpbb_notification_type_interface', $classes) !== false) + { + unset($classes[array_search('phpbb_notification_type_interface', $classes)]); + } + + if (array_search('phpbb_notification_type_base', $classes) !== false) + { + unset($classes[array_search('phpbb_notification_type_base', $classes)]); + } + + if (array_search('phpbb_notification_method_interface', $classes) !== false) + { + unset($classes[array_search('phpbb_notification_method_interface', $classes)]); + } + + if (array_search('phpbb_notification_method_base', $classes) !== false) + { + unset($classes[array_search('phpbb_notification_method_base', $classes)]); + } return $classes; } -- cgit v1.2.1 From e549b7663da47d7518b93074e513c7e1d034bf52 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:09:20 -0500 Subject: [ticket/11103] Set basic notifications to be enabled by default Now, if there is no row for the user in the user_notifications table, the user will receive basic notifications. If the user wishes to not receive notifications, a row must be added with notify = 0. For other methods besides the basic (e.g. email, jabber) a row must still be added with notify = 1 for them to receive notifications PHPBB3-11103 --- phpBB/includes/notification/manager.php | 131 +++++++++++++++++---- phpBB/includes/notification/type/approve_post.php | 27 +---- phpBB/includes/notification/type/approve_topic.php | 27 +---- phpBB/includes/notification/type/base.php | 54 +++++++-- phpBB/includes/notification/type/bookmark.php | 23 +--- phpBB/includes/notification/type/pm.php | 28 +---- phpBB/includes/notification/type/post.php | 23 +--- phpBB/includes/notification/type/post_in_queue.php | 27 +---- phpBB/includes/notification/type/quote.php | 23 +--- phpBB/includes/notification/type/report_pm.php | 27 +---- phpBB/includes/notification/type/topic.php | 29 +---- .../includes/notification/type/topic_in_queue.php | 27 +---- 12 files changed, 175 insertions(+), 271 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 75155c5dc3..3e816108f4 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -545,41 +545,57 @@ class phpbb_notification_manager } /** - * Get subscriptions + * Get global subscriptions (item_id = 0) * * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) - * @param bool $only_global True to select only global subscription options (item_id = 0) * * @return array Subscriptions */ - public function get_subscriptions($user_id = false, $only_global = false) + public function get_global_subscriptions($user_id = false) { $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $subscriptions = array(); - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $user_id . - (($only_global) ? ' AND item_id = 0' : ''); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) + foreach ($this->get_subscription_types() as $group_name => $types) { - if ($only_global) + foreach ($types as $id => $type) { - if (!isset($subscriptions[$row['item_type']])) + $sql = 'SELECT method, notify + FROM ' . USER_NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $user_id . " + AND item_type = '" . $this->db->sql_escape($id) . "' + AND item_id = 0"; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + if (!$row) { - $subscriptions[$row['item_type']] = array(); + // No rows at all, default to '' + $subscriptions[$id] = array(''); } + else + { + do + { + if (!$row['notify']) + { + continue; + } - $subscriptions[$row['item_type']][] = $row['method']; - } - else - { - $subscriptions[] = $row; + if (!isset($subscriptions[$id])) + { + $subscriptions[$id] = array(); + } + + $subscriptions[$id][] = $row['method']; + } + while ($row = $this->db->sql_fetchrow($result)); + } + + $this->db->sql_freeresult($result); } } - $this->db->sql_freeresult($result); return $subscriptions; } @@ -594,16 +610,45 @@ class phpbb_notification_manager */ public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false) { + if ($method !== '') + { + $this->add_subscription($item_type, $item_type, '', $user_id); + } + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; - $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . - $this->db->sql_build_array('INSERT', array( - 'item_type' => $item_type, - 'item_id' => (int) $item_id, - 'user_id' => (int) $user_id, - 'method' => $method, - )); + $sql = 'SELECT notify + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; $this->db->sql_query($sql); + $current = $this->db->sql_fetchfield('notify'); + $this->db->sql_freeresult(); + + if ($current === false) + { + $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => (int) $user_id, + 'method' => $method, + 'notify' => 1, + )); + $this->db->sql_query($sql); + } + else if (!$current) + { + $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . " + SET notify = 1 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; + $this->db->sql_query($sql); + } } /** @@ -618,12 +663,46 @@ class phpbb_notification_manager { $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; - $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " + // If no method, make sure that no other notification methods for this item are selected before deleting + if ($method === '') + { + $sql = 'SELECT COUNT(*) as count + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method <> '' + AND notify = 1"; + $this->db->sql_query($sql); + $count = $this->db->sql_fetchfield('count'); + $this->db->sql_freeresult(); + + if ($count) + { + return; + } + } + + $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . " + SET notify = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND user_id = ' .(int) $user_id . " AND method = '" . $this->db->sql_escape($method) . "'"; $this->db->sql_query($sql); + + if (!$this->db->sql_affectedrows()) + { + $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => (int) $user_id, + 'method' => $method, + 'notify' => 0, + )); + $this->db->sql_query($sql); + } } /** diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index e08039baa9..26f56e6333 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -73,30 +73,9 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 6d3f8e60ae..78837f643d 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -73,30 +73,9 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index df04dc2a49..c2c52fe8e9 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -310,26 +310,54 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Find the users who want to receive notifications (helper) * - * @param array $item_id The item_id to search for + * @param array $user_ids User IDs to check if they want to receive notifications + * (Bool False to check all users besides anonymous and bots (USER_IGNORE)) * * @return array */ - protected function _find_users_for_notification($item_id, $options) + protected function check_user_notification_options($user_ids = false, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), + 'item_type' => get_class($this), + 'item_id' => 0, // Global by default ), $options); - $rowset = array(); + if ($user_ids === false) + { + $user_ids = array(); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE user_id <> ' . ANONYMOUS . ' + AND user_type <> ' . USER_IGNORE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $user_ids[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + } + + if (empty($user_ids)) + { + return array(); + } + + $rowset = $resulting_user_ids = array(); - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND item_id = " . (int) $item_id; + $sql = 'SELECT user_id, method, notify + FROM ' . USER_NOTIFICATIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . " + AND item_type = '" . $this->db->sql_escape($options['item_type']) . "' + AND item_id = " . (int) $options['item_id']; $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + $resulting_user_ids[] = $row['user_id']; + + if (!$row['notify'] || (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))) { continue; } @@ -341,8 +369,18 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $rowset[$row['user_id']][] = $row['method']; } + $this->db->sql_freeresult($result); + foreach ($user_ids as $user_id) + { + if (!in_array($user_id, $resulting_user_ids) && !isset($options['ignore_users'][$user_id])) + { + // No rows at all for this user, default to '' + $rowset[$user_id] = array(''); + } + } + return $rowset; } diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 4bbe9bbbf4..6fe00d9dd0 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -87,28 +87,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); + $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 697feca962..a60d022a12 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -80,33 +80,11 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base return array(); } - $this->notification_manager->load_users(array_keys($pm['recipients'])); - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])) . ' - AND user_id <> ' . $pm['from_user_id']; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } + unset($pm['recipients'][$pm['from_user_id']]); - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); + $this->notification_manager->load_users(array_keys($pm['recipients'])); - return $notify_users; + return $this->check_user_notification_options(array_keys($pm['recipients']), $options); } /** diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 11202ee6e9..22fb5cd980 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -108,28 +108,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); + $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index d0f5f22e0f..e9e7c6120e 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -82,30 +82,9 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $auth_approve[$post['forum_id']] = array_unique(array_merge($auth_approve[$post['forum_id']], $auth_approve[0])); - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 47337b1cda..c9f0f923c1 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -106,28 +106,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); + $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index b2f514d483..7cf97402cc 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -96,31 +96,14 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]) . ' - AND user_id <> ' . $this->user->data['user_id']; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) + if (($key = array_search($this->user->data['user_id'], $auth_approve[$post['forum_id']][$this->permission]))) { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; + unset($auth_approve[$post['forum_id']][$this->permission][$key]); } - $this->db->sql_freeresult($result); - return $notify_users; + return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 99f7b5bee4..fbee650ad8 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -82,10 +82,6 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base 'ignore_users' => array(), ), $options); - // Let's continue to use the phpBB subscriptions system, at least for now. - // It may not be the nicest thing, but it is already working and it would be significant work to replace it - //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); - $users = array(); $sql = 'SELECT user_id @@ -112,30 +108,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_read[$topic['forum_id']]['f_read'], $options); } /** diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index f99fde4c75..66aecb0d05 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -75,30 +75,9 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top $auth_approve[$topic['forum_id']] = array_unique(array_merge($auth_approve[$topic['forum_id']], $auth_approve[0])); - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_approve[$topic['forum_id']]['m_approve'], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** -- cgit v1.2.1 From ecf6f1eb8ca34da43b14b2da642cc7f1aa397d36 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:15:01 -0500 Subject: [ticket/11103] Code cleanup PHPBB3-11103 --- phpBB/includes/notification/manager.php | 2 +- phpBB/includes/notification/type/approve_post.php | 32 ---------------------- phpBB/includes/notification/type/approve_topic.php | 30 -------------------- 3 files changed, 1 insertion(+), 63 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 3e816108f4..ffdce2032d 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -231,7 +231,7 @@ class phpbb_notification_manager return; } - $time = ($time) ?: time(); + $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 26f56e6333..60b66fd4f6 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -78,38 +78,6 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post ))); } - /** - * Pre create insert array function - * This allows you to perform certain actions, like run a query - * and load data, before create_insert_array() is run. The data - * returned from this function will be sent to create_insert_array(). - * - * @param array $post Post data from submit_post - * @param array $notify_users Notify users list - * Formated from find_users_for_notification() - * @return array Whatever you want to send to create_insert_array(). - */ - public function pre_create_insert_array($post, $notify_users) - { - /*if (!sizeof($notify_users)) - { - return array(); - } - - // Mark the topic unread before the post - $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . ' - SET mark_time = ' . (int) ($post['post_time'] - 1) . ' - WHERE topic_id = ' . (int) $post['topic_id'] . ' - AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); - $this->db->sql_query($sql);*/ - - // In the parent class, this is used to check if the post is already - // read by a user and marks the notification read if it was marked read. - // Returning an empty array in effect, forces it to be marked as unread - // (and also saves a query) - return array(); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 78837f643d..4fd247a789 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -78,36 +78,6 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi ))); } - /** - * Pre create insert array function - * This allows you to perform certain actions, like run a query - * and load data, before create_insert_array() is run. The data - * returned from this function will be sent to create_insert_array(). - * - * @param array $post Post data from submit_post - * @param array $notify_users Notify users list - * Formated from find_users_for_notification() - * @return array Whatever you want to send to create_insert_array(). - */ - public function pre_create_insert_array($post, $notify_users) - { - /*if (!sizeof($notify_users)) - { - return array(); - } - - // Mark the topic unread - $sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . ' - WHERE topic_id = ' . (int) $post['topic_id'] . ' - AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); - $this->db->sql_query($sql*/ - - // In the parent class, this is used to check if the post is already - // read by a user and marks the notification read if it was marked read. - // Returning an empty array in effect, forces it to be marked as unread - return array(); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) -- cgit v1.2.1 From b60ae30b02c411db5ce3711f25e8f43a019ef9ec Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:20:07 -0500 Subject: [ticket/11103] More cleanup PHPBB3-11103 --- phpBB/includes/notification/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index ffdce2032d..b8c9c9742e 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -262,7 +262,7 @@ class phpbb_notification_manager return; } - $time = ($time) ?: time(); + $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 @@ -281,7 +281,7 @@ class phpbb_notification_manager */ public function mark_notifications_read_by_id($notification_id, $time = false) { - $time = ($time) ?: time(); + $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 -- cgit v1.2.1 From b1ba7b27ad611d674ac54f97ea602ea95c8955b0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:35:54 -0500 Subject: [ticket/11103] _get_avatar -> get_user_avatar PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 2 +- phpBB/includes/notification/type/pm.php | 2 +- phpBB/includes/notification/type/post.php | 2 +- phpBB/includes/notification/type/report_pm.php | 2 +- phpBB/includes/notification/type/report_pm_closed.php | 2 +- phpBB/includes/notification/type/report_post.php | 2 +- phpBB/includes/notification/type/report_post_closed.php | 2 +- phpBB/includes/notification/type/topic.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index c2c52fe8e9..fdd8a5b9cb 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -390,7 +390,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * @param int $user_id * @return string */ - protected function _get_avatar($user_id) + protected function get_user_avatar($user_id) { $user = $this->notification_manager->get_user($user_id); diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index a60d022a12..1c38002892 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -92,7 +92,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_avatar() { - return $this->_get_avatar($this->get_data('from_user_id')); + return $this->get_user_avatar($this->get_data('from_user_id')); } /** diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 22fb5cd980..b1a3ee9a26 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -140,7 +140,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function get_avatar() { - return $this->_get_avatar($this->get_data('poster_id')); + return $this->get_user_avatar($this->get_data('poster_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 7cf97402cc..63d153bd27 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -187,7 +187,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_avatar() { - return $this->_get_avatar($this->get_data('reporter_id')); + return $this->get_user_avatar($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 46bca8d831..c86fe77b0e 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -112,7 +112,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p */ public function get_avatar() { - return $this->_get_avatar($this->get_data('closer_id')); + return $this->get_user_avatar($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 2a493d7f2a..26dd9512bf 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -154,7 +154,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function get_avatar() { - return $this->_get_avatar($this->get_data('reporter_id')); + return $this->get_user_avatar($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 34b69dbe47..7454760dc0 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -112,7 +112,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function get_avatar() { - return $this->_get_avatar($this->get_data('closer_id')); + return $this->get_user_avatar($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index fbee650ad8..db268fa53e 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -116,7 +116,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function get_avatar() { - return $this->_get_avatar($this->get_data('poster_id')); + return $this->get_user_avatar($this->get_data('poster_id')); } /** -- cgit v1.2.1 From 6c213bd5fa4f93875e7771edbf519990580286c4 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 23:20:59 -0500 Subject: [ticket/11103] Make sure post/topic approved notifications are always unread PHPBB3-11103 --- phpBB/includes/notification/type/approve_post.php | 20 ++++++++++++++++++++ phpBB/includes/notification/type/approve_topic.php | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 60b66fd4f6..d79bc6ae13 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -78,6 +78,26 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post ))); } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + // (and also saves a query) + return array(); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 4fd247a789..605965bf2f 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -78,6 +78,26 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi ))); } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + // (and also saves a query) + return array(); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) -- cgit v1.2.1 From 05e74b82ac5b65896b1a6aa5b7bca7aa1acd3ada Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 23:34:51 -0500 Subject: [ticket/11103] enable/disable notifications functions disable_notifications This should be called when an extension which has notification types is disabled so that all those notifications are hidden and do not cause errors enable_notifications This should be called when an extension which has notification types that was disabled is re-enabled so that all those notifications that were hidden are shown again PHPBB3-11103 --- phpBB/includes/notification/manager.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index b8c9c9742e..fef93a30c2 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -705,6 +705,38 @@ class phpbb_notification_manager } } + /** + * Disable all notifications of a certain type + * This should be called when an extension which has notification types + * is disabled so that all those notifications are hidden and do not + * cause errors + * + * @param string $item_type + */ + public function disable_notifications($item_type) + { + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET is_enabled = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); + } + + /** + * Enable all notifications of a certain type + * This should be called when an extension which has notification types + * that was disabled is re-enabled so that all those notifications that + * were hidden are shown again + * + * @param string $item_type + */ + public function enable_notifications($item_type) + { + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET is_enabled = 1 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); + } + /** * Load user helper * -- cgit v1.2.1 From f09ee162528d931aabc3f216410d02d3a072c21d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 9 Nov 2012 07:40:08 -0600 Subject: [ticket/11103] Use phpBB Container to load types/methods PHPBB3-11103 --- phpBB/includes/notification/manager.php | 70 +++++++--------------- phpBB/includes/notification/method/email.php | 10 ++++ phpBB/includes/notification/method/interface.php | 7 +++ phpBB/includes/notification/method/jabber.php | 10 ++++ phpBB/includes/notification/type/approve_post.php | 10 ++++ phpBB/includes/notification/type/approve_topic.php | 10 ++++ phpBB/includes/notification/type/base.php | 6 +- phpBB/includes/notification/type/bookmark.php | 14 ++++- .../includes/notification/type/disapprove_post.php | 10 ++++ .../notification/type/disapprove_topic.php | 10 ++++ phpBB/includes/notification/type/interface.php | 7 +++ phpBB/includes/notification/type/pm.php | 10 ++++ phpBB/includes/notification/type/post.php | 14 ++++- phpBB/includes/notification/type/post_in_queue.php | 10 ++++ phpBB/includes/notification/type/quote.php | 20 +++++-- phpBB/includes/notification/type/report_pm.php | 10 ++++ .../notification/type/report_pm_closed.php | 10 ++++ phpBB/includes/notification/type/report_post.php | 10 ++++ .../notification/type/report_post_closed.php | 10 ++++ phpBB/includes/notification/type/topic.php | 10 ++++ .../includes/notification/type/topic_in_queue.php | 10 ++++ 21 files changed, 217 insertions(+), 61 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index fef93a30c2..102623ab93 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -21,6 +23,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_manager { + /** @var ContainerBuilder */ + protected $phpbb_container = null; + /** @var dbal */ protected $db = null; @@ -55,8 +60,9 @@ class phpbb_notification_manager */ protected $users = array(); - public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(ContainerBuilder $phpbb_container, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { + $this->phpbb_container = $phpbb_container; $this->db = $db; $this->cache = $cache; $this->template = $template; @@ -495,17 +501,17 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->get_subscription_files('notification/type/') as $class_name) + foreach ($this->phpbb_container->findTaggedServiceIds('notification.type') as $type_name => $data) { - $class = $this->get_item_type_class($class_name); + $type = $this->get_item_type_class($type_name); - if ($class instanceof phpbb_notification_type_interface && $class->is_available()) + if ($type instanceof phpbb_notification_type_interface && $type->is_available()) { $options = array_merge(array( - 'id' => $class_name, - 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name), + 'id' => $type->get_type(), + 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()), 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', - ), (($class_name::$notification_option !== false) ? $class_name::$notification_option : array())); + ), (($type::$notification_option !== false) ? $type::$notification_option : array())); $subscription_types[$options['group']][$options['id']] = $options; } @@ -531,13 +537,16 @@ class phpbb_notification_manager { $subscription_methods = array(); - foreach ($this->get_subscription_files('notification/method/') as $class_name) + foreach ($this->phpbb_container->findTaggedServiceIds('notification.method') as $method_name => $data) { - $method = $this->get_method_class($class_name); + $method = $this->get_method_class($method_name); if ($method instanceof phpbb_notification_method_interface && $method->is_available()) { - $subscription_methods[] = $class_name; + $subscription_methods[$method_name] = array( + 'id' => $method->get_type(), + 'lang' => 'NOTIFICATION_METHOD_' . strtoupper($method->get_type()), + ); } } @@ -783,7 +792,7 @@ class phpbb_notification_manager */ public function get_item_type_class($item_type, $data = array()) { - $item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); + $item = $this->phpbb_container->get($item_type); $item->set_initial_data($data); @@ -795,43 +804,6 @@ class phpbb_notification_manager */ public function get_method_class($method_name) { - return new $method_name($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); - } - - /** - * Helper to get subscription related files with the finder - */ - private function get_subscription_files($path) - { - $finder = $this->extension_manager->get_finder(); - - $subscription_files = array(); - - $classes = $finder - ->core_path('includes/' . $path) - ->extension_directory($path) - ->get_classes(); - - if (array_search('phpbb_notification_type_interface', $classes) !== false) - { - unset($classes[array_search('phpbb_notification_type_interface', $classes)]); - } - - if (array_search('phpbb_notification_type_base', $classes) !== false) - { - unset($classes[array_search('phpbb_notification_type_base', $classes)]); - } - - if (array_search('phpbb_notification_method_interface', $classes) !== false) - { - unset($classes[array_search('phpbb_notification_method_interface', $classes)]); - } - - if (array_search('phpbb_notification_method_base', $classes) !== false) - { - unset($classes[array_search('phpbb_notification_method_base', $classes)]); - } - - return $classes; + return $this->phpbb_container->get($method_name); } } diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index df7edb13e7..a47284bc61 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_method_email extends phpbb_notification_method_base { + /** + * Get notification method name + * + * @return string + */ + public function get_type() + { + return 'email'; + } + /** * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) * diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/includes/notification/method/interface.php index 3c6c757d5c..ef875942cc 100644 --- a/phpBB/includes/notification/method/interface.php +++ b/phpBB/includes/notification/method/interface.php @@ -21,6 +21,13 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notification_method_interface { + /** + * Get notification method name + * + * @return string + */ + public function get_type(); + /** * Is this method available for the user? * This is checked on the notifications options diff --git a/phpBB/includes/notification/method/jabber.php b/phpBB/includes/notification/method/jabber.php index 664e387d61..fc43d8d4b9 100644 --- a/phpBB/includes/notification/method/jabber.php +++ b/phpBB/includes/notification/method/jabber.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_method_jabber extends phpbb_notification_method_email { + /** + * Get notification method name + * + * @return string + */ + public function get_type() + { + return 'jabber'; + } + /** * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) * diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index d79bc6ae13..38ff3f1d70 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_approve_post extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'approve_post'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 605965bf2f..5b9ea409fe 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topic { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'approve_topic'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index fdd8a5b9cb..2b201c2752 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -116,7 +116,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i public function __toString() { - return (!empty($this->data)) ? var_export($this->data, true) : get_class($this); + return (!empty($this->data)) ? var_export($this->data, true) : $this->get_type(); } /** @@ -156,7 +156,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i // Defaults $this->data = array_merge(array( 'item_id' => static::get_item_id($type_data), - 'item_type' => get_class($this), + 'item_type' => $this->get_type(), 'item_parent_id' => static::get_item_parent_id($type_data), 'time' => time(), @@ -319,7 +319,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i { $options = array_merge(array( 'ignore_users' => array(), - 'item_type' => get_class($this), + 'item_type' => $this->get_type(), 'item_id' => 0, // Global by default ), $options); diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 6fe00d9dd0..e5ad4132fb 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_bookmark extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'bookmark'; + } + /** * Language key used to output the text * @@ -93,7 +103,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $update_notifications = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 AND is_enabled = 1'; @@ -103,7 +113,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post // Do not create a new notification unset($notify_users[$row['user_id']]); - $notification = $this->notification_manager->get_item_type_class(get_class($this), $row); + $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index ddacd4d367..d1d56086e7 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_approve_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'disapprove_post'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index dfda4f8371..7affaa8afa 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_approve_topic { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'disapprove_topic'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 9d9965261e..a40fdafd09 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -21,6 +21,13 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notification_type_interface { + /** + * Get notification type name + * + * @return string + */ + public function get_type(); + /** * Set initial data from the database * diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 1c38002892..fbdf351062 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_pm extends phpbb_notification_type_base { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'pm'; + } + /** * Notification option data (for outputting to the user) * diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index b1a3ee9a26..a99558efe7 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_post extends phpbb_notification_type_base { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'post'; + } + /** * Language key used to output the text * @@ -114,7 +124,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $update_notifications = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 AND is_enabled = 1'; @@ -124,7 +134,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Do not create a new notification unset($notify_users[$row['user_id']]); - $notification = $this->notification_manager->get_item_type_class(get_class($this), $row); + $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index e9e7c6120e..95e0ce02bb 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'post_in_queue'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index c9f0f923c1..c3763da229 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_quote extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'quote'; + } + /** * regular expression to match to find usernames * @@ -112,7 +122,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $update_notifications = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 AND is_enabled = 1'; @@ -122,7 +132,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // Do not create a new notification unset($notify_users[$row['user_id']]); - $notification = $this->notification_manager->get_item_type_class(get_class($this), $row); + $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; @@ -143,7 +153,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $old_notifications = array(); $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_id = " . self::get_item_id($post) . ' AND is_enabled = 1'; $result = $this->db->sql_query($sql); @@ -167,13 +177,13 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post } // Add the necessary notifications - $this->notification_manager->add_notifications_for_users(get_class($this), $post, $add_notifications); + $this->notification_manager->add_notifications_for_users($this->get_type(), $post, $add_notifications); // Remove the necessary notifications if (!empty($remove_notifications)) { $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_id = " . self::get_item_id($post) . ' AND ' . $this->db->sql_in_set('user_id', $remove_notifications); $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 63d153bd27..2841468475 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_pm'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index c86fe77b0e..de87c9f760 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_pm { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_pm_closed'; + } + /** * Email template to use to send notifications * diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 26dd9512bf..433a5e835d 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_post extends phpbb_notification_type_post_in_queue { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_post'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 7454760dc0..cde0ff85a8 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_post_closed extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_post_closed'; + } + /** * Email template to use to send notifications * diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index db268fa53e..4eb03194f5 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_topic extends phpbb_notification_type_base { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'topic'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 66aecb0d05..38bc2ab58d 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_topic { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'topic_in_queue'; + } + /** * Language key used to output the text * -- cgit v1.2.1 From b8bdcc957bc49b96d43d74077c95a55f4f88e2fa Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 9 Nov 2012 07:45:23 -0600 Subject: [ticket/11103] count is reserved, do not use in a SQL query PHPBB3-11103 --- phpBB/includes/notification/manager.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 102623ab93..ca018fbf3b 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -122,25 +122,25 @@ class phpbb_notification_manager if ($options['count_unread']) { // Get the total number of unread notifications - $sql = 'SELECT COUNT(*) AS count + $sql = 'SELECT COUNT(*) AS unread_count FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND is_enabled = 1'; $result = $this->db->sql_query($sql); - $unread_count = (int) $this->db->sql_fetchfield('count', $result); + $unread_count = (int) $this->db->sql_fetchfield('unread_count', $result); $this->db->sql_freeresult($result); } if ($options['count_total']) { // Get the total number of notifications - $sql = 'SELECT COUNT(*) AS count + $sql = 'SELECT COUNT(*) AS total_count FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND is_enabled = 1'; $result = $this->db->sql_query($sql); - $total_count = (int) $this->db->sql_fetchfield('count', $result); + $total_count = (int) $this->db->sql_fetchfield('total_count', $result); $this->db->sql_freeresult($result); } @@ -675,7 +675,7 @@ class phpbb_notification_manager // If no method, make sure that no other notification methods for this item are selected before deleting if ($method === '') { - $sql = 'SELECT COUNT(*) as count + $sql = 'SELECT COUNT(*) as num_notifications FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' @@ -683,10 +683,10 @@ class phpbb_notification_manager AND method <> '' AND notify = 1"; $this->db->sql_query($sql); - $count = $this->db->sql_fetchfield('count'); + $num_notifications = $this->db->sql_fetchfield('num_notifications'); $this->db->sql_freeresult(); - if ($count) + if ($num_notifications) { return; } -- cgit v1.2.1 From 6a0f6833e61532d28d7bebcc8ad0ec2b2b722e19 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 9 Nov 2012 07:48:18 -0600 Subject: [ticket/11103] Comment indentation PHPBB3-11103 --- phpBB/includes/notification/manager.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index ca018fbf3b..8392928bd2 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -716,9 +716,10 @@ class phpbb_notification_manager /** * Disable all notifications of a certain type - * This should be called when an extension which has notification types - * is disabled so that all those notifications are hidden and do not - * cause errors + * + * This should be called when an extension which has notification types + * is disabled so that all those notifications are hidden and do not + * cause errors * * @param string $item_type */ @@ -732,9 +733,10 @@ class phpbb_notification_manager /** * Enable all notifications of a certain type - * This should be called when an extension which has notification types - * that was disabled is re-enabled so that all those notifications that - * were hidden are shown again + * + * This should be called when an extension which has notification types + * that was disabled is re-enabled so that all those notifications that + * were hidden are shown again * * @param string $item_type */ -- cgit v1.2.1 From 6c8c54d4d2575cd40fe873cd2108b031ae5830a6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 9 Nov 2012 08:48:41 -0600 Subject: [ticket/11103] Inject table prefix to notifications system instead of constants PHPBB3-11103 --- phpBB/includes/notification/manager.php | 52 ++++++++++++++++++------------- phpBB/includes/notification/type/base.php | 12 ++++++- 2 files changed, 42 insertions(+), 22 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 8392928bd2..3d0ada4a43 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -53,6 +53,12 @@ class phpbb_notification_manager /** @var string */ protected $php_ext = null; + /** @var string */ + protected $notifications_table = null; + + /** @var string */ + protected $user_notifications_table = null; + /** * Users loaded from the DB * @@ -60,7 +66,7 @@ class phpbb_notification_manager */ protected $users = array(); - public function __construct(ContainerBuilder $phpbb_container, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(ContainerBuilder $phpbb_container, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { $this->phpbb_container = $phpbb_container; $this->db = $db; @@ -70,8 +76,12 @@ class phpbb_notification_manager $this->user = $user; $this->auth = $auth; $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + + $this->notifications_table = $notifications_table; + $this->user_notifications_table = $user_notifications_table; } /** @@ -123,7 +133,7 @@ class phpbb_notification_manager { // Get the total number of unread notifications $sql = 'SELECT COUNT(*) AS unread_count - FROM ' . NOTIFICATIONS_TABLE . ' + FROM ' . $this->notifications_table . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND is_enabled = 1'; @@ -136,7 +146,7 @@ class phpbb_notification_manager { // Get the total number of notifications $sql = 'SELECT COUNT(*) AS total_count - FROM ' . NOTIFICATIONS_TABLE . ' + FROM ' . $this->notifications_table . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND is_enabled = 1'; $result = $this->db->sql_query($sql); @@ -150,7 +160,7 @@ class phpbb_notification_manager // Get the main notifications $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . ' + FROM ' . $this->notifications_table . ' WHERE user_id = ' . (int) $options['user_id'] . (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . ' AND is_enabled = 1 @@ -167,7 +177,7 @@ class phpbb_notification_manager if ($unread_count && $options['all_unread'] && !empty($rowset)) { $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . ' + FROM ' . $this->notifications_table . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' @@ -239,7 +249,7 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 WHERE time <= " . $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . @@ -270,7 +280,7 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND time <= " . $time . @@ -289,7 +299,7 @@ class phpbb_notification_manager { $time = ($time !== false) ? $time : time(); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 WHERE time <= " . $time . ' AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); @@ -365,7 +375,7 @@ class phpbb_notification_manager // 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 $sql = 'SELECT user_id - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND is_enabled = 1'; @@ -415,7 +425,7 @@ class phpbb_notification_manager } // insert into the db - $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); + $this->db->sql_multi_insert($this->notifications_table, $new_rows); // We need to load all of the users to send notifications $this->load_users($user_ids); @@ -460,7 +470,7 @@ class phpbb_notification_manager $item_id = $item_type::get_item_id($data); $update_array = $notification->create_update_array($data); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id; @@ -486,7 +496,7 @@ class phpbb_notification_manager return; } - $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + $sql = 'DELETE FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id); $this->db->sql_query($sql); @@ -571,7 +581,7 @@ class phpbb_notification_manager foreach ($types as $id => $type) { $sql = 'SELECT method, notify - FROM ' . USER_NOTIFICATIONS_TABLE . ' + FROM ' . $this->user_notifications_table . ' WHERE user_id = ' . (int) $user_id . " AND item_type = '" . $this->db->sql_escape($id) . "' AND item_id = 0"; @@ -627,7 +637,7 @@ class phpbb_notification_manager $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'SELECT notify - FROM ' . USER_NOTIFICATIONS_TABLE . " + FROM ' . $this->user_notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND user_id = ' .(int) $user_id . " @@ -638,7 +648,7 @@ class phpbb_notification_manager if ($current === false) { - $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' . $this->db->sql_build_array('INSERT', array( 'item_type' => $item_type, 'item_id' => (int) $item_id, @@ -650,7 +660,7 @@ class phpbb_notification_manager } else if (!$current) { - $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->user_notifications_table . " SET notify = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' @@ -676,7 +686,7 @@ class phpbb_notification_manager if ($method === '') { $sql = 'SELECT COUNT(*) as num_notifications - FROM ' . USER_NOTIFICATIONS_TABLE . " + FROM ' . $this->user_notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND user_id = ' .(int) $user_id . " @@ -692,7 +702,7 @@ class phpbb_notification_manager } } - $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->user_notifications_table . " SET notify = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' @@ -702,7 +712,7 @@ class phpbb_notification_manager if (!$this->db->sql_affectedrows()) { - $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' . $this->db->sql_build_array('INSERT', array( 'item_type' => $item_type, 'item_id' => (int) $item_id, @@ -725,7 +735,7 @@ class phpbb_notification_manager */ public function disable_notifications($item_type) { - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET is_enabled = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); @@ -742,7 +752,7 @@ class phpbb_notification_manager */ public function enable_notifications($item_type) { - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET is_enabled = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 2b201c2752..419dce3dd0 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -51,6 +51,12 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var string */ protected $php_ext = null; + /** @var string */ + protected $notifications_table = null; + + /** @var string */ + protected $user_notifications_table = null; + /** * Notification option data (for outputting to the user) * @@ -78,7 +84,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { $this->notification_manager = $notification_manager; $this->db = $db; @@ -88,8 +94,12 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->user = $user; $this->auth = $auth; $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + + $this->notifications_table = $notifications_table; + $this->user_notifications_table = $user_notifications_table; } /** -- cgit v1.2.1 From 985d234a29b22086a196dca427e6c474229e3d36 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 11 Nov 2012 11:37:14 -0600 Subject: [ticket/11103] Move all email templates to the email/ directory & prep short Prepare short email templates (to be used in jabber) PHPBB3-11103 --- phpBB/includes/notification/type/bookmark.php | 2 +- phpBB/includes/notification/type/post_in_queue.php | 2 +- phpBB/includes/notification/type/quote.php | 2 +- phpBB/includes/notification/type/report_pm.php | 2 +- phpBB/includes/notification/type/report_post.php | 2 +- phpBB/includes/notification/type/topic_in_queue.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index e5ad4132fb..a40bbde5e4 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -131,6 +131,6 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post */ public function get_email_template() { - return 'notifications/bookmark'; + return 'bookmark'; } } diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 95e0ce02bb..3cd9b11283 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -132,6 +132,6 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post */ public function get_email_template() { - return 'notifications/post_in_queue'; + return 'post_in_queue'; } } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index c3763da229..f45bb1ae7d 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -200,7 +200,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post */ public function get_email_template() { - return 'notifications/quote'; + return 'quote'; } /** diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 2841468475..9bdc59a4ef 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -123,7 +123,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_email_template() { - return 'notifications/report_pm'; + return 'report_pm'; } /** diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 433a5e835d..d80c7b754f 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -83,7 +83,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function get_email_template() { - return 'notifications/report_post'; + return 'report_post'; } /** diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 38bc2ab58d..170a98ca1b 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -125,6 +125,6 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top */ public function get_email_template() { - return 'notifications/topic_in_queue'; + return 'topic_in_queue'; } } -- cgit v1.2.1 From 7948aaa78ed7e543a0773ee1a858ef45f5e5a5bf Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 11 Nov 2012 11:41:18 -0600 Subject: [ticket/11103] Make jabber use short/ email template files PHPBB3-11103 --- phpBB/includes/notification/method/email.php | 9 ++++++++- phpBB/includes/notification/method/jabber.php | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index a47284bc61..2ff30b177f 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -40,6 +40,13 @@ class phpbb_notification_method_email extends phpbb_notification_method_base */ protected $notify_method = NOTIFY_EMAIL; + /** + * Base directory to prepend to the email template name + * + * @var string + */ + protected $email_template_base_dir = ''; + /** * Is this method available for the user? * This is checked on the notifications options @@ -100,7 +107,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base continue; } - $messenger->template($notification->get_email_template(), $user['user_lang']); + $messenger->template($this->email_template_base_dir . $notification->get_email_template(), $user['user_lang']); $messenger->to($user['user_email'], $user['username']); diff --git a/phpBB/includes/notification/method/jabber.php b/phpBB/includes/notification/method/jabber.php index fc43d8d4b9..e3eb571fbc 100644 --- a/phpBB/includes/notification/method/jabber.php +++ b/phpBB/includes/notification/method/jabber.php @@ -40,6 +40,13 @@ class phpbb_notification_method_jabber extends phpbb_notification_method_email */ protected $notify_method = NOTIFY_IM; + /** + * Base directory to prepend to the email template name + * + * @var string + */ + protected $email_template_base_dir = 'short/'; + /** * Is this method available for the user? * This is checked on the notifications options -- cgit v1.2.1 From 2afb8b9df873c3f9572a32ab7a62ea8ba8d8a45b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 20 Nov 2012 18:14:48 -0600 Subject: [ticket/11103] Create user loader class, update for DIC Create a very basic user loader class to handle querying/storing user data in a centralized location. Use DIC collection service for notification types/methods. Cleanup unused dependencies. Fix some other issues. PHPBB3-11103 --- phpBB/includes/notification/manager.php | 127 ++++++++------------- phpBB/includes/notification/method/base.php | 14 ++- phpBB/includes/notification/method/email.php | 4 +- phpBB/includes/notification/type/base.php | 39 ++----- phpBB/includes/notification/type/bookmark.php | 4 +- phpBB/includes/notification/type/pm.php | 8 +- phpBB/includes/notification/type/post.php | 10 +- phpBB/includes/notification/type/quote.php | 10 +- phpBB/includes/notification/type/report_pm.php | 4 +- .../notification/type/report_pm_closed.php | 2 +- phpBB/includes/notification/type/report_post.php | 4 +- .../notification/type/report_post_closed.php | 4 +- phpBB/includes/notification/type/topic.php | 6 +- 13 files changed, 98 insertions(+), 138 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 3d0ada4a43..fbfe388c80 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -7,8 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; - /** * @ignore */ @@ -23,30 +21,24 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_manager { + /** @var array */ + protected $notification_types = null; + + /** @var array */ + protected $notification_methods = null; + /** @var ContainerBuilder */ protected $phpbb_container = null; - - /** @var dbal */ - protected $db = null; - - /** @var phpbb_cache_service */ - protected $cache = null; - /** @var phpbb_template */ - protected $template = null; + /** @var phpbb_user_loader */ + protected $user_loader = null; - /** @var phpbb_extension_manager */ - protected $extension_manager = null; + /** @var dbal */ + protected $db = null; /** @var phpbb_user */ protected $user = null; - /** @var phpbb_auth */ - protected $auth = null; - - /** @var phpbb_config */ - protected $config = null; - /** @var string */ protected $phpbb_root_path = null; @@ -59,23 +51,15 @@ class phpbb_notification_manager /** @var string */ protected $user_notifications_table = null; - /** - * Users loaded from the DB - * - * @var array Array of user data that we've loaded from the DB - */ - protected $users = array(); - - public function __construct(ContainerBuilder $phpbb_container, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, dbal $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { + $this->notification_types = $notification_types; + $this->notification_methods = $notification_methods; $this->phpbb_container = $phpbb_container; + + $this->user_loader = $user_loader; $this->db = $db; - $this->cache = $cache; - $this->template = $template; - $this->extension_manager = $extension_manager; $this->user = $user; - $this->auth = $auth; - $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; @@ -209,7 +193,7 @@ class phpbb_notification_manager $notifications[$row['notification_id']] = $notification; } - $this->load_users($user_ids); + $this->user_loader->load_users($user_ids); // Allow each type to load its own special items foreach ($load_special as $item_type => $data) @@ -334,7 +318,7 @@ class phpbb_notification_manager return $notified_users; } - $item_id = $item_type::get_item_id($data); + $item_id = $this->get_item_type_class($item_type)->get_item_id($data); // find out which users want to receive this type of notification $notify_users = $this->get_item_type_class($item_type)->find_users_for_notification($data, $options); @@ -363,7 +347,7 @@ class phpbb_notification_manager return; } - $item_id = $item_type::get_item_id($data); + $item_id = $this->get_item_type_class($item_type)->get_item_id($data); $user_ids = array(); $notification_objects = $notification_methods = array(); @@ -428,7 +412,7 @@ class phpbb_notification_manager $this->db->sql_multi_insert($this->notifications_table, $new_rows); // We need to load all of the users to send notifications - $this->load_users($user_ids); + $this->user_loader->load_users($user_ids); // run the queue for each method to send notifications foreach ($notification_methods as $method) @@ -467,7 +451,7 @@ class phpbb_notification_manager } } - $item_id = $item_type::get_item_id($data); + $item_id = $notification->get_item_id($data); $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . $this->notifications_table . ' @@ -511,7 +495,7 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->phpbb_container->findTaggedServiceIds('notification.type') as $type_name => $data) + foreach ($this->notification_types as $type_name => $data) { $type = $this->get_item_type_class($type_name); @@ -547,7 +531,7 @@ class phpbb_notification_manager { $subscription_methods = array(); - foreach ($this->phpbb_container->findTaggedServiceIds('notification.method') as $method_name => $data) + foreach ($this->notification_methods as $method_name => $data) { $method = $this->get_method_class($method_name); @@ -759,63 +743,48 @@ class phpbb_notification_manager } /** - * Load user helper - * - * @param array $user_ids + * Helper to get the notifications item type class and set it up */ - public function load_users($user_ids) + public function get_item_type_class($item_type, $data = array()) { - $user_ids[] = ANONYMOUS; - - // Load the users - $user_ids = array_unique($user_ids); - - // Do not load users we already have in $this->users - $user_ids = array_diff($user_ids, array_keys($this->users)); + $item = $this->load_object('notification.type.' . $item_type); - if (sizeof($user_ids)) - { - $sql = 'SELECT * - FROM ' . USERS_TABLE . ' - WHERE ' . $this->db->sql_in_set('user_id', $user_ids); - $result = $this->db->sql_query($sql); + $item->set_initial_data($data); - while ($row = $this->db->sql_fetchrow($result)) - { - $this->users[$row['user_id']] = $row; - } - $this->db->sql_freeresult($result); - } + return $item; } /** - * Get a user row from our users cache - * - * @param int $user_id - * @return array + * Helper to get the notifications method class and set it up */ - public function get_user($user_id) + public function get_method_class($method_name) { - return (isset($this->users[$user_id])) ? $this->users[$user_id] : $this->users[ANONYMOUS]; + return $this->load_object('notification.method.' . $method_name); } /** - * Helper to get the notifications item type class and set it up + * Helper to load objects (notification types/methods) */ - public function get_item_type_class($item_type, $data = array()) + protected function load_object($object_name) { - $item = $this->phpbb_container->get($item_type); + // Here we cannot just use ContainerBuilder->get(name) + // The reason for this is because get handles services + // which are initialized once and shared. Here we need + // separate new objects because we pass around objects + // that store row data in each object, which would lead + // to over-writing of data if we used get() - $item->set_initial_data($data); + $parameterBag = $this->phpbb_container->getParameterBag(); + $definition = $this->phpbb_container->getDefinition($object_name); + $arguments = $this->phpbb_container->resolveServices( + $parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments())) + ); + $r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass())); - return $item; - } + $object = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments); - /** - * Helper to get the notifications method class and set it up - */ - public function get_method_class($method_name) - { - return $this->phpbb_container->get($method_name); + $object->set_notification_manager($this); + + return $object; } } diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 88ec2674be..3f85d62a09 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -24,6 +24,9 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth /** @var phpbb_notification_manager */ protected $notification_manager = null; + /** @var phpbb_user_loader */ + protected $user_loader = null; + /** @var dbal */ protected $db = null; @@ -58,13 +61,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - $this->notification_manager = $notification_manager; + $this->user_loader = $user_loader; $this->db = $db; $this->cache = $cache; - $this->template = $template; - $this->extension_manager = $extension_manager; $this->user = $user; $this->auth = $auth; $this->config = $config; @@ -72,6 +73,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth $this->php_ext = $php_ext; } + public function set_notification_manager(phpbb_notification_manager $notification_manager) + { + $this->notification_manager = $notification_manager; + } + /** * Add a notification to the queue * diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index 2ff30b177f..429dfda2ba 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -82,7 +82,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base $banned_users = phpbb_get_banned_user_ids($user_ids); // Load all the users we need - $this->notification_manager->load_users($user_ids); + $this->user_loader->load_users($user_ids); // Load the messenger if (!class_exists('messenger')) @@ -100,7 +100,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base continue; } - $user = $this->notification_manager->get_user($notification->user_id); + $user = $this->user_loader->get_user($notification->user_id); if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) { diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 419dce3dd0..d596c06167 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -24,6 +24,9 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var phpbb_notification_manager */ protected $notification_manager = null; + /** @var phpbb_user_loader */ + protected $user_loader = null; + /** @var dbal */ protected $db = null; @@ -33,9 +36,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var phpbb_template */ protected $template = null; - /** @var phpbb_extension_manager */ - protected $extension_manager = null; - /** @var phpbb_user */ protected $user = null; @@ -84,13 +84,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { - $this->notification_manager = $notification_manager; + $this->user_loader = $user_loader; $this->db = $db; $this->cache = $cache; - $this->template = $template; - $this->extension_manager = $extension_manager; $this->user = $user; $this->auth = $auth; $this->config = $config; @@ -102,6 +100,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->user_notifications_table = $user_notifications_table; } + public function set_notification_manager(phpbb_notification_manager $notification_manager) + { + $this->notification_manager = $notification_manager; + } + /** * Set initial data from the database * @@ -357,7 +360,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $rowset = $resulting_user_ids = array(); $sql = 'SELECT user_id, method, notify - FROM ' . USER_NOTIFICATIONS_TABLE . ' + FROM ' . $this->user_notifications_table . ' WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . " AND item_type = '" . $this->db->sql_escape($options['item_type']) . "' AND item_id = " . (int) $options['item_id']; @@ -394,24 +397,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i return $rowset; } - /** - * Get avatar helper - * - * @param int $user_id - * @return string - */ - protected function get_user_avatar($user_id) - { - $user = $this->notification_manager->get_user($user_id); - - if (!function_exists('get_user_avatar')) - { - include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); - } - - return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar'); - } - /** * Mark this item read/unread helper * @@ -435,7 +420,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i return $where; } - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET unread = ' . (int) $this->unread . ' WHERE ' . $where; $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index a40bbde5e4..a17d8f5db7 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -102,7 +102,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 @@ -114,7 +114,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post unset($notify_users[$row['user_id']]); $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index fbdf351062..1eaeb1a250 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -92,7 +92,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base unset($pm['recipients'][$pm['from_user_id']]); - $this->notification_manager->load_users(array_keys($pm['recipients'])); + $this->user_loader->load_users(array_keys($pm['recipients'])); return $this->check_user_notification_options(array_keys($pm['recipients']), $options); } @@ -102,7 +102,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('from_user_id')); + return $this->user_loader->get_avatar($this->get_data('from_user_id')); } /** @@ -112,7 +112,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_title() { - $user_data = $this->notification_manager->get_user($this->get_data('from_user_id')); + $user_data = $this->user_loader->get_user($this->get_data('from_user_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -136,7 +136,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_email_template_variables() { - $user_data = $this->notification_manager->get_user($this->get_data('from_user_id')); + $user_data = $this->user_loader->get_user($this->get_data('from_user_id')); return array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index a99558efe7..7e06779982 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -123,7 +123,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 @@ -135,7 +135,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base unset($notify_users[$row['user_id']]); $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; $this->db->sql_query($sql); @@ -150,7 +150,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('poster_id')); + return $this->user_loader->get_avatar($this->get_data('poster_id')); } /** @@ -181,7 +181,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->notification_manager->get_user($responder['poster_id']); + $user_data = $this->user_loader->get_user($responder['poster_id']); $usernames[] = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } @@ -217,7 +217,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index f45bb1ae7d..1796343a0e 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -121,7 +121,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 @@ -133,7 +133,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post unset($notify_users[$row['user_id']]); $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; $this->db->sql_query($sql); @@ -152,7 +152,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post { $old_notifications = array(); $sql = 'SELECT user_id - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_id = " . self::get_item_id($post) . ' AND is_enabled = 1'; @@ -182,7 +182,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // Remove the necessary notifications if (!empty($remove_notifications)) { - $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + $sql = 'DELETE FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_id = " . self::get_item_id($post) . ' AND ' . $this->db->sql_in_set('user_id', $remove_notifications); @@ -210,7 +210,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post */ public function get_email_template_variables() { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); return array_merge(parent::get_email_template_variables(), array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 9bdc59a4ef..73e22dc83b 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -160,7 +160,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { $this->user->add_lang('mcp'); - $user_data = $this->notification_manager->get_user($this->get_data('reporter_id')); + $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -197,7 +197,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('reporter_id')); + return $this->user_loader->get_avatar($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index de87c9f760..51e5204304 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -106,7 +106,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p */ public function get_title() { - $user_data = $this->notification_manager->get_user($this->get_data('closer_id')); + $user_data = $this->user_loader->get_user($this->get_data('closer_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index d80c7b754f..2508644b0b 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -127,7 +127,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i { $this->user->add_lang('mcp'); - $user_data = $this->notification_manager->get_user($this->get_data('reporter_id')); + $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -164,7 +164,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('reporter_id')); + return $this->user_loader->get_avatar($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index cde0ff85a8..a7016a8f3d 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -106,7 +106,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function get_title() { - $user_data = $this->notification_manager->get_user($this->get_data('closer_id')); + $user_data = $this->user_loader->get_user($this->get_data('closer_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -122,7 +122,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('closer_id')); + return $this->user_loader->get_avatar($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 4eb03194f5..6e9347d4a8 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -126,7 +126,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('poster_id')); + return $this->user_loader->get_avatar($this->get_data('poster_id')); } /** @@ -142,7 +142,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } @@ -178,7 +178,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } -- cgit v1.2.1 From 570c5ad3c08378f377385aaff7d3810ccb8db3ff Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 20 Nov 2012 23:12:37 -0600 Subject: [ticket/11103] Some comments PHPBB3-11103 --- phpBB/includes/notification/manager.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index fbfe388c80..ea91496fb9 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -78,10 +78,15 @@ class phpbb_notification_manager * order_dir Order direction (Default: DESC) * limit Number of notifications to load (Default: 5) * start Notifications offset (Default: 0) - * all_unread Load all unread messages? If set to true, count_unread is set to true (Default: false) - * count_unread Count all unread messages? (Default: false) + * all_unread Load all unread notifications? If set to true, count_unread is set to true (Default: false) + * count_unread Count all unread notifications? (Default: false) + * count_total Count all notifications? (Default: false) + * @return array Array of information based on the request with keys: + * 'notifications' array of notification type objects + * 'unread_count' number of unread notifications the user has if count_unread is true in the options + * 'total_count' number of notifications the user has if count_total is true in the options */ - public function load_notifications($options = array()) + public function load_notifications(array $options = array()) { // Merge default options $options = array_merge(array( @@ -297,8 +302,11 @@ class phpbb_notification_manager * Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive * a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array * @param array $data Data specific for this type that will be inserted + * @param array $options Optional options to control what notifications are loaded + * ignore_users array of data to specify which users should not receive certain types of notifications + * @return array Information about what users were notified and how they were notified */ - public function add_notifications($item_type, $data, $options = array()) + public function add_notifications($item_type, $data, array $options = array()) { $options = array_merge(array( 'ignore_users' => array(), -- cgit v1.2.1 From c911a34b5b7541b46ee2408da366d2dc7c302090 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 21 Nov 2012 16:04:01 -0600 Subject: [ticket/11103] Do not prepend notification.(type|method) unless necessary PHPBB3-11103 --- phpBB/includes/notification/manager.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index ea91496fb9..4c25fa72f0 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -755,7 +755,9 @@ class phpbb_notification_manager */ public function get_item_type_class($item_type, $data = array()) { - $item = $this->load_object('notification.type.' . $item_type); + $item_type = (strpos($item_type, 'notification.type.') === 0) ? $item_type : 'notification.type.' . $item_type; + + $item = $this->load_object($item_type); $item->set_initial_data($data); @@ -767,7 +769,9 @@ class phpbb_notification_manager */ public function get_method_class($method_name) { - return $this->load_object('notification.method.' . $method_name); + $method_name = (strpos($method_name, 'notification.method.') === 0) ? $method_name : 'notification.method.' . $method_name; + + return $this->load_object($method_name); } /** -- cgit v1.2.1 From 37565f37e4363f257a160145bc7973a2d5738a86 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Dec 2012 18:40:41 -0600 Subject: [ticket/11103] Some improvements to the user loader PHPBB3-11103 --- phpBB/includes/notification/type/pm.php | 4 +--- phpBB/includes/notification/type/post.php | 8 ++------ phpBB/includes/notification/type/report_pm.php | 6 ++---- phpBB/includes/notification/type/report_pm_closed.php | 4 +--- phpBB/includes/notification/type/report_post.php | 4 +--- phpBB/includes/notification/type/report_post_closed.php | 4 +--- phpBB/includes/notification/type/topic.php | 8 ++------ 7 files changed, 10 insertions(+), 28 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 1eaeb1a250..8d31c87817 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -112,9 +112,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_title() { - $user_data = $this->user_loader->get_user($this->get_data('from_user_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('from_user_id'), 'no_profile'); return $this->user->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 7e06779982..0646282c94 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -181,9 +181,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->user_loader->get_user($responder['poster_id']); - - $usernames[] = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $usernames[] = $this->user_loader->get_username($responder['poster_id'], 'no_profile'); } } @@ -217,9 +215,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->user_loader->get_user($this->get_data('poster_id')); - - $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile'); } return array( diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 73e22dc83b..877e8209e3 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -160,9 +160,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { $this->user->add_lang('mcp'); - $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); if ($this->get_data('report_text')) { @@ -186,7 +184,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return $this->user->lang( $this->language_key, - $username, + $username, censor_text($this->get_data('message_subject')), $this->get_data('reason_description') ); diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 51e5204304..2d60ae21d4 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -106,9 +106,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p */ public function get_title() { - $user_data = $this->user_loader->get_user($this->get_data('closer_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile'); return $this->user->lang( $this->language_key, diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 2508644b0b..0334fdb109 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -127,9 +127,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i { $this->user->add_lang('mcp'); - $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); if ($this->get_data('report_text')) { diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index a7016a8f3d..3282ba7d8c 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -106,9 +106,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function get_title() { - $user_data = $this->user_loader->get_user($this->get_data('closer_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile'); return $this->user->lang( $this->language_key, diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 6e9347d4a8..614d644501 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -142,9 +142,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->user_loader->get_user($this->get_data('poster_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile'); } return $this->user->lang( @@ -178,9 +176,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->user_loader->get_user($this->get_data('poster_id')); - - $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile'); } return array( -- cgit v1.2.1 From 84284a9ccee7d5ccc658c3d1f751a5254b3b9175 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Dec 2012 13:43:06 -0600 Subject: [ticket/11103] Use scope: prototype This lets us clean up the mess that was in load_object(), but requires scope: prototype to be added to the service definitions for all types or methods! PHPBB3-11103 --- phpBB/includes/notification/manager.php | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 4c25fa72f0..22f8f58783 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -779,24 +779,6 @@ class phpbb_notification_manager */ protected function load_object($object_name) { - // Here we cannot just use ContainerBuilder->get(name) - // The reason for this is because get handles services - // which are initialized once and shared. Here we need - // separate new objects because we pass around objects - // that store row data in each object, which would lead - // to over-writing of data if we used get() - - $parameterBag = $this->phpbb_container->getParameterBag(); - $definition = $this->phpbb_container->getDefinition($object_name); - $arguments = $this->phpbb_container->resolveServices( - $parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments())) - ); - $r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass())); - - $object = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments); - - $object->set_notification_manager($this); - - return $object; + return $this->phpbb_container->get($object_name); } } -- cgit v1.2.1 From ddd874ba76366cebe3cc30df6daa1974e29f34d1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 13 Dec 2012 19:46:32 -0600 Subject: [ticket/11103] dbal -> phpbb_db_driver PHPBB3-11103 --- phpBB/includes/notification/manager.php | 4 ++-- phpBB/includes/notification/method/base.php | 4 ++-- phpBB/includes/notification/type/base.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 22f8f58783..653446ab73 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -33,7 +33,7 @@ class phpbb_notification_manager /** @var phpbb_user_loader */ protected $user_loader = null; - /** @var dbal */ + /** @var phpbb_db_driver */ protected $db = null; /** @var phpbb_user */ @@ -51,7 +51,7 @@ class phpbb_notification_manager /** @var string */ protected $user_notifications_table = null; - public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, dbal $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { $this->notification_types = $notification_types; $this->notification_methods = $notification_methods; diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 3f85d62a09..f37e7e7845 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -27,7 +27,7 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth /** @var phpbb_user_loader */ protected $user_loader = null; - /** @var dbal */ + /** @var phpbb_db_driver */ protected $db = null; /** @var phpbb_cache_service */ @@ -61,7 +61,7 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->user_loader = $user_loader; $this->db = $db; diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index d596c06167..31792de04c 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -27,7 +27,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var phpbb_user_loader */ protected $user_loader = null; - /** @var dbal */ + /** @var phpbb_db_driver */ protected $db = null; /** @var phpbb_cache_service */ @@ -84,7 +84,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { $this->user_loader = $user_loader; $this->db = $db; -- cgit v1.2.1 From 95bd4d73eb41d677470b0bf77c521ae2a9bb731e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 10:33:03 -0600 Subject: [ticket/11103] Mark topic/post subscription notification read when approved PHPBB3-11103 --- phpBB/includes/notification/manager.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 653446ab73..6bf97a3e71 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -226,16 +226,6 @@ class phpbb_notification_manager */ 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 !== false) ? $time : time(); $sql = 'UPDATE ' . $this->notifications_table . " -- cgit v1.2.1 From d0375c46f91eb88508cbd8e320c7eda78d4f01dd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 18:25:26 -0600 Subject: [ticket/11103] Purge notifications (to be used when an extension is purged) PHPBB3-11103 --- phpBB/includes/notification/manager.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 653446ab73..fee1d079aa 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -733,6 +733,21 @@ class phpbb_notification_manager $this->db->sql_query($sql); } + /** + * Purge all notifications of a certain type + * + * This should be called when an extension which has notification types + * is purged so that all those notifications are removed + * + * @param string $item_type + */ + public function purge_notifications($item_type) + { + $sql = 'DELETE FROM ' . $this->notifications_table . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); + } + /** * Enable all notifications of a certain type * -- cgit v1.2.1 From c6f138ff12f015543f92d07fb5c93c083a246bab Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 18:35:17 -0600 Subject: [ticket/11103] Prune notifications function To delete all notifications before a certain time PHPBB3-11103 --- phpBB/includes/notification/manager.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 90916401c0..a5e1b09754 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -713,7 +713,7 @@ class phpbb_notification_manager * is disabled so that all those notifications are hidden and do not * cause errors * - * @param string $item_type + * @param string $item_type Type identifier of the subscription */ public function disable_notifications($item_type) { @@ -729,7 +729,7 @@ class phpbb_notification_manager * This should be called when an extension which has notification types * is purged so that all those notifications are removed * - * @param string $item_type + * @param string $item_type Type identifier of the subscription */ public function purge_notifications($item_type) { @@ -745,7 +745,7 @@ class phpbb_notification_manager * that was disabled is re-enabled so that all those notifications that * were hidden are shown again * - * @param string $item_type + * @param string $item_type Type identifier of the subscription */ public function enable_notifications($item_type) { @@ -755,6 +755,18 @@ class phpbb_notification_manager $this->db->sql_query($sql); } + /** + * Delete all notifications older than a certain time + * + * @param int $timestamp Unix timestamp to delete all notifications that were created before + */ + public function prune_notifications($timestamp) + { + $sql = 'DELETE FROM ' . $this->notifications_table . ' + WHERE time < ' . (int) $timestamp; + $this->db->sql_query($sql); + } + /** * Helper to get the notifications item type class and set it up */ -- cgit v1.2.1 From f47e51d6dea9d59a36a6babf1f4033104c93a53d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 19:18:26 -0600 Subject: [ticket/11103] Move is_enabled to a separate table for better performance PHPBB3-11103 --- phpBB/includes/notification/manager.php | 98 +++++++++++++++++---------- phpBB/includes/notification/type/base.php | 4 -- phpBB/includes/notification/type/bookmark.php | 13 ++-- phpBB/includes/notification/type/post.php | 13 ++-- phpBB/includes/notification/type/quote.php | 24 ++++--- 5 files changed, 91 insertions(+), 61 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index a5e1b09754..63db3e6e9a 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -45,13 +45,16 @@ class phpbb_notification_manager /** @var string */ protected $php_ext = null; + /** @var string */ + protected $notification_types_table = null; + /** @var string */ protected $notifications_table = null; /** @var string */ protected $user_notifications_table = null; - public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) { $this->notification_types = $notification_types; $this->notification_methods = $notification_methods; @@ -64,6 +67,7 @@ class phpbb_notification_manager $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->notification_types_table = $notification_types_table; $this->notifications_table = $notifications_table; $this->user_notifications_table = $user_notifications_table; } @@ -121,11 +125,12 @@ class phpbb_notification_manager if ($options['count_unread']) { // Get the total number of unread notifications - $sql = 'SELECT COUNT(*) AS unread_count - FROM ' . $this->notifications_table . ' - WHERE user_id = ' . (int) $options['user_id'] . ' - AND unread = 1 - AND is_enabled = 1'; + $sql = 'SELECT COUNT(n.notification_id) AS unread_count + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt + WHERE n.user_id = ' . (int) $options['user_id'] . ' + AND n.unread = 1 + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('unread_count', $result); $this->db->sql_freeresult($result); @@ -134,10 +139,11 @@ class phpbb_notification_manager if ($options['count_total']) { // Get the total number of notifications - $sql = 'SELECT COUNT(*) AS total_count - FROM ' . $this->notifications_table . ' - WHERE user_id = ' . (int) $options['user_id'] . ' - AND is_enabled = 1'; + $sql = 'SELECT COUNT(n.notification_id) AS total_count + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt + WHERE n.user_id = ' . (int) $options['user_id'] . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); $total_count = (int) $this->db->sql_fetchfield('total_count', $result); $this->db->sql_freeresult($result); @@ -148,12 +154,13 @@ class phpbb_notification_manager $rowset = array(); // Get the main notifications - $sql = 'SELECT * - FROM ' . $this->notifications_table . ' - WHERE user_id = ' . (int) $options['user_id'] . - (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . ' - AND is_enabled = 1 - ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt + WHERE n.user_id = ' . (int) $options['user_id'] . + (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('n.notification_id', $options['notification_id']) : ' AND n.notification_id = ' . (int) $options['notification_id']) : '') . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1 + ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); while ($row = $this->db->sql_fetchrow($result)) @@ -165,13 +172,14 @@ class phpbb_notification_manager // Get all unread notifications if ($unread_count && $options['all_unread'] && !empty($rowset)) { - $sql = 'SELECT * - FROM ' . $this->notifications_table . ' - WHERE user_id = ' . (int) $options['user_id'] . ' - AND unread = 1 - AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' - AND is_enabled = 1 - ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt + WHERE n.user_id = ' . (int) $options['user_id'] . ' + AND n.unread = 1 + AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1 + ORDER BY n.' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); while ($row = $this->db->sql_fetchrow($result)) @@ -345,6 +353,23 @@ class phpbb_notification_manager return; } + $sql = 'SELECT notification_type + FROM ' . $this->notification_types_table . " + WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'"; + $result = $this->db->sql_query($sql); + + if ($this->db->sql_fetchrow($result) === false) + { + // Does not exist in the database, must add the item type + $sql = 'INSERT INTO ' . $this->notification_types_table . ' ' . $this->db->sql_build_array('INSERT', array( + 'notification_type' => $item_type, + 'notification_type_enabled' => 1, + )); + $this->db->sql_query($sql); + } + + $this->db->sql_freeresult($result); + $item_id = $this->get_item_type_class($item_type)->get_item_id($data); $user_ids = array(); @@ -356,11 +381,12 @@ class phpbb_notification_manager // 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 - $sql = 'SELECT user_id - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND item_id = " . (int) $item_id . ' - AND is_enabled = 1'; + $sql = 'SELECT n.user_id + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->db->sql_escape($item_type) . "' + AND n.item_id = " . (int) $item_id . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -717,9 +743,9 @@ class phpbb_notification_manager */ public function disable_notifications($item_type) { - $sql = 'UPDATE ' . $this->notifications_table . " - SET is_enabled = 0 - WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $sql = 'UPDATE ' . $this->notification_types_table . " + SET notification_type_enabled = 0 + WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); } @@ -736,6 +762,10 @@ class phpbb_notification_manager $sql = 'DELETE FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . $this->notification_types_table . " + WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); } /** @@ -749,9 +779,9 @@ class phpbb_notification_manager */ public function enable_notifications($item_type) { - $sql = 'UPDATE ' . $this->notifications_table . " - SET is_enabled = 1 - WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $sql = 'UPDATE ' . $this->notification_types_table . " + SET notification_type_enabled = 1 + WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 31792de04c..effa57e3a3 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -72,10 +72,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * user_id * unread - * is_enabled - EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! - * - Set is_enabled to 0 for all your notifications when your extension is disabled so they are ignored and do not cause errors. - * - When your extension is enabled again, set is_enabled to 1 and your notifications will be working again. - * * time * data (special serialized field that each notification type can use to store stuff) * diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index a17d8f5db7..750bd3b6cb 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -101,12 +101,13 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); - $sql = 'SELECT * - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->get_type() . "' - AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1 - AND is_enabled = 1'; + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->get_type() . "' + AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND n.unread = 1 + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 0646282c94..0a42029f18 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -122,12 +122,13 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); - $sql = 'SELECT * - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->get_type() . "' - AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1 - AND is_enabled = 1'; + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->get_type() . "' + AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND n.unread = 1 + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 1796343a0e..b3a347f98c 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -120,12 +120,13 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); - $sql = 'SELECT * - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->get_type() . "' - AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1 - AND is_enabled = 1'; + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->get_type() . "' + AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND n.unread = 1 + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -151,11 +152,12 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post public function update_notifications($post) { $old_notifications = array(); - $sql = 'SELECT user_id - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->get_type() . "' - AND item_id = " . self::get_item_id($post) . ' - AND is_enabled = 1'; + $sql = 'SELECT n.user_id + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->get_type() . "' + AND n.item_id = " . self::get_item_id($post) . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { -- cgit v1.2.1 From 47bed3321634d888a51a611e6586c012a27eb1eb Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 21:02:28 -0600 Subject: [ticket/11103] time -> notification_time PHPBB3-11103 --- phpBB/includes/notification/manager.php | 11 +++++------ phpBB/includes/notification/type/approve_post.php | 4 ++-- phpBB/includes/notification/type/approve_topic.php | 2 +- phpBB/includes/notification/type/base.php | 6 +++--- phpBB/includes/notification/type/disapprove_post.php | 2 +- phpBB/includes/notification/type/disapprove_topic.php | 2 +- phpBB/includes/notification/type/post.php | 4 ++-- phpBB/includes/notification/type/post_in_queue.php | 2 +- phpBB/includes/notification/type/report_pm_closed.php | 2 +- phpBB/includes/notification/type/report_post_closed.php | 2 +- phpBB/includes/notification/type/topic.php | 4 ++-- phpBB/includes/notification/type/topic_in_queue.php | 2 +- 12 files changed, 21 insertions(+), 22 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 63db3e6e9a..8276996b94 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -96,7 +96,7 @@ class phpbb_notification_manager $options = array_merge(array( 'notification_id' => false, 'user_id' => $this->user->data['user_id'], - 'order_by' => 'time', + 'order_by' => 'notification_time', 'order_dir' => 'DESC', 'limit' => 0, 'start' => 0, @@ -238,10 +238,9 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 - WHERE time <= " . $time . + WHERE notification_time <= " . $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . - (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); $this->db->sql_query($sql); } @@ -270,7 +269,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND time <= " . $time . + AND notification_time <= " . $time . (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); $this->db->sql_query($sql); @@ -288,7 +287,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 - WHERE time <= " . $time . ' + WHERE notification_time <= " . $time . ' AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); $this->db->sql_query($sql); } @@ -793,7 +792,7 @@ class phpbb_notification_manager public function prune_notifications($timestamp) { $sql = 'DELETE FROM ' . $this->notifications_table . ' - WHERE time < ' . (int) $timestamp; + WHERE notification_time < ' . (int) $timestamp; $this->db->sql_query($sql); } diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 38ff3f1d70..1a30781c35 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -32,7 +32,7 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post { return 'approve_post'; } - + /** * Language key used to output the text * @@ -123,7 +123,7 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 5b9ea409fe..e728e9ac30 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -121,7 +121,7 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi { $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index effa57e3a3..45d0e5f60c 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -168,7 +168,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'item_type' => $this->get_type(), 'item_parent_id' => static::get_item_parent_id($type_data), - 'time' => time(), + 'notification_time' => time(), 'unread' => true, 'data' => array(), @@ -195,7 +195,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i // Unset data unique to each row unset( - $data['time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function) + $data['notification_time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function) $data['notification_id'], $data['unread'], $data['user_id'] @@ -250,7 +250,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'FORMATTED_TITLE' => $this->get_title(), 'URL' => $this->get_url(), - 'TIME' => $this->user->format_date($this->time), + 'TIME' => $this->user->format_date($this->notification_time), 'UNREAD' => $this->unread, diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index d1d56086e7..951c7e0254 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -103,7 +103,7 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap $data = parent::create_insert_array($post); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 7affaa8afa..038e528797 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -103,7 +103,7 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 0a42029f18..5eced0ca83 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -320,11 +320,11 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $this->set_data('forum_name', $post['forum_name']); - $this->time = $post['post_time']; + $this->notification_time = $post['post_time']; // Topics can be "read" before they are public (while awaiting approval). // Make sure that if the user has read the topic, it's marked as read in the notification - if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time) { $this->unread = false; } diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 3cd9b11283..1c29bee3cd 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -120,7 +120,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post { $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 2d60ae21d4..a735d2a822 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -148,7 +148,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p $data = parent::create_insert_array($pm, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 3282ba7d8c..8b984fc8ce 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -148,7 +148,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 614d644501..6eb78c30bb 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -261,11 +261,11 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $this->set_data('forum_name', $post['forum_name']); - $this->time = $post['post_time']; + $this->notification_time = $post['post_time']; // Topics can be "read" before they are public (while awaiting approval). // Make sure that if the user has read the topic, it's marked as read in the notification - if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time) { $this->unread = false; } diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 170a98ca1b..dc0b9f9869 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -113,7 +113,7 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top { $data = parent::create_insert_array($topic, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } -- cgit v1.2.1 From fad6bc5a7e58ddd370b88f73712de350b61bca29 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 21:08:26 -0600 Subject: [ticket/11103] unread -> notification_read PHPBB3-11103 --- phpBB/includes/notification/manager.php | 15 +++++++++++---- phpBB/includes/notification/type/base.php | 14 +++++++------- phpBB/includes/notification/type/bookmark.php | 2 +- phpBB/includes/notification/type/post.php | 4 ++-- phpBB/includes/notification/type/quote.php | 2 +- phpBB/includes/notification/type/topic.php | 2 +- 6 files changed, 23 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 8276996b94..fa1fd4b81f 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -128,8 +128,13 @@ class phpbb_notification_manager $sql = 'SELECT COUNT(n.notification_id) AS unread_count FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt WHERE n.user_id = ' . (int) $options['user_id'] . ' +<<<<<<< HEAD AND n.unread = 1 AND nt.notification_type = n.item_type +======= + AND n.notification_read = 0 + AND nt.notification_type = n.notification_type +>>>>>>> 5cedca0... [ticket/11103] unread -> notification_read AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('unread_count', $result); @@ -175,7 +180,7 @@ class phpbb_notification_manager $sql = 'SELECT n.* FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt WHERE n.user_id = ' . (int) $options['user_id'] . ' - AND n.unread = 1 + AND n.notification_read = 0 AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . ' AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1 @@ -237,7 +242,7 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . $this->notifications_table . " - SET unread = 0 + SET notification_read = 1 WHERE notification_time <= " . $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . @@ -267,8 +272,10 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . $this->notifications_table . " - SET unread = 0 + SET notification_read = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + SET notification_read = 1 + WHERE notification_type = '" . $this->db->sql_escape($notification_type) . "' AND notification_time <= " . $time . (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); @@ -286,7 +293,7 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . $this->notifications_table . " - SET unread = 0 + SET notification_read = 1 WHERE notification_time <= " . $time . ' AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 45d0e5f60c..cdca9aa642 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -168,8 +168,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'item_type' => $this->get_type(), 'item_parent_id' => static::get_item_parent_id($type_data), - 'notification_time' => time(), - 'unread' => true, + 'notification_time' => time(), + 'notification_read' => false, 'data' => array(), ), $this->data); @@ -197,7 +197,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i unset( $data['notification_time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function) $data['notification_id'], - $data['unread'], + $data['notification_read'], $data['user_id'] ); @@ -252,9 +252,9 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'URL' => $this->get_url(), 'TIME' => $this->user->format_date($this->notification_time), - 'UNREAD' => $this->unread, + 'UNREAD' => !$this->notification_read, - 'U_MARK_READ' => ($this->unread) ? $u_mark_read : '', + 'U_MARK_READ' => (!$this->notification_read) ? $u_mark_read : '', ); } @@ -402,7 +402,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function mark($unread = true, $return = false) { - $this->unread = (bool) $unread; + $this->notification_read = (bool) !$unread; $where = array( "item_type = '" . $this->db->sql_escape($this->item_type) . "'", @@ -417,7 +417,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } $sql = 'UPDATE ' . $this->notifications_table . ' - SET unread = ' . (int) $this->unread . ' + SET notification_read = ' . (int) $this->notification_read . ' WHERE ' . $where; $this->db->sql_query($sql); } diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 750bd3b6cb..4e48a967d0 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -105,7 +105,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt WHERE n.item_type = '" . $this->get_type() . "' AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND n.unread = 1 + AND n.notification_read = 0 AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 5eced0ca83..f29372923e 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -126,7 +126,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt WHERE n.item_type = '" . $this->get_type() . "' AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND n.unread = 1 + AND n.notification_read = 0 AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); @@ -326,7 +326,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Make sure that if the user has read the topic, it's marked as read in the notification if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time) { - $this->unread = false; + $this->notification_read = true; } return parent::create_insert_array($post, $pre_create_data); diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index b3a347f98c..5453b267c8 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -124,7 +124,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt WHERE n.item_type = '" . $this->get_type() . "' AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND n.unread = 1 + AND n.notification_read = 0 AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 6eb78c30bb..4f51ed4cb1 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -267,7 +267,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base // Make sure that if the user has read the topic, it's marked as read in the notification if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time) { - $this->unread = false; + $this->notification_read = true; } return parent::create_insert_array($post, $pre_create_data); -- cgit v1.2.1 From eeb40181956b578ca98ed0106f3019d8c8299ed3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 21:17:05 -0600 Subject: [ticket/11103] data -> notification_data PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 10 +++++----- phpBB/includes/notification/type/post.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index cdca9aa642..c262fbeedb 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -110,7 +110,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i { // The row from the database (unless this is a new notification we're going to add) $this->data = $data; - $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); + $this->data['notification_data'] = (isset($this->data['notification_data'])) ? unserialize($this->data['notification_data']) : array(); } public function __get($name) @@ -137,7 +137,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function get_data($name) { - return ($name === false) ? $this->data['data'] : ((isset($this->data['data'][$name])) ? $this->data['data'][$name] : null); + return ($name === false) ? $this->data['notification_data'] : ((isset($this->data['notification_data'][$name])) ? $this->data['notification_data'][$name] : null); } /** @@ -148,7 +148,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function set_data($name, $value) { - $this->data['data'][$name] = $value; + $this->data['notification_data'][$name] = $value; } /** @@ -171,12 +171,12 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'notification_time' => time(), 'notification_read' => false, - 'data' => array(), + 'notification_data' => array(), ), $this->data); $data = $this->data; - $data['data'] = serialize($data['data']); + $data['notification_data'] = serialize($data['notification_data']); return $data; } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index f29372923e..ddfa720e5e 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -342,7 +342,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Do not add them as a responder if they were the original poster that created the notification if ($this->get_data('poster_id') == $post['poster_id']) { - return array('data' => serialize($this->get_data(false))); + return array('notification_data' => serialize($this->get_data(false))); } $responders = $this->get_data('responders'); @@ -354,7 +354,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Do not add them as a responder multiple times if ($responder['poster_id'] == $post['poster_id']) { - return array('data' => serialize($this->get_data(false))); + return array('notification_data' => serialize($this->get_data(false))); } } @@ -365,6 +365,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $this->set_data('responders', $responders); - return array('data' => serialize($this->get_data(false))); + return array('notification_data' => serialize($this->get_data(false))); } } -- cgit v1.2.1 From 30356efab9503f44c26c6eebe6421911cd70ec64 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 21:54:19 -0600 Subject: [ticket/11103] updating comments PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index c262fbeedb..315bcb04c9 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -71,9 +71,9 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * item_id - ID of the item (e.g. post_id, msg_id) * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * user_id - * unread - * time - * data (special serialized field that each notification type can use to store stuff) + * notification_read + * notification_time + * notification_data (special serialized field that each notification type can use to store stuff) * * @var array $data Notification row from the database * This must be private, all interaction should use __get(), __set(), get_data(), set_data() -- cgit v1.2.1 From bf93dceb1f69cddc625b7dbbdf588847660070fa Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 26 Dec 2012 11:09:03 -0600 Subject: [ticket/11103] Fix merge conflict PHPBB3-11103 --- phpBB/includes/notification/manager.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index fa1fd4b81f..9858cda898 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -128,13 +128,8 @@ class phpbb_notification_manager $sql = 'SELECT COUNT(n.notification_id) AS unread_count FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt WHERE n.user_id = ' . (int) $options['user_id'] . ' -<<<<<<< HEAD - AND n.unread = 1 - AND nt.notification_type = n.item_type -======= AND n.notification_read = 0 - AND nt.notification_type = n.notification_type ->>>>>>> 5cedca0... [ticket/11103] unread -> notification_read + AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('unread_count', $result); -- cgit v1.2.1 From 5a8520da62a540f140319ecaef011fc49eaba451 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 27 Dec 2012 10:28:57 -0600 Subject: [ticket/11103] Fix some more merging issues PHPBB3-11103 --- phpBB/includes/notification/manager.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 9858cda898..52cfa77388 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -240,7 +240,7 @@ class phpbb_notification_manager SET notification_read = 1 WHERE notification_time <= " . $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . - (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . + (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : ''); $this->db->sql_query($sql); } @@ -269,8 +269,6 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET notification_read = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - SET notification_read = 1 - WHERE notification_type = '" . $this->db->sql_escape($notification_type) . "' AND notification_time <= " . $time . (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); -- cgit v1.2.1 From 192039a9e070f7ae09397d232d19d33a71e48ed2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 27 Dec 2012 10:30:21 -0600 Subject: [ticket/11103] Fix sending the user ids to get the username/avatar PHPBB3-11103 --- phpBB/includes/notification/type/pm.php | 2 +- phpBB/includes/notification/type/report_pm.php | 2 +- phpBB/includes/notification/type/report_pm_closed.php | 2 +- phpBB/includes/notification/type/report_post.php | 2 +- phpBB/includes/notification/type/report_post_closed.php | 2 +- phpBB/includes/notification/type/topic.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 8d31c87817..b3db7ad5ad 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -161,7 +161,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function users_to_query() { - return array($this->data['from_user_id']); + return array($this->get_data('from_user_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 877e8209e3..3fa73bab41 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -205,7 +205,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function users_to_query() { - return array($this->data['reporter_id']); + return array($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index a735d2a822..63dfa92064 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -130,7 +130,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p */ public function users_to_query() { - return array($this->data['closer_id']); + return array($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 0334fdb109..1ea532c929 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -172,7 +172,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function users_to_query() { - return array($this->data['reporter_id']); + return array($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 8b984fc8ce..3916cd8db7 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -130,7 +130,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function users_to_query() { - return array($this->data['closer_id']); + return array($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 4f51ed4cb1..71e074fb50 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -208,7 +208,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function users_to_query() { - return array($this->data['poster_id']); + return array($this->get_data('poster_id')); } /** -- cgit v1.2.1 From 07282a30ae077825ea81a4e26839ac0473dc97b7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 15 Jan 2013 12:10:07 -0600 Subject: [ticket/11103] Fix some various issues, better comments PHPBB3-11103 --- phpBB/includes/notification/manager.php | 40 +++++++++---- phpBB/includes/notification/method/base.php | 40 +++++++++---- phpBB/includes/notification/type/base.php | 92 +++++++++++++++++++++++------ 3 files changed, 130 insertions(+), 42 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 52cfa77388..a289ec0dfa 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -22,38 +22,54 @@ if (!defined('IN_PHPBB')) class phpbb_notification_manager { /** @var array */ - protected $notification_types = null; + protected $notification_types; /** @var array */ - protected $notification_methods = null; + protected $notification_methods; /** @var ContainerBuilder */ - protected $phpbb_container = null; + protected $phpbb_container; /** @var phpbb_user_loader */ - protected $user_loader = null; + protected $user_loader; /** @var phpbb_db_driver */ - protected $db = null; + protected $db; /** @var phpbb_user */ - protected $user = null; + protected $user; /** @var string */ - protected $phpbb_root_path = null; + protected $phpbb_root_path; /** @var string */ - protected $php_ext = null; + protected $php_ext; /** @var string */ - protected $notification_types_table = null; + protected $notification_types_table; /** @var string */ - protected $notifications_table = null; + protected $notifications_table; /** @var string */ - protected $user_notifications_table = null; + protected $user_notifications_table; + /** + * Notification Constructor + * + * @param array $notification_types + * @param array $notification_methods + * @param ContainerBuilder $phpbb_container + * @param phpbb_user_loader $user_loader + * @param phpbb_db_driver $db + * @param phpbb_user $user + * @param string $phpbb_root_path + * @param string $php_ext + * @param string $notification_types_table + * @param string $notifications_table + * @param string $user_notifications_table + * @return phpbb_notification_manager + */ public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) { $this->notification_types = $notification_types; @@ -78,7 +94,7 @@ class phpbb_notification_manager * @param array $options Optional options to control what notifications are loaded * notification_id Notification id to load (or array of notification ids) * user_id User id to load notifications for (Default: $user->data['user_id']) - * order_by Order by (Default: time) + * order_by Order by (Default: notification_time) * order_dir Order direction (Default: DESC) * limit Number of notifications to load (Default: 5) * start Notifications offset (Default: 0) diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index f37e7e7845..c4c0a64ae0 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -22,37 +22,37 @@ if (!defined('IN_PHPBB')) abstract class phpbb_notification_method_base implements phpbb_notification_method_interface { /** @var phpbb_notification_manager */ - protected $notification_manager = null; + protected $notification_manager; /** @var phpbb_user_loader */ - protected $user_loader = null; + protected $user_loader; /** @var phpbb_db_driver */ - protected $db = null; + protected $db; /** @var phpbb_cache_service */ - protected $cache = null; + protected $cache; /** @var phpbb_template */ - protected $template = null; + protected $template; /** @var phpbb_extension_manager */ - protected $extension_manager = null; + protected $extension_manager; /** @var phpbb_user */ - protected $user = null; + protected $user; /** @var phpbb_auth */ - protected $auth = null; + protected $auth; /** @var phpbb_config */ - protected $config = null; + protected $config; /** @var string */ - protected $phpbb_root_path = null; + protected $phpbb_root_path; /** @var string */ - protected $php_ext = null; + protected $php_ext; /** * Queue of messages to be sent @@ -61,6 +61,19 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); + /** + * Notification Method Base Constructor + * + * @param phpbb_user_loader $user_loader + * @param phpbb_db_driver $db + * @param phpbb_cache_driver_interface $cache + * @param mixed $user + * @param phpbb_auth $auth + * @param phpbb_config $config + * @param mixed $phpbb_root_path + * @param mixed $php_ext + * @return phpbb_notification_method_base + */ public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->user_loader = $user_loader; @@ -73,6 +86,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth $this->php_ext = $php_ext; } + /** + * Set notification manager (required) + * + * @param phpbb_notification_manager $notification_manager + */ public function set_notification_manager(phpbb_notification_manager $notification_manager) { $this->notification_manager = $notification_manager; diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 315bcb04c9..f52f14c09e 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -22,40 +22,43 @@ if (!defined('IN_PHPBB')) abstract class phpbb_notification_type_base implements phpbb_notification_type_interface { /** @var phpbb_notification_manager */ - protected $notification_manager = null; + protected $notification_manager; /** @var phpbb_user_loader */ - protected $user_loader = null; + protected $user_loader; /** @var phpbb_db_driver */ - protected $db = null; + protected $db; /** @var phpbb_cache_service */ - protected $cache = null; + protected $cache; /** @var phpbb_template */ - protected $template = null; + protected $template; /** @var phpbb_user */ - protected $user = null; + protected $user; /** @var phpbb_auth */ - protected $auth = null; + protected $auth; /** @var phpbb_config */ - protected $config = null; + protected $config; /** @var string */ - protected $phpbb_root_path = null; + protected $phpbb_root_path; /** @var string */ - protected $php_ext = null; + protected $php_ext; /** @var string */ - protected $notifications_table = null; + protected $notification_types_table; /** @var string */ - protected $user_notifications_table = null; + protected $notifications_table; + + /** @var string */ + protected $user_notifications_table; /** * Notification option data (for outputting to the user) @@ -80,7 +83,23 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + /** + * Notification Type Base Constructor + * + * @param phpbb_user_loader $user_loader + * @param phpbb_db_driver $db + * @param phpbb_cache_driver_interface $cache + * @param phpbb_user $user + * @param phpbb_auth $auth + * @param phpbb_config $config + * @param string $phpbb_root_path + * @param string $php_ext + * @param string $notification_types_table + * @param string $notifications_table + * @param string $user_notifications_table + * @return phpbb_notification_type_base + */ + public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) { $this->user_loader = $user_loader; $this->db = $db; @@ -92,10 +111,16 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->notification_types_table = $notification_types_table; $this->notifications_table = $notifications_table; $this->user_notifications_table = $user_notifications_table; } + /** + * Set notification manager (required) + * + * @param phpbb_notification_manager $notification_manager + */ public function set_notification_manager(phpbb_notification_manager $notification_manager) { $this->notification_manager = $notification_manager; @@ -113,16 +138,38 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->data['notification_data'] = (isset($this->data['notification_data'])) ? unserialize($this->data['notification_data']) : array(); } + /** + * Magic method to get data from this notification + * + * @param mixed $name + * @return mixed + */ public function __get($name) { return (!isset($this->data[$name])) ? null : $this->data[$name]; } + + /** + * Magic method to set data on this notification + * + * @param mixed $name + * @return mixed + */ public function __set($name, $value) { $this->data[$name] = $value; } + + /** + * Magic method to get a string of this notification + * + * Primarily for testing + * + * @param string $name + * @return mixed + */ public function __toString() { return (!empty($this->data)) ? var_export($this->data, true) : $this->get_type(); @@ -132,7 +179,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Get special data (only important for the classes that extend this) * * @param string $name Name of the variable to get - * * @return mixed */ protected function get_data($name) @@ -157,7 +203,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * * @param array $type_data Data unique to this notification type * @param array $pre_create_data Data from pre_create_insert_array() - * * @return array Array of data ready to be inserted into the database */ public function create_insert_array($type_data, $pre_create_data = array()) @@ -186,7 +231,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * (The service handles insertion) * * @param array $type_data Data unique to this notification type - * * @return array Array of data ready to be updated in the database */ public function create_update_array($type_data) @@ -208,7 +252,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Mark this item read * * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string + * @return string|null If $return is False, nothing will be returned, else the sql code to update this item */ public function mark_read($return = false) { @@ -219,7 +263,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Mark this item unread * * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string + * @return string|null If $return is False, nothing will be returned, else the sql code to update this item */ public function mark_unread($return = false) { @@ -228,6 +272,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Prepare to output the notification to the template + * + * @return array Template variables */ public function prepare_for_display() { @@ -274,6 +320,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Get the user's avatar (fall back) + * + * @return string */ public function get_avatar() { @@ -282,6 +330,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Get the special items to load (fall back) + * + * @return array */ public function get_load_special() { @@ -298,6 +348,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Is available (fall back) + * + * @return bool */ public function is_available() { @@ -306,6 +358,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Pre create insert array function (fall back) + * + * @return array */ public function pre_create_insert_array($type_data, $notify_users) { @@ -398,7 +452,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * * @param bool $unread Unread (True/False) (Default: False) * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string + * @return string|null If $return is False, nothing will be returned, else the sql code to update this item */ protected function mark($unread = true, $return = false) { -- cgit v1.2.1 From f089e099fed38b1bdae5316fb09f0c8ed847d495 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 15 Jan 2013 12:29:20 -0600 Subject: [ticket/11103] Including the set call in the declaration throws errors Call the set_notification_manager from the load_object function instead. PHPBB3-11103 --- phpBB/includes/notification/manager.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index a289ec0dfa..5c1016335a 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -841,6 +841,13 @@ class phpbb_notification_manager */ protected function load_object($object_name) { - return $this->phpbb_container->get($object_name); + $object = $this->phpbb_container->get($object_name); + + if (method_exists($object, 'set_notification_manager')) + { + $object->set_notification_manager($this); + } + + return $object; } } -- cgit v1.2.1 From bd499425522a61ddd617e9ac4cfed9a7859bf949 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 15 Jan 2013 12:54:39 -0600 Subject: [ticket/11103] Correcting constructor comments PHPBB3-11103 --- phpBB/includes/notification/method/base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index c4c0a64ae0..22418c9be8 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -67,11 +67,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth * @param phpbb_user_loader $user_loader * @param phpbb_db_driver $db * @param phpbb_cache_driver_interface $cache - * @param mixed $user + * @param phpbb_user $user * @param phpbb_auth $auth * @param phpbb_config $config - * @param mixed $phpbb_root_path - * @param mixed $php_ext + * @param string $phpbb_root_path + * @param string $php_ext * @return phpbb_notification_method_base */ public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) -- cgit v1.2.1 From b41b1a36d1ee85abc05c22b443db7b10af077f7e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 28 Feb 2013 15:25:18 -0600 Subject: [ticket/11103] Case time in queries as an int PHPBB3-11103 --- phpBB/includes/notification/manager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 5c1016335a..ff83d4bb37 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -254,7 +254,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET notification_read = 1 - WHERE notification_time <= " . $time . + WHERE notification_time <= " . (int) $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : ''); $this->db->sql_query($sql); @@ -285,7 +285,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET notification_read = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND notification_time <= " . $time . + AND notification_time <= " . (int) $time . (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); $this->db->sql_query($sql); @@ -303,7 +303,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET notification_read = 1 - WHERE notification_time <= " . $time . ' + WHERE notification_time <= " . (int) $time . ' AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); $this->db->sql_query($sql); } -- cgit v1.2.1 From ee264e723566eb96ab9d068d3da671778f49a4f2 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 28 Feb 2013 17:25:39 -0600 Subject: [ticket/11103] Don't call generate_board_url many times Fix a URL and some comments PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 3 ++- phpBB/includes/notification/type/report_post.php | 2 +- phpBB/includes/notification/type/topic.php | 10 ++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index f52f14c09e..600ef7c965 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -154,7 +154,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Magic method to set data on this notification * * @param mixed $name - * @return mixed + * @return null */ public function __set($name, $value) { @@ -191,6 +191,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * * @param string $name Name of the variable to set * @param mixed $value Value to set to the variable + * @return mixed */ protected function set_data($name, $value) { diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 1ea532c929..de5c54a291 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -99,7 +99,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - 'U_VIEW_REPORT' => "{$board_url}mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", + 'U_VIEW_REPORT' => "{$board_url}/mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 71e074fb50..2549b29409 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -170,6 +170,8 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function get_email_template_variables() { + $board_url = generate_board_url(); + if ($this->get_data('post_username')) { $username = $this->get_data('post_username'); @@ -184,10 +186,10 @@ class phpbb_notification_type_topic extends phpbb_notification_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", + 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->item_parent_id}", + 'U_STOP_WATCHING_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum", ); } -- cgit v1.2.1 From ab4c1b5d0c07dcf60e4dc41a4b6b4abfec64cd1e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 5 Mar 2013 10:28:52 -0600 Subject: [ticket/11400] If email is disabled, disable it for notifications PHPBB3-11400 --- phpBB/includes/notification/method/email.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index 429dfda2ba..4a7fea6df3 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -53,8 +53,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base */ public function is_available() { - // Email is always available - return true; + return (bool) $this->config['email_enable']; } /** -- cgit v1.2.1 From 0eb6f56a9ae6af541e4c12dec0235da0b508d65d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 5 Mar 2013 11:46:58 -0600 Subject: [ticket/11402] Fix undefined index in post/topic_in_queue PHPBB3-11402 --- phpBB/includes/notification/type/post_in_queue.php | 18 ++++++++++++---- .../includes/notification/type/topic_in_queue.php | 25 ++++++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/notification') diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 1c29bee3cd..9c719205e6 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -64,9 +64,9 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post */ public function is_available() { - $m_approve = $this->auth->acl_getf($this->permission, true); + $has_permission = $this->auth->acl_getf($this->permission, true); - return (!empty($m_approve)); + return (!empty($has_permission)); } /** @@ -90,9 +90,19 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post return array(); } - $auth_approve[$post['forum_id']] = array_unique(array_merge($auth_approve[$post['forum_id']], $auth_approve[0])); + $has_permission = array(); - return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, array( + if (isset($auth_approve[$post['forum_id']][$this->permission])) + { + $has_permission = $auth_approve[$post['forum_id']][$this->permission]; + } + + if (isset($auth_approve[0][$this->permission])) + { + $has_permission = array_unique(array_merge($has_permission, $auth_approve[0][$this->permission])); + } + + return $this->check_user_notification_options($has_permission, array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index dc0b9f9869..c501434c43 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -52,14 +52,21 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top 'group' => 'NOTIFICATION_GROUP_MODERATION', ); + /** + * Permission to check for (in find_users_for_notification) + * + * @var string Permission name + */ + protected $permission = 'm_approve'; + /** * Is available */ public function is_available() { - $m_approve = $this->auth->acl_getf('m_approve', true); + $has_permission = $this->auth->acl_getf($this->permission, true); - return (!empty($m_approve)); + return (!empty($has_permission)); } /** @@ -83,9 +90,19 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top return array(); } - $auth_approve[$topic['forum_id']] = array_unique(array_merge($auth_approve[$topic['forum_id']], $auth_approve[0])); + $has_permission = array(); + + if (isset($auth_approve[$topic['forum_id']][$this->permission])) + { + $has_permission = $auth_approve[$topic['forum_id']][$this->permission]; + } + + if (isset($auth_approve[0][$this->permission])) + { + $has_permission = array_unique(array_merge($has_permission, $auth_approve[0][$this->permission])); + } - return $this->check_user_notification_options($auth_approve[$topic['forum_id']]['m_approve'], array_merge($options, array( + return $this->check_user_notification_options($has_permission, array_merge($options, array( 'item_type' => self::$notification_option['id'], ))); } -- cgit v1.2.1