PDF rausgenommen
This commit is contained in:
137
msd2/phpBB3/phpbb/notification/method/base.php
Normal file
137
msd2/phpBB3/phpbb/notification/method/base.php
Normal 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();
|
||||
}
|
||||
}
|
399
msd2/phpBB3/phpbb/notification/method/board.php
Normal file
399
msd2/phpBB3/phpbb/notification/method/board.php
Normal 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);
|
||||
}
|
||||
}
|
78
msd2/phpBB3/phpbb/notification/method/email.php
Normal file
78
msd2/phpBB3/phpbb/notification/method/email.php
Normal 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);
|
||||
}
|
||||
}
|
95
msd2/phpBB3/phpbb/notification/method/jabber.php
Normal file
95
msd2/phpBB3/phpbb/notification/method/jabber.php
Normal 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/');
|
||||
}
|
||||
}
|
134
msd2/phpBB3/phpbb/notification/method/messenger_base.php
Normal file
134
msd2/phpBB3/phpbb/notification/method/messenger_base.php
Normal 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();
|
||||
}
|
||||
}
|
149
msd2/phpBB3/phpbb/notification/method/method_interface.php
Normal file
149
msd2/phpBB3/phpbb/notification/method/method_interface.php
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user