xref: /dokuwiki/inc/Manifest.php (revision 24870174d2ee45460ba6bcfe5f5a0ae94715efd7)
1c9071834SMichael Große<?php
2c9071834SMichael Große
3c9071834SMichael Großenamespace dokuwiki;
4c9071834SMichael Große
5cbb44eabSAndreas Gohruse dokuwiki\Extension\Event;
6cbb44eabSAndreas Gohr
7c9071834SMichael Großeclass Manifest
8c9071834SMichael Große{
9c9071834SMichael Große    public function sendManifest()
10c9071834SMichael Große    {
11c9071834SMichael Große        $manifest = retrieveConfig('manifest', 'jsonToArray');
12c9071834SMichael Große
13c9071834SMichael Große        global $conf;
14c9071834SMichael Große
15c9071834SMichael Große        $manifest['scope'] = DOKU_REL;
16c9071834SMichael Große
17c9071834SMichael Große        if (empty($manifest['name'])) {
18c9071834SMichael Große            $manifest['name'] = $conf['title'];
19c9071834SMichael Große        }
20c9071834SMichael Große
21c9071834SMichael Große        if (empty($manifest['short_name'])) {
22c9071834SMichael Große            $manifest['short_name'] = $conf['title'];
23c9071834SMichael Große        }
24c9071834SMichael Große
25c9071834SMichael Große        if (empty($manifest['description'])) {
26c9071834SMichael Große            $manifest['description'] = $conf['tagline'];
27c9071834SMichael Große        }
28c9071834SMichael Große
29c9071834SMichael Große        if (empty($manifest['start_url'])) {
30c9071834SMichael Große            $manifest['start_url'] = DOKU_REL;
31c9071834SMichael Große        }
32c9071834SMichael Große
33*24870174SAndreas Gohr        $styleUtil = new StyleUtils();
344593dbd2SAnna Dabrowska        $styleIni = $styleUtil->cssStyleini();
35c9071834SMichael Große        $replacements = $styleIni['replacements'];
36c9071834SMichael Große
37c9071834SMichael Große        if (empty($manifest['background_color'])) {
38c9071834SMichael Große            $manifest['background_color'] = $replacements['__background__'];
39c9071834SMichael Große        }
40c9071834SMichael Große
41c9071834SMichael Große        if (empty($manifest['theme_color'])) {
42*24870174SAndreas Gohr            $manifest['theme_color'] = empty($replacements['__theme_color__'])
43*24870174SAndreas Gohr                ? $replacements['__background_alt__']
44*24870174SAndreas Gohr                : $replacements['__theme_color__'];
45c9071834SMichael Große        }
46c9071834SMichael Große
47c9071834SMichael Große        if (empty($manifest['icons'])) {
48c9071834SMichael Große            $manifest['icons'] = [];
492d8226d6SMichael Große            if (file_exists(mediaFN(':wiki:favicon.ico'))) {
502d8226d6SMichael Große                $url = ml(':wiki:favicon.ico', '', true, '', true);
51c9071834SMichael Große                $manifest['icons'][] = [
52c9071834SMichael Große                    'src' => $url,
532d8226d6SMichael Große                    'sizes' => '16x16',
54c9071834SMichael Große                ];
552d8226d6SMichael Große            }
562d8226d6SMichael Große
572d8226d6SMichael Große            $look = [
582d8226d6SMichael Große                ':wiki:logo.svg',
592d8226d6SMichael Große                ':logo.svg',
602d8226d6SMichael Große                ':wiki:dokuwiki.svg'
612d8226d6SMichael Große            ];
622d8226d6SMichael Große
632d8226d6SMichael Große            foreach ($look as $svgLogo) {
642d8226d6SMichael Große
652d8226d6SMichael Große                $svgLogoFN = mediaFN($svgLogo);
662d8226d6SMichael Große
672d8226d6SMichael Große                if (file_exists($svgLogoFN)) {
682d8226d6SMichael Große                    $url = ml($svgLogo, '', true, '', true);
692d8226d6SMichael Große                    $manifest['icons'][] = [
702d8226d6SMichael Große                        'src' => $url,
712d8226d6SMichael Große                        'sizes' => '17x17 512x512',
722d8226d6SMichael Große                        'type' => 'image/svg+xml',
732d8226d6SMichael Große                    ];
742d8226d6SMichael Große                    break;
75c9071834SMichael Große                };
76c9071834SMichael Große            }
77c9071834SMichael Große        }
78c9071834SMichael Große
79cbb44eabSAndreas Gohr        Event::createAndTrigger('MANIFEST_SEND', $manifest);
80c9071834SMichael Große
81c9071834SMichael Große        header('Content-Type: application/manifest+json');
82*24870174SAndreas Gohr        echo json_encode($manifest, JSON_THROW_ON_ERROR);
83c9071834SMichael Große    }
84c9071834SMichael Große}
85