1<?php 2 3// must be run within Dokuwiki 4if (!defined('DOKU_INC')) die(); 5class helper_plugin_approve extends DokuWiki_Plugin { 6 /** 7 * checks if an id is within one of the namespaces in $namespace_list 8 * 9 * @param string $namespace_list 10 * @param string $id 11 * 12 * @return bool 13 */ 14 function in_namespace($namespace_list, $id) { 15 // PHP apparantly does not have closures - 16 // so we will parse $valid ourselves. Wasteful. 17 $namespace_list = preg_split('/\s+/', $namespace_list); 18 19 //if(count($valid) == 0) { return true; }//whole wiki matches 20 if(count($namespace_list) == 1 && $namespace_list[0] == "") { return false; }//whole wiki matches 21 22 $id = trim($id, ':'); 23 $id = explode(':', $id); 24 25 // Check against all possible namespaces 26 foreach($namespace_list as $namespace) { 27 $namespace = explode(':', $namespace); 28 $current_ns_depth = 0; 29 $total_ns_depth = count($namespace); 30 $matching = true; 31 32 // Check each element, untill all elements of $v satisfied 33 while($current_ns_depth < $total_ns_depth) { 34 if($namespace[$current_ns_depth] != $id[$current_ns_depth]) { 35 // not a match 36 $matching = false; 37 break; 38 } 39 $current_ns_depth += 1; 40 } 41 if($matching) { return true; } // a match 42 } 43 return false; 44 } 45} 46