xref: /plugin/diagrams/action/action.php (revision 5a651f4b90f042c9b80137d5f8c16c4c9d4fb218)
1<?php
2
3/**
4 * Action component of diagrams plugin
5 *
6 * This handles general operations independent of the configured mode
7 *
8 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
9 * @author  Innovakom + CosmoCode <dokuwiki@cosmocode.de>
10 */
11class action_plugin_diagrams_action extends DokuWiki_Action_Plugin
12{
13
14    /**@inheritDoc */
15    public function register(Doku_Event_Handler $controller)
16    {
17        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addJsinfo');
18        $controller->register_hook('MEDIAMANAGER_STARTED', 'AFTER', $this, 'addJsinfo');
19        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'checkConf');
20    }
21
22    /**
23     * Add data to JSINFO
24     *
25     * full service URL
26     * digram mode
27     * security token used for uploading
28     *
29     * @param Doku_Event $event DOKUWIKI_STARTED|MEDIAMANAGER_STARTED
30     */
31    public function addJsinfo(Doku_Event $event)
32    {
33        global $JSINFO;
34        $JSINFO['sectok'] = getSecurityToken();
35        $JSINFO['plugins']['diagrams'] = [
36            'service_url' => $this->getConf('service_url'),
37            'mode' => $this->getConf('mode'),
38        ];
39    }
40
41    /**
42     * Check if DokuWiki is properly configured to handle SVG diagrams
43     *
44     * @param Doku_Event $event DOKUWIKI_STARTED
45     */
46    public function checkConf(Doku_Event $event)
47    {
48        $mime = getMimeTypes();
49        if (!array_key_exists('svg', $mime) || $mime['svg'] !== 'image/svg+xml') {
50            msg($this->getLang('missingConfig'), -1);
51        }
52    }
53}
54