]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - wiki_fullsearch.php3
bringing documentation up to date
[SourceForge/phpwiki.git] / wiki_fullsearch.php3
1 <!-- $Id: wiki_fullsearch.php3,v 1.10 2000-09-21 19:21:25 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>Searching for \"" . htmlspecialchars($full) .
15                 "\" ....</B></P>\n<DL>\n";
16
17    // quote regexp chars
18    $full = preg_quote($full);
19
20    // search matching pages
21    $query = InitFullSearch($dbi, $full);
22    while ($pagehash = FullSearchNextMatch($dbi, $query)) {
23       $result .= "<DT><B>" . LinkExistingWikiWord($pagehash["pagename"]) . "</B>\n";
24       $count++;
25
26       // print out all matching lines, highlighting the match
27       for ($j = 0; $j < (count($pagehash["content"])); $j++) {
28          if ($hits = preg_match_all("|$full|i", $pagehash["content"][$j], $dummy)) {
29             $matched = preg_replace("|$full|i",
30                                 "${FieldSeparator}OT\\0${FieldSeparator}CT",
31                                 $pagehash["content"][$j]);
32             $matched = htmlspecialchars($matched);
33             $matched = str_replace("${FieldSeparator}OT", '<b>', $matched);
34             $matched = str_replace("${FieldSeparator}CT", '</b>', $matched);
35             $result .= "<dd><small>$matched</small></dd>\n";
36             $found += $hits;
37          }
38       }
39    }
40
41    $result .= "</dl>\n<hr noshade>$found matches found in $count pages.\n";
42    GeneratePage('MESSAGE', $result, "Full Text Search Results", 0);
43 ?>