1<?php
2/**
3 * @author         Szymon Olewniczak <solewniczak@rid.pl>
4 */
5
6// must be run within Dokuwiki
7if(!defined('DOKU_INC')) die();
8
9class action_plugin_jplayer extends DokuWiki_Action_Plugin {
10
11    /**
12     * Register its handlers with the DokuWiki's event controller
13     */
14    public function register(Doku_Event_Handler $controller) {
15        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'include_dependencies', array());
16        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER',  $this, 'jsinfo');
17    }
18    public function include_dependencies(Doku_Event $event, $param) {
19        $skin = $this->getConf('skin');
20        // Adding a stylesheet
21        $event->data['link'][] = array (
22            'type' => 'text/css',
23            'rel' => 'stylesheet',
24            'href' => DOKU_BASE .
25            'lib/plugins/jplayer/vendor/happyworm/jplayer/dist/skin/'.$skin.'/css/jplayer.'.$skin.'.min.css',
26        );
27
28        // Adding a JavaScript File
29        $event->data['script'][] = array (
30            'type' => 'text/javascript',
31            'src' => DOKU_BASE .
32            'lib/plugins/jplayer/vendor/happyworm/jplayer/dist/jplayer/jquery.jplayer.min.js',
33            'defer' => 'defer',
34            '_data' => '',
35        );
36
37        $event->data['script'][] = array (
38            'type' => 'text/javascript',
39            'src' => DOKU_BASE .
40            'lib/plugins/jplayer/vendor/happyworm/jplayer/dist/add-on/jplayer.playlist.min.js',
41            'defer' => 'defer',
42            '_data' => '',
43        );
44    }
45
46    public function jsinfo(Doku_Event $event, $param) {
47        global $JSINFO, $ID;
48
49        if (!isset($JSINFO['plugin'])) $JSINFO['plugin'] = array();
50
51        $name = $this->getPluginName();
52        $JSINFO['plugin'][$name] = p_get_metadata($ID, "plugin $name");
53    }
54}
55