1<?php 2/** 3 4 */ 5 6if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 8require_once(DOKU_PLUGIN.'syntax.php'); 9 10/** 11 * All DokuWiki plugins to extend the parser/rendering mechanism 12 * need to inherit from this class 13 */ 14class syntax_plugin_sectiontoggle extends DokuWiki_Syntax_Plugin { 15 16 17 function getType(){ 18 return 'substition'; 19 } 20 21 22 function getPType(){ 23 return 'block'; 24 } 25 26 27 function getSort(){ 28 return 199; 29 } 30 31 32 function connectTo($mode) { 33 $this->Lexer->addSpecialPattern('~~stoggle_buttons~~',$mode,'plugin_sectiontoggle'); 34 $this->Lexer->addSpecialPattern('~~stoggle_openDIV~~',$mode,'plugin_sectiontoggle'); 35 $this->Lexer->addSpecialPattern('~~stoggle_closeDIV~~',$mode,'plugin_sectiontoggle'); 36 } 37 38 39 function handle($match, $state, $pos, Doku_Handler $handler){ 40 $match = substr($match,10,-2); 41 switch ($state) { 42 case DOKU_LEXER_SPECIAL : 43 return array($state, $match); 44 } 45 return array($state,""); 46 } 47 48 49 function render($mode, Doku_Renderer $renderer, $data) { 50 if($mode == 'xhtml'){ 51 $renderer->nocache(); 52 list($state,$match) = $data; 53 switch ($state) { 54 case DOKU_LEXER_SPECIAL : 55 if($match == 'buttons') { 56 $open = $this->getLang('open_all'); 57 $close = $this->getLang('close_all'); 58 $renderer->doc .= '<p class="sectoggle"><button onclick = "SectionToggle.open_all();" style="white-space:nowrap;" >' . $open . '</button> <button onclick = "SectionToggle.close_all();" style="white-space:nowrap;" >' . $close .'</button></p>'; // ptype = 'block' 59 } 60 elseif($match == 'openDIV') { 61 $renderer->doc .= "\n<div id='section__toggle'>\n"; 62 } 63 elseif($match == 'closeDIV') { 64 $renderer->doc .= "\n</div>\n"; 65 } 66 return true; 67 } 68 } 69 return false; 70 } 71} 72 73?>