1<?php
2/**
3 * Plugin twcheckliste:
4 * v1.0
5 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author   web@agentur-triebwerk.de
7 */
8
9if (!defined('DOKU_INC'))
10	define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/');
11if (!defined('DOKU_PLUGIN'))
12	define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
13
14require_once (DOKU_INC . 'inc/parserutils.php');
15require_once (DOKU_PLUGIN . 'syntax.php');
16
17/**
18 * All DokuWiki plugins to extend the parser/rendering mechanism
19 * need to inherit from this class
20 */
21class syntax_plugin_twcheckliste extends DokuWiki_Syntax_Plugin {
22
23	function getType() {
24		return 'container';
25	}
26
27	function getPType() {
28		return 'stack';
29	}
30
31	function getAllowedTypes() {
32		return array('container', 'baseonly', 'substition', 'protected', 'disabled', 'formatting', 'paragraphs');
33	}
34
35	function getSort() {
36		return 189;
37	}
38
39	function accepts($mode) {
40		if ($mode == substr(get_class($this), 7))
41			return true;
42		return parent::accepts($mode);
43	}
44
45	function connectTo($mode) {
46		$this -> Lexer -> addEntryPattern('<checkliste.*?>(?=.*?</checkliste>)', $mode, 'plugin_twcheckliste');
47	}
48
49	function postConnect() {
50		$this -> Lexer -> addExitPattern('</checkliste>', 'plugin_twcheckliste');
51	}
52
53	function handle($match, $state, $pos, &$handler) {
54
55		switch ($state) {
56			case DOKU_LEXER_ENTER :
57				$return = array('active' => 'true', 'element' => Array(), 'onHidden' => '', 'onVisible' => '', 'initialState' => 'hidden', 'state' => $state, 'printHead' => true, 'bytepos_start' => $pos, 'edit' => false, 'editText' => $this -> getLang('edit'), 'onExportPdf' => '');
58				$match = substr($match, 11, -1);
59				if (trim($match) == "angebot") {
60					$this -> match_kind = 1;
61				} else {
62					$this -> match_kind = 0;
63				}
64
65				return $return;
66
67			case DOKU_LEXER_UNMATCHED :
68				$html = $this -> replaceTags($match);
69				print_r($match);
70				print_r($html);
71				return array($state, $html);
72			default :
73				return array('state' => $state, 'bytepos_end' => $pos + strlen($match));
74		}
75	}
76
77	private function _grepOption(&$options, $tag, &$match) {
78		preg_match("/$tag *= *\"([^\"]*)\" ?/i", $match, $text);
79		if (count($text) != 0) {
80			$match = str_replace($text[0], '', $match);
81			$options[$tag] = $text[1];
82		}
83	}
84
85	function render($mode, &$renderer, $data) {
86
87		if ($mode == 'xhtml') {
88			switch ($data['state']) {
89				case DOKU_LEXER_ENTER :
90
91					$renderer -> doc .= '<link href="/lib/plugins/twcheckliste/style.css" type="text/css" rel="stylesheet" /><form action="lib/plugins/twcheckliste/theme_twCheckliste/tw_checklist.php" method="post" target="_blank"><div class="checkliste" id="checkliste"><input type="hidden" name="match_kind" value="' . $this -> match_kind . '" />';
92					break;
93
94				case DOKU_LEXER_UNMATCHED :
95					$text = $renderer -> _xmlEntities($data['text']);
96					if (preg_match("/^[ \t]*={2,}[^\n]+={2,}[ \t]*$/", $text, $match)) {
97						$title = trim($match[0]);
98						$level = 7 - strspn($title, '=');
99						if ($level < 1)
100							$level = 1;
101						$title = trim($title, '=');
102						$title = trim($title);
103						$renderer -> header($title, $level, 0);
104					} else {
105						$renderer -> doc .= $text;
106					}
107
108					break;
109
110				case DOKU_LEXER_EXIT :
111					$renderer -> doc .= '</div><br /><div style="color: red;"><b>Wegen aktuellen Bug im Druck von Webkit Browser bitte Firefox verwenden !!!</b></div><br /><input type="submit" class="button" name="checkliste" value="'.$this -> getLang('btn_generieren').'" /> </form>';
112					$renderer -> doc = str_replace ("ROLLE_PM<", "<span class='rolle_pm'>ROLLE_PM</span><", $renderer -> doc);
113					$renderer -> doc = str_replace ("UNCHECKED<", "<span class='unchecked'>UNCHECKED</span><", $renderer -> doc);
114
115					//close hiddenBody and hiddenGlobal
116					/*if (array_pop($this -> editableBlocks)) {
117					 $renderer -> finishSectionEdit($data['bytepos_end']);
118					 }*/
119					break;
120			}
121			return true;
122		}
123
124		return false;
125	}
126
127	function replaceTags($match) {
128
129		$search = array('#CLsection#i', '#CLarea#i', '#CLcheckpoint#i', '#CLcoption#i');
130
131		$replace = array('h2', 'h3', 'h4', 'li');
132
133		return preg_replace($search, $replace, $match);
134	}
135
136}
137