<?php
// *********************
// *** Einstellungen ***
// *********************
// Domain-Name für die Anzeige in den Resultaten
// z.B. "http://www.gaijin.at"
$DomainName="http://meinedomain/index.php?section=";
// Root-Verzeichnis für den Zugriff auf die Dateien am Server
// Beispiel: $RootDir=dirname("/htdocs");
$RootDir=dirname($_SERVER['SCRIPT_FILENAME']);
// Dateiname für die Protokollierung der Suchbegriffe
// (kein Dateiname zum deaktivieren der Protokollierung)
// z.B. "../../files/logs/search_words.log"
$SearchWordLog="";
// Länge der Textfragmente um die Fundstellen (in Zeichen)
$Found_Piece_Len=50;
// Erlaubtes Verzeichnis
// Z.B.: $AllowedDirs=$RootDir."/content";
$AllowedDir=$RootDir;
// Erlaubte Erweiterungen als Array, getrennt mit einem Beistrich
// Z.B.: $AllowedExts=array(".php",".php3",".php4",".htm",".html",".ihtml",".shtm",".shtml",".txt");
$AllowedExts=array(".php",".html",".shtml","");
// Deutsche Umlaute dekodieren (dadurch wird beispielsweise "ä" zu "ä")
$Activate_Umlaut=true;
// *********************
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>/</title>
<meta name="publisher" content="Gaijin">
<meta name="robots" content="noindex,nofollow">
<meta http-equiv="content-language" content="de-at">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel=stylesheet type="text/css" href="search.css">
</head>
<body>
<h4>Suche</h4>
<?php
if (isset($_POST['p_search'])) $search=FormatSearchString(stripslashes($_POST['p_search'])); else $search="";
?>
<table border="0" cellspacing="0" cellpadding="1"><tr><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><td id="border3d">
<table border="0" cellspacing="0" cellpadding="5"><tr><td id="back3d">
<table border="0" cellspacing="0" cellpadding="2">
<tr><td nowrap align=right id="formtext">Suche: </td>
<td width=100%><input type="text" name="p_search" size=40 maxlength=250 value="<?php echo $search; ?>"></td></tr>
<tr><td nowrap align=right> </td>
<td width=100% id="formtext"><input type="submit" value="Suchen" name="submit"> <small>(mit UND-Verknüpfung)</small></td></tr>
</td></tr>
</table>
</td></tr></table>
</td></form></tr></table>
<br>
<?php
if($search){
// Protokollierung der Suchbegriffe
if(file_exists($SearchWordLog)) {
$fp=@fopen($SearchWordLog,"a");
if($fp) {
flock($fp,2);
fputs($fp,$search."\r\n",256);
flock($fp,3);
fclose($fp);
}
}
echo "<h4>Ergebnis:</h4>\n";
$files=ReadDirs($AllowedDir,$AllowedExts);
$ResultCount=0;
if($files && $search){
foreach($files as $f){
if(SearchFile($f,$search)){
$fn=$f;
if(substr($f,0,strlen($RootDir))==$RootDir) $fn=$DomainName.substr($f,strlen($RootDir));
$ResultCount++;
echo $ResultCount.". ";
echo "<a href=\"".$fn."\"><b>".$Site_Title."</b></a><br>\n";
if($Meta_Description) echo $Meta_Description."<br>\n";
echo "<span id=small><span id=grey>".$Site_Content."</span></span><br>\n";
echo "<span id=grey>Datei:</span> <span id=green>".$fn."</span>";
echo " - ";
echo "<span id=grey>Größe:</span> <span id=green>".round(filesize($f)/1024,2)." KB</span>";
}
}
clearstatcache();
}
echo "Es wurden <b>".$ResultCount."</b> Seiten gefunden.<br>\n";
}
function SearchFile($url,$search){
global $Found_Piece_Len;
global $Activate_Umlaut;
global $RootDir;
global $DomainName;
global $Site_Title;
global $Site_Content;
global $Meta_Description;
global $Meta_Robots;
$Site_Title="";
$Meta_Keywords="";
$Site_Content="";
$Meta_Description="";
$Meta_Robots="";
// *** Meta-Angaben ermitteln ***
$gmtarray=get_meta_tags($url);
while(list($key,$val)=each($gmtarray)){
switch(strtolower($key)){
case "title": $Meta_Title=$val; break;
case "keywords": $Meta_Keywords=$val; break;
case "description": $Meta_Description=$val; break;
case "robots": $Meta_Robots=strtolower($val); break;
case "revisit": $Meta_Revisit=strtolower($val); break;
case "revisit-after": $Meta_RevisitAfter=strtolower($val); break;
}
}
$Meta_Description="";
//if(eregi("noindex",$Meta_Robots)) return false;
// *** Dateiinhalt einlesen (bzw. Ausgabe bei PHP) ***
$fp=@fopen($url,"r");
if(!$fp) return false;
$content="";
while(!feof($fp)){
$content.=fgets($fp,10240);
}
fclose($fp);
$content=str_replace("<"."?","<",$content);
$content=str_replace("?".">",">",$content);
$content=trim($content);
$content=$Site_Title." ".$Meta_Title." ".$Meta_Keywords." ".$Meta_Description." ".$content;
// *** Seitentitel ermitteln ***
$Site_Title=GetSiteTitle($content);
if(!$Site_Title) $Site_Title=$Meta_Title;
if(!$Site_Title) $Site_Title=basename($url);
if(substr($content,0,strlen($Site_Title))==$Site_Title) $content=substr($content,strlen($Site_Title));
$content=strip_tags($content);
$content=str_replace("\n"," ",$content);
$content=str_replace("\r","",$content);
$sc=" ".trim($content);
while(strpos($sc," ")){
$sc=str_replace(" "," ",$sc);
}
$content=$sc;
// Deutsche Umlaute konvertieren
if($Activate_Umlaut){
$content=str_replace("ä","ä",$content);
$content=str_replace("ö","ö",$content);
$content=str_replace("ü","ü",$content);
$content=str_replace("Ä","Ä",$content);
$content=str_replace("Ö","Ö",$content);
$content=str_replace("Ü","Ü",$content);
$content=str_replace("ß","ß",$content);
}
$content=str_replace("€","€",$content);
$content=str_replace(" "," ",$content);
// *** Suchen ***
$found=false;
$a=explode(" ",strtolower($search));
$lowcontent=strtolower($content);
$result_text="";
foreach($a as $arg){
$p0=strpos($lowcontent,$arg);
if($p0>0){
$p1=$Found_Piece_Len;
$p2=$Found_Piece_Len;
if (($p0-$p1) < 0) $p1=$p0;
$result_text.="...".substr($content,$p0-$p1,$p1)."<b id=red>";
$result_text.=substr($content,$p0,strlen($arg))."</b>".substr($content,$p0+strlen($arg),$p2);
$found=true;
}else{
$found=false;
break;
}
}
if(!$found) return false;
if($result_text) $result_text.="...";
$Site_Content=$result_text;
return true;
}
function FormatSearchString($search){
$chars=".:-_,;!§$%&/()=#+*~'?\[|]{^°}²³µ@€ äöüß1234567890abcdefghijklmnopqrstuvwxyz";
$s="";
for($i=0;$i<strlen($search);$i++){
$a=substr($search,$i,1);
if(stristr($chars,$a)) $s.=$a;
}
while(strpos($s," ")){
$s=str_replace(" "," ",$s);
}
return trim($s);
}
function ReadDirs($d,$ExtArray){
$fileArray=array();
if($hDir = opendir($d)){
while($file=readdir($hDir)){
if(!is_dir($d."/".$file)){
// *** .*-Dateien (zB .htaccess) ignorieren ***
if(substr($file,0,1)!="."){
foreach($ExtArray as $ext){
if(substr(strtolower($file),strlen($file)-strlen($ext),strlen($ext))==strtolower($ext)){
array_push($fileArray,$d."/".$file);
continue;
}
}
}
}
}
closedir($hDir);
}
return $fileArray;
}
function GetSiteTitle($content)
{
$p1=strpos(strtolower($content),"<title>");
if(!$p1) return false;
$p2=strpos(strtolower($content),"</title>",$p1);
if(!$p2) return false;
return trim(substr($content,$p1+7,$p2-$p1-7));
}
?>
</body>
</html>