-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsyntax.php
105 lines (81 loc) · 2.89 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
<?php
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_dtable extends DokuWiki_Syntax_Plugin {
function getPType(){
return 'block';
}
function getType() { return 'container'; }
function getSort() { return 400; }
function getAllowedTypes() {return array('container','formatting','substition');}
function connectTo($mode) { $this->Lexer->addEntryPattern('<dtab[0-9][0-9]>(?=.*</dtable>)',$mode,'plugin_dtable'); }
function postConnect() { $this->Lexer->addExitPattern('</dtable>','plugin_dtable'); }
function handle($match, $state, $pos, Doku_Handler $handler) {
global $INFO;
global $ID;
switch ($state) {
case DOKU_LEXER_ENTER :
try {
$table_nr = (int) substr($match, 5, 2);
return array($state, array($pos, $table_nr, p_get_metadata($INFO['id'] ?? null, 'dtable_pages')));
} catch(Exception $e)
{
return array($state, false);
}
case DOKU_LEXER_UNMATCHED : return array($state, $match);
case DOKU_LEXER_EXIT : return array($state, '');
}
return array();
}
function render($mode, Doku_Renderer $renderer, $data) {
global $ID;
if($mode == 'xhtml')
{
list($state,$match) = $data;
switch ($state) {
case DOKU_LEXER_ENTER :
if($match != false)
{
if (auth_quickaclcheck($ID) >= AUTH_EDIT)
{
$dtable = plugin_load('helper', 'dtable');
$pos = $match[0];
$table_nr = $match[1];
$dtable_pages = $match[2];
$id = $dtable_pages[$table_nr];
$filepath = wikiFN( $id );
$start_line = $dtable->line_nr($pos, $filepath) ;
//search for first row
$file_cont = explode("\n", io_readWikiPage($filepath, $id));
$start_line++;
$i = $start_line;
while( $i < count($file_cont) && strpos($file_cont[$i], '|') !== 0 && strpos($file_cont[$i], '^') !== 0)
$i += 1;
$start_line = $i;
$raw_lines = '';
while( $i < count($file_cont) && strpos( $file_cont[ $i ], '</dtable>' ) !== 0 )
{
$raw_lines .= $file_cont[$i]."\n";
$i++;
}
$lines = $dtable->rows($raw_lines, $id, $start_line);
$renderer->doc .= '<form class="dtable dynamic_form" id="dtable_'.$start_line.'_'.$id.'" action="'.DOKU_BASE.'lib/exe/ajax.php" method="post" data-table="'.htmlspecialchars(json_encode($lines)).'">';
$renderer->doc .= '<input type="hidden" class="dtable_field" value="dtable" name="call">';
//This is needed to correct linkwiz behaviour.
$renderer->doc .= '<input type="hidden" class="dtable_field" value="'.$id.'" name="id">';
}
}
break;
case DOKU_LEXER_UNMATCHED : $renderer->doc .= $renderer->_xmlEntities($match); break;
case DOKU_LEXER_EXIT :
if (auth_quickaclcheck($ID) >= AUTH_EDIT)
$renderer->doc .= "</form>";
break;
}
return true;
}
return false;
}
}