mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-03 15:27:42 +02:00
Merge pull request #6416 from marc1706/ticket/17010
[ticket/17010] Implement notification method for web push
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
use Minishlink\WebPush\VAPID;
|
||||
use phpbb\config\config;
|
||||
use phpbb\language\language;
|
||||
use phpbb\user;
|
||||
@@ -485,6 +486,20 @@ class acp_board
|
||||
);
|
||||
break;
|
||||
|
||||
case 'webpush':
|
||||
$display_vars = [
|
||||
'title' => 'ACP_WEBPUSH_SETTINGS',
|
||||
'vars' => [
|
||||
'legend1' => 'GENERAL_SETTINGS',
|
||||
'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],
|
||||
|
||||
'legend3' => 'ACP_SUBMIT_CHANGES',
|
||||
],
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
trigger_error('NO_MODE', E_USER_ERROR);
|
||||
break;
|
||||
@@ -1347,4 +1362,49 @@ class acp_board
|
||||
return '<input class="button2" type="submit" id="' . $key . '" name="' . $key . '" value="' . $user->lang('SEND_TEST_EMAIL') . '" />
|
||||
<textarea id="' . $key . '_text" name="' . $key . '_text" placeholder="' . $user->lang('MESSAGE') . '"></textarea>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate form data for web push enable
|
||||
*
|
||||
* @param string $value Webpush enable value
|
||||
* @param string $key Webpush enable config key
|
||||
*
|
||||
* @return array[] Form data
|
||||
*/
|
||||
public function webpush_enable($value, $key): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'radio',
|
||||
'buttons' => [
|
||||
[
|
||||
'name' => "config[$key]",
|
||||
'label' => $this->language->lang('YES'),
|
||||
'type' => 'radio',
|
||||
'class' => 'radio',
|
||||
'value' => 1,
|
||||
'checked' => $value,
|
||||
],
|
||||
[
|
||||
'name' => "config[$key]",
|
||||
'label' => $this->language->lang('NO'),
|
||||
'type' => 'radio',
|
||||
'class' => 'radio',
|
||||
'value' => 0,
|
||||
'checked' => !$value,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'tag' => 'input',
|
||||
'class' => 'button2',
|
||||
'name' => "config[$key]",
|
||||
'type' => 'button',
|
||||
'value' => $this->language->lang('WEBPUSH_GENERATE_VAPID_KEYS'),
|
||||
'data' => [
|
||||
'ajax' => 'generate_vapid_keys',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -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')),
|
||||
|
@@ -2009,16 +2009,14 @@ function check_link_hash($token, $link_name)
|
||||
*/
|
||||
function add_form_key($form_name, $template_variable_suffix = '')
|
||||
{
|
||||
global $config, $template, $user, $phpbb_dispatcher;
|
||||
global $phpbb_container, $phpbb_dispatcher, $template;
|
||||
|
||||
$now = time();
|
||||
$token_sid = ($user->data['user_id'] == ANONYMOUS && !empty($config['form_token_sid_guests'])) ? $user->session_id : '';
|
||||
$token = sha1($now . $user->data['user_form_salt'] . $form_name . $token_sid);
|
||||
/** @var \phpbb\form\form_helper $form_helper */
|
||||
$form_helper = $phpbb_container->get('form_helper');
|
||||
|
||||
$s_fields = build_hidden_fields(array(
|
||||
'creation_time' => $now,
|
||||
'form_token' => $token,
|
||||
));
|
||||
$form_tokens = $form_helper->get_form_tokens($form_name, $now, $token_sid, $token);
|
||||
|
||||
$s_fields = build_hidden_fields($form_tokens);
|
||||
|
||||
/**
|
||||
* Perform additional actions on creation of the form token
|
||||
@@ -2058,35 +2056,12 @@ function add_form_key($form_name, $template_variable_suffix = '')
|
||||
*/
|
||||
function check_form_key($form_name, $timespan = false)
|
||||
{
|
||||
global $config, $request, $user;
|
||||
global $phpbb_container;
|
||||
|
||||
if ($timespan === false)
|
||||
{
|
||||
// we enforce a minimum value of half a minute here.
|
||||
$timespan = ($config['form_token_lifetime'] == -1) ? -1 : max(30, $config['form_token_lifetime']);
|
||||
}
|
||||
/** @var \phpbb\form\form_helper $form_helper */
|
||||
$form_helper = $phpbb_container->get('form_helper');
|
||||
|
||||
if ($request->is_set_post('creation_time') && $request->is_set_post('form_token'))
|
||||
{
|
||||
$creation_time = abs($request->variable('creation_time', 0));
|
||||
$token = $request->variable('form_token', '');
|
||||
|
||||
$diff = time() - $creation_time;
|
||||
|
||||
// If creation_time and the time() now is zero we can assume it was not a human doing this (the check for if ($diff)...
|
||||
if (defined('DEBUG_TEST') || $diff && ($diff <= $timespan || $timespan === -1))
|
||||
{
|
||||
$token_sid = ($user->data['user_id'] == ANONYMOUS && !empty($config['form_token_sid_guests'])) ? $user->session_id : '';
|
||||
$key = sha1($creation_time . $user->data['user_form_salt'] . $form_name . $token_sid);
|
||||
|
||||
if ($key === $token)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return $form_helper->check_form_tokens($form_name, $timespan !== false ? $timespan : null);
|
||||
}
|
||||
|
||||
// Message/Login boxes
|
||||
|
@@ -14,6 +14,11 @@
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
use phpbb\controller\helper;
|
||||
use phpbb\form\form_helper;
|
||||
use phpbb\notification\method\extended_method_interface;
|
||||
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
@@ -23,17 +28,28 @@ class ucp_notifications
|
||||
{
|
||||
public $u_action;
|
||||
|
||||
private const FORM_TOKEN_NAME = 'ucp_notification';
|
||||
|
||||
/** @var helper */
|
||||
private helper $controller_helper;
|
||||
|
||||
/** @var form_helper */
|
||||
private form_helper $form_helper;
|
||||
|
||||
public function main($id, $mode)
|
||||
{
|
||||
global $config, $template, $user, $request, $phpbb_container, $phpbb_dispatcher;
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
add_form_key('ucp_notification');
|
||||
add_form_key(self::FORM_TOKEN_NAME);
|
||||
|
||||
$start = $request->variable('start', 0);
|
||||
$form_time = $request->variable('form_time', 0);
|
||||
$form_time = ($form_time <= 0 || $form_time > time()) ? time() : $form_time;
|
||||
|
||||
$this->controller_helper = $phpbb_container->get('controller.helper');
|
||||
$this->form_helper = $phpbb_container->get('form_helper');
|
||||
|
||||
/* @var $phpbb_notifications \phpbb\notification\manager */
|
||||
$phpbb_notifications = $phpbb_container->get('notification_manager');
|
||||
|
||||
@@ -48,7 +64,7 @@ class ucp_notifications
|
||||
// Add/remove subscriptions
|
||||
if ($request->is_set_post('submit'))
|
||||
{
|
||||
if (!check_form_key('ucp_notification'))
|
||||
if (!check_form_key(self::FORM_TOKEN_NAME))
|
||||
{
|
||||
trigger_error('FORM_INVALID');
|
||||
}
|
||||
@@ -103,11 +119,15 @@ class ucp_notifications
|
||||
trigger_error($message);
|
||||
}
|
||||
|
||||
$this->output_notification_methods($phpbb_notifications, $template, $user, 'notification_methods');
|
||||
$this->output_notification_methods($phpbb_notifications, $template, $user);
|
||||
|
||||
$this->output_notification_types($subscriptions, $phpbb_notifications, $template, $user, $phpbb_dispatcher, 'notification_types');
|
||||
|
||||
$this->tpl_name = 'ucp_notifications';
|
||||
$template->assign_vars([
|
||||
'FORM_TOKENS' => $this->form_helper->get_form_tokens(self::FORM_TOKEN_NAME),
|
||||
]);
|
||||
|
||||
$this->tpl_name = 'ucp_notifications_options';
|
||||
$this->page_title = 'UCP_NOTIFICATION_OPTIONS';
|
||||
break;
|
||||
|
||||
@@ -138,7 +158,7 @@ class ucp_notifications
|
||||
// Mark specific notifications read
|
||||
if ($request->is_set_post('submit'))
|
||||
{
|
||||
if (!check_form_key('ucp_notification'))
|
||||
if (!check_form_key(self::FORM_TOKEN_NAME))
|
||||
{
|
||||
trigger_error('FORM_INVALID');
|
||||
}
|
||||
@@ -266,11 +286,16 @@ class ucp_notifications
|
||||
{
|
||||
$notification_methods = $phpbb_notifications->get_subscription_methods();
|
||||
|
||||
foreach ($notification_methods as $method => $method_data)
|
||||
foreach ($notification_methods as $method_data)
|
||||
{
|
||||
if ($method_data['method'] instanceof extended_method_interface)
|
||||
{
|
||||
$ucp_template_data = $method_data['method']->get_ucp_template_data($this->controller_helper, $this->form_helper);
|
||||
$template->assign_vars($ucp_template_data);
|
||||
}
|
||||
|
||||
$template->assign_block_vars($block, array(
|
||||
'METHOD' => $method_data['id'],
|
||||
|
||||
'NAME' => $user->lang($method_data['lang']),
|
||||
));
|
||||
}
|
||||
|
Reference in New Issue
Block a user