[ticket/17010] Add first webpush controller and start ucp integration

PHPBB3-17010
This commit is contained in:
Marc Alexander 2022-09-25 20:23:21 +02:00
parent 9bd9962aea
commit 199bc8f964
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
8 changed files with 145 additions and 35 deletions

View file

@ -256,3 +256,5 @@ services:
- '%core.php_ext%' - '%core.php_ext%'
- '%tables.notification_push%' - '%tables.notification_push%'
- '%tables.push_subscriptions%' - '%tables.push_subscriptions%'
tags:
- { name: notification.method }

View file

@ -15,3 +15,8 @@ services:
- '%tables.users%' - '%tables.users%'
- '%core.root_path%' - '%core.root_path%'
- '%core.php_ext%' - '%core.php_ext%'
phpbb.ucp.controller.push_worker:
class: phpbb\ucp\controller\webpush
arguments:
- '@config'

View file

@ -5,3 +5,11 @@ phpbb_ucp_reset_password_controller:
phpbb_ucp_forgot_password_controller: phpbb_ucp_forgot_password_controller:
path: /forgot_password path: /forgot_password
defaults: { _controller: phpbb.ucp.controller.reset_password:request } 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 }

View file

@ -107,7 +107,12 @@ class ucp_notifications
$this->output_notification_types($subscriptions, $phpbb_notifications, $template, $user, $phpbb_dispatcher, 'notification_types'); $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'; $this->page_title = 'UCP_NOTIFICATION_OPTIONS';
break; break;
@ -266,6 +271,11 @@ class ucp_notifications
{ {
$notification_methods = $phpbb_notifications->get_subscription_methods(); $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) foreach ($notification_methods as $method => $method_data)
{ {
$template->assign_block_vars($block, array( $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'],
]);
}
} }

View file

@ -332,6 +332,7 @@ $lang = array_merge($lang, array(
'NOTIFICATION_METHOD_BOARD' => 'Notifications', 'NOTIFICATION_METHOD_BOARD' => 'Notifications',
'NOTIFICATION_METHOD_EMAIL' => 'Email', 'NOTIFICATION_METHOD_EMAIL' => 'Email',
'NOTIFICATION_METHOD_JABBER' => 'Jabber', 'NOTIFICATION_METHOD_JABBER' => 'Jabber',
'NOTIFICATION_METHOD_WEBPUSH' => 'Web push',
'NOTIFICATION_TYPE' => 'Notification type', 'NOTIFICATION_TYPE' => 'Notification type',
'NOTIFICATION_TYPE_BOOKMARK' => 'Someone replies to a topic you have bookmarked', 'NOTIFICATION_TYPE_BOOKMARK' => 'Someone replies to a topic you have bookmarked',
'NOTIFICATION_TYPE_GROUP_REQUEST' => 'Someone requests to join a group you lead', '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_EXPLAIN' => 'Method for sending messages sent via this board.',
'NOTIFY_METHOD_IM' => 'Jabber only', 'NOTIFY_METHOD_IM' => 'Jabber only',
'NOTIFY_ON_PM' => 'Notify me on new private messages', '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.<br>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_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_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.', 'NOT_ADDED_FRIENDS_FOES' => 'You cannot add users to your friends list who are on your foes list.',

View file

@ -0,0 +1,27 @@
<?php
namespace phpbb\ucp\controller;
use phpbb\config\config;
use Symfony\Component\HttpFoundation\Response;
class webpush
{
/** @var config */
protected $config;
public function __construct(config $config)
{
$this->config = $config;
}
/**
* Handle password reset request
*
* @return Response
*/
public function request(): Response
{
return new Response('foo');
}
}

View file

@ -12,38 +12,6 @@
<div class="inner"> <div class="inner">
<p class="cp-desc">{TITLE_EXPLAIN}</p> <p class="cp-desc">{TITLE_EXPLAIN}</p>
<!-- IF MODE == 'notification_options' -->
<table class="table1">
<thead>
<tr>
<th>{L_NOTIFICATION_TYPE}</th>
<!-- BEGIN notification_methods -->
<th class="mark">{notification_methods.NAME}</th>
<!-- END notification_methods -->
</tr>
</thead>
<tbody>
<!-- BEGIN notification_types -->
<!-- IF notification_types.GROUP_NAME -->
<tr class="bg3">
<td colspan="{NOTIFICATION_TYPES_COLS}">{notification_types.GROUP_NAME}</td>
</tr>
<!-- ELSE -->
<tr class="<!-- IF notification_types.S_ROW_COUNT is odd -->bg1<!-- ELSE -->bg2<!-- ENDIF -->">
<td>
{notification_types.NAME}
<!-- IF notification_types.EXPLAIN --><br />&nbsp; &nbsp;{notification_types.EXPLAIN}<!-- ENDIF -->
</td>
<!-- BEGIN notification_methods -->
<td class="mark"><input type="checkbox" name="{notification_types.TYPE}_{notification_types.notification_methods.METHOD}"<!-- IF notification_types.notification_methods.SUBSCRIBED --> checked="checked"<!-- ENDIF --><!-- IF not notification_types.notification_methods.AVAILABLE --> disabled="disabled"<!-- ENDIF --> /></td>
<!-- END notification_methods -->
</tr>
<!-- ENDIF -->
<!-- END notification_types -->
</tbody>
</table>
<!-- ELSE -->
<!-- IF .notification_list --> <!-- IF .notification_list -->
<div class="action-bar bar-top"> <div class="action-bar bar-top">
<div class="pagination"> <div class="pagination">
@ -105,8 +73,6 @@
<!-- ELSE --> <!-- ELSE -->
<p><strong>{L_NO_NOTIFICATIONS}</strong></p> <p><strong>{L_NO_NOTIFICATIONS}</strong></p>
<!-- ENDIF --> <!-- ENDIF -->
<!-- ENDIF -->
</div> </div>
</div> </div>

View file

@ -0,0 +1,71 @@
{% include('ucp_header.html') %}
<form id="ucp" method="post" action="{{ S_UCP_ACTION }}"{{ S_FORM_ENCTYPE }}>
<h2 class="cp-title">{{ TITLE }}</h2>
{% if NOTIFICATIONS_WEBPUSH_ENABLE %}
<div class="panel">
<div class="inner">
<fieldset>
<dl>
<dt><label for="activate_webpush">{{ lang('NOTIFY_WEBPUSH_ENABLE') ~ lang('COLON') }}</label><br><span>{{ lang('NOTIFY_WEBPUSH_ENABLE_EXPLAIN') }}</span></dt>
<dd>
<a href="{{ U_WEBPUSH_SUBSCRIBE }}" data-ajax-action="activate_webpush" id="activate_webpush" title="{{ lang('NOTIFY_WEBPUSH_ACTIVATE') }}">{{ lang('NOTIFY_WEBPUSH_ACTIVATE') }}</a>
</dd>
</dl>
</fieldset>
</div>
</div>
{% endif %}
<div class="panel">
<div class="inner">
<p class="cp-desc">{{ TITLE_EXPLAIN }}</p>
<table class="table1">
<thead>
<tr>
<th>{{ lang('NOTIFICATION_TYPE') }}</th>
{% for method in notification_methods %}
<th class="mark">{{ method.NAME }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for notification_type in notification_types %}
{% if notification_type.GROUP_NAME %}
<tr class="bg3">
<td colspan="{{ NOTIFICATION_TYPES_COLS }}">{{ notification_type.GROUP_NAME }}</td>
</tr>
{% else %}
<tr class="{% if loop.index is even %}bg1{% else %}bg2{% endif %}">
<td>
{{ notification_type.NAME }}
{% if notification_type.EXPLAIN %}<br>&nbsp; &nbsp;{{ notification_type.EXPLAIN }}{% endif %}
</td>
{% for notification_method in notification_type.notification_methods %}
{% apply spaceless %}
<td class="mark">
<input type="checkbox" name="{{ notification_type.TYPE }}_{{ notification_method.METHOD }}"{% if notification_method.SUBSCRIBED %} checked="checked"{% endif %}{% if not notification_method.AVAILABLE %} disabled="disabled"{% endif %}/></td>
{% endapply %}
{% endfor %}
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
{% if notification_types or notification_list %}
<fieldset class="display-actions">
<input type="hidden" name="form_time" value="{{ FORM_TIME }}" />
{{ S_HIDDEN_FIELDS }}
<input type="submit" name="submit" value="{% if MODE == 'notification_options' %}{{ lang('SUBMIT') }}{% else %}{{ lang('MARK_READ') }}{% endif %}" class="button1 button button-form" />
<div><a href="#" onclick="$('#ucp input:checkbox').prop('checked', true); return false;">{{ lang('MARK_ALL') }}</a> &bull; <a href="#" onclick="$('#ucp input:checkbox').prop('checked', false); return false;">{{ lang('UNMARK_ALL') }}</a></div>
{{ S_FORM_TOKEN }}
</fieldset>
{% endif %}
</form>
{% include('ucp_footer.html') %}