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 //if(count($valid) == 0) { return true; }//whole wiki matches 19 if((count($namespace_list)==1) and ($namespace_list[0]=="")) { return true; }//whole wiki matches 20 $id = trim($id, ':'); 21 $id = explode(':', $id); 22 23 // Check against all possible namespaces 24 foreach($namespace_list as $namespace) { 25 $namespace = explode(':', $namespace); 26 $current_ns_depth = 0; 27 $total_ns_depth = count($namespace); 28 $matching = true; 29 30 // Check each element, untill all elements of $v satisfied 31 while($current_ns_depth < $total_ns_depth) { 32 if($namespace[$current_ns_depth] != $id[$current_ns_depth]) { 33 // not a match 34 $matching = false; 35 break; 36 } 37 $current_ns_depth += 1; 38 } 39 if($matching) { return true; } // a match 40 } 41 return false; 42 } 43} 44