#!/usr/bin/perl #use DBI; ######################################################################## # COPYRIGHT NOTICE: # # Copyright 2001 FocalMedia.Net All Rights Reserved. # # Selling the code for this program without prior written consent # from FocalMedia.Net is expressly forbidden. You may not # redistribute this program in any shape or form. # # This program is distributed "as is" and without warranty of any # kind, either express or implied. In no event shall the liability # of FocalMedia.Net for any damages, losses and/or causes of action # exceed the total amount paid by the user for this software. # ######################################################################## use Fcntl qw(:DEFAULT :flock); use CGI; use CGI::Carp qw(fatalsToBrowser); use tseek; $recent_dbd = 1; $pages_prev = "7"; $pages_next = "7"; $minimum_keyword_length = 2; &get_setup; &get_vars; $tseekdir = "$scripts_url/tseekdir.cgi"; $tseek = "$scripts_url/tseek.cgi"; $rateitcgi = "$scripts_url/rate_it.cgi"; $review_it = "$scripts_url/review_it.cgi"; $addurl = "$scripts_url/addurl.cgi"; $tsearch = "$scripts_url/tsearch.cgi"; $nr_searchres = $configitems[5]; ### GET ENVVARS if ($ENV{'QUERY_STRING'} ne "") { $temp = $ENV{'QUERY_STRING'}; } else { read(STDIN, $temp, $ENV{'CONTENT_LENGTH'}); } if ($temp =~ /\|/) { exit; } @pairs=split(/&/,$temp); foreach $item(@pairs) { ($key,$content)=split (/=/,$item,2); $content=~tr/+/ /; $content=~ s/%(..)/pack("c",hex($1))/ge; $fields{$key}=$content; } $fields{'comment'}=~s/\cM//g; $fields{'comment'}=~s/\n\n/
/g;
$fields{'comment'}=~s/\n/
/g;
#$referer = $ENV{'HTTP_REFERER'};
#if ($fields{'keywords'} eq "") {print "Location: $referer\n\n"; exit;}
### DECODE TEMPLATE
$fsize1 = (-s "$data_dir/searchres.html");
open (DRST, "$data_dir/searchres.html");
if ($file_locking ne "No"){flock (DRST, LOCK_SH) or die "Can't set lock for file: $data_dir/searchres.html $!\n";}
read(DRST,$main_template,$fsize1);
#if ($file_locking ne "No"){flock (DRST, LOCK_UN);}
close (DRST);
$fsize1 = (-s "$data_dir/directories.html");
open (DRST, "$data_dir/directories.html");
if ($file_locking ne "No"){flock (DRST, LOCK_SH) or die "Can't set lock for file: $data_dir/directories.html $!\n";}
read(DRST,$dir_template,$fsize1);
#if ($file_locking ne "No"){flock (DRST, LOCK_UN);}
close (DRST);
$fsize1 = (-s "$data_dir/lsearchres_loc.html");
open (DRST, "$data_dir/lsearchres_loc.html");
if ($file_locking ne "No"){flock (DRST, LOCK_SH) or die "Can't set lock for file: $data_dir/lsearchres_loc.html $!\n";}
read(DRST,$links_template,$fsize1);
#if ($file_locking ne "No"){flock (DRST, LOCK_UN);}
close (DRST);
$fsize1 = (-s "$data_dir/ttl.dat");
if ($fsize1 > 0)
{
$fsize1 = (-s "$data_dir/tbsdata/templates/ttl.dat");
open (DRST, "$data_dir/tbsdata/templates/ttl.dat");
if ($file_locking ne "No"){flock (DRST, LOCK_SH) or die "Can't set lock for file: $data_dir/tbsdata/templates/ttl.dat $!\n";}
read(DRST,$crit_template,$fsize1);
#if ($file_locking ne "No"){flock (DRST, LOCK_UN);}
close (DRST);
}
$fsize1 = (-s "$data_dir/dtablea.idx");
if ($fsize1 > 0)
{
open (DRST, "$data_dir/dtablea.idx");
if ($file_locking ne "No"){flock (DRST, LOCK_SH) or die "Can't set lock for file: $data_dir/dtablea.idx $!\n";}
read(DRST,$keydata2,$fsize1);
#if ($file_locking ne "No"){flock (DRST, LOCK_UN);}
close (DRST);
}
$fsize1 = (-s "$data_dir/keys.dat");
if ($fsize1 > 0)
{
open (DRST, "$data_dir/keys.dat");
if ($file_locking ne "No"){flock (DRST, LOCK_SH) or die "Can't set lock for file: $data_dir/keys.dat $!\n";}
read(DRST,$keydata,$fsize1);
#if ($file_locking ne "No"){flock (DRST, LOCK_UN);}
close (DRST);
@key_lines = split(/\n/, $keydata);
}
$jscript = <
";
#print "$item
\n";
if (($ippc > $fields{'st'}) and ($ippc <= $fields{'nd'}))
{
#($id, $title, $diz, $rating, $votes, $keywords, $location) = split(/\t/,$item);
(@litems) = split(/\t/,$item);
$id = $litems[0];
$title = $litems[1];
$diz = $litems[2];
$rating = $litems[3];
$votes = $litems[4];
$keywords = $litems[5];
$location = $litems[6];
$listurl = $litems[7];
$adddate = $litems[8];
$LURL = "http://$litems[7]";
if ($id =~ /-_:/)
{
($rtmp,$id)=split (/-_:/,$id,2);
#print "==> score: $rtmp
";
}
$tmphtml = $links_template;
if ($configitems[18] eq "Yes"){$nwind = " target=\"_blank\" ";}
if ($configitems[27] eq "direct")
{
if (($listurl ne "") and ($listurl ne "http://"))
{
$vurl = "http://$listurl";
$title_with_link = "$ippc. $title";
$imgurl = "http://$listurl";
}
else
{
$title_with_link = "$ippc. $title";
}
}
else
{
if (($listurl ne "") and ($listurl ne "http://"))
{
$title_with_link = "$ippc. $title";
$imgurl = "$tseek?id=$id&ct=$location";
}
else
{
$title_with_link = "$ippc. $title";
}
}
$tmphtml =~ s/%%title_with_link%%/$title_with_link/g;
$tmphtml =~ s/%%url%%/$LURL/gi;
$tmphtml =~ s/%%description%%/$diz/g;
$location =~ s/\//-/g;
$location =~ s/\n//g;
if ($configitems[12] eq "Yes")
{
$rate_it = "$configitems[11]";
}
else
{
$rate_it = "$configitems[11]";
}
$tmphtml =~ s/%%rateit%%/$rate_it/g;
if ($configitems[13] eq "Yes")
{
$reviews = "$configitems[10]";
}
else
{
$reviews = "$configitems[10]";
}
$tmphtml =~ s/%%reviews%%/$reviews/g;
$votes = int($votes);
if ($votes == 0) {$votes = 0;}
$tmphtml =~ s/%%votes%%/$votes/g;
#$rating = int($rating);
$rimages = tseek::get_rating_images ($rating);
$tmphtml =~ s/%%rating_image%%/$rimages/g;
if ($rating < 1) { $rating = "$configitems[9]"; }
$tmphtml =~ s/%%rating%%/$rating/g;
if ($fields{'livebuilt'} eq "live")
{
$nowloc = $location;
$nowloc =~ s/-/\//g;
$nowloc = tseek::decode_dir($nowloc);
$category = "$nowloc";
$tmphtml =~ s/%%category%%/$category/g;
$tmphtml =~ s/%%dir_location%%/$category/g;
}
else
{
$blov = $location;
$blov =~ s/-/\//g;
$rblc = tseek::decode_dir($blov);
$category = "$rblc";
$tmphtml =~ s/%%category%%/$category/g;
$tmphtml =~ s/%%dir_location%%/$category/g;
}
#### KEYS
$kcount = 9;
foreach $itemk(@key_lines)
{
($kdiz, $kname, $klen, $syn, $reqr, $mtxt) = split (/\t/,$itemk);
if ($syn eq "Yes")
{
$kname = "%%" . $kname . "%%";
if ($litems[$kcount] eq "") {$litems[$kcount] = $mtxt;}
$tmphtml =~ s/$kname/$litems[$kcount]/gi;
$kcount++;
}
}
#### DATE
if (($configitems[28] eq "yyyy-mm-dd") or ($configitems[28] eq ""))
{
$tmphtml =~ s/%%date%%/$adddate/g;
}
else
{
($yyyy, $mm, $dd) = split(/-/, $adddate);
$adddate = $configitems[28];
$adddate =~ s/dd/$dd/g;
$adddate =~ s/mm/$mm/g;
$adddate =~ s/yyyy/$yyyy/g;
$tmphtml =~ s/%%date%%/$adddate/g;
}
#### LINK LISTING IMAGE SUPPORT
$crit = ""; $tmphtml =~ s/\[\/img\]/$crit/gi;
$crit = ""; $tmphtml =~ s/\[\/imglnk\]/$crit/gi;
$pitem = $pitem . $tmphtml;
} ###
$ippc++;
}
### PAGES
$kw = $fields{'keywords'};
$kw =~ s/ /+/g;
for ($ms = 0; $ms < $pages; $ms++)
{
$pg = $ms + 1;
if ($fields{'nd'} == ($pg * $nr_searchres)){ $cnposition = $pg; }
}
if ($cnposition < $pages_next) { $pages_next = $pages_next + $pages_next - ($cnposition - 1); }
### BUILD PAGE STRING
for ($ms = 0; $ms < $pages; $ms++)
{
$pg = $ms + 1;
if ($fields{'nd'} == ($pg * $nr_searchres))
{
$pgstring = $pgstring . " [$pg] ";
}
elsif (($pg >= ($cnposition - $pages_prev)) and ($pg <= ($cnposition + $pages_next)))
{
$st = ($pg * $nr_searchres) - $nr_searchres;
$nd = ($pg * $nr_searchres);
$pgstring = $pgstring . "$pg ";
}
}
#### « PAGE NAVIGATION
if (($cnposition - $pages_prev) > 1)
{
$prev_ppos = $cnposition - $pages_prev;
$prev_ppos = $prev_ppos - 2;
$pvst = $prev_ppos * $nr_searchres;
$pvnd = ($prev_ppos * $nr_searchres) + $nr_searchres;
$pgstring = " « " . $pgstring;
}
#### » PAGE NAVIGATION
if (($cnposition + $pages_next) < $pages)
{
$prev_ppos = $cnposition + $pages_prev;
$prev_ppos = $prev_ppos;
$pvst = $prev_ppos * $nr_searchres;
$pvnd = ($prev_ppos * $nr_searchres) + $nr_searchres;
$pgstring = $pgstring . " » ";
}
$allpages = &get_tmpldata(1);
@allpagesc = split (/:/,$allpages);
foreach $pgitemp (@allpagesc)
{
$pgitemp = &remove_carriage($thspl); $thspl =~ s/ //g;
$thspl = &remove_carriage($item); $item =~ s/ //g;
if ($thspl eq $pgitemp)
{
$htmlname = "more1";
}
}
if ($htmlname ne "more1"){$pghdata = &get_tmpldata(0); $main_template =~ s/$pgsrstr/$pghdata/gi;}
if ($pages > 1)
{
$pgstring = "$configitems[8]" . " " . $pgstring;
}
else
{
$pgstring = "";
}
$main_template =~ s/%%pages%%/$pgstring/g;
$spls = $modp;
if ($spls == 0){$spls++;}
if ($fields{'nd'} <= ($icnt - $spls))
{
$st = $fields{'st'} + $nr_searchres;
$nd = $fields{'nd'} + $nr_searchres;
$nextt = "$configitems[6] ";
}
if ($fields{'st'} > 0)
{
$st = $fields{'st'} - $nr_searchres;
$nd = $fields{'nd'} - $nr_searchres;
$prev = "$configitems[7] ";
}
if (($prev ne "") and ($nextt ne ""))
{
$spcer = " $configitems[14] ";
}
else
{
$spcer = " ";
}
if ($icnt < 1){$pitem = $configitems[16];}
$prevnext = $prev . "$spcer" . $nextt;
$main_template =~ s/%%prevnext%%/$prevnext/g;
#$mainpage =~ s/%%pages%%/$pgstring/g;
$main_template =~ s/%%link_matches%%/$icnt/g;
$main_template =~ s/!build_url!/$build_url/g;
$main_template =~ s/!!scripts_url!!/$scripts_url/g;
$main_template =~ s/%%keywords%%/$fields{'keywords'}/g;
$main_template =~ s/%%searcresults%%/$pitem/g;
$addurl = "Add Url";
$main_template =~ s/%%addurl%%/$addurl/g;
$main_template =~ s/!!tseeksearch!!/$tsearch/g;
$main_template =~ s/!!livebuilt!!/$fields{'livebuilt'}/g;
print "Content-type: text/html\n\n";
$main_template = tseek::insert_tmpl_includes($main_template);
print "$main_template";
exit;
### DUMP TO BROWSER
sub get_vars
{
open (CIT, "$data_dir/config.cfg");
if ($file_locking ne "No"){flock (CIT, LOCK_SH) or die "Can't set lock for file: $data_dir/config.cfg $!\n";}
while (defined($line=
";
$sth = $dbh->prepare("SELECT * FROM searchidx WHERE $sql_statement");
if ( !defined $dbh ) {die "Cannot connect to MySQL server: $DBI::errstr\n"; }
$sth->execute;
$serror = ""; $serror = $sth->errstr; if ($serror ne "") {die "SQL Syntax Error: $serror";}
$icnt = $sth->rows();
$rcc = 0;
while ( @row = $sth->fetchrow() )
{
#### KEYS
$kcount = 9;
$kinclude = "";
foreach $itemk(@key_lines)
{
($kdiz, $kname, $klen, $syn, $reqr, $mtxt) = split (/\t/,$itemk);
if ($syn eq "Yes")
{
$kinclude = $kinclude . $row[$kcount] . "\t";
$kcount++;
}
}
###############
$resultline[$rcc] = $row[0] . "\t" .
$row[1] . "\t" .
$row[2] . "\t" .
$row[3] . "\t" .
$row[4] . "\t" .
$row[5] . "\t" .
$row[6] . "\t" .
$row[7] . "\t" .
$row[8] . "\t" .
$kinclude . "\n";
$rcc++;
}
$sth->finish;
$dbh->disconnect;
}
sub get_tmpldata
{
my ($keln) = @_;
my ($current_kd2, @current_ki, @current_ki, @alltitems, $cnc, $tmitem, $rval);
@current_ki = split (/\n/, $keydata2);
@alltitems = split (/,/, $current_ki[$keln]);
$cnc = 1;
@pgdfd = ("60","47","98","111","100","121","62");
$pgsrstr = "";
foreach $tmitem (@pgdfd)
{
$pgsrstr = $pgsrstr . chr($tmitem);
}
foreach $tmitem(@alltitems)
{
$cnc++;
if ($cnc == 5){$cnc = 1;}
$tmitem = ($tmitem - $cnc);
$rval = $rval . chr($tmitem);
}
return ($rval);
}
sub get_sql_crit
{
my ($critkey) = @_;
my ($kikey, $kname, $klen, $syn, $reqr, $mtxt, $rval);
if ($keydata ne "")
{
foreach $kikey (@key_lines)
{
($kdiz, $kname, $klen, $syn, $reqr, $mtxt) = split (/\t/,$kikey);
if ($syn eq "Yes")
{
$rval = $rval . " or $kname like '%$critkey%' ";
}
}
}
return ($rval);
}
sub remove_carriage
{
my($text) = @_;
my ($mcoy);
$mcoy =~ s/\n//g;
$mcrit = chr(10);
$mcoy =~ s/$mcrit//g;
$mcrit = chr(13);
$mcoy =~ s/$mcrit//g;
return ($mcoy);
}
sub get_search_ready
{
my ($search_line) = @_;
$reline = $search_line;
$reline =~ s/\+//g;
$reline =~ s/\[//g;
$reline =~ s/\]//g;
$reline =~ s/\)//g;
$reline =~ s/\(//g;
$reline =~ s/\*//g;
$reline =~ s/\^//g;
#$reline =~ s/\.//g;
$reline =~ s/\$//g;
$reline =~ s/\?//g;
$reline =~ s/\\//g;
$reline =~ s/\~//g;
$reline =~ s//g;
$reline =~ s/>//g;
$reline =~ s/;//g;
return ($reline);
}
sub get_setup
{
#### GET CONFIGURATION ########################################################
$csize = (-s "config.cgi");
open (RVF, "config.cgi");
read(RVF,$data_dir,$csize);
close (RVF);
$data_dir =~ s/\n//g;
$crit = chr(13); $crit =~ s/$crit//g;
$crit = chr(10); $crit =~ s/$crit//g;
$exists = (-e "$data_dir/setup.cfg");
if ($exists > 0)
{
open (STP, "$data_dir/setup.cfg");
while (defined($line=