1<?php
2
3use ComboStrap\ColorRgb;
4use ComboStrap\Mime;
5use ComboStrap\Site;
6
7
8
9/**
10 *
11 * To add the manifest image
12 *
13 * https://www.dokuwiki.org/devel:manifest
14 *
15 * @see <a href="https://combostrap.com/manifest">manifest</a>
16 *
17 * [[doku>devel:manifest|webmanifest]]
18 * https://developer.mozilla.org/en-US/docs/Web/Manifest
19 */
20class action_plugin_combo_manifest extends DokuWiki_Action_Plugin
21{
22
23
24    function register(Doku_Event_Handler $controller)
25    {
26
27        /* This will call the function _manifest */
28        $controller->register_hook(
29            'MANIFEST_SEND',
30            'AFTER',
31            $this,
32            '_manifest',
33            array()
34        );
35
36
37    }
38
39
40    /**
41     * Main function; dispatches the visual comment actions
42     * @param   $event Doku_Event
43     *
44     * We take into account the file generated by https://realfavicongenerator.net/
45     *
46     *
47     *
48     */
49    function _manifest(&$event, $param)
50    {
51
52        $mediaId = ":android-chrome-192x192.png";
53        $mediaFile = mediaFN($mediaId);
54        if (file_exists($mediaFile)) {
55            $url = ml($mediaId, '', true, '', true);
56            $event->data['icons'][] =
57                array(
58                    "src" => $url,
59                    "sizes" => "192x192",
60                    "type" => "image/png"
61                );
62        }
63
64        $primaryColor = Site::getPrimaryColor();
65        if ($primaryColor !== null) {
66            $event->data["theme_color"] = $primaryColor->toRgbHex();
67        }
68
69        /**
70         * Id setting
71         * https://developer.chrome.com/blog/pwa-manifest-id/
72         * It seems that this is a unique id domain based
73         * We set then the start_url (ie another pwa may be living on another path)
74         */
75        $event->data["id"] = $event->data["start_url"];
76
77
78        /**
79         * Svg must be size any for svg
80         * https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes
81         * otherwise we get this kind of error in devtool.
82         * ``
83         * Actual Size (150x150)px of Icon .... svg does not  match the specified size (17x17, 512x512)
84         * ``
85         * Note:
86         *   * 150x150 is not the true size
87         *   * (17x17, 512x512) is set by dokuwiki
88         */
89        foreach ($event->data['icons'] as &$iconArray) {
90            if ($iconArray["type"] === Mime::SVG) {
91                $iconArray["sizes"] = "any";
92            }
93        }
94
95
96    }
97
98
99}
100