Skip to content

Commit

Permalink
Make manifest a static page
Browse files Browse the repository at this point in the history
  • Loading branch information
iMattPro committed Dec 17, 2024
1 parent 4d5c5a1 commit 6715928
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
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 }
2 changes: 1 addition & 1 deletion event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,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.php',
'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
59 changes: 59 additions & 0 deletions manifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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
**/
define('IN_PHPBB', true);
$phpbb_root_path = ((defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './') . '../../../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

/** @var \phpbb\path_helper $path_helper */
$path_helper = $phpbb_container->get('path_helper');

$board_path = $config['force_server_vars'] ? $config['script_path'] : $path_helper->get_web_root_path();
$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',
'dir' => $language->lang('DIRECTION'),
'start_url' => $board_path,
'scope' => $board_path,
];

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 }}">
<link rel="manifest" href="{{ ROOT_PATH ~ U_MANIFEST_URL }}">

{% if U_TOUCH_ICON %}
<!-- App icon for iOS, a fallback to icons defined in the manifest -->
Expand Down

0 comments on commit 6715928

Please sign in to comment.