diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index df7c8bf657..d6ce8f23c4 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -485,6 +485,19 @@ class acp_board ); break; + case 'webpush': + $display_vars = [ + 'title' => 'ACP_WEBPUSH_SETTINGS', + 'vars' => [ + 'legend1' => 'GENERAL_SETTINGS', + 'webpush_vapid_public' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true], + 'webpush_vapid_private' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true], + + 'legend3' => 'ACP_SUBMIT_CHANGES', + ], + ]; + break; + default: trigger_error('NO_MODE', E_USER_ERROR); break; diff --git a/phpBB/includes/acp/info/acp_board.php b/phpBB/includes/acp/info/acp_board.php index 1a3ee7b6be..a1d9f4fdd1 100644 --- a/phpBB/includes/acp/info/acp_board.php +++ b/phpBB/includes/acp/info/acp_board.php @@ -30,6 +30,7 @@ class acp_board_info 'auth' => array('title' => 'ACP_AUTH_SETTINGS', 'auth' => 'acl_a_server', 'cat' => array('ACP_CLIENT_COMMUNICATION')), 'email' => array('title' => 'ACP_EMAIL_SETTINGS', 'auth' => 'acl_a_server', 'cat' => array('ACP_CLIENT_COMMUNICATION')), + 'webpush' => array('title' => 'ACP_WEBPUSH_SETTINGS', 'auth' => 'acl_a_server', 'cat' => array('ACP_CLIENT_COMMUNICATION')), 'cookie' => array('title' => 'ACP_COOKIE_SETTINGS', 'auth' => 'acl_a_server', 'cat' => array('ACP_SERVER_CONFIGURATION')), 'server' => array('title' => 'ACP_SERVER_SETTINGS', 'auth' => 'acl_a_server', 'cat' => array('ACP_SERVER_CONFIGURATION')), diff --git a/phpBB/phpbb/db/migration/data/v400/add_notification_push_table.php b/phpBB/phpbb/db/migration/data/v400/add_notification_push_table.php index 0d71f5fb60..e822a39405 100644 --- a/phpBB/phpbb/db/migration/data/v400/add_notification_push_table.php +++ b/phpBB/phpbb/db/migration/data/v400/add_notification_push_table.php @@ -52,4 +52,31 @@ class add_notification_push_table extends migration 'drop_tables' => [$this->table_prefix . 'notification_push'], ]; } + + public function update_data(): array + { + return [ + ['config.add', ['webpush_vapid_public', '']], + ['config.add', ['webpush_vapid_private', '']], + ['module.add', [ + 'acp', + 'ACP_BOARD_CONFIGURATION', + [ + 'module_basename' => 'acp_board', + 'module_langname' => 'ACP_WEBPUSH_SETTINGS', + 'module_mode' => 'webpush', + 'module_auth' => 'acl_a_board', + 'after' => ['settings', 'ACP_JABBER_SETTINGS'], + ], + ]], + ]; + } + + public function revert_data(): array + { + return [ + ['config.remove', ['webpush_vapid_public']], + ['config.remove', ['webpush_vapid_private']], + ]; + } } diff --git a/phpBB/phpbb/notification/method/webpush.php b/phpBB/phpbb/notification/method/webpush.php index f88cfc7cf9..48787901b0 100644 --- a/phpBB/phpbb/notification/method/webpush.php +++ b/phpBB/phpbb/notification/method/webpush.php @@ -115,10 +115,63 @@ class webpush extends \phpbb\notification\method\messenger_base $insert_buffer->flush(); // @todo: add actual web push code + $this->notify_using_webpush(); return false; } + protected function notify_using_webpush() + { + if (empty($this->queue)) + { + return; + } + + // Load all users we want to notify (we need their email address) + $user_ids = []; + foreach ($this->queue as $notification) + { + $user_ids[] = $notification->user_id; + } + + // We do not send emails to banned users + if (!function_exists('phpbb_get_banned_user_ids')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + $banned_users = phpbb_get_banned_user_ids($user_ids); + + // Load all the users we need + $this->user_loader->load_users(array_diff($user_ids, $banned_users), array(USER_IGNORE)); + + // Time to go through the queue and send emails + /** @var type_interface $notification */ + foreach ($this->queue as $notification) + { + $user = $this->user_loader->get_user($notification->user_id); + + if ($user['user_type'] == USER_INACTIVE && $user['user_inactive_reason'] == INACTIVE_MANUAL) + { + continue; + } + + // add actual web push data + $data['data'] = [ + 'badge' => '', // @todo: to be filled? + 'body' => $notification->get_title(), + 'icon' => '', // @todo: to be filled? + 'image' => '', // @todo: to be filled? + 'title' => $this->config['sitename'], + 'url' => $notification->get_url(), + ]; + + // @todo: start implementing actual web push code + } + + // We're done, empty the queue + $this->empty_queue(); + } + /** * {@inheritdoc} */