0) die("This version of the script requires PHP 4.0.0 or higher.
"); // ---------------------------------------------------------------------------- // Settings (change if necessary) // ---------------------------------------------------------------------------- // Highlight matched words in results $Highlighting = 1; // 0 = off, 1 = on $HighlightColor = "#B9E5FB"; // Highlight colour // Set this to your template HTML page // (for the formatting and location of the search form) $TemplateFilename = "search_template.html"; // The options available in the dropdown menu for number of results // per page $PerPageOptions = array(10, 20, 50, 100); $FormFormat = 2; //0 = No search form (note that you must pass parameters to // the script directly from elsewhere on your website). //1 = Basic search form //2 = Advanced search form (with options) $ZoomInfo = 0; //0 = Don't display Zoom info line at bottom of search //1 = Display Zoom info line at bottom of search $OutputStyle = 1; //0 = Basic Style, Page Title, Score and URL //1 = Descriptive Style, Match number, Page Title, // Page description, Score and URL $Logging = 1; //0 = No logging of words that a user enter. //1 = Words are logged to a file for later analysis. (See // documentation for file permission issues) //Path and File name of search word log file $LogFileName = "./logs/searchwords.log"; // Maximum line length of a single line in the KeyWords file. // Increase, if required, so that // MaxKeyWordLineLen >= Number of web pages in site * 6 $MaxKeyWordLineLen = 4000; $WordSplit = 0; //0 = Only split input search phrase into words when a // Space character is found //1 = Split input search phrase at Space ' ', // UnderScore '_' , Dash '-' and Plus '+' characters $Timing = 1; // 0 = do not perform timing on searches // 1 = perform timing and display results at bottom of page // ---------------------------------------------------------------------------- // Parameter initilisation (necessary since PHP 4.2.0 and later // prefers register_globals to be off) // ---------------------------------------------------------------------------- // For versions of PHP before 4.1.0 // we will emulate the superglobals by creating references // NOTE: references created are NOT superglobals if (!isset($_SERVER) && isset($HTTP_SERVER_VARS)) $_SERVER = &$HTTP_SERVER_VARS; if (!isset($_GET) && isset($HTTP_GET_VARS)) $_GET = &$HTTP_GET_VARS; if (!isset($_POST) && isset($HTTP_POST_VARS)) $_POST = &$HTTP_POST_VARS; // check if magic_quotes are on for Get/Post/Cookie variables // and fix accordingly (we don't use cookies so we leave them out) if (get_magic_quotes_gpc() == 1) { while (list($key, $value) = each($_GET)) $_GET["$key"] = stripslashes($value); while (list($key, $value) = each($_POST)) $_POST["$key"] = stripslashes($value); } // check magic_quotes for runtime stuff (reading from files, etc) if (get_magic_quotes_runtime() == 1) set_magic_quotes_runtime(0); // for compatibility with Zoom < 2.0 HTML forms // using the POST 'searchword' parameter if (isset($_POST['searchword'])) $query = $_POST['searchword']; // we use the method=GET and 'query' parameter now (for sub-result pages etc) if (isset($_GET['zoom_query'])) $query = rtrim($_GET['zoom_query']); // number of results per page, defaults to 10 if not specified if (isset($_GET['zoom_per_page'])) $per_page = $_GET['zoom_per_page']; else $per_page = 20; // current result page number, defaults to the first page if not specified if (isset($_GET['zoom_page'])) $page = $_GET['zoom_page']; else $page = 1; // AND operator. // 1 if we are searching for ALL terms // 0 if we are searching for ANY terms (default) if (isset($_GET['zoom_and'])) $and = $_GET['zoom_and']; else $and = 1; function PrintEndOfTemplate($template, $line) { global $ZoomInfo; //Let others know about Zoom. if ($ZoomInfo == 1) echo "\n

Search powered by the Zoom Search Engine

\n"; //Print out the end of the template while ($line < count($template)) { echo $template[$line]; $line++; } } function PrintHighlightDescription($line) { global $matchwords; global $matchwords_num; global $HighlightColor; $res = $line; for ($i = 0; $i < $matchwords_num; $i++) { // replace with marker text, assumes [;:] and [:;] is not the search text... $res = preg_replace("|\b(" .quotemeta($matchwords[$i]) . ")\b|iU", "[;:]\\1[:;]", $res); } // replace the marker text with the html text // this is to avoid finding previous 'ed text. $res = str_replace("[;:]", "", $res); $res = str_replace("[:;]", "", $res); print $res; } // ---------------------------------------------------------------------------- // Compares the two values, used for sorting output results // Results that match all search terms are put first, highest score // ---------------------------------------------------------------------------- function SortCompare ($a, $b) { if ($a[2] < $b[2]) return 1; else if ($a[2] > $b[2]) return -1; else { if ($a[1] < $b[1]) return 1; else if ($a[1] > $b[1]) return -1; else return 0; } } // ---------------------------------------------------------------------------- // Translates a typical shell wildcard pattern ("zoo*" => "zoom" etc.) // to a regular expression pattern. Supports only '*' and '?' characters. // ---------------------------------------------------------------------------- function pattern2regexp($pattern) { $i = 0; $len = strlen($pattern); // add "\b" to res before and after the pattern, to ensure a distinct match // eg: no word stemming $res = "/\b"; while ($i < $len) { $c = $pattern[$i]; $i++; if ($c == '*') $res = $res . ".*"; else if ($c == '?') $res = $res . "."; else $res = $res . preg_quote($c, '/'); } return $res . '\b/i'; } // ---------------------------------------------------------------------------- // Main starts here // ---------------------------------------------------------------------------- if ($Timing == 1) { $mtime = explode(" ", microtime()); $starttime = doubleval($mtime[1]) + doubleval($mtime[0]); } //Open and print start of result page template $template = file ($TemplateFilename); $numtlines = count ($template); //Number of lines in the template $line = 0; while ($line < $numtlines) { if (!stristr($template[$line], "")) { echo $template[$line]; $line++; } else { break; } } $line++; // Replace the key text with the following if ($FormFormat > 0) { // Insert the form print("
\n"); print("

Suchbegriff: \n"); print("\n"); if ($FormFormat == 2) { print("Ergebnisse je Seite:\n"); print("

\n"); print("Ergebnis finden: \n"); if ($zoom_and == 0) { print("mit irgendeinem Suchbegriff\n"); print("mit allen Suchbegriffen

Für Ergebnisse aus unseren Foren, verwenden Sie bitte die Suchfunktion in unserem Board! \n"); } else { print("mit irgendeinem Suchbegriff\n"); print("mit allen Suchbegriffen

Für Ergebnisse aus unseren Foren, verwenden Sie bitte die Suchfunktion in unserem Board!\n"); } print("
\n"); } print("
\n"); } // Give up early if no search words provided if (empty($query)) { // only display 'no query' line if no form is shown if ($FormFormat == 0) print("No search query entered.
"); PrintEndOfTemplate($template, $line); return; } //Split search phrase into words if ($WordSplit == 1) $SearchWords = split ('[-_ +/=]', $query); else $SearchWords = split ('[ ]', $query); // Load the entire pages file into an array, all URL's on the site $urls = file ('zoom_pages.dat'); // Load the entire page titles file into an array $titles = file ('zoom_titles.dat'); if ($OutputStyle == 1) $descriptions = file ('zoom_descriptions.dat'); //Print heading print "Suchergebnis \"$query\""; //Open keywords file $fpkeywords = fopen ("zoom_keywords.dat", "r"); if ($urls == FALSE || $titles == FALSE || $fpkeywords == FALSE) { print("Can not find one or more of the Zoom index files.
Please make sure the generated index files are uploaded to the same path as this search script.
\n"); return; } //Loop through all search words $numwords = count ($SearchWords); $outputline = 0; $UseWildCards = 1; // default as using wildcard if ($Highlighting == 1) { $matchwords = array(); $matchwords_num = 0; } for ($sw = 0; $sw < $numwords; $sw++) { // check whether there are any wildcards used if (strstr($SearchWords[$sw], "*") == FALSE && strstr($SearchWords[$sw], "?") == FALSE) $UseWildCards = 0; else $pattern = pattern2regexp($SearchWords[$sw]); //Read in a line at a time from the keywords files while ($data = fgetcsv ($fpkeywords, $MaxKeyWordLineLen, ",")) { // if we're not using wildcards, direct match if ($UseWildCards == 0) $result = strcasecmp($SearchWords[$sw], $data[0]); else // if we have wildcards... $result = !(preg_match($pattern, $data[0])); if ($result == 0) { //Keyword found, so include it in the output list if ($Highlighting == 1) { // Add to matched words list if (!in_array($data[0], $matchwords)) { $matchwords[$matchwords_num] = $data[0]; $matchwords_num++; } } $num = count ($data); for ($kw=1; $kw < $num; $kw +=2) { //Check if page is already in output list $pageexists = 0; $ipage = $data[$kw]; for ($ol = 0; $ol < $outputline; $ol++) { if ($output[$ol][0] == $ipage) { //Page is already in output list, so add to count + extra if ($output[$ol][1] > 10000) { // take it easy if its too big (to prevent huge scores) $output[$ol][1] += 1; } else { $output[$ol][1] += $data[$kw+1]; //Add in score $output[$ol][1] *= 2; //Double Score as we have two words matching } $output[$ol][2] += 1; //Increase word match count $pageexists = 1; } } if ($pageexists == 0) { //New page to add to list $output[$outputline][0] = $ipage; //Page index $output[$outputline][1] = $data[$kw+1]; //Score $output[$outputline][2] = 1; //Single word match only so far $outputline++; } } if ($UseWildCards == 0) break; //This search word was found, so skip to next } } //Return to start of file rewind ($fpkeywords); } //Close the files fclose ($fpkeywords); //Get number of pages matched $matches = $outputline; //Sort results in order of score, use the "SortCompare" function if ($matches > 1) usort ($output, "SortCompare"); //Count number of output lines that match ALL search terms $oline = 0; $fullmatches = 0; while (($oline < $matches) && $numwords > 1) { if ($output[$oline][2] == $numwords) { $fullmatches++; } else if ($and == 1) { // AND search // Remove the not-AND result unset($output[$oline]); } $oline++; } if ($and == 1 && $numwords > 1) { // we need to re-index the array $output = array_values($output); // and the matches now are only the number of fullmatches $matches = count($output); } //Display search result information print ""; if ($matches == 1) print "<

Der Suchbegriff erzielte 1 Treffer.
"; else if ($matches == 0) print "

Leider keine Treffer gefunden.

"; else if ($numwords > 1 && $and == 0) { //OR $SomeTermMatches = $matches - $fullmatches; print "

$fullmatches Seiten wurden gefunden, die alle Suchbegriffe beinhalten. "; if ($SomeTermMatches > 0) print "
$SomeTermMatches Seiten wurden gefunden, die einige Suchbegriffe beinhalten."; print "

"; } else if ($numwords > 1 && $and == 1) //AND print "
$fullmatches Seiten wurden gefunden, die alle Suchbegriffe beinhalten.

"; else print "

Der Suchbegriff erzielte $matches Treffer.

"; if ($matches < 3 && $and == 1 && $numwords > 1) { print "
Sie können vielleicht mehr Treffer erzielen, wenn Sie mit allen Suchbegriffen suchen.
"; } print "
\n"; // Number of pages of results $num_pages = ceil($matches / $per_page); if ($num_pages > 1) print "
Ergebnisse verteilt auf $num_pages Seiten.
\n"; // Determine current line of result from the $output array if ($page == 1) { $arrayline = 0; } else { $arrayline = (($page - 1) * $per_page); } // The last result to show on this page $result_limit = $arrayline + $per_page; // Display the results while ($arrayline < $matches && $arrayline < $result_limit) { $ipage = $output[$arrayline][0]; $score = $output[$arrayline][1]; if ($OutputStyle == 0) { //Basic style print "

"."Page: ".rtrim($titles[$ipage])."
\n"; print "Score: " . $score ."  
URL:".rtrim($urls[$ipage])."

\n"; } else { //Descriptive style print "

".($arrayline+1).". ".rtrim($titles[$ipage])."
"; if ($Highlighting == 1) PrintHighlightDescription(rtrim($descriptions[$ipage])); else print rtrim($descriptions[$ipage]); print "...
\n"; print "
Suchbegriff enthalten: ". $output[$arrayline][2]. " Score: " . $score ."  
URL: ".rtrim($urls[$ipage])."

\n"; } $arrayline++; } // Show links to other result pages if ($num_pages > 1) { print "

Weitere Ergebnisse:

"; if ($page > 1) print "<< zurück "; for ($i = 1; $i <= $num_pages; $i++) { if ($i == $page) { print $page." "; } else { print "".$i." "; } } if ($page != $num_pages) print "weiter >> "; } if ($Timing == 1) { $mtime = explode(" ", microtime()); $endtime = doubleval($mtime[1]) + doubleval($mtime[0]); $difference = abs($starttime - $endtime); print "

Die Suche dauerte: " . number_format($difference, 5, '.', '') . " Sekunden\n"; } //Print out the end of the template PrintEndOfTemplate($template, $line); //Log the search words, if required if ($Logging == 1) { $LogString = Date("d-m-y, H:i:s") . ", " . $REMOTE_ADDR . ", " . " \"" .$query . "\"" . ", Matches = " . $matches; if ($and == 1) $LogString = $LogString . ", AND\n"; else $LogString = $LogString . ", OR\n"; $fp = fopen ($LogFileName, "a"); if ($fp != false) { fputs ($fp, $LogString); fclose ($fp); } } ?>