#!/usr/bin/perl #print "Content-type: text/html\n\n"; ################################################## # Make sure these paths are correct ############## ################################################## require 'config.pl'; &config_dat; require 'functions.pl'; ################################################## # Get Form Input ################################# ################################################## use CGI; $inform = new CGI; $search = $inform->param('search'); $searchtype = $inform->param('searchtype'); $start = $inform->param('start'); unless($disptype){ $disptype = $inform->param('disptype'); } $cat = $inform->param('cat'); $navcat = $cat; unless($start){$start = 1;} unless($disptype){$disptype = "disp1";} ################################################## if($cat eq ""){&error("You didn't enter any search criteria.");} $cat =~ s/_/ /gi; $search = $cat; if($cat =~ /:/g){@catparts = split(/:/, $cat);}else{push(@catparts, $cat);} foreach $catpart (@catparts) { if($grow){$grow = $grow . ":" . $catpart;}else{$grow = $catpart;} $grow =~ s/ /_/g; $viewgrow =~ s/_/ /g; $reslcat[$rc++] = "$catpart:"; } $cachename = "CC_$cat"; $cachename =~ s/\s+/_/g; if(-f "cache/$cachename"){ if((-C "cache/$cachename") > $cache_exp){ &namedata; &newsearch; }else{ &getcache; } }else{ &namedata; &newsearch; } &output; sub namedata { opendir(DIRECTORY, "data") || die "Can't open Database Directory"; @datafiles = readdir(DIRECTORY); } sub newsearch { foreach $datafile (@datafiles){ open(DAT, "data/$datafile"); @entries = ; close(DAT); foreach $thisentry (@entries){ $score = 0; ($etime, $eurl, $etitle, $edescription, $ekeywords, $eemail, $ecattree, $elevel, $epassword, $ereview, $eimglocation) = split(/\|\|/, $thisentry); if($ecattree =~ /^$cat/ig){ # Scoring... $score = 1; while($etitle =~ /$cat/ig){$score = $score + $te;} while($edescription =~ /$cat/ig){$score = $score + $de;} foreach $searchword (@catparts){ while($etitle =~ /$searchword/ig){$score = $score + $tc;} while($edescription =~ /$searchword/ig){$score = $score + $dc;} while($ekeywords =~ /$searchword/ig){$score = $score + $kc;} while($eurl =~ /$searchword/ig){$score = $score + $uc;} while($ecattree =~ /$searchword/ig){$score = $score + $cc;} } if($score > $highscore){$highscore = $score;} if($score > 0){&addtolist("$eurl|$etitle|$edescription|$ecattree|$score|$elevel|$eemail|$etime|$ereview|$eimglocation\n");} }} } if(!@thelist){&noresults;} @thelist = sort relevant @thelist; @thelist = sort relevant2 @thelist; unshift(@thelist, "$highscore\n"); open(TCH, ">cache/$cachename"); print TCH @thelist; close(TCH); opendir(CCC, "cache"); @cachefiles = readdir(CCC); close(CCC); foreach $cachefile (@cachefiles){ if((-C "cache/$cachefile") > $cache_exp){ unlink("cache/$cachefile"); } } } sub addtolist { $string = shift @_; push(@thelist, $string); } sub relevant { my @a = split /\|/, $a; my @b = split /\|/, $b; $b[4] <=> $a[4]; } sub relevant2 { my @a = split /\|/, $a; my @b = split /\|/, $b; $a[5] <=> $b[5]; } sub noresults { $outsource[$osc++] = "Sorry, we were unable to locate any sites using your search criteria: $search"; &output; exit; } sub getcache { open(TLS, "cache/$cachename"); @thelist = ; close(TLS); } sub output { if($webvertise == 1){ $newtime = time; open(ZON, "$zoneinfo"); @zlines = ; close(ZON); foreach $zline (@zlines){ @zonedet = split(/\|/, $zline); foreach $catpart (@catparts){ if($catpart =~ /$zonedet[0]/ig){ $usezone = $zonedet[0]; $foundzone = 1; last; } } if($foundzone == 1){last;} } unless($foundzone){$usezone = "ROT";} } print "Content-type: text/html\n\n"; $highscore = @thelist[0]; chomp($highscore); $outsource[$osc++] = "\n"; $cse[$cts++] = "
Recommended Searches:\n"; for($i = $start; ($i < $start + $numresults) && ($i - 1 < $#thelist);$i +=1){ ($eurl, $etitle, $edescription, $ecattree, $score, $elevel, $eemail, $etime, $ereview, $eimglocation) = split(/\|/, @thelist[$i]); $rank = sprintf("%.1f%%", ($score/$highscore)*100); if($elevel < 10){$rank = "100\%";} $entertime = localtime($etime); &cust_display; if($usecategories && ($ecattree gt " ")){ $nodupcat = grep(/$ecattree/, @curcats); if($nodupcat < 1){ $urlcat = $ecattree; $urlcat =~ s/ /_/ig; if($odd){ $cse[$cts++] = "\n"; $odd = 0; }else{ $cse[$cts++] = ""; $odd = 1; } push(@curcats, $ecattree); } } } if($odd){$cse[$cts++] = "\n";} $outsource[$osc++] = "
$ecattree
$ecattree
\n"; $cse[$cts++] = "
\n"; $finish = $i - 1; unless(!@thelist){ $resultstat = "$start - $finish of $#thelist results relevant to @reslcat\n"; $next = $i; $fnext = $next; } # Nav Bar $prevstart = $start - $numresults; $nbprev = "<<Prev "; $nbnext = " Next>> "; $totpages = int($#thelist / $numresults); if(($#thelist / $numresults) > $totpages){$totpages +=1;} $firstpage = int($start / $numresults); if($firstpage < 1){$firstpage = 1;} $navpgmax = $firstpage + ($navpgmax - 1); # $firstpage = 1; if($totpages > $navpgmax){ $dotdotdot = 1; # $watch = (($navpgmax * $numresults) + 1); # if($start ge $watch){ # $firstpage = $navpgmax + 1; # $navpgmax = $navpgmax * 2; # } } if($prevstart > 0){$navbar[$nb++] = "$nbprev";}else{$navbar[$nb++] = "<<Prev ";} for($p = $firstpage; ($p <= $navpgmax) && ($p <= $totpages); $p +=1){ $pageholds = $p * $numresults; $newstart = $pageholds - ($numresults - 1); if($start eq $newstart){ $navbar[$nb++] = "$p "; } if($start != $newstart){ $navbar[$nb++] = "$p "; } } if($dotdotdot && ($newstart + $numresults < $#thelist)){ $newstart = $newstart + $numresults; $navbar[$nb++] = " ... "; } if($#thelist > $next){$navbar[$nb++] = "$nbnext";}else{$navbar[$nb++] = " Next>>";} ## open(TMP, "resulttemplate.html"); @templines = ; close(TMP); foreach $templine (@templines){ if($usecategories && $urlcat){ $templine =~ s//@cse/ig; } if($webvertise){ $templine =~ s/\%\%ZONE\%\%/$usezone/ig; $templine =~ s/\%\%TIME\%\%/$newtime/ig; } $templine =~ s//$resultstat/ig; $templine =~ s//@outsource/ig; $templine =~ s//@navbar/ig; print $templine; } } sub cust_display { require "displays/$disptype.pl"; &tablerow; #$outsource[$osc++] = "$i. $etitle
\n $edescription\n
$rank Date: $entertime $eurl\n"; } 1;