This repository has been archived by the owner on Nov 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
syntax.php
165 lines (137 loc) · 4.37 KB
/
syntax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/*
* Yurii's Gantt Plugin
*
* Copyright (C) 2020 Yurii K.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses
*/
use dokuwiki\plugin\yuriigantt\src\Driver\Embedded;
use dokuwiki\plugin\yuriigantt\src\Driver\Embedded\Handler;
class syntax_plugin_yuriigantt extends DokuWiki_Syntax_Plugin // \dokuwiki\Extension\SyntaxPlugin
{
const VIEW = 'dhtmlxgantt';
/**
* Connect lookup pattern to lexer.
*
* @param string $mode Parser mode
*/
public function connectTo($mode)
{
if ($mode === 'base') {
Embedded::addLexerPattern($this->Lexer, $mode);
}
}
/**
* {@inheritdoc}
*/
public function getPType()
{
return 'block';
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'substition';
}
/**
* {@inheritdoc}
*/
public function getSort()
{
return 1;
}
/**
* @param string $match
* @param int $state
* @param int $pos
* @param Doku_Handler|Handler $handler
* @return array
*/
public function handle($match, $state, $pos, \Doku_Handler $handler)
{
global $ID;
$data = mb_substr($match, mb_strpos($match, "\n") + 1);
$data = mb_substr($data, 0, mb_strrpos($data, "\n"));
$database = json_decode($data);
if (empty($database) && !empty($ID)) {
$database = Embedded::initDatabase($ID);
}
if (!empty($ID) && $ID !== $database->pageId) {
$database->pageId = $ID;
}
//special case for embedded db
if ($handler instanceof Handler) {
$handler->setDatabase($database);
}
return $database;
}
/**
* Handles the actual output creation.
*
* The function must not assume any other of the classes methods have been run
* during the object's current life. The only reliable data it receives are its
* parameters.
*
* The function should always check for the given output format and return false
* when a format isn't supported.
*
* $renderer contains a reference to the renderer object which is
* currently handling the rendering. You need to use it for writing
* the output. How this is done depends on the renderer used (specified
* by $format
*
* The contents of the $data array depends on what the handler() function above
* created
*
* @param string $format output format being rendered
* @param Doku_Renderer|\dokuwiki\plugin\yuriigantt\src\Driver\Embedded\Renderer $renderer the current renderer object
* @param array $data data created by handler()
* @return boolean rendered correctly? (however, returned value is not used at the moment)
*/
public function render($format, \Doku_Renderer $renderer, $data)
{
if (strtolower($format) === 'xhtml') {
return $this->renderXHtml($renderer, $data);
} elseif (strtolower($format) === Embedded::MODE) {
$renderer->raw(Embedded::embed($data));
return true;
}
return false;
}
protected function renderXHtml(Doku_Renderer $renderer, $data)
{
global $conf;
if ($data->dsn !== Embedded::DSN) {
return false; // NOTE: add new drivers here
}
$html = $this->viewRender(self::VIEW, [
'database' => $data,
'pluginName' => $this->getPluginName(),
'baseUrl' => DOKU_URL,
'lang' => $conf['lang'],
]);
$renderer->html($html);
return true;
}
protected function viewRender($view, array $params = [])
{
ob_start();
extract($params);
require __DIR__ . "/src/Views/{$view}.php";
return ob_get_clean();
}
}