mirror of
https://github.com/phpbb/phpbb.git
synced 2025-02-24 12:03:21 +01:00
[ticket/11103] Private Message type notification
Also cleanup PHPBB3-11103
This commit is contained in:
parent
e45fb0025e
commit
32a966b21d
@ -87,9 +87,9 @@ class phpbb_notifications_service
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$type_class_name = $this->get_type_class_name($row['item_type'], true);
|
||||
$item_type_class_name = $this->get_item_type_class_name($row['item_type'], true);
|
||||
|
||||
$notification = new $type_class_name($this->phpbb_container, $row);
|
||||
$notification = new $item_type_class_name($this->phpbb_container, $row);
|
||||
$notification->users($this->users);
|
||||
|
||||
$user_ids = array_merge($user_ids, $notification->users_to_query());
|
||||
@ -123,13 +123,18 @@ class phpbb_notifications_service
|
||||
/**
|
||||
* Add a notification
|
||||
*
|
||||
* @param string $type Type identifier
|
||||
* @param int $type_id Identifier within the type
|
||||
* @param string $item_type Type identifier
|
||||
* @param int $item_id Identifier within the type
|
||||
* @param array $data Data specific for this type that will be inserted
|
||||
*/
|
||||
public function add_notifications($type, $data)
|
||||
public function add_notifications($item_type, $data)
|
||||
{
|
||||
$type_class_name = $this->get_type_class_name($type);
|
||||
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
||||
|
||||
$item_id = $item_type_class_name::get_item_id($data);
|
||||
|
||||
// Update any existing notifications for this item
|
||||
$this->update_notifications($item_type, $item_id, $data);
|
||||
|
||||
$notify_users = array();
|
||||
$notification_objects = $notification_methods = array();
|
||||
@ -150,10 +155,22 @@ class phpbb_notifications_service
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Make sure not to send new notifications to users who've already been notified about this item
|
||||
// This may happen when an item was added, but now new users are able to see the item
|
||||
$sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . "
|
||||
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
|
||||
AND item_id = " . (int) $item_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
unset($notify_users[$row['user_id']]);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Go through each user so we can insert a row in the DB and then notify them by their desired means
|
||||
foreach ($notify_users as $user => $methods)
|
||||
{
|
||||
$notification = new $type_class_name($this->phpbb_container);
|
||||
$notification = new $item_type_class_name($this->phpbb_container);
|
||||
|
||||
$notification->user_id = (int) $user;
|
||||
|
||||
@ -188,34 +205,49 @@ class phpbb_notifications_service
|
||||
/**
|
||||
* Update a notification
|
||||
*
|
||||
* @param string $type Type identifier
|
||||
* @param int $type_id Identifier within the type
|
||||
* @param string $item_type Type identifier
|
||||
* @param int $item_id Identifier within the type
|
||||
* @param array $data Data specific for this type that will be updated
|
||||
*/
|
||||
public function update_notifications($type, $type_id, $data)
|
||||
public function update_notifications($item_type, $item_id, $data)
|
||||
{
|
||||
$type_class_name = $this->get_type_class_name($type);
|
||||
$item_type_class_name = $this->get_item_type_class_name($item_type);
|
||||
|
||||
$notification = new $type_class_name($this->phpbb_container);
|
||||
$notification = new $item_type_class_name($this->phpbb_container);
|
||||
$update_array = $notification->create_update_array($data);
|
||||
|
||||
$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $update_array) . "
|
||||
WHERE item_type = '" . $this->db->sql_escape($type) . "'
|
||||
AND item_id = " . (int) $type_id;
|
||||
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
|
||||
AND item_id = " . (int) $item_id;
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the notifications type class name and clean it if unsafe
|
||||
* Delete a notification
|
||||
*
|
||||
* @param string $item_type Type identifier
|
||||
* @param int $item_id Identifier within the type
|
||||
* @param array $data Data specific for this type that will be updated
|
||||
*/
|
||||
private function get_type_class_name(&$type, $safe = false)
|
||||
public function delete_notifications($item_type, $item_id)
|
||||
{
|
||||
$sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . "
|
||||
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
|
||||
AND item_id = " . (int) $item_id;
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the notifications item type class name and clean it if unsafe
|
||||
*/
|
||||
private function get_item_type_class_name(&$item_type, $safe = false)
|
||||
{
|
||||
if (!$safe)
|
||||
{
|
||||
$type = preg_replace('#[^a-z]#', '', $type);
|
||||
$item_type = preg_replace('#[^a-z]#', '', $item_type);
|
||||
}
|
||||
|
||||
return 'phpbb_notifications_type_' . $type;
|
||||
return 'phpbb_notifications_type_' . $item_type;
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type
|
||||
{
|
||||
// Defaults
|
||||
$data = array_merge(array(
|
||||
'item_type' => $this->get_type(),
|
||||
'item_type' => $this->get_item_type(),
|
||||
'time' => time(),
|
||||
'unread' => true,
|
||||
|
||||
|
@ -21,7 +21,9 @@ if (!defined('IN_PHPBB'))
|
||||
*/
|
||||
interface phpbb_notifications_type_interface
|
||||
{
|
||||
public function get_type();
|
||||
public static function get_item_type();
|
||||
|
||||
public static function get_item_id($post);
|
||||
|
||||
public function get_title();
|
||||
|
||||
|
97
phpBB/includes/notifications/type/pm.php
Normal file
97
phpBB/includes/notifications/type/pm.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package notifications
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private message notifications class
|
||||
* @package notifications
|
||||
*/
|
||||
class phpbb_notifications_type_pm extends phpbb_notifications_type_base
|
||||
{
|
||||
/**
|
||||
* Get the type of notification this is
|
||||
* phpbb_notifications_type_
|
||||
*/
|
||||
public static function get_item_type()
|
||||
{
|
||||
return 'pm';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the
|
||||
*
|
||||
* @param array $pm The data from the private message
|
||||
*/
|
||||
public static function get_item_id($pm)
|
||||
{
|
||||
return $pm['msg_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of this notification
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title()
|
||||
{
|
||||
$user_data = $this->get_user($this->get_data('author_id'));
|
||||
|
||||
$username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']);
|
||||
|
||||
return $username . ' sent you a private message titled: ' . $this->get_data('message_subject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url to this item
|
||||
*
|
||||
* @return string URL
|
||||
*/
|
||||
public function get_url()
|
||||
{
|
||||
return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Users needed to query before this notification can be displayed
|
||||
*
|
||||
* @return array Array of user_ids
|
||||
*/
|
||||
public function users_to_query()
|
||||
{
|
||||
return array($this->data['author_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for preparing the data for insertion in an SQL query
|
||||
* (The service handles insertion)
|
||||
*
|
||||
* @param array $post Data from submit_post
|
||||
*
|
||||
* @return array Array of data ready to be inserted into the database
|
||||
*/
|
||||
public function create_insert_array($post)
|
||||
{
|
||||
$this->item_id = $post['msg_id'];
|
||||
|
||||
$this->set_data('author_id', $post['author_id']);
|
||||
|
||||
$this->set_data('message_subject', $post['message_subject']);
|
||||
|
||||
$this->time = $post['message_time'];
|
||||
|
||||
return parent::create_insert_array($post);
|
||||
}
|
||||
}
|
@ -25,11 +25,21 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base
|
||||
* Get the type of notification this is
|
||||
* phpbb_notifications_type_
|
||||
*/
|
||||
public function get_type()
|
||||
public static function get_item_type()
|
||||
{
|
||||
return 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the
|
||||
*
|
||||
* @param array $post The data from the post
|
||||
*/
|
||||
public static function get_item_id($post)
|
||||
{
|
||||
return $post['post_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of this notification
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user