-
Notifications
You must be signed in to change notification settings - Fork 3
/
syntax.php
137 lines (110 loc) · 3.25 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
<?php
/**
* Info Plugin: Displays information about various DokuWiki internals
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <[email protected]>
*/
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_nslist extends DokuWiki_Syntax_Plugin {
/**
* 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('{{nslist>[^}]*}}',$mode,'plugin_nslist');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler){
global $ID;
$match = substr($match,9,-2); //strip {{nslist> from start and }} from end
$conf = array(
'ns' => getNS($ID),
'depth' => 1,
'date' => 1,
'dsort' => 1
);
list($ns,$params) = explode(' ',$match,2);
$ns = cleanID($ns);
if(preg_match('/\bnodate\b/i',$params)) $conf['date'] = 0;
if(preg_match('/\bnodsort\b/i',$params)) $conf['dsort'] = 0;
if(preg_match('/\b(\d+)\b/i',$params,$m)) $conf['depth'] = $m[1];
if($ns) $conf['ns'] = $ns;
$conf['dir'] = str_replace(':','/',$conf['ns']);
// prepare data
return $conf;
}
/**
* Create output
*/
function render($format, Doku_Renderer $R, $data) {
global $conf;
global $lang;
if($format != 'xhtml') return false;
$opts = array(
'depth' => $data['depth'],
'listfiles' => true,
'listdirs' => false,
'pagesonly' => true,
'meta' => true
);
// read the directory
$result = array();
search($result,$conf['datadir'],'search_universal',$opts,$data['dir']);
if($data['dsort']){
usort($result,array($this,'_sort_date'));
}else{
usort($result,array($this,'_sort_page'));
}
$R->listu_open();
foreach($result as $item){
$R->listitem_open(1);
$R->listcontent_open();
$R->internallink(':'.$item['id']);
if($data['date']) $R->cdata(' '.dformat($item['mtime']));
$R->listcontent_close();
$R->listitem_close();
}
$R->listu_close();
return true;
}
function _sort_page($a,$b){
return strcmp($a['id'],$b['id']);
}
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']);
}
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :