#!/usr/local/bin/perl ########################################################################## ## ## ## Smart Search version 4.23 ## ## ---------------------- ## ## By Smarter Scripts ## ## (http://www.smarterscripts.com) ## ## ## ## "Smart Search" is not a free script. If you got this from someplace ## ## other than SmarterScripts.com, please contact us, we do offer ## ## rewards for that type of information. Visit our site for up to date ## ## versions. Most CGIs are over $200, sometimes more than $500, ## ## this script is much less. We can keep this script cheap, ## ## as well as free scripts on our site, if people don't steal it. ## ## Also, no return links are required, but we appreciate it if you ## ## do find a spot for us. ## ## Thanks! ## ## ## ## Special Notice to Resellers ## ## =========================== ## ## You can use this script on any site of yours, but if you sell one ## ## of these sites, you are required to FIRST purchase a reseller ## ## license for the domain. If you don't, it's considered copyright ## ## infringement and we will prosecute any offenders. ## ## WE MONITOR EBAY.COM AUCTIONS, SO BEWARE. ## ## Reseller prices are very low, for more information, go to: ## ## http://www.smarterscripts.com/resellers.shtml ## ## ## ## (c) copyright 2002 SmarterScripts.com and R3N3 Internet Services ## ########################################################################## if ($ENV{'SERVER_SOFTWARE'} =~ /microsoft/i) { $path = $ENV{'PATH_TRANSLATED'}; $path =~ /^(.*)\\[^\\]*$/; $path = $1; chdir $path; } require 'include/functions.cgi'; require 'include/search.cgi'; &loadsettings; if ($settings{'debug'}) { open(DEBUG, ">$data_dir/debug.dat") } use CGI; use CGI::Carp qw/fatalsToBrowser/; $smartsearch = 1; $cgi = new CGI; $keywords = $cgi->param('keywords'); $start = ($cgi->param('s') ne '') ? $cgi->param('s') : 0; $username = $cgi->param('username'); $crawlsite = $cgi->param('crawlsite'); if ($crawlsite) { $settings{'crawl'} = $crawlsite } $biddedtotal = $cgi->param('bt'); $freetotal = $cgi->param('f'); $catchall = $cgi->param('c'); $dbtotal = $cgi->param('db'); $external = $cgi->param('e'); $keywords =~ s/\///g; $keywords =~ tr/A-Z/a-z/; $temp = ''; # Only one space between keywords foreach ( split(/\s/, $keywords) ) { if ( $_ ne '' ) { if ($temp ne '') { $temp .= ' ' } $temp .= $_; } } $keywords = $temp; if ($keywords eq '') { $info{'HIDDENFORM'} = ''; &dotemplate('search_index.tpl'); exit; } $info{'KEYWORDS'} = $keywords; if ($settings{'filter'}) { if ( &dofilter($keywords) ) { $info{'AFFILIATE'} = $username; &dotemplate('search_filter.tpl'); exit; } } if ($settings{'affiliate'} && $username ne '' && $start == 0 && $settings{'affiliate_per_search'} > 0) { require 'include/affiliate.cgi'; &afflog($username, 1, $settings{'affiliate_per_search'}) } $klink = $keywords; $klink =~ tr/ /+/; $klinkgo = &Encrypt($keywords,$encryptkey,'asdfhzxcvnmpoiyk'); $klinkgo =~ s/ /+/g; if ($settings{'dirs'}) { &dirs } if ($start == 0 && $biddedtotal == 0) { $biddedtotal = -1; $dbtotal = -1 if ($settings{'db_file'} ne ''); $freetotal = -1 if ($settings{'free_listings'}); $external = -2 if ($settings{'crawl'} ne '' || $settings{'outside_urls'} ne ''); } $linecount = &dosearch($start, $settings{'display_max'}, 0, 'search_results_paid.tpl', 'search_results_free.tpl'); if ($linecount == 0) { $info{'AFFILIATE'} = $username; &dotemplate('search_nomatch.tpl'); exit; } if ($dbtotal == -1) { &getdb(100000, 0, $settings{'db_file'}, $settings{'db_delimiter'}, $settings{'db_title'}-1, $settings{'db_desc'}-1, $settings{'db_url'}-1) } if ($freetotal == -1) { &getfree(100000, 0) } if ($external == -2) { require 'include/crawl.cgi'; &crawl(0, $linecount+1); $linecount-- } if ($external == -1) { $info{'ATLEAST'} = $settings{'search_at_least'}; $total = $biddedtotal + $dbtotal + $freetotal; } else { $total = $biddedtotal + $dbtotal + $freetotal + $external } if ($settings{'debug'}) { print DEBUG "biddedtotal - $biddedtotal\n"; print DEBUG "dbtotal - $dbtotal\n"; print DEBUG "freetotal - $freetotal\n"; print DEBUG "external - $external\n"; } $info{'TOTAL'} = $total; if($start > 0) { $s = $start - $settings{'display_max'}; if ($catchall > 0) { $c = $s } $info{'LINKPREV'} = "$settings{display_last}"; } elsif ($settings{'logkeys'}) { &logkey } if ($start+$linecount < $total) { $s = $start + $settings{'display_max'}; $info{'LINKNEXT'} = "$settings{display_next}"; } $info{'START'} = $start+1; $info{'END'} = $start+$linecount; $info{'RESULTS'} = $results; $info{'AFFILIATE'} = $username; &dotemplate('search_main.tpl'); exit; sub dotemplate { my ($temp) = @_; &readtemplate('search_header.tpl'); $info{'HEADER'} = $tpl; &readtemplate('search_footer.tpl'); $info{'FOOTER'} = $tpl; &readtemplate($temp); $info{'SITETITLE'} = $settings{'sitetitle'}; $tpl =~ s/<<([^>]+)>>/$info{$1}/g; print $cgi->header; print $tpl; } sub dirs { open(DATA, "$data_dir/directories.txt"); flock(DATA, $LOCK_SH); $foundd = 0; $count = 0; my (@subcats, $subcat); my($mycat) = ''; while ( $line = ) { my ($precat) = ''; $rkeywords = ®escape($keywords); if ($line =~ /$rkeywords/i ) { my($addto) = 1; foreach $link ( split('/', $line) ) { if ($link =~ /^($rkeywords)$/i) { $foundd = 1; $mycat = $precat . "$1"; $addto = 2; } elsif ($addto == 1) { if ($link ne '') { $link2 = $link; $link2 =~ tr/ /+/; $precat .= "$link > "; } } elsif ($addto == 2) { $subcats{$link} = $count++; $addto = 0; } } } } flock(DATA, $LOCK_UN); close(DATA); if ($foundd) { foreach $link ( sort { $subcats{$a} <=> $subcats{$b} } keys %subcats ) { $link2 = $link; $link2 =~ tr/ /+/; $mysubcat .= "$link
\n"; } $info{'CATEGORIES'} = $mycat; $info{'SUBCATEGORIES'} = $mysubcat; } } sub direct_hit { @kdata = split(/&&/, $keydata[0]); print DEBUG "In direct_hit\n"; for $i (0..$#kdata) { print DEBUG "$i - $kdata[$i]\n"; } if ($bid > 0 && $kdata[5] eq '') { $time = &Encrypt(time(),$encryptkey,'asdfhzxcvnmpoiyk'); $user = &Encrypt($kdata[1],$encryptkey,'asdfhzxcvnmpoiyk'); $url = &Encrypt($kdata[3],$encryptkey,'asdfhzxcvnmpoiyk'); $bid = &Encrypt($kdata[0],$encryptkey,'asdfhzxcvnmpoiyk'); $direct_hit_url = "$settings{frame_url}$settings{cgi_url}/go.cgi?u=$user&url=$url&b=$bid&t=$time"; } elsif ($kdata[5] ne '') { $direct_hit_url = $kdata[5] } else { $direct_hit_url = $kdata[3] } print "Location: $direct_hit_url\n\n"; exit; } sub logkey { open(DATA,">> $data_dir/keywordlog_$months[$month]-$dayofmonth-$year.txt"); flock(DATA, $LOCK_EX); print DATA "$keywords\n"; flock(DATA, $LOCK_UN); close(DATA); }