1<?php 2 3/** 4 * DokuWiki Plugin structsection (Action Component) 5 * 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7 * @author Michael Große <mic.grosse@googlemail.com> 8 */ 9 10class action_plugin_structsection extends \DokuWiki_Action_Plugin 11{ 12 13 /** 14 * Registers a callback function for a given event 15 * 16 * @param \Doku_Event_Handler $controller DokuWiki's event controller object 17 * @return void 18 */ 19 public function register(\Doku_Event_Handler $controller) 20 { 21 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addPageRevisionToJSINFO'); 22 $controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'appendPluginOutputToPage'); 23 $controller->register_hook('PLUGIN_STRUCT_TYPECLASS_INIT', 'BEFORE', $this, 'registerTypeWithStructPlugin'); 24 } 25 26 public function addPageRevisionToJSINFO(\Doku_Event $event, $param) 27 { 28 global $ACT; 29 30 if (act_clean($ACT) !== 'show') { 31 return; 32 } 33 global $JSINFO, $INFO; 34 $JSINFO['plugin_structsection'] = [ 35 'rev' => $INFO['currentrev'], 36 ]; 37 } 38 39 /** 40 * Event handler for PARSER_HANDLER_DONE 41 * 42 * @param \Doku_Event $event event object by reference 43 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 44 * handler was registered] 45 * @return void 46 */ 47 final public function appendPluginOutputToPage(\Doku_Event $event, $param) 48 { 49 static $instructionsAdded = false; 50 51 /** @var \helper_plugin_struct $struct */ 52 $struct = plugin_load('helper', 'struct'); 53 if (!$struct) { 54 return; 55 } 56 57 global $ACT; 58 59 if (act_clean($ACT) != 'show') { 60 return; 61 } 62 63 if ($instructionsAdded) { 64 return; 65 } 66 67 $instructionsAdded = true; 68 69 $last = end($event->data->calls); 70 71 $INSTRUCTION_POSITION_INDEX = 2; 72 $pos = $last[$INSTRUCTION_POSITION_INDEX]; 73 74 $event->data->calls[] = array( 75 'plugin', 76 array( 77 'structsection', array('pos' => $pos), DOKU_LEXER_SPECIAL, '', 78 ), 79 $pos, 80 ); 81 } 82 83 /** 84 * Event handler for PLUGIN_STRUCT_TYPECLASS_INIT 85 * 86 * @param \Doku_Event $event 87 * @param $param 88 */ 89 final public function registerTypeWithStructPlugin(\Doku_Event $event, $param) 90 { 91 $event->data['Section'] = 'dokuwiki\\plugin\\structsection\\types\\Section'; 92 } 93} 94 95// vim:ts=4:sw=4:et: 96