]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/fullsearch.php
second int. patch from Jan (slightly modified)
[SourceForge/phpwiki.git] / lib / fullsearch.php
1 <!-- $Id: fullsearch.php,v 1.2 2000-10-20 11:42:52 ahollosi Exp $ -->
2 <?php
3    /*
4       Search the text of pages for a match.
5       A few too many regexps for my liking, but it works.
6    */
7
8    $found = 0;
9    $count = 0;
10
11    if(get_magic_quotes_gpc())
12       $full = stripslashes($full);
13
14    $result = "<P><B>";
15    $result .= sprintf(gettext ("Searching for \"%s\" ....."),
16       htmlspecialchars($full));
17    $result .= "</B></P>\n<DL>\n";
18
19    // quote regexp chars
20    $full = preg_quote($full);
21
22    // search matching pages
23    $query = InitFullSearch($dbi, $full);
24    while ($pagehash = FullSearchNextMatch($dbi, $query)) {
25       $result .= "<DT><B>" . LinkExistingWikiWord($pagehash["pagename"]) . "</B>\n";
26       $count++;
27
28       // print out all matching lines, highlighting the match
29       for ($j = 0; $j < (count($pagehash["content"])); $j++) {
30          if ($hits = preg_match_all("|$full|i", $pagehash["content"][$j], $dummy)) {
31             $matched = preg_replace("|$full|i",
32                                 "${FieldSeparator}OT\\0${FieldSeparator}CT",
33                                 $pagehash["content"][$j]);
34             $matched = htmlspecialchars($matched);
35             $matched = str_replace("${FieldSeparator}OT", '<b>', $matched);
36             $matched = str_replace("${FieldSeparator}CT", '</b>', $matched);
37             $result .= "<dd><small>$matched</small></dd>\n";
38             $found += $hits;
39          }
40       }
41    }
42
43    $result .= "</dl>\n<hr noshade>";
44    $result .= sprintf (gettext ("%d matches found in %d pages."),
45      $found, $count);
46    $result .= "\n";
47    GeneratePage('MESSAGE', $result, gettext ("Full Text Search Results"), 0);
48 ?>