1<?php 2/** 3 * Plugin Search Form: Inserts a search form in any page 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Sergio Merino <sergio.merino@thecorpora.com> 7 * @code based on the plugin searchform from Adolfo González Blázquez 8 */ 9 10// must be run within Dokuwiki 11if(!defined('DOKU_INC')) die(); 12 13/** 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 */ 17class syntax_plugin_confsearch extends DokuWiki_Syntax_Plugin { 18 19 public function getType() { return 'substition'; } 20 21 public function getSort() { return 138; } 22 23 public function connectTo($mode) { 24 $this->Lexer->addSpecialPattern('\{confsearch[^\}]*\}',$mode,'plugin_confsearch'); 25 } 26 27 protected function getLastCrumb() 28 { 29 $br = breadcrumbs(); 30 $lastcrumb = ''; 31 foreach ($br as $a=>$b) $lastcrumb=$a; 32 return $lastcrumb; 33 } 34 35 public function getBaseNs($id) 36 { 37 return getNS(cleanID($id)); 38 } 39 40 public function handle($match, $state, $pos, Doku_Handler $handler) { 41 return array($match, $state, $pos); 42 } 43 44 protected function buttonname($data) { 45 $params=trim($data[0]," \{\}"); 46 list($pluginname,$parameters,$button)=explode('>',$params,3); 47 $replacedparams = str_replace(array( 48 '@NS@', 49 '@USER@', 50 ), 51 array( 52 $this->getBaseNs($this->getLastCrumb()), 53 $_SERVER['REMOTE_USER'], 54 ), $button); 55 if ($replacedparams=="") 56 $replacedparams="Search"; 57 return $replacedparams; 58 } 59 60 protected function processparameters($data) { 61 $params=trim($data[0]," \{\}"); 62 list($pluginname,$parameters,$button)=explode('>',$params,3); 63 $replacedparams = str_replace(array( 64 '@NS@', 65 '@USER@', 66 ), 67 array( 68 $this->getBaseNs($this->getLastCrumb()), 69 $_SERVER['REMOTE_USER'], 70 ), $parameters); 71 return $replacedparams; 72 } 73 74 public function render($mode, Doku_Renderer $renderer, $data) { 75 76 global $lang; 77 78 79 if ($mode == 'xhtml') { 80 81 $renderer->doc .= '<div id="searchform_plugin">'."\n"; 82 $renderer->doc .= '<form name="ns_search" action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search2" method="get"><div class="no">'."\n"; 83 $renderer->doc .= '<input type="hidden" name="do" value="search" />'."\n"; 84 $renderer->doc .= '<input type="hidden" id="dw__ns" name="ns" value="'.$this->processparameters($data).'">'."\n"; 85//Debug line $renderer->doc .= 'Debug--'.$this->processparameters($data); 86 $renderer->doc .= '<input type="text" id="qsearch2__in" accesskey="f" name="id" class="edit" autocomplete="off">'."\n"; 87 $renderer->doc .= '<input type="submit" value="'.$this->buttonname($data).'" class="button" title="Search App" onclick= "document.ns_search.id.value= document.ns_search.id.value+\' \'+document.ns_search.ns.value" />'."\n"; 88 89 $renderer->doc .= '<div id="qsearch2__out" class="ajax_qsearch JSpopup"></div>'."\n"; 90 $renderer->doc .= '</div></form>'."\n"; 91 $renderer->doc .= '</div>'."\n"; 92 return true; 93 } 94 return false; 95 } 96} 97?> 98