xref: /dokuwiki/inc/Manifest.php (revision 64159a61e94d0ce680071c8890e144982c3a8cbe)
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'])) {
40*64159a61SAndreas Gohr            $manifest['theme_color'] = !empty($replacements['__theme_color__'])
41*64159a61SAndreas Gohr                ? $replacements['__theme_color__']
42*64159a61SAndreas Gohr                : $replacements['__background_alt__'];
43c9071834SMichael Große        }
44c9071834SMichael Große
45c9071834SMichael Große        if (empty($manifest['icons'])) {
46c9071834SMichael Große            $manifest['icons'] = [];
472d8226d6SMichael Große            if (file_exists(mediaFN(':wiki:favicon.ico'))) {
482d8226d6SMichael Große                $url = ml(':wiki:favicon.ico', '', true, '', true);
49c9071834SMichael Große                $manifest['icons'][] = [
50c9071834SMichael Große                    'src' => $url,
512d8226d6SMichael Große                    'sizes' => '16x16',
52c9071834SMichael Große                ];
532d8226d6SMichael Große            }
542d8226d6SMichael Große
552d8226d6SMichael Große            $look = [
562d8226d6SMichael Große                ':wiki:logo.svg',
572d8226d6SMichael Große                ':logo.svg',
582d8226d6SMichael Große                ':wiki:dokuwiki.svg'
592d8226d6SMichael Große            ];
602d8226d6SMichael Große
612d8226d6SMichael Große            foreach ($look as $svgLogo) {
622d8226d6SMichael Große
632d8226d6SMichael Große                $svgLogoFN = mediaFN($svgLogo);
642d8226d6SMichael Große
652d8226d6SMichael Große                if (file_exists($svgLogoFN)) {
662d8226d6SMichael Große                    $url = ml($svgLogo, '', true, '', true);
672d8226d6SMichael Große                    $manifest['icons'][] = [
682d8226d6SMichael Große                        'src' => $url,
692d8226d6SMichael Große                        'sizes' => '17x17 512x512',
702d8226d6SMichael Große                        'type' => 'image/svg+xml',
712d8226d6SMichael Große                    ];
722d8226d6SMichael Große                    break;
73c9071834SMichael Große                };
74c9071834SMichael Große            }
75c9071834SMichael Große        }
76c9071834SMichael Große
77c9071834SMichael Große        trigger_event('MANIFEST_SEND', $manifest);
78c9071834SMichael Große
79c9071834SMichael Große        header('Content-Type: application/manifest+json');
80c9071834SMichael Große        echo json_encode($manifest);
81c9071834SMichael Große    }
82c9071834SMichael Große}
83