<?php
include ("./admin/inc/config.inc.php");
@setlocale("LC_ALL", "da_DA");
$search_exp = strip_tags($HTTP_POST_VARS["search_exp"]);
$exp_capital = strip_tags($HTTP_POST_VARS["exp_capital"]);
$exp_full = strip_tags($HTTP_POST_VARS["exp_full"]);
if (!empty($search_exp) || !empty($HTTP_GET_VARS["search_exp"])) {
if (!empty($HTTP_GET_VARS["search_exp"])) {
$search_exp = $HTTP_GET_VARS["search_exp"];
}
$frrepl = array("=\+=", "=\s+=");
$torepl = array("", " ");
$search_exp = preg_replace( $frrepl, $torepl, $search_exp);
$search_exp = preg_quote($search_exp);
$search_exp = trim($search_exp);
if (strlen($search_exp) < $sexp_length) {
$tmpl = join('', file("./results/search-error.php"));
$tmpl = preg_replace("=\[search_error_count\]=", $error_count, $tmpl);
$tmpl = preg_replace("=\[search_error_empty\]=", "", $tmpl);
echo $tmpl;
} else {
$search_arr = explode(" ",$search_exp);
$search_count = count($search_arr);
$arr = array();
$arr_all = array();
$tmpl = join('', file("./results/search-results.php"));
preg_match_all("=\[SEARCH_START\](.*)\[SEARCH_STOP\]=siU", $tmpl, $between);
$search_pages = 0;
$cont_part = do_search();
$search_pages = count($cont_part);
rsort($cont_part);
$blaetter = seitenaufteilung($search_pages);
if (!isset($HTTP_GET_VARS['a'])) {
$a = 0;
}
for ($j=$a; $j!=$a+$nps; $j++) {
if (($j==$search_pages) || (!preg_match("=.*aNe.*=sU", "$blaetter"))) {
break;
}
list($anz_searchexp, $title, $descr, $new_path, $searchx) = $cont_part[$j];
$content = preg_replace("=\[SEARCH_TITLE\]=", "$title", $between[1][0]);
$search_nr = $j+1;
$content = preg_replace("=\[SEARCH_NR\]=", "$search_nr", $content);
$searchx = stripslashes($searchx);
$content = preg_replace("=\[SEARCH_CONTENT\]=", "$searchx", $content);
$content = preg_replace("=\[SEARCH_LINK\]=", "$from_dir"."$new_path", $content);
$content = preg_replace("=\[SEARCH_URL\]=", "http://"."$HTTP_SERVER_VARS[SERVER_NAME]"."$from_dir"."$new_path", $content);
$content = preg_replace("=\[SEARCH_DESC\]=", "$descr", $content);
$content = preg_replace("=\[SEARCH_COUNT\]=", "$anz_searchexp", $content);
$cont_x .= $content;
}
$tmpl = preg_replace("=\[SEARCH_START\](.*)\[SEARCH_STOP\]=siU", $cont_x, $tmpl);
$search_exp_all = urldecode($search_exp);
$search_exp_all = str_replace('\\', '', $search_exp_all);
$tmpl = preg_replace("=\[SEARCH_WORDS\]=", $search_exp_all, $tmpl);
$tmpl = preg_replace("=\[SEARCH_PAGES\]=", $search_pages, $tmpl);
$tmpl = preg_replace("=\[SHOW_PAGES\]=", $blaetter, $tmpl);
if (empty($cont_part)) {
$tmpl = preg_replace("=\[NO_MATCH\]=", $no_match, $tmpl);
} else {
$tmpl = preg_replace("=\[NO_MATCH\]=", "", $tmpl);
}
echo $tmpl;
foreach ($search_arr as $search_exp) {
$zeilen = file("./admin/_log/search_log.txt");
$anz_zeilen = sizeof($zeilen);
$x=0;
for ($i=0; $i<$anz_zeilen; $i++) {
list ($search_word, $search_num) = split("\\|", chop($zeilen[$i]));
if ($search_exp==$search_word) {
$search_num++;
$i-2;
$x++;
}
$new_log .= "$search_word|$search_num\n";
}
if ($x==0) {
$search_num = "1";
$new_log .= "$search_exp|$search_num\n";
}
$data = fopen("./admin/_log/search_log.txt","w+");
flock($data,1);
fwrite($data, $new_log);
flock($data,3);
fclose($data);
unset($new_log);
}
}
}
else {
$tmpl = join('', file("./results/search-error.php"));
$tmpl = preg_replace("=\[search_error_count\]=", "", $tmpl);
$tmpl = preg_replace("=\[search_error_empty\]=", $error_empty, $tmpl);
echo $tmpl;
}
function do_search() {
global $search_exp, $exp_capital, $exp_full, $search_arr, $search_count, $search_area, $cont_part, $search_pages, $arr_all, $maxz, $hit_area, $HTTP_GET_VARS;
$zeilen = file("./admin/data/search_data.php");
$anz_zeilen = sizeof($zeilen);
for ($i=0; $i<$anz_zeilen; $i++) {
list ($path, $title, $description, $keywords, $content) = split("\\|\|\|", chop($zeilen[$i]));
if ($search_area==1) {
$a = "$title"."$description"."$keywords";
}
else {
$a = "$content"."$title"."$description"."$keywords";
}
$a = ch_uml($a);
$j=0;
if (empty($exp_full)) {
$exp_full = $HTTP_GET_VARS['exp_full'];
}
if (empty($exp_capital)) {
$exp_capital = $HTTP_GET_VARS['exp_capital'];
}
if ($exp_full=="yes") {
$pref = "\b";
}
if ($exp_capital=="no") {
$capit = "i";
}
foreach ($search_arr as $search_word) {
if (preg_match("=$pref$search_word$pref=$capit", $a)) {
$anz_searchexp += preg_match_all("=$pref$search_word$pref=$capit"."sU", $a, $nullinger);
$j++;
if ($j==$search_count) {
if ($hit_area==1) {
$swlen = strlen($search_word);
$strlen = strlen($a);
$len = floor(($maxz-$swlen)/2);
foreach ($search_arr as $search_word) {
if (preg_match("=$pref$search_word$pref=$capit", $hitx)) {
$hitx = $hitx;
}
else {
if (isset($hitx)) {
$len = floor($len/2);
}
preg_match("=\b.{0,$len}($pref$search_word$pref).{0,$len}\b=s$capit", $a, $hit);
if ($strlen>$swlen) { $hit[0] = " ...".$hit[0]."... "; }
$hitx .= $hit[0];
}
}
foreach ($search_arr as $search_word) {
$hitx = preg_replace("=$pref($search_word)$pref=$capit", "<span class='hitword'>\\1</span>", $hitx);
}
}
$s_show = array();
$s_show[] = $anz_searchexp;
$s_show[] = $title;
$s_show[] = $description;
$s_show[] = $path;
$s_show[] = $hitx;
array_push($arr_all, $s_show);
unset($a, $anz_searchexp, $hitx);
}
}
}
}
$cont_part = $arr_all;
return ($cont_part);
}
function ch_uml($del_uml) {
$del_uml = preg_replace("=ä=", "ä", $del_uml);
$del_uml = preg_replace("=ö=", "ö", $del_uml);
$del_uml = preg_replace("=ü=", "ü", $del_uml);
$del_uml = preg_replace("=Ä=", "Ä", $del_uml);
$del_uml = preg_replace("=Ö=", "Ö", $del_uml);
$del_uml = preg_replace("=Ü=", "Ü", $del_uml);
$del_uml = preg_replace("=ß=", "ß", $del_uml);
return ($del_uml);
}
function seitenaufteilung($anz_zeilen) {
global $nps, $a, $HTTP_SERVER_VARS, $HTTP_GET_VARS, $search_exp, $exp_full, $exp_capital;
$a = $HTTP_GET_VARS['a'];
$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
$search_exp = urlencode($search_exp);
$seiten=ceil($anz_zeilen / $nps);
$foot = "<table width=600 border=0 cellspacing=0 cellpadding=0 align=center><tr><td> </td></tr><tr><td align=center>";
if($a >= $nps) {
$back=$a-$nps;
$foot .= "<a href='$PHP_SELF?search_exp=$search_exp&exp_full=$exp_full&exp_capital=$exp_capital&a=$back' class='page_link'><<</a> ";
}
if ($anz_zeilen<=$nps) {
$foot .= "";
} else {
for ($i=1;$i<=$seiten;$i++) {
$fwd=($i-1)*$nps;
if ($a==$fwd) {
$foot .= "<a href='$PHP_SELF?search_exp=$search_exp&exp_full=$exp_full&exp_capital=$exp_capital&a=$fwd' class='page_link'>-$i-</a> ";
} else{
$foot .= "<a href='$PHP_SELF?search_exp=$search_exp&exp_full=$exp_full&exp_capital=$exp_capital&a=$fwd' class='page_link'>$i</a> ";
}
}
}
if(($a < $anz_zeilen-$nps) && ($nps<$anz_zeilen)) {
$fwd=$a+$nps;
$foot .= " <a href='$PHP_SELF?search_exp=$search_exp&exp_full=$exp_full&exp_capital=$exp_capital&a=$fwd' class='page_link'>>></a>";
}
$foot .= "</td></tr><tr><td> </td></tr><tr><td align=right><a href='http://www.planetc.de' target='_blank' class='copy'>PlaNet Search</a></td></tr></table><br>";
return("$foot");
}
?>