1<?php
2/**
3 * DokuWiki Plugin singlesearchresult (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Matthias Schulte <dokuwiki@lupo49.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12if(!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if(!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
15
16class action_plugin_singlesearchresult extends DokuWiki_Action_Plugin {
17
18    public function register(Doku_Event_Handler $controller) {
19        $controller->register_hook('SEARCH_QUERY_FULLPAGE', 'AFTER', $this, 'handle_search_query_pagelookup');
20    }
21
22    public function handle_search_query_pagelookup(Doku_Event &$event, $param) {
23        global $conf;
24        $result = $event->result;
25
26        // Only one page found, skip result overview and open the found page
27        if(count($result) == 1) {
28            $pageid = key($result);
29
30            if($_SERVER['REMOTE_USER']) {
31                $perm = auth_quickaclcheck($pageid);
32            } else {
33                $perm = auth_aclcheck($pageid, '', null);
34            }
35
36            if($perm > AUTH_NONE) {
37                if($conf['allowdebug']) {
38                    msg("Only one page found, skipping result overview. Redirect to: ".$pageid);
39                }
40                $link = wl($pageid, '', true);
41                print "<script type='text/javascript'>window.location.href='$link'</script>";
42            }
43        }
44    }
45}
46
47// vim:ts=4:sw=4:et:
48