Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lupo49 committed Apr 7, 2013
0 parents commit 5b46258
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
singlesearchresult Plugin for DokuWiki

Redirects directly to found page when only one page is found

All documentation for this plugin can be found at
https://www.dokuwiki.org/plugin:singlesearchresult

If you install this plugin manually, make sure it is installed in
lib/plugins/singlesearchresult/ - if the folder is called different it
will not work!

Please refer to http://www.dokuwiki.org/plugins for additional info
on how to install plugins in DokuWiki.

----
Copyright (C) Matthias Schulte <dokuwiki@lupo49.de>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

See the COPYING file in your DokuWiki folder for details
52 changes: 52 additions & 0 deletions action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* DokuWiki Plugin singlesearchresult (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Matthias Schulte <dokuwiki@lupo49.de>
*/

// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

if(!defined('DOKU_LF')) define('DOKU_LF', "\n");
if(!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');

require_once DOKU_PLUGIN.'action.php';

class action_plugin_singlesearchresult extends DokuWiki_Action_Plugin {

public function register(Doku_Event_Handler &$controller) {
$controller->register_hook('SEARCH_QUERY_FULLPAGE', 'AFTER', $this, 'handle_search_query_pagelookup');
//$controller->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'handle_search_query_pagelookup1');
}

// Bei einem Ergebnis ein trigger_event (ACTION_ACT_PREPROCESS) ausl�sen, dass ein redirect macht.?
public function handle_search_query_pagelookup(Doku_Event &$event, $param) {
global $conf;
$result = $event->result;

// Only one page found, skip result overview and open the found page
if(count($result) == 1) {
$pageid = key($result);

if($_SERVER['REMOTE_USER']) {
$perm = auth_quickaclcheck($pageid);
} else {
$perm = auth_aclcheck($pageid, '', null);
}

if($perm > AUTH_NONE) {
if($conf['allowdebug']) {
msg("Only one page found, skipping result overview. Redirect to: " . $pageid);
}
$link = wl($pageid, '', true);
print "<script type='text/javascript'>window.location.href='$link'</script>";
}
}
}
}

// vim:ts=4:sw=4:et:
7 changes: 7 additions & 0 deletions plugin.info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
base singlesearchresult
author Matthias Schulte
email dokuwiki@lupo49.de
date 2013-04-07
name singlesearchresult plugin
desc Redirects directly to found page when only one page is found
url https://www.dokuwiki.org/plugin:singlesearchresult

0 comments on commit 5b46258

Please sign in to comment.