diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index a6d925f95e..9e203e0519 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -25,7 +25,7 @@ class ucp_notifications public function main($id, $mode) { - global $config, $template, $user, $request, $phpbb_container; + global $config, $template, $user, $request, $phpbb_container, $phpbb_dispatcher; global $phpbb_root_path, $phpEx; add_form_key('ucp_notification'); @@ -57,15 +57,34 @@ class ucp_notifications foreach ($phpbb_notifications->get_subscription_types() as $group => $subscription_types) { - foreach ($subscription_types as $type => $data) + foreach ($subscription_types as $type => $type_data) { foreach ($notification_methods as $method => $method_data) { - if ($request->is_set_post(str_replace('.', '_', $type . '_' . $method_data['id'])) && (!isset($subscriptions[$type]) || !in_array($method_data['id'], $subscriptions[$type]))) + $is_set_notify = ($request->is_set_post(str_replace('.', '_', $type . '_' . $method_data['id']))) ? true : false; + + /** + * Event to perform additional actions before ucp_notifications is submitted + * + * @event core.ucp_notifications_submit_notification_is_set + * @var array type_data The notification type data + * @var array method_data The notification method data + * @var bool is_set_notify The notification is set or not + * + * @since 3.2.10-RC1 + */ + $vars = array( + 'type_data', + 'method_data', + 'is_set_notify', + ); + extract($phpbb_dispatcher->trigger_event('core.ucp_notifications_submit_notification_is_set', compact($vars))); + + if ($is_set_notify && (!isset($subscriptions[$type]) || !in_array($method_data['id'], $subscriptions[$type]))) { $phpbb_notifications->add_subscription($type, 0, $method_data['id']); } - else if (!$request->is_set_post(str_replace('.', '_', $type . '_' . $method_data['id'])) && isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) + else if (!$is_set_notify && isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) { $phpbb_notifications->delete_subscription($type, 0, $method_data['id']); } @@ -80,7 +99,7 @@ class ucp_notifications $this->output_notification_methods($phpbb_notifications, $template, $user, 'notification_methods'); - $this->output_notification_types($subscriptions, $phpbb_notifications, $template, $user, 'notification_types'); + $this->output_notification_types($subscriptions, $phpbb_notifications, $template, $user, $phpbb_dispatcher, 'notification_types'); $this->tpl_name = 'ucp_notifications'; $this->page_title = 'UCP_NOTIFICATION_OPTIONS'; @@ -168,9 +187,12 @@ class ucp_notifications * @param \phpbb\notification\manager $phpbb_notifications * @param \phpbb\template\template $template * @param \phpbb\user $user + * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher * @param string $block + * + * @changed 3.2.10-RC1 Added $phpbb_dispatcher */ - public function output_notification_types($subscriptions, \phpbb\notification\manager $phpbb_notifications, \phpbb\template\template $template, \phpbb\user $user, $block = 'notification_types') + public function output_notification_types($subscriptions, \phpbb\notification\manager $phpbb_notifications, \phpbb\template\template $template, \phpbb\user $user, \phpbb\event\dispatcher_interface $phpbb_dispatcher, $block = 'notification_types') { $notification_methods = $phpbb_notifications->get_subscription_methods(); @@ -191,15 +213,31 @@ class ucp_notifications foreach ($notification_methods as $method => $method_data) { - $template->assign_block_vars($block . '.notification_methods', array( + $tpl_ary = [ 'METHOD' => $method_data['id'], - 'NAME' => $user->lang($method_data['lang']), - 'AVAILABLE' => $method_data['method']->is_available($type_data['type']), - 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) ? true : false, - )); + ]; + + /** + * Event to perform additional actions before ucp_notifications is displayed + * + * @event core.ucp_notifications_output_notification_types_modify_template_vars + * @var array type_data The notification type data + * @var array method_data The notification method data + * @var array tpl_ary The template variables + * + * @since 3.2.10-RC1 + */ + $vars = array( + 'type_data', + 'method_data', + 'tpl_ary', + ); + extract($phpbb_dispatcher->trigger_event('core.ucp_notifications_output_notification_types_modify_template_vars', compact($vars))); + + $template->assign_block_vars($block . '.notification_methods', $tpl_ary); } } } diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index 52c650df5d..a22e108b23 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -277,7 +277,7 @@ class manager * Here, $notify_users is already filtered by f_read and the ignored list included in the options variable * * @event core.notification_manager_add_notifications - * @var string notification_type_name The forum id from where the topic belongs + * @var string notification_type_name The notification type identifier * @var array data Data specific for the notification_type_name used will be inserted * @var array notify_users The array of userid that are going to be notified for this notification. Set to array() to cancel. * @var array options The options that were used when this method was called (read only) @@ -333,10 +333,34 @@ class manager foreach ($this->get_subscription_methods_instances() as $method) { $notified_users = $method->get_notified_users($notification_type_id, array('item_id' => $item_id)); + $notification_method_name = $method->get_type(); + foreach ($notified_users as $user => $notifications) { unset($notify_users[$user]); } + + /** + * Allow filtering the notify_users array by notification_type_name & notification_method_name for a notification that is about to be sent. + * Here, $notify_users is already filtered from users who've already been notified. + * + * @event core.notification_manager_add_notifications_for_users_modify_data + * @var string notification_type_name The notification type identifier + * @var string notification_method_name The notification method identifier (read only) + * @var array data Data specific for the notification_type_name used will be inserted + * @var array notify_users The array of userid that are going to be notified for this notification. Set to array() to cancel or unset each user by userid. + * @var array notified_users The list of the users already notified (read only) + * + * @since 3.2.10-RC1 + */ + $vars = array( + 'notification_type_name', + 'notification_method_name', + 'data', + 'notify_users', + 'notified_users', + ); + extract($this->phpbb_dispatcher->trigger_event('core.notification_manager_add_notifications_for_users_modify_data', compact($vars))); } if (!count($notify_users))