Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
manifest | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
handle | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb; |
15 | |
16 | use phpbb\config\config; |
17 | use phpbb\event\dispatcher_interface; |
18 | use phpbb\exception\http_exception; |
19 | use phpbb\language\language; |
20 | use Symfony\Component\HttpFoundation\JsonResponse; |
21 | use Symfony\Component\HttpFoundation\Response; |
22 | |
23 | class manifest |
24 | { |
25 | /** @var config */ |
26 | protected $config; |
27 | |
28 | /** @var language */ |
29 | protected $language; |
30 | |
31 | /** @var path_helper */ |
32 | protected $path_helper; |
33 | |
34 | /** @var dispatcher_interface */ |
35 | protected $phpbb_dispatcher; |
36 | |
37 | /** @var user */ |
38 | protected $user; |
39 | |
40 | /** |
41 | * Constructor for manifest controller |
42 | * |
43 | * @param config $config |
44 | * @param language $language |
45 | * @param path_helper $path_helper |
46 | * @param dispatcher_interface $phpbb_dispatcher |
47 | * @param user $user |
48 | */ |
49 | public function __construct(config $config, language $language, path_helper $path_helper, dispatcher_interface $phpbb_dispatcher, user $user) |
50 | { |
51 | $this->config = $config; |
52 | $this->path_helper = $path_helper; |
53 | $this->phpbb_dispatcher = $phpbb_dispatcher; |
54 | $this->language = $language; |
55 | $this->user = $user; |
56 | } |
57 | |
58 | /** |
59 | * Handle creation of a manifest json file for progressive web-app support |
60 | * |
61 | * @return JsonResponse |
62 | */ |
63 | public function handle(): JsonResponse |
64 | { |
65 | if ($this->user->data['is_bot']) |
66 | { |
67 | throw new http_exception(Response::HTTP_FORBIDDEN, 'NO_AUTH_OPERATION'); |
68 | } |
69 | |
70 | $board_path = $this->config['force_server_vars'] ? $this->config['script_path'] : $this->path_helper->get_web_root_path(); |
71 | |
72 | $sitename = html_entity_decode($this->config['sitename'], ENT_QUOTES, 'UTF-8'); |
73 | $sitename_short = html_entity_decode($this->config['sitename_short'], ENT_QUOTES, 'UTF-8'); |
74 | |
75 | $manifest = [ |
76 | 'name' => $sitename, |
77 | 'short_name' => $sitename_short ?: utf8_substr($sitename, 0, 12), |
78 | 'display' => 'standalone', |
79 | 'orientation' => 'portrait', |
80 | 'dir' => $this->language->lang('DIRECTION'), |
81 | 'start_url' => $board_path, |
82 | 'scope' => $board_path, |
83 | ]; |
84 | |
85 | /** |
86 | * Event to modify manifest data before it is outputted |
87 | * |
88 | * @event core.modify_manifest |
89 | * @var array manifest Array of manifest members |
90 | * @var string board_path Path to the board root |
91 | * @since 4.0.0-a1 |
92 | */ |
93 | $vars = array('manifest', 'board_path'); |
94 | extract($this->phpbb_dispatcher->trigger_event('core.modify_manifest', compact($vars))); |
95 | |
96 | return new JsonResponse($manifest); |
97 | } |
98 | } |