Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manifesting #103

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 0 additions & 4 deletions config/routing.yml
Original file line number Diff line number Diff line change
@@ -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 }
9 changes: 1 addition & 8 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- '@user'
- '@notification_manager'
- '%core.root_path%'
- '%core.php_ext%'
tags:
- { name: event.listener }

Expand Down Expand Up @@ -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'
99 changes: 0 additions & 99 deletions controller/manifest.php

This file was deleted.

9 changes: 7 additions & 2 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class listener implements EventSubscriberInterface
/** @var string */
protected $root_path;

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

/**
* Constructor
*
Expand All @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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']),
]);
Expand Down
54 changes: 54 additions & 0 deletions manifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
*
* phpBB Browser Push Notifications. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2024, phpBB Limited <https://www.phpbb.com>
* @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();
2 changes: 1 addition & 1 deletion styles/all/template/event/overall_header_head_append.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<meta name="application-name" content="{{ SHORT_SITE_NAME }}">

<!-- Link to app's configuration manifest -->
<link rel="manifest" href="{{ U_MANIFEST_URL }}" crossorigin="use-credentials">
<link rel="manifest" href="{{ ROOT_PATH ~ U_MANIFEST_URL }}" crossorigin="use-credentials">

{% if U_TOUCH_ICON %}
<!-- App icon for iOS, a fallback to icons defined in the manifest -->
Expand Down
9 changes: 7 additions & 2 deletions tests/event/listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -121,6 +124,7 @@ protected function setUp(): void
);

$this->root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
}

protected function set_listener()
Expand All @@ -134,7 +138,8 @@ protected function set_listener()
$this->template,
$this->user,
$this->notifications,
$this->root_path
$this->root_path,
$this->php_ext
);
}

Expand Down Expand Up @@ -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',
]);
Expand Down
7 changes: 3 additions & 4 deletions tests/functional/functional_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
}

Expand Down