1<?php 2/** 3 * DokuWiki Plugin abc2 (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Anika Henke <anika@selfthinker.org> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) { 11 die(); 12} 13 14class action_plugin_abc2 extends DokuWiki_Action_Plugin 15{ 16 17 /** 18 * Registers a callback function for a given event 19 * 20 * @param Doku_Event_Handler $controller DokuWiki's event controller object 21 * 22 * @return void 23 */ 24 public function register(Doku_Event_Handler $controller) 25 { 26 global $ACT; 27 28 // only load JS when it is needed 29 $allowedAct = array('show', 'preview', 'export_xhtml', 'export_xhtmlbody'); 30 $showJS = in_array(act_clean($ACT), $allowedAct); 31 // abc2svg parses abc wherever it is, including within the edit textarea 32 // that is why it cannot be used in preview mode 33 if (($this->getConf('library') == 'abc2svg') && (act_clean($ACT) == 'preview')) { 34 $showJS = false; 35 } 36 37 if ($this->getConf('abcok') && $showJS) { 38 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_addJavascript'); 39 } 40 } 41 42 /** 43 * Add JavaScripts, depending on chosen abc library 44 * 45 * Called for event: TPL_METAHEADER_OUTPUT 46 * 47 * @param Doku_Event $event event object by reference 48 * 49 * @return void 50 */ 51 public function _addJavascript(Doku_Event $event) 52 { 53 switch ($this->getConf('library')) { 54 case 'abcjs': 55 $event->data['script'][] = array( 56 'charset' => 'utf-8', 57 '_data' => '', 58 'src' => DOKU_BASE.'lib/plugins/abc2/abc-libraries/abcjs/abcjs_plugin-midi_6.0.0-beta.25-min.js' 59 ); 60 break; 61 62 case 'abc2svg': 63 $event->data['script'][] = array( 64 'charset' => 'utf-8', 65 '_data' => '', 66 'src' => DOKU_BASE.'lib/plugins/abc2/abc-libraries/abc2svg/abcweb-1.js' 67 ); 68 if (!$this->getConf('stayLibre')) { 69 $event->data['script'][] = array( 70 'charset' => 'utf-8', 71 '_data' => '', 72 'src' => DOKU_BASE.'lib/plugins/abc2/abc-libraries/abc2svg/snd-1.js' 73 ); 74 } 75 break; 76 77 case 'abc-ui': 78 $event->data['script'][] = array( 79 'charset' => 'utf-8', 80 '_data' => '', 81 'src' => DOKU_BASE.'lib/plugins/abc2/abc-libraries/abc-ui/abc-ui-1.0.0.min.js' 82 ); 83 break; 84 } 85 } 86 87} 88