]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - wiki_fullsearch.php3
The to-do list.
[SourceForge/phpwiki.git] / wiki_fullsearch.php3
1 <!-- $Id: wiki_fullsearch.php3,v 1.6 2000-06-18 15:12:13 ahollosi Exp $ -->
2 <?
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 = $count = 0;
9
10    if(get_magic_quotes_gpc())
11       $full = stripslashes($full);
12
13    $result = "<P><B>Searching for \"" . htmlspecialchars($full) .
14                 "\" ....</B></P>\n<DL>\n";
15
16    // quote regexp chars
17    $full = preg_quote($full);
18
19    // search matching pages
20    $query = InitFullSearch($dbi, $full);
21    while ($page = FullSearchNextMatch($dbi, $query)) {
22       $pagename = $page['name'];
23       $pagehash = $page['hash'];
24
25       $result .= "<DT><B>" . LinkExistingWikiWord($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 (preg_match("/$full/i", $pagehash["content"][$j], $pmatches)) {
31             $matched = preg_replace("/$full/i", "<b>\\0</b>",
32                                     $pagehash["content"][$j]);
33             $result .= "<dd><small>$matched</small></dd>\n";
34             $found += count($pmatches);
35          }
36       }
37    }
38
39    $result .= "</dl>\n<hr noshade>$found matches found in $count pages.\n";
40    GeneratePage('MESSAGE', $result, "Full Text Search Results", 0);
41 ?>