1<?php
2/**
3 * SearchText Action Plugin
4 *
5 * @author     Michael Hamann <michael@content-space.de>
6 * @author     Todd Augsburger <todd@rollerorgans.com>
7 */
8
9if(!defined('DOKU_INC')) die();
10
11class action_plugin_searchtext extends DokuWiki_Action_Plugin {
12  function register(Doku_Event_Handler $controller) {
13    $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE',  $this, '_getSearch');
14    $controller->register_hook('FULLTEXT_SNIPPET_CREATE', 'BEFORE',  $this, '_getSnippet');
15    $controller->register_hook('INDEXER_VERSION_GET', 'BEFORE', $this, '_indexerVersion');
16  }
17
18  function _indexerVersion(&$event, $param) {
19    if ($this->getConf('search_in_text')) {
20      $text_plugin = plugin_load('renderer', 'text');
21      if ($text_plugin != NULL) {
22        $text_info = $text_plugin->getInfo();
23        $event->data['plugin_searchtext'] = '1-' . $text_info['date'];
24      }
25    }
26  }
27
28  function _getSearch(&$event, $param) {
29    if($this->getConf('search_in_text')) {
30      global $ID;
31
32      $prevID = $ID;
33      $ID = $event->data['page'];
34      $event->data['body'] .= p_cached_output(wikiFN($event->data['page']),'text');
35      $ID = $prevID;
36      $event->preventDefault();
37    }
38  }
39
40  function _getSnippet(&$event, $param) {
41    if($this->getConf('snippet_in_text')) {
42      global $ID;
43
44      $prevID = $ID;
45      $ID = $event->data['id'];
46      $event->data['text'] = p_cached_output(wikiFN($event->data['id']),'text');
47      $ID = $prevID;
48    }
49  }
50}
51