forked from cosmocode/dokuwiki-plugin-publish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
78 lines (69 loc) · 2.57 KB
/
helper.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
<?php
/**
* DokuWiki Plugin publish (Helper Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Jarrod Lowe <[email protected]>
* @author Andreas Gohr <[email protected]>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
class helper_plugin_publish extends DokuWiki_Plugin {
// FIXME find out what this is supposed to do and how it can be done better
function in_namespace($valid, $check) {
// PHP apparantly does not have closures -
// so we will parse $valid ourselves. Wasteful.
$valid = preg_split('/\s+/', $valid);
//if(count($valid) == 0) { return true; }//whole wiki matches
if((count($valid)==1) and ($valid[0]=="")) { return true; }//whole wiki matches
$check = trim($check, ':');
$check = explode(':', $check);
// Check against all possible namespaces
foreach($valid as $v) {
$v = explode(':', $v);
$n = 0;
$c = count($v);
$matching = 1;
// Check each element, untill all elements of $v satisfied
while($n < $c) {
if($v[$n] != $check[$n]) {
// not a match
$matching = 0;
break;
}
$n += 1;
}
if($matching == 1) { return true; } // a match
}
return false;
}
// FIXME find out what this is supposed to do and how it can be done better
function in_sub_namespace($valid, $check) {
// is check a dir which contains any valid?
// PHP apparantly does not have closures -
// so we will parse $valid ourselves. Wasteful.
$valid = preg_split('/\s+/', $valid);
//if(count($valid) == 0) { return true; }//whole wiki matches
if((count($valid)==1) and ($valid[0]=="")) { return true; }//whole wiki matches
$check = trim($check, ':');
$check = explode(':', $check);
// Check against all possible namespaces
foreach($valid as $v) {
$v = explode(':', $v);
$n = 0;
$c = count($check); //this is what is different from above!
$matching = 1;
// Check each element, untill all elements of $v satisfied
while($n < $c) {
if($v[$n] != $check[$n]) {
// not a match
$matching = 0;
break;
}
$n += 1;
}
if($matching == 1) { return true; } // a match
}
return false;
}
}