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