PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,22 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification;
/**
* Notifications exception
*/
class exception extends \phpbb\exception\runtime_exception
{
}

View File

@ -0,0 +1,978 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Notifications service class
*/
class manager
{
/** @var array */
protected $notification_types;
/** @var array */
protected $subscription_types;
/** @var method\method_interface[] */
protected $notification_methods;
/** @var ContainerInterface */
protected $phpbb_container;
/** @var \phpbb\user_loader */
protected $user_loader;
/** @var \phpbb\event\dispatcher_interface */
protected $phpbb_dispatcher;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\cache\service */
protected $cache;
/** @var \phpbb\language\language */
protected $language;
/** @var \phpbb\user */
protected $user;
/** @var string */
protected $notification_types_table;
/** @var string */
protected $user_notifications_table;
/**
* Notification Constructor
*
* @param array $notification_types
* @param array $notification_methods
* @param ContainerInterface $phpbb_container
* @param \phpbb\user_loader $user_loader
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache
* @param \phpbb\language\language $language
* @param \phpbb\user $user
* @param string $notification_types_table
* @param string $user_notifications_table
*
* @return \phpbb\notification\manager
*/
public function __construct($notification_types, $notification_methods, ContainerInterface $phpbb_container, \phpbb\user_loader $user_loader, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\language\language $language, \phpbb\user $user, $notification_types_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->phpbb_dispatcher = $phpbb_dispatcher;
$this->db = $db;
$this->cache = $cache;
$this->language = $language;
$this->user = $user;
$this->notification_types_table = $notification_types_table;
$this->user_notifications_table = $user_notifications_table;
}
/**
* Load the user's notifications for a given method
*
* @param string $method_name
* @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: notification_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 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
* @throws \phpbb\notification\exception when the method doesn't refer to a class extending \phpbb\notification\method\method_interface
*/
public function load_notifications($method_name, array $options = array())
{
$method = $this->get_method_class($method_name);
if (! $method instanceof \phpbb\notification\method\method_interface)
{
throw new \phpbb\notification\exception($this->language->lang('NOTIFICATION_METHOD_INVALID', $method_name));
}
else if ($method->is_available())
{
return $method->load_notifications($options);
}
else
{
return array(
'notifications' => array(),
'unread_count' => 0,
'total_count' => 0,
);
}
}
/**
* Mark notifications read or unread for all available methods
*
* @param bool|string|array $notification_type_name 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)
*
* @deprecated since 3.2
*/
public function mark_notifications_read($notification_type_name, $item_id, $user_id, $time = false)
{
$this->mark_notifications($notification_type_name, $item_id, $user_id, $time);
}
/**
* Mark notifications read or unread for all available methods
*
* @param bool|string|array $notification_type_name 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)
* @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
*/
public function mark_notifications($notification_type_name, $item_id, $user_id, $time = false, $mark_read = true)
{
if (is_array($notification_type_name))
{
$notification_type_id = $this->get_notification_type_ids($notification_type_name);
}
else if ($notification_type_name !== false)
{
$notification_type_id = $this->get_notification_type_id($notification_type_name);
}
else
{
$notification_type_id = false;
}
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method)
{
$method->mark_notifications($notification_type_id, $item_id, $user_id, $time, $mark_read);
}
}
/**
* Mark notifications read or unread from a parent identifier for all available methods
*
* @param string|array $notification_type_name 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)
*
* @deprecated since 3.2
*/
public function mark_notifications_read_by_parent($notification_type_name, $item_parent_id, $user_id, $time = false)
{
$this->mark_notifications_by_parent($notification_type_name, $item_parent_id, $user_id, $time);
}
/**
* Mark notifications read or unread from a parent identifier for all available methods
*
* @param string|array $notification_type_name 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)
* @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
*/
public function mark_notifications_by_parent($notification_type_name, $item_parent_id, $user_id, $time = false, $mark_read = true)
{
if (is_array($notification_type_name))
{
$notification_type_id = $this->get_notification_type_ids($notification_type_name);
}
else
{
$notification_type_id = $this->get_notification_type_id($notification_type_name);
}
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method)
{
$method->mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time, $mark_read);
}
}
/**
* Mark notifications read or unread for a given method
*
* @param string $method_name
* @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)
* @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
*/
public function mark_notifications_by_id($method_name, $notification_id, $time = false, $mark_read = true)
{
$method = $this->get_method_class($method_name);
if ($method instanceof \phpbb\notification\method\method_interface && $method->is_available())
{
$method->mark_notifications_by_id($notification_id, $time, $mark_read);
}
}
/**
* Add a notification
*
* @param string|array $notification_type_name 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
* @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($notification_type_name, $data, array $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
if (is_array($notification_type_name))
{
$notified_users = array();
$temp_options = $options;
foreach ($notification_type_name as $type)
{
$temp_options['ignore_users'] = $options['ignore_users'] + $notified_users;
$notified_users += $this->add_notifications($type, $data, $temp_options);
}
return $notified_users;
}
// find out which users want to receive this type of notification
$notify_users = $this->get_item_type_class($notification_type_name)->find_users_for_notification($data, $options);
/**
* Allow filtering the notify_users array for a notification that is about to be sent.
* Here, $notify_users is already filtered by f_read and the ignored list included in the options variable
*
* @event core.notification_manager_add_notifications
* @var string notification_type_name The forum id from where the topic belongs
* @var array data Data specific for the notification_type_name used will be inserted
* @var array notify_users The array of userid that are going to be notified for this notification. Set to array() to cancel.
* @var array options The options that were used when this method was called (read only)
*
* @since 3.1.3-RC1
*/
$vars = array(
'notification_type_name',
'data',
'notify_users',
'options',
);
extract($this->phpbb_dispatcher->trigger_event('core.notification_manager_add_notifications', compact($vars)));
$this->add_notifications_for_users($notification_type_name, $data, $notify_users);
return $notify_users;
}
/**
* Add a notification for specific users
*
* @param string|array $notification_type_name 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($notification_type_name, $data, $notify_users)
{
if (is_array($notification_type_name))
{
foreach ($notification_type_name as $type)
{
$this->add_notifications_for_users($type, $data, $notify_users);
}
return;
}
$notification_type_id = $this->get_notification_type_id($notification_type_name);
$item_id = $this->get_item_type_class($notification_type_name)->get_item_id($data);
$user_ids = array();
$notification_methods = 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
// We remove each user which was already notified by at least one method.
/** @var method\method_interface $method */
foreach ($this->get_subscription_methods_instances() as $method)
{
$notified_users = $method->get_notified_users($notification_type_id, array('item_id' => $item_id));
foreach ($notified_users as $user => $notifications)
{
unset($notify_users[$user]);
}
}
if (!count($notify_users))
{
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($notification_type_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)
{
$notification = $this->get_item_type_class($notification_type_name);
$notification->user_id = (int) $user;
// Generate the insert_array
$notification->create_insert_array($data, $pre_create_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 (!isset($notification_methods[$method]))
{
$notification_methods[$method] = $this->get_method_class($method);
}
$notification_methods[$method]->add_to_queue($notification);
}
}
// We need to load all of the users to send notifications
$this->user_loader->load_users($user_ids);
// run the queue for each method to send notifications
foreach ($notification_methods as $method)
{
$method->notify();
}
}
/**
* Update notification
*
* @param string|array $notification_type_name 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
* @param array $options
*/
public function update_notifications($notification_type_name, array $data, array $options = array())
{
if (is_array($notification_type_name))
{
foreach ($notification_type_name as $type)
{
$this->update_notifications($type, $data);
}
return;
}
$this->update_notification($this->get_item_type_class($notification_type_name), $data, $options);
}
/**
* Update a notification
*
* @param \phpbb\notification\type\type_interface $notification The notification
* @param array $data Data specific for this type that will be updated
* @param array $options
*/
public function update_notification(\phpbb\notification\type\type_interface $notification, array $data, array $options = array())
{
if (empty($options))
{
$options['item_id'] = $notification->get_item_id($data);
}
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method)
{
$method->update_notification($notification, $data, $options);
}
}
/**
* Delete a notification
*
* @param string|array $notification_type_name 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 mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked)
* @param mixed $user_id User id (Default: false; not checked)
*/
public function delete_notifications($notification_type_name, $item_id, $parent_id = false, $user_id = false)
{
if (is_array($notification_type_name))
{
foreach ($notification_type_name as $type)
{
$this->delete_notifications($type, $item_id, $parent_id, $user_id);
}
return;
}
$notification_type_id = $this->get_notification_type_id($notification_type_name);
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method)
{
$method->delete_notifications($notification_type_id, $item_id, $parent_id, $user_id);
}
}
/**
* Get all of the subscription types
*
* @return array Array of item types
*/
public function get_subscription_types()
{
if ($this->subscription_types === null)
{
$this->subscription_types = array();
foreach ($this->notification_types as $type_name => $data)
{
/** @var type\base $type */
$type = $this->get_item_type_class($type_name);
if ($type instanceof \phpbb\notification\type\type_interface && $type->is_available())
{
$options = array_merge(array(
'type' => $type,
'id' => $type->get_type(),
'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()),
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS',
), (($type::$notification_option !== false) ? $type::$notification_option : array()));
$this->subscription_types[$options['group']][$options['id']] = $options;
}
}
// Move Miscellaneous to the very last section
if (isset($this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']))
{
$miscellaneous = $this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'];
unset($this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
$this->subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous;
}
}
return $this->subscription_types;
}
/**
* Get all of the subscription methods
*
* @return array Array of methods
*/
public function get_subscription_methods()
{
$subscription_methods = array();
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method_name => $method)
{
$subscription_methods[$method_name] = array(
'method' => $method,
'id' => $method->get_type(),
'lang' => str_replace('.', '_', strtoupper($method->get_type())),
);
}
return $subscription_methods;
}
/**
* Get all of the subscription methods
*
* @return array Array of method's instances
*/
private function get_subscription_methods_instances()
{
$subscription_methods = array();
foreach ($this->notification_methods as $method_name => $data)
{
$method = $this->get_method_class($method_name);
if ($method instanceof \phpbb\notification\method\method_interface)
{
$subscription_methods[$method_name] = $method;
}
}
return $subscription_methods;
}
/**
* Get all of the available subscription methods
*
* @return array Array of method's instances
*/
private function get_available_subscription_methods()
{
$subscription_methods = array();
/** @var method\method_interface $method */
foreach ($this->get_subscription_methods_instances() as $method_name => $method)
{
if ($method->is_available())
{
$subscription_methods[$method_name] = $method;
}
}
return $subscription_methods;
}
/**
* Get user's notification data
*
* @param int $user_id The user_id of the user to get the notifications for
*
* @return array User's notification
*/
protected function get_user_notifications($user_id)
{
$sql = 'SELECT method, notify, item_type
FROM ' . $this->user_notifications_table . '
WHERE user_id = ' . (int) $user_id . '
AND item_id = 0';
$result = $this->db->sql_query($sql);
$user_notifications = array();
while ($row = $this->db->sql_fetchrow($result))
{
$user_notifications[$row['item_type']][] = $row;
}
$this->db->sql_freeresult($result);
return $user_notifications;
}
/**
* Get global subscriptions (item_id = 0)
*
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*
* @return array Subscriptions
*/
public function get_global_subscriptions($user_id = false)
{
$user_id = $user_id ?: $this->user->data['user_id'];
$subscriptions = array();
$default_methods = $this->get_default_methods();
$user_notifications = $this->get_user_notifications($user_id);
foreach ($this->get_subscription_types() as $types)
{
foreach ($types as $id => $type)
{
$type_subscriptions = $default_methods;
if (!empty($user_notifications[$id]))
{
foreach ($user_notifications[$id] as $user_notification)
{
$key = array_search($user_notification['method'], $type_subscriptions, true);
if (!$user_notification['notify'])
{
if ($key !== false)
{
unset($type_subscriptions[$key]);
}
continue;
}
else if ($key === false)
{
$type_subscriptions[] = $user_notification['method'];
}
}
}
if (!empty($type_subscriptions))
{
$subscriptions[$id] = $type_subscriptions;
}
}
}
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. 'board', 'email', or 'jabber'
* (if null a subscription will be added for all the defaults methods)
* @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 = null, $user_id = false)
{
if ($method === null)
{
foreach ($this->get_default_methods() as $method_name)
{
$this->add_subscription($item_type, $item_id, $method_name, $user_id);
}
return;
}
$user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
$sql = 'SELECT notify
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 . "
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 ' . $this->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 ' . $this->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);
}
}
/**
* 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. 'board', '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 = null, $user_id = false)
{
if ($method === null)
{
foreach ($this->get_default_methods() as $method_name)
{
$this->delete_subscription($item_type, $item_id, $method_name, $user_id);
}
return;
}
$user_id = $user_id ?: $this->user->data['user_id'];
$sql = 'UPDATE ' . $this->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 ' . $this->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);
}
}
/**
* 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 $notification_type_name Type identifier of the subscription
*/
public function disable_notifications($notification_type_name)
{
$sql = 'UPDATE ' . $this->notification_types_table . "
SET notification_type_enabled = 0
WHERE notification_type_name = '" . $this->db->sql_escape($notification_type_name) . "'";
$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 $notification_type_name Type identifier of the subscription
*/
public function purge_notifications($notification_type_name)
{
// If a notification is never used, its type will not be added to the database
// nor its id cached. If this method is called by an extension during the
// purge step, and that extension never used its notifications,
// get_notification_type_id() will throw an exception. However,
// because no notification type was added to the database,
// there is nothing to delete, so we can silently drop the exception.
try
{
$notification_type_id = $this->get_notification_type_id($notification_type_name);
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method)
{
$method->purge_notifications($notification_type_id);
}
}
catch (\phpbb\notification\exception $e)
{
// Continue
}
}
/**
* 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 $notification_type_name Type identifier of the subscription
*/
public function enable_notifications($notification_type_name)
{
$sql = 'UPDATE ' . $this->notification_types_table . "
SET notification_type_enabled = 1
WHERE notification_type_name = '" . $this->db->sql_escape($notification_type_name) . "'";
$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
* @param bool $only_read True (default) to only prune read notifications
*/
public function prune_notifications($timestamp, $only_read = true)
{
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method)
{
$method->prune_notifications($timestamp, $only_read);
}
}
/**
* Helper to get the list of methods enabled by default
*
* @return method\method_interface[]
*/
public function get_default_methods()
{
$default_methods = array();
foreach ($this->notification_methods as $method)
{
if ($method->is_enabled_by_default() && $method->is_available())
{
$default_methods[] = $method->get_type();
}
}
return $default_methods;
}
/**
* Helper to get the notifications item type class and set it up
*
* @param string $notification_type_name
* @param array $data
* @return type\type_interface
*/
public function get_item_type_class($notification_type_name, $data = array())
{
$item = $this->load_object($notification_type_name);
$item->set_initial_data($data);
return $item;
}
/**
* Helper to get the notifications method class and set it up
*
* @param string $method_name
* @return method\method_interface
*/
public function get_method_class($method_name)
{
return $this->load_object($method_name);
}
/**
* Helper to load objects (notification types/methods)
*
* @param string $object_name
* @return method\method_interface|type\type_interface
*/
protected function load_object($object_name)
{
$object = $this->phpbb_container->get($object_name);
if (method_exists($object, 'set_notification_manager'))
{
$object->set_notification_manager($this);
}
return $object;
}
/**
* Get the notification type id from the name
*
* @param string $notification_type_name The name
* @return int the notification_type_id
* @throws \phpbb\notification\exception
*/
public function get_notification_type_id($notification_type_name)
{
$sql = 'SELECT notification_type_id, notification_type_name
FROM ' . $this->notification_types_table;
$result = $this->db->sql_query($sql, 604800); // cache for one week
while ($row = $this->db->sql_fetchrow($result))
{
$notification_type_ids[$row['notification_type_name']] = (int) $row['notification_type_id'];
}
$this->db->sql_freeresult($result);
if (!isset($notification_type_ids[$notification_type_name]))
{
if (!isset($this->notification_types[$notification_type_name]) && !isset($this->notification_types['notification.type.' . $notification_type_name]))
{
throw new \phpbb\notification\exception('NOTIFICATION_TYPE_NOT_EXIST', array($notification_type_name));
}
$sql = 'INSERT INTO ' . $this->notification_types_table . ' ' . $this->db->sql_build_array('INSERT', array(
'notification_type_name' => $notification_type_name,
'notification_type_enabled' => 1,
));
$this->db->sql_query($sql);
// expose new notification type ID for this request
$notification_type_ids[$notification_type_name] = (int) $this->db->sql_nextid();
// destroy cache, we have a new addition which we have to to load next time
$this->cache->destroy('sql', $this->notification_types_table);
}
return $notification_type_ids[$notification_type_name];
}
/**
* Get notification type ids (as an array)
*
* @param string|array $notification_type_names Notification type names
* @return array Array of integers
*/
public function get_notification_type_ids($notification_type_names)
{
if (!is_array($notification_type_names))
{
$notification_type_names = array($notification_type_names);
}
$notification_type_ids = array();
foreach ($notification_type_names as $name)
{
$notification_type_ids[$name] = $this->get_notification_type_id($name);
}
return $notification_type_ids;
}
/**
* Find the users which are already notified
*
* @param bool|string|array $notification_type_name Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to retrieve all item types
* @param array $options
* @return array The list of the notified users
*/
public function get_notified_users($notification_type_name, array $options)
{
$notification_type_id = $this->get_notification_type_id($notification_type_name);
$notified_users = array();
/** @var method\method_interface $method */
foreach ($this->get_available_subscription_methods() as $method)
{
$notified_users = $notified_users + $method->get_notified_users($notification_type_id, $options);
}
return $notified_users;
}
}

View File

@ -0,0 +1,137 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\method;
/**
* Base notifications method class
*/
abstract class base implements \phpbb\notification\method\method_interface
{
/** @var \phpbb\notification\manager */
protected $notification_manager;
/**
* Queue of messages to be sent
*
* @var array
*/
protected $queue = array();
/**
* 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;
}
/**
* Is the method enable by default?
*
* @return bool
*/
public function is_enabled_by_default()
{
return false;
}
/**
* {@inheritdoc}
*/
public function get_notified_users($notification_type_id, array $options)
{
return array();
}
/**
* {@inheritdoc}
*/
public function load_notifications(array $options = array())
{
return array(
'notifications' => array(),
'unread_count' => 0,
'total_count' => 0,
);
}
/**
* Add a notification to the queue
*
* @param \phpbb\notification\type\type_interface $notification
*/
public function add_to_queue(\phpbb\notification\type\type_interface $notification)
{
$this->queue[] = $notification;
}
/**
* {@inheritdoc}
*/
public function update_notification($notification, array $data, array $options)
{
}
/**
* {@inheritdoc
*/
public function mark_notifications($notification_type_id, $item_id, $user_id, $time = false, $mark_read = true)
{
}
/**
* {@inheritdoc}
*/
public function mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time = false, $mark_read = true)
{
}
/**
* {@inheritdoc}
*/
public function mark_notifications_by_id($notification_id, $time = false, $mark_read = true)
{
}
/**
* {@inheritdoc}
*/
public function delete_notifications($notification_type_id, $item_id, $parent_id = false, $user_id = false)
{
}
/**
* {@inheritdoc}
*/
public function prune_notifications($timestamp, $only_read = true)
{
}
/**
* {@inheritdoc}
*/
public function purge_notifications($notification_type_id)
{
}
/**
* Empty the queue
*/
protected function empty_queue()
{
$this->queue = array();
}
}

View File

@ -0,0 +1,399 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\method;
/**
* In Board notification method class
* This class handles in board notifications. This method is enabled by default.
*
* @package notifications
*/
class board extends \phpbb\notification\method\base
{
/** @var \phpbb\user_loader */
protected $user_loader;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\cache\driver\driver_interface */
protected $cache;
/** @var \phpbb\user */
protected $user;
/** @var \phpbb\config\config */
protected $config;
/** @var string */
protected $notification_types_table;
/** @var string */
protected $notifications_table;
/**
* Notification Method Board Constructor
*
* @param \phpbb\user_loader $user_loader
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\driver\driver_interface $cache
* @param \phpbb\user $user
* @param \phpbb\config\config $config
* @param string $notification_types_table
* @param string $notifications_table
*/
public function __construct(\phpbb\user_loader $user_loader, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, \phpbb\user $user, \phpbb\config\config $config, $notification_types_table, $notifications_table)
{
$this->user_loader = $user_loader;
$this->db = $db;
$this->cache = $cache;
$this->user = $user;
$this->config = $config;
$this->notification_types_table = $notification_types_table;
$this->notifications_table = $notifications_table;
}
/**
* {@inheritdoc}
*/
public function add_to_queue(\phpbb\notification\type\type_interface $notification)
{
$this->queue[] = $notification;
}
/**
* {@inheritdoc}
*/
public function get_type()
{
return 'notification.method.board';
}
/**
* {@inheritdoc}
*/
public function is_available()
{
return $this->config['allow_board_notifications'];
}
/**
* {@inheritdoc}
*/
public function is_enabled_by_default()
{
return true;
}
/**
* {@inheritdoc}
*/
public function get_notified_users($notification_type_id, array $options)
{
$notified_users = array();
$sql = 'SELECT n.*
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.notification_type_id = ' . (int) $notification_type_id .
(isset($options['item_id']) ? ' AND n.item_id = ' . (int) $options['item_id'] : '') .
(isset($options['item_parent_id']) ? ' AND n.item_parent_id = ' . (int) $options['item_parent_id'] : '') .
(isset($options['user_id']) ? ' AND n.user_id = ' . (int) $options['user_id'] : '') .
(isset($options['read']) ? ' AND n.notification_read = ' . (int) $options['read'] : '') .'
AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$notified_users[$row['user_id']] = $row;
}
$this->db->sql_freeresult($result);
return $notified_users;
}
/**
* {@inheritdoc}
*/
public function load_notifications(array $options = array())
{
// Merge default options
$options = array_merge(array(
'notification_id' => false,
'user_id' => $this->user->data['user_id'],
'order_by' => 'notification_time',
'order_dir' => 'DESC',
'limit' => 0,
'start' => 0,
'all_unread' => false,
'count_unread' => false,
'count_total' => false,
), $options);
// 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
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(),
'unread_count' => 0,
'total_count' => 0,
);
}
$notifications = $user_ids = array();
$load_special = array();
$total_count = $unread_count = 0;
if ($options['count_unread'])
{
// Get the total number of unread notifications
$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.notification_read = 0
AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
$unread_count = (int) $this->db->sql_fetchfield('unread_count');
$this->db->sql_freeresult($result);
}
if ($options['count_total'])
{
// Get the total number of notifications
$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_id = n.notification_type_id
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
$total_count = (int) $this->db->sql_fetchfield('total_count');
$this->db->sql_freeresult($result);
}
if (!$options['count_total'] || $total_count)
{
$rowset = array();
// Get the main notifications
$sql = 'SELECT n.*, nt.notification_type_name
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_id = n.notification_type_id
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))
{
$rowset[$row['notification_id']] = $row;
}
$this->db->sql_freeresult($result);
// Get all unread notifications
if ($unread_count && $options['all_unread'] && !empty($rowset))
{
$sql = 'SELECT n.*, nt.notification_type_name
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.user_id = ' . (int) $options['user_id'] . '
AND n.notification_read = 0
AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . '
AND nt.notification_type_id = n.notification_type_id
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))
{
$rowset[$row['notification_id']] = $row;
}
$this->db->sql_freeresult($result);
}
foreach ($rowset as $row)
{
$notification = $this->notification_manager->get_item_type_class($row['notification_type_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['notification_type_name']]))
{
$load_special[$row['notification_type_name']] = array();
}
$load_special[$row['notification_type_name']] = array_merge($load_special[$row['notification_type_name']], $notification->get_load_special());
$notifications[$row['notification_id']] = $notification;
}
$this->user_loader->load_users($user_ids);
// Allow each type to load its own special items
foreach ($load_special as $item_type => $data)
{
$item_class = $this->notification_manager->get_item_type_class($item_type);
$item_class->load_special($data, $notifications);
}
}
return array(
'notifications' => $notifications,
'unread_count' => $unread_count,
'total_count' => $total_count,
);
}
/**
* {@inheritdoc}
*/
public function notify()
{
$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->notifications_table);
/** @var \phpbb\notification\type\type_interface $notification */
foreach ($this->queue as $notification)
{
$data = $notification->get_insert_array();
$insert_buffer->insert($data);
}
$insert_buffer->flush();
// We're done, empty the queue
$this->empty_queue();
}
/**
* {@inheritdoc}
*/
public function update_notification($notification, array $data, array $options)
{
// Allow the notifications class to over-ride the update_notifications functionality
if (method_exists($notification, 'update_notifications'))
{
// Return False to over-ride the rest of the update
if ($notification->update_notifications($data) === false)
{
return;
}
}
$notification_type_id = $this->notification_manager->get_notification_type_id($notification->get_type());
$update_array = $notification->create_update_array($data);
$sql = 'UPDATE ' . $this->notifications_table . '
SET ' . $this->db->sql_build_array('UPDATE', $update_array) . '
WHERE notification_type_id = ' . (int) $notification_type_id .
(isset($options['item_id']) ? ' AND item_id = ' . (int) $options['item_id'] : '') .
(isset($options['item_parent_id']) ? ' AND item_parent_id = ' . (int) $options['item_parent_id'] : '') .
(isset($options['user_id']) ? ' AND user_id = ' . (int) $options['user_id'] : '') .
(isset($options['read']) ? ' AND notification_read = ' . (int) $options['read'] : '');
$this->db->sql_query($sql);
}
/**
* {@inheritdoc}
*/
public function mark_notifications($notification_type_id, $item_id, $user_id, $time = false, $mark_read = true)
{
$time = ($time !== false) ? $time : time();
$sql = 'UPDATE ' . $this->notifications_table . '
SET notification_read = ' . ($mark_read ? 1 : 0) . '
WHERE notification_time <= ' . (int) $time .
(($notification_type_id !== false) ? ' AND ' .
(is_array($notification_type_id) ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : 'notification_type_id = ' . $notification_type_id) : '') .
(($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_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);
}
/**
* {@inheritdoc}
*/
public function mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time = false, $mark_read = true)
{
$time = ($time !== false) ? $time : time();
$sql = 'UPDATE ' . $this->notifications_table . '
SET notification_read = ' . ($mark_read ? 1 : 0) . '
WHERE notification_time <= ' . (int) $time .
(($notification_type_id !== false) ? ' AND ' .
(is_array($notification_type_id) ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : 'notification_type_id = ' . $notification_type_id) : '') .
(($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id, false, true) : '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);
}
/**
* {@inheritdoc}
*/
public function mark_notifications_by_id($notification_id, $time = false, $mark_read = true)
{
$time = ($time !== false) ? $time : time();
$sql = 'UPDATE ' . $this->notifications_table . '
SET notification_read = ' . ($mark_read ? 1 : 0) . '
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);
}
/**
* {@inheritdoc}
*/
public function delete_notifications($notification_type_id, $item_id, $parent_id = false, $user_id = false)
{
$sql = 'DELETE FROM ' . $this->notifications_table . '
WHERE notification_type_id = ' . (int) $notification_type_id . '
AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) .
(($parent_id !== false) ? ' AND ' . ((is_array($parent_id) ? $this->db->sql_in_set('item_parent_id', $parent_id) : 'item_parent_id = ' . (int) $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);
}
/**
* {@inheritdoc}
*/
public function prune_notifications($timestamp, $only_read = true)
{
$sql = 'DELETE FROM ' . $this->notifications_table . '
WHERE notification_time < ' . (int) $timestamp .
(($only_read) ? ' AND notification_read = 1' : '');
$this->db->sql_query($sql);
$this->config->set('read_notification_last_gc', time(), false);
}
/**
* {@inheritdoc}
*/
public function purge_notifications($notification_type_id)
{
$sql = 'DELETE FROM ' . $this->notifications_table . '
WHERE notification_type_id = ' . (int) $notification_type_id;
$this->db->sql_query($sql);
$sql = 'DELETE FROM ' . $this->notification_types_table . '
WHERE notification_type_id = ' . (int) $notification_type_id;
$this->db->sql_query($sql);
$this->cache->destroy('sql', $this->notification_types_table);
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\method;
use phpbb\notification\type\type_interface;
/**
* Email notification method class
* This class handles sending emails for notifications
*/
class email extends \phpbb\notification\method\messenger_base
{
/** @var \phpbb\user */
protected $user;
/** @var \phpbb\config\config */
protected $config;
/**
* Notification Method email Constructor
*
* @param \phpbb\user_loader $user_loader
* @param \phpbb\user $user
* @param \phpbb\config\config $config
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(\phpbb\user_loader $user_loader, \phpbb\user $user, \phpbb\config\config $config, $phpbb_root_path, $php_ext)
{
parent::__construct($user_loader, $phpbb_root_path, $php_ext);
$this->user = $user;
$this->config = $config;
}
/**
* Get notification method name
*
* @return string
*/
public function get_type()
{
return 'notification.method.email';
}
/**
* Is this method available for the user?
* This is checked on the notifications options
*
* @param type_interface $notification_type An optional instance of a notification type. If provided, this
* method additionally checks if the type provides an email template.
* @return bool
*/
public function is_available(type_interface $notification_type = null)
{
return parent::is_available($notification_type) && $this->config['email_enable'] && !empty($this->user->data['user_email']);
}
/**
* Parse the queue and notify the users
*/
public function notify()
{
return $this->notify_using_messenger(NOTIFY_EMAIL);
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\method;
use phpbb\notification\type\type_interface;
/**
* Jabber notification method class
* This class handles sending Jabber messages for notifications
*/
class jabber extends \phpbb\notification\method\messenger_base
{
/** @var \phpbb\user */
protected $user;
/** @var \phpbb\config\config */
protected $config;
/**
* Notification Method jabber Constructor
*
* @param \phpbb\user_loader $user_loader
* @param \phpbb\user $user
* @param \phpbb\config\config $config
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(\phpbb\user_loader $user_loader, \phpbb\user $user, \phpbb\config\config $config, $phpbb_root_path, $php_ext)
{
parent::__construct($user_loader, $phpbb_root_path, $php_ext);
$this->user = $user;
$this->config = $config;
}
/**
* Get notification method name
*
* @return string
*/
public function get_type()
{
return 'notification.method.jabber';
}
/**
* Is this method available for the user?
* This is checked on the notifications options
*
* @param type_interface $notification_type An optional instance of a notification type. If provided, this
* method additionally checks if the type provides an email template.
* @return bool
*/
public function is_available(type_interface $notification_type = null)
{
return parent::is_available($notification_type) && $this->global_available() && $this->user->data['user_jabber'];
}
/**
* Is this method available at all?
* This is checked before notifications are sent
*/
public function global_available()
{
return !(
empty($this->config['jab_enable']) ||
empty($this->config['jab_host']) ||
empty($this->config['jab_username']) ||
empty($this->config['jab_password']) ||
!@extension_loaded('xml')
);
}
public function notify()
{
if (!$this->global_available())
{
return;
}
$this->notify_using_messenger(NOTIFY_IM, 'short/');
}
}

View File

@ -0,0 +1,134 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\method;
use phpbb\notification\type\type_interface;
/**
* Abstract notification method handling email and jabber notifications
* using the phpBB messenger.
*/
abstract class messenger_base extends \phpbb\notification\method\base
{
/** @var \phpbb\user_loader */
protected $user_loader;
/** @var string */
protected $phpbb_root_path;
/** @var string */
protected $php_ext;
/**
* Notification Method Board Constructor
*
* @param \phpbb\user_loader $user_loader
* @param string $phpbb_root_path
* @param string $php_ext
*/
public function __construct(\phpbb\user_loader $user_loader, $phpbb_root_path, $php_ext)
{
$this->user_loader = $user_loader;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* Is this method available for the user?
* This is checked on the notifications options
*
* @param type_interface $notification_type An optional instance of a notification type. This method returns false
* only if the type is provided and if it doesn't provide an email template.
* @return bool
*/
public function is_available(type_interface $notification_type = null)
{
return $notification_type === null || $notification_type->get_email_template() !== false;
}
/**
* Notify using phpBB messenger
*
* @param int $notify_method Notify method for messenger (e.g. NOTIFY_IM)
* @param string $template_dir_prefix Base directory to prepend to the email template name
*
* @return null
*/
protected function notify_using_messenger($notify_method, $template_dir_prefix = '')
{
if (empty($this->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_root_path . 'includes/functions_user.' . $this->php_ext);
}
$banned_users = phpbb_get_banned_user_ids($user_ids);
// Load all the users we need
$this->user_loader->load_users(array_diff($user_ids, $banned_users), array(USER_IGNORE));
// Load the messenger
if (!class_exists('messenger'))
{
include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
}
$messenger = new \messenger();
// Time to go through the queue and send emails
/** @var \phpbb\notification\type\type_interface $notification */
foreach ($this->queue as $notification)
{
if ($notification->get_email_template() === false)
{
continue;
}
$user = $this->user_loader->get_user($notification->user_id);
if ($user['user_type'] == USER_INACTIVE && $user['user_inactive_reason'] == INACTIVE_MANUAL)
{
continue;
}
$messenger->template($notification->get_email_template(), $user['user_lang'], '', $template_dir_prefix);
$messenger->set_addresses($user);
$messenger->assign_vars(array_merge(array(
'USERNAME' => $user['username'],
'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications&mode=notification_options',
), $notification->get_email_template_variables()));
$messenger->send($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();
}
}

View File

@ -0,0 +1,149 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\method;
/**
* Base notifications method interface
*/
interface method_interface
{
/**
* Get notification method name
*
* @return string
*/
public function get_type();
/**
* Is the method enable by default?
*
* @return bool
*/
public function is_enabled_by_default();
/**
* Is this method available for the user?
* This is checked on the notifications options
*/
public function is_available();
/**
* Return the list of the users already notified
*
* @param int $notification_type_id Type of the notification
* @param array $options
* @return array User
*/
public function get_notified_users($notification_type_id, array $options);
/**
* 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: notification_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 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(array $options = array());
/**
* Add a notification to the queue
*
* @param \phpbb\notification\type\type_interface $notification
*/
public function add_to_queue(\phpbb\notification\type\type_interface $notification);
/**
* Parse the queue and notify the users
*/
public function notify();
/**
* Update a notification
*
* @param \phpbb\notification\type\type_interface $notification Notification to update
* @param array $data Data specific for this type that will be updated
* @param array $options
*/
public function update_notification($notification, array $data, array $options);
/**
* Mark notifications read or unread
*
* @param bool|string $notification_type_id Type identifier of item 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)
* @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
*/
public function mark_notifications($notification_type_id, $item_id, $user_id, $time = false, $mark_read = true);
/**
* Mark notifications read or unread from a parent identifier
*
* @param string $notification_type_id Type identifier of item 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)
* @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
*/
public function mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time = false, $mark_read = true);
/**
* Mark notifications read or unread
*
* @param int $notification_id Notification id 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)
* @param bool $mark_read Define if the notification as to be set to True or False. (Default: True)
*/
public function mark_notifications_by_id($notification_id, $time = false, $mark_read = true);
/**
* Delete a notification
*
* @param string $notification_type_id Type identifier of item types
* @param int|array $item_id Identifier within the type (or array of ids)
* @param mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked)
* @param mixed $user_id User id (Default: false; not checked)
*/
public function delete_notifications($notification_type_id, $item_id, $parent_id = false, $user_id = false);
/**
* Delete all notifications older than a certain time
*
* @param int $timestamp Unix timestamp to delete all notifications that were created before
* @param bool $only_read True (default) to only prune read notifications
*/
public function prune_notifications($timestamp, $only_read = true);
/**
* 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 $notification_type_id Type identifier of the subscription
*/
public function purge_notifications($notification_type_id);
}

View File

@ -0,0 +1,185 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Admin activation notifications class
* This class handles notifications for users requiring admin activation
*/
class admin_activate_user extends \phpbb\notification\type\base
{
/**
* {@inheritdoc}
*/
public function get_type()
{
return 'notification.type.admin_activate_user';
}
/**
* {@inheritdoc}
*/
protected $language_key = 'NOTIFICATION_ADMIN_ACTIVATE_USER';
/**
* {@inheritdoc}
*/
static public $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_ADMIN_ACTIVATE_USER',
'group' => 'NOTIFICATION_GROUP_ADMINISTRATION',
);
/** @var \phpbb\user_loader */
protected $user_loader;
/** @var \phpbb\config\config */
protected $config;
public function set_config(\phpbb\config\config $config)
{
$this->config = $config;
}
public function set_user_loader(\phpbb\user_loader $user_loader)
{
$this->user_loader = $user_loader;
}
/**
* {@inheritdoc}
*/
public function is_available()
{
return ($this->auth->acl_get('a_user') && $this->config['require_activation'] == USER_ACTIVATION_ADMIN);
}
/**
* {@inheritdoc}
*/
static public function get_item_id($user)
{
return (int) $user['user_id'];
}
/**
* {@inheritdoc}
*/
static public function get_item_parent_id($post)
{
return 0;
}
/**
* {@inheritdoc}
*/
public function find_users_for_notification($user, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
// Grab admins that have permission to administer users.
$admin_ary = $this->auth->acl_get_list(false, 'a_user', false);
$users = (!empty($admin_ary[0]['a_user'])) ? $admin_ary[0]['a_user'] : array();
// Grab founders
$sql = 'SELECT user_id
FROM ' . USERS_TABLE . '
WHERE user_type = ' . USER_FOUNDER;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$users[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
if (empty($users))
{
return array();
}
$users = array_unique($users);
return $this->check_user_notification_options($users, $options);
}
/**
* {@inheritdoc}
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->item_id, false, true);
}
/**
* {@inheritdoc}
*/
public function get_title()
{
$username = $this->user_loader->get_username($this->item_id, 'no_profile');
return $this->language->lang($this->language_key, $username);
}
/**
* {@inheritdoc}
*/
public function get_email_template()
{
return 'admin_activate';
}
/**
* {@inheritdoc}
*/
public function get_email_template_variables()
{
$board_url = generate_board_url();
$username = $this->user_loader->get_username($this->item_id, 'username');
return array(
'USERNAME' => htmlspecialchars_decode($username),
'U_USER_DETAILS' => "{$board_url}/memberlist.{$this->php_ext}?mode=viewprofile&u={$this->item_id}",
'U_ACTIVATE' => "{$board_url}/ucp.{$this->php_ext}?mode=activate&u={$this->item_id}&k={$this->get_data('user_actkey')}",
);
}
/**
* {@inheritdoc}
*/
public function get_url()
{
return $this->user_loader->get_username($this->item_id, 'profile');
}
/**
* {@inheritdoc}
*/
public function users_to_query()
{
return array($this->item_id);
}
/**
* {@inheritdoc}
*/
public function create_insert_array($user, $pre_create_data = array())
{
$this->set_data('user_actkey', $user['user_actkey']);
$this->notification_time = $user['user_regdate'];
parent::create_insert_array($user, $pre_create_data);
}
}

View File

@ -0,0 +1,149 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Post approved notifications class
* This class handles notifications for posts when they are approved (to their authors)
*/
class approve_post extends \phpbb\notification\type\post
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.approve_post';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_POST_APPROVED';
/**
* Inherit notification read status from post.
*
* @var bool
*/
protected $inherit_read_status = false;
/**
* 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')
*/
static public $notification_option = array(
'id' => 'moderation_queue',
'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/**
* Is available
*/
public function is_available()
{
return !$this->auth->acl_get('m_approve');
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$users = array();
$users[$post['poster_id']] = $this->notification_manager->get_default_methods();
return $this->get_authorised_recipients(array_keys($users), $post['forum_id'], array_merge($options, array(
'item_type' => static::$notification_option['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)
{
// 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();
}
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$this->set_data('post_subject', $post['post_subject']);
parent::create_insert_array($post, $pre_create_data);
$this->notification_time = time();
}
/**
* {@inheritdoc}
*/
public function get_insert_array()
{
$data = parent::get_insert_array();
$data['notification_time'] = $this->notification_time;
return $data;
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'post_approved';
}
/**
* {inheritDoc}
*/
public function get_redirect_url()
{
return $this->get_url();
}
}

View File

@ -0,0 +1,140 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Topic approved notifications class
* This class handles notifications for topics when they are approved (for authors)
*/
class approve_topic extends \phpbb\notification\type\topic
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.approve_topic';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_TOPIC_APPROVED';
/**
* Inherit notification read status from topic.
*
* @var bool
*/
protected $inherit_read_status = false;
/**
* 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')
*/
static public $notification_option = array(
'id' => 'moderation_queue',
'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/**
* Is available
*/
public function is_available()
{
return !$this->auth->acl_get('m_approve');
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$users = array();
$users[$post['poster_id']] = $this->notification_manager->get_default_methods();
return $this->get_authorised_recipients(array_keys($users), $post['forum_id'], array_merge($options, array(
'item_type' => static::$notification_option['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)
{
// 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();
}
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
parent::create_insert_array($post, $pre_create_data);
$this->notification_time = time();
}
/**
* {@inheritdoc}
*/
public function get_insert_array()
{
$data = parent::get_insert_array();
$data['notification_time'] = $this->notification_time;
return $data;
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'topic_approved';
}
}

View File

@ -0,0 +1,577 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Base notifications class
*/
abstract class base implements \phpbb\notification\type\type_interface
{
/** @var \phpbb\notification\manager */
protected $notification_manager;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\language\language */
protected $language;
/** @var \phpbb\user */
protected $user;
/** @var \phpbb\auth\auth */
protected $auth;
/** @var string */
protected $phpbb_root_path;
/** @var string */
protected $php_ext;
/** @var string */
protected $user_notifications_table;
/**
* 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', 'lang', and 'group')
*/
static public $notification_option = false;
/**
* The notification_type_id, set upon creation of the class
* This is the notification_type_id from the notification_types table
*
* @var int
*/
protected $notification_type_id;
/**
* Identification data
* notification_type_id - ID of the item type (auto generated, from notification types table)
* 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
* 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()
*/
private $data = array();
/**
* Notification Type Base Constructor
*
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\language\language $language
* @param \phpbb\user $user
* @param \phpbb\auth\auth $auth
* @param string $phpbb_root_path
* @param string $php_ext
* @param string $user_notifications_table
*/
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\language\language $language, \phpbb\user $user, \phpbb\auth\auth $auth, $phpbb_root_path, $php_ext, $user_notifications_table)
{
$this->db = $db;
$this->language = $language;
$this->user = $user;
$this->auth = $auth;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$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;
$this->notification_type_id = $this->notification_manager->get_notification_type_id($this->get_type());
}
/**
* 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['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
* @param mixed $value
*
* @return null
*/
public function __set($name, $value)
{
$this->data[$name] = $value;
}
/**
* Magic method to get a string of this notification
*
* Primarily for testing
*
* @return mixed
*/
public function __toString()
{
return (!empty($this->data)) ? var_export($this->data, true) : $this->get_type();
}
/**
* 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 ($name === false) ? $this->data['notification_data'] : ((isset($this->data['notification_data'][$name])) ? $this->data['notification_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
* @return mixed
*/
protected function set_data($name, $value)
{
$this->data['notification_data'][$name] = $value;
}
/**
* {@inheritdoc}
*/
public function create_insert_array($type_data, $pre_create_data = array())
{
// Defaults
$this->data = array_merge(array(
'item_id' => static::get_item_id($type_data),
'notification_type_id' => $this->notification_type_id,
'item_parent_id' => static::get_item_parent_id($type_data),
'notification_time' => time(),
'notification_read' => false,
'notification_data' => array(),
), $this->data);
}
/**
* {@inheritdoc}
*/
public function get_insert_array()
{
$data = $this->data;
$data['notification_data'] = serialize($data['notification_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)
{
$this->create_insert_array($type_data);
$data = $this->get_insert_array();
// Unset data unique to each row
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['notification_read'],
$data['user_id']
);
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|null If $return is False, nothing will be returned, else the sql code to update this item
*/
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|null If $return is False, nothing will be returned, else the sql code to update this item
*/
public function mark_unread($return = false)
{
return $this->mark(true, $return);
}
/**
* {inheritDoc}
*/
public function get_redirect_url()
{
return $this->get_url();
}
/**
* Prepare to output the notification to the template
*
* @return array Template variables
*/
public function prepare_for_display()
{
$mark_hash = generate_link_hash('mark_notification_read');
if ($this->get_url())
{
$u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&amp;hash=' . $mark_hash);
}
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 . '&amp;hash=' . $mark_hash . '&amp;redirect=' . urlencode($redirect));
}
return array(
'NOTIFICATION_ID' => $this->notification_id,
'STYLING' => $this->get_style_class(),
'AVATAR' => $this->get_avatar(),
'FORMATTED_TITLE' => $this->get_title(),
'REFERENCE' => $this->get_reference(),
'FORUM' => $this->get_forum(),
'REASON' => $this->get_reason(),
'URL' => $this->get_url(),
'TIME' => $this->user->format_date($this->notification_time),
'UNREAD' => !$this->notification_read,
'U_MARK_READ' => (!$this->notification_read) ? $u_mark_read : '',
);
}
/**
* -------------- 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
* @return false
*/
public function get_unsubscribe_url($method = false)
{
return false;
}
/**
* Get the CSS style class of the notification (fall back)
*
* @return string
*/
public function get_style_class()
{
return '';
}
/**
* Get the user's avatar (fall back)
*
* @return string
*/
public function get_avatar()
{
return '';
}
/**
* Get the reference of the notifcation (fall back)
*
* @return string
*/
public function get_reference()
{
return '';
}
/**
* Get the forum of the notification reference (fall back)
*
* @return string
*/
public function get_forum()
{
return '';
}
/**
* Get the reason for the notifcation (fall back)
*
* @return string
*/
public function get_reason()
{
return '';
}
/**
* Get the special items to load (fall back)
*
* @return array
*/
public function get_load_special()
{
return array();
}
/**
* Load the special items (fall back)
*
* @param array $data
* @param array $notifications
*/
public function load_special($data, $notifications)
{
return;
}
/**
* Is available (fall back)
*
* @return bool
*/
public function is_available()
{
return true;
}
/**
* Pre create insert array function (fall back)
*
* @param array $type_data
* @param array $notify_users
* @return array
*/
public function pre_create_insert_array($type_data, $notify_users)
{
return array();
}
/**
* -------------- Helper functions -------------------
*/
/**
* Find the users who want to receive notifications (helper)
*
* @param array|bool $user_ids User IDs to check if they want to receive notifications
* (Bool False to check all users besides anonymous and bots (USER_IGNORE))
* @param array $options
* @return array
*/
protected function check_user_notification_options($user_ids = false, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
'item_type' => $this->get_type(),
'item_id' => 0, // Global by default
), $options);
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 = $output = array();
$sql = 'SELECT user_id, method, notify
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'];
$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']]))
{
$rowset[$row['user_id']] = array();
}
$rowset[$row['user_id']][$row['method']] = $row['notify'];
if (!isset($output[$row['user_id']]))
{
$output[$row['user_id']] = array();
}
if ($row['notify'])
{
$output[$row['user_id']][] = $row['method'];
}
}
$this->db->sql_freeresult($result);
$default_methods = $this->notification_manager->get_default_methods();
foreach ($user_ids as $user_id)
{
if (isset($options['ignore_users'][$user_id]))
{
continue;
}
if (!array_key_exists($user_id, $rowset))
{
// No rows at all for this user, use the default methods
$output[$user_id] = $default_methods;
}
else
{
foreach ($default_methods as $default_method)
{
if (!array_key_exists($default_method, $rowset[$user_id]))
{
// No user preference for this type recorded, but it should be enabled by default.
$output[$user_id][] = $default_method;
}
}
}
}
return $output;
}
/**
* 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|null If $return is False, nothing will be returned, else the sql code to update this item
*/
protected function mark($unread = true, $return = false)
{
$this->notification_read = (bool) !$unread;
if ($return)
{
$where = array(
'notification_type_id = ' . (int) $this->notification_type_id,
'item_id = ' . (int) $this->item_id,
'user_id = ' . (int) $this->user_id,
);
$where = implode(' AND ', $where);
return $where;
}
else
{
$this->notification_manager->mark_notifications($this->get_type(), (int) $this->item_id, (int) $this->user_id, false, $this->notification_read);
}
return null;
}
/**
* Get a list of users that are authorised to receive notifications
*
* @param array $users Array of users that have subscribed to a notification
* @param int $forum_id Forum ID of the forum
* @param array $options Array of notification options
* @param bool $sort Whether the users array should be sorted. Default: false
* @return array Array of users that are authorised recipients
*/
protected function get_authorised_recipients($users, $forum_id, $options, $sort = false)
{
if (empty($users))
{
return array();
}
$users = array_unique($users);
if ($sort)
{
sort($users);
}
$auth_read = $this->auth->acl_get_list($users, 'f_read', $forum_id);
if (empty($auth_read))
{
return array();
}
return $this->check_user_notification_options($auth_read[$forum_id]['f_read'], $options);
}
}

View File

@ -0,0 +1,128 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Bookmark updating notifications class
* This class handles notifications for replies to a bookmarked topic
*/
class bookmark extends \phpbb\notification\type\post
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.bookmark';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_BOOKMARK';
/**
* 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')
*/
static public $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_BOOKMARK',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/**
* Is available
*/
public function is_available()
{
return $this->config['allow_bookmarks'];
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$users = array();
$sql = 'SELECT user_id
FROM ' . BOOKMARKS_TABLE . '
WHERE ' . $this->db->sql_in_set('topic_id', $post['topic_id']) . '
AND user_id <> ' . (int) $post['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$users[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
$notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
if (empty($notify_users))
{
return array();
}
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
$notified_users = $this->notification_manager->get_notified_users($this->get_type(), array(
'item_parent_id' => static::get_item_parent_id($post),
'read' => 0,
));
foreach ($notified_users as $user => $notification_data)
{
unset($notify_users[$user]);
/** @var bookmark $notification */
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
$update_responders = $notification->add_responders($post);
if (!empty($update_responders))
{
$this->notification_manager->update_notification($notification, $update_responders, array(
'item_parent_id' => self::get_item_parent_id($post),
'read' => 0,
'user_id' => $user,
));
}
}
return $notify_users;
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'bookmark';
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Post disapproved notifications class
* This class handles notifications for posts when they are disapproved (for authors)
*/
class disapprove_post extends \phpbb\notification\type\approve_post
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.disapprove_post';
}
/**
* Get the CSS style class of the notification
*
* @return string
*/
public function get_style_class()
{
return 'notification-disapproved';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_POST_DISAPPROVED';
/**
* Inherit notification read status from post.
*
* @var bool
*/
protected $inherit_read_status = false;
/**
* 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')
*/
static public $notification_option = array(
'id' => 'moderation_queue',
'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title()
{
return $this->language->lang($this->language_key);
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->language->lang(
'NOTIFICATION_REFERENCE',
censor_text($this->get_data('topic_title'))
);
}
/**
* Get the reason for the disapproval notification
*
* @return string
*/
public function get_reason()
{
return $this->language->lang(
'NOTIFICATION_REASON',
$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')),
));
}
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$this->set_data('disapprove_reason', $post['disapprove_reason']);
parent::create_insert_array($post, $pre_create_data);
$this->notification_time = time();
}
/**
* {@inheritdoc}
*/
public function get_insert_array()
{
$data = parent::get_insert_array();
$data['notification_time'] = $this->notification_time;
return $data;
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'post_disapproved';
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Topic disapproved notifications class
* This class handles notifications for topics when they are disapproved (for authors)
*/
class disapprove_topic extends \phpbb\notification\type\approve_topic
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.disapprove_topic';
}
/**
* Get the CSS style class of the notification
*
* @return string
*/
public function get_style_class()
{
return 'notification-disapproved';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_TOPIC_DISAPPROVED';
/**
* Inherit notification read status from topic.
*
* @var bool
*/
protected $inherit_read_status = false;
/**
* 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')
*/
static public $notification_option = array(
'id' => 'moderation_queue',
'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title()
{
return $this->language->lang($this->language_key);
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->language->lang(
'NOTIFICATION_REFERENCE',
censor_text($this->get_data('topic_title'))
);
}
/**
* Get the reason for the disapproval notification
*
* @return string
*/
public function get_reason()
{
return $this->language->lang(
'NOTIFICATION_REASON',
$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')),
));
}
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$this->set_data('disapprove_reason', $post['disapprove_reason']);
parent::create_insert_array($post, $pre_create_data);
$this->notification_time = time();
}
/**
* {@inheritdoc}
*/
public function get_insert_array()
{
$data = parent::get_insert_array();
$data['notification_time'] = $this->notification_time;
return $data;
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'topic_disapproved';
}
}

View File

@ -0,0 +1,169 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
class group_request extends \phpbb\notification\type\base
{
/**
* {@inheritdoc}
*/
public function get_type()
{
return 'notification.type.group_request';
}
/**
* {@inheritdoc}
*/
static public $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_GROUP_REQUEST',
);
/** @var \phpbb\user_loader */
protected $user_loader;
public function set_user_loader(\phpbb\user_loader $user_loader)
{
$this->user_loader = $user_loader;
}
/**
* {@inheritdoc}
*/
public function is_available()
{
// Leader of any groups?
$sql = 'SELECT group_id
FROM ' . USER_GROUP_TABLE . '
WHERE user_id = ' . (int) $this->user->data['user_id'] . '
AND group_leader = 1';
$result = $this->db->sql_query_limit($sql, 1);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
return (!empty($row)) ? true : false;
}
/**
* {@inheritdoc}
*/
static public function get_item_id($group)
{
return (int) $group['user_id'];
}
/**
* {@inheritdoc}
*/
static public function get_item_parent_id($group)
{
// Group id is the parent
return (int) $group['group_id'];
}
/**
* {@inheritdoc}
*/
public function find_users_for_notification($group, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$sql = 'SELECT user_id
FROM ' . USER_GROUP_TABLE . '
WHERE group_leader = 1
AND group_id = ' . (int) $group['group_id'];
$result = $this->db->sql_query($sql);
$user_ids = array();
while ($row = $this->db->sql_fetchrow($result))
{
$user_ids[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
$this->user_loader->load_users($user_ids);
return $this->check_user_notification_options($user_ids, $options);
}
/**
* {@inheritdoc}
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->item_id, false, true);
}
/**
* {@inheritdoc}
*/
public function get_title()
{
$username = $this->user_loader->get_username($this->item_id, 'no_profile');
return $this->language->lang('NOTIFICATION_GROUP_REQUEST', $username, $this->get_data('group_name'));
}
/**
* {@inheritdoc}
*/
public function get_email_template()
{
return 'group_request';
}
/**
* {@inheritdoc}
*/
public function get_email_template_variables()
{
$user_data = $this->user_loader->get_user($this->item_id);
return array(
'GROUP_NAME' => htmlspecialchars_decode($this->get_data('group_name')),
'REQUEST_USERNAME' => htmlspecialchars_decode($user_data['username']),
'U_PENDING' => generate_board_url() . "/ucp.{$this->php_ext}?i=groups&mode=manage&action=list&g={$this->item_parent_id}",
'U_GROUP' => generate_board_url() . "/memberlist.{$this->php_ext}?mode=group&g={$this->item_parent_id}",
);
}
/**
* {@inheritdoc}
*/
public function get_url()
{
return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=groups&mode=manage&action=list&g={$this->item_parent_id}");
}
/**
* {@inheritdoc}
*/
public function users_to_query()
{
return array($this->item_id);
}
/**
* {@inheritdoc}
*/
public function create_insert_array($group, $pre_create_data = array())
{
$this->set_data('group_name', $group['group_name']);
parent::create_insert_array($group, $pre_create_data);
}
}

View File

@ -0,0 +1,116 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
class group_request_approved extends \phpbb\notification\type\base
{
/**
* {@inheritdoc}
*/
public function get_type()
{
return 'notification.type.group_request_approved';
}
/**
* {@inheritdoc}
*/
public function is_available()
{
return false;
}
/**
* {@inheritdoc}
*/
static public function get_item_id($group)
{
return (int) $group['group_id'];
}
/**
* {@inheritdoc}
*/
static public function get_item_parent_id($group)
{
return 0;
}
/**
* {@inheritdoc}
*/
public function find_users_for_notification($group, $options = array())
{
$users = array();
$group['user_ids'] = (!is_array($group['user_ids'])) ? array($group['user_ids']) : $group['user_ids'];
foreach ($group['user_ids'] as $user_id)
{
$users[$user_id] = $this->notification_manager->get_default_methods();
}
return $users;
}
/**
* {@inheritdoc}
*/
public function get_title()
{
return $this->language->lang('NOTIFICATION_GROUP_REQUEST_APPROVED', $this->get_data('group_name'));
}
/**
* {@inheritdoc}
*/
public function get_url()
{
return append_sid($this->phpbb_root_path . 'memberlist.' . $this->php_ext, "mode=group&g={$this->item_id}");
}
/**
* {@inheritdoc}
*/
public function create_insert_array($group, $pre_create_data = array())
{
$this->set_data('group_name', $group['group_name']);
parent::create_insert_array($group, $pre_create_data);
}
/**
* {@inheritdoc}
*/
public function users_to_query()
{
return array();
}
/**
* {@inheritdoc}
*/
public function get_email_template()
{
return false;
}
/**
* {@inheritdoc}
*/
public function get_email_template_variables()
{
return array();
}
}

View File

@ -0,0 +1,205 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Private message notifications class
* This class handles notifications for private messages
*/
class pm extends \phpbb\notification\type\base
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return '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', 'lang', and 'group')
*/
static public $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_PM',
);
/** @var \phpbb\user_loader */
protected $user_loader;
/** @var \phpbb\config\config */
protected $config;
public function set_config(\phpbb\config\config $config)
{
$this->config = $config;
}
public function set_user_loader(\phpbb\user_loader $user_loader)
{
$this->user_loader = $user_loader;
}
/**
* Is available
*/
public function is_available()
{
return ($this->config['allow_privmsg'] && $this->auth->acl_get('u_readpm'));
}
/**
* Get the id of the
*
* @param array $pm The data from the private message
*/
static public function get_item_id($pm)
{
return (int) $pm['msg_id'];
}
/**
* Get the id of the parent
*
* @param array $pm The data from the pm
*/
static public function get_item_parent_id($pm)
{
// No parent
return 0;
}
/**
* Find the users who want to receive notifications
*
* @param array $pm Data from submit_pm
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($pm, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
if (!count($pm['recipients']))
{
return array();
}
unset($pm['recipients'][$pm['from_user_id']]);
$this->user_loader->load_users(array_keys($pm['recipients']));
return $this->check_user_notification_options(array_keys($pm['recipients']), $options);
}
/**
* Get the user's avatar
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('from_user_id'), false, true);
}
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title()
{
$username = $this->user_loader->get_username($this->get_data('from_user_id'), 'no_profile');
return $this->language->lang('NOTIFICATION_PM', $username);
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->language->lang(
'NOTIFICATION_REFERENCE',
$this->get_data('message_subject')
);
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'privmsg_notify';
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
$user_data = $this->user_loader->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&amp;mode=view&amp;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->get_data('from_user_id'));
}
/**
* {@inheritdoc}
*/
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']);
parent::create_insert_array($pm, $pre_create_data);
}
}

View File

@ -0,0 +1,467 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Post notifications class
* This class handles notifications for replies to a topic
*/
class post extends \phpbb\notification\type\base
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.post';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_POST';
/**
* Inherit notification read status from post.
*
* @var bool
*/
protected $inherit_read_status = true;
/**
* 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')
*/
static public $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_POST',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/** @var \phpbb\user_loader */
protected $user_loader;
/** @var \phpbb\config\config */
protected $config;
public function set_config(\phpbb\config\config $config)
{
$this->config = $config;
}
public function set_user_loader(\phpbb\user_loader $user_loader)
{
$this->user_loader = $user_loader;
}
/**
* Is available
*/
public function is_available()
{
return $this->config['allow_topic_notify'];
}
/**
* Get the id of the item
*
* @param array $post The data from the post
* @return int The post id
*/
static public function get_item_id($post)
{
return (int) $post['post_id'];
}
/**
* Get the id of the parent
*
* @param array $post The data from the post
* @return int The topic id
*/
static public function get_item_parent_id($post)
{
return (int) $post['topic_id'];
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$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 = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$users[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
$sql = 'SELECT user_id
FROM ' . FORUMS_WATCH_TABLE . '
WHERE forum_id = ' . (int) $post['forum_id'] . '
AND notify_status = ' . NOTIFY_YES . '
AND user_id <> ' . (int) $post['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$users[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
$notify_users = $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
if (empty($notify_users))
{
return array();
}
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
$notified_users = $this->notification_manager->get_notified_users($this->get_type(), array(
'item_parent_id' => static::get_item_parent_id($post),
'read' => 0,
));
foreach ($notified_users as $user => $notification_data)
{
unset($notify_users[$user]);
/** @var post $notification */
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $notification_data);
$update_responders = $notification->add_responders($post);
if (!empty($update_responders))
{
$this->notification_manager->update_notification($notification, $update_responders, array(
'item_parent_id' => self::get_item_parent_id($post),
'read' => 0,
'user_id' => $user,
));
}
}
return $notify_users;
}
/**
* Get the user's avatar
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('poster_id'), false, true);
}
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title()
{
$responders = $this->get_data('responders');
$usernames = array();
if (!is_array($responders))
{
$responders = array();
}
$responders = array_merge(array(array(
'poster_id' => $this->get_data('poster_id'),
'username' => $this->get_data('post_username'),
)), $responders);
$responders_cnt = count($responders);
$responders = $this->trim_user_ary($responders);
$trimmed_responders_cnt = $responders_cnt - count($responders);
foreach ($responders as $responder)
{
if ($responder['username'])
{
$usernames[] = $responder['username'];
}
else
{
$usernames[] = $this->user_loader->get_username($responder['poster_id'], 'no_profile');
}
}
if ($trimmed_responders_cnt > 20)
{
$usernames[] = $this->language->lang('NOTIFICATION_MANY_OTHERS');
}
else if ($trimmed_responders_cnt)
{
$usernames[] = $this->language->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt);
}
return $this->language->lang(
$this->language_key,
phpbb_generate_string_list($usernames, $this->user),
$responders_cnt
);
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->language->lang(
'NOTIFICATION_REFERENCE',
censor_text($this->get_data('topic_title'))
);
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'topic_notify';
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
if ($this->get_data('post_username'))
{
$username = $this->get_data('post_username');
}
else
{
$username = $this->user_loader->get_username($this->get_data('poster_id'), 'username');
}
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'))),
'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}&e=1&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}");
}
/**
* {inheritDoc}
*/
public function get_redirect_url()
{
return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->item_parent_id}&amp;view=unread#unread");
}
/**
* Users needed to query before this notification can be displayed
*
* @return array Array of user_ids
*/
public function users_to_query()
{
$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 $this->trim_user_ary($users);
}
/**
* Trim the user array passed down to 3 users if the array contains
* more than 4 users.
*
* @param array $users Array of users
* @return array Trimmed array of user_ids
*/
public function trim_user_ary($users)
{
if (count($users) > 4)
{
array_splice($users, 3);
}
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 (!count($notify_users) || !$this->inherit_read_status)
{
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'];
}
$this->db->sql_freeresult($result);
return $tracking_data;
}
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$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->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 ($this->inherit_read_status && isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
{
$this->notification_read = true;
}
parent::create_insert_array($post, $pre_create_data);
}
/**
* Add responders to the notification
*
* @param mixed $post
* @return array Array of responder data
*/
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();
}
$responders = $this->get_data('responders');
$responders = ($responders === null) ? array() : $responders;
// Do not add more than 25 responders,
// we trim the username list to "a, b, c and x others" anyway
// so there is no use to add all of them anyway.
if (count($responders) > 25)
{
return array();
}
foreach ($responders as $responder)
{
// Do not add them as a responder multiple times
if ($responder['poster_id'] == $post['poster_id'])
{
return array();
}
}
$responders[] = array(
'poster_id' => $post['poster_id'],
'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''),
);
$this->set_data('responders', $responders);
$serialized_data = serialize($this->get_data(false));
// If the data is longer then 4000 characters, it would cause a SQL error.
// We don't add the username to the list if this is the case.
if (utf8_strlen($serialized_data) >= 4000)
{
return array();
}
$data_array = array_merge(array(
'post_time' => $post['post_time'],
'post_id' => $post['post_id'],
'topic_id' => $post['topic_id']
), $this->get_data(false));
return $data_array;
}
}

View File

@ -0,0 +1,163 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Post in queue notifications class
* This class handles notifications for posts that are put in the moderation queue (for moderators)
*/
class post_in_queue extends \phpbb\notification\type\post
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.post_in_queue';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_POST_IN_QUEUE';
/**
* 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')
*/
static public $notification_option = array(
'id' => 'notification.type.needs_approval',
'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE',
'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()
{
$has_permission = $this->auth->acl_getf($this->permission, true);
return (!empty($has_permission));
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from the post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
// 0 is for global moderator permissions
$auth_approve = $this->auth->acl_get_list(false, $this->permission, array($post['forum_id'], 0));
if (empty($auth_approve))
{
return array();
}
$has_permission = 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]));
}
sort($has_permission);
$auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $post['forum_id']);
if (empty($auth_read))
{
return array();
}
return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array(
'item_type' => static::$notification_option['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, "i=queue&amp;mode=approve_details&amp;f={$this->get_data('forum_id')}&amp;p={$this->item_id}");
}
/**
* {inheritDoc}
*/
public function get_redirect_url()
{
return parent::get_url();
}
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
parent::create_insert_array($post, $pre_create_data);
$this->notification_time = time();
}
/**
* {@inheritdoc}
*/
public function get_insert_array()
{
$data = parent::get_insert_array();
$data['notification_time'] = $this->notification_time;
return $data;
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'post_in_queue';
}
}

View File

@ -0,0 +1,184 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Post quoting notifications class
* This class handles notifying users when they have been quoted in a post
*/
class quote extends \phpbb\notification\type\post
{
/**
* @var \phpbb\textformatter\utils_interface
*/
protected $utils;
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.quote';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_QUOTE';
/**
* 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')
*/
static public $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_QUOTE',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/**
* Is available
*/
public function is_available()
{
return true;
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$usernames = $this->utils->get_outermost_quote_authors($post['post_text']);
if (empty($usernames))
{
return array();
}
$usernames = array_unique($usernames);
$usernames = array_map('utf8_clean_string', $usernames);
$users = array();
$sql = 'SELECT user_id
FROM ' . USERS_TABLE . '
WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . '
AND user_id <> ' . (int) $post['poster_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$users[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
return $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
}
/**
* Update a notification
*
* @param array $post Data specific for this type that will be updated
* @return true
*/
public function update_notifications($post)
{
$old_notifications = $this->notification_manager->get_notified_users($this->get_type(), array(
'item_id' => static::get_item_id($post),
));
// Find the new users to notify
$notifications = $this->find_users_for_notification($post);
// Find the notifications we must delete
$remove_notifications = array_diff(array_keys($old_notifications), array_keys($notifications));
// Find the notifications we must add
$add_notifications = array();
foreach (array_diff(array_keys($notifications), array_keys($old_notifications)) as $user_id)
{
$add_notifications[$user_id] = $notifications[$user_id];
}
// Add the necessary notifications
$this->notification_manager->add_notifications_for_users($this->get_type(), $post, $add_notifications);
// Remove the necessary notifications
if (!empty($remove_notifications))
{
$this->notification_manager->delete_notifications($this->get_type(), static::get_item_id($post), false, $remove_notifications);
}
// return true to continue with the update code in the notifications service (this will update the rest of the notifications)
return true;
}
/**
* {inheritDoc}
*/
public function get_redirect_url()
{
return $this->get_url();
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'quote';
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
$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']),
));
}
/**
* Set the utils service used to retrieve quote authors
*
* @param \phpbb\textformatter\utils_interface $utils
*/
public function set_utils(\phpbb\textformatter\utils_interface $utils)
{
$this->utils = $utils;
}
}

View File

@ -0,0 +1,254 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Private message reported notifications class
* This class handles notifications for private messages when they are reported
*/
class report_pm extends \phpbb\notification\type\pm
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.report_pm';
}
/**
* Get the CSS style class of the notification
*
* @return string
*/
public function get_style_class()
{
return 'notification-reported';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_REPORT_PM';
/**
* Permission to check for (in find_users_for_notification)
*
* @var string Permission name
*/
protected $permission = 'm_pm_report';
/**
* 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')
*/
static public $notification_option = array(
'id' => 'notification.type.report',
'lang' => 'NOTIFICATION_TYPE_REPORT',
'group' => 'NOTIFICATION_GROUP_MODERATION',
);
/**
* Get the id of the parent
*
* @param array $pm The data from the pm
* @return int The report id
*/
static public function get_item_parent_id($pm)
{
return (int) $pm['report_id'];
}
/**
* 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()
{
$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)
*
* @param array $post Data from the post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
{
$options = array_merge(array(
'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))
{
return array();
}
if (($key = array_search($this->user->data['user_id'], $auth_approve[$post['forum_id']][$this->permission])))
{
unset($auth_approve[$post['forum_id']][$this->permission][$key]);
}
return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, array(
'item_type' => static::$notification_option['id'],
)));
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'report_pm';
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
$user_data = $this->user_loader->get_user($this->get_data('reporter_id'));
return array(
'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}&amp;i=pm_reports&amp;mode=pm_report_details",
);
}
/**
* Get the url to this item
*
* @return string URL
*/
public function get_url()
{
return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "r={$this->item_parent_id}&amp;i=pm_reports&amp;mode=pm_report_details");
}
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title()
{
$this->language->add_lang('mcp');
$username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile');
return $this->language->lang(
$this->language_key,
$username
);
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->language->lang(
'NOTIFICATION_REFERENCE',
censor_text($this->get_data('message_subject'))
);
}
/**
* Get the reason for the notification
*
* @return string
*/
public function get_reason()
{
if ($this->get_data('report_text'))
{
return $this->language->lang(
'NOTIFICATION_REASON',
$this->get_data('report_text')
);
}
if ($this->language->is_set($this->get_data('reason_title')))
{
return $this->language->lang(
'NOTIFICATION_REASON',
$this->language->lang($this->get_data('reason_title'))
);
}
return $this->language->lang(
'NOTIFICATION_REASON',
$this->get_data('reason_description')
);
}
/**
* Get the user's avatar
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('reporter_id'), false, true);
}
/**
* Users needed to query before this notification can be displayed
*
* @return array Array of user_ids
*/
public function users_to_query()
{
return array($this->get_data('reporter_id'));
}
/**
* {@inheritdoc}
*/
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']);
$this->set_data('report_text', $post['report_text']);
parent::create_insert_array($post, $pre_create_data);
}
}

View File

@ -0,0 +1,168 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* PM report closed notifications class
* This class handles notifications for when reports are closed on PMs (for the one who reported the PM)
*/
class report_pm_closed extends \phpbb\notification\type\pm
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.report_pm_closed';
}
/**
* Email template to use to send notifications
*
* @var string
*/
public $email_template = '';
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_REPORT_CLOSED';
public function is_available()
{
return false;
}
/**
* Find the users who want to receive notifications
*
* @param array $pm Data from submit_pm
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($pm, $options = array())
{
if ($pm['reporter'] == $this->user->data['user_id'])
{
return array();
}
return array($pm['reporter'] => $this->notification_manager->get_default_methods());
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return false;
}
/**
* 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()
{
$username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile');
return $this->language->lang(
$this->language_key,
$username
);
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->language->lang(
'NOTIFICATION_REFERENCE',
censor_text($this->get_data('message_subject'))
);
}
/**
* Get the user's avatar
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('closer_id'), false, true);
}
/**
* Users needed to query before this notification can be displayed
*
* @return array Array of user_ids
*/
public function users_to_query()
{
return array($this->get_data('closer_id'));
}
/**
* {@inheritdoc}
*/
public function create_insert_array($pm, $pre_create_data = array())
{
$this->set_data('closer_id', $pm['closer_id']);
parent::create_insert_array($pm, $pre_create_data);
$this->notification_time = time();
}
/**
* {@inheritdoc}
*/
public function get_insert_array()
{
$data = parent::get_insert_array();
$data['notification_time'] = $this->notification_time;
return $data;
}
}

View File

@ -0,0 +1,224 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Reported post notifications class
* This class handles notifications for reported posts
*/
class report_post extends \phpbb\notification\type\post_in_queue
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.report_post';
}
/**
* Get the CSS style class of the notification
*
* @return string
*/
public function get_style_class()
{
return 'notification-reported';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_REPORT_POST';
/**
* Inherit notification read status from post.
*
* @var bool
*/
protected $inherit_read_status = false;
/**
* Permission to check for (in find_users_for_notification)
*
* @var string Permission name
*/
protected $permission = 'm_report';
/**
* 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')
*/
static public $notification_option = array(
'id' => 'notification.type.report',
'lang' => 'NOTIFICATION_TYPE_REPORT',
'group' => 'NOTIFICATION_GROUP_MODERATION',
);
/**
* Find the users who want to receive notifications
*
* @param array $post Data from the post
* @param array $options Options for finding users for notification
*
* @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
*
* @return string|bool
*/
public function get_email_template()
{
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')}&amp;p={$this->item_id}&amp;i=reports&amp;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')}&amp;p={$this->item_id}&amp;i=reports&amp;mode=report_details#reports");
}
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title()
{
$this->language->add_lang('mcp');
$username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile');
return $this->language->lang(
$this->language_key,
$username
);
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->language->lang(
'NOTIFICATION_REFERENCE',
censor_text($this->get_data('post_subject'))
);
}
/**
* Get the reason for the notification
*
* @return string
*/
public function get_reason()
{
if ($this->get_data('report_text'))
{
return $this->language->lang(
'NOTIFICATION_REASON',
$this->get_data('report_text')
);
}
if ($this->language->is_set($this->get_data('reason_title')))
{
return $this->language->lang(
'NOTIFICATION_REASON',
$this->language->lang($this->get_data('reason_title'))
);
}
return $this->language->lang(
'NOTIFICATION_REASON',
$this->get_data('reason_description')
);
}
/**
* Get the user's avatar
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('reporter_id'), false, true);
}
/**
* Users needed to query before this notification can be displayed
*
* @return array Array of user_ids
*/
public function users_to_query()
{
return array($this->get_data('reporter_id'));
}
/**
* {@inheritdoc}
*/
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']);
$this->set_data('report_text', $post['report_text']);
parent::create_insert_array($post, $pre_create_data);
}
}

View File

@ -0,0 +1,175 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Post report closed notifications class
* This class handles notifications for when reports are closed on posts (for the one who reported the post)
*/
class report_post_closed extends \phpbb\notification\type\post
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.report_post_closed';
}
/**
* Email template to use to send notifications
*
* @var string
*/
public $email_template = '';
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_REPORT_CLOSED';
/**
* Inherit notification read status from post.
*
* @var bool
*/
protected $inherit_read_status = false;
public function is_available()
{
return false;
}
/**
* Find the users who want to receive notifications
*
* @param array $post Data from submit_post
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($post, $options = array())
{
if ($post['reporter'] == $this->user->data['user_id'])
{
return array();
}
return array($post['reporter'] => $this->notification_manager->get_default_methods());
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return false;
}
/**
* 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()
{
$username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile');
return $this->language->lang(
$this->language_key,
$username
);
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->language->lang(
'NOTIFICATION_REFERENCE',
censor_text($this->get_data('post_subject'))
);
}
/**
* Get the user's avatar
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('closer_id'), false, true);
}
/**
* Users needed to query before this notification can be displayed
*
* @return array Array of user_ids
*/
public function users_to_query()
{
return array($this->get_data('closer_id'));
}
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$this->set_data('closer_id', $post['closer_id']);
parent::create_insert_array($post, $pre_create_data);
$this->notification_time = time();
}
/**
* {@inheritdoc}
*/
public function get_insert_array()
{
$data = parent::get_insert_array();
$data['notification_time'] = $this->notification_time;
return $data;
}
}

View File

@ -0,0 +1,307 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Topic notifications class
* This class handles notifications for new topics
*/
class topic extends \phpbb\notification\type\base
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.topic';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_TOPIC';
/**
* Inherit notification read status from topic.
*
* @var bool
*/
protected $inherit_read_status = true;
/**
* 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')
*/
static public $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_TOPIC',
'group' => 'NOTIFICATION_GROUP_POSTING',
);
/** @var \phpbb\user_loader */
protected $user_loader;
/** @var \phpbb\config\config */
protected $config;
public function set_config(\phpbb\config\config $config)
{
$this->config = $config;
}
public function set_user_loader(\phpbb\user_loader $user_loader)
{
$this->user_loader = $user_loader;
}
/**
* Is available
*/
public function is_available()
{
return $this->config['allow_forum_notify'];
}
/**
* Get the id of the item
*
* @param array $post The data from the post
* @return int The topic id
*/
static public function get_item_id($post)
{
return (int) $post['topic_id'];
}
/**
* Get the id of the parent
*
* @param array $post The data from the post
* @return int The forum id
*/
static public function get_item_parent_id($post)
{
return (int) $post['forum_id'];
}
/**
* Find the users who want to receive notifications
*
* @param array $topic Data from the topic
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($topic, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
$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 = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$users[] = (int) $row['user_id'];
}
$this->db->sql_freeresult($result);
return $this->get_authorised_recipients($users, $topic['forum_id'], $options);
}
/**
* Get the user's avatar
*/
public function get_avatar()
{
return $this->user_loader->get_avatar($this->get_data('poster_id'), false, true);
}
/**
* 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
{
$username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile');
}
return $this->language->lang(
$this->language_key,
$username
);
}
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference()
{
return $this->language->lang(
'NOTIFICATION_REFERENCE',
censor_text($this->get_data('topic_title'))
);
}
/**
* Get the forum of the notification reference
*
* @return string
*/
public function get_forum()
{
return $this->language->lang(
'NOTIFICATION_FORUM',
$this->get_data('forum_name')
);
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'newtopic_notify';
}
/**
* Get email template variables
*
* @return array
*/
public function get_email_template_variables()
{
$board_url = generate_board_url();
if ($this->get_data('post_username'))
{
$username = $this->get_data('post_username');
}
else
{
$username = $this->user_loader->get_username($this->get_data('poster_id'), 'username');
}
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'))),
'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",
);
}
/**
* 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}&amp;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->get_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 (!count($notify_users) || !$this->inherit_read_status)
{
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'];
}
$this->db->sql_freeresult($result);
return $tracking_data;
}
/**
* {@inheritdoc}
*/
public function create_insert_array($post, $pre_create_data = array())
{
$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->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 ($this->inherit_read_status && isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
{
$this->notification_read = true;
}
parent::create_insert_array($post, $pre_create_data);
}
}

View File

@ -0,0 +1,155 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Topic in queue notifications class
* This class handles notifications for topics when they are put in the moderation queue (for moderators)
*/
class topic_in_queue extends \phpbb\notification\type\topic
{
/**
* Get notification type name
*
* @return string
*/
public function get_type()
{
return 'notification.type.topic_in_queue';
}
/**
* Language key used to output the text
*
* @var string
*/
protected $language_key = 'NOTIFICATION_TOPIC_IN_QUEUE';
/**
* 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')
*/
static public $notification_option = array(
'id' => 'notification.type.needs_approval',
'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE',
'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()
{
$has_permission = $this->auth->acl_getf($this->permission, true);
return (!empty($has_permission));
}
/**
* Find the users who want to receive notifications
*
* @param array $topic Data from the topic
* @param array $options Options for finding users for notification
*
* @return array
*/
public function find_users_for_notification($topic, $options = array())
{
$options = array_merge(array(
'ignore_users' => array(),
), $options);
// 0 is for global moderator permissions
$auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($topic['forum_id'], 0));
if (empty($auth_approve))
{
return array();
}
$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]));
}
sort($has_permission);
$auth_read = $this->auth->acl_get_list($has_permission, 'f_read', $topic['forum_id']);
if (empty($auth_read))
{
return array();
}
return $this->check_user_notification_options($auth_read[$topic['forum_id']]['f_read'], array_merge($options, array(
'item_type' => static::$notification_option['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, "i=queue&amp;mode=approve_details&amp;f={$this->item_parent_id}&amp;t={$this->item_id}");
}
/**
* {@inheritdoc}
*/
public function create_insert_array($topic, $pre_create_data = array())
{
parent::create_insert_array($topic, $pre_create_data);
$this->notification_time = time();
}
/**
* {@inheritdoc}
*/
public function get_insert_array()
{
$data = parent::get_insert_array();
$data['notification_time'] = $this->notification_time;
return $data;
}
/**
* Get email template
*
* @return string|bool
*/
public function get_email_template()
{
return 'topic_in_queue';
}
}

View File

@ -0,0 +1,218 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\notification\type;
/**
* Base notifications interface
*/
interface type_interface
{
/**
* Get notification type name
*
* @return string
*/
public function get_type();
/**
* Set initial data from the database
*
* @param array $data Row directly from the database
*/
public function set_initial_data($data);
/**
* Get the id of the item
*
* @param array $type_data The type specific data
*/
static public function get_item_id($type_data);
/**
* Get the id of the parent
*
* @param array $type_data The type specific data
*/
static public 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);
/**
* Users needed to query before this notification can be displayed
*
* @return array Array of user_ids
*/
public function users_to_query();
/**
* 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 CSS style class of the notification
*
* @return string
*/
public function get_style_class();
/**
* Get the HTML formatted title of this notification
*
* @return string
*/
public function get_title();
/**
* Get the HTML formatted reference of the notification
*
* @return string
*/
public function get_reference();
/**
* Get the forum of the notification reference
*
* @return string
*/
public function get_forum();
/**
* Get the url to this item
*
* @return string URL
*/
public function get_url();
/**
* Get the url to redirect after the item has been marked as read
*
* @return string URL
*/
public function get_redirect_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);
/**
* 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
*
* @return string|bool
*/
public function get_email_template();
/**
* 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
*
* @param array $type_data The type specific data
* @param array $pre_create_data Data from pre_create_insert_array()
*/
public function create_insert_array($type_data, $pre_create_data);
/**
* Function for getting the data for insertion in an SQL query
*
* @return array Array of data ready to be inserted into the database
*/
public function get_insert_array();
/**
* 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 = false);
/**
* 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);
}