diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php
index 27d3be83e7..d2076ce086 100644
--- a/phpBB/includes/acp/acp_board.php
+++ b/phpBB/includes/acp/acp_board.php
@@ -494,6 +494,8 @@ class acp_board
'webpush_enable' => ['lang' => 'WEBPUSH_ENABLE', 'validate' => 'bool', 'type' => 'custom', 'method' => 'webpush_enable', 'explain' => true],
'webpush_vapid_public' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true],
'webpush_vapid_private' => ['lang' => 'WEBPUSH_VAPID_PRIVATE', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true],
+ 'webpush_method_default_enable' => ['lang' => 'WEBPUSH_METHOD_DEFAULT_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
+ 'webpush_dropdown_subscribe' => ['lang' => 'WEBPUSH_DROPDOWN_SUBSCRIBE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'legend3' => 'ACP_SUBMIT_CHANGES',
],
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index c3028c45a5..0e52fb37d6 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -3735,6 +3735,9 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
$timezone_name = $user->lang['timezones'][$timezone_name];
}
+ /** @var \phpbb\controller\helper $controller_helper */
+ $controller_helper = $phpbb_container->get('controller.helper');
+
// Output the notifications
$notifications = false;
if ($config['load_notifications'] && $config['allow_board_notifications'] && $user->data['user_id'] != ANONYMOUS && $user->data['user_type'] != USER_IGNORE)
@@ -3751,10 +3754,22 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
{
$template->assign_block_vars('notifications', $notification->prepare_for_display());
}
+
+ // Assign web push template vars globally (if not done already by ucp_notifications) for the dropdown subscribe button
+ if ($config['webpush_enable'] && $config['webpush_dropdown_subscribe']
+ && $template->retrieve_var('NOTIFICATIONS_WEBPUSH_ENABLE') === null)
+ {
+ $methods = $phpbb_notifications->get_subscription_methods();
+ $webpush = $methods['notification.method.webpush'] ?? null;
+
+ if ($webpush)
+ {
+ $form_helper = $phpbb_container->get('form_helper');
+ $template->assign_vars($webpush['method']->get_ucp_template_data($controller_helper, $form_helper));
+ }
+ }
}
- /** @var \phpbb\controller\helper $controller_helper */
- $controller_helper = $phpbb_container->get('controller.helper');
$notification_mark_hash = generate_link_hash('mark_all_notifications_read');
$phpbb_version_parts = explode('.', PHPBB_VERSION, 3);
diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql
index 68a97decb7..ba8f654a90 100644
--- a/phpBB/install/schemas/schema_data.sql
+++ b/phpBB/install/schemas/schema_data.sql
@@ -329,6 +329,8 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\con
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_enable', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_public', '');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_private', '');
+INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_method_default_enable', '1');
+INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_dropdown_subscribe', '1');
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1);
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1);
diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php
index c57cefe685..3228db126b 100644
--- a/phpBB/language/en/acp/board.php
+++ b/phpBB/language/en/acp/board.php
@@ -590,6 +590,10 @@ $lang = array_merge($lang, [
'WEBPUSH_VAPID_PUBLIC_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) public key is shared to authenticate push messages from your site.
Caution: Modifying the VAPID public key will automatically render all Web Push subscriptions invalid.',
'WEBPUSH_VAPID_PRIVATE' => 'Server identification private key',
'WEBPUSH_VAPID_PRIVATE_EXPLAIN' => 'The Voluntary Application Server Identification (VAPID) private key is used to generate authenticated push messages dispatched from your site. The VAPID private key must form a valid public-private key pair alongside the VAPID public key.
Caution: Modifying the VAPID private key will automatically render all Web Push subscriptions invalid.',
+ 'WEBPUSH_METHOD_DEFAULT_ENABLE' => 'Enable all user-based web push notification options by default',
+ 'WEBPUSH_METHOD_DEFAULT_ENABLE_EXPLAIN' => 'When this setting is enabled, users who subscribe and allow browser notifications will start receiving them automatically. Users only need to visit the UCP Notification settings to disable any unwanted notifications.
If this setting is disabled, users will not receive any notifications, even if they have subscribed, until they visit the UCP Notification settings to enable the specific notification options they wish to receive.',
+ 'WEBPUSH_DROPDOWN_SUBSCRIBE' => 'Show “Subscribe” button in notification dropdown',
+ 'WEBPUSH_DROPDOWN_SUBSCRIBE_EXPLAIN' => 'Display a “Subscribe” button in the Notification dropdown, allowing users to easily subscribe to push notifications from anywhere in the forum.',
]);
// Jabber settings
diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php
index 71790e499b..5933cc8f5c 100644
--- a/phpBB/language/en/common.php
+++ b/phpBB/language/en/common.php
@@ -512,6 +512,9 @@ $lang = array_merge($lang, array(
),
'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.',
'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: %1$s',
+ 'NOTIFY_WEB_PUSH_ENABLE' => 'Enable Web Push notifications',
+ 'NOTIFY_WEB_PUSH_SUBSCRIBE' => 'Subscribe',
+ 'NOTIFY_WEB_PUSH_SUBSCRIBED'=> 'Subscribed',
'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.',
'NO_ACTION' => 'No action specified.',
'NO_ADMINISTRATORS' => 'There are no administrators.',
diff --git a/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php
new file mode 100644
index 0000000000..751ab9e5f4
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v400/add_webpush_options.php
@@ -0,0 +1,47 @@
+
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\db\migration\data\v400;
+
+use phpbb\db\migration\migration;
+
+class add_webpush_options extends migration
+{
+ public static function depends_on(): array
+ {
+ return [
+ '\phpbb\db\migration\data\v400\add_webpush',
+ ];
+ }
+
+ public function effectively_installed(): bool
+ {
+ return $this->config->offsetExists('webpush_method_default_enable') || $this->config->offsetExists('webpush_dropdown_subscribe');
+ }
+
+ public function update_data(): array
+ {
+ return [
+ ['config.add', ['webpush_method_default_enable', true]],
+ ['config.add', ['webpush_dropdown_subscribe', true]],
+ ];
+ }
+
+ public function revert_data(): array
+ {
+ return [
+ ['config.remove', ['webpush_method_default_enable']],
+ ['config.remove', ['webpush_dropdown_subscribe']],
+ ];
+ }
+}
diff --git a/phpBB/phpbb/notification/method/webpush.php b/phpBB/phpbb/notification/method/webpush.php
index a5a3b5e699..4d2d18bdc6 100644
--- a/phpBB/phpbb/notification/method/webpush.php
+++ b/phpBB/phpbb/notification/method/webpush.php
@@ -94,6 +94,14 @@ class webpush extends messenger_base implements extended_method_interface
&& !empty($this->config['webpush_vapid_public']) && !empty($this->config['webpush_vapid_private']);
}
+ /**
+ * {@inheritDoc}
+ */
+ public function is_enabled_by_default()
+ {
+ return (bool) $this->config['webpush_method_default_enable'];
+ }
+
/**
* {@inheritdoc}
*/
@@ -352,7 +360,7 @@ class webpush extends messenger_base implements extended_method_interface
}
return [
- 'NOTIFICATIONS_WEBPUSH_ENABLE' => true,
+ 'NOTIFICATIONS_WEBPUSH_ENABLE' => $this->config['webpush_dropdown_subscribe'] || stripos($this->user->page['page'], 'notification_options'),
'U_WEBPUSH_SUBSCRIBE' => $controller_helper->route('phpbb_ucp_push_subscribe_controller'),
'U_WEBPUSH_UNSUBSCRIBE' => $controller_helper->route('phpbb_ucp_push_unsubscribe_controller'),
'VAPID_PUBLIC_KEY' => $this->config['webpush_vapid_public'],
diff --git a/phpBB/styles/prosilver/template/notification_dropdown.html b/phpBB/styles/prosilver/template/notification_dropdown.html
index 52bc546976..ff52543d0a 100644
--- a/phpBB/styles/prosilver/template/notification_dropdown.html
+++ b/phpBB/styles/prosilver/template/notification_dropdown.html
@@ -44,6 +44,13 @@