diff options
Diffstat (limited to 'inc/search.php')
-rw-r--r-- | inc/search.php | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/inc/search.php b/inc/search.php index 884aa7b23..c2d31b959 100644 --- a/inc/search.php +++ b/inc/search.php @@ -9,14 +9,15 @@ if(!defined('DOKU_INC')) die('meh.'); /** - * recurse direcory + * Recurse directory * * This function recurses into a given base directory * and calls the supplied function for each file and directory * - * @param array ref $data The results of the search are stored here + * @param array &$data The results of the search are stored here * @param string $base Where to start the search * @param callback $func Callback (function name or array with object,method) + * @param array $opts option array will be given to the Callback * @param string $dir Current directory beyond $base * @param int $lvl Recursion Level * @param mixed $sort 'natural' to use natural order sorting (default); 'date' to sort by filemtime; leave empty to skip sorting. @@ -68,12 +69,12 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort='natural'){ * decide if this directory should be traversed (true) or not (false) * The function has to accept the following parameters: * - * &$data - Reference to the result data structure - * $base - Base usually $conf['datadir'] - * $file - current file or directory relative to $base - * $type - Type either 'd' for directory or 'f' for file - * $lvl - Current recursion depht - * $opts - option array as given to search() + * array &$data - Reference to the result data structure + * string $base - Base usually $conf['datadir'] + * string $file - current file or directory relative to $base + * string $type - Type either 'd' for directory or 'f' for file + * int $lvl - Current recursion depht + * array $opts - option array as given to search() * * return values for files are ignored * @@ -110,7 +111,7 @@ function search_index(&$data,$base,$file,$type,$lvl,$opts){ $opts = array( 'pagesonly' => true, 'listdirs' => true, - 'listfiles' => !$opts['nofiles'], + 'listfiles' => empty($opts['nofiles']), 'sneakyacl' => $conf['sneaky_index'], // Hacky, should rather use recmatch 'depth' => preg_match('#^'.preg_quote($file, '#').'(/|$)#','/'.$opts['ns']) ? 0 : -1 @@ -334,6 +335,15 @@ function pathID($path,$keeptxt=false){ * showhidden bool show hidden files too * firsthead bool return first heading for pages * + * @param array &$data - Reference to the result data structure + * @param string $base - Base usually $conf['datadir'] + * @param string $file - current file or directory relative to $base + * @param string $type - Type either 'd' for directory or 'f' for file + * @param int $lvl - Current recursion depht + * @param array $opts - option array as given to search() + * @return bool if this directory should be traversed (true) or not (false) + * return value is ignored for files + * * @author Andreas Gohr <gohr@cosmocode.de> */ function search_universal(&$data,$base,$file,$type,$lvl,$opts){ @@ -367,7 +377,7 @@ function search_universal(&$data,$base,$file,$type,$lvl,$opts){ } // check ACL - if(!$opts['skipacl']){ + if(empty($opts['skipacl'])){ if($type == 'd'){ $item['perm'] = auth_quickaclcheck($item['id'].':*'); }else{ @@ -379,17 +389,17 @@ function search_universal(&$data,$base,$file,$type,$lvl,$opts){ // are we done here maybe? if($type == 'd'){ - if(!$opts['listdirs']) return $return; - if(!$opts['skipacl'] && $opts['sneakyacl'] && $item['perm'] < AUTH_READ) return false; //neither list nor recurse - if($opts['dirmatch'] && !preg_match('/'.$opts['dirmatch'].'/',$file)) return $return; - if($opts['nsmatch'] && !preg_match('/'.$opts['nsmatch'].'/',$item['ns'])) return $return; + if(empty($opts['listdirs'])) return $return; + if(empty($opts['skipacl']) && !empty($opts['sneakyacl']) && $item['perm'] < AUTH_READ) return false; //neither list nor recurse + if(!empty($opts['dirmatch']) && !preg_match('/'.$opts['dirmatch'].'/',$file)) return $return; + if(!empty($opts['nsmatch']) && !preg_match('/'.$opts['nsmatch'].'/',$item['ns'])) return $return; }else{ - if(!$opts['listfiles']) return $return; - if(!$opts['skipacl'] && $item['perm'] < AUTH_READ) return $return; - if($opts['pagesonly'] && (substr($file,-4) != '.txt')) return $return; - if(!$opts['showhidden'] && isHiddenPage($item['id'])) return $return; - if($opts['filematch'] && !preg_match('/'.$opts['filematch'].'/',$file)) return $return; - if($opts['idmatch'] && !preg_match('/'.$opts['idmatch'].'/',$item['id'])) return $return; + if(empty($opts['listfiles'])) return $return; + if(empty($opts['skipacl']) && $item['perm'] < AUTH_READ) return $return; + if(!empty($opts['pagesonly']) && (substr($file,-4) != '.txt')) return $return; + if(empty($opts['showhidden']) && isHiddenPage($item['id'])) return $return; + if(!empty($opts['filematch']) && !preg_match('/'.$opts['filematch'].'/',$file)) return $return; + if(!empty($opts['idmatch']) && !preg_match('/'.$opts['idmatch'].'/',$item['id'])) return $return; } // still here? prepare the item |