forked from phpbb-extensions/webpushnotifications
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanifest.php
More file actions
95 lines (82 loc) · 2.38 KB
/
manifest.php
File metadata and controls
95 lines (82 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?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)
*
*/
namespace phpbb\webpushnotifications\controller;
use phpbb\config\config;
use phpbb\user;
use phpbb\webpushnotifications\ext;
use Symfony\Component\HttpFoundation\JsonResponse;
class manifest
{
/** @var config */
protected $config;
/** @var user */
protected $user;
/**
* Constructor for webpush controller
*
* @param config $config
* @param user $user
*/
public function __construct(config $config, user $user)
{
$this->config = $config;
$this->user = $user;
}
/**
* Handle creation of a manifest json file for progressive web-app support
*
* @return JsonResponse
*/
public function handle(): JsonResponse
{
// 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, PHP_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);
$sitename_short = ext::decode_entities($this->config['pwa_short_name'], ENT_QUOTES);
$manifest = [
'name' => $sitename,
'short_name' => $sitename_short ?: utf8_substr($sitename, 0, 12),
'display' => 'standalone',
'orientation' => 'portrait',
'start_url' => $start_url,
'scope' => $scope,
];
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'
]
];
}
$response = new JsonResponse($manifest);
$response->setPublic();
$response->setMaxAge(3600);
$response->headers->addCacheControlDirective('must-revalidate', true);
if (!empty($this->user->data['is_bot']))
{
// Let reverse proxies know we detected a bot.
$response->headers->set('X-PHPBB-IS-BOT', 'yes');
}
return $response;
}
}