1<?php 2/** 3 * DokuWiki Plugin copycode (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Nicolas Prigent <mail.nicolasprigent@gmail.com> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) { 11 die(); 12} 13 14class action_plugin_copycode_copycode 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 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'pass_settings_js'); 27 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this,'hook_copycode_js'); 28 } 29 30 /** 31 * [Custom event handler which performs action] 32 * 33 * Called for event: 34 * 35 * @param Doku_Event $event event object by reference 36 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 37 * handler was registered] 38 * 39 * @return void 40 */ 41 public function hook_copycode_js(Doku_Event $event, $param) 42 { 43 // this code does not need execution (anymore?), as 'script.js' is automatically merged into global js.php. 44 // $event->data['script'][] = array( 45 // 'type' => 'text/javascript', 46 // 'charset' => 'utf-8', 47 // '_data' => '', 48 // 'src' => DOKU_PLUGIN.'copycode/script.js'); 49 } 50 51 /** 52 * Event handler to pass settings to JavaScript via $JSINFO 53 * 54 * Called for event: 55 * 56 * @param Doku_Event $event event object by reference 57 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 58 * handler was registered] 59 * 60 * @return void 61 */ 62 public function pass_settings_js(Doku_Event $event, $param) 63 { 64 65 global $JSINFO; 66 if (empty($JSINFO['plugins'])) { 67 $JSINFO['plugins'] = []; 68 } 69 $JSINFO['plugins']['copycode'] = [ 70 'EnableForInline' => $this->getConf('enable_for_inline', 0) 71 ]; 72 } 73 74} 75 76