use strict; use vars qw(%CONFIG %VARS); sub amazon_results { my ($count, $order, $mode, $depth, $image_status, $al1, $al2) = @_; $count = 3 unless(defined($count)); $order = "ul" unless(defined($order)); $mode = "books" unless(defined($mode)); $depth = 2 unless(defined($depth)); $image_status = "image" unless(defined($image_status)); $al1 = "center" unless(defined($al1)); $al2 = "center" unless(defined($al2)); my $out; my $url; use LWP::UserAgent; if($VARS{'PAGE_TYPE'} eq "cat"){ my $temp1; if($depth == 1){ $VARS{'RAW_CURRENT_CAT'} =~ m#([^/]*)$#; my $temp1 = $1; $temp1 =~ s#_#\+#g; } else{ if($VARS{'RAW_CURRENT_CAT'} =~ m#/#){ $VARS{'RAW_CURRENT_CAT'} =~ m#([^/]*/[^/]*)$#; $temp1 = $1; } else{ $VARS{'RAW_CURRENT_CAT'} =~ m#([^/]*)$#; $temp1 = $1; } $temp1 =~ s#(_|/)#\+#g; $temp1 = lc($temp1); } $url = "http://www.amazon.com/exec/obidos/external-search/?mode=$mode\&keyword=$temp1\&tag=$CONFIG{'AMAZON_ASSOCIATES_ID'}"; } elsif($VARS{'PAGE_TYPE'} eq "search"){ my $temp = lc($VARS{'SEARCH_STRING'}); $url = "http://www.amazon.com/exec/obidos/external-search/?mode=$mode\&keyword=$temp\&tag=$CONFIG{'AMAZON_ASSOCIATES_ID'}"; } my $ua = new LWP::UserAgent; my $res = $ua->request(HTTP::Request->new(GET => $url)); my $html = $res->content; my @books = $html =~ m#([^<]*)#gs; my $first_book = $books[0]; if(scalar(@books) > $count){ @books = @books[0..($count-1)]; } for (@books){ s#/ASIN/([^/]*)/[^"]*#/ASIN/$1/$CONFIG{'AMAZON_ASSOCIATES_ID'}#; s#href="#href="http://www.amazon.com#; } my $out2; if(scalar(@books)>0){ my $li = ""; if(lc($order) ne "none"){ $li = "
  • "; } if($image_status eq "image"){ if($first_book =~ m#(()([^<]*))#s){ my $book = $1; my $link = $2; my $ASIN = $3; my $link_text = $4; $book =~ s#/ASIN/([^/]*)/[^"]*#/ASIN/$1/$CONFIG{'AMAZON_ASSOCIATES_ID'}#; $book =~ s#href="#href="http://www.amazon.com#; $link =~ s#/ASIN/([^/]*)/[^"]*#/ASIN/$1/$CONFIG{'AMAZON_ASSOCIATES_ID'}#; $link =~ s#href="#href="http://www.amazon.com#; if( head("http://images.amazon.com/images/P/$ASIN.01.MZZZZZZZ.gif") ){ $out2 = qq!
    $link $link_text

    $book

    !; shift(@books); } else{ $out2 = ""; } } else { $out2 = "" } } $out = join("
    \n$li", @books); my $out_beg = "<$order>"; $out = "$li$out"; if(lc($order) ne "none"){ $out = $out_beg . $out; $out .= ""; } $out = $out2 . $out ; } else { $out = "
    No items found

    "; } # $out .= "sadasdad"; return $out; } 1;