182c064c1SAndreas Gohr<?php 282c064c1SAndreas Gohr/** 382c064c1SAndreas Gohr * DokuWiki Plugin struct (Action Component) 482c064c1SAndreas Gohr * 582c064c1SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 682c064c1SAndreas Gohr * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 782c064c1SAndreas Gohr */ 882c064c1SAndreas Gohr 982c064c1SAndreas Gohr// must be run within Dokuwiki 1082c064c1SAndreas Gohrif(!defined('DOKU_INC')) die(); 1182c064c1SAndreas Gohr 1282c064c1SAndreas Gohr/** 1382c064c1SAndreas Gohr * Class action_plugin_struct_output 1482c064c1SAndreas Gohr * 1582c064c1SAndreas Gohr * This action component handles the automatic output of all schema data that has been assigned 1682c064c1SAndreas Gohr * to the current page by appending the appropriate instruction to the handler calls. 1782c064c1SAndreas Gohr * 1882c064c1SAndreas Gohr * The real output creation is done within the syntax component 1982c064c1SAndreas Gohr * @see syntax_plugin_struct_output 2082c064c1SAndreas Gohr */ 2182c064c1SAndreas Gohrclass action_plugin_struct_output extends DokuWiki_Action_Plugin { 2282c064c1SAndreas Gohr 2382c064c1SAndreas Gohr /** 2482c064c1SAndreas Gohr * Registers a callback function for a given event 2582c064c1SAndreas Gohr * 2682c064c1SAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 2782c064c1SAndreas Gohr * @return void 2882c064c1SAndreas Gohr */ 2982c064c1SAndreas Gohr public function register(Doku_Event_Handler $controller) { 3082c064c1SAndreas Gohr $controller->register_hook('PARSER_HANDLER_DONE', 'AFTER', $this, 'handle_output'); 3182c064c1SAndreas Gohr 3282c064c1SAndreas Gohr } 3382c064c1SAndreas Gohr 3482c064c1SAndreas Gohr /** 3582c064c1SAndreas Gohr * Appends the instruction to render our syntax output component to each page 36*28b818ceSAndreas Gohr * after the first found headline or the very begining if no headline was found 3782c064c1SAndreas Gohr * 3882c064c1SAndreas Gohr * @param Doku_Event $event 3982c064c1SAndreas Gohr * @param $param 4082c064c1SAndreas Gohr */ 4182c064c1SAndreas Gohr public function handle_output(Doku_Event &$event, $param) { 4282c064c1SAndreas Gohr global $ACT; 435a1eab78SAndreas Gohr global $ID; 44a8db5950SAndreas Gohr // blank $ACT happens when instructions are rendered in indexer 45a8db5950SAndreas Gohr if(!blank($ACT) && $ACT != 'show') return; //FIXME what about export_*? 4602481400SAndreas Gohr if(!page_exists($ID)) return; 4782c064c1SAndreas Gohr 48*28b818ceSAndreas Gohr $ins = -1; 49*28b818ceSAndreas Gohr $pos = 0; 50*28b818ceSAndreas Gohr foreach($event->data->calls as $num => $call) { 51*28b818ceSAndreas Gohr // try to find the first header 52*28b818ceSAndreas Gohr if($call[0] == 'header') { 53*28b818ceSAndreas Gohr $pos = $call[2]; 54*28b818ceSAndreas Gohr $ins = $num; 55*28b818ceSAndreas Gohr break; 56*28b818ceSAndreas Gohr } 5782c064c1SAndreas Gohr 58*28b818ceSAndreas Gohr // abort when after we looked at the first 150 bytes 59*28b818ceSAndreas Gohr if($call[3] > 150) { 60*28b818ceSAndreas Gohr break; 61*28b818ceSAndreas Gohr } 62*28b818ceSAndreas Gohr } 63*28b818ceSAndreas Gohr 64*28b818ceSAndreas Gohr // insert our own call after the found position 65*28b818ceSAndreas Gohr array_splice( 66*28b818ceSAndreas Gohr $event->data->calls, 67*28b818ceSAndreas Gohr $ins+1, 68*28b818ceSAndreas Gohr 0, 69*28b818ceSAndreas Gohr array( 70*28b818ceSAndreas Gohr array( 7182c064c1SAndreas Gohr 'plugin', 7282c064c1SAndreas Gohr array( 735a1eab78SAndreas Gohr 'struct_output', array('pos' => $pos), DOKU_LEXER_SPECIAL, '' 7482c064c1SAndreas Gohr ), 7582c064c1SAndreas Gohr $pos 76*28b818ceSAndreas Gohr ) 77*28b818ceSAndreas Gohr ) 7882c064c1SAndreas Gohr ); 7982c064c1SAndreas Gohr } 8082c064c1SAndreas Gohr 8182c064c1SAndreas Gohr} 8282c064c1SAndreas Gohr 8382c064c1SAndreas Gohr// vim:ts=4:sw=4:et: 84