<?php
include ("./inc/config.inc.php");
$root_dir = $_SERVER["DOCUMENT_ROOT"].$from_dir."/";
@setlocale("LC_ALL", "de_DE");
$search_exp = strip_tags($_POST["search_exp"]);
if (!empty($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("./tmpl/search_error.htm"));
$tmpl = preg_replace("=\[search_error_count\]=", $error_count, $tmpl);
$tmpl = preg_replace("=\[search_error_empty\]=", "", $tmpl);
eval('?>' . $tmpl);
} else {
$search_arr = explode(" ",$search_exp);
$search_count = count($search_arr);
$arr = array();
$arr_all = array();
$tmpl = join('', file("./tmpl/search_result.php"));
preg_match_all("=\[SEARCH_START\](.*)\[SEARCH_STOP\]=siU", $tmpl, $between);
$search_pages = 0;
$cont_part = walk_dir($root_dir);
$search_pages = count($cont_part);
rsort($cont_part);
for ($j=0; $j<$search_pages; $j++) {
list($anz_searchexp, $title, $descr, $new_path) = $cont_part[$j];
$content = preg_replace("=\[SEARCH_TITLE\]=", "$title", $between[1][0]);
$content = preg_replace("=\[SEARCH_LINK\]=", "$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 = str_replace('\\', '', $search_exp);
$tmpl = preg_replace("=\[SEARCH_WORDS\]=", $search_exp, $tmpl);
$tmpl = preg_replace("=\[SEARCH_PAGES\]=", $search_pages, $tmpl);
if (empty($cont_part)) {
$tmpl = preg_replace("=\[NO_MATCH\]=", $no_match, $tmpl);
} else {
$tmpl = preg_replace("=\[NO_MATCH\]=", "", $tmpl);
}
eval('?>' . $tmpl);
foreach ($search_arr as $search_exp) {
$zeilen = file("./_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("./_log/search_log.txt","w+");
flock($data,1);
fwrite($data, $new_log);
flock($data,3);
fclose($data);
unset($new_log);
}
}
}
else {
$tmpl = join('', file("./tmpl/search_error.php"));
$tmpl = preg_replace("=\[search_error_count\]=", "", $tmpl);
$tmpl = preg_replace("=\[search_error_empty\]=", $error_empty, $tmpl);
eval('?>' . $tmpl);
}
function walk_dir($dir, $pos=2)
{
global $search_exp, $search_arr, $search_count, $arr, $ignore_dir, $dat_type, $root_dir, $search_area, $cont_part, $no_title, $search_pages, $arr_all;
$handle = @opendir($dir);
while ($file = @readdir ($handle))
{
if (preg_match("=^\.{1,2}$=",$file))
{
continue;
}
$cut_dir = preg_replace("=$root_dir=siU", "", $dir);
if (in_array($cut_dir, $ignore_dir)) continue;
if (preg_match('=(_vti_cnf|_notes)=i', $cut_dir)) continue;
if(is_dir($dir.$file))
{
walk_dir($dir.$file."/", $pos + 3);
}
else
{
$abs_dir = preg_replace("=$root_dir=","",$dir);
if (preg_match("=(\.$dat_type)$=",$file)) {
$str = join('', file("$dir$file"));
if (!preg_match("=\<\!\-\-.no_search.\-\-\>=siU", $str)) {
$str = ch_uml($str);
preg_match("=<title>(.*)</title>=siU", $str, $title);
preg_match('=<meta.*name\="description".*content\="(.*)".*>=siU',$str,$descr);
preg_match('=<meta.*name\="keywords".*content\="(.*)".*>=siU',$str,$keyw);
if ($search_area==1) {
$a = "$title[1]"."$descr[1]"."$keyw[1]";
}
else {
$str = preg_replace("=\<\!\-\-.no_search_start.\-\-\>.*?\<\!\-\-.no_search_stop.\-\-\>=s", "", $str);
$a = preg_replace("=<script.*>.*<\/script>=siU", "", $str);
$a = preg_replace("=<\?.*?\?>=s", "", $a);
$a = preg_replace("=(<[^>]+>)=siU", "", $str);
$a .= "$title[1]"."$descr[1]"."$keyw[1]";
}
$i=0;
foreach ($search_arr as $search_word) {
if (preg_match("=($search_word)=i", $a)) {
$anz_searchexp += preg_match_all("=$search_word=siU", $a, $nullinger);
$i++;
if ($i==$search_count) {
if (!empty($title[1]))
{
$new_title = "$title[1]";
$new_path = "/$abs_dir$file";
}
else {
$new_title = "$no_title";
$new_path = "/$abs_dir$file";
}
if (!empty($descr[1]))
{
$new_descr = "$descr[1]";
}
else {
$new_descr = "";
}
if (!preg_match("=^\(\.\*\)$=", $new_title)) {
$s_show = array();
$s_show[] = $anz_searchexp;
$s_show[] = $new_title;
$s_show[] = $new_descr;
$s_show[] = $new_path;
array_push($arr_all, $s_show);
}
unset($str, $anz_searchexp);
}
}
}
}
}
}
}
$cont_part = $arr_all;
return ($cont_part);
@closedir($handle);
}
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);
}
?>