diff options
Diffstat (limited to 'phpBB/includes')
26 files changed, 203 insertions, 323 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 2827dae1a8..3488a3003b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1330,7 +1330,14 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark all forums read (index page) // Mark all topic notifications read for this user - $phpbb_notifications->mark_notifications_read(array('topic', 'quote', 'bookmark', 'post', 'approve_topic', 'approve_post'), false, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read(array( + 'phpbb_notification_type_topic', + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + 'phpbb_notification_type_approve_topic', + 'phpbb_notification_type_approve_post', + ), false, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) { @@ -1386,7 +1393,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $forum_id = array($forum_id); } - $phpbb_notifications->mark_notifications_read_by_parent(array('topic', 'approve_topic'), $forum_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array( + 'phpbb_notification_type_topic', + 'phpbb_notification_type_approve_topic', + ), $forum_id, $user->data['user_id'], $post_time); // Mark all post/quote notifications read for this user in this forum $topic_ids = array(); @@ -1400,7 +1410,12 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } $db->sql_freeresult($result); - $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_ids, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + 'phpbb_notification_type_approve_post', + ), $topic_ids, $user->data['user_id'], $post_time); // Add 0 to forums array to mark global announcements correctly // $forum_id[] = 0; @@ -1500,8 +1515,16 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } // Mark post notifications read for this user in this topic - $phpbb_notifications->mark_notifications_read(array('topic', 'approve_topic'), $topic_id, $user->data['user_id'], $post_time); - $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read(array( + 'phpbb_notification_type_topic', + 'phpbb_notification_type_approve_topic', + ), $topic_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + 'phpbb_notification_type_approve_post', + ), $topic_id, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) { diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 893c7a247d..fdae1905a0 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -716,7 +716,11 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s set_config_count('num_topics', $approved_topics * (-1), true); } - $phpbb_notifications->delete_notifications(array('topic', 'approve_topic', 'topic_in_queue'), $topic_ids); + $phpbb_notifications->delete_notifications(array( + 'phpbb_notification_type_topic', + 'phpbb_notification_type_approve_topic', + 'phpbb_notification_type_topic_in_queue', + ), $topic_ids); return $return; } @@ -896,7 +900,13 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = delete_topics('topic_id', $remove_topics, $auto_sync, $post_count_sync, false); } - $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post', 'approve_post', 'post_in_queue'), $post_ids); + $phpbb_notifications->delete_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + 'phpbb_notification_type_approve_post', + 'phpbb_notification_type_post_in_queue', + ), $post_ids); return sizeof($post_ids); } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4deffe653b..02c31eb6cc 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2234,19 +2234,31 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post': - $phpbb_notifications->add_notifications(array('quote', 'topic'), $notification_data); + $phpbb_notifications->add_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_topic', + ), $notification_data); break; case 'reply': case 'quote': - $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $notification_data); + $phpbb_notifications->add_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + ), $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': - $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'topic', 'post'), $notification_data); + $phpbb_notifications->update_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_topic', + 'phpbb_notification_type_post', + ), $notification_data); break; } } @@ -2255,20 +2267,24 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post': - $phpbb_notifications->add_notifications(array('topic_in_queue'), $notification_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_topic_in_queue', $notification_data); break; case 'reply': case 'quote': - $phpbb_notifications->add_notifications(array('post_in_queue'), $notification_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_post_in_queue', $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': - $phpbb_notifications->delete_notifications('topic', $data['topic_id']); - $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']); + $phpbb_notifications->delete_notifications('phpbb_notification_type_topic', $data['topic_id']); + $phpbb_notifications->delete_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + ), $data['post_id']); break; } } diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 4638091601..ec671e4f41 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -878,7 +878,7 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) global $db, $user, $phpbb_notifications; - $phpbb_notifications->mark_notifications_read('pm', $msg_id, $user_id); + $phpbb_notifications->mark_notifications_read('phpbb_notification_type_pm', $msg_id, $user_id); $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . " SET pm_unread = 0 @@ -1096,7 +1096,7 @@ function delete_pm($user_id, $msg_ids, $folder_id) $user->data['user_unread_privmsg'] -= $num_unread; } - $phpbb_notifications->delete_notifications('pm', array_keys($delete_rows)); + $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', array_keys($delete_rows)); // Now we have to check which messages we can delete completely $sql = 'SELECT msg_id @@ -1260,7 +1260,7 @@ function phpbb_delete_user_pms($user_id) AND ' . $db->sql_in_set('msg_id', $delivered_msg); $db->sql_query($sql); - $phpbb_notifications->delete_notifications('pm', $delivered_msg); + $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $delivered_msg); } if (!empty($undelivered_msg)) @@ -1273,7 +1273,7 @@ function phpbb_delete_user_pms($user_id) WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); $db->sql_query($sql); - $phpbb_notifications->delete_notifications('pm', $undelivered_msg); + $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $undelivered_msg); } } @@ -1317,7 +1317,7 @@ function phpbb_delete_user_pms($user_id) WHERE ' . $db->sql_in_set('msg_id', $delete_ids); $db->sql_query($sql); - $phpbb_notifications->delete_notifications('pm', $delete_ids); + $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $delete_ids); } } @@ -1862,11 +1862,11 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) if ($mode == 'edit') { - $phpbb_notifications->update_notifications('pm', $pm_data); + $phpbb_notifications->update_notifications('phpbb_notification_type_pm', $pm_data); } else { - $phpbb_notifications->add_notifications('pm', $pm_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_pm', $pm_data); } return $data['msg_id']; diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index 001edfd8db..572969af4a 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -90,7 +90,7 @@ class mcp_pm_reports trigger_error('NO_REPORT'); } - $phpbb_notifications->mark_notifications_read_by_parent('report_pm', $report_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications_read_by_parent('phpbb_notification_type_report_pm', $report_id, $user->data['user_id']); $pm_id = $report['pm_id']; $report_id = $report['report_id']; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 72f1c00c72..f13ce914bf 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -86,7 +86,7 @@ class mcp_queue { $post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; - $phpbb_notifications->mark_notifications_read('topic_in_queue', $topic_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('phpbb_notification_type_topic_in_queue', $topic_id, $user->data['user_id']); } else { @@ -94,7 +94,7 @@ class mcp_queue } } - $phpbb_notifications->mark_notifications_read('post_in_queue', $post_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('phpbb_notification_type_post_in_queue', $post_id, $user->data['user_id']); $post_info = get_post_data(array($post_id), 'm_approve', true); @@ -610,24 +610,28 @@ function approve_post($post_id_list, $id, $mode) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) { - $phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']); + $phpbb_notifications->delete_notifications('phpbb_notification_type_topic_in_queue', $post_data['topic_id']); - $phpbb_notifications->add_notifications('topic', $post_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_topic', $post_data); if ($notify_poster) { - $phpbb_notifications->add_notifications('approve_topic', $post_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_approve_topic', $post_data); } } else { - $phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id); + $phpbb_notifications->delete_notifications('phpbb_notification_type_post_in_queue', $post_id); - $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); + $phpbb_notifications->add_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + ), $post_data); if ($notify_poster) { - $phpbb_notifications->add_notifications('approve_post', $post_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_approve_post', $post_data); } } } @@ -855,11 +859,11 @@ function disapprove_post($post_id_list, $id, $mode) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) { - $phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']); + $phpbb_notifications->delete_notifications('phpbb_notification_type_topic_in_queue', $post_data['topic_id']); } else { - $phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id); + $phpbb_notifications->delete_notifications('phpbb_notification_type_post_in_queue', $post_id); } } @@ -905,14 +909,14 @@ function disapprove_post($post_id_list, $id, $mode) { if ($notify_poster) { - $phpbb_notifications->add_notifications('disapprove_topic', $post_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_topic', $post_data); } } else { if ($notify_poster) { - $phpbb_notifications->add_notifications('disapprove_post', $post_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_post', $post_data); } } } diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index f6121e7e03..5bda6f2de7 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -88,7 +88,7 @@ class mcp_reports trigger_error('NO_REPORT'); } - $phpbb_notifications->mark_notifications_read('report_post', $post_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('phpbb_notification_type_report_post', $post_id, $user->data['user_id']); if (!$report_id && $report['report_closed']) { @@ -647,20 +647,20 @@ function close_report($report_id_list, $mode, $action, $pm = false) if ($pm) { - $phpbb_notifications->add_notifications('report_pm_closed', array_merge($post_info[$post_id], array( + $phpbb_notifications->add_notifications('phpbb_notification_type_report_pm_closed', array_merge($post_info[$post_id], array( 'reporter' => $reporter['user_id'], 'closer_id' => $user->data['user_id'], 'from_user_id' => $post_info[$post_id]['author_id'], ))); - $phpbb_notifications->delete_notifications('report_pm', $post_id); + $phpbb_notifications->delete_notifications('phpbb_notification_type_report_pm', $post_id); } else { - $phpbb_notifications->add_notifications('report_post_closed', array_merge($post_info[$post_id], array( + $phpbb_notifications->add_notifications('phpbb_notification_type_report_post_closed', array_merge($post_info[$post_id], array( 'reporter' => $reporter['user_id'], 'closer_id' => $user->data['user_id'], ))); - $phpbb_notifications->delete_notifications('report_post', $post_id); + $phpbb_notifications->delete_notifications('phpbb_notification_type_report_post', $post_id); } } } 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 . " @@ -693,36 +668,10 @@ class phpbb_notification_manager } /** - * 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 @@ -43,15 +43,6 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post ); /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'approve_post'; - } - - /** * Is available */ public function 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 @@ -43,15 +43,6 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi ); /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'approve_topic'; - } - - /** * Is available */ public function 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 @@ -43,15 +43,6 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap ); /** - * 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 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 @@ -43,15 +43,6 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a ); /** - * 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 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 @@ -29,12 +29,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 * * @param array $type_data The type specific data 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,19 +37,11 @@ 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 * * @param array $post The data from the post @@ -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 @@ -50,15 +50,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 */ public function 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 @@ -50,15 +50,6 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm ); /** - * 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 * * @param array $pm The data from the pm 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 @@ -43,15 +43,6 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p } /** - * 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 * * @param array $pm Data from 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 @@ -50,15 +50,6 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i ); /** - * 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 * * @param array $post Data from the post 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 @@ -43,15 +43,6 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type } /** - * 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 * * @param array $post Data from 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,19 +37,11 @@ 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 * * @param array $post The data from the post @@ -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 @@ -53,15 +53,6 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top } /** - * 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 array $topic Data from the topic diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index aeace13968..8749c88ba1 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -192,7 +192,7 @@ class ucp_notifications $template->assign_block_vars($block . '.notification_methods', array( 'METHOD' => $method, - 'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), + 'NAME' => $user->lang(strtoupper($method)), 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false, )); @@ -218,7 +218,7 @@ class ucp_notifications $template->assign_block_vars($block, array( 'METHOD' => $method, - 'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), + 'NAME' => $user->lang(strtoupper($method)), )); } } |
