-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax.php
213 lines (184 loc) · 5.87 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/**
* Info Plugin: Displays information about various DokuWiki internals without "start" page
* Based on: nslist plugin by Andreas Gohr <andi@splitbrain.org>
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Zaher Dirkey <zaherdirkey@yahoo.com>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
require_once(DOKU_INC.'inc/search.php');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_pglist extends DokuWiki_Syntax_Plugin {
function getInfo(){
return array(
'author' => 'Zaher Dirkey',
'email' => 'zaherdirkey@yahoo.com',
'date' => '2018-11-16',
'name' => 'Page List Plugin',
'desc' => 'List pages of namespace, based on nslist.',
'url' => 'http://dokuwiki.org/plugin:pglist',
);
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
/**
* What about paragraphs?
*/
function getPType(){
return 'block';
}
/**
* Where to sort in?
*/
function getSort(){
return 302;
}
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('{{pglist>[^}]*}}',$mode,'plugin_pglist');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler){
global $ID;
$match = substr($match, 9, -2); //strip {{pglist> from start and }} from end
$conf = array(
'ns' => getNS($ID),
'depth' => 1,
'dirs' => 0,
'files' => 0,
'me' => 0,
'sibling' => 0, //todo
// 'same' => 0, /** If there is a dir have the same name of the file make it as namespace **/
'nostart' => 0,
'any' => 0,
'date' => 0,
'fsort' => 0,
'dsort' => 0
);
list($ns, $params) = explode(' ', $match, 2);
if ($ns) {
if ($ns === '*') {
$conf['ns'] = cleanID($ID);
}
else if ($ns[0] === '/')
$conf['ns'] = cleanID($ns);
else
$conf['ns'] = cleanID('/'.getNS($ID).'/'.$ns);
}
if(preg_match('/\bdirs\b/i',$params)) $conf['dirs'] = 1;
if(preg_match('/\bfiles\b/i',$params)) $conf['files'] = 1;
if(preg_match('/\bme\b/i',$params)) $conf['me'] = 1;
if(preg_match('/\bsibling\b/i',$params)) $conf['sibling'] = 1;
if(preg_match('/\bsame\b/i',$params)) $conf['same'] = 1;
if(preg_match('/\bany\b/i',$params)) $conf['any'] = 1;
if(preg_match('/\bnostart\b/i',$params)) $conf['nostart'] = 1;
if(preg_match('/\bdate\b/i',$params)) $conf['date'] = 1;
if(preg_match('/\bfsort\b/i',$params)) $conf['fsort'] = 1;
if(preg_match('/\bdsort\b/i',$params)) $conf['dsort'] = 1;
if(preg_match('/\b(\d+)\b/i',$params,$m)) $conf['depth'] = $m[1];
$conf['dir'] = str_replace(':','/',$conf['ns']);
// prepare data
return $conf;
}
/**
* Create output
*/
function render($format, Doku_Renderer $renderer, $data) {
global $conf;
global $lang;
global $ID;
if($format != 'xhtml')
return false;
$opts = array(
'depth' => $data['depth'],
'listfiles' => true,
'listdirs' => false,
'pagesonly' => true,
'firsthead' => true,
'meta' => true
);
if($data['dirs']) {
$opts['listdirs'] = true;
if ($data['files'])
$opts['listfiles'] = true;
else
$opts['listfiles'] = false;
}
// read the directory
$result = array();
search($result, $conf['datadir'], 'search_universal', $opts, $data['dir']);
if($data['fsort']){
usort($result,array($this,'_sort_file'));
}elseif($data['dsort']){
usort($result,array($this,'_sort_date'));
}else{
usort($result,array($this,'_sort_page'));
}
$start = cleanID($data['ns'].':'.$conf['start']);
$renderer->listu_open();
foreach($result as $item) {
$skip_it = false;
if ($data['nostart'] and ($item['file'] == $conf['start'].'.txt'))
$skip_it = true;
else if (!$data['me'] and ($item['id'] == $ID))
$skip_it = true;
else if (isHiddenPage($item['id']))
$skip_it = true;
else if ($item['type']=='d') {
$P = resolve_id($item['id'], $conf['start'], false);
if (!$data['any'] and !page_exists($P))
$skip_it = true;
} else
$P = ':'.$item['id'];
if (!$skip_it)
{
$renderer->listitem_open(1);
$renderer->listcontent_open();
$renderer->internallink($P);
if($data['date'])
$renderer->cdata(' '.dformat($item['mtime']));
$renderer->listcontent_close();
$renderer->listitem_close();
}
}
$renderer->listu_close();
return true;
}
function _sort_page($a,$b){
$r = strcmp($a['type'],$b['type']);
if ($r<>0)
return $r;
else
return strcmp($a['id'],$b['id']);
}
function _sort_file($a,$b){
$r = strcmp($a['type'],$b['type']);
if ($r<>0)
return $r;
else
return strcmp($a['file'],$b['file']);
}
function _sort_date($a,$b) {
if ($b['mtime'] < $a['mtime']) {
return -1;
} elseif($b['mtime'] > $a['mtime']) {
return 1;
} else {
return strcmp($a['id'],$b['id']);
}
}
}