1<?php
2/**
3 * @license     GPL 2 (http://www.gnu.org/licenses/gpl.html
4 * @author      Patrick Brown <ptbrown@whoopdedo.org>
5 */
6// must be run within Dokuwiki
7if(!defined('DOKU_INC')) die();
8
9class action_plugin_emoji extends DokuWiki_Action_Plugin {
10
11    public function register(Doku_Event_Handler $controller) {
12        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'tplMetaheaderOutput');
13    }
14
15    public function tplMetaheaderOutput(Doku_Event &$event, $param) {
16        $assetsrc = DOKU_BASE.'lib/plugins/emoji/';
17        switch($this->getConf('assetsrc')) {
18            case 'cdn':
19                $assetsrc = '//cdn.jsdelivr.net/emojione/';
20                break;
21            case 'external':
22                $asseturi = $this->getConf('asseturi');
23                if($asseturi)
24                    $assetsrc = $asseturi;
25                break;
26        }
27        /* Insert JS variable for CDN server. */
28        /* Use a global variable because otherwise there would need to be yet */
29        /* another hook to modify the JSINFO array that has already been written. */
30        $json = new JSON();
31        $event->data['script'][] = array(
32            'type'  => 'text/javascript',
33            '_data' => 'var emoji_assetsrc = '.$json->encode($assetsrc).';'
34        );
35    }
36
37}
38
39