19d2d02ffSMichael Große<?php 2eadb8fe2SMichael Große 39d2d02ffSMichael Große/** 4284f9fc3SMichael Große * DokuWiki Plugin structsection (Action Component) 59d2d02ffSMichael Große * 69d2d02ffSMichael Große * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 79d2d02ffSMichael Große * @author Michael Große <mic.grosse@googlemail.com> 89d2d02ffSMichael Große */ 99d2d02ffSMichael Große 10eadb8fe2SMichael Großeclass action_plugin_structsection extends \DokuWiki_Action_Plugin 1115756b07SMichael Große{ 129d2d02ffSMichael Große 139d2d02ffSMichael Große /** 149d2d02ffSMichael Große * Registers a callback function for a given event 159d2d02ffSMichael Große * 16eadb8fe2SMichael Große * @param \Doku_Event_Handler $controller DokuWiki's event controller object 179d2d02ffSMichael Große * @return void 189d2d02ffSMichael Große */ 19eadb8fe2SMichael Große public function register(\Doku_Event_Handler $controller) 2015756b07SMichael Große { 21*cb058b5aSMichael Große $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'addPageRevisionToJSINFO'); 2215756b07SMichael Große $controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'appendPluginOutputToPage'); 2315756b07SMichael Große $controller->register_hook('PLUGIN_STRUCT_TYPECLASS_INIT', 'BEFORE', $this, 'registerTypeWithStructPlugin'); 249d2d02ffSMichael Große } 259d2d02ffSMichael Große 26*cb058b5aSMichael Große public function addPageRevisionToJSINFO(\Doku_Event $event, $param) 27*cb058b5aSMichael Große { 28*cb058b5aSMichael Große global $ACT; 29*cb058b5aSMichael Große 30*cb058b5aSMichael Große if (act_clean($ACT) !== 'show') { 31*cb058b5aSMichael Große return; 32*cb058b5aSMichael Große } 33*cb058b5aSMichael Große global $JSINFO, $INFO; 34*cb058b5aSMichael Große $JSINFO['plugin_structsection'] = [ 35*cb058b5aSMichael Große 'rev' => $INFO['currentrev'], 36*cb058b5aSMichael Große ]; 37*cb058b5aSMichael Große } 38*cb058b5aSMichael Große 399d2d02ffSMichael Große /** 4015756b07SMichael Große * Event handler for PARSER_HANDLER_DONE 419d2d02ffSMichael Große * 42eadb8fe2SMichael Große * @param \Doku_Event $event event object by reference 439d2d02ffSMichael Große * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 449d2d02ffSMichael Große * handler was registered] 459d2d02ffSMichael Große * @return void 469d2d02ffSMichael Große */ 47eadb8fe2SMichael Große final public function appendPluginOutputToPage(\Doku_Event $event, $param) 4815756b07SMichael Große { 491d58a283SMichael Große static $instructionsAdded = false; 501d58a283SMichael Große 51eadb8fe2SMichael Große /** @var \helper_plugin_struct $struct */ 526b380169SMichael Große $struct = plugin_load('helper', 'struct'); 536b380169SMichael Große if (!$struct) { 546b380169SMichael Große return; 556b380169SMichael Große } 566b380169SMichael Große 576b380169SMichael Große global $ACT; 586b380169SMichael Große 596b380169SMichael Große if (act_clean($ACT) != 'show') { 606b380169SMichael Große return; 616b380169SMichael Große } 626b380169SMichael Große 631d58a283SMichael Große if ($instructionsAdded) { 641d58a283SMichael Große return; 651d58a283SMichael Große } 661d58a283SMichael Große 671d58a283SMichael Große $instructionsAdded = true; 681d58a283SMichael Große 696b380169SMichael Große $last = end($event->data->calls); 7078317c4bSMichael Große 7178317c4bSMichael Große $INSTRUCTION_POSITION_INDEX = 2; 7278317c4bSMichael Große $pos = $last[$INSTRUCTION_POSITION_INDEX]; 736b380169SMichael Große 746b380169SMichael Große $event->data->calls[] = array( 756b380169SMichael Große 'plugin', 766b380169SMichael Große array( 77284f9fc3SMichael Große 'structsection', array('pos' => $pos), DOKU_LEXER_SPECIAL, '', 786b380169SMichael Große ), 796b380169SMichael Große $pos, 806b380169SMichael Große ); 816b380169SMichael Große } 826b380169SMichael Große 8315756b07SMichael Große /** 8415756b07SMichael Große * Event handler for PLUGIN_STRUCT_TYPECLASS_INIT 8515756b07SMichael Große * 86eadb8fe2SMichael Große * @param \Doku_Event $event 8715756b07SMichael Große * @param $param 8815756b07SMichael Große */ 89eadb8fe2SMichael Große final public function registerTypeWithStructPlugin(\Doku_Event $event, $param) 9015756b07SMichael Große { 91284f9fc3SMichael Große $event->data['Section'] = 'dokuwiki\\plugin\\structsection\\types\\Section'; 929d2d02ffSMichael Große } 939d2d02ffSMichael Große} 949d2d02ffSMichael Große 959d2d02ffSMichael Große// vim:ts=4:sw=4:et: 96