Skip to content

Commit 2655053

Browse files
committed
Add settings for progressive web app options
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent adad5af commit 2655053

6 files changed

Lines changed: 122 additions & 6 deletions

File tree

controller/manifest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,24 @@ public function handle(): JsonResponse
6464

6565
$manifest = [
6666
'name' => $this->config['sitename'],
67-
'short_name' => substr($this->config['sitename'], 0, 12), // TODO need an ACP option for short name
67+
'short_name' => $this->config['pwa_short_name'] ?? substr($this->config['sitename'], 0, 12),
6868
'display' => 'standalone',
6969
'orientation' => 'portrait',
7070
'dir' => $this->language->lang('DIRECTION'),
7171
'start_url' => $board_url,
7272
'scope' => $board_url,
7373
];
7474

75-
// TODO add support for icons
76-
if (isset($this->config['wpn_app_icon_small'], $this->config['wpn_app_icon_large']))
75+
if (!empty($this->config['pwa_icon_small']) && !empty($this->config['pwa_icon_large']))
7776
{
7877
$manifest['icons'] = [
7978
[
80-
'src' => $this->config['icons_path'] . $this->config['wpn_app_icon_small'],
79+
'src' => $this->config['icons_path'] . '/' . $this->config['pwa_icon_small'],
8180
'sizes' => '192x192',
8281
'type' => 'image/png'
8382
],
8483
[
85-
'src' => $this->config['icons_path'] . $this->config['wpn_app_icon_large'],
84+
'src' => $this->config['icons_path'] . '/' . $this->config['pwa_icon_large'],
8685
'sizes' => '512x512',
8786
'type' => 'image/png'
8887
]

event/listener.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static function getSubscribedEvents()
3131
'core.ucp_display_module_before' => 'load_language',
3232
'core.acp_main_notice' => 'compatibility_notice',
3333
'core.page_header_after' => 'load_template_data',
34+
'core.acp_board_config_edit_add' => 'acp_pwa_options',
3435
];
3536
}
3637

@@ -102,4 +103,27 @@ public function compatibility_notice()
102103
{
103104
$this->template->assign_var('S_WPN_COMPATIBILITY_NOTICE', phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '>='));
104105
}
106+
107+
/**
108+
* Progressive web app options for the ACP
109+
*
110+
* @param \phpbb\event\data $event
111+
* @return void
112+
*/
113+
public function acp_pwa_options($event)
114+
{
115+
if ($event['mode'] === 'settings' && array_key_exists('legend4', $event['display_vars']['vars']))
116+
{
117+
$this->language->add_lang('webpushnotifications_common_acp', 'phpbb/webpushnotifications');
118+
119+
$my_config_vars = [
120+
'legend_pwa_settings'=> 'PWA_SETTINGS',
121+
'pwa_short_name' => ['lang' => 'PWA_SHORT_NAME', 'validate' => 'string', 'type' => 'text:40:12', 'explain' => true],
122+
'pwa_icon_small' => ['lang' => 'PWA_ICON_SMALL', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true],
123+
'pwa_icon_large' => ['lang' => 'PWA_ICON_LARGE', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true],
124+
];
125+
126+
$event->update_subarray('display_vars', 'vars', phpbb_insert_config_array($event['display_vars']['vars'], $my_config_vars, ['before' => 'legend4']));
127+
}
128+
}
105129
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
*
4+
* phpBB Browser Push Notifications. An extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2024, phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
/**
12+
* DO NOT CHANGE
13+
*/
14+
if (!defined('IN_PHPBB'))
15+
{
16+
exit;
17+
}
18+
19+
if (empty($lang) || !is_array($lang))
20+
{
21+
$lang = [];
22+
}
23+
24+
// DEVELOPERS PLEASE NOTE
25+
//
26+
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
27+
//
28+
// Placeholders can now contain order information, e.g. instead of
29+
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
30+
// translators to re-order the output of data while ensuring it remains correct
31+
//
32+
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
33+
// equally where a string contains only two placeholders which are used to wrap text
34+
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
35+
//
36+
// Some characters you may want to copy&paste:
37+
// ’ » “ ” …
38+
//
39+
40+
$lang = array_merge($lang, [
41+
'PWA_SETTINGS' => 'Web application options',
42+
'PWA_SHORT_NAME' => 'Short site name',
43+
'PWA_SHORT_NAME_EXPLAIN' => 'Your site name in 12 characters or less, which may be used as a label for an icon on a mobile device’s home screen.',
44+
'PWA_ICON_SMALL' => 'Small mobile device icon',
45+
'PWA_ICON_SMALL_EXPLAIN' => 'File name of a 192x192 PNG image. This file must be uploaded to your <samp>icons</samp> directory, i.e.: <samp>./images/icons</samp>',
46+
'PWA_ICON_LARGE' => 'Large mobile device icon',
47+
'PWA_ICON_LARGE_EXPLAIN' => 'File name of a 512x512 PNG image. This file must be uploaded to your <samp>icons</samp> directory, i.e.: <samp>./images/icons</samp>',
48+
]);

migrations/add_acp_pwa_configs.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
*
4+
* phpBB Browser Push Notifications. An extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2024, phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\webpushnotifications\migrations;
12+
13+
use phpbb\db\migration\migration;
14+
15+
class add_acp_pwa_configs extends migration
16+
{
17+
public function effectively_installed(): bool
18+
{
19+
return $this->config->offsetExists('pwa_short_name');
20+
}
21+
22+
public static function depends_on()
23+
{
24+
return ['\phpbb\webpushnotifications\migrations\add_webpush'];
25+
}
26+
27+
public function update_data(): array
28+
{
29+
return [
30+
['config.add', ['pwa_short_name', '']],
31+
['config.add', ['pwa_icon_small', '']],
32+
['config.add', ['pwa_icon_large', '']],
33+
];
34+
}
35+
36+
public function revert_data(): array
37+
{
38+
return [
39+
['config.remove', ['pwa_short_name']],
40+
['config.remove', ['pwa_icon_small']],
41+
['config.remove', ['pwa_icon_large']],
42+
];
43+
}
44+
}

notification/method/webpush.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public function get_ucp_template_data(helper $controller_helper, form_helper $fo
387387
'SUBSCRIPTIONS' => $subscriptions,
388388
'WEBPUSH_FORM_TOKENS' => $form_helper->get_form_tokens(\phpbb\webpushnotifications\ucp\controller\webpush::FORM_TOKEN_UCP),
389389
'U_MANIFEST_URL' => $controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
390-
'U_TOUCH_ICON' => $this->config['wpn_app_icon_small'] ?? '',
390+
'U_TOUCH_ICON' => $this->config['pwa_icon_small'],
391391
];
392392
}
393393

tests/event/listener_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public function test_getSubscribedEvents()
126126
'core.ucp_display_module_before',
127127
'core.acp_main_notice',
128128
'core.page_header_after',
129+
'core.acp_board_config_edit_add',
129130
], array_keys(\phpbb\webpushnotifications\event\listener::getSubscribedEvents()));
130131
}
131132

0 commit comments

Comments
 (0)