1<?php
2/**
3* DokuWiki Plugin dirtylittlehelper (Syntax Component)
4*
5* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6* @author  KalleAPunkt
7*/
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) {
11die();
12}
13
14class syntax_plugin_dirtylittlehelper_sidebar extends DokuWiki_Syntax_Plugin
15{
16
17		var $togglesb_html = '<input type="hidden" id="dlh_left_tmp_sb" value="x">'
18						.'<input type="hidden" id="dlh_left_tmp_content" value="x">'
19						.'<input type="hidden" id="dlh_left_tmp_status" value="show">'
20						.'<button onClick="dlh_sb_toggle();" class="dlh_left_button_sb_toggle">&nbsp;</button>';
21
22		var $hidesb_html = '<script>document.addEventListener("DOMContentLoaded", function(event) { '
23						.' dlh_sb_toggle(\'hide\');'
24						.' }); </script>';
25
26		var $force_nosb = false;
27
28		var $nosb_html = '<style> '
29						.' #dokuwiki__aside{ display:none !important;}  '
30						.' #dokuwiki__aside *{ display:none !important;}   '
31						.' .showSidebar #dokuwiki__content > .pad{ margin-left:0px !important; } '
32						.' </style>';
33
34
35        /**
36        * @return string Syntax mode type
37        */
38        public function getType()
39        {
40                return 'substition';
41        }
42
43        /**
44        * @return string Paragraph type
45        */
46        public function getPType()
47        {
48                return 'normal';
49        }
50
51        /**
52        * @return int Sort order - Low numbers go before high numbers
53        */
54        public function getSort()
55        {
56                return 150;
57        }
58
59        /**
60        * Connect lookup pattern to lexer.
61        *
62        * @param string $mode Parser mode
63        */
64        public function connectTo($mode)
65        {
66                $this->Lexer->addSpecialPattern('\<dlh\.togglesb\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
67                $this->Lexer->addSpecialPattern('\<dlh\.nosb\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
68                $this->Lexer->addSpecialPattern('\<dlh\.hidesb\>',$mode,'plugin_dirtylittlehelper_'.$this->getPluginComponent());
69        }
70
71
72
73        /**
74        * Handle matches of the DLH syntax
75        *
76        * @param string       $match   The match of the syntax
77        * @param int          $state   The state of the handler
78        * @param int          $pos     The position in the document
79        * @param Doku_Handler $handler The handler
80        *
81        * @return array Data for the renderer
82        */
83        public function handle($match, $state, $pos, Doku_Handler $handler)
84        {
85
86                switch ($state) {
87
88                        case DOKU_LEXER_SPECIAL:
89
90                                if ($match == '<dlh.togglesb>'){
91									return array( $state, 'TOGGLESB',$match);
92
93                                }elseif(  $match == '<dlh.nosb>'){
94									$this->force_nosb = true;
95									return array($state, 'NOSB',$match);
96
97								}elseif(  $match == '<dlh.hidesb>'){
98									return array($state, 'HIDESB',$match);
99                                }
100
101						break;
102
103                }
104        return false;
105
106        } //handle
107
108
109        /**
110        * Render xhtml output or metadata
111        *
112        * @param string        $mode     Renderer mode (supported modes: xhtml)
113        * @param Doku_Renderer $renderer The renderer
114        * @param array         $data     The data from the handler() function
115        *
116        * @return bool If rendering was successful.
117        */
118        public function render($mode, Doku_Renderer $renderer, $data)
119        {
120                if ($mode == 'xhtml') {
121
122                        if(  $data[1]=='TOGGLESB' ){
123
124
125							if( $this->force_nosb == false){
126									$renderer->doc .= $this->togglesb_html;
127									return true;
128							}
129							return true;
130
131                        }elseif($data[1]=='HIDESB'){
132                                $renderer->doc .= $this->hidesb_html;
133								return true;
134
135                        }elseif($data[1]=='NOSB'){
136								$renderer->doc .= $this->nosb_html;
137								return true;
138
139						}
140
141
142                        return false;
143
144
145                } //mode xhtml
146
147				return false;
148
149        } //function render
150
151
152
153
154} //class
155
156
157
158
159
160
161