]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/fullsearch.php
More munging of the translated pgsrc and templates.
[SourceForge/phpwiki.git] / lib / fullsearch.php
1 <?php
2    // Search the text of pages for a match.
3    rcs_id('$Id: fullsearch.php,v 1.6 2001-02-12 01:43:10 dairiki Exp $');
4
5    if (empty($searchterm))
6       $searchterm = '';         // FIXME: do something better here?
7
8    fix_magic_quotes_gpc($searchterm);
9
10    $html = "<P><B>"
11            . sprintf(gettext ("Searching for \"%s\" ....."),
12                    htmlspecialchars($searchterm))
13            . "</B></P>\n<DL>\n";
14
15    // search matching pages
16    $query = InitFullSearch($dbi, $searchterm);
17
18    // quote regexp chars (space are treated as "or" operator)
19    $qterm = preg_replace("/\s+/", "|", preg_quote($searchterm));
20
21    $found = 0;
22    $count = 0;
23    while ($pagehash = FullSearchNextMatch($dbi, $query)) {
24       $html .= "<DT><B>" . LinkExistingWikiWord($pagehash["pagename"]) . "</B>\n";
25       $count++;
26
27       // print out all matching lines, highlighting the match
28       for ($j = 0; $j < (count($pagehash["content"])); $j++) {
29          if ($hits = preg_match_all("/$qterm/i", $pagehash["content"][$j], $dummy)) {
30             $matched = preg_replace("/$qterm/i",
31                                 "${FieldSeparator}OT\\0${FieldSeparator}CT",
32                                 $pagehash["content"][$j]);
33             $matched = htmlspecialchars($matched);
34             $matched = str_replace("${FieldSeparator}OT", '<b>', $matched);
35             $matched = str_replace("${FieldSeparator}CT", '</b>', $matched);
36             $html .= "<dd><small>$matched</small></dd>\n";
37             $found += $hits;
38          }
39       }
40    }
41
42    $html .= "</dl>\n<hr noshade>"
43             . sprintf (gettext ("%d matches found in %d pages."),
44                        $found, $count)
45             . "\n";
46
47    echo GeneratePage('MESSAGE', $html, gettext ("Full Text Search Results"), 0);
48 ?>