From 199bc8f964fcdb3da2be089389cdf5f0950c3dd9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 25 Sep 2022 20:23:21 +0200 Subject: [PATCH] [ticket/17010] Add first webpush controller and start ucp integration PHPBB3-17010 --- .../container/services_notification.yml | 2 + .../config/default/container/services_ucp.yml | 5 ++ phpBB/config/default/routing/ucp.yml | 8 +++ phpBB/includes/ucp/ucp_notifications.php | 29 +++++++- phpBB/language/en/ucp.php | 4 ++ phpBB/phpbb/ucp/controller/webpush.php | 27 +++++++ .../prosilver/template/ucp_notifications.html | 34 --------- .../template/ucp_notifications_options.html | 71 +++++++++++++++++++ 8 files changed, 145 insertions(+), 35 deletions(-) create mode 100644 phpBB/phpbb/ucp/controller/webpush.php create mode 100644 phpBB/styles/prosilver/template/ucp_notifications_options.html diff --git a/phpBB/config/default/container/services_notification.yml b/phpBB/config/default/container/services_notification.yml index c018416da3..acb136641c 100644 --- a/phpBB/config/default/container/services_notification.yml +++ b/phpBB/config/default/container/services_notification.yml @@ -256,3 +256,5 @@ services: - '%core.php_ext%' - '%tables.notification_push%' - '%tables.push_subscriptions%' + tags: + - { name: notification.method } diff --git a/phpBB/config/default/container/services_ucp.yml b/phpBB/config/default/container/services_ucp.yml index 69ef5ffbf8..1d0535a116 100644 --- a/phpBB/config/default/container/services_ucp.yml +++ b/phpBB/config/default/container/services_ucp.yml @@ -15,3 +15,8 @@ services: - '%tables.users%' - '%core.root_path%' - '%core.php_ext%' + + phpbb.ucp.controller.push_worker: + class: phpbb\ucp\controller\webpush + arguments: + - '@config' diff --git a/phpBB/config/default/routing/ucp.yml b/phpBB/config/default/routing/ucp.yml index 06bd7c3a58..a88b6fc5ae 100644 --- a/phpBB/config/default/routing/ucp.yml +++ b/phpBB/config/default/routing/ucp.yml @@ -5,3 +5,11 @@ phpbb_ucp_reset_password_controller: phpbb_ucp_forgot_password_controller: path: /forgot_password defaults: { _controller: phpbb.ucp.controller.reset_password:request } + +phpbb_ucp_push_worker_controller: + path: /push/worker + defaults: { _controller: phpbb.ucp.controller.webpush:request } + +phpbb_ucp_push_subscribe_controller: + path: /push/subscribe + defaults: { _controller: phpbb.ucp.controller.webpush:request } diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 7a46d3e5aa..7b07138595 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -107,7 +107,12 @@ class ucp_notifications $this->output_notification_types($subscriptions, $phpbb_notifications, $template, $user, $phpbb_dispatcher, 'notification_types'); - $this->tpl_name = 'ucp_notifications'; + /** @var \phpbb\controller\helper $controller_helper */ + $controller_helper = $phpbb_container->get('controller.helper'); + + $template->assign_var('U_WEBPUSH_SUBSCRIBE', $controller_helper->route('phpbb_ucp_push_subscribe_controller')); + + $this->tpl_name = 'ucp_notifications_options'; $this->page_title = 'UCP_NOTIFICATION_OPTIONS'; break; @@ -266,6 +271,11 @@ class ucp_notifications { $notification_methods = $phpbb_notifications->get_subscription_methods(); + if (isset($notification_methods['notification.method.webpush'])) + { + $this->output_webpush_data($template); + } + foreach ($notification_methods as $method => $method_data) { $template->assign_block_vars($block, array( @@ -275,4 +285,21 @@ class ucp_notifications )); } } + + /** + * Output data for webpush + * + * @param \phpbb\template\template $template + * + * @return void + */ + protected function output_webpush_data(\phpbb\template\template $template): void + { + global $config; + + $template->assign_vars([ + 'NOTIFICATIONS_WEBPUSH_ENABLE' => true, // already checked, otherwise we wouldn't be here + 'NOTIFICATIONS_WEBPUSH_VAPID_PUBLIC' => $config['webpush_vapid_public'], + ]); + } } diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index a4dcdf775d..09bf7824e5 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -332,6 +332,7 @@ $lang = array_merge($lang, array( 'NOTIFICATION_METHOD_BOARD' => 'Notifications', 'NOTIFICATION_METHOD_EMAIL' => 'Email', 'NOTIFICATION_METHOD_JABBER' => 'Jabber', + 'NOTIFICATION_METHOD_WEBPUSH' => 'Web push', 'NOTIFICATION_TYPE' => 'Notification type', 'NOTIFICATION_TYPE_BOOKMARK' => 'Someone replies to a topic you have bookmarked', 'NOTIFICATION_TYPE_GROUP_REQUEST' => 'Someone requests to join a group you lead', @@ -355,6 +356,9 @@ $lang = array_merge($lang, array( 'NOTIFY_METHOD_EXPLAIN' => 'Method for sending messages sent via this board.', 'NOTIFY_METHOD_IM' => 'Jabber only', 'NOTIFY_ON_PM' => 'Notify me on new private messages', + 'NOTIFY_WEBPUSH_ACTIVATE' => 'Activate push notifications', + 'NOTIFY_WEBPUSH_ENABLE' => 'Enable receiving webpush notifications', + 'NOTIFY_WEBPUSH_ENABLE_EXPLAIN' => 'Enable receiving browser-based push notifications.
The notifications can be turned off at any time in your browser settings or by disabling the push notifications below.', 'NOT_ADDED_FRIENDS_ANONYMOUS' => 'You cannot add the anonymous user to your friends list.', 'NOT_ADDED_FRIENDS_BOTS' => 'You cannot add bots to your friends list.', 'NOT_ADDED_FRIENDS_FOES' => 'You cannot add users to your friends list who are on your foes list.', diff --git a/phpBB/phpbb/ucp/controller/webpush.php b/phpBB/phpbb/ucp/controller/webpush.php new file mode 100644 index 0000000000..67ef237d5b --- /dev/null +++ b/phpBB/phpbb/ucp/controller/webpush.php @@ -0,0 +1,27 @@ +config = $config; + } + + /** + * Handle password reset request + * + * @return Response + */ + public function request(): Response + { + return new Response('foo'); + } +} diff --git a/phpBB/styles/prosilver/template/ucp_notifications.html b/phpBB/styles/prosilver/template/ucp_notifications.html index d7019dee1c..7c5715fb41 100644 --- a/phpBB/styles/prosilver/template/ucp_notifications.html +++ b/phpBB/styles/prosilver/template/ucp_notifications.html @@ -12,38 +12,6 @@

{TITLE_EXPLAIN}

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
{L_NOTIFICATION_TYPE}{notification_methods.NAME}
{notification_types.GROUP_NAME}
- {notification_types.NAME} -
   {notification_types.EXPLAIN} -
checked="checked" disabled="disabled" />
-
diff --git a/phpBB/styles/prosilver/template/ucp_notifications_options.html b/phpBB/styles/prosilver/template/ucp_notifications_options.html new file mode 100644 index 0000000000..6536fb56cd --- /dev/null +++ b/phpBB/styles/prosilver/template/ucp_notifications_options.html @@ -0,0 +1,71 @@ +{% include('ucp_header.html') %} + +
+ +

{{ TITLE }}

+ {% if NOTIFICATIONS_WEBPUSH_ENABLE %} +
+
+
+
+

{{ lang('NOTIFY_WEBPUSH_ENABLE_EXPLAIN') }}
+
+ {{ lang('NOTIFY_WEBPUSH_ACTIVATE') }} +
+
+
+
+
+ {% endif %} +
+
+

{{ TITLE_EXPLAIN }}

+ + + + + + {% for method in notification_methods %} + + {% endfor %} + + + + {% for notification_type in notification_types %} + {% if notification_type.GROUP_NAME %} + + + + {% else %} + + + {% for notification_method in notification_type.notification_methods %} + {% apply spaceless %} + + {% endapply %} + {% endfor %} + + {% endif %} + {% endfor %} + +
{{ lang('NOTIFICATION_TYPE') }}{{ method.NAME }}
{{ notification_type.GROUP_NAME }}
+ {{ notification_type.NAME }} + {% if notification_type.EXPLAIN %}
   {{ notification_type.EXPLAIN }}{% endif %} +
+
+
+
+ + {% if notification_types or notification_list %} +
+ + {{ S_HIDDEN_FIELDS }} + +
{{ lang('MARK_ALL') }}{{ lang('UNMARK_ALL') }}
+ {{ S_FORM_TOKEN }} +
+ {% endif %} + +
+ +{% include('ucp_footer.html') %}