summaryrefslogtreecommitdiff
path: root/platform/www/inc/Manifest.php
blob: 29e7f263ff5fa1ecbfe64379001ce29e41cd91db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php

namespace dokuwiki;

use dokuwiki\Extension\Event;

class Manifest
{
    public function sendManifest()
    {
        $manifest = retrieveConfig('manifest', 'jsonToArray');

        global $conf;

        $manifest['scope'] = DOKU_REL;

        if (empty($manifest['name'])) {
            $manifest['name'] = $conf['title'];
        }

        if (empty($manifest['short_name'])) {
            $manifest['short_name'] = $conf['title'];
        }

        if (empty($manifest['description'])) {
            $manifest['description'] = $conf['tagline'];
        }

        if (empty($manifest['start_url'])) {
            $manifest['start_url'] = DOKU_REL;
        }

        $styleUtil = new \dokuwiki\StyleUtils();
        $styleIni = $styleUtil->cssStyleini();
        $replacements = $styleIni['replacements'];

        if (empty($manifest['background_color'])) {
            $manifest['background_color'] = $replacements['__background__'];
        }

        if (empty($manifest['theme_color'])) {
            $manifest['theme_color'] = !empty($replacements['__theme_color__'])
                ? $replacements['__theme_color__']
                : $replacements['__background_alt__'];
        }

        if (empty($manifest['icons'])) {
            $manifest['icons'] = [];
            if (file_exists(mediaFN(':wiki:favicon.ico'))) {
                $url = ml(':wiki:favicon.ico', '', true, '', true);
                $manifest['icons'][] = [
                    'src' => $url,
                    'sizes' => '16x16',
                ];
            }

            $look = [
                ':wiki:logo.svg',
                ':logo.svg',
                ':wiki:dokuwiki.svg'
            ];

            foreach ($look as $svgLogo) {

                $svgLogoFN = mediaFN($svgLogo);

                if (file_exists($svgLogoFN)) {
                    $url = ml($svgLogo, '', true, '', true);
                    $manifest['icons'][] = [
                        'src' => $url,
                        'sizes' => '17x17 512x512',
                        'type' => 'image/svg+xml',
                    ];
                    break;
                };
            }
        }

        Event::createAndTrigger('MANIFEST_SEND', $manifest);

        header('Content-Type: application/manifest+json');
        echo json_encode($manifest);
    }
}