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/** 1215fae107Sandi * recurse direcory 1315fae107Sandi * 14f3f0262cSandi * This function recurses into a given base directory 15f3f0262cSandi * and calls the supplied function for each file and directory 1615fae107Sandi * 1724baa045SAndreas Gohr * @param array ref $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) 2024baa045SAndreas Gohr * @param string $dir Current directory beyond $base 2124baa045SAndreas Gohr * @param int $lvl Recursion Level 22ec24a2dfSPhilipp A. Hartmann * @param mixed $sort 'natural' to use natural order sorting (default); 'date' to sort by filemtime; leave empty to skip sorting. 2315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 24f3f0262cSandi */ 25155e63c9SChristopher Smithfunction search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort='natural'){ 26f3f0262cSandi $dirs = array(); 27f3f0262cSandi $files = array(); 28abc306f4SKate Arzamastseva $filepaths = array(); 29f3f0262cSandi 30f3f0262cSandi //read in directories and files 31f3f0262cSandi $dh = @opendir($base.'/'.$dir); 32f3f0262cSandi if(!$dh) return; 33f3f0262cSandi while(($file = readdir($dh)) !== false){ 34de3dfc91Sandi if(preg_match('/^[\._]/',$file)) continue; //skip hidden files and upper dirs 35f3f0262cSandi if(is_dir($base.'/'.$dir.'/'.$file)){ 36f3f0262cSandi $dirs[] = $dir.'/'.$file; 37f3f0262cSandi continue; 38f3f0262cSandi } 39f3f0262cSandi $files[] = $dir.'/'.$file; 40abc306f4SKate Arzamastseva $filepaths[] = $base.'/'.$dir.'/'.$file; 41f3f0262cSandi } 42f3f0262cSandi closedir($dh); 43ec24a2dfSPhilipp A. Hartmann if (!empty($sort)) { 44abc306f4SKate Arzamastseva if ($sort == 'date') { 45d971ea8bSKate Arzamastseva @array_multisort(array_map('filemtime', $filepaths), SORT_NUMERIC, SORT_DESC, $files); 461dc5d48bSChristopher Smith } else /* natural */ { 471dc5d48bSChristopher Smith natsort($files); 48abc306f4SKate Arzamastseva } 491dc5d48bSChristopher Smith natsort($dirs); 50ec24a2dfSPhilipp A. Hartmann } 51f3f0262cSandi 52f3f0262cSandi //give directories to userfunction then recurse 53f3f0262cSandi foreach($dirs as $dir){ 54d8126df2SGina Haeussge if (call_user_func_array($func, array(&$data,$base,$dir,'d',$lvl,$opts))){ 555514a5a7SChristopher Smith search($data,$base,$func,$opts,$dir,$lvl+1,$sort); 56f3f0262cSandi } 57f3f0262cSandi } 58f3f0262cSandi //now handle the files 59f3f0262cSandi foreach($files as $file){ 60d8126df2SGina Haeussge call_user_func_array($func, array(&$data,$base,$file,'f',$lvl,$opts)); 61f3f0262cSandi } 62f3f0262cSandi} 63f3f0262cSandi 64f3f0262cSandi/** 65f3f0262cSandi * The following functions are userfunctions to use with the search 66f3f0262cSandi * function above. This function is called for every found file or 67f3f0262cSandi * directory. When a directory is given to the function it has to 68f3f0262cSandi * decide if this directory should be traversed (true) or not (false) 69f3f0262cSandi * The function has to accept the following parameters: 70f3f0262cSandi * 71f3f0262cSandi * &$data - Reference to the result data structure 72f3f0262cSandi * $base - Base usually $conf['datadir'] 73f3f0262cSandi * $file - current file or directory relative to $base 74f3f0262cSandi * $type - Type either 'd' for directory or 'f' for file 75f3f0262cSandi * $lvl - Current recursion depht 76f3f0262cSandi * $opts - option array as given to search() 77f3f0262cSandi * 78f3f0262cSandi * return values for files are ignored 79f3f0262cSandi * 80f3f0262cSandi * All functions should check the ACL for document READ rights 81783d2e49SAdrian Lang * namespaces (directories) are NOT checked (when sneaky_index is 0) as this 82783d2e49SAdrian Lang * would break the recursion (You can have an nonreadable dir over a readable 830e1a261eSMichael Klier * one deeper nested) also make sure to check the file type (for example 840e1a261eSMichael Klier * in case of lockfiles). 85f3f0262cSandi */ 86f3f0262cSandi 87f3f0262cSandi/** 8863f2400bSandi * Searches for pages beginning with the given query 8963f2400bSandi * 9063f2400bSandi * @author Andreas Gohr <andi@splitbrain.org> 9163f2400bSandi */ 9263f2400bSandifunction search_qsearch(&$data,$base,$file,$type,$lvl,$opts){ 938705cc81SAndreas Gohr $opts = array( 948705cc81SAndreas Gohr 'idmatch' => '(^|:)'.preg_quote($opts['query'],'/').'/', 958705cc81SAndreas Gohr 'listfiles' => true, 968705cc81SAndreas Gohr 'pagesonly' => true, 978705cc81SAndreas Gohr ); 988705cc81SAndreas Gohr return search_universal($data,$base,$file,$type,$lvl,$opts); 9963f2400bSandi} 10063f2400bSandi 10163f2400bSandi/** 10215fae107Sandi * Build the browsable index of pages 103f3f0262cSandi * 104783d2e49SAdrian Lang * $opts['ns'] is the currently viewed namespace 10515fae107Sandi * 10615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 107f3f0262cSandi */ 108f3f0262cSandifunction search_index(&$data,$base,$file,$type,$lvl,$opts){ 109d1c7b6ecSAndreas Gohr global $conf; 110783d2e49SAdrian Lang $opts = array( 111783d2e49SAdrian Lang 'pagesonly' => true, 112783d2e49SAdrian Lang 'listdirs' => true, 113783d2e49SAdrian Lang 'listfiles' => !$opts['nofiles'], 114783d2e49SAdrian Lang 'sneakyacl' => $conf['sneaky_index'], 115783d2e49SAdrian Lang // Hacky, should rather use recmatch 1161c6c1c6cSMichael Hamann 'depth' => preg_match('#^'.preg_quote($file, '#').'(/|$)#','/'.$opts['ns']) ? 0 : -1 117783d2e49SAdrian Lang ); 118f3f0262cSandi 119783d2e49SAdrian Lang return search_universal($data, $base, $file, $type, $lvl, $opts); 120f3f0262cSandi} 121f3f0262cSandi 122f3f0262cSandi/** 12315fae107Sandi * List all namespaces 12415fae107Sandi * 12515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 126f3f0262cSandi */ 127f3f0262cSandifunction search_namespaces(&$data,$base,$file,$type,$lvl,$opts){ 1288705cc81SAndreas Gohr $opts = array( 1298705cc81SAndreas Gohr 'listdirs' => true, 1308705cc81SAndreas Gohr ); 1318705cc81SAndreas Gohr return search_universal($data,$base,$file,$type,$lvl,$opts); 132f3f0262cSandi} 133f3f0262cSandi 134f3f0262cSandi/** 13515fae107Sandi * List all mediafiles in a namespace 13615fae107Sandi * 13715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 138f3f0262cSandi */ 139f3f0262cSandifunction search_media(&$data,$base,$file,$type,$lvl,$opts){ 140b8219d2dSAndreas Gohr 141f3f0262cSandi //we do nothing with directories 1421a49ac65SGina Haeussge if($type == 'd') { 143224122cfSAndreas Gohr if(!$opts['depth']) return true; // recurse forever 14478315408SAndreas Gohr $depth = substr_count($file,'/'); 145b8219d2dSAndreas Gohr if($depth >= $opts['depth']) return false; // depth reached 146224122cfSAndreas Gohr return true; 1471a49ac65SGina Haeussge } 148f3f0262cSandi 149f3f0262cSandi $info = array(); 150156a608cSandi $info['id'] = pathID($file,true); 15164807c84SAndreas Gohr if($info['id'] != cleanID($info['id'])){ 15264807c84SAndreas Gohr if($opts['showmsg']) 15364807c84SAndreas Gohr msg(hsc($info['id']).' is not a valid file name for DokuWiki - skipped',-1); 15464807c84SAndreas Gohr return false; // skip non-valid files 15564807c84SAndreas Gohr } 156f3f0262cSandi 157f3f0262cSandi //check ACL for namespace (we have no ACL for mediafiles) 158224122cfSAndreas Gohr $info['perm'] = auth_quickaclcheck(getNS($info['id']).':*'); 159224122cfSAndreas Gohr if(!$opts['skipacl'] && $info['perm'] < AUTH_READ){ 160224122cfSAndreas Gohr return false; 161224122cfSAndreas Gohr } 162224122cfSAndreas Gohr 163224122cfSAndreas Gohr //check pattern filter 164224122cfSAndreas Gohr if($opts['pattern'] && !@preg_match($opts['pattern'], $info['id'])){ 165f3f0262cSandi return false; 166f3f0262cSandi } 167f3f0262cSandi 1683009a773SAndreas Gohr $info['file'] = utf8_basename($file); 169f3f0262cSandi $info['size'] = filesize($base.'/'.$file); 1705e7fa82eSAndreas Gohr $info['mtime'] = filemtime($base.'/'.$file); 1713df72098SAndreas Gohr $info['writable'] = is_writable($base.'/'.$file); 172f3f0262cSandi if(preg_match("/\.(jpe?g|gif|png)$/",$file)){ 173f3f0262cSandi $info['isimg'] = true; 17423a34783SAndreas Gohr $info['meta'] = new JpegMeta($base.'/'.$file); 175f3f0262cSandi }else{ 176f3f0262cSandi $info['isimg'] = false; 177f3f0262cSandi } 178224122cfSAndreas Gohr if($opts['hash']){ 179dfd343c4SAndreas Gohr $info['hash'] = md5(io_readFile(mediaFN($info['id']),false)); 180224122cfSAndreas Gohr } 181224122cfSAndreas Gohr 182f3f0262cSandi $data[] = $info; 183f3f0262cSandi 184f3f0262cSandi return false; 185f3f0262cSandi} 186f3f0262cSandi 187f3f0262cSandi/** 188f3f0262cSandi * This function just lists documents (for RSS namespace export) 18915fae107Sandi * 19015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 191f3f0262cSandi */ 192f3f0262cSandifunction search_list(&$data,$base,$file,$type,$lvl,$opts){ 193f3f0262cSandi //we do nothing with directories 194f3f0262cSandi if($type == 'd') return false; 1950e1a261eSMichael Klier //only search txt files 1960e1a261eSMichael Klier if(substr($file,-4) == '.txt'){ 197f3f0262cSandi //check ACL 198f3f0262cSandi $id = pathID($file); 199f3f0262cSandi if(auth_quickaclcheck($id) < AUTH_READ){ 200f3f0262cSandi return false; 201f3f0262cSandi } 2020e1a261eSMichael Klier $data[]['id'] = $id; 203f3f0262cSandi } 204f3f0262cSandi return false; 205f3f0262cSandi} 206f3f0262cSandi 207f3f0262cSandi/** 208f3f0262cSandi * Quicksearch for searching matching pagenames 209f3f0262cSandi * 210f3f0262cSandi * $opts['query'] is the search query 21115fae107Sandi * 21215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 213f3f0262cSandi */ 214f3f0262cSandifunction search_pagename(&$data,$base,$file,$type,$lvl,$opts){ 215f3f0262cSandi //we do nothing with directories 216f3f0262cSandi if($type == 'd') return true; 217f3f0262cSandi //only search txt files 2180e1a261eSMichael Klier if(substr($file,-4) != '.txt') return true; 219f3f0262cSandi 220f3f0262cSandi //simple stringmatching 221396b7edbSmatthiasgrimm if (!empty($opts['query'])){ 222f3f0262cSandi if(strpos($file,$opts['query']) !== false){ 223f3f0262cSandi //check ACL 224f3f0262cSandi $id = pathID($file); 225f3f0262cSandi if(auth_quickaclcheck($id) < AUTH_READ){ 226f3f0262cSandi return false; 227f3f0262cSandi } 228f3f0262cSandi $data[]['id'] = $id; 229f3f0262cSandi } 230396b7edbSmatthiasgrimm } 231f3f0262cSandi return true; 232f3f0262cSandi} 233f3f0262cSandi 234f3f0262cSandi/** 23558b6f612SAndreas Gohr * Just lists all documents 23658b6f612SAndreas Gohr * 2371fcfad4dSAndreas Gohr * $opts['depth'] recursion level, 0 for all 2381fcfad4dSAndreas Gohr * $opts['hash'] do md5 sum of content? 239224122cfSAndreas Gohr * $opts['skipacl'] list everything regardless of ACL 2401fcfad4dSAndreas Gohr * 24158b6f612SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 24258b6f612SAndreas Gohr */ 24358b6f612SAndreas Gohrfunction search_allpages(&$data,$base,$file,$type,$lvl,$opts){ 2448451f4adSGuillaume Turri if(isset($opts['depth']) && $opts['depth']){ 245c647387eSGuillaume Turri $parts = explode('/',ltrim($file,'/')); 246*5737a81eSMichael Hamann if(($type == 'd' && count($parts) >= $opts['depth']) 247*5737a81eSMichael Hamann || ($type != 'd' && count($parts) > $opts['depth'])){ 248c647387eSGuillaume Turri return false; // depth reached 249c647387eSGuillaume Turri } 250c647387eSGuillaume Turri } 251c647387eSGuillaume Turri 25258b6f612SAndreas Gohr //we do nothing with directories 2531fcfad4dSAndreas Gohr if($type == 'd'){ 2541fcfad4dSAndreas Gohr return true; 2551fcfad4dSAndreas Gohr } 2561fcfad4dSAndreas Gohr 25758b6f612SAndreas Gohr //only search txt files 2580e1a261eSMichael Klier if(substr($file,-4) != '.txt') return true; 25958b6f612SAndreas Gohr 2601fcfad4dSAndreas Gohr $item['id'] = pathID($file); 261061df79cSAndreas Gohr if(!$opts['skipacl'] && auth_quickaclcheck($item['id']) < AUTH_READ){ 2621fcfad4dSAndreas Gohr return false; 2631fcfad4dSAndreas Gohr } 2641fcfad4dSAndreas Gohr 2651fcfad4dSAndreas Gohr $item['rev'] = filemtime($base.'/'.$file); 266224122cfSAndreas Gohr $item['mtime'] = $item['rev']; 2671fcfad4dSAndreas Gohr $item['size'] = filesize($base.'/'.$file); 2681fcfad4dSAndreas Gohr if($opts['hash']){ 2691fcfad4dSAndreas Gohr $item['hash'] = md5(trim(rawWiki($item['id']))); 2701fcfad4dSAndreas Gohr } 2711fcfad4dSAndreas Gohr 2721fcfad4dSAndreas Gohr $data[] = $item; 27358b6f612SAndreas Gohr return true; 27458b6f612SAndreas Gohr} 27558b6f612SAndreas Gohr 27658b6f612SAndreas Gohr/** 277b59a406bSmatthiasgrimm * Reference search 278b59a406bSmatthiasgrimm * This fuction searches for existing references to a given media file 279b59a406bSmatthiasgrimm * and returns an array with the found pages. It doesn't pay any 280b59a406bSmatthiasgrimm * attention to ACL permissions to find every reference. The caller 281b59a406bSmatthiasgrimm * must check if the user has the appropriate rights to see the found 282b59a406bSmatthiasgrimm * page and eventually have to prevent the result from displaying. 283b59a406bSmatthiasgrimm * 284b59a406bSmatthiasgrimm * @param array $data Reference to the result data structure 285b59a406bSmatthiasgrimm * @param string $base Base usually $conf['datadir'] 286b59a406bSmatthiasgrimm * @param string $file current file or directory relative to $base 287b59a406bSmatthiasgrimm * @param char $type Type either 'd' for directory or 'f' for file 288b59a406bSmatthiasgrimm * @param int $lvl Current recursion depht 289b59a406bSmatthiasgrimm * @param mixed $opts option array as given to search() 290b59a406bSmatthiasgrimm * 291b59a406bSmatthiasgrimm * $opts['query'] is the demanded media file name 292b59a406bSmatthiasgrimm * 293b59a406bSmatthiasgrimm * @author Andreas Gohr <andi@splitbrain.org> 294b59a406bSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 295b59a406bSmatthiasgrimm */ 296b59a406bSmatthiasgrimmfunction search_reference(&$data,$base,$file,$type,$lvl,$opts){ 297b59a406bSmatthiasgrimm global $conf; 298b59a406bSmatthiasgrimm 299b59a406bSmatthiasgrimm //we do nothing with directories 300b59a406bSmatthiasgrimm if($type == 'd') return true; 301b59a406bSmatthiasgrimm 302b59a406bSmatthiasgrimm //only search txt files 3030e1a261eSMichael Klier if(substr($file,-4) != '.txt') return true; 304b59a406bSmatthiasgrimm 305e28299ccSmatthiasgrimm //we finish after 'cnt' references found. The return value 306b59a406bSmatthiasgrimm //'false' will skip subdirectories to speed search up. 307e28299ccSmatthiasgrimm $cnt = $conf['refshow'] > 0 ? $conf['refshow'] : 1; 308e28299ccSmatthiasgrimm if(count($data) >= $cnt) return false; 309b59a406bSmatthiasgrimm 310d67ca2c0Smatthiasgrimm $reg = '\{\{ *\:?'.$opts['query'].' *(\|.*)?\}\}'; 311b59a406bSmatthiasgrimm search_regex($data,$base,$file,$reg,array($opts['query'])); 312b59a406bSmatthiasgrimm return true; 313b59a406bSmatthiasgrimm} 314b59a406bSmatthiasgrimm 315b59a406bSmatthiasgrimm/* ------------- helper functions below -------------- */ 316b59a406bSmatthiasgrimm 317b59a406bSmatthiasgrimm/** 31815fae107Sandi * fulltext sort 31915fae107Sandi * 320f3f0262cSandi * Callback sort function for use with usort to sort the data 321f3f0262cSandi * structure created by search_fulltext. Sorts descending by count 32215fae107Sandi * 32315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 324f3f0262cSandi */ 325f3f0262cSandifunction sort_search_fulltext($a,$b){ 326f3f0262cSandi if($a['count'] > $b['count']){ 327f3f0262cSandi return -1; 328f3f0262cSandi }elseif($a['count'] < $b['count']){ 329f3f0262cSandi return 1; 330f3f0262cSandi }else{ 331f3f0262cSandi return strcmp($a['id'],$b['id']); 332f3f0262cSandi } 333f3f0262cSandi} 334f3f0262cSandi 335f3f0262cSandi/** 336f3f0262cSandi * translates a document path to an ID 33715fae107Sandi * 33815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org> 33937e34a5eSandi * @todo move to pageutils 340f3f0262cSandi */ 341156a608cSandifunction pathID($path,$keeptxt=false){ 34249c713a3Sandi $id = utf8_decodeFN($path); 34349c713a3Sandi $id = str_replace('/',':',$id); 344156a608cSandi if(!$keeptxt) $id = preg_replace('#\.txt$#','',$id); 345709b1063SAdrian Lang $id = trim($id, ':'); 346f3f0262cSandi return $id; 347f3f0262cSandi} 348f3f0262cSandi 349340756e4Sandi 3503abeade3SAndreas Gohr/** 3513abeade3SAndreas Gohr * This is a very universal callback for the search() function, replacing 3523abeade3SAndreas Gohr * many of the former individual functions at the cost of a more complex 3533abeade3SAndreas Gohr * setup. 3543abeade3SAndreas Gohr * 3553abeade3SAndreas Gohr * How the function behaves, depends on the options passed in the $opts 3563abeade3SAndreas Gohr * array, where the following settings can be used. 3573abeade3SAndreas Gohr * 3583abeade3SAndreas Gohr * depth int recursion depth. 0 for unlimited 3593abeade3SAndreas Gohr * keeptxt bool keep .txt extension for IDs 3603abeade3SAndreas Gohr * listfiles bool include files in listing 3613abeade3SAndreas Gohr * listdirs bool include namespaces in listing 3623abeade3SAndreas Gohr * pagesonly bool restrict files to pages 3633abeade3SAndreas Gohr * skipacl bool do not check for READ permission 3643abeade3SAndreas Gohr * sneakyacl bool don't recurse into nonreadable dirs 3653abeade3SAndreas Gohr * hash bool create MD5 hash for files 3663abeade3SAndreas Gohr * meta bool return file metadata 3673abeade3SAndreas Gohr * filematch string match files against this regexp 3688705cc81SAndreas Gohr * idmatch string match full ID against this regexp 3698705cc81SAndreas Gohr * dirmatch string match directory against this regexp when adding 3708705cc81SAndreas Gohr * nsmatch string match namespace against this regexp when adding 3718705cc81SAndreas Gohr * recmatch string match directory against this regexp when recursing 3723abeade3SAndreas Gohr * showmsg bool warn about non-ID files 3733abeade3SAndreas Gohr * showhidden bool show hidden files too 3743abeade3SAndreas Gohr * firsthead bool return first heading for pages 3753abeade3SAndreas Gohr * 3763abeade3SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 3773abeade3SAndreas Gohr */ 3783abeade3SAndreas Gohrfunction search_universal(&$data,$base,$file,$type,$lvl,$opts){ 3793abeade3SAndreas Gohr $item = array(); 3803abeade3SAndreas Gohr $return = true; 3813abeade3SAndreas Gohr 3823abeade3SAndreas Gohr // get ID and check if it is a valid one 383e63d421bSAndreas Gohr $item['id'] = pathID($file,($type == 'd' || $opts['keeptxt'])); 3848537abd1SAdrian Lang if($item['id'] != cleanID($item['id'])){ 3853abeade3SAndreas Gohr if($opts['showmsg']) 3868537abd1SAdrian Lang msg(hsc($item['id']).' is not a valid file name for DokuWiki - skipped',-1); 3873abeade3SAndreas Gohr return false; // skip non-valid files 3883abeade3SAndreas Gohr } 3898705cc81SAndreas Gohr $item['ns'] = getNS($item['id']); 3903abeade3SAndreas Gohr 3913abeade3SAndreas Gohr if($type == 'd') { 3923abeade3SAndreas Gohr // decide if to recursion into this directory is wanted 3933abeade3SAndreas Gohr if(!$opts['depth']){ 3943abeade3SAndreas Gohr $return = true; // recurse forever 3953abeade3SAndreas Gohr }else{ 3963abeade3SAndreas Gohr $depth = substr_count($file,'/'); 3973abeade3SAndreas Gohr if($depth >= $opts['depth']){ 3983abeade3SAndreas Gohr $return = false; // depth reached 3993abeade3SAndreas Gohr }else{ 4003abeade3SAndreas Gohr $return = true; 4013abeade3SAndreas Gohr } 4023abeade3SAndreas Gohr } 4033abeade3SAndreas Gohr if($return && !preg_match('/'.$opts['recmatch'].'/',$file)){ 4043abeade3SAndreas Gohr $return = false; // doesn't match 4053abeade3SAndreas Gohr } 4063abeade3SAndreas Gohr } 4073abeade3SAndreas Gohr 4083abeade3SAndreas Gohr // check ACL 4093abeade3SAndreas Gohr if(!$opts['skipacl']){ 4103abeade3SAndreas Gohr if($type == 'd'){ 4113abeade3SAndreas Gohr $item['perm'] = auth_quickaclcheck($item['id'].':*'); 4123abeade3SAndreas Gohr }else{ 4133abeade3SAndreas Gohr $item['perm'] = auth_quickaclcheck($item['id']); //FIXME check namespace for media files 4143abeade3SAndreas Gohr } 4153abeade3SAndreas Gohr }else{ 4163abeade3SAndreas Gohr $item['perm'] = AUTH_DELETE; 4173abeade3SAndreas Gohr } 4183abeade3SAndreas Gohr 4193abeade3SAndreas Gohr // are we done here maybe? 4203abeade3SAndreas Gohr if($type == 'd'){ 4213abeade3SAndreas Gohr if(!$opts['listdirs']) return $return; 4223abeade3SAndreas Gohr if(!$opts['skipacl'] && $opts['sneakyacl'] && $item['perm'] < AUTH_READ) return false; //neither list nor recurse 4233abeade3SAndreas Gohr if($opts['dirmatch'] && !preg_match('/'.$opts['dirmatch'].'/',$file)) return $return; 4248705cc81SAndreas Gohr if($opts['nsmatch'] && !preg_match('/'.$opts['nsmatch'].'/',$item['ns'])) return $return; 4253abeade3SAndreas Gohr }else{ 4263abeade3SAndreas Gohr if(!$opts['listfiles']) return $return; 4273abeade3SAndreas Gohr if(!$opts['skipacl'] && $item['perm'] < AUTH_READ) return $return; 4283abeade3SAndreas Gohr if($opts['pagesonly'] && (substr($file,-4) != '.txt')) return $return; 429de3eb1d7SAdrian Lang if(!$opts['showhidden'] && isHiddenPage($item['id'])) return $return; 4303abeade3SAndreas Gohr if($opts['filematch'] && !preg_match('/'.$opts['filematch'].'/',$file)) return $return; 4318705cc81SAndreas Gohr if($opts['idmatch'] && !preg_match('/'.$opts['idmatch'].'/',$item['id'])) return $return; 4323abeade3SAndreas Gohr } 4333abeade3SAndreas Gohr 4343abeade3SAndreas Gohr // still here? prepare the item 4353abeade3SAndreas Gohr $item['type'] = $type; 43632d6093dSAndreas Gohr $item['level'] = $lvl; 4373abeade3SAndreas Gohr $item['open'] = $return; 4383abeade3SAndreas Gohr 4393abeade3SAndreas Gohr if($opts['meta']){ 4403009a773SAndreas Gohr $item['file'] = utf8_basename($file); 4413abeade3SAndreas Gohr $item['size'] = filesize($base.'/'.$file); 4423abeade3SAndreas Gohr $item['mtime'] = filemtime($base.'/'.$file); 4433abeade3SAndreas Gohr $item['rev'] = $item['mtime']; 4443abeade3SAndreas Gohr $item['writable'] = is_writable($base.'/'.$file); 4453abeade3SAndreas Gohr $item['executable'] = is_executable($base.'/'.$file); 4463abeade3SAndreas Gohr } 4473abeade3SAndreas Gohr 4483abeade3SAndreas Gohr if($type == 'f'){ 4493abeade3SAndreas Gohr if($opts['hash']) $item['hash'] = md5(io_readFile($base.'/'.$file,false)); 45067c15eceSMichael Hamann if($opts['firsthead']) $item['title'] = p_get_first_heading($item['id'],METADATA_DONT_RENDER); 4513abeade3SAndreas Gohr } 4523abeade3SAndreas Gohr 4533abeade3SAndreas Gohr // finally add the item 4543abeade3SAndreas Gohr $data[] = $item; 4553abeade3SAndreas Gohr return $return; 4563abeade3SAndreas Gohr} 4573abeade3SAndreas Gohr 458e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 459