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           list($state,$match) = $data;
52            switch ($state) {
53              case DOKU_LEXER_SPECIAL :
54               if($match == 'buttons') {
55                $open = $this->getLang('open_all');
56                $close = $this->getLang('close_all');
57                $renderer->doc .= '<p class="sectoggle"><button onclick = "SectionToggle.open_all();" style="white-space:nowrap;" >' . $open . '</button>&nbsp;&nbsp;<button onclick = "SectionToggle.close_all();" style="white-space:nowrap;" >' . $close .'</button></p>';     // ptype = 'block'
58                }
59                elseif($match == 'openDIV') {
60                   $renderer->doc .= "\n<div id='section__toggle'>\n";
61                }
62                elseif($match == 'closeDIV') {
63                   $renderer->doc .= "\n</div>\n";
64                }
65               return true;
66            }
67        }
68        return false;
69    }
70}
71
72?>