-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsyntax.php
More file actions
131 lines (113 loc) · 3.36 KB
/
syntax.php
File metadata and controls
131 lines (113 loc) · 3.36 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
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
<?php
use dokuwiki\Extension\SyntaxPlugin;
/**
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
class syntax_plugin_aclinfo extends SyntaxPlugin
{
/** @inheritdoc */
public function getType()
{
return 'substition';
}
/** @inheritdoc */
public function getPType()
{
return 'block';
}
/** @inheritdoc */
public function getSort()
{
return 155;
}
/** @inheritdoc */
public function connectTo($mode)
{
$this->Lexer->addSpecialPattern('~~ACLINFO!?[^~]*?~~', $mode, 'plugin_aclinfo');
}
/** @inheritdoc */
public function handle($match, $state, $pos, Doku_Handler $handler)
{
$match = substr($match, 10, -2);
return [$match];
}
/** @inheritdoc */
public function render($format, Doku_Renderer $R, $data)
{
global $INFO;
if ($format != 'xhtml') return false;
if (!$data[0]) {
$page = $INFO['id'];
} else {
$page = $data[0];
}
$perms = $this->aclCheck($page);
$R->doc .= '<div class="plugin_aclinfo">';
$R->listu_open();
foreach ($perms as $who => $p) {
$R->listitem_open(1);
$R->listcontent_open();
$R->cdata(sprintf($this->getLang('perm' . $p), urldecode($who)));
$R->listcontent_close();
$R->listitem_close();
}
$R->listu_close();
$R->doc .= '</div>';
return true;
}
/**
* Parse the ACL setup and return the permissions for the given page ID.
*
* @param string $id The page ID to check
* @return array
*/
protected function aclCheck($id)
{
global $AUTH_ACL;
$id = cleanID($id);
$ns = getNS($id);
$perms = [];
//check exact match first
$matches = preg_grep('/^' . preg_quote($id, '/') . '\s+/', $AUTH_ACL);
$perms = array_merge($perms, $this->processAclMatches($matches));
//still here? do the namespace checks
if ($ns) {
$path = $ns . ':\*';
} else {
$path = '\*'; //root document
}
do {
$matches = preg_grep('/^' . $path . '\s+/', $AUTH_ACL);
$perms = array_merge($perms, $this->processAclMatches($matches));
//get next higher namespace
$ns = getNS($ns);
if ($path != '\*') {
$path = $ns . ':\*';
if ($path == ':\*') $path = '\*';
} else {
//we did this already
//break here
break;
}
} while (1); //this should never loop endless
return $perms;
}
/**
* Process ACL matches and return parsed permissions.
*
* @param array $matches Array of ACL lines to process
* @return array Parsed permissions array
*/
protected function processAclMatches(array $matches)
{
$perms = [];
foreach ($matches as $match) {
$match = preg_replace('/#.*$/', '', $match); //ignore comments
$acl = preg_split('/\s+/', $match);
if ($acl[2] > AUTH_DELETE) $acl[2] = AUTH_DELETE; //no admins in the ACL!
if (!isset($perms[$acl[1]])) $perms[$acl[1]] = $acl[2];
}
return $perms;
}
}