diff --git a/config/routing.yml b/config/routing.yml
index ac70d57..bb01754 100644
--- a/config/routing.yml
+++ b/config/routing.yml
@@ -1,7 +1,3 @@
phpbb_webpushnotifications_ucp_routing:
resource: wpn_ucp.yml
prefix: /user
-
-phpbb_webpushnotifications_manifest_controller:
- path: /manifest
- defaults: { _controller: phpbb.wpn.controller.manifest:handle }
diff --git a/config/services.yml b/config/services.yml
index 07cd894..24b47ca 100644
--- a/config/services.yml
+++ b/config/services.yml
@@ -21,6 +21,7 @@ services:
- '@user'
- '@notification_manager'
- '%core.root_path%'
+ - '%core.php_ext%'
tags:
- { name: event.listener }
@@ -57,11 +58,3 @@ services:
- '@template.twig.environment'
- '%tables.phpbb.wpn.notification_push%'
- '%tables.phpbb.wpn.push_subscriptions%'
-
- phpbb.wpn.controller.manifest:
- class: phpbb\webpushnotifications\controller\manifest
- arguments:
- - '@config'
- - '@language'
- - '@path_helper'
- - '@user'
diff --git a/controller/manifest.php b/controller/manifest.php
deleted file mode 100644
index d1ebff7..0000000
--- a/controller/manifest.php
+++ /dev/null
@@ -1,99 +0,0 @@
-
- * @license GNU General Public License, version 2 (GPL-2.0)
- *
- */
-
-namespace phpbb\webpushnotifications\controller;
-
-use phpbb\config\config;
-use phpbb\exception\http_exception;
-use phpbb\language\language;
-use phpbb\path_helper;
-use phpbb\user;
-use phpbb\webpushnotifications\ext;
-use Symfony\Component\HttpFoundation\JsonResponse;
-use Symfony\Component\HttpFoundation\Response;
-
-class manifest
-{
- /** @var config */
- protected $config;
-
- /** @var language */
- protected $language;
-
- /** @var path_helper */
- protected $path_helper;
-
- /** @var user */
- protected $user;
-
- /**
- * Constructor for webpush controller
- *
- * @param config $config
- * @param path_helper $path_helper
- * @param language $language
- * @param user $user
- */
- public function __construct(config $config, language $language, path_helper $path_helper, user $user)
- {
- $this->config = $config;
- $this->path_helper = $path_helper;
- $this->language = $language;
- $this->user = $user;
- }
-
- /**
- * Handle creation of a manifest json file for progressive web-app support
- *
- * @return JsonResponse
- */
- public function handle(): JsonResponse
- {
- if ($this->user->data['is_bot'])
- {
- throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION');
- }
-
- $board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path();
- $board_url = generate_board_url();
-
- // 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);
-
- $manifest = [
- 'name' => $sitename,
- 'short_name' => $pwa_short_name ?: utf8_substr($sitename, 0, 12),
- 'display' => 'standalone',
- 'orientation' => 'portrait',
- 'dir' => $this->language->lang('DIRECTION'),
- 'start_url' => $board_path,
- 'scope' => $board_path,
- ];
-
- if (!empty($this->config['pwa_icon_small']) && !empty($this->config['pwa_icon_large']))
- {
- $manifest['icons'] = [
- [
- 'src' => $board_url . '/' . ext::PWA_ICON_DIR . '/' . $this->config['pwa_icon_small'],
- 'sizes' => '192x192',
- 'type' => 'image/png'
- ],
- [
- 'src' => $board_url . '/' . ext::PWA_ICON_DIR . '/' . $this->config['pwa_icon_large'],
- 'sizes' => '512x512',
- 'type' => 'image/png'
- ]
- ];
- }
-
- return new JsonResponse($manifest);
- }
-}
diff --git a/event/listener.php b/event/listener.php
index 9d1098e..bb55741 100644
--- a/event/listener.php
+++ b/event/listener.php
@@ -53,6 +53,9 @@ class listener implements EventSubscriberInterface
/** @var string */
protected $root_path;
+ /** @var string */
+ protected $php_ext;
+
/**
* Constructor
*
@@ -65,8 +68,9 @@ class listener implements EventSubscriberInterface
* @param user $user
* @param manager $phpbb_notifications Notifications manager object
* @param string $root_path
+ * @param string $php_ext
*/
- 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)
+ 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, $php_ext)
{
$this->config = $config;
$this->controller_helper = $controller_helper;
@@ -77,6 +81,7 @@ public function __construct(config $config, controller_helper $controller_helper
$this->user = $user;
$this->phpbb_notifications = $phpbb_notifications;
$this->root_path = $root_path;
+ $this->php_ext = $php_ext;
}
public static function getSubscribedEvents()
@@ -143,7 +148,7 @@ public function compatibility_notice()
public function pwa_manifest()
{
$this->template->assign_vars([
- 'U_MANIFEST_URL' => $this->controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
+ 'U_MANIFEST_URL' => 'ext/phpbb/webpushnotifications/manifest.' . $this->php_ext,
'U_TOUCH_ICON' => $this->config['pwa_icon_small'] ? ext::PWA_ICON_DIR . '/' . $this->config['pwa_icon_small'] : null,
'SHORT_SITE_NAME' => $this->config['pwa_short_name'] ?: $this->trim_shortname($this->config['sitename']),
]);
diff --git a/manifest.php b/manifest.php
new file mode 100644
index 0000000..ff572d0
--- /dev/null
+++ b/manifest.php
@@ -0,0 +1,54 @@
+
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ */
+
+use Symfony\Component\HttpFoundation\JsonResponse;
+use phpbb\webpushnotifications\ext;
+
+/**
+* @ignore
+**/
+const IN_PHPBB = true;
+$phpbb_root_path = ((defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './') . '../../../';
+$phpEx = substr(strrchr(__FILE__, '.'), 1);
+include($phpbb_root_path . 'common.' . $phpEx);
+
+$board_url = generate_board_url();
+
+// Emoji fixer-uppers
+$sitename = ext::decode_entities($config['sitename'], ENT_QUOTES);
+$pwa_short_name = ext::decode_entities($config['pwa_short_name'], ENT_QUOTES);
+
+$manifest = [
+ 'name' => $sitename,
+ 'short_name' => $pwa_short_name ?: utf8_substr($sitename, 0, 12),
+ 'display' => 'standalone',
+ 'orientation' => 'portrait',
+ 'start_url' => $board_url,
+ 'scope' => $board_url . '/',
+];
+
+if (!empty($config['pwa_icon_small']) && !empty($config['pwa_icon_large']))
+{
+ $manifest['icons'] = [
+ [
+ 'src' => $board_url . '/' . ext::PWA_ICON_DIR . '/' . $config['pwa_icon_small'],
+ 'sizes' => '192x192',
+ 'type' => 'image/png'
+ ],
+ [
+ 'src' => $board_url . '/' . ext::PWA_ICON_DIR . '/' . $config['pwa_icon_large'],
+ 'sizes' => '512x512',
+ 'type' => 'image/png'
+ ]
+ ];
+}
+
+$response = new JsonResponse($manifest);
+$response->send();
diff --git a/styles/all/template/event/overall_header_head_append.html b/styles/all/template/event/overall_header_head_append.html
index 0724173..f7df4a8 100644
--- a/styles/all/template/event/overall_header_head_append.html
+++ b/styles/all/template/event/overall_header_head_append.html
@@ -14,7 +14,7 @@
-
+
{% if U_TOUCH_ICON %}
diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php
index 70a4a6f..9e76e86 100644
--- a/tests/event/listener_test.php
+++ b/tests/event/listener_test.php
@@ -43,6 +43,9 @@ class listener_test extends \phpbb_database_test_case
/** @var string */
protected $root_path;
+ /** @var string */
+ protected $php_ext;
+
protected static function setup_extensions()
{
return ['phpbb/webpushnotifications'];
@@ -121,6 +124,7 @@ protected function setUp(): void
);
$this->root_path = $phpbb_root_path;
+ $this->php_ext = $phpEx;
}
protected function set_listener()
@@ -134,7 +138,8 @@ protected function set_listener()
$this->template,
$this->user,
$this->notifications,
- $this->root_path
+ $this->root_path,
+ $this->php_ext
);
}
@@ -321,7 +326,7 @@ public function test_pwa_manifest()
$this->template->expects(self::once())
->method('assign_vars')
->with([
- 'U_MANIFEST_URL' => $this->controller_helper->route('phpbb_webpushnotifications_manifest_controller'),
+ 'U_MANIFEST_URL' => 'ext/phpbb/webpushnotifications/manifest.' . $this->php_ext,
'U_TOUCH_ICON' => ext::PWA_ICON_DIR . '/icon-192x192.png',
'SHORT_SITE_NAME' => 'Test',
]);
diff --git a/tests/functional/functional_test.php b/tests/functional/functional_test.php
index ac7adf9..78f06ab 100644
--- a/tests/functional/functional_test.php
+++ b/tests/functional/functional_test.php
@@ -120,9 +120,8 @@ public function test_manifest()
'short_name' => 'yourdomain',
'display' => 'standalone',
'orientation' => 'portrait',
- 'dir' => 'ltr',
- 'start_url' => '/',
- 'scope' => '/',
+ 'start_url' => rtrim(self::$root_url, '/'),
+ 'scope' => self::$root_url,
];
$this->login();
@@ -137,7 +136,7 @@ public function test_manifest()
$crawler = self::submit($form);
$this->assertStringContainsString($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());
- self::request('GET', 'app.php/manifest', [], false);
+ self::request('GET', 'ext/phpbb/webpushnotifications/manifest.php', [], false);
$this->assertEquals(json_encode($expected), self::get_content());
}