Failed Conditions
Push — master ( b4384f...430a27 )
by Michael
10:56 queued 06:33
created

Manifest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 76
rs 10
wmc 12
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
F sendManifest() 0 73 12
1
<?php
2
3
namespace dokuwiki;
4
5
class 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__']) ? $replacements['__theme_color__'] : $replacements['__background_alt__'];
41
        }
42
43
        if (empty($manifest['icons'])) {
44
            $manifest['icons'] = [];
45
            if (file_exists(mediaFN(':wiki:favicon.ico'))) {
46
                $url = ml(':wiki:favicon.ico', '', true, '', true);
47
                $manifest['icons'][] = [
48
                    'src' => $url,
49
                    'sizes' => '16x16',
50
                ];
51
            }
52
53
            $look = [
54
                ':wiki:logo.svg',
55
                ':logo.svg',
56
                ':wiki:dokuwiki.svg'
57
            ];
58
59
            foreach ($look as $svgLogo) {
60
61
                $svgLogoFN = mediaFN($svgLogo);
62
63
                if (file_exists($svgLogoFN)) {
64
                    $url = ml($svgLogo, '', true, '', true);
65
                    $manifest['icons'][] = [
66
                        'src' => $url,
67
                        'sizes' => '17x17 512x512',
68
                        'type' => 'image/svg+xml',
69
                    ];
70
                    break;
71
                };
72
            }
73
        }
74
75
        trigger_event('MANIFEST_SEND', $manifest);
76
77
        header('Content-Type: application/manifest+json');
78
        echo json_encode($manifest);
79
    }
80
}
81