xref: /dokuwiki/inc/search.php (revision ce4301e3e16dc98ad647b0cde0643072f82aba48)
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/**
12*ce4301e3SGerrit 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
31f3f0262cSandi    //read in directories and files
32f3f0262cSandi    $dh = @opendir($base.'/'.$dir);
33f3f0262cSandi    if(!$dh) return;
34f3f0262cSandi    while(($file = readdir($dh)) !== false){
35de3dfc91Sandi        if(preg_match('/^[\._]/',$file)) continue; //skip hidden files and upper dirs
36f3f0262cSandi        if(is_dir($base.'/'.$dir.'/'.$file)){
37f3f0262cSandi            $dirs[] = $dir.'/'.$file;
38f3f0262cSandi            continue;
39f3f0262cSandi        }
40f3f0262cSandi        $files[] = $dir.'/'.$file;
41abc306f4SKate Arzamastseva        $filepaths[] = $base.'/'.$dir.'/'.$file;
42f3f0262cSandi    }
43f3f0262cSandi    closedir($dh);
44ec24a2dfSPhilipp A. Hartmann    if (!empty($sort)) {
45abc306f4SKate Arzamastseva        if ($sort == 'date') {
46d971ea8bSKate Arzamastseva            @array_multisort(array_map('filemtime', $filepaths), SORT_NUMERIC, SORT_DESC, $files);
471dc5d48bSChristopher Smith        } else /* natural */ {
481dc5d48bSChristopher Smith            natsort($files);
49abc306f4SKate Arzamastseva        }
501dc5d48bSChristopher Smith        natsort($dirs);
51ec24a2dfSPhilipp A. Hartmann    }
52f3f0262cSandi
53f3f0262cSandi    //give directories to userfunction then recurse
54f3f0262cSandi    foreach($dirs as $dir){
55d8126df2SGina Haeussge        if (call_user_func_array($func, array(&$data,$base,$dir,'d',$lvl,$opts))){
565514a5a7SChristopher Smith            search($data,$base,$func,$opts,$dir,$lvl+1,$sort);
57f3f0262cSandi        }
58f3f0262cSandi    }
59f3f0262cSandi    //now handle the files
60f3f0262cSandi    foreach($files as $file){
61d8126df2SGina Haeussge        call_user_func_array($func, array(&$data,$base,$file,'f',$lvl,$opts));
62f3f0262cSandi    }
63f3f0262cSandi}
64f3f0262cSandi
65f3f0262cSandi/**
66f3f0262cSandi * The following functions are userfunctions to use with the search
67f3f0262cSandi * function above. This function is called for every found file or
68f3f0262cSandi * directory. When a directory is given to the function it has to
69f3f0262cSandi * decide if this directory should be traversed (true) or not (false)
70f3f0262cSandi * The function has to accept the following parameters:
71f3f0262cSandi *
72*ce4301e3SGerrit Uitslag * array &$data  - Reference to the result data structure
73*ce4301e3SGerrit Uitslag * string $base  - Base usually $conf['datadir']
74*ce4301e3SGerrit Uitslag * string $file  - current file or directory relative to $base
75*ce4301e3SGerrit Uitslag * string $type  - Type either 'd' for directory or 'f' for file
76*ce4301e3SGerrit Uitslag * int    $lvl   - Current recursion depht
77*ce4301e3SGerrit Uitslag * array  $opts  - option array as given to search()
78f3f0262cSandi *
79f3f0262cSandi * return values for files are ignored
80f3f0262cSandi *
81f3f0262cSandi * All functions should check the ACL for document READ rights
82783d2e49SAdrian Lang * namespaces (directories) are NOT checked (when sneaky_index is 0) as this
83783d2e49SAdrian Lang * would break the recursion (You can have an nonreadable dir over a readable
840e1a261eSMichael Klier * one deeper nested) also make sure to check the file type (for example
850e1a261eSMichael Klier * in case of lockfiles).
86f3f0262cSandi */
87f3f0262cSandi
88f3f0262cSandi/**
8963f2400bSandi * Searches for pages beginning with the given query
9063f2400bSandi *
9163f2400bSandi * @author Andreas Gohr <andi@splitbrain.org>
9263f2400bSandi */
9363f2400bSandifunction search_qsearch(&$data,$base,$file,$type,$lvl,$opts){
948705cc81SAndreas Gohr    $opts = array(
958705cc81SAndreas Gohr            'idmatch'   => '(^|:)'.preg_quote($opts['query'],'/').'/',
968705cc81SAndreas Gohr            'listfiles' => true,
978705cc81SAndreas Gohr            'pagesonly' => true,
988705cc81SAndreas Gohr            );
998705cc81SAndreas Gohr    return search_universal($data,$base,$file,$type,$lvl,$opts);
10063f2400bSandi}
10163f2400bSandi
10263f2400bSandi/**
10315fae107Sandi * Build the browsable index of pages
104f3f0262cSandi *
105783d2e49SAdrian Lang * $opts['ns'] is the currently viewed namespace
10615fae107Sandi *
10715fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
108f3f0262cSandi */
109f3f0262cSandifunction search_index(&$data,$base,$file,$type,$lvl,$opts){
110d1c7b6ecSAndreas Gohr    global $conf;
111783d2e49SAdrian Lang    $opts = array(
112783d2e49SAdrian Lang        'pagesonly' => true,
113783d2e49SAdrian Lang        'listdirs' => true,
114783d2e49SAdrian Lang        'listfiles' => !$opts['nofiles'],
115783d2e49SAdrian Lang        'sneakyacl' => $conf['sneaky_index'],
116783d2e49SAdrian Lang        // Hacky, should rather use recmatch
1171c6c1c6cSMichael Hamann        'depth' => preg_match('#^'.preg_quote($file, '#').'(/|$)#','/'.$opts['ns']) ? 0 : -1
118783d2e49SAdrian Lang    );
119f3f0262cSandi
120783d2e49SAdrian Lang    return search_universal($data, $base, $file, $type, $lvl, $opts);
121f3f0262cSandi}
122f3f0262cSandi
123f3f0262cSandi/**
12415fae107Sandi * List all namespaces
12515fae107Sandi *
12615fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
127f3f0262cSandi */
128f3f0262cSandifunction search_namespaces(&$data,$base,$file,$type,$lvl,$opts){
1298705cc81SAndreas Gohr    $opts = array(
1308705cc81SAndreas Gohr            'listdirs' => true,
1318705cc81SAndreas Gohr            );
1328705cc81SAndreas Gohr    return search_universal($data,$base,$file,$type,$lvl,$opts);
133f3f0262cSandi}
134f3f0262cSandi
135f3f0262cSandi/**
13615fae107Sandi * List all mediafiles in a namespace
13715fae107Sandi *
13815fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
139f3f0262cSandi */
140f3f0262cSandifunction search_media(&$data,$base,$file,$type,$lvl,$opts){
141b8219d2dSAndreas Gohr
142f3f0262cSandi    //we do nothing with directories
1431a49ac65SGina Haeussge    if($type == 'd') {
144224122cfSAndreas Gohr        if(!$opts['depth']) return true; // recurse forever
14578315408SAndreas Gohr        $depth = substr_count($file,'/');
146b8219d2dSAndreas Gohr        if($depth >= $opts['depth']) return false; // depth reached
147224122cfSAndreas Gohr        return true;
1481a49ac65SGina Haeussge    }
149f3f0262cSandi
150f3f0262cSandi    $info         = array();
151156a608cSandi    $info['id']   = pathID($file,true);
15264807c84SAndreas Gohr    if($info['id'] != cleanID($info['id'])){
15364807c84SAndreas Gohr        if($opts['showmsg'])
15464807c84SAndreas Gohr            msg(hsc($info['id']).' is not a valid file name for DokuWiki - skipped',-1);
15564807c84SAndreas Gohr        return false; // skip non-valid files
15664807c84SAndreas Gohr    }
157f3f0262cSandi
158f3f0262cSandi    //check ACL for namespace (we have no ACL for mediafiles)
159224122cfSAndreas Gohr    $info['perm'] = auth_quickaclcheck(getNS($info['id']).':*');
160224122cfSAndreas Gohr    if(!$opts['skipacl'] && $info['perm'] < AUTH_READ){
161224122cfSAndreas Gohr        return false;
162224122cfSAndreas Gohr    }
163224122cfSAndreas Gohr
164224122cfSAndreas Gohr    //check pattern filter
165224122cfSAndreas Gohr    if($opts['pattern'] && !@preg_match($opts['pattern'], $info['id'])){
166f3f0262cSandi        return false;
167f3f0262cSandi    }
168f3f0262cSandi
1693009a773SAndreas Gohr    $info['file']     = utf8_basename($file);
170f3f0262cSandi    $info['size']     = filesize($base.'/'.$file);
1715e7fa82eSAndreas Gohr    $info['mtime']    = filemtime($base.'/'.$file);
1723df72098SAndreas Gohr    $info['writable'] = is_writable($base.'/'.$file);
173f3f0262cSandi    if(preg_match("/\.(jpe?g|gif|png)$/",$file)){
174f3f0262cSandi        $info['isimg'] = true;
17523a34783SAndreas Gohr        $info['meta']  = new JpegMeta($base.'/'.$file);
176f3f0262cSandi    }else{
177f3f0262cSandi        $info['isimg'] = false;
178f3f0262cSandi    }
179224122cfSAndreas Gohr    if($opts['hash']){
180dfd343c4SAndreas Gohr        $info['hash'] = md5(io_readFile(mediaFN($info['id']),false));
181224122cfSAndreas Gohr    }
182224122cfSAndreas Gohr
183f3f0262cSandi    $data[] = $info;
184f3f0262cSandi
185f3f0262cSandi    return false;
186f3f0262cSandi}
187f3f0262cSandi
188f3f0262cSandi/**
189f3f0262cSandi * This function just lists documents (for RSS namespace export)
19015fae107Sandi *
19115fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
192f3f0262cSandi */
193f3f0262cSandifunction search_list(&$data,$base,$file,$type,$lvl,$opts){
194f3f0262cSandi    //we do nothing with directories
195f3f0262cSandi    if($type == 'd') return false;
1960e1a261eSMichael Klier    //only search txt files
1970e1a261eSMichael Klier    if(substr($file,-4) == '.txt'){
198f3f0262cSandi        //check ACL
199f3f0262cSandi        $id = pathID($file);
200f3f0262cSandi        if(auth_quickaclcheck($id) < AUTH_READ){
201f3f0262cSandi            return false;
202f3f0262cSandi        }
2030e1a261eSMichael Klier        $data[]['id'] = $id;
204f3f0262cSandi    }
205f3f0262cSandi    return false;
206f3f0262cSandi}
207f3f0262cSandi
208f3f0262cSandi/**
209f3f0262cSandi * Quicksearch for searching matching pagenames
210f3f0262cSandi *
211f3f0262cSandi * $opts['query'] is the search query
21215fae107Sandi *
21315fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
214f3f0262cSandi */
215f3f0262cSandifunction search_pagename(&$data,$base,$file,$type,$lvl,$opts){
216f3f0262cSandi    //we do nothing with directories
217f3f0262cSandi    if($type == 'd') return true;
218f3f0262cSandi    //only search txt files
2190e1a261eSMichael Klier    if(substr($file,-4) != '.txt') return true;
220f3f0262cSandi
221f3f0262cSandi    //simple stringmatching
222396b7edbSmatthiasgrimm    if (!empty($opts['query'])){
223f3f0262cSandi        if(strpos($file,$opts['query']) !== false){
224f3f0262cSandi            //check ACL
225f3f0262cSandi            $id = pathID($file);
226f3f0262cSandi            if(auth_quickaclcheck($id) < AUTH_READ){
227f3f0262cSandi                return false;
228f3f0262cSandi            }
229f3f0262cSandi            $data[]['id'] = $id;
230f3f0262cSandi        }
231396b7edbSmatthiasgrimm    }
232f3f0262cSandi    return true;
233f3f0262cSandi}
234f3f0262cSandi
235f3f0262cSandi/**
23658b6f612SAndreas Gohr * Just lists all documents
23758b6f612SAndreas Gohr *
2381fcfad4dSAndreas Gohr * $opts['depth']   recursion level, 0 for all
2391fcfad4dSAndreas Gohr * $opts['hash']    do md5 sum of content?
240224122cfSAndreas Gohr * $opts['skipacl'] list everything regardless of ACL
2411fcfad4dSAndreas Gohr *
24258b6f612SAndreas Gohr * @author  Andreas Gohr <andi@splitbrain.org>
24358b6f612SAndreas Gohr */
24458b6f612SAndreas Gohrfunction search_allpages(&$data,$base,$file,$type,$lvl,$opts){
2458451f4adSGuillaume Turri    if(isset($opts['depth']) && $opts['depth']){
246c647387eSGuillaume Turri        $parts = explode('/',ltrim($file,'/'));
2475737a81eSMichael Hamann        if(($type == 'd' && count($parts) >= $opts['depth'])
2485737a81eSMichael Hamann          || ($type != 'd' && count($parts) > $opts['depth'])){
249c647387eSGuillaume Turri            return false; // depth reached
250c647387eSGuillaume Turri        }
251c647387eSGuillaume Turri    }
252c647387eSGuillaume Turri
25358b6f612SAndreas Gohr    //we do nothing with directories
2541fcfad4dSAndreas Gohr    if($type == 'd'){
2551fcfad4dSAndreas Gohr        return true;
2561fcfad4dSAndreas Gohr    }
2571fcfad4dSAndreas Gohr
25858b6f612SAndreas Gohr    //only search txt files
2590e1a261eSMichael Klier    if(substr($file,-4) != '.txt') return true;
26058b6f612SAndreas Gohr
2611fcfad4dSAndreas Gohr    $item['id']   = pathID($file);
262061df79cSAndreas Gohr    if(!$opts['skipacl'] && auth_quickaclcheck($item['id']) < AUTH_READ){
2631fcfad4dSAndreas Gohr        return false;
2641fcfad4dSAndreas Gohr    }
2651fcfad4dSAndreas Gohr
2661fcfad4dSAndreas Gohr    $item['rev']   = filemtime($base.'/'.$file);
267224122cfSAndreas Gohr    $item['mtime'] = $item['rev'];
2681fcfad4dSAndreas Gohr    $item['size']  = filesize($base.'/'.$file);
2691fcfad4dSAndreas Gohr    if($opts['hash']){
2701fcfad4dSAndreas Gohr        $item['hash'] = md5(trim(rawWiki($item['id'])));
2711fcfad4dSAndreas Gohr    }
2721fcfad4dSAndreas Gohr
2731fcfad4dSAndreas Gohr    $data[] = $item;
27458b6f612SAndreas Gohr    return true;
27558b6f612SAndreas Gohr}
27658b6f612SAndreas Gohr
277b59a406bSmatthiasgrimm/* ------------- helper functions below -------------- */
278b59a406bSmatthiasgrimm
279b59a406bSmatthiasgrimm/**
28015fae107Sandi * fulltext sort
28115fae107Sandi *
282f3f0262cSandi * Callback sort function for use with usort to sort the data
283f3f0262cSandi * structure created by search_fulltext. Sorts descending by count
28415fae107Sandi *
28515fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
286f3f0262cSandi */
287f3f0262cSandifunction sort_search_fulltext($a,$b){
288f3f0262cSandi    if($a['count'] > $b['count']){
289f3f0262cSandi        return -1;
290f3f0262cSandi    }elseif($a['count'] < $b['count']){
291f3f0262cSandi        return 1;
292f3f0262cSandi    }else{
293f3f0262cSandi        return strcmp($a['id'],$b['id']);
294f3f0262cSandi    }
295f3f0262cSandi}
296f3f0262cSandi
297f3f0262cSandi/**
298f3f0262cSandi * translates a document path to an ID
29915fae107Sandi *
30015fae107Sandi * @author  Andreas Gohr <andi@splitbrain.org>
30137e34a5eSandi * @todo    move to pageutils
302f3f0262cSandi */
303156a608cSandifunction pathID($path,$keeptxt=false){
30449c713a3Sandi    $id = utf8_decodeFN($path);
30549c713a3Sandi    $id = str_replace('/',':',$id);
306156a608cSandi    if(!$keeptxt) $id = preg_replace('#\.txt$#','',$id);
307709b1063SAdrian Lang    $id = trim($id, ':');
308f3f0262cSandi    return $id;
309f3f0262cSandi}
310f3f0262cSandi
311340756e4Sandi
3123abeade3SAndreas Gohr/**
3133abeade3SAndreas Gohr * This is a very universal callback for the search() function, replacing
3143abeade3SAndreas Gohr * many of the former individual functions at the cost of a more complex
3153abeade3SAndreas Gohr * setup.
3163abeade3SAndreas Gohr *
3173abeade3SAndreas Gohr * How the function behaves, depends on the options passed in the $opts
3183abeade3SAndreas Gohr * array, where the following settings can be used.
3193abeade3SAndreas Gohr *
3203abeade3SAndreas Gohr * depth      int     recursion depth. 0 for unlimited
3213abeade3SAndreas Gohr * keeptxt    bool    keep .txt extension for IDs
3223abeade3SAndreas Gohr * listfiles  bool    include files in listing
3233abeade3SAndreas Gohr * listdirs   bool    include namespaces in listing
3243abeade3SAndreas Gohr * pagesonly  bool    restrict files to pages
3253abeade3SAndreas Gohr * skipacl    bool    do not check for READ permission
3263abeade3SAndreas Gohr * sneakyacl  bool    don't recurse into nonreadable dirs
3273abeade3SAndreas Gohr * hash       bool    create MD5 hash for files
3283abeade3SAndreas Gohr * meta       bool    return file metadata
3293abeade3SAndreas Gohr * filematch  string  match files against this regexp
3308705cc81SAndreas Gohr * idmatch    string  match full ID against this regexp
3318705cc81SAndreas Gohr * dirmatch   string  match directory against this regexp when adding
3328705cc81SAndreas Gohr * nsmatch    string  match namespace against this regexp when adding
3338705cc81SAndreas Gohr * recmatch   string  match directory against this regexp when recursing
3343abeade3SAndreas Gohr * showmsg    bool    warn about non-ID files
3353abeade3SAndreas Gohr * showhidden bool    show hidden files too
3363abeade3SAndreas Gohr * firsthead  bool    return first heading for pages
3373abeade3SAndreas Gohr *
338*ce4301e3SGerrit Uitslag * @param array &$data - Reference to the result data structure
339*ce4301e3SGerrit Uitslag * @param string $base  - Base usually $conf['datadir']
340*ce4301e3SGerrit Uitslag * @param string $file  - current file or directory relative to $base
341*ce4301e3SGerrit Uitslag * @param string $type  - Type either 'd' for directory or 'f' for file
342*ce4301e3SGerrit Uitslag * @param int    $lvl   - Current recursion depht
343*ce4301e3SGerrit Uitslag * @param array  $opts  - option array as given to search()
344*ce4301e3SGerrit Uitslag * @return bool if this directory should be traversed (true) or not (false)
345*ce4301e3SGerrit Uitslag *              return value is ignored for files
346*ce4301e3SGerrit Uitslag *
3473abeade3SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de>
3483abeade3SAndreas Gohr */
3493abeade3SAndreas Gohrfunction search_universal(&$data,$base,$file,$type,$lvl,$opts){
3503abeade3SAndreas Gohr    $item   = array();
3513abeade3SAndreas Gohr    $return = true;
3523abeade3SAndreas Gohr
3533abeade3SAndreas Gohr    // get ID and check if it is a valid one
354e63d421bSAndreas Gohr    $item['id'] = pathID($file,($type == 'd' || $opts['keeptxt']));
3558537abd1SAdrian Lang    if($item['id'] != cleanID($item['id'])){
3563abeade3SAndreas Gohr        if($opts['showmsg'])
3578537abd1SAdrian Lang            msg(hsc($item['id']).' is not a valid file name for DokuWiki - skipped',-1);
3583abeade3SAndreas Gohr        return false; // skip non-valid files
3593abeade3SAndreas Gohr    }
3608705cc81SAndreas Gohr    $item['ns']  = getNS($item['id']);
3613abeade3SAndreas Gohr
3623abeade3SAndreas Gohr    if($type == 'd') {
3633abeade3SAndreas Gohr        // decide if to recursion into this directory is wanted
3643abeade3SAndreas Gohr        if(!$opts['depth']){
3653abeade3SAndreas Gohr            $return = true; // recurse forever
3663abeade3SAndreas Gohr        }else{
3673abeade3SAndreas Gohr            $depth = substr_count($file,'/');
3683abeade3SAndreas Gohr            if($depth >= $opts['depth']){
3693abeade3SAndreas Gohr                $return = false; // depth reached
3703abeade3SAndreas Gohr            }else{
3713abeade3SAndreas Gohr                $return = true;
3723abeade3SAndreas Gohr            }
3733abeade3SAndreas Gohr        }
3743abeade3SAndreas Gohr        if($return && !preg_match('/'.$opts['recmatch'].'/',$file)){
3753abeade3SAndreas Gohr            $return = false; // doesn't match
3763abeade3SAndreas Gohr        }
3773abeade3SAndreas Gohr    }
3783abeade3SAndreas Gohr
3793abeade3SAndreas Gohr    // check ACL
3803abeade3SAndreas Gohr    if(!$opts['skipacl']){
3813abeade3SAndreas Gohr        if($type == 'd'){
3823abeade3SAndreas Gohr            $item['perm'] = auth_quickaclcheck($item['id'].':*');
3833abeade3SAndreas Gohr        }else{
3843abeade3SAndreas Gohr            $item['perm'] = auth_quickaclcheck($item['id']); //FIXME check namespace for media files
3853abeade3SAndreas Gohr        }
3863abeade3SAndreas Gohr    }else{
3873abeade3SAndreas Gohr        $item['perm'] = AUTH_DELETE;
3883abeade3SAndreas Gohr    }
3893abeade3SAndreas Gohr
3903abeade3SAndreas Gohr    // are we done here maybe?
3913abeade3SAndreas Gohr    if($type == 'd'){
3923abeade3SAndreas Gohr        if(!$opts['listdirs']) return $return;
3933abeade3SAndreas Gohr        if(!$opts['skipacl'] && $opts['sneakyacl'] && $item['perm'] < AUTH_READ) return false; //neither list nor recurse
3943abeade3SAndreas Gohr        if($opts['dirmatch'] && !preg_match('/'.$opts['dirmatch'].'/',$file)) return $return;
3958705cc81SAndreas Gohr        if($opts['nsmatch'] && !preg_match('/'.$opts['nsmatch'].'/',$item['ns'])) return $return;
3963abeade3SAndreas Gohr    }else{
3973abeade3SAndreas Gohr        if(!$opts['listfiles']) return $return;
3983abeade3SAndreas Gohr        if(!$opts['skipacl'] && $item['perm'] < AUTH_READ) return $return;
3993abeade3SAndreas Gohr        if($opts['pagesonly'] && (substr($file,-4) != '.txt')) return $return;
400de3eb1d7SAdrian Lang        if(!$opts['showhidden'] && isHiddenPage($item['id'])) return $return;
4013abeade3SAndreas Gohr        if($opts['filematch'] && !preg_match('/'.$opts['filematch'].'/',$file)) return $return;
4028705cc81SAndreas Gohr        if($opts['idmatch'] && !preg_match('/'.$opts['idmatch'].'/',$item['id'])) return $return;
4033abeade3SAndreas Gohr    }
4043abeade3SAndreas Gohr
4053abeade3SAndreas Gohr    // still here? prepare the item
4063abeade3SAndreas Gohr    $item['type']  = $type;
40732d6093dSAndreas Gohr    $item['level'] = $lvl;
4083abeade3SAndreas Gohr    $item['open']  = $return;
4093abeade3SAndreas Gohr
4103abeade3SAndreas Gohr    if($opts['meta']){
4113009a773SAndreas Gohr        $item['file']       = utf8_basename($file);
4123abeade3SAndreas Gohr        $item['size']       = filesize($base.'/'.$file);
4133abeade3SAndreas Gohr        $item['mtime']      = filemtime($base.'/'.$file);
4143abeade3SAndreas Gohr        $item['rev']        = $item['mtime'];
4153abeade3SAndreas Gohr        $item['writable']   = is_writable($base.'/'.$file);
4163abeade3SAndreas Gohr        $item['executable'] = is_executable($base.'/'.$file);
4173abeade3SAndreas Gohr    }
4183abeade3SAndreas Gohr
4193abeade3SAndreas Gohr    if($type == 'f'){
4203abeade3SAndreas Gohr        if($opts['hash']) $item['hash'] = md5(io_readFile($base.'/'.$file,false));
42167c15eceSMichael Hamann        if($opts['firsthead']) $item['title'] = p_get_first_heading($item['id'],METADATA_DONT_RENDER);
4223abeade3SAndreas Gohr    }
4233abeade3SAndreas Gohr
4243abeade3SAndreas Gohr    // finally add the item
4253abeade3SAndreas Gohr    $data[] = $item;
4263abeade3SAndreas Gohr    return $return;
4273abeade3SAndreas Gohr}
4283abeade3SAndreas Gohr
429e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
430