1<?php 2/** 3 * DokuWiki Plugin publish (Helper Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Jarrod Lowe <dokuwiki@rrod.net> 7 * @author Andreas Gohr <gohr@cosmocode.de> 8 */ 9 10// must be run within Dokuwiki 11if (!defined('DOKU_INC')) die(); 12 13class helper_plugin_publish extends DokuWiki_Plugin { 14 15 // FIXME find out what this is supposed to do and how it can be done better 16 function in_namespace($valid, $check) { 17 // PHP apparantly does not have closures - 18 // so we will parse $valid ourselves. Wasteful. 19 $valid = preg_split('/\s+/', $valid); 20 //if(count($valid) == 0) { return true; }//whole wiki matches 21 if((count($valid)==1) and ($valid[0]=="")) { return true; }//whole wiki matches 22 $check = trim($check, ':'); 23 $check = explode(':', $check); 24 25 // Check against all possible namespaces 26 foreach($valid as $v) { 27 $v = explode(':', $v); 28 $n = 0; 29 $c = count($v); 30 $matching = 1; 31 32 // Check each element, untill all elements of $v satisfied 33 while($n < $c) { 34 if($v[$n] != $check[$n]) { 35 // not a match 36 $matching = 0; 37 break; 38 } 39 $n += 1; 40 } 41 if($matching == 1) { return true; } // a match 42 } 43 return false; 44 } 45 46 // FIXME find out what this is supposed to do and how it can be done better 47 function in_sub_namespace($valid, $check) { 48 // is check a dir which contains any valid? 49 // PHP apparantly does not have closures - 50 // so we will parse $valid ourselves. Wasteful. 51 $valid = preg_split('/\s+/', $valid); 52 //if(count($valid) == 0) { return true; }//whole wiki matches 53 if((count($valid)==1) and ($valid[0]=="")) { return true; }//whole wiki matches 54 $check = trim($check, ':'); 55 $check = explode(':', $check); 56 57 // Check against all possible namespaces 58 foreach($valid as $v) { 59 $v = explode(':', $v); 60 $n = 0; 61 $c = count($check); //this is what is different from above! 62 $matching = 1; 63 64 // Check each element, untill all elements of $v satisfied 65 while($n < $c) { 66 if($v[$n] != $check[$n]) { 67 // not a match 68 $matching = 0; 69 break; 70 } 71 $n += 1; 72 } 73 if($matching == 1) { return true; } // a match 74 } 75 return false; 76 } 77 78} 79