1<?php 2/** 3 * DokuWiki Plugin c3chart (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Jason Xun Xu <dev@jasonxu.net> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12class action_plugin_c3chart 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 22 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_tpl_metaheader_output'); 23 24 } 25 26 /** 27 * [Custom event handler which performs action] 28 * 29 * @param Doku_Event $event event object by reference 30 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 31 * handler was registered] 32 * @return void 33 */ 34 35 public function handle_tpl_metaheader_output(Doku_Event &$event, $param) { 36 $event->data["script"][] = array ( 37 "type" => "text/javascript", 38 "src" => $this->get_asset('url_yaml'), 39 "_data" => "", 40 ); 41 $event->data["script"][] = array ( 42 "type" => "text/javascript", 43 "src" => $this->get_asset('url_d3'), 44 "_data" => "", 45 ); 46 $event->data["script"][] = array ( 47 "type" => "text/javascript", 48 "src" => $this->get_asset('url_c3'), 49 "_data" => "", 50 ); 51 $event->data["link"][] = array ( 52 "type" => "text/css", 53 "rel" => "stylesheet", 54 "href" => $this->get_asset('url_c3_css'), 55 ); 56 } 57 58 private function get_asset($asset) { 59 $u = $this->getConf($asset); 60 if(!preg_match('#^(?:(?:https?:)?/)?/#', $u)) { 61 $info = $this->getInfo(); 62 $u = DOKU_BASE."lib/plugins/".$info['base']."/assets/".$u; 63 } 64 return $u; 65 } 66 67} 68 69// vim:ts=4:sw=4:et: 70