1<?php 2class remote_plugin_remotelistnamespace extends DokuWiki_Remote_Plugin { 3 public function _getMethods() { 4 return array( 5 'listNamespace' => array( 6 'args' => array('string', 'array'), 7 'return' => 'array', 8 'doc' => 'List all namespaces within the given namespace.', 9 'name' => 'listNamespace' 10 ) 11 ); 12 } 13 14 /** 15 * List all namespaces in the given namespace (and below) 16 * 17 * @param string $ns 18 * @param array $opts 19 * $opts['depth'] recursion level, 0 for all 20 * @return array 21 */ 22 public function listNamespace($ns,$opts){ 23 global $conf; 24 25 if(!is_array($opts)) $opts=array(); 26 27 $ns = cleanID($ns); 28 $dir = utf8_encodeFN(str_replace(':', '/', $ns)); 29 $data = array(); 30 search($data, $conf['datadir'], Array($this, 'search_namespace'), $opts, $dir); 31 return $data; 32 } 33 34 /** 35 * Just lists all namespaces 36 * 37 * $opts['depth'] recursion level, 0 for all 38 * 39 * @author Michael Braun <michael-dev@fami-braun.de> 40 */ 41 function search_namespace(&$data,$base,$file,$type,$lvl,$opts){ 42 //we do nothing with files 43 if($type != 'd'){ 44 return false; 45 } 46 47 if(isset($opts['depth']) && $opts['depth']){ 48 $parts = explode('/',ltrim($file,'/')); 49 if(count($parts) > $opts['depth']) 50 return false; // depth reached 51 } 52 53 $item = array(); 54 $item['id'] = pathID($file); 55 if(auth_quickaclcheck($item['id']) < AUTH_READ){ 56 return false; 57 } 58 59 $data[] = $item; 60 61 if(isset($opts['depth']) && $opts['depth']){ 62 $parts = explode('/',ltrim($file,'/')); 63 if(count($parts) >= $opts['depth']) 64 return false; // depth reached, no recursion required 65 } 66 return true; 67 } 68 69} 70 71