]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/fullsearch.php
Fix SF bug #445108: Empty search string results in phpwiki error.
[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.4.2.2 2001-11-07 21:42:34 dairiki Exp $');
4
5    if(get_magic_quotes_gpc())
6       $full = stripslashes($full);
7    $full = trim($full);
8       
9    $html = "<P><B>"
10            . sprintf(gettext ("Searching for \"%s\" ....."),
11                    htmlspecialchars($full))
12            . "</B></P>\n<DL>\n";
13    $found = 0;
14    $count = 0;
15
16    if (strlen($full)) {           
17      // search matching pages
18      $query = InitFullSearch($dbi, $full);
19       
20      // quote regexp chars (space are treated as "or" operator)
21      $full = preg_replace("/\s+/", "|", preg_quote($full));
22
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(":$full:i", $pagehash["content"][$j], $dummy)) {
30            $matched = preg_replace(":$full: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    else {
43      $html .= "<dd>" . gettext("(You entered an empty search string)") . "</dd>\n";
44    }
45
46    $html .= "</dl>\n<hr noshade>"
47             . sprintf (gettext ("%d matches found in %d pages."),
48                        $found, $count)
49             . "\n";
50
51    GeneratePage('MESSAGE', $html, gettext ("Full Text Search Results"), 0);
52 ?>