xref: /plugin/diagrams/action/action.php (revision 59e7180efcc3e125683f24f98a466ef29145cfce)
1317bdfc2SAndreas Gohr<?php
2317bdfc2SAndreas Gohr
3317bdfc2SAndreas Gohr/**
4317bdfc2SAndreas Gohr * Action component of diagrams plugin
5317bdfc2SAndreas Gohr *
6*59e7180eSAndreas Gohr * This handles general operations independent of the configured mode
7*59e7180eSAndreas Gohr *
8*59e7180eSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
9*59e7180eSAndreas Gohr * @author  Innovakom + CosmoCode <dokuwiki@cosmocode.de>
10317bdfc2SAndreas Gohr */
11317bdfc2SAndreas Gohrclass action_plugin_diagrams_action extends DokuWiki_Action_Plugin
12317bdfc2SAndreas Gohr{
13317bdfc2SAndreas Gohr
14*59e7180eSAndreas Gohr    /**@inheritDoc */
15317bdfc2SAndreas Gohr    public function register(Doku_Event_Handler $controller)
16317bdfc2SAndreas Gohr    {
17317bdfc2SAndreas Gohr        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addJsinfo');
18317bdfc2SAndreas Gohr        $controller->register_hook('MEDIAMANAGER_STARTED', 'AFTER', $this, 'addJsinfo');
19317bdfc2SAndreas Gohr        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'checkConf');
20*59e7180eSAndreas Gohr
21*59e7180eSAndreas Gohr
22317bdfc2SAndreas Gohr    }
23317bdfc2SAndreas Gohr
24317bdfc2SAndreas Gohr    /**
25*59e7180eSAndreas Gohr     * Add data to JSINFO
26317bdfc2SAndreas Gohr     *
27*59e7180eSAndreas Gohr     * full service URL
28*59e7180eSAndreas Gohr     * digram mode
29*59e7180eSAndreas Gohr     * security token used for uploading
30*59e7180eSAndreas Gohr     *
31*59e7180eSAndreas Gohr     * @param Doku_Event $event DOKUWIKI_STARTED|MEDIAMANAGER_STARTED
32317bdfc2SAndreas Gohr     */
33317bdfc2SAndreas Gohr    public function addJsinfo(Doku_Event $event)
34317bdfc2SAndreas Gohr    {
35317bdfc2SAndreas Gohr        global $JSINFO;
36317bdfc2SAndreas Gohr        $JSINFO['sectok'] = getSecurityToken();
37*59e7180eSAndreas Gohr        $JSINFO['plugins']['diagrams'] = [
38*59e7180eSAndreas Gohr            'service_url' => $this->getConf('service_url'),
39*59e7180eSAndreas Gohr            'mode' => $this->getConf('mode'),
40*59e7180eSAndreas Gohr        ];
41317bdfc2SAndreas Gohr    }
42317bdfc2SAndreas Gohr
43317bdfc2SAndreas Gohr    /**
44317bdfc2SAndreas Gohr     * Check if DokuWiki is properly configured to handle SVG diagrams
45317bdfc2SAndreas Gohr     *
46*59e7180eSAndreas Gohr     * @param Doku_Event $event DOKUWIKI_STARTED
47317bdfc2SAndreas Gohr     */
48317bdfc2SAndreas Gohr    public function checkConf(Doku_Event $event)
49317bdfc2SAndreas Gohr    {
50317bdfc2SAndreas Gohr        $mime = getMimeTypes();
51317bdfc2SAndreas Gohr        if (!array_key_exists('svg', $mime) || $mime['svg'] !== 'image/svg+xml') {
52317bdfc2SAndreas Gohr            msg($this->getLang('missingConfig'), -1);
53317bdfc2SAndreas Gohr        }
54317bdfc2SAndreas Gohr    }
55317bdfc2SAndreas Gohr
56317bdfc2SAndreas Gohr
57317bdfc2SAndreas Gohr
58317bdfc2SAndreas Gohr}
59