Skip to content

Commit 074918e

Browse files
authored
Merge branch 'main' into Release-1.0.0
2 parents 13cbc63 + a269b00 commit 074918e

15 files changed

Lines changed: 178 additions & 95 deletions

File tree

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,14 @@ jobs:
357357
db: "mcr.microsoft.com/mssql/server:2017-latest"
358358
db_alias: 'MSSQL 2017'
359359
- php: '7.3'
360-
db: "mcr.microsoft.com/mssql/server:2019-latest"
360+
db: "mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04"
361361
db_alias: 'MSSQL 2019'
362362

363363
name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}
364364

365365
services:
366366
mssql:
367-
image: ${{ matrix.db != 'mcr.microsoft.com/mssql/server:2017-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2019-latest' && 'mcr.microsoft.com/mssql/server:2017-latest' || matrix.db }}
367+
image: ${{ matrix.db != 'mcr.microsoft.com/mssql/server:2017-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04' && 'mcr.microsoft.com/mssql/server:2017-latest' || matrix.db }}
368368
env:
369369
SA_PASSWORD: "Pssw0rd_12"
370370
ACCEPT_EULA: "y"
@@ -404,7 +404,7 @@ jobs:
404404
env:
405405
MATRIX_DB: ${{ matrix.db }}
406406
run: |
407-
if [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2017-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2019-latest' ]
407+
if [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2017-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04' ]
408408
then
409409
db='mssql'
410410
else

composer.json

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,34 @@
2424
],
2525
"require": {
2626
"php": ">=7.3",
27+
"ext-curl": "*",
28+
"ext-json": "*",
29+
"ext-mbstring": "*",
30+
"ext-openssl": "*",
2731
"composer/installers": "~1.0",
2832
"minishlink/web-push": "^7.0"
2933
},
3034
"require-dev": {
3135
"phing/phing": "~2.4"
3236
},
33-
"config": {
34-
"allow-plugins": {
35-
"composer/installers": true
36-
}
37-
},
38-
"extra": {
37+
"suggest": {
38+
"ext-gmp": "Optional but better for performance"
39+
},
40+
"config": {
41+
"allow-plugins": {
42+
"composer/installers": true
43+
}
44+
},
45+
"extra": {
3946
"display-name": "phpBB Browser Push Notifications",
4047
"soft-require": {
4148
"phpbb/phpbb": ">=3.3.12,<4.0.0@dev"
42-
},
43-
"version-check": {
44-
"host": "www.phpbb.com",
45-
"directory": "/customise/db/extension/webpushnotifications",
46-
"filename": "version_check",
47-
"ssl": true
49+
},
50+
"version-check": {
51+
"host": "www.phpbb.com",
52+
"directory": "/customise/db/extension/webpushnotifications",
53+
"filename": "version_check",
54+
"ssl": true
4855
}
4956
}
5057
}

config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ services:
1818
- '@phpbb.wpn.form_helper'
1919
- '@language'
2020
- '@template'
21+
- '@user'
2122
- '@notification_manager'
2223
- '%core.root_path%'
2324
tags:

controller/manifest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function handle(): JsonResponse
6161
}
6262

6363
$board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path();
64+
$board_url = generate_board_url();
6465

6566
$manifest = [
6667
'name' => $this->config['sitename'],
@@ -76,12 +77,12 @@ public function handle(): JsonResponse
7677
{
7778
$manifest['icons'] = [
7879
[
79-
'src' => $this->config['icons_path'] . '/' . $this->config['pwa_icon_small'],
80+
'src' => $board_url . '/' . $this->config['icons_path'] . '/' . $this->config['pwa_icon_small'],
8081
'sizes' => '192x192',
8182
'type' => 'image/png'
8283
],
8384
[
84-
'src' => $this->config['icons_path'] . '/' . $this->config['pwa_icon_large'],
85+
'src' => $board_url . '/' . $this->config['icons_path'] . '/' . $this->config['pwa_icon_large'],
8586
'sizes' => '512x512',
8687
'type' => 'image/png'
8788
]

event/listener.php

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010

1111
namespace phpbb\webpushnotifications\event;
1212

13-
/**
14-
* @ignore
15-
*/
16-
1713
use FastImageSize\FastImageSize;
1814
use phpbb\config\config;
1915
use phpbb\controller\helper as controller_helper;
2016
use phpbb\language\language;
2117
use phpbb\notification\manager;
2218
use phpbb\template\template;
19+
use phpbb\user;
2320
use phpbb\webpushnotifications\form\form_helper;
2421
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2522

@@ -46,6 +43,9 @@ class listener implements EventSubscriberInterface
4643
/* @var template */
4744
protected $template;
4845

46+
/** @var user */
47+
protected $user;
48+
4949
/* @var manager */
5050
protected $phpbb_notifications;
5151

@@ -61,27 +61,29 @@ class listener implements EventSubscriberInterface
6161
* @param form_helper $form_helper Form helper object
6262
* @param language $language Language object
6363
* @param template $template Template object
64+
* @param user $user
6465
* @param manager $phpbb_notifications Notifications manager object
6566
* @param $root_path
6667
*/
67-
public function __construct(config $config, controller_helper $controller_helper, FastImageSize $imagesize, form_helper $form_helper, language $language, template $template, manager $phpbb_notifications, $root_path)
68+
public function __construct(config $config, controller_helper $controller_helper, FastImageSize $imagesize, form_helper $form_helper, language $language, template $template, user $user, manager $phpbb_notifications, $root_path)
6869
{
6970
$this->config = $config;
7071
$this->controller_helper = $controller_helper;
7172
$this->imagesize = $imagesize;
7273
$this->form_helper = $form_helper;
7374
$this->language = $language;
7475
$this->template = $template;
76+
$this->user = $user;
7577
$this->phpbb_notifications = $phpbb_notifications;
7678
$this->root_path = $root_path;
7779
}
7880

7981
public static function getSubscribedEvents()
8082
{
8183
return [
84+
'core.page_header_after' => [['load_template_data'], ['pwa_manifest']],
8285
'core.ucp_display_module_before' => 'load_language',
8386
'core.acp_main_notice' => 'compatibility_notice',
84-
'core.page_header_after' => 'load_template_data',
8587
'core.acp_board_config_edit_add' => 'acp_pwa_options',
8688
'core.validate_config_variable' => 'validate_pwa_options',
8789
];
@@ -92,23 +94,30 @@ public static function getSubscribedEvents()
9294
*/
9395
public function load_template_data()
9496
{
97+
if (!$this->can_use_notifications())
98+
{
99+
return;
100+
}
101+
95102
$methods = $this->phpbb_notifications->get_subscription_methods();
96103
$webpush_method = $methods['notification.method.phpbb.wpn.webpush'] ?? null;
97104

98-
if ($webpush_method !== null)
105+
if ($webpush_method === null)
99106
{
100-
if (!$this->language->is_set('NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH'))
101-
{
102-
$this->language->add_lang('webpushnotifications_module_ucp', 'phpbb/webpushnotifications');
103-
}
107+
return;
108+
}
104109

105-
$template_ary = $webpush_method['method']->get_ucp_template_data($this->controller_helper, $this->form_helper);
106-
$this->template->assign_vars($template_ary);
110+
if (!$this->language->is_set('NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH'))
111+
{
112+
$this->load_language();
107113
}
114+
115+
$template_ary = $webpush_method['method']->get_ucp_template_data($this->controller_helper, $this->form_helper);
116+
$this->template->assign_vars($template_ary);
108117
}
109118

110119
/**
111-
* Load language file
120+
* Load language file (this is required for the UCP)
112121
*/
113122
public function load_language()
114123
{
@@ -123,6 +132,19 @@ public function compatibility_notice()
123132
$this->template->assign_var('S_WPN_COMPATIBILITY_NOTICE', phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '>='));
124133
}
125134

135+
/**
136+
* Assign template data for web manifest support
137+
*
138+
* @return void
139+
*/
140+
public function pwa_manifest()
141+
{
142+
$this->template->assign_vars([
143+
'U_MANIFEST_URL' => $this->controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
144+
'U_TOUCH_ICON' => $this->config['pwa_icon_small'],
145+
]);
146+
}
147+
126148
/**
127149
* Progressive web app options for the ACP
128150
*
@@ -217,4 +239,16 @@ protected function add_error($event, $error_key, $param = null)
217239
$error[] = $this->language->lang($error_key, $param);
218240
$event['error'] = $error;
219241
}
242+
243+
/**
244+
* Can notifications be used by the user?
245+
*
246+
* @return bool
247+
*/
248+
protected function can_use_notifications()
249+
{
250+
return $this->config['wpn_webpush_enable']
251+
&& ANONYMOUS !== $this->user->id()
252+
&& USER_IGNORE !== (int) $this->user->data['user_type'];
253+
}
220254
}

ext.php

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,35 @@
1515
*/
1616
class ext extends \phpbb\extension\base
1717
{
18+
/**
19+
* Require phpBB 3.3.12 due to new template and core events.
20+
*/
21+
public const PHPBB_MIN_VERSION = '3.3.12';
22+
23+
/**
24+
* Should not be installed in phpBB 4 because it already has push notifications.
25+
*/
26+
public const PHPBB_MAX_VERSION = '4.0.0-dev';
27+
28+
/**
29+
* Require PHP 7.3 due to 3rd party libraries included.
30+
*/
31+
public const PHP_MIN_VERSION = '7.3';
32+
1833
/**
1934
* @var array An array of installation error messages
2035
*/
2136
protected $errors = [];
2237

2338
/**
2439
* {@inheritdoc}
25-
*
26-
* Requires phpBB 3.3.12 due to new template and core events.
27-
* Should not be installed in phpBB 4.0.0-a1 because it already has push notifications.
28-
* Requires PHP 7.3 due to 3rd party libraries included.
2940
*/
3041
public function is_enableable()
3142
{
32-
return $this->check_phpbb_version()->check_php_version()->result();
43+
return $this->check_phpbb_version()
44+
->check_php_version()
45+
->check_php_requirements()
46+
->result();
3347
}
3448

3549
/**
@@ -39,12 +53,12 @@ public function is_enableable()
3953
*/
4054
protected function check_phpbb_version()
4155
{
42-
if (phpbb_version_compare(PHPBB_VERSION, '3.3.12', '<'))
56+
if (phpbb_version_compare(PHPBB_VERSION, self::PHPBB_MIN_VERSION, '<'))
4357
{
4458
$this->errors[] = 'PHPBB_VERSION_MIN_ERROR';
4559
}
4660

47-
if (phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '>='))
61+
if (phpbb_version_compare(PHPBB_VERSION, self::PHPBB_MAX_VERSION, '>='))
4862
{
4963
$this->errors[] = 'PHPBB_VERSION_MAX_ERROR';
5064
}
@@ -67,6 +81,24 @@ protected function check_php_version()
6781
return $this;
6882
}
6983

84+
/**
85+
* Check the installed PHP extensions meet this extension's requirements.
86+
*
87+
* @return \phpbb\webpushnotifications\ext
88+
*/
89+
protected function check_php_requirements()
90+
{
91+
foreach (['curl', 'mbstring', 'openssl'] as $extension)
92+
{
93+
if (!extension_loaded($extension))
94+
{
95+
$this->errors[] = ['PHP_EXT_MISSING', $extension];
96+
}
97+
}
98+
99+
return $this;
100+
}
101+
70102
/**
71103
* Return the is_enableable result. Either true, or the best enable failed
72104
* response for the current phpBB environment: array of error messages
@@ -85,7 +117,9 @@ protected function result()
85117
{
86118
$language = $this->container->get('language');
87119
$language->add_lang('install', 'phpbb/webpushnotifications');
88-
return array_map([$language, 'lang'], $this->errors);
120+
return array_map(static function($error) use ($language) {
121+
return call_user_func_array([$language, 'lang'], (array) $error);
122+
}, $this->errors);
89123
}
90124

91125
return false;

language/en/install.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
//
3939

4040
$lang = array_merge($lang, [
41-
'PHPBB_VERSION_MAX_ERROR' => 'This extension can not be installed on your board. You are using phpBB 4, which already contains the features in this extension.',
42-
'PHPBB_VERSION_MIN_ERROR' => 'This extension is not compatible with your board. You must be using phpBB 3.3.12 or newer.',
43-
'PHP_VERSION_ERROR' => 'This extension is not compatible with your server. Your server must be running PHP 7.3 or newer.',
41+
'PHPBB_VERSION_MAX_ERROR' => 'This extension can not be installed on this board. This is a phpBB 4 board, which already contains the features in this extension.',
42+
'PHPBB_VERSION_MIN_ERROR' => 'phpBB ' . \phpbb\webpushnotifications\ext::PHPBB_MIN_VERSION . ' or newer is required.',
43+
'PHP_VERSION_ERROR' => 'PHP ' . \phpbb\webpushnotifications\ext::PHP_MIN_VERSION . ' or newer is required.',
44+
'PHP_EXT_MISSING' => 'The “%s” extension for PHP must be installed on this server.',
4445
]);

language/ru/install.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
$lang = array_merge($lang, [
4141
'PHPBB_VERSION_MAX_ERROR' => 'Данное расширение несовместимо с установленной версией конференции. Вы используете версию phpBB 4, которая уже содержит соответствующие функции.',
42-
'PHPBB_VERSION_MIN_ERROR' => 'Данное расширение несовместимо с установленной версией конференции. Необходима версия phpBB 3.3.12 или выше.',
43-
'PHP_VERSION_ERROR' => 'Данное расширение несовместимо с установленной на сервере версией PHP. Необходима версия PHP 7.3 или выше.',
42+
'PHPBB_VERSION_MIN_ERROR' => 'Данное расширение несовместимо с установленной версией конференции. Необходима версия phpBB ' . \phpbb\webpushnotifications\ext::PHPBB_MIN_VERSION . ' или выше.',
43+
'PHP_VERSION_ERROR' => 'Данное расширение несовместимо с установленной на сервере версией PHP. Необходима версия PHP ' . \phpbb\webpushnotifications\ext::PHP_MIN_VERSION . ' или выше.',
44+
'PHP_EXT_MISSING' => 'На этом сервере должно быть установлено расширение «%s» для PHP.',
4445
]);

notification/method/webpush.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,13 @@ public function get_ucp_template_data(helper $controller_helper, form_helper $fo
378378
}
379379

380380
return [
381-
'NOTIFICATIONS_WEBPUSH_ENABLE' => $this->allowed_user() && ($this->config['wpn_webpush_dropdown_subscribe'] || stripos($this->user->page['page'], 'notification_options')),
381+
'NOTIFICATIONS_WEBPUSH_ENABLE' => ($this->config['load_notifications'] && $this->config['allow_board_notifications'] && $this->config['wpn_webpush_dropdown_subscribe']) || stripos($this->user->page['page'], 'notification_options'),
382382
'U_WEBPUSH_SUBSCRIBE' => $controller_helper->route('phpbb_webpushnotifications_ucp_push_subscribe_controller'),
383383
'U_WEBPUSH_UNSUBSCRIBE' => $controller_helper->route('phpbb_webpushnotifications_ucp_push_unsubscribe_controller'),
384384
'VAPID_PUBLIC_KEY' => $this->config['wpn_webpush_vapid_public'],
385385
'U_WEBPUSH_WORKER_URL' => $controller_helper->route('phpbb_webpushnotifications_ucp_push_worker_controller'),
386386
'SUBSCRIPTIONS' => $subscriptions,
387387
'WEBPUSH_FORM_TOKENS' => $form_helper->get_form_tokens(\phpbb\webpushnotifications\ucp\controller\webpush::FORM_TOKEN_UCP),
388-
'U_MANIFEST_URL' => $controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
389-
'U_TOUCH_ICON' => $this->config['pwa_icon_small'],
390388
];
391389
}
392390

@@ -552,17 +550,4 @@ protected function load_recipients_data(): array
552550

553551
return $notify_users;
554552
}
555-
556-
/**
557-
* User is allowed to use web push notifications
558-
*
559-
* @return bool
560-
*/
561-
protected function allowed_user()
562-
{
563-
return $this->user->id() !== ANONYMOUS
564-
&& !$this->user->data['is_bot']
565-
&& (int) $this->user->data['user_type'] !== USER_IGNORE
566-
&& (int) $this->user->data['user_type'] !== USER_INACTIVE;
567-
}
568553
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<meta name="apple-mobile-web-app-capable" content="yes">
2+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
3+
<meta name="apple-mobile-web-app-title" content="{{ SITENAME }}">
4+
<link rel="manifest" href="{{ U_MANIFEST_URL }}">
5+
{% if U_TOUCH_ICON %}<link rel="apple-touch-icon" href="{{ T_ICONS_PATH ~ U_TOUCH_ICON }}">{% endif %}
6+
17
{% if NOTIFICATIONS_WEBPUSH_ENABLE %}
28
{% include '@phpbb_webpushnotifications/ucp_notifications_webpush.html' %}
39
{% endif %}

0 commit comments

Comments
 (0)