]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/FullTextSearch.php
More infiltration of new object-based HTML generation.
[SourceForge/phpwiki.git] / lib / plugin / FullTextSearch.php
1 <?php // -*-php-*-
2 rcs_id('$Id: FullTextSearch.php,v 1.6 2002-01-21 06:55:47 dairiki Exp $');
3
4 require_once('lib/TextSearchQuery.php');
5
6 /**
7  */
8 class WikiPlugin_FullTextSearch
9 extends WikiPlugin
10 {
11     function getName () {
12         return _("FullTextSearch");
13     }
14
15     function getDescription () {
16         return _("Full Text Search");
17     }
18
19     function getDefaultArguments() {
20         return array('s'                => false,
21                      'noheader'         => false);
22     }
23
24         
25     function run($dbi, $argstr, $request) {
26
27         $args = $this->getArgs($argstr, $request);
28         if (empty($args['s']))
29             return '';
30
31         extract($args);
32         
33         $query = new TextSearchQuery($s);
34         $pages = $dbi->fullSearch($query);
35         $lines = array();
36         $hilight_re = $query->getHighlightRegexp();
37         $count = 0;
38         $found = 0;
39
40         $list = HTML::dl();
41         global $Theme;
42         
43         while ($page = $pages->next()) {
44             $count++;
45             $name = $page->getName();
46             $list->pushContent(HTML::dt($Theme->linkExistingWikiWord($name)));
47             if ($hilight_re)
48                 $list->pushContent($this->showhits($page, $hilight_re));
49         }
50         if (!$list->getContent())
51             $list->pushContent(HTML::dd(_("<no matches>")));
52
53         if ($noheader)
54             return $list;
55         
56         return array(HTML::p(fmt("Full text search results for '%s'", $s)),
57                      $list);
58     }
59
60     function showhits($page, $hilight_re) {
61         $FS = &$GLOBALS['FieldSeparator'];
62         $current = $page->getCurrentRevision();
63         $matches = preg_grep("/$hilight_re/i", $current->getContent());
64         $html = array();
65         foreach ($matches as $line) {
66             $line = str_replace($FS, '', $line);
67             $line = preg_replace("/$hilight_re/i", "${FS}OT\\0${FS}CT", $line);
68             $line = htmlspecialchars($line);
69             $line = str_replace("${FS}OT", '<strong>', $line);
70             $line = str_replace("${FS}CT", '</strong>', $line);
71             $html[] = HTML::dd(HTML::small(new RawXml($line)));
72         }
73         return $html;
74     }
75 };
76         
77 // Local Variables:
78 // mode: php
79 // tab-width: 8
80 // c-basic-offset: 4
81 // c-hanging-comment-ender-p: nil
82 // indent-tabs-mode: nil
83 // End:   
84 ?>