diff options
author | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
---|---|---|
committer | Maat <maat-pub@mageia.biz> | 2020-05-08 21:52:11 +0200 |
commit | 8ea437e30605e0f66b5220bf904a61d7c1d11ddd (patch) | |
tree | e0db2bb4a012d5b06a633160b19f62f4868ecd28 /phpBB/phpbb/notification/type | |
parent | 36bc1870f21fac04736a1049c1d5b8e127d729f4 (diff) | |
parent | 2fdd46b36431ae0f58bb2e78e42553168db9a0ff (diff) | |
download | forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.gz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.bz2 forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.tar.xz forums-8ea437e30605e0f66b5220bf904a61d7c1d11ddd.zip |
Merge remote-tracking branch 'upstream/prep-release-3.2.9'
Diffstat (limited to 'phpBB/phpbb/notification/type')
20 files changed, 438 insertions, 356 deletions
diff --git a/phpBB/phpbb/notification/type/admin_activate_user.php b/phpBB/phpbb/notification/type/admin_activate_user.php index 7c5c18aa47..78c10ac36a 100644 --- a/phpBB/phpbb/notification/type/admin_activate_user.php +++ b/phpBB/phpbb/notification/type/admin_activate_user.php @@ -36,11 +36,27 @@ class admin_activate_user extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static $notification_option = array( + 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} */ @@ -52,7 +68,7 @@ class admin_activate_user extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static function get_item_id($user) + static public function get_item_id($user) { return (int) $user['user_id']; } @@ -60,7 +76,7 @@ class admin_activate_user extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static function get_item_parent_id($post) + static public function get_item_parent_id($post) { return 0; } @@ -114,7 +130,7 @@ class admin_activate_user extends \phpbb\notification\type\base { $username = $this->user_loader->get_username($this->item_id, 'no_profile'); - return $this->user->lang($this->language_key, $username); + return $this->language->lang($this->language_key, $username); } /** @@ -159,11 +175,11 @@ class admin_activate_user extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public function create_insert_array($user, $pre_create_data) + public function create_insert_array($user, $pre_create_data = array()) { $this->set_data('user_actkey', $user['user_actkey']); $this->notification_time = $user['user_regdate']; - return parent::create_insert_array($user, $pre_create_data); + parent::create_insert_array($user, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/approve_post.php b/phpBB/phpbb/notification/type/approve_post.php index 5760c12166..e4b111e4da 100644 --- a/phpBB/phpbb/notification/type/approve_post.php +++ b/phpBB/phpbb/notification/type/approve_post.php @@ -50,7 +50,7 @@ class approve_post extends \phpbb\notification\type\post * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + static public $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', 'group' => 'NOTIFICATION_GROUP_POSTING', @@ -79,7 +79,7 @@ class approve_post extends \phpbb\notification\type\post ), $options); $users = array(); - $users[$post['poster_id']] = 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'], @@ -107,21 +107,24 @@ class approve_post extends \phpbb\notification\type\post } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('post_subject', $post['post_subject']); - $data = parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($post, $pre_create_data); + + $this->notification_time = time(); + } - $this->notification_time = $data['notification_time'] = time(); + /** + * {@inheritdoc} + */ + public function get_insert_array() + { + $data = parent::get_insert_array(); + $data['notification_time'] = $this->notification_time; return $data; } diff --git a/phpBB/phpbb/notification/type/approve_topic.php b/phpBB/phpbb/notification/type/approve_topic.php index 26e51bf9cd..f8a3fdec6f 100644 --- a/phpBB/phpbb/notification/type/approve_topic.php +++ b/phpBB/phpbb/notification/type/approve_topic.php @@ -50,7 +50,7 @@ class approve_topic extends \phpbb\notification\type\topic * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + static public $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', 'group' => 'NOTIFICATION_GROUP_POSTING', @@ -79,7 +79,7 @@ class approve_topic extends \phpbb\notification\type\topic ), $options); $users = array(); - $users[$post['poster_id']] = 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'], @@ -107,19 +107,23 @@ class approve_topic extends \phpbb\notification\type\topic } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { - $data = parent::create_insert_array($post, $pre_create_data); - $this->notification_time = $data['notification_time'] = time(); + 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; } diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index 4ead06071e..77ed7f2b09 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -21,17 +21,11 @@ abstract class base implements \phpbb\notification\type\type_interface /** @var \phpbb\notification\manager */ protected $notification_manager; - /** @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\template\template */ - protected $template; + /** @var \phpbb\language\language */ + protected $language; /** @var \phpbb\user */ protected $user; @@ -39,9 +33,6 @@ abstract class base implements \phpbb\notification\type\type_interface /** @var \phpbb\auth\auth */ protected $auth; - /** @var \phpbb\config\config */ - protected $config; - /** @var string */ protected $phpbb_root_path; @@ -49,12 +40,6 @@ abstract class base implements \phpbb\notification\type\type_interface protected $php_ext; /** @var string */ - protected $notification_types_table; - - /** @var string */ - protected $notifications_table; - - /** @var string */ protected $user_notifications_table; /** @@ -63,7 +48,7 @@ abstract class base implements \phpbb\notification\type\type_interface * @var bool|array False if the service should use its default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = false; + static public $notification_option = false; /** * The notification_type_id, set upon creation of the class @@ -74,7 +59,7 @@ abstract class base implements \phpbb\notification\type\type_interface protected $notification_type_id; /** - * Indentification data + * 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) @@ -89,35 +74,26 @@ abstract class base implements \phpbb\notification\type\type_interface private $data = array(); /** - * Notification Type Base 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\auth\auth $auth - * @param \phpbb\config\config $config - * @param string $phpbb_root_path - * @param string $php_ext - * @param string $notification_types_table - * @param string $notifications_table - * @param string $user_notifications_table - * @return \phpbb\notification\type\base - */ - public function __construct(\phpbb\user_loader $user_loader, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $user, \phpbb\auth\auth $auth, \phpbb\config\config $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) + * 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->user_loader = $user_loader; $this->db = $db; - $this->cache = $cache; + $this->language = $language; $this->user = $user; $this->auth = $auth; - $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; - $this->notification_types_table = $notification_types_table; - $this->notifications_table = $notifications_table; $this->user_notifications_table = $user_notifications_table; } @@ -207,12 +183,7 @@ abstract class base implements \phpbb\notification\type\type_interface } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $type_data Data unique to this notification type - * @param array $pre_create_data Data from pre_create_insert_array() - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($type_data, $pre_create_data = array()) { @@ -225,9 +196,15 @@ abstract class base implements \phpbb\notification\type\type_interface 'notification_time' => time(), 'notification_read' => false, - 'notification_data' => array(), + 'notification_data' => array(), ), $this->data); + } + /** + * {@inheritdoc} + */ + public function get_insert_array() + { $data = $this->data; $data['notification_data'] = serialize($data['notification_data']); @@ -244,7 +221,8 @@ abstract class base implements \phpbb\notification\type\type_interface */ public function create_update_array($type_data) { - $data = $this->create_insert_array($type_data); + $this->create_insert_array($type_data); + $data = $this->get_insert_array(); // Unset data unique to each row unset( @@ -330,6 +308,7 @@ abstract class base implements \phpbb\notification\type\type_interface * 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) { @@ -397,8 +376,11 @@ abstract class base implements \phpbb\notification\type\type_interface } /** - * Load the special items (fall back) - */ + * Load the special items (fall back) + * + * @param array $data + * @param array $notifications + */ public function load_special($data, $notifications) { return; @@ -415,10 +397,12 @@ abstract class base implements \phpbb\notification\type\type_interface } /** - * Pre create insert array function (fall back) - * - * @return array - */ + * 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(); @@ -429,13 +413,13 @@ abstract class base implements \phpbb\notification\type\type_interface */ /** - * Find the users who want to receive notifications (helper) - * - * @param array $user_ids User IDs to check if they want to receive notifications - * (Bool False to check all users besides anonymous and bots (USER_IGNORE)) - * - * @return array - */ + * 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( @@ -465,7 +449,7 @@ abstract class base implements \phpbb\notification\type\type_interface return array(); } - $rowset = $resulting_user_ids = array(); + $rowset = $output = array(); $sql = 'SELECT user_id, method, notify FROM ' . $this->user_notifications_table . ' @@ -476,9 +460,7 @@ abstract class base implements \phpbb\notification\type\type_interface while ($row = $this->db->sql_fetchrow($result)) { - $resulting_user_ids[] = $row['user_id']; - - if (!$row['notify'] || (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))) + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { continue; } @@ -487,22 +469,47 @@ abstract class base implements \phpbb\notification\type\type_interface { $rowset[$row['user_id']] = array(); } + $rowset[$row['user_id']][$row['method']] = $row['notify']; - $rowset[$row['user_id']][] = $row['method']; + 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 (!in_array($user_id, $resulting_user_ids) && !isset($options['ignore_users'][$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 { - // No rows at all for this user, default to '' - $rowset[$user_id] = array(''); + 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 $rowset; + return $output; } /** @@ -516,22 +523,23 @@ abstract class base implements \phpbb\notification\type\type_interface { $this->notification_read = (bool) !$unread; - $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); - 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); + } - $sql = 'UPDATE ' . $this->notifications_table . ' - SET notification_read = ' . (int) $this->notification_read . ' - WHERE ' . $where; - $this->db->sql_query($sql); + return null; } /** diff --git a/phpBB/phpbb/notification/type/bookmark.php b/phpBB/phpbb/notification/type/bookmark.php index 1626add22c..ebbb961c57 100644 --- a/phpBB/phpbb/notification/type/bookmark.php +++ b/phpBB/phpbb/notification/type/bookmark.php @@ -43,7 +43,7 @@ class bookmark extends \phpbb\notification\type\post * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + static public $notification_option = array( 'lang' => 'NOTIFICATION_TYPE_BOOKMARK', 'group' => 'NOTIFICATION_GROUP_POSTING', ); @@ -91,31 +91,27 @@ class bookmark extends \phpbb\notification\type\post } // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications - $update_notifications = array(); - $sql = 'SELECT n.* - FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt - WHERE n.notification_type_id = ' . (int) $this->notification_type_id . ' - AND n.item_parent_id = ' . (int) static::get_item_parent_id($post) . ' - 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); - while ($row = $this->db->sql_fetchrow($result)) + $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) { - // Do not create a new notification - unset($notify_users[$row['user_id']]); + unset($notify_users[$user]); - $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); + /** @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)) { - $sql = 'UPDATE ' . $this->notifications_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $update_responders) . ' - WHERE notification_id = ' . $row['notification_id']; - $this->db->sql_query($sql); + $this->notification_manager->update_notification($notification, $update_responders, array( + 'item_parent_id' => self::get_item_parent_id($post), + 'read' => 0, + 'user_id' => $user, + )); } } - $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/phpbb/notification/type/disapprove_post.php b/phpBB/phpbb/notification/type/disapprove_post.php index 6c7bcbcaee..2d908eb254 100644 --- a/phpBB/phpbb/notification/type/disapprove_post.php +++ b/phpBB/phpbb/notification/type/disapprove_post.php @@ -60,7 +60,7 @@ class disapprove_post extends \phpbb\notification\type\approve_post * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + static public $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', 'group' => 'NOTIFICATION_GROUP_POSTING', @@ -73,7 +73,7 @@ class disapprove_post extends \phpbb\notification\type\approve_post */ public function get_title() { - return $this->user->lang($this->language_key); + return $this->language->lang($this->language_key); } /** @@ -83,7 +83,7 @@ class disapprove_post extends \phpbb\notification\type\approve_post */ public function get_reference() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REFERENCE', censor_text($this->get_data('topic_title')) ); @@ -96,7 +96,7 @@ class disapprove_post extends \phpbb\notification\type\approve_post */ public function get_reason() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REASON', $this->get_data('disapprove_reason') ); @@ -125,21 +125,24 @@ class disapprove_post extends \phpbb\notification\type\approve_post } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('disapprove_reason', $post['disapprove_reason']); - $data = parent::create_insert_array($post); + parent::create_insert_array($post, $pre_create_data); + + $this->notification_time = time(); + } - $this->notification_time = $data['notification_time'] = time(); + /** + * {@inheritdoc} + */ + public function get_insert_array() + { + $data = parent::get_insert_array(); + $data['notification_time'] = $this->notification_time; return $data; } diff --git a/phpBB/phpbb/notification/type/disapprove_topic.php b/phpBB/phpbb/notification/type/disapprove_topic.php index efa5eb7ecd..c2522fb562 100644 --- a/phpBB/phpbb/notification/type/disapprove_topic.php +++ b/phpBB/phpbb/notification/type/disapprove_topic.php @@ -60,7 +60,7 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + static public $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', 'group' => 'NOTIFICATION_GROUP_POSTING', @@ -73,7 +73,7 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic */ public function get_title() { - return $this->user->lang($this->language_key); + return $this->language->lang($this->language_key); } /** @@ -83,7 +83,7 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic */ public function get_reference() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REFERENCE', censor_text($this->get_data('topic_title')) ); @@ -96,7 +96,7 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic */ public function get_reason() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REASON', $this->get_data('disapprove_reason') ); @@ -125,21 +125,24 @@ class disapprove_topic extends \phpbb\notification\type\approve_topic } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('disapprove_reason', $post['disapprove_reason']); - $data = parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($post, $pre_create_data); + + $this->notification_time = time(); + } - $this->notification_time = $data['notification_time'] = time(); + /** + * {@inheritdoc} + */ + public function get_insert_array() + { + $data = parent::get_insert_array(); + $data['notification_time'] = $this->notification_time; return $data; } diff --git a/phpBB/phpbb/notification/type/group_request.php b/phpBB/phpbb/notification/type/group_request.php index 96bfc86322..28a9e73bf9 100644 --- a/phpBB/phpbb/notification/type/group_request.php +++ b/phpBB/phpbb/notification/type/group_request.php @@ -26,10 +26,18 @@ class group_request extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static $notification_option = array( + 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} */ @@ -50,7 +58,7 @@ class group_request extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static function get_item_id($group) + static public function get_item_id($group) { return (int) $group['user_id']; } @@ -58,7 +66,7 @@ class group_request extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static function get_item_parent_id($group) + static public function get_item_parent_id($group) { // Group id is the parent return (int) $group['group_id']; @@ -106,7 +114,7 @@ class group_request extends \phpbb\notification\type\base { $username = $this->user_loader->get_username($this->item_id, 'no_profile'); - return $this->user->lang('NOTIFICATION_GROUP_REQUEST', $username, $this->get_data('group_name')); + return $this->language->lang('NOTIFICATION_GROUP_REQUEST', $username, $this->get_data('group_name')); } /** @@ -156,6 +164,6 @@ class group_request extends \phpbb\notification\type\base { $this->set_data('group_name', $group['group_name']); - return parent::create_insert_array($group, $pre_create_data); + parent::create_insert_array($group, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/group_request_approved.php b/phpBB/phpbb/notification/type/group_request_approved.php index d284046ffa..f55d28bafd 100644 --- a/phpBB/phpbb/notification/type/group_request_approved.php +++ b/phpBB/phpbb/notification/type/group_request_approved.php @@ -34,7 +34,7 @@ class group_request_approved extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static function get_item_id($group) + static public function get_item_id($group) { return (int) $group['group_id']; } @@ -42,7 +42,7 @@ class group_request_approved extends \phpbb\notification\type\base /** * {@inheritdoc} */ - public static function get_item_parent_id($group) + static public function get_item_parent_id($group) { return 0; } @@ -58,7 +58,7 @@ class group_request_approved extends \phpbb\notification\type\base foreach ($group['user_ids'] as $user_id) { - $users[$user_id] = array(''); + $users[$user_id] = $this->notification_manager->get_default_methods(); } return $users; @@ -69,7 +69,7 @@ class group_request_approved extends \phpbb\notification\type\base */ public function get_title() { - return $this->user->lang('NOTIFICATION_GROUP_REQUEST_APPROVED', $this->get_data('group_name')); + return $this->language->lang('NOTIFICATION_GROUP_REQUEST_APPROVED', $this->get_data('group_name')); } /** @@ -87,7 +87,7 @@ class group_request_approved extends \phpbb\notification\type\base { $this->set_data('group_name', $group['group_name']); - return parent::create_insert_array($group, $pre_create_data); + parent::create_insert_array($group, $pre_create_data); } /** diff --git a/phpBB/phpbb/notification/type/pm.php b/phpBB/phpbb/notification/type/pm.php index d2f34f95d0..c51586afb9 100644 --- a/phpBB/phpbb/notification/type/pm.php +++ b/phpBB/phpbb/notification/type/pm.php @@ -36,10 +36,26 @@ class pm extends \phpbb\notification\type\base * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + 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 */ @@ -53,7 +69,7 @@ class pm extends \phpbb\notification\type\base * * @param array $pm The data from the private message */ - public static function get_item_id($pm) + static public function get_item_id($pm) { return (int) $pm['msg_id']; } @@ -63,7 +79,7 @@ class pm extends \phpbb\notification\type\base * * @param array $pm The data from the pm */ - public static function get_item_parent_id($pm) + static public function get_item_parent_id($pm) { // No parent return 0; @@ -83,7 +99,7 @@ class pm extends \phpbb\notification\type\base 'ignore_users' => array(), ), $options); - if (!sizeof($pm['recipients'])) + if (!count($pm['recipients'])) { return array(); } @@ -112,7 +128,7 @@ class pm extends \phpbb\notification\type\base { $username = $this->user_loader->get_username($this->get_data('from_user_id'), 'no_profile'); - return $this->user->lang('NOTIFICATION_PM', $username); + return $this->language->lang('NOTIFICATION_PM', $username); } /** @@ -122,7 +138,7 @@ class pm extends \phpbb\notification\type\base */ public function get_reference() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REFERENCE', $this->get_data('message_subject') ); @@ -176,13 +192,7 @@ class pm extends \phpbb\notification\type\base } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $pm Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($pm, $pre_create_data = array()) { @@ -190,6 +200,6 @@ class pm extends \phpbb\notification\type\base $this->set_data('message_subject', $pm['message_subject']); - return parent::create_insert_array($pm, $pre_create_data); + parent::create_insert_array($pm, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/post.php b/phpBB/phpbb/notification/type/post.php index 2969da550d..254f4c07b3 100644 --- a/phpBB/phpbb/notification/type/post.php +++ b/phpBB/phpbb/notification/type/post.php @@ -50,11 +50,27 @@ class post extends \phpbb\notification\type\base * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + 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 */ @@ -67,8 +83,9 @@ class post extends \phpbb\notification\type\base * Get the id of the item * * @param array $post The data from the post + * @return int The post id */ - public static function get_item_id($post) + static public function get_item_id($post) { return (int) $post['post_id']; } @@ -77,8 +94,9 @@ class post extends \phpbb\notification\type\base * Get the id of the parent * * @param array $post The data from the post + * @return int The topic id */ - public static function get_item_parent_id($post) + static public function get_item_parent_id($post) { return (int) $post['topic_id']; } @@ -131,31 +149,27 @@ class post extends \phpbb\notification\type\base } // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications - $update_notifications = array(); - $sql = 'SELECT n.* - FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt - WHERE n.notification_type_id = ' . (int) $this->notification_type_id . ' - AND n.item_parent_id = ' . (int) static::get_item_parent_id($post) . ' - 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); - while ($row = $this->db->sql_fetchrow($result)) + $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) { - // Do not create a new notification - unset($notify_users[$row['user_id']]); + unset($notify_users[$user]); - $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); + /** @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)) { - $sql = 'UPDATE ' . $this->notifications_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $update_responders) . ' - WHERE notification_id = ' . $row['notification_id']; - $this->db->sql_query($sql); + $this->notification_manager->update_notification($notification, $update_responders, array( + 'item_parent_id' => self::get_item_parent_id($post), + 'read' => 0, + 'user_id' => $user, + )); } } - $this->db->sql_freeresult($result); return $notify_users; } @@ -188,9 +202,9 @@ class post extends \phpbb\notification\type\base 'username' => $this->get_data('post_username'), )), $responders); - $responders_cnt = sizeof($responders); + $responders_cnt = count($responders); $responders = $this->trim_user_ary($responders); - $trimmed_responders_cnt = $responders_cnt - sizeof($responders); + $trimmed_responders_cnt = $responders_cnt - count($responders); foreach ($responders as $responder) { @@ -206,14 +220,14 @@ class post extends \phpbb\notification\type\base if ($trimmed_responders_cnt > 20) { - $usernames[] = $this->user->lang('NOTIFICATION_MANY_OTHERS'); + $usernames[] = $this->language->lang('NOTIFICATION_MANY_OTHERS'); } else if ($trimmed_responders_cnt) { - $usernames[] = $this->user->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt); + $usernames[] = $this->language->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt); } - return $this->user->lang( + return $this->language->lang( $this->language_key, phpbb_generate_string_list($usernames, $this->user), $responders_cnt @@ -227,7 +241,7 @@ class post extends \phpbb\notification\type\base */ public function get_reference() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REFERENCE', censor_text($this->get_data('topic_title')) ); @@ -323,7 +337,7 @@ class post extends \phpbb\notification\type\base */ public function trim_user_ary($users) { - if (sizeof($users) > 4) + if (count($users) > 4) { array_splice($users, 3); } @@ -343,7 +357,7 @@ class post extends \phpbb\notification\type\base */ public function pre_create_insert_array($post, $notify_users) { - if (!sizeof($notify_users) || !$this->inherit_read_status) + if (!count($notify_users) || !$this->inherit_read_status) { return array(); } @@ -363,13 +377,7 @@ class post extends \phpbb\notification\type\base } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { @@ -394,13 +402,14 @@ class post extends \phpbb\notification\type\base $this->notification_read = true; } - return parent::create_insert_array($post, $pre_create_data); + 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) { @@ -417,7 +426,7 @@ class post extends \phpbb\notification\type\base // 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 (sizeof($responders) > 25) + if (count($responders) > 25) { return array(); } @@ -447,6 +456,12 @@ class post extends \phpbb\notification\type\base return array(); } - return array('notification_data' => $serialized_data); + $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; } } diff --git a/phpBB/phpbb/notification/type/post_in_queue.php b/phpBB/phpbb/notification/type/post_in_queue.php index 5832c99cd2..2d556fc9c8 100644 --- a/phpBB/phpbb/notification/type/post_in_queue.php +++ b/phpBB/phpbb/notification/type/post_in_queue.php @@ -43,7 +43,7 @@ class post_in_queue extends \phpbb\notification\type\post * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + static public $notification_option = array( 'id' => 'notification.type.needs_approval', 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', 'group' => 'NOTIFICATION_GROUP_MODERATION', @@ -131,19 +131,22 @@ class post_in_queue extends \phpbb\notification\type\post } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { - $data = parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($post, $pre_create_data); + + $this->notification_time = time(); + } - $this->notification_time = $data['notification_time'] = time(); + /** + * {@inheritdoc} + */ + public function get_insert_array() + { + $data = parent::get_insert_array(); + $data['notification_time'] = $this->notification_time; return $data; } diff --git a/phpBB/phpbb/notification/type/quote.php b/phpBB/phpbb/notification/type/quote.php index 2732cb84e4..323c18b204 100644 --- a/phpBB/phpbb/notification/type/quote.php +++ b/phpBB/phpbb/notification/type/quote.php @@ -21,6 +21,11 @@ namespace phpbb\notification\type; class quote extends \phpbb\notification\type\post { /** + * @var \phpbb\textformatter\utils_interface + */ + protected $utils; + + /** * Get notification type name * * @return string @@ -31,13 +36,6 @@ class quote extends \phpbb\notification\type\post } /** - * regular expression to match to find usernames - * - * @var string - */ - protected static $regular_expression_match = '#\[quote="(.+?)"#'; - - /** * Language key used to output the text * * @var string @@ -50,7 +48,7 @@ class quote extends \phpbb\notification\type\post * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + static public $notification_option = array( 'lang' => 'NOTIFICATION_TYPE_QUOTE', 'group' => 'NOTIFICATION_GROUP_POSTING', ); @@ -77,17 +75,16 @@ class quote extends \phpbb\notification\type\post 'ignore_users' => array(), ), $options); - $usernames = false; - preg_match_all(static::$regular_expression_match, $post['post_text'], $usernames); + $usernames = $this->utils->get_outermost_quote_authors($post['post_text']); - if (empty($usernames[1])) + if (empty($usernames)) { return array(); } - $usernames[1] = array_unique($usernames[1]); + $usernames = array_unique($usernames); - $usernames = array_map('utf8_clean_string', $usernames[1]); + $usernames = array_map('utf8_clean_string', $usernames); $users = array(); @@ -109,32 +106,23 @@ class quote extends \phpbb\notification\type\post * Update a notification * * @param array $post Data specific for this type that will be updated + * @return true */ public function update_notifications($post) { - $old_notifications = array(); - $sql = 'SELECT n.user_id - FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt - WHERE n.notification_type_id = ' . (int) $this->notification_type_id . ' - AND n.item_id = ' . static::get_item_id($post) . ' - 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)) - { - $old_notifications[] = $row['user_id']; - } - $this->db->sql_freeresult($result); + $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($old_notifications, array_keys($notifications)); + $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), $old_notifications) as $user_id) + foreach (array_diff(array_keys($notifications), array_keys($old_notifications)) as $user_id) { $add_notifications[$user_id] = $notifications[$user_id]; } @@ -145,11 +133,7 @@ class quote extends \phpbb\notification\type\post // Remove the necessary notifications if (!empty($remove_notifications)) { - $sql = 'DELETE FROM ' . $this->notifications_table . ' - WHERE notification_type_id = ' . (int) $this->notification_type_id . ' - AND item_id = ' . static::get_item_id($post) . ' - AND ' . $this->db->sql_in_set('user_id', $remove_notifications); - $this->db->sql_query($sql); + $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) @@ -187,4 +171,14 @@ class quote extends \phpbb\notification\type\post '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; + } } diff --git a/phpBB/phpbb/notification/type/report_pm.php b/phpBB/phpbb/notification/type/report_pm.php index fc39623c5c..444f98270d 100644 --- a/phpBB/phpbb/notification/type/report_pm.php +++ b/phpBB/phpbb/notification/type/report_pm.php @@ -60,7 +60,7 @@ class report_pm extends \phpbb\notification\type\pm * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + static public $notification_option = array( 'id' => 'notification.type.report', 'lang' => 'NOTIFICATION_TYPE_REPORT', 'group' => 'NOTIFICATION_GROUP_MODERATION', @@ -70,8 +70,9 @@ class report_pm extends \phpbb\notification\type\pm * Get the id of the parent * * @param array $pm The data from the pm + * @return int The report id */ - public static function get_item_parent_id($pm) + static public function get_item_parent_id($pm) { return (int) $pm['report_id']; } @@ -141,13 +142,16 @@ class report_pm extends \phpbb\notification\type\pm */ public function get_email_template_variables() { - $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); + $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'))), + '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}&i=pm_reports&mode=pm_report_details", + /** @deprecated 3.2.6-RC1 (to be removed in 4.0.0) use {SUBJECT} instead in report_pm.txt */ + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), + + 'U_VIEW_REPORT' => generate_board_url() . "/mcp.{$this->php_ext}?r={$this->item_parent_id}&i=pm_reports&mode=pm_report_details", ); } @@ -168,11 +172,11 @@ class report_pm extends \phpbb\notification\type\pm */ public function get_title() { - $this->user->add_lang('mcp'); + $this->language->add_lang('mcp'); $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); - return $this->user->lang( + return $this->language->lang( $this->language_key, $username ); @@ -185,7 +189,7 @@ class report_pm extends \phpbb\notification\type\pm */ public function get_reference() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REFERENCE', censor_text($this->get_data('message_subject')) ); @@ -200,21 +204,21 @@ class report_pm extends \phpbb\notification\type\pm { if ($this->get_data('report_text')) { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REASON', $this->get_data('report_text') ); } - if (isset($this->user->lang[$this->get_data('reason_title')])) + if ($this->language->is_set($this->get_data('reason_title'))) { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REASON', - $this->user->lang[$this->get_data('reason_title')] + $this->language->lang($this->get_data('reason_title')) ); } - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REASON', $this->get_data('reason_description') ); @@ -235,17 +239,13 @@ class report_pm extends \phpbb\notification\type\pm */ public function users_to_query() { - return array($this->get_data('reporter_id')); - } + return array( + $this->get_data('from_user_id'), + $this->get_data('reporter_id'), + ); } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { @@ -254,6 +254,6 @@ class report_pm extends \phpbb\notification\type\pm $this->set_data('reason_description', $post['reason_description']); $this->set_data('report_text', $post['report_text']); - return parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($post, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/report_pm_closed.php b/phpBB/phpbb/notification/type/report_pm_closed.php index 1c99db60c3..5e98eb5feb 100644 --- a/phpBB/phpbb/notification/type/report_pm_closed.php +++ b/phpBB/phpbb/notification/type/report_pm_closed.php @@ -64,7 +64,7 @@ class report_pm_closed extends \phpbb\notification\type\pm return array(); } - return array($pm['reporter'] => array('')); + return array($pm['reporter'] => $this->notification_manager->get_default_methods()); } /** @@ -106,7 +106,7 @@ class report_pm_closed extends \phpbb\notification\type\pm { $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile'); - return $this->user->lang( + return $this->language->lang( $this->language_key, $username ); @@ -119,7 +119,7 @@ class report_pm_closed extends \phpbb\notification\type\pm */ public function get_reference() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REFERENCE', censor_text($this->get_data('message_subject')) ); @@ -144,21 +144,24 @@ class report_pm_closed extends \phpbb\notification\type\pm } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $pm PM Data - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($pm, $pre_create_data = array()) { $this->set_data('closer_id', $pm['closer_id']); - $data = parent::create_insert_array($pm, $pre_create_data); + parent::create_insert_array($pm, $pre_create_data); + + $this->notification_time = time(); + } - $this->notification_time = $data['notification_time'] = time(); + /** + * {@inheritdoc} + */ + public function get_insert_array() + { + $data = parent::get_insert_array(); + $data['notification_time'] = $this->notification_time; return $data; } diff --git a/phpBB/phpbb/notification/type/report_post.php b/phpBB/phpbb/notification/type/report_post.php index aed31e8642..84a5241417 100644 --- a/phpBB/phpbb/notification/type/report_post.php +++ b/phpBB/phpbb/notification/type/report_post.php @@ -66,7 +66,7 @@ class report_post extends \phpbb\notification\type\post_in_queue * @var bool|array False if the service should use it's default data * Array of data (including keys 'id' and 'lang') */ - public static $notification_option = array( + static public $notification_option = array( 'id' => 'notification.type.report', 'lang' => 'NOTIFICATION_TYPE_REPORT', 'group' => 'NOTIFICATION_GROUP_MODERATION', @@ -139,11 +139,11 @@ class report_post extends \phpbb\notification\type\post_in_queue */ public function get_title() { - $this->user->add_lang('mcp'); + $this->language->add_lang('mcp'); $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); - return $this->user->lang( + return $this->language->lang( $this->language_key, $username ); @@ -156,7 +156,7 @@ class report_post extends \phpbb\notification\type\post_in_queue */ public function get_reference() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REFERENCE', censor_text($this->get_data('post_subject')) ); @@ -171,21 +171,21 @@ class report_post extends \phpbb\notification\type\post_in_queue { if ($this->get_data('report_text')) { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REASON', $this->get_data('report_text') ); } - if (isset($this->user->lang[$this->get_data('reason_title')])) + if ($this->language->is_set($this->get_data('reason_title'))) { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REASON', - $this->user->lang[$this->get_data('reason_title')] + $this->language->lang($this->get_data('reason_title')) ); } - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REASON', $this->get_data('reason_description') ); @@ -210,13 +210,7 @@ class report_post extends \phpbb\notification\type\post_in_queue } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { @@ -225,6 +219,6 @@ class report_post extends \phpbb\notification\type\post_in_queue $this->set_data('reason_description', $post['reason_description']); $this->set_data('report_text', $post['report_text']); - return parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($post, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/report_post_closed.php b/phpBB/phpbb/notification/type/report_post_closed.php index 3f4378628b..165034d57e 100644 --- a/phpBB/phpbb/notification/type/report_post_closed.php +++ b/phpBB/phpbb/notification/type/report_post_closed.php @@ -71,7 +71,7 @@ class report_post_closed extends \phpbb\notification\type\post return array(); } - return array($post['reporter'] => array('')); + return array($post['reporter'] => $this->notification_manager->get_default_methods()); } /** @@ -113,7 +113,7 @@ class report_post_closed extends \phpbb\notification\type\post { $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile'); - return $this->user->lang( + return $this->language->lang( $this->language_key, $username ); @@ -126,7 +126,7 @@ class report_post_closed extends \phpbb\notification\type\post */ public function get_reference() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REFERENCE', censor_text($this->get_data('post_subject')) ); @@ -151,21 +151,24 @@ class report_post_closed extends \phpbb\notification\type\post } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('closer_id', $post['closer_id']); - $data = parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($post, $pre_create_data); + + $this->notification_time = time(); + } - $this->notification_time = $data['notification_time'] = time(); + /** + * {@inheritdoc} + */ + public function get_insert_array() + { + $data = parent::get_insert_array(); + $data['notification_time'] = $this->notification_time; return $data; } diff --git a/phpBB/phpbb/notification/type/topic.php b/phpBB/phpbb/notification/type/topic.php index fb08a9eee1..5c42afa8c8 100644 --- a/phpBB/phpbb/notification/type/topic.php +++ b/phpBB/phpbb/notification/type/topic.php @@ -50,11 +50,27 @@ class topic extends \phpbb\notification\type\base * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + 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 */ @@ -67,8 +83,9 @@ class topic extends \phpbb\notification\type\base * Get the id of the item * * @param array $post The data from the post + * @return int The topic id */ - public static function get_item_id($post) + static public function get_item_id($post) { return (int) $post['topic_id']; } @@ -77,8 +94,9 @@ class topic extends \phpbb\notification\type\base * Get the id of the parent * * @param array $post The data from the post + * @return int The forum id */ - public static function get_item_parent_id($post) + static public function get_item_parent_id($post) { return (int) $post['forum_id']; } @@ -138,7 +156,7 @@ class topic extends \phpbb\notification\type\base $username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile'); } - return $this->user->lang( + return $this->language->lang( $this->language_key, $username ); @@ -151,7 +169,7 @@ class topic extends \phpbb\notification\type\base */ public function get_reference() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_REFERENCE', censor_text($this->get_data('topic_title')) ); @@ -164,7 +182,7 @@ class topic extends \phpbb\notification\type\base */ public function get_forum() { - return $this->user->lang( + return $this->language->lang( 'NOTIFICATION_FORUM', $this->get_data('forum_name') ); @@ -243,7 +261,7 @@ class topic extends \phpbb\notification\type\base */ public function pre_create_insert_array($post, $notify_users) { - if (!sizeof($notify_users) || !$this->inherit_read_status) + if (!count($notify_users) || !$this->inherit_read_status) { return array(); } @@ -263,13 +281,7 @@ class topic extends \phpbb\notification\type\base } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($post, $pre_create_data = array()) { @@ -290,6 +302,6 @@ class topic extends \phpbb\notification\type\base $this->notification_read = true; } - return parent::create_insert_array($post, $pre_create_data); + parent::create_insert_array($post, $pre_create_data); } } diff --git a/phpBB/phpbb/notification/type/topic_in_queue.php b/phpBB/phpbb/notification/type/topic_in_queue.php index 6e57b9ac0c..2d732b9cd7 100644 --- a/phpBB/phpbb/notification/type/topic_in_queue.php +++ b/phpBB/phpbb/notification/type/topic_in_queue.php @@ -43,7 +43,7 @@ class topic_in_queue extends \phpbb\notification\type\topic * @var bool|array False if the service should use it's default data * Array of data (including keys 'id', 'lang', and 'group') */ - public static $notification_option = array( + static public $notification_option = array( 'id' => 'notification.type.needs_approval', 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', 'group' => 'NOTIFICATION_GROUP_MODERATION', @@ -123,19 +123,22 @@ class topic_in_queue extends \phpbb\notification\type\topic } /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $topic Data from submit_post - * @param array $pre_create_data Data from pre_create_insert_array() - * - * @return array Array of data ready to be inserted into the database + * {@inheritdoc} */ public function create_insert_array($topic, $pre_create_data = array()) { - $data = parent::create_insert_array($topic, $pre_create_data); + parent::create_insert_array($topic, $pre_create_data); + + $this->notification_time = time(); + } - $this->notification_time = $data['notification_time'] = time(); + /** + * {@inheritdoc} + */ + public function get_insert_array() + { + $data = parent::get_insert_array(); + $data['notification_time'] = $this->notification_time; return $data; } diff --git a/phpBB/phpbb/notification/type/type_interface.php b/phpBB/phpbb/notification/type/type_interface.php index 5c5a110836..f9f832bdda 100644 --- a/phpBB/phpbb/notification/type/type_interface.php +++ b/phpBB/phpbb/notification/type/type_interface.php @@ -37,14 +37,14 @@ interface type_interface * * @param array $type_data The type specific data */ - public static function get_item_id($type_data); + static public function get_item_id($type_data); /** * Get the id of the parent * * @param array $type_data The type specific data */ - public static function get_item_parent_id($type_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) @@ -177,14 +177,18 @@ interface type_interface /** * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) * * @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 create_insert_array($type_data, $pre_create_data); + public function get_insert_array(); /** * Function for preparing the data for update in an SQL query @@ -202,7 +206,7 @@ interface type_interface * @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); + public function mark_read($return = false); /** * Mark this item unread @@ -210,5 +214,5 @@ interface type_interface * @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); + public function mark_unread($return = false); } |