1<?php 2/** 3 * DokuWiki Plugin AmCharts (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Sylvain Menu <35niavlys@gmail.com> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12class action_plugin_amcharts extends DokuWiki_Action_Plugin { 13 14 /** 15 * Registers a callback function for a given event 16 * 17 * @param Doku_Event_Handler $controller DokuWiki's event controller object 18 * @return void 19 */ 20 public function register(Doku_Event_Handler $controller) { 21 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_tpl_metaheader_output'); 22 } 23 24 /** 25 * [Custom event handler which performs action] 26 * 27 * @param Doku_Event $event event object by reference 28 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 29 * handler was registered] 30 * @return void 31 */ 32 public function handle_tpl_metaheader_output(Doku_Event &$event, $param) { 33 34 $event->data["script"][] = array ( 35 "type" => "text/javascript", 36 "src" => $this->get_asset($this->getConf('url_yaml')), 37 "_data" => "", 38 ); 39 40 $url_amcharts = $this->getConf('url_amcharts'); 41 42 $jsfiles = preg_split("/\|/", $this->getConf('amcharts_js')); 43 foreach($jsfiles as $jsfile) { 44 $event->data["script"][] = array ( 45 "type" => "text/javascript", 46 "src" => $this->get_asset($url_amcharts.'/'.$jsfile), 47 "_data" => "" 48 ); 49 } 50 51 $cssfiles = preg_split("/\|/", $this->getConf('amcharts_css')); 52 foreach($cssfiles as $cssfile) { 53 $event->data["link"][] = array ( 54 "type" => "text/css", 55 "rel" => "stylesheet", 56 "href" => $this->get_asset($url_amcharts.'/'.$cssfile) 57 ); 58 } 59 60 } 61 62 private function get_asset($resource) { 63 if(!preg_match('#^(?:(?:https?:)?/)?/#', $resource)) { 64 $info = $this->getInfo(); 65 $resource = DOKU_BASE."lib/plugins/".$info['base']."/assets/".$resource; 66 } 67 return $resource; 68 } 69 70} 71