Skip to content

Commit 2a16e93

Browse files
authored
Merge pull request #116 from iMattPro/updates
Fix manifest scope and start url paths
2 parents b06c7c7 + 826d52a commit 2a16e93

File tree

7 files changed

+31
-66
lines changed

7 files changed

+31
-66
lines changed

config/services.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ services:
3333
- '@log'
3434
- '@user_loader'
3535
- '@user'
36-
- '@path_helper'
3736
- '%core.root_path%'
3837
- '%core.php_ext%'
3938
- '%tables.phpbb.wpn.notification_push%'
@@ -62,5 +61,4 @@ services:
6261
class: phpbb\webpushnotifications\controller\manifest
6362
arguments:
6463
- '@config'
65-
- '@path_helper'
6664
- '@user'

controller/manifest.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
namespace phpbb\webpushnotifications\controller;
1212

1313
use phpbb\config\config;
14-
use phpbb\path_helper;
1514
use phpbb\user;
1615
use phpbb\webpushnotifications\ext;
1716
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -21,23 +20,18 @@ class manifest
2120
/** @var config */
2221
protected $config;
2322

24-
/** @var path_helper */
25-
protected $path_helper;
26-
2723
/** @var user */
2824
protected $user;
2925

3026
/**
3127
* Constructor for webpush controller
3228
*
3329
* @param config $config
34-
* @param path_helper $path_helper
3530
* @param user $user
3631
*/
37-
public function __construct(config $config, path_helper $path_helper, user $user)
32+
public function __construct(config $config, user $user)
3833
{
3934
$this->config = $config;
40-
$this->path_helper = $path_helper;
4135
$this->user = $user;
4236
}
4337

@@ -48,20 +42,25 @@ public function __construct(config $config, path_helper $path_helper, user $user
4842
*/
4943
public function handle(): JsonResponse
5044
{
51-
$board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path();
45+
// Get the board URL and extract the path component
5246
$board_url = generate_board_url();
47+
$board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : (parse_url($board_url)['path'] ?? '');
48+
49+
// Ensure path ends with '/' for PWA scope
50+
$scope = rtrim($board_path, '/\\') . '/';
51+
$start_url = $scope;
5352

5453
// Emoji fixer-uppers
5554
$sitename = ext::decode_entities($this->config['sitename'], ENT_QUOTES);
56-
$pwa_short_name = ext::decode_entities($this->config['pwa_short_name'], ENT_QUOTES);
55+
$sitename_short = ext::decode_entities($this->config['pwa_short_name'], ENT_QUOTES);
5756

5857
$manifest = [
5958
'name' => $sitename,
60-
'short_name' => $pwa_short_name ?: utf8_substr($sitename, 0, 12),
59+
'short_name' => $sitename_short ?: utf8_substr($sitename, 0, 12),
6160
'display' => 'standalone',
6261
'orientation' => 'portrait',
63-
'start_url' => $board_path,
64-
'scope' => $board_path,
62+
'start_url' => $start_url,
63+
'scope' => $scope,
6564
];
6665

6766
if (!empty($this->config['pwa_icon_small']) && !empty($this->config['pwa_icon_large']))

notification/method/webpush.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use phpbb\log\log_interface;
1818
use phpbb\notification\method\base;
1919
use phpbb\notification\type\type_interface;
20-
use phpbb\path_helper;
2120
use phpbb\user;
2221
use phpbb\user_loader;
2322
use phpbb\webpushnotifications\form\form_helper;
@@ -44,9 +43,6 @@ class webpush extends base implements extended_method_interface
4443
/** @var user */
4544
protected $user;
4645

47-
/** @var path_helper */
48-
protected $path_helper;
49-
5046
/** @var string */
5147
protected $phpbb_root_path;
5248

@@ -73,21 +69,19 @@ class webpush extends base implements extended_method_interface
7369
* @param log_interface $log
7470
* @param user_loader $user_loader
7571
* @param user $user
76-
* @param path_helper $path_helper
7772
* @param string $phpbb_root_path
7873
* @param string $php_ext
7974
* @param string $notification_webpush_table
8075
* @param string $push_subscriptions_table
8176
*/
82-
public function __construct(config $config, driver_interface $db, log_interface $log, user_loader $user_loader, user $user, path_helper $path_helper,
77+
public function __construct(config $config, driver_interface $db, log_interface $log, user_loader $user_loader, user $user,
8378
string $phpbb_root_path, string $php_ext, string $notification_webpush_table, string $push_subscriptions_table)
8479
{
8580
$this->config = $config;
8681
$this->db = $db;
8782
$this->log = $log;
8883
$this->user_loader = $user_loader;
8984
$this->user = $user;
90-
$this->path_helper = $path_helper;
9185
$this->phpbb_root_path = $phpbb_root_path;
9286
$this->php_ext = $php_ext;
9387
$this->notification_webpush_table = $notification_webpush_table;

styles/all/template/event/overall_header_head_append.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
<!-- Android / Chrome PWA support -->
2+
<meta name="mobile-web-app-capable" content="yes">
3+
<!-- iOS PWA support -->
14
<meta name="apple-mobile-web-app-capable" content="yes">
25
<meta name="apple-mobile-web-app-title" content="{{ SHORT_SITE_NAME }}">
6+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
37

48
<link rel="manifest" href="{{ U_MANIFEST_URL }}" crossorigin="use-credentials">
59

tests/controller/controller_manifest_test.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
class controller_manifest_test extends \phpbb_test_case
1616
{
1717
protected $config;
18-
protected $path_helper;
1918
protected $user;
2019
protected $manifest;
2120

2221
protected function setUp(): void
2322
{
24-
global $phpbb_root_path, $phpEx;
25-
global $config, $user, $request, $symfony_request;
23+
global $config, $user, $phpbb_root_path, $phpEx;
2624

2725
parent::setUp();
2826

@@ -38,21 +36,14 @@ protected function setUp(): void
3836
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
3937
$language = new \phpbb\language\language($lang_loader);
4038
$user = $this->user = new \phpbb\user($language, '\phpbb\datetime');
41-
$symfony_request = $this->createMock(\phpbb\symfony_request::class);
42-
$request = $this->request = $this->createMock(\phpbb\request\request_interface::class);
43-
$this->path_helper = new \phpbb\path_helper($symfony_request, new \phpbb\filesystem\filesystem(), $this->request, $phpbb_root_path, $phpEx);
44-
45-
$this->manifest = new \phpbb\webpushnotifications\controller\manifest(
46-
$this->config,
47-
$this->path_helper,
48-
$this->user
49-
);
39+
40+
$this->manifest = new \phpbb\webpushnotifications\controller\manifest($this->config, $this->user);
5041
}
5142

5243
public function manifest_data()
5344
{
5445
return [
55-
'using web root path' => [
46+
'using board url root path' => [
5647
[
5748
'force_server_vars' => false,
5849
'script_path' => '',
@@ -64,14 +55,14 @@ public function manifest_data()
6455
'short_name' => 'yourdomain',
6556
'display' => 'standalone',
6657
'orientation' => 'portrait',
67-
'start_url' => './phpBB/',
68-
'scope' => './phpBB/',
58+
'start_url' => '/',
59+
'scope' => '/',
6960
],
7061
],
7162
'using script path' => [
7263
[
7364
'force_server_vars' => true,
74-
'script_path' => '/',
65+
'script_path' => '/foo/',
7566
'sitename' => 'yourdomain.com',
7667
'pwa_short_name' => 'yourdomain',
7768
],
@@ -80,8 +71,8 @@ public function manifest_data()
8071
'short_name' => 'yourdomain',
8172
'display' => 'standalone',
8273
'orientation' => 'portrait',
83-
'start_url' => '/',
84-
'scope' => '/',
74+
'start_url' => '/foo/',
75+
'scope' => '/foo/',
8576
],
8677
],
8778
'with shortname' => [
@@ -94,8 +85,8 @@ public function manifest_data()
9485
'short_name' => 'testdomain',
9586
'display' => 'standalone',
9687
'orientation' => 'portrait',
97-
'start_url' => './phpBB/',
98-
'scope' => './phpBB/',
88+
'start_url' => '/',
89+
'scope' => '/',
9990
],
10091
],
10192
'without shortname' => [
@@ -108,8 +99,8 @@ public function manifest_data()
10899
'short_name' => 'testdomain.c',
109100
'display' => 'standalone',
110101
'orientation' => 'portrait',
111-
'start_url' => './phpBB/',
112-
'scope' => './phpBB/',
102+
'start_url' => '/',
103+
'scope' => '/',
113104
],
114105
],
115106
'with icons' => [
@@ -124,8 +115,8 @@ public function manifest_data()
124115
'short_name' => '',
125116
'display' => 'standalone',
126117
'orientation' => 'portrait',
127-
'start_url' => './phpBB/',
128-
'scope' => './phpBB/',
118+
'start_url' => '/',
119+
'scope' => '/',
129120
'icons' => [
130121
[
131122
'src' => 'http://images/site_icons/foo_sm.png',

tests/event/listener_test.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ protected function setUp(): void
9595
$this->user
9696
);
9797

98-
$path_helper = $this->getMockBuilder('\phpbb\path_helper')
99-
->disableOriginalConstructor()
100-
->setMethods(array())
101-
->getMock();
102-
10398
$this->notifications = $this->getMockBuilder('\phpbb\notification\manager')
10499
->disableOriginalConstructor()
105100
->getMock();
@@ -113,7 +108,6 @@ protected function setUp(): void
113108
new \phpbb\log\dummy(),
114109
$user_loader,
115110
$this->user,
116-
$path_helper,
117111
$phpbb_root_path,
118112
$phpEx,
119113
'phpbb_wpn_notification_push',

tests/notification/notification_method_webpush_test.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,6 @@ protected function setUp(): void
128128
$phpEx
129129
);
130130

131-
$request = new \phpbb_mock_request;
132-
$symfony_request = new \phpbb\symfony_request(
133-
$request
134-
);
135-
$filesystem = new \phpbb\filesystem\filesystem();
136-
$phpbb_path_helper = new \phpbb\path_helper(
137-
$symfony_request,
138-
$filesystem,
139-
$request,
140-
$phpbb_root_path,
141-
$phpEx
142-
);
143-
144131
$log_table = 'phpbb_log';
145132
$this->log = new \phpbb\log\log($this->db, $user, $auth, $this->phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, $log_table);
146133

@@ -158,7 +145,6 @@ protected function setUp(): void
158145
$phpbb_container->set('log', $this->log);
159146
$phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils());
160147
$phpbb_container->set('dispatcher', $this->phpbb_dispatcher);
161-
$phpbb_container->set('path_helper', $phpbb_path_helper);
162148
$phpbb_container->setParameter('core.root_path', $phpbb_root_path);
163149
$phpbb_container->setParameter('core.php_ext', $phpEx);
164150
$phpbb_container->setParameter('tables.notifications', 'phpbb_notifications');
@@ -174,7 +160,6 @@ protected function setUp(): void
174160
$phpbb_container->get('log'),
175161
$phpbb_container->get('user_loader'),
176162
$phpbb_container->get('user'),
177-
$phpbb_container->get('path_helper'),
178163
$phpbb_root_path,
179164
$phpEx,
180165
$phpbb_container->getParameter('tables.phpbb.wpn.notification_push'),

0 commit comments

Comments
 (0)