From 45aecb2d0b18b316d8952b9b926001719a7788af Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 8 Jan 2024 19:35:23 +0700 Subject: [PATCH] Add respective ACP button with handler method and language entries. --- acp/wpn_acp_module.php | 25 +++++++++++++++++++ adm/style/wpn_acp_settings.html | 4 +++ .../en/webpushnotifications_module_acp.php | 3 +++ 3 files changed, 32 insertions(+) diff --git a/acp/wpn_acp_module.php b/acp/wpn_acp_module.php index ebdadc1..b54a986 100644 --- a/acp/wpn_acp_module.php +++ b/acp/wpn_acp_module.php @@ -85,6 +85,19 @@ public function main($id, $mode) $this->save_settings(); } + if ($this->request->is_set_post('webpush_enable_for_all_users') + && $this->config['wpn_webpush_enable'] + && $this->config['wpn_webpush_vapid_public'] + ) + { + if (!check_form_key($form_key)) + { + trigger_error($this->lang->lang('FORM_INVALID'), E_USER_WARNING); + } + + $this->webpush_enable_for_all_users(); + } + $this->display_settings(); } } @@ -147,4 +160,16 @@ public function save_settings() trigger_error($this->lang->lang('CONFIG_UPDATED') . adm_back_link($this->u_action), E_USER_NOTICE); } + + /** + * Enable webpush notifications for all users having + * board notifications enabled for the same notification types + * + * @return void + */ + public function webpush_enable_for_all_users() + { + /* TODO: handle subscriptions */ + trigger_error($this->lang->lang('WEBPUSH_ENABLED_FOR_ALL_USERS') . adm_back_link($this->u_action), E_USER_NOTICE); + } } diff --git a/adm/style/wpn_acp_settings.html b/adm/style/wpn_acp_settings.html index aaa1a4f..c9f87ba 100644 --- a/adm/style/wpn_acp_settings.html +++ b/adm/style/wpn_acp_settings.html @@ -29,6 +29,10 @@

{{ lang('WARNING') }}


{{ lang('WEBPUSH_VAPID_PRIVATE_EXPLAIN') }}
+
+

{{ lang('WEBPUSH_ENABLE_FOR_ALL_USERS_EXPLAIN') }}
+
+
  diff --git a/language/en/webpushnotifications_module_acp.php b/language/en/webpushnotifications_module_acp.php index 41ff440..aa72f2f 100644 --- a/language/en/webpushnotifications_module_acp.php +++ b/language/en/webpushnotifications_module_acp.php @@ -41,6 +41,9 @@ 'ACP_WEBPUSH_SETTINGS_EXPLAIN' => 'Here you can enable and control the use of Web Push for board notifications. Web Push is a simple protocol for the delivery of real-time events to user agents, more commonly known as push messages. It is supported by most modern browsers on desktop and mobile devices.', 'WEBPUSH_ENABLE' => 'Enable Web Push', 'WEBPUSH_ENABLE_EXPLAIN' => 'Allow receiving notifications via Web Push. It is required to enter or generate valid VAPID identification keys to be able to use Web Push.', + 'WEBPUSH_ENABLE_FOR_ALL_USERS' => 'Enable Web Push for all users', + 'WEBPUSH_ENABLE_FOR_ALL_USERS_EXPLAIN' => 'This switch allows receiving notifications via Web Push to be enabled for all users having board notifications enabled. If enabled, users will be subscribed to receive notifications via Web Push for the same notification types they have board notifications enabled.', + 'WEBPUSH_ENABLED_FOR_ALL_USERS' => 'Users were subscribed to receive notifications via Web Push successfully.', 'WEBPUSH_GENERATE_VAPID_KEYS' => 'Generate Identification keys', 'WEBPUSH_VAPID_PUBLIC' => 'Server identification public key', 'WEBPUSH_VAPID_PUBLIC_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) public key will be shared to authenticate push messages sent by your site.
Warning: Changing the VAPID public key will automatically invalidate all Webpush subscriptions.',