1ed7b5f09Sandi<?php 215fae107Sandi/** 315fae107Sandi * DokuWiki search functions 415fae107Sandi * 515fae107Sandi * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 715fae107Sandi */ 8f3f0262cSandi 9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 10f3f0262cSandi 11f3f0262cSandi/** 12ce4301e3SGerrit Uitslag * Recurse directory 1315fae107Sandi * 14f3f0262cSandi * This function recurses into a given base directory 15f3f0262cSandi * and calls the supplied function for each file and directory 1615fae107Sandi * 1724998b31SGerrit Uitslag * @param array &$data The results of the search are stored here 1824baa045SAndreas Gohr * @param string $base Where to start the search 19fe82d751SChristopher Smith * @param callback $func Callback (function name or array with object,method) 2024998b31SGerrit Uitslag * @param array $opts option array will be given to the Callback 2124baa045SAndreas Gohr * @param string $dir Current directory beyond $base 2224baa045SAndreas Gohr * @param int $lvl Recursion Level 23ec24a2dfSPhilipp A. Hartmann * @param mixed $sort 'natural' to use natural order sorting (default); 'date' to sort by filemtime; leave empty to skip sorting. 2415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 25f3f0262cSandi */ 26155e63c9SChristopher Smithfunction search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort='natural'){ 27f3f0262cSandi $dirs = array(); 28f3f0262cSandi $files = array(); 29abc306f4SKate Arzamastseva $filepaths = array(); 30f3f0262cSandi 31*e0b6aadeSAndreas Gohr // safeguard against runaways #1452 32*e0b6aadeSAndreas Gohr if($base == '' || $base == '/') { 33*e0b6aadeSAndreas Gohr throw new RuntimeException('No valid $base passed to search() - possible misconfiguration or bug'); 34*e0b6aadeSAndreas Gohr } 35*e0b6aadeSAndreas Gohr 36f3f0262cSandi //read in directories and files 37f3f0262cSandi $dh = @opendir($base.'/'.$dir); 38f3f0262cSandi if(!$dh) return; 39f3f0262cSandi while(($file = readdir($dh)) !== false){ 40de3dfc91Sandi if(preg_match('/^[\._]/',$file)) continue; //skip hidden files and upper dirs 41f3f0262cSandi if(is_dir($base.'/'.$dir.'/'.$file)){ 42f3f0262cSandi $dirs[] = $dir.'/'.$file; 43f3f0262cSandi continue; 44f3f0262cSandi } 45f3f0262cSandi $files[] = $dir.'/'.$file; 46abc306f4SKate Arzamastseva $filepaths[] = $base.'/'.$dir.'/'.$file; 47f3f0262cSandi } 48f3f0262cSandi closedir($dh); 49ec24a2dfSPhilipp A. Hartmann if (!empty($sort)) { 50abc306f4SKate Arzamastseva if ($sort == 'date') { 51d971ea8bSKate Arzamastseva @array_multisort(array_map('filemtime', $filepaths), SORT_NUMERIC, SORT_DESC, $files); 521dc5d48bSChristopher Smith } else /* natural */ { 531dc5d48bSChristopher Smith natsort($files); 54abc306f4SKate Arzamastseva } 551dc5d48bSChristopher Smith natsort($dirs); 56ec24a2dfSPhilipp A. Hartmann } 57f3f0262cSandi 58f3f0262cSandi //give directories to userfunction then recurse 59f3f0262cSandi foreach($dirs as $dir){ 60d8126df2SGina Haeussge if (call_user_func_array($func, array(&$data,$base,$dir,'d',$lvl,$opts))){ 615514a5a7SChristopher Smith search($data,$base,$func,$opts,$dir,$lvl+1,$sort); 62f3f0262cSandi } 63f3f0262cSandi } 64f3f0262cSandi //now handle the files 65f3f0262cSandi foreach($files as $file){ 66d8126df2SGina Haeussge call_user_func_array($func, array(&$data,$base,$file,'f',$lvl,$opts)); 67f3f0262cSandi } 68f3f0262cSandi} 69f3f0262cSandi 70f3f0262cSandi/** 71f3f0262cSandi * The following functions are userfunctions to use with the search 72f3f0262cSandi * function above. This function is called for every found file or 73f3f0262cSandi * directory. When a directory is given to the function it has to 74f3f0262cSandi * decide if this directory should be traversed (true) or not (false) 75f3f0262cSandi * The function has to accept the following parameters: 76f3f0262cSandi * 77ce4301e3SGerrit Uitslag * array &$data - Reference to the result data structure 78ce4301e3SGerrit Uitslag * string $base - Base usually $conf['datadir'] 79ce4301e3SGerrit Uitslag * string $file - current file or directory relative to $base 80ce4301e3SGerrit Uitslag * string $type - Type either 'd' for directory or 'f' for file 81ce4301e3SGerrit Uitslag * int $lvl - Current recursion depht 82ce4301e3SGerrit Uitslag * array $opts - option array as given to search() 83f3f0262cSandi * 84f3f0262cSandi * return values for files are ignored 85f3f0262cSandi * 86f3f0262cSandi * All functions should check the ACL for document READ rights 87783d2e49SAdrian Lang * namespaces (directories) are NOT checked (when sneaky_index is 0) as this 88783d2e49SAdrian Lang * would break the recursion (You can have an nonreadable dir over a readable 890e1a261eSMichael Klier * one deeper nested) also make sure to check the file type (for example 900e1a261eSMichael Klier * in case of lockfiles). 91f3f0262cSandi */ 92f3f0262cSandi 93f3f0262cSandi/** 9463f2400bSandi * Searches for pages beginning with the given query 9563f2400bSandi * 9663f2400bSandi * @author Andreas Gohr <andi@splitbrain.org> 9763f2400bSandi */ 9863f2400bSandifunction search_qsearch(&$data,$base,$file,$type,$lvl,$opts){ 998705cc81SAndreas Gohr $opts = array( 1008705cc81SAndreas Gohr 'idmatch' => '(^|:)'.preg_quote($opts['query'],'/').'/', 1018705cc81SAndreas Gohr 'listfiles' => true, 1028705cc81SAndreas Gohr 'pagesonly' => true, 1038705cc81SAndreas Gohr ); 1048705cc81SAndreas Gohr return search_universal($data,$base,$file,$type,$lvl,$opts); 10563f2400bSandi} 10663f2400bSandi 10763f2400bSandi/** 10815fae107Sandi * Build the browsable index of pages 109f3f0262cSandi * 110783d2e49SAdrian Lang * $opts['ns'] is the currently viewed namespace 11115fae107Sandi * 11215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 113f3f0262cSandi */ 114f3f0262cSandifunction search_index(&$data,$base,$file,$type,$lvl,$opts){ 115d1c7b6ecSAndreas Gohr global $conf; 116783d2e49SAdrian Lang $opts = array( 117783d2e49SAdrian Lang 'pagesonly' => true, 118783d2e49SAdrian Lang 'listdirs' => true, 119443e135dSChristopher Smith 'listfiles' => empty($opts['nofiles']), 120783d2e49SAdrian Lang 'sneakyacl' => $conf['sneaky_index'], 121783d2e49SAdrian Lang // Hacky, should rather use recmatch 1221c6c1c6cSMichael Hamann 'depth' => preg_match('#^'.preg_quote($file, '#').'(/|$)#','/'.$opts['ns']) ? 0 : -1 123783d2e49SAdrian Lang ); 124f3f0262cSandi 125783d2e49SAdrian Lang return search_universal($data, $base, $file, $type, $lvl, $opts); 126f3f0262cSandi} 127f3f0262cSandi 128f3f0262cSandi/** 12915fae107Sandi * List all namespaces 13015fae107Sandi * 13115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 132f3f0262cSandi */ 133f3f0262cSandifunction search_namespaces(&$data,$base,$file,$type,$lvl,$opts){ 1348705cc81SAndreas Gohr $opts = array( 1358705cc81SAndreas Gohr 'listdirs' => true, 1368705cc81SAndreas Gohr ); 1378705cc81SAndreas Gohr return search_universal($data,$base,$file,$type,$lvl,$opts); 138f3f0262cSandi} 139f3f0262cSandi 140f3f0262cSandi/** 14115fae107Sandi * List all mediafiles in a namespace 14242ea7f44SGerrit Uitslag * $opts['depth'] recursion level, 0 for all 14342ea7f44SGerrit Uitslag * $opts['showmsg'] shows message if invalid media id is used 14442ea7f44SGerrit Uitslag * $opts['skipacl'] skip acl checking 14542ea7f44SGerrit Uitslag * $opts['pattern'] check given pattern 14642ea7f44SGerrit Uitslag * $opts['hash'] add hashes to result list 14715fae107Sandi * 14815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 149f3f0262cSandi */ 150f3f0262cSandifunction search_media(&$data,$base,$file,$type,$lvl,$opts){ 151b8219d2dSAndreas Gohr 152f3f0262cSandi //we do nothing with directories 1531a49ac65SGina Haeussge if($type == 'd') { 1540e80bb5eSChristopher Smith if(empty($opts['depth'])) return true; // recurse forever 15578315408SAndreas Gohr $depth = substr_count($file,'/'); 156b8219d2dSAndreas Gohr if($depth >= $opts['depth']) return false; // depth reached 157224122cfSAndreas Gohr return true; 1581a49ac65SGina Haeussge } 159f3f0262cSandi 160f3f0262cSandi $info = array(); 161156a608cSandi $info['id'] = pathID($file,true); 16264807c84SAndreas Gohr if($info['id'] != cleanID($info['id'])){ 16364807c84SAndreas Gohr if($opts['showmsg']) 16464807c84SAndreas Gohr msg(hsc($info['id']).' is not a valid file name for DokuWiki - skipped',-1); 16564807c84SAndreas Gohr return false; // skip non-valid files 16664807c84SAndreas Gohr } 167f3f0262cSandi 168f3f0262cSandi //check ACL for namespace (we have no ACL for mediafiles) 169224122cfSAndreas Gohr $info['perm'] = auth_quickaclcheck(getNS($info['id']).':*'); 1700e80bb5eSChristopher Smith if(empty($opts['skipacl']) && $info['perm'] < AUTH_READ){ 171224122cfSAndreas Gohr return false; 172224122cfSAndreas Gohr } 173224122cfSAndreas Gohr 174224122cfSAndreas Gohr //check pattern filter 1750e80bb5eSChristopher Smith if(!empty($opts['pattern']) && !@preg_match($opts['pattern'], $info['id'])){ 176f3f0262cSandi return false; 177f3f0262cSandi } 178f3f0262cSandi 1793009a773SAndreas Gohr $info['file'] = utf8_basename($file); 180f3f0262cSandi $info['size'] = filesize($base.'/'.$file); 1815e7fa82eSAndreas Gohr $info['mtime'] = filemtime($base.'/'.$file); 1823df72098SAndreas Gohr $info['writable'] = is_writable($base.'/'.$file); 183f3f0262cSandi if(preg_match("/\.(jpe?g|gif|png)$/",$file)){ 184f3f0262cSandi $info['isimg'] = true; 18523a34783SAndreas Gohr $info['meta'] = new JpegMeta($base.'/'.$file); 186f3f0262cSandi }else{ 187f3f0262cSandi $info['isimg'] = false; 188f3f0262cSandi } 1890e80bb5eSChristopher Smith if(!empty($opts['hash'])){ 190dfd343c4SAndreas Gohr $info['hash'] = md5(io_readFile(mediaFN($info['id']),false)); 191224122cfSAndreas Gohr } 192224122cfSAndreas Gohr 193f3f0262cSandi $data[] = $info; 194f3f0262cSandi 195f3f0262cSandi return false; 196f3f0262cSandi} 197f3f0262cSandi 198f3f0262cSandi/** 199f3f0262cSandi * This function just lists documents (for RSS namespace export) 20015fae107Sandi * 20115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 202f3f0262cSandi */ 203f3f0262cSandifunction search_list(&$data,$base,$file,$type,$lvl,$opts){ 204f3f0262cSandi //we do nothing with directories 205f3f0262cSandi if($type == 'd') return false; 2060e1a261eSMichael Klier //only search txt files 2070e1a261eSMichael Klier if(substr($file,-4) == '.txt'){ 208f3f0262cSandi //check ACL 209f3f0262cSandi $id = pathID($file); 210f3f0262cSandi if(auth_quickaclcheck($id) < AUTH_READ){ 211f3f0262cSandi return false; 212f3f0262cSandi } 2130e1a261eSMichael Klier $data[]['id'] = $id; 214f3f0262cSandi } 215f3f0262cSandi return false; 216f3f0262cSandi} 217f3f0262cSandi 218f3f0262cSandi/** 219f3f0262cSandi * Quicksearch for searching matching pagenames 220f3f0262cSandi * 221f3f0262cSandi * $opts['query'] is the search query 22215fae107Sandi * 22315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 224f3f0262cSandi */ 225f3f0262cSandifunction search_pagename(&$data,$base,$file,$type,$lvl,$opts){ 226f3f0262cSandi //we do nothing with directories 227f3f0262cSandi if($type == 'd') return true; 228f3f0262cSandi //only search txt files 2290e1a261eSMichael Klier if(substr($file,-4) != '.txt') return true; 230f3f0262cSandi 231f3f0262cSandi //simple stringmatching 232396b7edbSmatthiasgrimm if (!empty($opts['query'])){ 233f3f0262cSandi if(strpos($file,$opts['query']) !== false){ 234f3f0262cSandi //check ACL 235f3f0262cSandi $id = pathID($file); 236f3f0262cSandi if(auth_quickaclcheck($id) < AUTH_READ){ 237f3f0262cSandi return false; 238f3f0262cSandi } 239f3f0262cSandi $data[]['id'] = $id; 240f3f0262cSandi } 241396b7edbSmatthiasgrimm } 242f3f0262cSandi return true; 243f3f0262cSandi} 244f3f0262cSandi 245f3f0262cSandi/** 24658b6f612SAndreas Gohr * Just lists all documents 24758b6f612SAndreas Gohr * 2481fcfad4dSAndreas Gohr * $opts['depth'] recursion level, 0 for all 2491fcfad4dSAndreas Gohr * $opts['hash'] do md5 sum of content? 250224122cfSAndreas Gohr * $opts['skipacl'] list everything regardless of ACL 2511fcfad4dSAndreas Gohr * 25258b6f612SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 25358b6f612SAndreas Gohr */ 25458b6f612SAndreas Gohrfunction search_allpages(&$data,$base,$file,$type,$lvl,$opts){ 2558451f4adSGuillaume Turri if(isset($opts['depth']) && $opts['depth']){ 256c647387eSGuillaume Turri $parts = explode('/',ltrim($file,'/')); 2575737a81eSMichael Hamann if(($type == 'd' && count($parts) >= $opts['depth']) 2585737a81eSMichael Hamann || ($type != 'd' && count($parts) > $opts['depth'])){ 259c647387eSGuillaume Turri return false; // depth reached 260c647387eSGuillaume Turri } 261c647387eSGuillaume Turri } 262c647387eSGuillaume Turri 26358b6f612SAndreas Gohr //we do nothing with directories 2641fcfad4dSAndreas Gohr if($type == 'd'){ 2651fcfad4dSAndreas Gohr return true; 2661fcfad4dSAndreas Gohr } 2671fcfad4dSAndreas Gohr 26858b6f612SAndreas Gohr //only search txt files 2690e1a261eSMichael Klier if(substr($file,-4) != '.txt') return true; 27058b6f612SAndreas Gohr 27159bc3b48SGerrit Uitslag $item = array(); 2721fcfad4dSAndreas Gohr $item['id'] = pathID($file); 273061df79cSAndreas Gohr if(!$opts['skipacl'] && auth_quickaclcheck($item['id']) < AUTH_READ){ 2741fcfad4dSAndreas Gohr return false; 2751fcfad4dSAndreas Gohr } 2761fcfad4dSAndreas Gohr 2771fcfad4dSAndreas Gohr $item['rev'] = filemtime($base.'/'.$file); 278224122cfSAndreas Gohr $item['mtime'] = $item['rev']; 2791fcfad4dSAndreas Gohr $item['size'] = filesize($base.'/'.$file); 2801fcfad4dSAndreas Gohr if($opts['hash']){ 2811fcfad4dSAndreas Gohr $item['hash'] = md5(trim(rawWiki($item['id']))); 2821fcfad4dSAndreas Gohr } 2831fcfad4dSAndreas Gohr 2841fcfad4dSAndreas Gohr $data[] = $item; 28558b6f612SAndreas Gohr return true; 28658b6f612SAndreas Gohr} 28758b6f612SAndreas Gohr 288b59a406bSmatthiasgrimm/* ------------- helper functions below -------------- */ 289b59a406bSmatthiasgrimm 290b59a406bSmatthiasgrimm/** 29115fae107Sandi * fulltext sort 29215fae107Sandi * 293f3f0262cSandi * Callback sort function for use with usort to sort the data 294f3f0262cSandi * structure created by search_fulltext. Sorts descending by count 29515fae107Sandi * 29615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 297f3f0262cSandi */ 298f3f0262cSandifunction sort_search_fulltext($a,$b){ 299f3f0262cSandi if($a['count'] > $b['count']){ 300f3f0262cSandi return -1; 301f3f0262cSandi }elseif($a['count'] < $b['count']){ 302f3f0262cSandi return 1; 303f3f0262cSandi }else{ 304f3f0262cSandi return strcmp($a['id'],$b['id']); 305f3f0262cSandi } 306f3f0262cSandi} 307f3f0262cSandi 308f3f0262cSandi/** 309f3f0262cSandi * translates a document path to an ID 31015fae107Sandi * 31115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 31237e34a5eSandi * @todo move to pageutils 313f3f0262cSandi */ 314156a608cSandifunction pathID($path,$keeptxt=false){ 31549c713a3Sandi $id = utf8_decodeFN($path); 31649c713a3Sandi $id = str_replace('/',':',$id); 317156a608cSandi if(!$keeptxt) $id = preg_replace('#\.txt$#','',$id); 318709b1063SAdrian Lang $id = trim($id, ':'); 319f3f0262cSandi return $id; 320f3f0262cSandi} 321f3f0262cSandi 322340756e4Sandi 3233abeade3SAndreas Gohr/** 3243abeade3SAndreas Gohr * This is a very universal callback for the search() function, replacing 3253abeade3SAndreas Gohr * many of the former individual functions at the cost of a more complex 3263abeade3SAndreas Gohr * setup. 3273abeade3SAndreas Gohr * 3283abeade3SAndreas Gohr * How the function behaves, depends on the options passed in the $opts 3293abeade3SAndreas Gohr * array, where the following settings can be used. 3303abeade3SAndreas Gohr * 331e14fe973SGerrit Uitslag * depth int recursion depth. 0 for unlimited (default: 0) 332e14fe973SGerrit Uitslag * keeptxt bool keep .txt extension for IDs (default: false) 333e14fe973SGerrit Uitslag * listfiles bool include files in listing (default: false) 334e14fe973SGerrit Uitslag * listdirs bool include namespaces in listing (default: false) 335e14fe973SGerrit Uitslag * pagesonly bool restrict files to pages (default: false) 336e14fe973SGerrit Uitslag * skipacl bool do not check for READ permission (default: false) 337e14fe973SGerrit Uitslag * sneakyacl bool don't recurse into nonreadable dirs (default: false) 338e14fe973SGerrit Uitslag * hash bool create MD5 hash for files (default: false) 339e14fe973SGerrit Uitslag * meta bool return file metadata (default: false) 340e14fe973SGerrit Uitslag * filematch string match files against this regexp (default: '', so accept everything) 341e14fe973SGerrit Uitslag * idmatch string match full ID against this regexp (default: '', so accept everything) 342e14fe973SGerrit Uitslag * dirmatch string match directory against this regexp when adding (default: '', so accept everything) 343e14fe973SGerrit Uitslag * nsmatch string match namespace against this regexp when adding (default: '', so accept everything) 344e14fe973SGerrit Uitslag * recmatch string match directory against this regexp when recursing (default: '', so accept everything) 345e14fe973SGerrit Uitslag * showmsg bool warn about non-ID files (default: false) 346e14fe973SGerrit Uitslag * showhidden bool show hidden files(e.g. by hidepages config) too (default: false) 347e14fe973SGerrit Uitslag * firsthead bool return first heading for pages (default: false) 3483abeade3SAndreas Gohr * 349ce4301e3SGerrit Uitslag * @param array &$data - Reference to the result data structure 350ce4301e3SGerrit Uitslag * @param string $base - Base usually $conf['datadir'] 351ce4301e3SGerrit Uitslag * @param string $file - current file or directory relative to $base 352ce4301e3SGerrit Uitslag * @param string $type - Type either 'd' for directory or 'f' for file 353ce4301e3SGerrit Uitslag * @param int $lvl - Current recursion depht 354ce4301e3SGerrit Uitslag * @param array $opts - option array as given to search() 355ce4301e3SGerrit Uitslag * @return bool if this directory should be traversed (true) or not (false) 356ce4301e3SGerrit Uitslag * return value is ignored for files 357ce4301e3SGerrit Uitslag * 3583abeade3SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 3593abeade3SAndreas Gohr */ 3603abeade3SAndreas Gohrfunction search_universal(&$data,$base,$file,$type,$lvl,$opts){ 3613abeade3SAndreas Gohr $item = array(); 3623abeade3SAndreas Gohr $return = true; 3633abeade3SAndreas Gohr 3643abeade3SAndreas Gohr // get ID and check if it is a valid one 365b7a3421aSChristopher Smith $item['id'] = pathID($file,($type == 'd' || !empty($opts['keeptxt']))); 3668537abd1SAdrian Lang if($item['id'] != cleanID($item['id'])){ 36749f299d6SChristopher Smith if(!empty($opts['showmsg'])){ 3688537abd1SAdrian Lang msg(hsc($item['id']).' is not a valid file name for DokuWiki - skipped',-1); 369b7a3421aSChristopher Smith } 3703abeade3SAndreas Gohr return false; // skip non-valid files 3713abeade3SAndreas Gohr } 3728705cc81SAndreas Gohr $item['ns'] = getNS($item['id']); 3733abeade3SAndreas Gohr 3743abeade3SAndreas Gohr if($type == 'd') { 3753abeade3SAndreas Gohr // decide if to recursion into this directory is wanted 3760e80bb5eSChristopher Smith if(empty($opts['depth'])){ 3773abeade3SAndreas Gohr $return = true; // recurse forever 3783abeade3SAndreas Gohr }else{ 3793abeade3SAndreas Gohr $depth = substr_count($file,'/'); 3803abeade3SAndreas Gohr if($depth >= $opts['depth']){ 3813abeade3SAndreas Gohr $return = false; // depth reached 3823abeade3SAndreas Gohr }else{ 3833abeade3SAndreas Gohr $return = true; 3843abeade3SAndreas Gohr } 3853abeade3SAndreas Gohr } 3869b4337c6SChristopher Smith 3879b4337c6SChristopher Smith if ($return) { 3889b4337c6SChristopher Smith $match = empty($opts['recmatch']) || preg_match('/'.$opts['recmatch'].'/',$file); 3899b4337c6SChristopher Smith if (!$match) { 3909b4337c6SChristopher Smith return false; // doesn't match 3919b4337c6SChristopher Smith } 3923abeade3SAndreas Gohr } 3933abeade3SAndreas Gohr } 3943abeade3SAndreas Gohr 3953abeade3SAndreas Gohr // check ACL 396443e135dSChristopher Smith if(empty($opts['skipacl'])){ 3973abeade3SAndreas Gohr if($type == 'd'){ 3983abeade3SAndreas Gohr $item['perm'] = auth_quickaclcheck($item['id'].':*'); 3993abeade3SAndreas Gohr }else{ 4003abeade3SAndreas Gohr $item['perm'] = auth_quickaclcheck($item['id']); //FIXME check namespace for media files 4013abeade3SAndreas Gohr } 4023abeade3SAndreas Gohr }else{ 4033abeade3SAndreas Gohr $item['perm'] = AUTH_DELETE; 4043abeade3SAndreas Gohr } 4053abeade3SAndreas Gohr 4063abeade3SAndreas Gohr // are we done here maybe? 4073abeade3SAndreas Gohr if($type == 'd'){ 408443e135dSChristopher Smith if(empty($opts['listdirs'])) return $return; 409443e135dSChristopher Smith if(empty($opts['skipacl']) && !empty($opts['sneakyacl']) && $item['perm'] < AUTH_READ) return false; //neither list nor recurse 410443e135dSChristopher Smith if(!empty($opts['dirmatch']) && !preg_match('/'.$opts['dirmatch'].'/',$file)) return $return; 411443e135dSChristopher Smith if(!empty($opts['nsmatch']) && !preg_match('/'.$opts['nsmatch'].'/',$item['ns'])) return $return; 4123abeade3SAndreas Gohr }else{ 413443e135dSChristopher Smith if(empty($opts['listfiles'])) return $return; 414443e135dSChristopher Smith if(empty($opts['skipacl']) && $item['perm'] < AUTH_READ) return $return; 415443e135dSChristopher Smith if(!empty($opts['pagesonly']) && (substr($file,-4) != '.txt')) return $return; 416443e135dSChristopher Smith if(empty($opts['showhidden']) && isHiddenPage($item['id'])) return $return; 417443e135dSChristopher Smith if(!empty($opts['filematch']) && !preg_match('/'.$opts['filematch'].'/',$file)) return $return; 418443e135dSChristopher Smith if(!empty($opts['idmatch']) && !preg_match('/'.$opts['idmatch'].'/',$item['id'])) return $return; 4193abeade3SAndreas Gohr } 4203abeade3SAndreas Gohr 4213abeade3SAndreas Gohr // still here? prepare the item 4223abeade3SAndreas Gohr $item['type'] = $type; 42332d6093dSAndreas Gohr $item['level'] = $lvl; 4243abeade3SAndreas Gohr $item['open'] = $return; 4253abeade3SAndreas Gohr 4260e80bb5eSChristopher Smith if(!empty($opts['meta'])){ 4273009a773SAndreas Gohr $item['file'] = utf8_basename($file); 4283abeade3SAndreas Gohr $item['size'] = filesize($base.'/'.$file); 4293abeade3SAndreas Gohr $item['mtime'] = filemtime($base.'/'.$file); 4303abeade3SAndreas Gohr $item['rev'] = $item['mtime']; 4313abeade3SAndreas Gohr $item['writable'] = is_writable($base.'/'.$file); 4323abeade3SAndreas Gohr $item['executable'] = is_executable($base.'/'.$file); 4333abeade3SAndreas Gohr } 4343abeade3SAndreas Gohr 4353abeade3SAndreas Gohr if($type == 'f'){ 4360e80bb5eSChristopher Smith if(!empty($opts['hash'])) $item['hash'] = md5(io_readFile($base.'/'.$file,false)); 4370e80bb5eSChristopher Smith if(!empty($opts['firsthead'])) $item['title'] = p_get_first_heading($item['id'],METADATA_DONT_RENDER); 4383abeade3SAndreas Gohr } 4393abeade3SAndreas Gohr 4403abeade3SAndreas Gohr // finally add the item 4413abeade3SAndreas Gohr $data[] = $item; 4423abeade3SAndreas Gohr return $return; 4433abeade3SAndreas Gohr} 4443abeade3SAndreas Gohr 445e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 446