xref: /dokuwiki/inc/Manifest.php (revision 3dc2d50c5fda9c4bf708ff4c26e266ba239af62c)
1<?php
2
3namespace dokuwiki;
4
5class Manifest
6{
7    public function sendManifest()
8    {
9        $manifest = retrieveConfig('manifest', 'jsonToArray');
10
11        global $conf;
12
13        $manifest['scope'] = DOKU_REL;
14
15        if (empty($manifest['name'])) {
16            $manifest['name'] = $conf['title'];
17        }
18
19        if (empty($manifest['short_name'])) {
20            $manifest['short_name'] = $conf['title'];
21        }
22
23        if (empty($manifest['description'])) {
24            $manifest['description'] = $conf['tagline'];
25        }
26
27        if (empty($manifest['start_url'])) {
28            $manifest['start_url'] = DOKU_REL;
29        }
30
31        $styleUtil = new \dokuwiki\StyleUtils();
32        $styleIni = $styleUtil->cssStyleini($conf['template']);
33        $replacements = $styleIni['replacements'];
34
35        if (empty($manifest['background_color'])) {
36            $manifest['background_color'] = $replacements['__background__'];
37        }
38
39        if (empty($manifest['theme_color'])) {
40            $manifest['theme_color'] = !empty($replacements['__theme_color__'])
41                ? $replacements['__theme_color__']
42                : $replacements['__background_alt__'];
43        }
44
45        if (empty($manifest['icons'])) {
46            $manifest['icons'] = [];
47            if (file_exists(mediaFN(':wiki:favicon.ico'))) {
48                $url = ml(':wiki:favicon.ico', '', true, '', true);
49                $manifest['icons'][] = [
50                    'src' => $url,
51                    'sizes' => '16x16',
52                ];
53            }
54
55            $look = [
56                ':wiki:logo.svg',
57                ':logo.svg',
58                ':wiki:dokuwiki.svg'
59            ];
60
61            foreach ($look as $svgLogo) {
62
63                $svgLogoFN = mediaFN($svgLogo);
64
65                if (file_exists($svgLogoFN)) {
66                    $url = ml($svgLogo, '', true, '', true);
67                    $manifest['icons'][] = [
68                        'src' => $url,
69                        'sizes' => '17x17 512x512',
70                        'type' => 'image/svg+xml',
71                    ];
72                    break;
73                };
74            }
75        }
76
77        trigger_event('MANIFEST_SEND', $manifest);
78
79        header('Content-Type: application/manifest+json');
80        echo json_encode($manifest);
81    }
82}
83