1<?php 2if(!defined('DOKU_INC')) die(); 3 4class action_plugin_selectsearch extends DokuWiki_Action_Plugin { 5 6 /** 7 * Register its handlers with the DokuWiki's event controller 8 */ 9 function register(&$controller) { 10 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, '_fixquery'); 11 } 12 13 /** 14 * Put namespace into search 15 */ 16 function _fixquery(&$event, $param) { 17 global $QUERY; 18 global $ACT; 19 20 if($ACT != 'search'){ 21 $QUERY = ''; 22 return; 23 } 24 25 if(trim($_REQUEST['namespace'])){ 26 $QUERY .= ' @'.trim($_REQUEST['namespace']); 27 } 28 } 29 30 function tpl_searchform() { 31 32 global $QUERY; 33 34 $searchnamespaces = explode("\n",$this->getConf('searchnamespaces')); 35 foreach ($searchnamespaces as $ns) { 36 list($namespace,$displayname) = explode("|",$ns); 37 trim($namespace); 38 trim($displayname); 39 $namespaces[$namespace] = $displayname; 40 } 41 42 $cur_val = isset($_REQUEST['namespace']) ? $_REQUEST['namespace'] : ''; 43 44 echo '<form id="dw__search" class="search" method="post" accept-charset="utf-8" action="">'; 45 echo '<div class="no">'; 46 echo '<select class="selectsearch_namespace" name="namespace">'; 47 foreach ($namespaces as $ns => $displayname){ 48 echo '<option value="'.hsc($ns).'"'.($cur_val === $ns ? ' selected="selected"' : '').'>'.hsc($displayname).'</option>'; 49 } 50 echo '</select>'; 51 echo '<input type="hidden" name="do" value="search" />'; 52 echo '<input type="hidden" id="qsearch__in"/>'; 53 echo '<input class="edit" id="selectsearch__input" type="text" name="id" autocomplete="off" title="[F]" value="'.hsc(preg_replace('/ ?@\S+/','',$QUERY)).'" accesskey="f" />'; 54 echo '<input class="button" type="submit" title="Search" value="Search">'; 55 echo '<div id="qsearch__out" class="ajax_qsearch JSpopup" style="display: none;"></div>'; 56 echo '</div>'; 57 echo '</form>'; 58 } 59} 60