xref: /plugin/mikioplugin/action.php (revision 7935713e90ae66bca4380ea057ab7fd4f3e18daa)
1<?php
2/**
3 * Mikio Plugin
4 *
5 * @version    1.0
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     James Collins <james.collins@outlook.com.au>
8 */
9
10if(!defined('DOKU_INC')) die();
11
12require_once('icons/icons.php');
13
14class action_plugin_mikioplugin extends DokuWiki_Action_Plugin {
15
16	public function register(Doku_Event_Handler $controller) {
17		$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_load');
18	}
19
20	public function _load(Doku_Event $event, $param) {
21		global $conf;
22        global $MIKIO_ICONS;
23
24        $baseDir = DOKU_BASE.'lib/plugins' . str_replace(dirname(dirname(__FILE__)), '', dirname(__FILE__)) . '/';
25        $stylesheets = [];
26        $scripts = [];
27
28        if(is_array($MIKIO_ICONS)) {
29            $icons = Array();
30            foreach($MIKIO_ICONS as $icon) {
31                if(isset($icon['name']) && isset($icon['css']) && isset($icon['insert'])) {
32                    $icons[] = $icon;
33
34                    if($icon['css'] != '') {
35                        if(strpos($icon['css'], '//') === FALSE) {
36                            $stylesheets[] = $baseDir . 'icons/' . $icon['css'];
37                        } else {
38                            $stylesheets[] = $icon['css'];
39                        }
40                    }
41                }
42            }
43            $MIKIO_ICONS = $icons;
44        } else {
45            $MIKIO_ICONS = [];
46        }
47
48        foreach ($stylesheets as $style) {
49            array_unshift($event->data['link'], array(
50                'type' => 'text/css',
51                'rel'  => 'stylesheet',
52                'href' => $style
53            ));
54        }
55
56        foreach ($scripts as $script) {
57            $event->data['script'][] = array(
58                 'type'  => 'text/javascript',
59              '_data' => '',
60              'src'   => $script
61          );
62      }
63    }
64}
65