-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsyntax.php
More file actions
61 lines (53 loc) · 1.81 KB
/
syntax.php
File metadata and controls
61 lines (53 loc) · 1.81 KB
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
<?php
/**
* DokuWiki Plugin numberof (Syntax Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author S.C. Yoo <dryoo@live.com>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
class syntax_plugin_numberof extends DokuWiki_Syntax_Plugin {
public function getType() { return 'substition'; }
public function getSort() { return 32; }
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('\{\{NUMBEROF[^\}]*\}\}',$mode,'plugin_numberof');
}
public function handle($match, $state, $pos, Doku_Handler $handler){
global $conf;
$list = array(
'file_count' => 0,
'dir_count' => 0,
'dir_nest' => 0,
);
$match=substr($match,10,-2);
$matches = sexplode(">", $match, 2, '');
$matches[1]=str_replace(":","/",$matches[1]);
switch ($matches[0]) {
case "PAGES":
search($list,$conf['datadir'].$matches[1],array($this,'_search_count'),array('all'=>false),'');
break;
case "MEDIAS":
search($list,$conf['mediadir'].$matches[1],array($this,'_search_count'),array('all'=>true));
break;
}
return ['count' => $list['file_count']];
}
public function render($mode, Doku_Renderer $renderer, $data) {
if($mode != 'xhtml') return false;
$renderer->doc .= $data['count'];
return true;
}
function _search_count(&$data,$base,$file,$type,$lvl,$opts){
if($type == 'd'){
if($data['dir_nest'] < $lvl) $data['dir_nest'] = $lvl;
$data['dir_count']++;
return true;
}
if($opts['all'] || substr($file,-4) == '.txt'){
$data['file_count']++;
}
return false;
}
}
// vim:ts=4:sw=4:et: