1<?php
2/**
3 * Toggle Plugin: toggles visibility of texts with syntax <TOGGLE></TOGGLE>
4 *
5 * @license		GPL3 (http://www.gnu.org/licenses/gpl.html)
6 * @author	 	condero Aktiengesellschaft <info@condero.com>
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_PLUGIN.'syntax.php');
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_toggle extends DokuWiki_Syntax_Plugin {
18
19	/**
20	 * return some info
21	 */
22	function getInfo(){
23		return array(
24			'author'	=> 'condero Aktiengesellschaft',
25			'email'		=> 'info@condero.com',
26			'date'		=> '2017-04-07',
27			'name'		=> 'Toggle Plugin',
28			'desc'		=> 'This plugin toggles visibility of text.',
29			'url'		=> 'http://www.dokuwiki.org/plugin:toggle',
30		);
31	}
32
33	/**
34	 * What kind of syntax are we?
35	 */
36	function getType(){
37		return 'protected';
38	}
39
40	/**
41	 * Where to sort in?
42	 */
43	function getSort(){
44		return 202;
45	}
46
47	/**
48	 * Connect pattern to lexer
49	 */
50	function connectTo($mode) {
51		$this->Lexer->addEntryPattern('<TOGGLE>(?=.*?</TOGGLE>)',$mode,'plugin_toggle');
52	}
53
54	function postConnect() {
55		$this->Lexer->addExitPattern('</TOGGLE>','plugin_toggle');
56	}
57
58	/**
59	 * Handle the match
60	 */
61	function handle($match, $state, $pos, &$handler){
62		switch ($state) {
63			case DOKU_LEXER_ENTER :
64				return array($state, '');
65			break;
66			case DOKU_LEXER_UNMATCHED :
67				return array($state, $match);
68			break;
69			case DOKU_LEXER_EXIT :
70				return array($state, '');
71			break;
72		}
73		return array();
74	}
75
76	/**
77	 * Create output
78	 */
79	function render($mode, &$renderer, $data) {
80		if($mode == 'xhtml'){
81			list($state, $match) = $data;
82			switch ($state) {
83				case DOKU_LEXER_ENTER :
84					$renderer->doc.= '';
85					break;
86				case DOKU_LEXER_UNMATCHED :
87					$renderer->doc.= '<span class="plugin_toggle" style="padding:2px; border:1px solid; cursor:pointer;" onclick="javascript:this.innerHTML=this.innerHTML==\'********\'?this.dataset.text:\'********\';" data-text="'.$match.'">********</span>';
88					break;
89				case DOKU_LEXER_EXIT :
90					$renderer->doc .= "";
91					break;
92			}
93			return true;
94		}
95		return false;
96	}
97}
98?>
99