Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ services:
- '@log'
- '@user_loader'
- '@user'
- '@path_helper'
- '%core.root_path%'
- '%core.php_ext%'
- '%tables.phpbb.wpn.notification_push%'
Expand Down Expand Up @@ -62,5 +61,4 @@ services:
class: phpbb\webpushnotifications\controller\manifest
arguments:
- '@config'
- '@path_helper'
- '@user'
23 changes: 11 additions & 12 deletions controller/manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace phpbb\webpushnotifications\controller;

use phpbb\config\config;
use phpbb\path_helper;
use phpbb\user;
use phpbb\webpushnotifications\ext;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -21,23 +20,18 @@ class manifest
/** @var config */
protected $config;

/** @var path_helper */
protected $path_helper;

/** @var user */
protected $user;

/**
* Constructor for webpush controller
*
* @param config $config
* @param path_helper $path_helper
* @param user $user
*/
public function __construct(config $config, path_helper $path_helper, user $user)
public function __construct(config $config, user $user)
{
$this->config = $config;
$this->path_helper = $path_helper;
$this->user = $user;
}

Expand All @@ -48,20 +42,25 @@ public function __construct(config $config, path_helper $path_helper, user $user
*/
public function handle(): JsonResponse
{
$board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path();
// Get the board URL and extract the path component
$board_url = generate_board_url();
$board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : (parse_url($board_url)['path'] ?? '');

// Ensure path ends with '/' for PWA scope
$scope = rtrim($board_path, '/\\') . '/';
$start_url = $scope;

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

$manifest = [
'name' => $sitename,
'short_name' => $pwa_short_name ?: utf8_substr($sitename, 0, 12),
'short_name' => $sitename_short ?: utf8_substr($sitename, 0, 12),
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => $board_path,
'scope' => $board_path,
'start_url' => $start_url,
'scope' => $scope,
];

if (!empty($this->config['pwa_icon_small']) && !empty($this->config['pwa_icon_large']))
Expand Down
8 changes: 1 addition & 7 deletions notification/method/webpush.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use phpbb\log\log_interface;
use phpbb\notification\method\base;
use phpbb\notification\type\type_interface;
use phpbb\path_helper;
use phpbb\user;
use phpbb\user_loader;
use phpbb\webpushnotifications\form\form_helper;
Expand All @@ -44,9 +43,6 @@ class webpush extends base implements extended_method_interface
/** @var user */
protected $user;

/** @var path_helper */
protected $path_helper;

/** @var string */
protected $phpbb_root_path;

Expand All @@ -73,21 +69,19 @@ class webpush extends base implements extended_method_interface
* @param log_interface $log
* @param user_loader $user_loader
* @param user $user
* @param path_helper $path_helper
* @param string $phpbb_root_path
* @param string $php_ext
* @param string $notification_webpush_table
* @param string $push_subscriptions_table
*/
public function __construct(config $config, driver_interface $db, log_interface $log, user_loader $user_loader, user $user, path_helper $path_helper,
public function __construct(config $config, driver_interface $db, log_interface $log, user_loader $user_loader, user $user,
string $phpbb_root_path, string $php_ext, string $notification_webpush_table, string $push_subscriptions_table)
{
$this->config = $config;
$this->db = $db;
$this->log = $log;
$this->user_loader = $user_loader;
$this->user = $user;
$this->path_helper = $path_helper;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->notification_webpush_table = $notification_webpush_table;
Expand Down
4 changes: 4 additions & 0 deletions styles/all/template/event/overall_header_head_append.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<!-- Android / Chrome PWA support -->
<meta name="mobile-web-app-capable" content="yes">
<!-- iOS PWA support -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="{{ SHORT_SITE_NAME }}">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

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

Expand Down
39 changes: 15 additions & 24 deletions tests/controller/controller_manifest_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
class controller_manifest_test extends \phpbb_test_case
{
protected $config;
protected $path_helper;
protected $user;
protected $manifest;

protected function setUp(): void
{
global $phpbb_root_path, $phpEx;
global $config, $user, $request, $symfony_request;
global $config, $user, $phpbb_root_path, $phpEx;

parent::setUp();

Expand All @@ -38,21 +36,14 @@ protected function setUp(): void
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$language = new \phpbb\language\language($lang_loader);
$user = $this->user = new \phpbb\user($language, '\phpbb\datetime');
$symfony_request = $this->createMock(\phpbb\symfony_request::class);
$request = $this->request = $this->createMock(\phpbb\request\request_interface::class);
$this->path_helper = new \phpbb\path_helper($symfony_request, new \phpbb\filesystem\filesystem(), $this->request, $phpbb_root_path, $phpEx);

$this->manifest = new \phpbb\webpushnotifications\controller\manifest(
$this->config,
$this->path_helper,
$this->user
);

$this->manifest = new \phpbb\webpushnotifications\controller\manifest($this->config, $this->user);
}

public function manifest_data()
{
return [
'using web root path' => [
'using board url root path' => [
[
'force_server_vars' => false,
'script_path' => '',
Expand All @@ -64,14 +55,14 @@ public function manifest_data()
'short_name' => 'yourdomain',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => './phpBB/',
'scope' => './phpBB/',
'start_url' => '/',
'scope' => '/',
],
],
'using script path' => [
[
'force_server_vars' => true,
'script_path' => '/',
'script_path' => '/foo/',
'sitename' => 'yourdomain.com',
'pwa_short_name' => 'yourdomain',
],
Expand All @@ -80,8 +71,8 @@ public function manifest_data()
'short_name' => 'yourdomain',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => '/',
'scope' => '/',
'start_url' => '/foo/',
'scope' => '/foo/',
],
],
'with shortname' => [
Expand All @@ -94,8 +85,8 @@ public function manifest_data()
'short_name' => 'testdomain',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => './phpBB/',
'scope' => './phpBB/',
'start_url' => '/',
'scope' => '/',
],
],
'without shortname' => [
Expand All @@ -108,8 +99,8 @@ public function manifest_data()
'short_name' => 'testdomain.c',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => './phpBB/',
'scope' => './phpBB/',
'start_url' => '/',
'scope' => '/',
],
],
'with icons' => [
Expand All @@ -124,8 +115,8 @@ public function manifest_data()
'short_name' => '',
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => './phpBB/',
'scope' => './phpBB/',
'start_url' => '/',
'scope' => '/',
'icons' => [
[
'src' => 'http://images/site_icons/foo_sm.png',
Expand Down
6 changes: 0 additions & 6 deletions tests/event/listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ protected function setUp(): void
$this->user
);

$path_helper = $this->getMockBuilder('\phpbb\path_helper')
->disableOriginalConstructor()
->setMethods(array())
->getMock();

$this->notifications = $this->getMockBuilder('\phpbb\notification\manager')
->disableOriginalConstructor()
->getMock();
Expand All @@ -113,7 +108,6 @@ protected function setUp(): void
new \phpbb\log\dummy(),
$user_loader,
$this->user,
$path_helper,
$phpbb_root_path,
$phpEx,
'phpbb_wpn_notification_push',
Expand Down
15 changes: 0 additions & 15 deletions tests/notification/notification_method_webpush_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,6 @@ protected function setUp(): void
$phpEx
);

$request = new \phpbb_mock_request;
$symfony_request = new \phpbb\symfony_request(
$request
);
$filesystem = new \phpbb\filesystem\filesystem();
$phpbb_path_helper = new \phpbb\path_helper(
$symfony_request,
$filesystem,
$request,
$phpbb_root_path,
$phpEx
);

$log_table = 'phpbb_log';
$this->log = new \phpbb\log\log($this->db, $user, $auth, $this->phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, $log_table);

Expand All @@ -158,7 +145,6 @@ protected function setUp(): void
$phpbb_container->set('log', $this->log);
$phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils());
$phpbb_container->set('dispatcher', $this->phpbb_dispatcher);
$phpbb_container->set('path_helper', $phpbb_path_helper);
$phpbb_container->setParameter('core.root_path', $phpbb_root_path);
$phpbb_container->setParameter('core.php_ext', $phpEx);
$phpbb_container->setParameter('tables.notifications', 'phpbb_notifications');
Expand All @@ -174,7 +160,6 @@ protected function setUp(): void
$phpbb_container->get('log'),
$phpbb_container->get('user_loader'),
$phpbb_container->get('user'),
$phpbb_container->get('path_helper'),
$phpbb_root_path,
$phpEx,
$phpbb_container->getParameter('tables.phpbb.wpn.notification_push'),
Expand Down