([^<]+)<\/ErrorMsg>/$error_msg = $1;/esi;
}
print "Content-type: text/html; charset=utf-8\n\n";
# I might not even need this
$html .='';
## Pick Contrasting Color to border
@color=((hex substr($color_bg, 0, 2)), (hex substr($color_bg, 2, 2)), (hex substr($color_bg, 4, 2)));
$color_bordertext=getTextHex($color);
$debug .= "Bordertext: ".$color_bordertext."
\n";
if ($ad_format eq "728x90_as"){$googleads=3;$starthtml=set_728x90_as_start();$endhtml=set_728x90_as_end();}
if ($ad_format eq "468x60_as"){$googleads=1;$starthtml=set_468x60_as_start();$endhtml=set_468x60_as_end();}
if ($ad_format eq "120x600_as"){$googleads=3;$starthtml=set_120x600_as_start();$endhtml=set_120x600_as_end();}
if ($ad_format eq "300x250_as"){$googleads=3;$starthtml=set_300x250_as_start();$endhtml=set_300x250_as_end();}
$html .= $starthtml;
for($x=0;$x<=$googleads;$x++) {
#print "Hello!!!
";
$Details[$x] =~ s/<([^>]+)>([^<]+)<\/\1>/${$1} = $2;/gsie;
if ($link_to_apf eq "yes") {
$result_link = $location_of_apf . "?input_search_type=AsinSearch&input_item=$Asin&input_locale=$locale";
} else {
$result_link = "http://www.$amazon_site/exec/obidos/ASIN/$Asin/ref=nosim/$associate_id?dev-t=$developer_token";
}
if ($ad_format eq "728x90_as"){$html .= set_728x90_as_html();}
if ($ad_format eq "468x60_as"){$html .= set_468x60_as_html();}
if ($ad_format eq "120x600_as"){$html .= set_120x600_as_html();}
if ($ad_format eq "300x250_as"){$html .= set_300x250_as_html();}
}
$html .= $endhtml;
# display result
if ($error_msg) { $html = $error_msg; }
if ($output_type eq "javascript") {
$html =~ s/"/'/g;
$html =~ s/\n/"\);\ndocument.write\("/g;
$html = qq[document.write("] . $html . qq[");\n];
$html =~ s/(document.write\(")?<\/?SCRIPT[^>]*>("\);)?//gi;
}
#print "Debug Codes:
$debug\n";
print "$html\n";
exit;
# the end - subs below
# yep, it's my standard input parser
sub get_url_input {
my (%FORM,$form_pair,$form_name,$form_value,$item);
for $form_pair (split(/&/, $ENV{QUERY_STRING})) {
$form_pair =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form_pair =~ s/[^\w|\d|\=|\,|\(|\)|\-|\:]/ /g;
($form_name, $form_value) = split(/=/, $form_pair);
if ($form_name eq $form_value) { $form_value = ""; }
$FORM{$form_name} = $form_value;
}
foreach $item (@ARGV) {
($form_name, $form_value) = split(/=/, $item);
$FORM{$form_name} = $form_value;
}
if (%FORM) {
$search = $FORM{input_string};
if ($FORM{input_mode} or $FORM{input_id}) { $mode = $FORM{input_mode}; }
if ($FORM{input_id}) { $browse_id = $FORM{input_id}; }
if ($FORM{input_item}) { $item_id = $FORM{input_item}; }
if ($FORM{input_output}) { $output_type = $FORM{input_output}; }
if ($FORM{input_locale}) { $locale = $FORM{input_locale}; }
if ($FORM{input_stream}) { $textstream = $FORM{input_stream}; }
if ($FORM{ad_format}) { $ad_format = $FORM{ad_format}; }
if ($FORM{color_border}) { $color_border = $FORM{color_border}; }
if ($FORM{color_bg}) { $color_bg = $FORM{color_bg}; }
if ($FORM{color_link}) { $color_link = $FORM{color_link}; }
if ($FORM{color_url}) { $color_url = $FORM{color_url}; }
if ($FORM{color_text}) { $color_text = $FORM{color_text}; }
}
}
# between the qq[ and ]; is the HTML that formats the result. feel free to change it to whatever you want
# possible variables are: $result_link, $Asin, $ProductName, $Catalog, $ReleaseDate, $Manufacturer, $ImageUrlSmall,
# $ImageUrlMedium, $ImageUrlLarge, $ListPrice, $OurPrice, $UsedPrice
sub set_728x90_as_start {
my $banner_html = qq[
];
}
sub set_728x90_as_end {
my $banner_html = qq[
![]() |
|
|
| AGAR |
];
}
sub set_728x90_as_html {
my $banner_html = qq[
![]() |
| ![]() |
];
}
sub set_468x60_as_start {
my $banner_html = qq[
];
}
sub set_468x60_as_end {
my $banner_html = qq[
|
|
AGAR
|
|
];
}
sub set_468x60_as_html {
my $banner_html = qq[
$ProductName
Buy now for only $OurPrice! |
];
}
sub set_120x600_as_start {
my $banner_html = qq[
];
}
sub set_120x600_as_end {
my $banner_html = qq[
|
| AGAR |
];
}
sub set_120x600_as_html {
my $banner_html = qq[
|
|
];
}
sub set_300x250_as_start {
my $banner_html = qq[
];
}
sub set_300x250_as_end {
my $banner_html = qq[
|
| AGAR |
];
}
sub set_300x250_as_html {
my $banner_html = qq[
|
|
];
}
sub get_url {
my $value = $_[0]; my $skip = $_[1];
my (%xml_cache,$xml_result,$dbm_error);
my $cache_expire = time() - 3600; my $cache_time = $value . "_time";
$debug .= "Checking on Cache... ";
if ($use_cache eq "yes") {
$debug .= "Cache should be used!
";
eval 'use Fcntl'; $dbm_error = $@;
eval 'use DB_File'; $dbm_error .= $@;
if (!$dbm_error) {
if (-s $cache_file > (7000 * $cache_max_size)) { unlink $cache_file; }
eval 'tie(%xml_cache,"DB_File",$cache_file,O_RDONLY)'; $dbm_error = $@;
}
}
if ($xml_cache{$value} and $xml_cache{$cache_time} > $cache_expire) {
$xml_result = $xml_cache{$value};
$debug .= "cache status = cached request size " . length($xml_result) . ", total requests cached " . keys(%xml_cache) . "\n";
untie %xml_cache;
} else {
untie %xml_cache;
eval 'use LWP::Simple qw($ua get)'; if ($@) { print "Content-type: text/html\n\n"; print "Unable to use LWP::Simple and this script cannot function without it.\n"; exit; }
my $ua = new LWP::UserAgent;
$ua->timeout(30);
$xml_result = get($value);
$xml_result =~ s/\<//<$1em>/gi;
$xml_result =~ s/<(\/?)b>/<$1strong>/gi;
$xml_result =~ s/
/
/gi;
$xml_result =~ s/<\/?p>/
/gi;
if (!$xml_result and $skip ne "skip_ok") { $MY_variables{error_msg} = "Sorry, we are currently unable to process your request in a timely manner.
Please try again later.\n"; }
if ($use_cache eq "yes" and !$dbm_error) {
my $count=0;
open(LOCK, ">$cache_file.lock");
until (flock(LOCK,2) or $count > 50) {
sleep .10;
++$count;
}
if ($count > 50) { $dbm_error = "lock failed"; }
if (!$dbm_error) {
eval 'tie(%xml_cache,"DB_File",$cache_file,O_CREAT|O_RDWR)'; $dbm_error = $@;
if (keys(%xml_cache) > $cache_max_size) { undef %xml_cache; $debug .= "cleared cache\n"; }
}
}
$xml_cache{$value} = $xml_result;
$xml_cache{$cache_time} = time;
untie %xml_cache;
close(LOCK);
$debug .= "cache status = not cached request size " . length($xml_result) . "\n";
}
$xml_result =~ s/([^<]+)<\/ErrorMsg>/if ($skip ne "skip_ok") { $MY_variables{error_msg} .= $1; }/esi;
return $xml_result;
}
sub getTextHex($color){
$debug.= "Number: ".(0.3*$color[0] + 0.59*$color[1] + 0.11*$color[2])."
\n";
return ((0.3*$color[0] + 0.59*$color[1] + 0.11*$color[2]) <= 128) ? "FFFFFF" : "000000";
}