1<?php
2
3
4require_once(__DIR__ . '/../ComboStrap/PluginUtility.php');
5
6use ComboStrap\DirectoryLayout;
7use ComboStrap\Identity;
8
9
10/**
11 * Class action_plugin_combo_svg
12 * Returned an svg optimized version
13 */
14class action_plugin_combo_svg extends DokuWiki_Action_Plugin
15{
16
17
18    public function register(Doku_Event_Handler $controller)
19    {
20
21
22        /**
23         * Hack the upload is done via the ajax.php file
24         * {@link media_upload()}
25         */
26        $controller->register_hook('AUTH_ACL_CHECK', 'BEFORE', $this, 'svg_mime');
27
28        /**
29         * When the parsing of a page starts
30         */
31        $controller->register_hook('PARSER_WIKITEXT_PREPROCESS', 'BEFORE', $this, 'svg_mime');
32
33
34    }
35
36
37    /**
38     * @param Doku_Event $event
39     * {@link media_save} is checking the authorized mime type
40     * Svg is not by default, we add it here if the user is admin or
41     * in a specified group
42     */
43    public function svg_mime(Doku_Event &$event)
44    {
45
46        self::allowSvgIfAuthorized();
47
48    }
49
50    /**
51     *
52     */
53    public static function allowSvgIfAuthorized()
54    {
55        $isAdmin = Identity::isAdmin();
56        $isMember = Identity::isMember("@" . Identity::CONF_DESIGNER_GROUP_NAME);
57
58        if ($isAdmin || $isMember) {
59            /**
60             * Enhance the svg mime type
61             * {@link getMimeTypes()}
62             */
63            global $config_cascade;
64            $svgMimeConf = DirectoryLayout::getComboResourcesDirectory()->resolve("conf")->resolve("svg.mime.conf")->toAbsoluteId();
65            $config_cascade['mime']['local'][] = $svgMimeConf;
66        }
67
68    }
69
70
71}
72