#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
$input=$ENV{'QUERY_STRING'};
$visitor=$ENV{'REMOTE_ADDR'};
$visitorgiveaway="klikafs";
$bigbrotherfile="/hotel/bigbrother/klikketpaied.txt";
if ($visitor =~ /216\.7\.179|195\.113\.214\.201|84\.177\.181\.230|80\.203\.102\.120|66\.154\.130\.167|84\.178.\150\.240q/){$visitortext.=" $visitorgiveaway $visitor $visitorgiveaway";}

$input=~ s/Flemming\+bornebie/-censureret-ord-/ig;
$input=~ s/vacansoleil/-censureret-ord-/ig; 
$input=~ s/xxx/-censureret-ord-/ig;
$input=~ s/sex/-censureret-ord-/ig;
$input=~ s/fisse/-censureret-ord-/ig;
$input=~ s/massage/-censureret-ord-/ig;
$input=~ s/orgy/-censureret-ord-/ig;
$input=~ s/cocaine/-censureret-ord-/ig;
$input=~ s/heroin/-censureret-ord-/ig;
$input=~ s/abortion/-censureret-ord-/ig;
$input=~ s/cancer/-censureret-ord-/ig;
$input=~ s/stroke/-censureret-ord-/ig;
$input=~ s/crash/-censureret-ord-/ig;
$input=~ s/disease/-censureret-ord-/ig;
$input=~ s/epidemic/-censureret-ord-/ig;
$input=~ s/funeral/-censureret-ord-/ig;
$input=~ s/suicide/-censureret-ord-/ig;
$input=~ s/murder/-censureret-ord-/ig;
$input=~ s/drowned/-censureret-ord-/ig;
$input=~ s/electric chair/-censureret-ord-/ig;
$input=~ s/bullshit/-censureret-ord-/ig;
$input=~ s/fuck/-censureret-ord-/ig;
$input=~ s/cunt/-censureret-ord-/ig;
$input=~ s/bitch/-censureret-ord-/ig;
$input=~ s/whore/-censureret-ord-/ig;
$input=~ s/tits/-censureret-ord-/ig;
$input=~ s/pedophile/-censureret-ord-/ig;
$input=~ s/erection/-censureret-ord-/ig;
$input=~ s/pussy/-censureret-ord-/ig;
$input=~ s/schlong/-censureret-ord-/ig;
$input=~ s/fuck/-censureret-ord-/ig;
$input=~ s/porn/-censureret-ord-/ig;
$input=~ s/latex/-censureret-ord-/ig;
$input=~ s/penis/-censureret-ord-/ig;
$input=~ s/vibrator/-censureret-ord-/ig;
$input=~ s/babes/-censureret-ord-/ig;
$input=~ s/anal/-censureret-ord-/ig;
$input=~ s/climax/-censureret-ord-/ig;
$input=~ s/piger/-censureret-ord-/ig;
$input=~ s/girls/-censureret-ord-/ig;
$input=~ s/eroti/-censureret-ord-/ig;
$input=~ s/massage/-censureret-ord-/ig;
$input=~ s/leather/-censureret-ord-/ig;
$input=~ s/forklaring/-censureret-ord-/ig;
$input=~ s/medicin/-censureret-ord-/ig;
if ($input=~/censureret/i){print header(-status=>'404 Not Found',-type=>'text/html');}
$input=~ s/\-censureret\-ord\-/ikke fundet - beklager/ig;

$input=~ s/Ã˜/Ø/ig;
$input=~ s/%C3%B8/ø/ig;
$input=~ s/%C3%83%C2%B8/ø/ig;
$input=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$input=~ s/Ã¸/ø/ig;
$input=~ s/Ã†/Æ/ig;
$visitortext=~ s/\./000/ig;
$input=~ s/Ã¦/æ/ig;
$input=~ s/Ã˜/Ø/ig;
$input=~ s/Ã¦/æ/ig;
$input=~ s/Ã¥/å/ig;
$input=~ s/Ã…/Å/ig;

$input=~ s/ÃƒËœ/ø/ig;
$input=~ s/ÃƒËœ/Ø/ig;

$input=~ s/%C3%B8/ø/ig;
$input=~ s/%C3%83%C2%B8/ø/ig;
$input=~ s/ÃƒÆ’Ã‚Â¸/ø/ig;
$input=~ s/ÃƒÂ¸/ø/ig;
$input=~ s/ÃƒÆ’Ã‹Å“/Ø/ig;
$input=~ s/Laan/Lån/g;
$input=~s/laan/lån/g;


$webpath=$ENV{'SCRIPT_NAME'};

$webpath=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$webpath=~ s/Ã¸/ø/ig;
$webpath=~ s/Ã~F/Æ/ig;
$webpath=~ s/Ã¦/æ/ig;
$webpath=~ s/Ã~X/Ø/ig;
$webpath=~ s/Ã¦/æ/ig;
$webpath=~ s/Ã¥/å/ig;
$webpath=~ s/Ã~E/Å/ig;

$webpath=~ s/Ã˜/Ø/ig;
$webpath=~ s/ÃƒËœ/Ø/ig;
$webpath=~ s/ÃƒÂ¸/ø/ig;
$webpath=~ s/ÃƒÆ’Ã‹Å“/Ø/ig;



$webpath=~ s/%C3%B8/ø/ig;
$webpath=~ s/%C3%83%C2%B8/ø/ig;
$webpath=~ s/Ã~CÆ~RÃ~BÂ¸/ø/ig;



$webpath=~ s/laan/lån/g;

$webpath=~ s/Laan/Lån/g;








if ($input)
{
(@inputparts)=split(/\&/,$input);
foreach $inputpart (@inputparts)
	{
	
	($navn,$indhold)=split(/\=/,$inputpart);
	$input{$navn}=$indhold;
	#print "$navn, $input{'find'}\n";
	}
}
$espotaffilliateid=160;
$page= $input{'find'};

if ($page =~ /Fleegaard/i){$page="Fleggaard";}
$page=ucfirst($page);
$espotpage=$input{'page'};
if ($espotpage <1){$espotpage=1;}
$pageinfo="Side $espotpage, gå til side:";

#/hotel/common/espottingcacheall/$lowercasekeyword.gratis.page$espotpage.hits$espothits.backfill$espotbackfill.noadult$espotnoadult.search
require "/hotel/software/WWW/cgi_bin/espotting-lib/espotting-lib.pl";
use LWP::Simple;
$espotbackfill=1;
&espotting($page);
#iprint @espotting;
#&addespotting;
$page =~ s/\+/ /ig;
$file=$page;
$file=~ s/ /+/ig;

#print "<h1>$webpath</h1>";

$skabelonfile="/hotel/klikket/skabeloner/search.txt";
$pathfile="/hotel/klikket/indexfiler/$file.path";
$subfile="/hotel/klikket/indexfiler/$file.txt";
$lasttenfile="/hotel/klikket/html/open/lastten.shtml";
$lastwordfile="/hotel/klikket/html/open/lastword.txt";

&hentskabelon;
#&hentkategori;
&delskabelon;

&hentkategori;
&hentsubkategori;
&addespotting;
#&printpage;
if ($webpath =~ /\.htm/)
        {
        open (LASTTEN, "$lasttenfile");
	@lastten=<LASTTEN>;
        close (LASTTEN);
	@lastten2=@lastten;
	$lasttenpage=substr($page,0,20);
	$lasttenline="						<a href=\"$webpath\" class=\"blckU\">.:$lasttenpage</a><br>\n";
if (length($page) > 25)
	{$lasttenline="";}
$lasttenpagetest=$lasttenpage;
$lasttenpagetest=~s/\W//ig;
$lasttenpagetest=~s/censur//ig;
if ($lasttenpagetest ne $lasttenpage)
	 {$lasttenline="";}

#if ($page=~ /\ /ig)

#        {$lasttenline="";}

	push (@lastten2, $lasttenline);
	while ($#lastten2 >9)
	{
	shift  (@lastten2);
	}
if ($lasttenpagetest eq $lasttenpage)
	{
        open (LASTTEN, ">$lasttenfile");
        print LASTTEN @lastten2;
        close (LASTTEN);
	

	open (LASTWORD, ">$lastwordfile");
	print LASTWORD $input;
	close (LASTWORD);
        }
	}
else {
        open (LASTTEN, "$lasttenfile");
        @lastten=<LASTTEN>;
        close (LASTTEN);
	}
$lastten= join('',@lastten);
#print $lastten; 

&printpage;

sub hentsubkategori
{
open (KATEGORI, "$subfile");
@subs=<KATEGORI>;
close (KATEGORI);

@subs=sort(@subs);
foreach $undersub (@subs)
{
chomp ($undersub);
if ($undersub)
{
$undersub1=$undersub;
$undersub=~ s/\ /\+/ig;
$path=$subkategorilines;
$path=~ s/PLEASEREPLACEWITHSUBKATEGORIURL/$basesub\/$undersub.htm/ig;
$path=~ s/PLEASEREPLACEWITHSUBKATEGORITITLE/$undersub1/ig;
$allsubs.=$path;
}
}
}

sub hentkategori
{
open (KATEGORI, "$pathfile");
$path=<KATEGORI>;
close (KATEGORI);
(@subs)=split(/\//,$path);
$path="";
foreach $sub (@subs)
{
$basesub.="/$sub";
if ($sub)
{
$basesub=~ s/\/\//\//g;
$basesub=~ s/\ /\+/ig;
$subudenplus=$sub;
$subudenplus=~ s/\+/ /ig;
$path=$kategorilines;
$path=~ s/PLEASEREPLACEWITHKATEGORIURL/$basesub.htm/ig;
$path=~ s/PLEASEREPLACEWITHKATEGORITITLE/$subudenplus/ig;
$allpath.=$path;
}
}
$path=$kategorilines;
$pageplus=$page;
$pageplus=~ s/\ /\+/ig;
$path=~ s/PLEASEREPLACEWITHKATEGORIURL/$basesub$sub\/$pageplus.htm/ig;
$countpage=1;
$linkmedophold="$basesub$sub\/$page.htm\">";
$linkmedophold=~ s/\ /\+/ig;

$pageinfo .="<a href=\"$linkmedophold$countpage</a> ";


while ($countpage<4)
{
$countpage++;
$linkmedophold="$basesub$sub\/$page";
$linkmedophold=~ s/\ /\+/ig;
$pageinfo .="<a href=\"$linkmedophold";
$pageinfo .="_$countpage.htm\">$countpage</a> ";
}
$path=~ s/PLEASEREPLACEWITHKATEGORITITLE/$page/ig;
$allpath.=$path;
$basesub.="/$page";
#$kategori.=$kategori;
}

sub hentbanner
{
#return;
$bannerordpage="$page";
$bannerordpage=~s/\ /\+/ig;
        open (BANNERPLACE, "/hotel/klikket/bannerord/$bannerordpage.txt") or open (BANNERPLACE, "/hotel/klikket/bannerord/default.txt");
        @bannerplaces=<BANNERPLACE>;
        close (BANNERPLACE);
$tal = rand(@bannerplaces);

$bannerplace=$bannerplaces[$tal];


#$centralbanner="$bannerplace";
     
chomp($bannerplace);
$bannerplace.='.txt';
$bannerplace=~ s/\.txt\.txt/\.txt/ig;

   open (BANNER, "/hotel/klikket/bannere/$bannerplace");
        @centerbanner=<BANNER>;
        close (BANNER);
#
$centralbanner=join ("\n",@centerbanner);
$centralbanner=~ s/REPLACEWITHEPI/$page\-$bannerplace/ig;
#$centralbanner.=$centerbanner[0];
#$centralbanner.="/hotel/klikket/bannere/$bannerplace";
#print @centerbanner;
}

sub printpage
{
&hentbanner;
$alllines=$toplines;
$alllines.=$allpath;
$alllines.=$underkategorilines;
if ($allsubs){$alllines.="<hr>"}
$alllines.=$allsubs;

$alllines.=$undersubkategorilines;
#$alllines.="<hr><hr>TOPSLUT<hr><hr>\n";
foreach $pageline (@pagelines)
{
$alllines.=$pageline;
}
#$alllines.=@espotting;
######################################TEXTADS


######################################TEXTADS




$alllines.=$bundlines;
#$alllines.="<hr><hr><hr><hr>\n";
#$alllines.=$bundlines;
$alllines=~ s/PLEASEREPLACEWITHCENTRALBANNER/$centralbanner/ig;
#$tostregerudenkategori="<hr>\n\n</center>\n<hr>";

$alllines=~ s/$tostregerudenkategori/<\/center>/ig;
$alllines=~ s/PLEASEREPLACEWITHPAGEINFO/$pageinfo/ig;

$alllines=~ s/PLEASEINSERTSEARCHWORDHERE/$page/ig;
$alllines=~ s/PLEASEINSERTDESCRIPTIONHERE/$pagedescription/ig;
$alllines=~ s/PLEASEINSERTKEYWORDSHERE/$pagekeywords/ig;
$alllines=~ s/PLEASEINSERTH1HERE/$page$visitortext/ig;
$alllines=~ s/PLEASEINSERTTITLE/$page/ig;
$alllines=~ s/PLEASEREPLACEWITHKATEGORI/$kategori/ig;
$alllines=~ s/PLEASEREPLACEWITHLASTTEN/$lastten/ig;
print $alllines;
#print $bannerplace;
}


sub hentskabelon
{
open (SKABELON, "$skabelonfile");
@skabelon=<SKABELON>;
close (SKABELON);
}
sub delskabelon
{
foreach $skabelonline (@skabelon)
{
if ($skabelonline =~ /PLEASEUSETHISASBUTTOM/i) 
{
$placement="bund";
next;
}

if ($skabelonline =~ /PLEASEUSEASKATEGORI/i) 
{
$placement="kategori";
next;
}
#page webpath


if ($skabelonline =~ /PLEASEUSEASSUBKATEGORI/i)
{
$placement="subkategori";
next;
}

if ($skabelonline =~ /PLEASEUSEASUNDERKATEGORI/i)
{
$placement="underkategori";
next;
}
if ($skabelonline =~ /PLEASEUSEASLINK/i)
{
$placement="espotting";
next;
}
if ($skabelonline =~ /PLEASEUSEASUNDERSUBKATEGORI/i)
{
$placement="undersubkategori";
next;
}






unless ($placement) {$toplines.=$skabelonline};
if ($placement eq "kategori"){$kategorilines.=$skabelonline};

if ($placement eq "subkategori"){$subkategorilines.=$skabelonline};
if ($placement eq "espotting"){$espottinglines.=$skabelonline};
if ($placement eq "bund"){$bundlines.=$skabelonline};
if ($placement eq "underkategori"){$underkategorilines.=$skabelonline};

if ($placement eq "undersubkategori"){$undersubkategorilines.=$skabelonline};
}




}



sub appendtobigbrother
{
open (BIGBROTHER, ">>$bigbrotherfile");
print BIGBROTHER "$page\n";
close (BIGBROTHER);
}

sub addespotting
{
foreach $espotresult (@espotting)
{
#espotresult="$espotadurl-BD-$espotadredirecturl-BD-$espotadtitle-BD-$espotaddescription-BD-$espotadlogo-BD-\n";
($away,$newurl,$titel,$desc,$espotlogo)=split(/-BD-/,$espotresult);
#print $espotresult;
$espottingtobeadded="$espottinglines";
$espottingtobeadded=~ s/PLEASEREPLACEWITHURL/$newurl/ig;
unless ($espotlogo){$titel=substr($titel,0,50);}
if ($espotlogo) {&appendtobigbrother;}


$espottingtobeadded=~ s/PLEASEREPLACEWITHLINKTITLE/$titel/g;
$espottingtobeadded=~ s/PLEASEREPLASEWITHLINKDESCRIPTION/$desc/;
unless ($espotlogo){$espotlogo="/images/nosponsor.gif";}
$espottingtobeadded=~ s/PLEASEREPLACEWITHLOGO/$espotlogo/ig;
#/images/kuffert.gif
push (@pagelines,$espottingtobeadded);
#print @pagelines;
#print "<hr>";
}

}
