1300ce4a2SGerry Weißbach<?php 2300ce4a2SGerry Weißbach/** 3300ce4a2SGerry Weißbach * Siteexport Plugin 4300ce4a2SGerry Weißbach * 5300ce4a2SGerry Weißbach * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6300ce4a2SGerry Weißbach * @author i-net software <tools@inetsoftware.de> 7300ce4a2SGerry Weißbach * @author Gerry Weissbach <gweissbach@inetsoftware.de> 8300ce4a2SGerry Weißbach */ 9300ce4a2SGerry Weißbach 10a8c17ab5Si-net /// softwareif (!defined('DOKU_INC')) define('DOKU_INC', /** @scrutinizer ignore-type */ realpath(dirname(__FILE__) . '/../../') . '/'); 11300ce4a2SGerry Weißbachif (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 12300ce4a2SGerry Weißbachrequire_once(DOKU_PLUGIN . 'syntax.php'); 13300ce4a2SGerry Weißbach 14300ce4a2SGerry Weißbach/** 15300ce4a2SGerry Weißbach * All DokuWiki plugins to extend the parser/rendering mechanism 16300ce4a2SGerry Weißbach * need to inherit from this class 17300ce4a2SGerry Weißbach */ 18300ce4a2SGerry Weißbachclass syntax_plugin_siteexport_toctools extends DokuWiki_Syntax_Plugin { 19300ce4a2SGerry Weißbach 2074627711SGerry Weißbach protected $special_pattern = '<mergehint\b[^>\r\n]*?/>'; 2174627711SGerry Weißbach protected $entry_pattern = '<mergehint\b.*?>(?=.*?</mergehint>)'; 2274627711SGerry Weißbach protected $exit_pattern = '</mergehint>'; 23300ce4a2SGerry Weißbach 24774ba46fSGerry Weißbach public function getType(){ return 'substition';} 25774ba46fSGerry Weißbach public function getAllowedTypes() { return array('container', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); } 26774ba46fSGerry Weißbach public function getPType(){ return 'stack';} 27774ba46fSGerry Weißbach public function getSort(){ return 999; } 28300ce4a2SGerry Weißbach 29300ce4a2SGerry Weißbach /** 30300ce4a2SGerry Weißbach * Connect pattern to lexer 31300ce4a2SGerry Weißbach */ 32774ba46fSGerry Weißbach public function connectTo($mode) { 3374627711SGerry Weißbach $this->Lexer->addSpecialPattern($this->special_pattern,$mode,'plugin_siteexport_toctools'); 3474627711SGerry Weißbach $this->Lexer->addEntryPattern($this->entry_pattern,$mode,'plugin_siteexport_toctools'); 3574627711SGerry Weißbach } 3674627711SGerry Weißbach 37774ba46fSGerry Weißbach public function postConnect() { 3874627711SGerry Weißbach $this->Lexer->addExitPattern($this->exit_pattern, 'plugin_siteexport_toctools'); 39300ce4a2SGerry Weißbach } 40300ce4a2SGerry Weißbach 41268cf88bSGerry Weißbach private function findPreviousSectionOpen( Doku_Handler $handler ) { 42268cf88bSGerry Weißbach foreach( array_reverse( $handler->calls ) as $call ) { 43268cf88bSGerry Weißbach if ( $calls[0] == 'section_open' ) { 44268cf88bSGerry Weißbach return $calls[1][0]; 45268cf88bSGerry Weißbach } 46268cf88bSGerry Weißbach } 47268cf88bSGerry Weißbach return 1; 48268cf88bSGerry Weißbach } 49268cf88bSGerry Weißbach 50268cf88bSGerry Weißbach private function addInstructionstoHandler( $match, $state, $pos, Doku_Handler $handler, $instructions ) { 51268cf88bSGerry Weißbach 52*16367ea8SGerry Weißbach if ($handler->getStatus('section')) { 53268cf88bSGerry Weißbach $handler->_addCall('section_close', array(), $pos); 54268cf88bSGerry Weißbach } 55268cf88bSGerry Weißbach 56268cf88bSGerry Weißbach // We need to add the current plugin first and then open the section again. 57268cf88bSGerry Weißbach $level = $this->findPreviousSectionOpen( $handler ); 58268cf88bSGerry Weißbach $handler->_addCall('plugin', array('siteexport_toctools', $instructions, $state), $pos); 59268cf88bSGerry Weißbach $handler->_addCall('section_open', array($level), $pos+strlen($match) ); 60268cf88bSGerry Weißbach } 61268cf88bSGerry Weißbach 62300ce4a2SGerry Weißbach /** 63300ce4a2SGerry Weißbach * Handle the match 64300ce4a2SGerry Weißbach */ 65774ba46fSGerry Weißbach public function handle($match, $state, $pos, Doku_Handler $handler){ 6674627711SGerry Weißbach global $conf; 6774627711SGerry Weißbach switch ($state) { 6874627711SGerry Weißbach case DOKU_LEXER_ENTER: 6974627711SGerry Weißbach case DOKU_LEXER_SPECIAL: 7074627711SGerry Weißbach $data = trim(substr($match,strpos($match,' '),-1)," \t\n/"); 71268cf88bSGerry Weißbach $this->addInstructionstoHandler( $match, $state, $pos, $handler, array('mergehint', 'start', $data, sectionid( $data ) ) ); 72268cf88bSGerry Weißbach break; 7374627711SGerry Weißbach case DOKU_LEXER_UNMATCHED: 7474627711SGerry Weißbach $handler->_addCall('cdata', array($match), $pos); 7574627711SGerry Weißbach break; 7674627711SGerry Weißbach case DOKU_LEXER_EXIT: 77268cf88bSGerry Weißbach $this->addInstructionstoHandler( $match, $state, $pos, $handler, array('mergehint', 'end', 'syntax' ) ); 7874627711SGerry Weißbach break; 7974627711SGerry Weißbach } 8074627711SGerry Weißbach return false; 81300ce4a2SGerry Weißbach } 82300ce4a2SGerry Weißbach 83300ce4a2SGerry Weißbach /** 84300ce4a2SGerry Weißbach * Create output 85300ce4a2SGerry Weißbach */ 86a8c17ab5Si-net /// software public function render($mode, Doku_Renderer $renderer, $data) { 87300ce4a2SGerry Weißbach if ($mode == 'xhtml') { 88300ce4a2SGerry Weißbach list( $type, $pos, $title, $id ) = $data; 89300ce4a2SGerry Weißbach if ( $type == 'mergehint' ) { 90300ce4a2SGerry Weißbach if ( $pos == 'start' ) { 91300ce4a2SGerry Weißbach $renderer->doc .= '<!-- MergeHint Start for "' . $title . '" -->'; 9206a81c5cSGerry Weißbach $renderer->doc .= '<div id="' . $id . '" class="siteexport mergehintwrapper"><aside class="mergehint">' . $title . '</aside><div class="mergehintcontent">'; 93300ce4a2SGerry Weißbach } else { 9406a81c5cSGerry Weißbach $renderer->doc .= '</div></div>'; 95300ce4a2SGerry Weißbach $renderer->doc .= '<!-- MergeHint End for "' . $title . '" -->'; 96300ce4a2SGerry Weißbach } 97300ce4a2SGerry Weißbach } else { 98300ce4a2SGerry Weißbach $renderer->doc .= "<br style=\"page-break-after:always;\" />"; 99300ce4a2SGerry Weißbach } 100300ce4a2SGerry Weißbach return true; 101300ce4a2SGerry Weißbach } 102300ce4a2SGerry Weißbach return false; 103300ce4a2SGerry Weißbach } 104300ce4a2SGerry Weißbach} 105300ce4a2SGerry Weißbach 106300ce4a2SGerry Weißbach//Setup VIM: ex: et ts=4 enc=utf-8 :