xref: /dokuwiki/inc/Ajax.php (revision 16a367d4fc734ab4d7ded6a2ca8ba3ed94d7a0a5)
1*16a367d4SAndreas Gohr<?php
2*16a367d4SAndreas Gohr
3*16a367d4SAndreas Gohrnamespace dokuwiki;
4*16a367d4SAndreas Gohr
5*16a367d4SAndreas Gohr/**
6*16a367d4SAndreas Gohr * Manage all builtin AJAX calls
7*16a367d4SAndreas Gohr *
8*16a367d4SAndreas Gohr * @todo The calls should be refactored out to their own proper classes
9*16a367d4SAndreas Gohr * @package dokuwiki
10*16a367d4SAndreas Gohr */
11*16a367d4SAndreas Gohrclass Ajax {
12*16a367d4SAndreas Gohr
13*16a367d4SAndreas Gohr    /**
14*16a367d4SAndreas Gohr     * Execute the given call
15*16a367d4SAndreas Gohr     *
16*16a367d4SAndreas Gohr     * @param string $call name of the ajax call
17*16a367d4SAndreas Gohr     */
18*16a367d4SAndreas Gohr    public function __construct($call) {
19*16a367d4SAndreas Gohr        $callfn = 'call_' . $call;
20*16a367d4SAndreas Gohr        if(method_exists($this, $callfn)) {
21*16a367d4SAndreas Gohr            $this->$callfn();
22*16a367d4SAndreas Gohr        } else {
23*16a367d4SAndreas Gohr            $evt = new \Doku_Event('AJAX_CALL_UNKNOWN', $call);
24*16a367d4SAndreas Gohr            if($evt->advise_before()) {
25*16a367d4SAndreas Gohr                print "AJAX call '" . hsc($call) . "' unknown!\n";
26*16a367d4SAndreas Gohr            } else {
27*16a367d4SAndreas Gohr                $evt->advise_after();
28*16a367d4SAndreas Gohr                unset($evt);
29*16a367d4SAndreas Gohr            }
30*16a367d4SAndreas Gohr        }
31*16a367d4SAndreas Gohr    }
32*16a367d4SAndreas Gohr
33*16a367d4SAndreas Gohr    /**
34*16a367d4SAndreas Gohr     * Searches for matching pagenames
35*16a367d4SAndreas Gohr     *
36*16a367d4SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
37*16a367d4SAndreas Gohr     */
38*16a367d4SAndreas Gohr    protected function call_qsearch() {
39*16a367d4SAndreas Gohr        global $lang;
40*16a367d4SAndreas Gohr        global $INPUT;
41*16a367d4SAndreas Gohr
42*16a367d4SAndreas Gohr        $maxnumbersuggestions = 50;
43*16a367d4SAndreas Gohr
44*16a367d4SAndreas Gohr        $query = $INPUT->post->str('q');
45*16a367d4SAndreas Gohr        if(empty($query)) $query = $INPUT->get->str('q');
46*16a367d4SAndreas Gohr        if(empty($query)) return;
47*16a367d4SAndreas Gohr
48*16a367d4SAndreas Gohr        $query = urldecode($query);
49*16a367d4SAndreas Gohr
50*16a367d4SAndreas Gohr        $data = ft_pageLookup($query, true, useHeading('navigation'));
51*16a367d4SAndreas Gohr
52*16a367d4SAndreas Gohr        if(!count($data)) return;
53*16a367d4SAndreas Gohr
54*16a367d4SAndreas Gohr        print '<strong>' . $lang['quickhits'] . '</strong>';
55*16a367d4SAndreas Gohr        print '<ul>';
56*16a367d4SAndreas Gohr        $counter = 0;
57*16a367d4SAndreas Gohr        foreach($data as $id => $title) {
58*16a367d4SAndreas Gohr            if(useHeading('navigation')) {
59*16a367d4SAndreas Gohr                $name = $title;
60*16a367d4SAndreas Gohr            } else {
61*16a367d4SAndreas Gohr                $ns = getNS($id);
62*16a367d4SAndreas Gohr                if($ns) {
63*16a367d4SAndreas Gohr                    $name = noNS($id) . ' (' . $ns . ')';
64*16a367d4SAndreas Gohr                } else {
65*16a367d4SAndreas Gohr                    $name = $id;
66*16a367d4SAndreas Gohr                }
67*16a367d4SAndreas Gohr            }
68*16a367d4SAndreas Gohr            echo '<li>' . html_wikilink(':' . $id, $name) . '</li>';
69*16a367d4SAndreas Gohr
70*16a367d4SAndreas Gohr            $counter++;
71*16a367d4SAndreas Gohr            if($counter > $maxnumbersuggestions) {
72*16a367d4SAndreas Gohr                echo '<li>...</li>';
73*16a367d4SAndreas Gohr                break;
74*16a367d4SAndreas Gohr            }
75*16a367d4SAndreas Gohr        }
76*16a367d4SAndreas Gohr        print '</ul>';
77*16a367d4SAndreas Gohr    }
78*16a367d4SAndreas Gohr
79*16a367d4SAndreas Gohr    /**
80*16a367d4SAndreas Gohr     * Support OpenSearch suggestions
81*16a367d4SAndreas Gohr     *
82*16a367d4SAndreas Gohr     * @link   http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.0
83*16a367d4SAndreas Gohr     * @author Mike Frysinger <vapier@gentoo.org>
84*16a367d4SAndreas Gohr     */
85*16a367d4SAndreas Gohr    protected function call_suggestions() {
86*16a367d4SAndreas Gohr        global $INPUT;
87*16a367d4SAndreas Gohr
88*16a367d4SAndreas Gohr        $query = cleanID($INPUT->post->str('q'));
89*16a367d4SAndreas Gohr        if(empty($query)) $query = cleanID($INPUT->get->str('q'));
90*16a367d4SAndreas Gohr        if(empty($query)) return;
91*16a367d4SAndreas Gohr
92*16a367d4SAndreas Gohr        $data = ft_pageLookup($query);
93*16a367d4SAndreas Gohr        if(!count($data)) return;
94*16a367d4SAndreas Gohr        $data = array_keys($data);
95*16a367d4SAndreas Gohr
96*16a367d4SAndreas Gohr        // limit results to 15 hits
97*16a367d4SAndreas Gohr        $data = array_slice($data, 0, 15);
98*16a367d4SAndreas Gohr        $data = array_map('trim', $data);
99*16a367d4SAndreas Gohr        $data = array_map('noNS', $data);
100*16a367d4SAndreas Gohr        $data = array_unique($data);
101*16a367d4SAndreas Gohr        sort($data);
102*16a367d4SAndreas Gohr
103*16a367d4SAndreas Gohr        /* now construct a json */
104*16a367d4SAndreas Gohr        $suggestions = array(
105*16a367d4SAndreas Gohr            $query,  // the original query
106*16a367d4SAndreas Gohr            $data,   // some suggestions
107*16a367d4SAndreas Gohr            array(), // no description
108*16a367d4SAndreas Gohr            array()  // no urls
109*16a367d4SAndreas Gohr        );
110*16a367d4SAndreas Gohr        $json = new \JSON();
111*16a367d4SAndreas Gohr
112*16a367d4SAndreas Gohr        header('Content-Type: application/x-suggestions+json');
113*16a367d4SAndreas Gohr        print $json->encode($suggestions);
114*16a367d4SAndreas Gohr    }
115*16a367d4SAndreas Gohr
116*16a367d4SAndreas Gohr    /**
117*16a367d4SAndreas Gohr     * Refresh a page lock and save draft
118*16a367d4SAndreas Gohr     *
119*16a367d4SAndreas Gohr     * Andreas Gohr <andi@splitbrain.org>
120*16a367d4SAndreas Gohr     */
121*16a367d4SAndreas Gohr    protected function call_lock() {
122*16a367d4SAndreas Gohr        global $conf;
123*16a367d4SAndreas Gohr        global $lang;
124*16a367d4SAndreas Gohr        global $ID;
125*16a367d4SAndreas Gohr        global $INFO;
126*16a367d4SAndreas Gohr        global $INPUT;
127*16a367d4SAndreas Gohr
128*16a367d4SAndreas Gohr        $ID = cleanID($INPUT->post->str('id'));
129*16a367d4SAndreas Gohr        if(empty($ID)) return;
130*16a367d4SAndreas Gohr
131*16a367d4SAndreas Gohr        $INFO = pageinfo();
132*16a367d4SAndreas Gohr
133*16a367d4SAndreas Gohr        if(!$INFO['writable']) {
134*16a367d4SAndreas Gohr            echo 'Permission denied';
135*16a367d4SAndreas Gohr            return;
136*16a367d4SAndreas Gohr        }
137*16a367d4SAndreas Gohr
138*16a367d4SAndreas Gohr        if(!checklock($ID)) {
139*16a367d4SAndreas Gohr            lock($ID);
140*16a367d4SAndreas Gohr            echo 1;
141*16a367d4SAndreas Gohr        }
142*16a367d4SAndreas Gohr
143*16a367d4SAndreas Gohr        if($conf['usedraft'] && $INPUT->post->str('wikitext')) {
144*16a367d4SAndreas Gohr            $client = $_SERVER['REMOTE_USER'];
145*16a367d4SAndreas Gohr            if(!$client) $client = clientIP(true);
146*16a367d4SAndreas Gohr
147*16a367d4SAndreas Gohr            $draft = array(
148*16a367d4SAndreas Gohr                'id' => $ID,
149*16a367d4SAndreas Gohr                'prefix' => substr($INPUT->post->str('prefix'), 0, -1),
150*16a367d4SAndreas Gohr                'text' => $INPUT->post->str('wikitext'),
151*16a367d4SAndreas Gohr                'suffix' => $INPUT->post->str('suffix'),
152*16a367d4SAndreas Gohr                'date' => $INPUT->post->int('date'),
153*16a367d4SAndreas Gohr                'client' => $client,
154*16a367d4SAndreas Gohr            );
155*16a367d4SAndreas Gohr            $cname = getCacheName($draft['client'] . $ID, '.draft');
156*16a367d4SAndreas Gohr            if(io_saveFile($cname, serialize($draft))) {
157*16a367d4SAndreas Gohr                echo $lang['draftdate'] . ' ' . dformat();
158*16a367d4SAndreas Gohr            }
159*16a367d4SAndreas Gohr        }
160*16a367d4SAndreas Gohr
161*16a367d4SAndreas Gohr    }
162*16a367d4SAndreas Gohr
163*16a367d4SAndreas Gohr    /**
164*16a367d4SAndreas Gohr     * Delete a draft
165*16a367d4SAndreas Gohr     *
166*16a367d4SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
167*16a367d4SAndreas Gohr     */
168*16a367d4SAndreas Gohr    protected function call_draftdel() {
169*16a367d4SAndreas Gohr        global $INPUT;
170*16a367d4SAndreas Gohr        $id = cleanID($INPUT->str('id'));
171*16a367d4SAndreas Gohr        if(empty($id)) return;
172*16a367d4SAndreas Gohr
173*16a367d4SAndreas Gohr        $client = $_SERVER['REMOTE_USER'];
174*16a367d4SAndreas Gohr        if(!$client) $client = clientIP(true);
175*16a367d4SAndreas Gohr
176*16a367d4SAndreas Gohr        $cname = getCacheName($client . $id, '.draft');
177*16a367d4SAndreas Gohr        @unlink($cname);
178*16a367d4SAndreas Gohr    }
179*16a367d4SAndreas Gohr
180*16a367d4SAndreas Gohr    /**
181*16a367d4SAndreas Gohr     * Return subnamespaces for the Mediamanager
182*16a367d4SAndreas Gohr     *
183*16a367d4SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
184*16a367d4SAndreas Gohr     */
185*16a367d4SAndreas Gohr    protected function call_medians() {
186*16a367d4SAndreas Gohr        global $conf;
187*16a367d4SAndreas Gohr        global $INPUT;
188*16a367d4SAndreas Gohr
189*16a367d4SAndreas Gohr        // wanted namespace
190*16a367d4SAndreas Gohr        $ns = cleanID($INPUT->post->str('ns'));
191*16a367d4SAndreas Gohr        $dir = utf8_encodeFN(str_replace(':', '/', $ns));
192*16a367d4SAndreas Gohr
193*16a367d4SAndreas Gohr        $lvl = count(explode(':', $ns));
194*16a367d4SAndreas Gohr
195*16a367d4SAndreas Gohr        $data = array();
196*16a367d4SAndreas Gohr        search($data, $conf['mediadir'], 'search_index', array('nofiles' => true), $dir);
197*16a367d4SAndreas Gohr        foreach(array_keys($data) as $item) {
198*16a367d4SAndreas Gohr            $data[$item]['level'] = $lvl + 1;
199*16a367d4SAndreas Gohr        }
200*16a367d4SAndreas Gohr        echo html_buildlist($data, 'idx', 'media_nstree_item', 'media_nstree_li');
201*16a367d4SAndreas Gohr    }
202*16a367d4SAndreas Gohr
203*16a367d4SAndreas Gohr    /**
204*16a367d4SAndreas Gohr     * Return list of files for the Mediamanager
205*16a367d4SAndreas Gohr     *
206*16a367d4SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
207*16a367d4SAndreas Gohr     */
208*16a367d4SAndreas Gohr    protected function call_medialist() {
209*16a367d4SAndreas Gohr        global $NS;
210*16a367d4SAndreas Gohr        global $INPUT;
211*16a367d4SAndreas Gohr
212*16a367d4SAndreas Gohr        $NS = cleanID($INPUT->post->str('ns'));
213*16a367d4SAndreas Gohr        $sort = $INPUT->post->bool('recent') ? 'date' : 'natural';
214*16a367d4SAndreas Gohr        if($INPUT->post->str('do') == 'media') {
215*16a367d4SAndreas Gohr            tpl_mediaFileList();
216*16a367d4SAndreas Gohr        } else {
217*16a367d4SAndreas Gohr            tpl_mediaContent(true, $sort);
218*16a367d4SAndreas Gohr        }
219*16a367d4SAndreas Gohr    }
220*16a367d4SAndreas Gohr
221*16a367d4SAndreas Gohr    /**
222*16a367d4SAndreas Gohr     * Return the content of the right column
223*16a367d4SAndreas Gohr     * (image details) for the Mediamanager
224*16a367d4SAndreas Gohr     *
225*16a367d4SAndreas Gohr     * @author Kate Arzamastseva <pshns@ukr.net>
226*16a367d4SAndreas Gohr     */
227*16a367d4SAndreas Gohr    protected function call_mediadetails() {
228*16a367d4SAndreas Gohr        global $IMG, $JUMPTO, $REV, $fullscreen, $INPUT;
229*16a367d4SAndreas Gohr        $fullscreen = true;
230*16a367d4SAndreas Gohr        require_once(DOKU_INC . 'lib/exe/mediamanager.php');
231*16a367d4SAndreas Gohr
232*16a367d4SAndreas Gohr        $image = '';
233*16a367d4SAndreas Gohr        if($INPUT->has('image')) $image = cleanID($INPUT->str('image'));
234*16a367d4SAndreas Gohr        if(isset($IMG)) $image = $IMG;
235*16a367d4SAndreas Gohr        if(isset($JUMPTO)) $image = $JUMPTO;
236*16a367d4SAndreas Gohr        $rev = false;
237*16a367d4SAndreas Gohr        if(isset($REV) && !$JUMPTO) $rev = $REV;
238*16a367d4SAndreas Gohr
239*16a367d4SAndreas Gohr        html_msgarea();
240*16a367d4SAndreas Gohr        tpl_mediaFileDetails($image, $rev);
241*16a367d4SAndreas Gohr    }
242*16a367d4SAndreas Gohr
243*16a367d4SAndreas Gohr    /**
244*16a367d4SAndreas Gohr     * Returns image diff representation for mediamanager
245*16a367d4SAndreas Gohr     *
246*16a367d4SAndreas Gohr     * @author Kate Arzamastseva <pshns@ukr.net>
247*16a367d4SAndreas Gohr     */
248*16a367d4SAndreas Gohr    protected function call_mediadiff() {
249*16a367d4SAndreas Gohr        global $NS;
250*16a367d4SAndreas Gohr        global $INPUT;
251*16a367d4SAndreas Gohr
252*16a367d4SAndreas Gohr        $image = '';
253*16a367d4SAndreas Gohr        if($INPUT->has('image')) $image = cleanID($INPUT->str('image'));
254*16a367d4SAndreas Gohr        $NS = getNS($image);
255*16a367d4SAndreas Gohr        $auth = auth_quickaclcheck("$NS:*");
256*16a367d4SAndreas Gohr        media_diff($image, $NS, $auth, true);
257*16a367d4SAndreas Gohr    }
258*16a367d4SAndreas Gohr
259*16a367d4SAndreas Gohr    /**
260*16a367d4SAndreas Gohr     * Manages file uploads
261*16a367d4SAndreas Gohr     *
262*16a367d4SAndreas Gohr     * @author Kate Arzamastseva <pshns@ukr.net>
263*16a367d4SAndreas Gohr     */
264*16a367d4SAndreas Gohr    protected function call_mediaupload() {
265*16a367d4SAndreas Gohr        global $NS, $MSG, $INPUT;
266*16a367d4SAndreas Gohr
267*16a367d4SAndreas Gohr        $id = '';
268*16a367d4SAndreas Gohr        if($_FILES['qqfile']['tmp_name']) {
269*16a367d4SAndreas Gohr            $id = $INPUT->post->str('mediaid', $_FILES['qqfile']['name']);
270*16a367d4SAndreas Gohr        } elseif($INPUT->get->has('qqfile')) {
271*16a367d4SAndreas Gohr            $id = $INPUT->get->str('qqfile');
272*16a367d4SAndreas Gohr        }
273*16a367d4SAndreas Gohr
274*16a367d4SAndreas Gohr        $id = cleanID($id);
275*16a367d4SAndreas Gohr
276*16a367d4SAndreas Gohr        $NS = $INPUT->str('ns');
277*16a367d4SAndreas Gohr        $ns = $NS . ':' . getNS($id);
278*16a367d4SAndreas Gohr
279*16a367d4SAndreas Gohr        $AUTH = auth_quickaclcheck("$ns:*");
280*16a367d4SAndreas Gohr        if($AUTH >= AUTH_UPLOAD) {
281*16a367d4SAndreas Gohr            io_createNamespace("$ns:xxx", 'media');
282*16a367d4SAndreas Gohr        }
283*16a367d4SAndreas Gohr
284*16a367d4SAndreas Gohr        if($_FILES['qqfile']['error']) unset($_FILES['qqfile']);
285*16a367d4SAndreas Gohr
286*16a367d4SAndreas Gohr        $res = false;
287*16a367d4SAndreas Gohr        if($_FILES['qqfile']['tmp_name']) $res = media_upload($NS, $AUTH, $_FILES['qqfile']);
288*16a367d4SAndreas Gohr        if($INPUT->get->has('qqfile')) $res = media_upload_xhr($NS, $AUTH);
289*16a367d4SAndreas Gohr
290*16a367d4SAndreas Gohr        if($res) {
291*16a367d4SAndreas Gohr            $result = array(
292*16a367d4SAndreas Gohr                'success' => true,
293*16a367d4SAndreas Gohr                'link' => media_managerURL(array('ns' => $ns, 'image' => $NS . ':' . $id), '&'),
294*16a367d4SAndreas Gohr                'id' => $NS . ':' . $id,
295*16a367d4SAndreas Gohr                'ns' => $NS
296*16a367d4SAndreas Gohr            );
297*16a367d4SAndreas Gohr        } else {
298*16a367d4SAndreas Gohr            $error = '';
299*16a367d4SAndreas Gohr            if(isset($MSG)) {
300*16a367d4SAndreas Gohr                foreach($MSG as $msg) {
301*16a367d4SAndreas Gohr                    $error .= $msg['msg'];
302*16a367d4SAndreas Gohr                }
303*16a367d4SAndreas Gohr            }
304*16a367d4SAndreas Gohr            $result = array(
305*16a367d4SAndreas Gohr                'error' => $error,
306*16a367d4SAndreas Gohr                'ns' => $NS
307*16a367d4SAndreas Gohr            );
308*16a367d4SAndreas Gohr        }
309*16a367d4SAndreas Gohr        $json = new \JSON;
310*16a367d4SAndreas Gohr        header('Content-Type: application/json');
311*16a367d4SAndreas Gohr        echo $json->encode($result);
312*16a367d4SAndreas Gohr    }
313*16a367d4SAndreas Gohr
314*16a367d4SAndreas Gohr    /**
315*16a367d4SAndreas Gohr     * Return sub index for index view
316*16a367d4SAndreas Gohr     *
317*16a367d4SAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
318*16a367d4SAndreas Gohr     */
319*16a367d4SAndreas Gohr    protected function call_index() {
320*16a367d4SAndreas Gohr        global $conf;
321*16a367d4SAndreas Gohr        global $INPUT;
322*16a367d4SAndreas Gohr
323*16a367d4SAndreas Gohr        // wanted namespace
324*16a367d4SAndreas Gohr        $ns = cleanID($INPUT->post->str('idx'));
325*16a367d4SAndreas Gohr        $dir = utf8_encodeFN(str_replace(':', '/', $ns));
326*16a367d4SAndreas Gohr
327*16a367d4SAndreas Gohr        $lvl = count(explode(':', $ns));
328*16a367d4SAndreas Gohr
329*16a367d4SAndreas Gohr        $data = array();
330*16a367d4SAndreas Gohr        search($data, $conf['datadir'], 'search_index', array('ns' => $ns), $dir);
331*16a367d4SAndreas Gohr        foreach(array_keys($data) as $item) {
332*16a367d4SAndreas Gohr            $data[$item]['level'] = $lvl + 1;
333*16a367d4SAndreas Gohr        }
334*16a367d4SAndreas Gohr        echo html_buildlist($data, 'idx', 'html_list_index', 'html_li_index');
335*16a367d4SAndreas Gohr    }
336*16a367d4SAndreas Gohr
337*16a367d4SAndreas Gohr    /**
338*16a367d4SAndreas Gohr     * List matching namespaces and pages for the link wizard
339*16a367d4SAndreas Gohr     *
340*16a367d4SAndreas Gohr     * @author Andreas Gohr <gohr@cosmocode.de>
341*16a367d4SAndreas Gohr     */
342*16a367d4SAndreas Gohr    protected function call_linkwiz() {
343*16a367d4SAndreas Gohr        global $conf;
344*16a367d4SAndreas Gohr        global $lang;
345*16a367d4SAndreas Gohr        global $INPUT;
346*16a367d4SAndreas Gohr
347*16a367d4SAndreas Gohr        $q = ltrim(trim($INPUT->post->str('q')), ':');
348*16a367d4SAndreas Gohr        $id = noNS($q);
349*16a367d4SAndreas Gohr        $ns = getNS($q);
350*16a367d4SAndreas Gohr
351*16a367d4SAndreas Gohr        $ns = cleanID($ns);
352*16a367d4SAndreas Gohr        $id = cleanID($id);
353*16a367d4SAndreas Gohr
354*16a367d4SAndreas Gohr        $nsd = utf8_encodeFN(str_replace(':', '/', $ns));
355*16a367d4SAndreas Gohr
356*16a367d4SAndreas Gohr        $data = array();
357*16a367d4SAndreas Gohr        if($q && !$ns) {
358*16a367d4SAndreas Gohr
359*16a367d4SAndreas Gohr            // use index to lookup matching pages
360*16a367d4SAndreas Gohr            $pages = ft_pageLookup($id, true);
361*16a367d4SAndreas Gohr
362*16a367d4SAndreas Gohr            // result contains matches in pages and namespaces
363*16a367d4SAndreas Gohr            // we now extract the matching namespaces to show
364*16a367d4SAndreas Gohr            // them seperately
365*16a367d4SAndreas Gohr            $dirs = array();
366*16a367d4SAndreas Gohr
367*16a367d4SAndreas Gohr            foreach($pages as $pid => $title) {
368*16a367d4SAndreas Gohr                if(strpos(noNS($pid), $id) === false) {
369*16a367d4SAndreas Gohr                    // match was in the namespace
370*16a367d4SAndreas Gohr                    $dirs[getNS($pid)] = 1; // assoc array avoids dupes
371*16a367d4SAndreas Gohr                } else {
372*16a367d4SAndreas Gohr                    // it is a matching page, add it to the result
373*16a367d4SAndreas Gohr                    $data[] = array(
374*16a367d4SAndreas Gohr                        'id' => $pid,
375*16a367d4SAndreas Gohr                        'title' => $title,
376*16a367d4SAndreas Gohr                        'type' => 'f',
377*16a367d4SAndreas Gohr                    );
378*16a367d4SAndreas Gohr                }
379*16a367d4SAndreas Gohr                unset($pages[$pid]);
380*16a367d4SAndreas Gohr            }
381*16a367d4SAndreas Gohr            foreach($dirs as $dir => $junk) {
382*16a367d4SAndreas Gohr                $data[] = array(
383*16a367d4SAndreas Gohr                    'id' => $dir,
384*16a367d4SAndreas Gohr                    'type' => 'd',
385*16a367d4SAndreas Gohr                );
386*16a367d4SAndreas Gohr            }
387*16a367d4SAndreas Gohr
388*16a367d4SAndreas Gohr        } else {
389*16a367d4SAndreas Gohr
390*16a367d4SAndreas Gohr            $opts = array(
391*16a367d4SAndreas Gohr                'depth' => 1,
392*16a367d4SAndreas Gohr                'listfiles' => true,
393*16a367d4SAndreas Gohr                'listdirs' => true,
394*16a367d4SAndreas Gohr                'pagesonly' => true,
395*16a367d4SAndreas Gohr                'firsthead' => true,
396*16a367d4SAndreas Gohr                'sneakyacl' => $conf['sneaky_index'],
397*16a367d4SAndreas Gohr            );
398*16a367d4SAndreas Gohr            if($id) $opts['filematch'] = '^.*\/' . $id;
399*16a367d4SAndreas Gohr            if($id) $opts['dirmatch'] = '^.*\/' . $id;
400*16a367d4SAndreas Gohr            search($data, $conf['datadir'], 'search_universal', $opts, $nsd);
401*16a367d4SAndreas Gohr
402*16a367d4SAndreas Gohr            // add back to upper
403*16a367d4SAndreas Gohr            if($ns) {
404*16a367d4SAndreas Gohr                array_unshift(
405*16a367d4SAndreas Gohr                    $data, array(
406*16a367d4SAndreas Gohr                             'id' => getNS($ns),
407*16a367d4SAndreas Gohr                             'type' => 'u',
408*16a367d4SAndreas Gohr                         )
409*16a367d4SAndreas Gohr                );
410*16a367d4SAndreas Gohr            }
411*16a367d4SAndreas Gohr        }
412*16a367d4SAndreas Gohr
413*16a367d4SAndreas Gohr        // fixme sort results in a useful way ?
414*16a367d4SAndreas Gohr
415*16a367d4SAndreas Gohr        if(!count($data)) {
416*16a367d4SAndreas Gohr            echo $lang['nothingfound'];
417*16a367d4SAndreas Gohr            exit;
418*16a367d4SAndreas Gohr        }
419*16a367d4SAndreas Gohr
420*16a367d4SAndreas Gohr        // output the found data
421*16a367d4SAndreas Gohr        $even = 1;
422*16a367d4SAndreas Gohr        foreach($data as $item) {
423*16a367d4SAndreas Gohr            $even *= -1; //zebra
424*16a367d4SAndreas Gohr
425*16a367d4SAndreas Gohr            if(($item['type'] == 'd' || $item['type'] == 'u') && $item['id']) $item['id'] .= ':';
426*16a367d4SAndreas Gohr            $link = wl($item['id']);
427*16a367d4SAndreas Gohr
428*16a367d4SAndreas Gohr            echo '<div class="' . (($even > 0) ? 'even' : 'odd') . ' type_' . $item['type'] . '">';
429*16a367d4SAndreas Gohr
430*16a367d4SAndreas Gohr            if($item['type'] == 'u') {
431*16a367d4SAndreas Gohr                $name = $lang['upperns'];
432*16a367d4SAndreas Gohr            } else {
433*16a367d4SAndreas Gohr                $name = hsc($item['id']);
434*16a367d4SAndreas Gohr            }
435*16a367d4SAndreas Gohr
436*16a367d4SAndreas Gohr            echo '<a href="' . $link . '" title="' . hsc($item['id']) . '" class="wikilink1">' . $name . '</a>';
437*16a367d4SAndreas Gohr
438*16a367d4SAndreas Gohr            if(!blank($item['title'])) {
439*16a367d4SAndreas Gohr                echo '<span>' . hsc($item['title']) . '</span>';
440*16a367d4SAndreas Gohr            }
441*16a367d4SAndreas Gohr            echo '</div>';
442*16a367d4SAndreas Gohr        }
443*16a367d4SAndreas Gohr
444*16a367d4SAndreas Gohr    }
445*16a367d4SAndreas Gohr
446*16a367d4SAndreas Gohr}
447