~ubuntu-branches/ubuntu/quantal/dokuwiki/quantal

« back to all changes in this revision

Viewing changes to inc/search.php

  • Committer: Package Import Robot
  • Author(s): Tanguy Ortolo
  • Date: 2012-01-26 23:10:28 UTC
  • mfrom: (1.1.14) (19.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20120126231028-gdcxrxo3j4jqp2de
Tags: 0.0.20120125-1
* New upstream release.
* debian/patches/debianize.diff: updated for the new release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * @param   int       $lvl  Recursion Level
22
22
 * @author  Andreas Gohr <andi@splitbrain.org>
23
23
 */
24
 
function search(&$data,$base,$func,$opts,$dir='',$lvl=1){
 
24
function search(&$data,$base,$func,$opts,$dir='',$lvl=1,$sort=false){
25
25
    $dirs   = array();
26
26
    $files  = array();
 
27
    $filepaths = array();
27
28
 
28
29
    //read in directories and files
29
30
    $dh = @opendir($base.'/'.$dir);
35
36
            continue;
36
37
        }
37
38
        $files[] = $dir.'/'.$file;
 
39
        $filepaths[] = $base.'/'.$dir.'/'.$file;
38
40
    }
39
41
    closedir($dh);
40
 
    sort($files);
 
42
    if ($sort == 'date') {
 
43
        @array_multisort(array_map('filemtime', $filepaths), SORT_NUMERIC, SORT_DESC, $files);
 
44
    } else {
 
45
        sort($files);
 
46
    }
41
47
    sort($dirs);
42
48
 
43
49
    //give directories to userfunction then recurse
78
84
 * return values for files are ignored
79
85
 *
80
86
 * All functions should check the ACL for document READ rights
81
 
 * namespaces (directories) are NOT checked as this would break
82
 
 * the recursion (You can have an nonreadable dir over a readable
 
87
 * namespaces (directories) are NOT checked (when sneaky_index is 0) as this
 
88
 * would break the recursion (You can have an nonreadable dir over a readable
83
89
 * one deeper nested) also make sure to check the file type (for example
84
90
 * in case of lockfiles).
85
91
 */
101
107
/**
102
108
 * Build the browsable index of pages
103
109
 *
104
 
 * $opts['ns'] is the current namespace
 
110
 * $opts['ns'] is the currently viewed namespace
105
111
 *
106
112
 * @author  Andreas Gohr <andi@splitbrain.org>
107
113
 */
108
114
function search_index(&$data,$base,$file,$type,$lvl,$opts){
109
115
    global $conf;
110
 
    $return = true;
111
 
 
112
 
    $item = array();
113
 
 
114
 
    if($type == 'd' && !preg_match('#^'.$file.'(/|$)#','/'.$opts['ns'])){
115
 
        //add but don't recurse
116
 
        $return = false;
117
 
    }elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){
118
 
        //don't add
119
 
        return false;
120
 
    }
121
 
 
122
 
    $id = pathID($file,($type == 'd'));
123
 
 
124
 
    if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){
125
 
        return false;
126
 
    }
127
 
 
128
 
    //check hidden
129
 
    if(isHiddenPage($id)){
130
 
        return false;
131
 
    }
132
 
 
133
 
    //check ACL
134
 
    if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){
135
 
        return false;
136
 
    }
137
 
 
138
 
    $data[]=array( 'id'    => $id,
139
 
            'type'  => $type,
140
 
            'level' => $lvl,
141
 
            'open'  => $return );
142
 
    return $return;
 
116
    $opts = array(
 
117
        'pagesonly' => true,
 
118
        'listdirs' => true,
 
119
        'listfiles' => !$opts['nofiles'],
 
120
        'sneakyacl' => $conf['sneaky_index'],
 
121
        // Hacky, should rather use recmatch
 
122
        'depth' => preg_match('#^'.$file.'(/|$)#','/'.$opts['ns']) ? 0 : -1
 
123
    );
 
124
 
 
125
    return search_universal($data, $base, $file, $type, $lvl, $opts);
143
126
}
144
127
 
145
128
/**