xref: /plugin/diagrams/action/action.php (revision 046ca1447d01a47b6caa55952ebefa80c90967a9)
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
24    /**
25     * Add data to JSINFO
26     *
27     * full service URL
28     * digram mode
29     * security token used for uploading
30     *
31     * @param Doku_Event $event DOKUWIKI_STARTED|MEDIAMANAGER_STARTED
32     */
33    public function addJsinfo(Doku_Event $event)
34    {
35        global $JSINFO;
36        $JSINFO['sectok'] = getSecurityToken();
37        $JSINFO['plugins']['diagrams'] = [
38            'service_url' => $this->getConf('service_url'),
39            'mode' => $this->getConf('mode'),
40        ];
41    }
42
43    /**
44     * Check if DokuWiki is properly configured to handle SVG diagrams
45     *
46     * @param Doku_Event $event DOKUWIKI_STARTED
47     */
48    public function checkConf(Doku_Event $event)
49    {
50        $mime = getMimeTypes();
51        if (!array_key_exists('svg', $mime) || $mime['svg'] !== 'image/svg+xml') {
52            msg($this->getLang('missingConfig'), -1);
53        }
54    }
55
56
57
58}
59