1<?php
2/**
3 * A Dokuwiki plugin to add a "Go" button to the search form that will go to a page instead of searching.
4 *
5 * @license    GPL (see file COPYING)
6 * @author     Payton Swick <payton (at) foolord (dot) com>
7 *
8 * To activate, put this in the template instead of '<?php tpl_searchform() ?>':
9 *
10 * <?php if (!plugin_isdisabled('searchformgoto')) { tpl_gotoform(); } else { tpl_searchform(); } ?>
11 *
12 */
13
14// must be run within Dokuwiki
15if(!defined('DOKU_INC')) die();
16
17if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
18require_once(DOKU_PLUGIN.'action.php');
19
20class action_plugin_searchformgoto extends DokuWiki_Action_Plugin {
21
22    function getInfo() {
23        return array(
24                'author' => 'Payton Swick',
25                'email'  => 'payton@foolord.com',
26                'date'   => @file_get_contents(DOKU_PLUGIN . 'searchformgoto/VERSION'),
27                'name'   => 'SearchFormGoto Plugin',
28                'desc'   => 'The search form now has a "Go" button which will go to a page instead of searching.',
29                'url'    => 'http://wiki.splitbrain.org/plugin:searchformgoto',
30                );
31    }
32
33    function register(&$contr) {
34        $contr->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_act_preprocess', array());
35   }
36
37
38
39
40    function handle_act_preprocess(&$event, $param) {
41        if ($event->data != 'goto') return;
42        $event->preventDefault();
43
44        $event->data = $this->_handle_goto();
45    }
46
47    function _handle_goto() {
48      global $ID;
49      global $QUERY;
50      global $conf;
51      global $INFO;
52      global $lang;
53
54      $s = cleanID($QUERY);
55      if(empty($s)) {
56        $ACT = 'show';
57      } else {
58        // Check if the 'Go' or the 'Search' button was pressed.
59        if ($_REQUEST['goto'] and $_REQUEST['goto'] == $lang['btn_search']) {
60          $ACT = 'search';
61        }
62        else {
63          $ns  = $_REQUEST['current_ns'];
64          $page_id = $s;
65          if (!preg_match('/\w+:\w+/', $page_id) and preg_match('/\w/', $ns))
66            $page_id = $ns.':'.$page_id;
67
68          $ns = (getNS($page_id) ? getNS($page_id) : '');
69          $no_ns = (noNS($page_id) ? noNS($page_id) : '');
70          resolve_pageid($ns, $no_ns, $exists);
71          $ID = $page_id;
72          if (!$exists) {
73            $ACT = 'search';
74          } else {
75            $ACT = 'show';
76          }
77        }
78      }
79      $INFO = pageinfo();
80      $ACT = act_permcheck($ACT);
81      return $ACT;
82    }
83}
84
85