1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

[ticket/11103] Use the full class name as the item_type/method

This is going to require you recreate the db tables.

PHPBB3-11103
This commit is contained in:
Nathan Guse
2012-10-20 20:54:18 -05:00
parent 6861af22ee
commit 94d682f774
39 changed files with 412 additions and 543 deletions

View File

@@ -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'])
{

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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'];

View File

@@ -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'];

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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());
$item_class = $this->get_item_type_class($item_type_class_name);
$notifications[$row['notification_id']] = $notification;
}
$item_class->load_special($data, $notifications);
$this->load_users($user_ids);
// 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);
}
}
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;
}
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 (!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;
return $classes;
}
}

View File

@@ -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
*/

View File

@@ -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
*/

View File

@@ -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))

View File

@@ -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'];

View File

@@ -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
*

View File

@@ -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
*

View File

@@ -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
*

View File

@@ -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);

View File

@@ -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'];

View File

@@ -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
*/

View File

@@ -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);

View File

@@ -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
*

View File

@@ -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
*

View File

@@ -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
*

View File

@@ -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
*

View File

@@ -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))

View File

@@ -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
*

View File

@@ -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)),
));
}
}