* @author @license GPL 2 (http://www.gnu.org/licenses/gpl.html) */ if(!defined('DOKU_INC')) die(); class action_plugin_docsearch_search extends DokuWiki_Action_Plugin { private $backupConfig; function register(Doku_Event_Handler $controller) { $controller->register_hook('TPL_CONTENT_DISPLAY', 'AFTER', $this, 'display', array()); } function display(Doku_Event &$event, $param) { global $ACT; global $conf; global $QUERY; global $lang; // only work with search if($ACT !== 'search') return; // backup the config array $this->backupConfig = $conf; // change index/pages folder for DocSearch $conf['indexdir'] = $conf['savedir'] . '/docsearch/index'; $conf['datadir'] = $conf['savedir'] . '/docsearch/pages'; $data = ft_pageSearch($QUERY, $regex); if(empty($data)) { $conf = $this->backupConfig; return; } $searchResults = array(); $runs = 0; foreach($data as $id => $hits) { $searchResults[$id] = array(); $searchResults[$id]['hits'] = $hits; if($runs++ < $this->getConf('showSnippets')) { $searchResults[$id]['snippet'] = ft_snippet($id, $regex); } } $conf = $this->backupConfig; echo '

' . hsc($this->getLang('title')) . '

'; echo '
'; $num = 0; foreach($searchResults as $id => $data) { if($this->getConf('showUsage') !== 0) { $usages = ft_mediause($id, $this->getConf('showUsage')); } else { $usages = array(); } echo '' . hsc($id) . ': '; echo '' . hsc($data['hits']) . ' ' . hsc($lang['hits']) . ''; if(!empty($usages)) { echo ''; echo ', ' . hsc($this->getLang('usage')) . ' '; foreach($usages as $usage) { echo html_wikilink($usage); } echo ''; } if(isset($data['snippet'])) { echo '
'; echo $data['snippet']; echo '
'; } echo '
'; $num++; } echo '
'; } }