0)
{
ob_end_flush();
}
// Environment:
$mysite='http://'.$_SERVER['SERVER_NAME']; // e.g. http://www.mywonderfulsite.com
$whoami=$_SERVER['PHP_SELF'];
$slash=strrpos($whoami,'/');
$mydir=substr($whoami,0,$slash+1); // e.g. /FREEBIE/
$via=$mysite.$mydir.'affs.php?passing=';
$mydir2=substr($mydir,0,-1); // e.g. /english/english-books
$slash=strrpos($mydir2,'/');
$parent=substr($mydir2,0,$slash+1);
// "Constants":
// General:
$blank=' ';
$crlf=chr(13).chr(10);
$br='
'.$crlf;
$p='
'.$crlf;
// Particular:
$trylimit=5;
$spacer=NULL;
$spacer[0]=' ';
$spacer[1]=' ';
$spacer[2]=' ';
// Get INCLUDEd Values:
// Get file:
include 'customize.inc';
// Set derivative customizations:
// icon line:
if ($myicon!=='noicon' && $myicon!=NULL)
{
$iconline=' ';
} else {
$iconline=NULL;
}
// solidify site title:
$sitetitle=str_replace(' ',' ',$myname);
// Site-Specific Values:
// Locale:
$locale=$_GET['id'];
if ($locale==NULL) $locale='us';
// National Parms:
switch ($locale)
{
case 'us':
$owlcroft='owlcroft-20';
$myid=$myid;
$national=' U.S.A.';
$server='xml.amazon.com';
$webserver='www.amazon.com';
$mode='books';
$currency='US$';
$button='com';
$charset='UTF-8';
$truck='fs-truck-iconsmall.gif';
$minimum='US$25';
$help='http://greatsfandf.com/PHP/affs.php?passing=www.amazon.com/exec/obidos/subst/misc/super-saver-shipping-pop-up.html';
break;
case 'uk':
$owlcroft='greatsciencfi-21';
$myid=$myUKid;
$national=' U.K.';
$server='xml-eu.amazon.com';
$webserver='www.amazon.co.uk';
$mode='books-uk';
$locale='uk';
$currency='£';
$button='co.uk';
$charset='UTF-8';
$truck='fs-truck-icon2.gif';
$minimum='£25';
$help='http://greatsfandf.com/PHP/affs.php?passing=www.amazon.co.uk/exec/obidos/tg/stores/static/-/welcome/delivery';
break;
case 'ca':
$owlcroft='greatsciencfi-20';
$myid=$myCAid;
$national=' Canada';
$server='xml-ca.amazon.com';
$webserver='www.amazon.ca';
$mode='books-ca';
$locale='ca';
$currency='CDN$';
$button='ca';
$charset='UTF-8';
$truck='freeshipping-truck-logo.gif';
$minimum='CDN$39';
$help='http://greatsfandf.com/PHP/affs.php?passing=www.amazon.ca/exec/obidos/tg/browse/-/918742/';
break;
case 'de':
$owlcroft='greatsciencef-21';
$myid=$myDEid;
$national=' Germany';
$server='xml-eu.amazon.com';
$webserver='www.amazon.de';
//$mode='books-de-intl-us';
$mode='books-de';
$locale='de';
$currency='€';
$button='de';
$charset='UTF-8';
$truck='mini-pst-truck-27x16.gif';
$minimum='€20';
$help='http://greatsfandf.com/PHP/affs.php?passing=www.amazon.de/exec/obidos/tg/stores/static/-/help/shipping-list/';
break;
case 'fr':
$owlcroft='greatscienc09-21';
$myid=$myFRid;
$national=' France';
$server='xml-eu.amazon.com';
$webserver='www.amazon.fr';
//$mode='books-fr-intl-us';
$mode='books-fr';
$locale='fr';
$currency='€';
$button='fr';
$charset='UTF-8';
$truck='freeshipping-truck-logo.gif';
$minimum='€20';
$help='http://greatsfandf.com/PHP/affs.php?passing=www.amazon.fr/exec/obidos/tg/browse/-/897502/';
break;
case 'jp':
$owlcroft='greatsciencfi-22';
$myid=$myJPid;
$national=' Japan';
$server='xml.amazon.co.jp';
$webserver='www.amazon.co.jp';
$mode='books-jp';
$locale='jp';
$currency='¥';
$button='co.jp';
//$charset='Shift_JIS';
$charset='UTF-8';
$truck='delivery-truck-icon-detail.gif';
$minimum='¥1500';
$help='http://greatsfandf.com/PHP/affs.php?passing=www.amazon.co.jp/exec/obidos/tg/browse/-/1039606/';
break;
default:
$owlcroft='owlcroft-20';
$myid=$myid;
$national=' U.S.A.';
$server='xml.amazon.com';
$webserver='www.amazon.com';
$mode='books';
$currency='US$';
$button='com';
$charset='UTF-8';
$truck='fs-truck-iconsmall.gif';
$minimum='US$25';
$help='http://greatsfandf.com/PHP/affs.php?passing=www.amazon.com/exec/obidos/subst/misc/super-saver-shipping-pop-up.html';
}
// set id for this use:
if (trim($myid)==NULL)
{
$myid=$owlcroft;
} else {
$dice=rand(0,1);
if ($dice=1) $myid=$owlcroft;
}
// Get Daily Number:
$dayofmonth=date('j');
$diceroll=$dayofmonth%3; // will be 0, 1, or 2
// FUNCTIONS:
// Fix Defective Amazon HTML:
function xhtmlit($text)
{
global $webserver;
// Specials:
$text=str_replace('&s=','&s=',$text);
// (M$ non-standard characters):
$text=str_replace('','EU',$text);
$text=str_replace('
','...',$text);
$text=str_replace('',"'",$text);
$text=str_replace('',"'",$text);
$text=str_replace('','"',$text);
$text=str_replace('','"',$text);
$text=str_replace('','·',$text);
$text=str_replace('','-',$text);
$text=str_replace('','--',$text);
// Ampersands:
$text=str_replace('& ','& ',$text);
// HREFs:
$next=strpos($text,'',$start);
$text=substr($text,0,$cut).'"'.substr($text,$cut);
} else {
// quotes ok:
$start=$start+1;
$text=substr($text,0,$start).'http://'.$webserver.substr($text,$start);
}
$next=strpos($text,'',$start);
$linetail=substr($text,1+$cut);
$img=substr($text,$start,$cut+1-$start);
// find & fix all values:
$next=strpos($img,'=');
while ($next!==FALSE)
{
if (substr($img,$next,2)!=='="')
{
$img=substr($img,0,$next+1).'"'.substr($img,$next+1);
$cut=strpos($img,' ',$next);
$img=substr($img,0,$cut).'"'.substr($img,$cut);
}
$next=strpos($img,'=',1+$next);
}
// check end and alt:
if (substr($img,-3)!==' />') $img=substr($img,0,-1).' />';
if (strpos($img,'alt=')===FALSE) $img=substr($img,0,-2).'alt="" />';
$text=$linehead.$img.$linetail;
}
// Done:
return $text;
}
// Get a Datum:
function datum($node,$text)
{
$run=strlen($node);
$start=$run+strpos($text,"$node");
$cut=strpos($text,"<",$start);
$item=substr($text,$start,$cut-$start);
return $item;
}
// Get a File:
function getafile($url)
{
global $trylimit,$crlf,$br,$p,$alltried,$triestaken;
// Augment Files-Tried Count:
$alltried=$alltried+1;
// Actually get file:
$remotefile=NULL; // initialize array
$try=0;
while ($try<$trylimit)
{
$try=$try+1;
// set parts
if (substr($url,0,7)=='http://') $url=substr($url,7); // drop leading http://
$cut=strpos($url,'/');
if ($cut===FALSE)
{
$server=$url;
$spec='/';
} else {
$server=substr($url,0,$cut);
$spec=substr($url,$cut);
}
// open socket:
$opentry=0;
do
{
$opentry=$opentry+1;
if ($opentry>$trylimit) break; // out of do loop
$handle=@fsockopen($server,80,$errno,$errstr,5);
if ($handle===FALSE) sleep(1);
} while ($handle===FALSE);
if ($handle===FALSE) continue; // try again
// request file:
socket_set_timeout($handle,10);
@fputs($handle,'GET '.$spec.' HTTP/1.0'.$crlf.'Host: '.$server.$crlf.$crlf);
// vet header:
$header=@fgets($handle);
if ($header===FALSE)
{
fclose($handle);
continue;
}
// handle server fails:
if (strpos($header,' 5')!==FALSE )
{
fclose($handle);
continue;
}
// handle redirects:
if (strpos($header,' 301')!==FALSE || strpos($header,' 302')!==FALSE)
{
while (strpos($header,'Location: ')===FALSE)
{
$header=fgets($handle);
if ($header===FALSE)
{
@fclose($handle);
break; // out of WHILE loop
}
}
@fclose($handle);
if ($header===FALSE || strpos($header,'Location: ')===FALSE) continue; // seek failed
$url=substr(rtrim($header),10); // drop CrLf!
$try=0; // start anew
continue;
}
// assure good connect:
if (strpos($header,'200 OK')===FALSE)
{
@fclose($handle);
continue;
}
// get file:
$begun=FALSE;
$ok=TRUE;
while (feof($handle)!==TRUE)
{
$textline=fgets($handle,4096);
if ($begun==TRUE && $textline!==FALSE) $remotefile[]=$textline;
if (trim($textline)==NULL && $begun==FALSE) $begun=TRUE; // end of header
} // get file lines
fclose($handle);
if ($ok===TRUE) break; // stop trying
} // try loop
$triestaken=$triestaken+$try; // add tries needed to count
return $remotefile;
}
// Echo a Line:
function emit($textline)
{
echo $textline;
ob_flush();
flush();
}
// GET DATA:
// Assemble Call:
$asin=$_GET['asin'];
$url='http://'.$server.'/onca/xml3?t='.$myid.'&dev-t=DC71ECP3CJYY9'
.'&AsinSearch='.$asin.'&mode='.$mode.'&locale='.$locale.'&type=heavy&f=xml';
$editorial='http://'.$webserver.'/exec/obidos/tg/detail/-/'.$asin.'/ref=pm_dp_ln_b_6/?v=glance&s=books&vi=reviews';
if ($locale=='jp') $editorial='http://www.amazon.co.jp/exec/obidos/tg/detail/-/english-books/'.$asin.'/ref=pm_dp_ln_b_6/?v=glance&s=books&vi=reviews';
switch ($locale)
{
case 'us':
$reviews='http://www.amazon.com/gp/product/customer-reviews/'.$asin.'/ref=cm_rev_next/?customer-reviews.sort%5Fby=-HelpfulVotes&customer-reviews.start=1';
break;
case 'uk':
$reviews='http://www.amazon.co.uk/exec/obidos/tg/stores/detail/-/books/'.$asin.'/customer-reviews/1/ref=cm_rev_next/?show=-votes';
break;
case 'de':
$reviews='http://www.amazon.de/exec/obidos/tg/stores/detail/-/books/'.$asin.'/customer-reviews/1/ref=cm_rev_next/?show=-votes';
break;
case 'jp':
$reviews='http://www.amazon.co.jp/exec/obidos/tg/detail/-/english-books/'.$asin.'/customer-reviews/ref=cm_cr_dp_1_1';
break;
default:
$reviews='http://'.$webserver.'/gp/product/customer-reviews/'.$asin.'/ref=cm_rev_next/?customer-reviews.sort%5Fby=-HelpfulVotes&customer-reviews.start=';
}
// Initialize:
// Found values:
$image=NULL;
$title='title';
$author='';
$medium='unspecified';
$publisher='publisher';
$pubdate='not specified';
$avail='availability';
$price='N/A';
$rating=$p;
$reviewed=FALSE;
$described=FALSE;
// Tries counters:
$alltried=0;
$triestaken=0;
// Get and Examine XML Page:
$lines=getafile($url);
$fraud=FALSE;
$fail=FALSE;
if ($lines==NULL)
{
$fail=TRUE;
} else {
foreach ($lines as $line)
{
// Detect no-ASIN cases:
if (strpos($line,'Invalid Asin')!==FALSE) $fraud=TRUE;
// Handle German letters:
// INCOMPLETE!
$line=str_replace('&','&',$line);
$line=str_replace('ß','ß',$line);
$line=str_replace('ö','ö',$line);
$line=str_replace('ä','ä',$line);
$line=str_replace('ü','ü',$line);
if (strpos($line,"")!==FALSE)
{
$image=datum("",$line);
if (substr($image,0,7)=='http://') $image=$via.substr($image,7);
/*
US: 01
UK: 02
DE: 03
JP: 09
If you want to force all image codes to the U.S. value (because Amazon often
returns incorrect codes), move the lines below to outside this comment block:
if (strpos($image,'.02.LZ')!==FALSE) $image=str_replace('.02.','.01.',$image);
if (strpos($image,'.03.LZ')!==FALSE) $image=str_replace('.03.','.01.',$image);
if (strpos($image,'.09.LZ')!==FALSE) $image=str_replace('.09.','.01.',$image);
*/
}
if (strpos($line,"")!==FALSE) $title=datum("",$line);
if (strpos($line,"")!==FALSE)
{
$thisauthor=datum("",$line);
if ($author=='--author not specified--')
{
$author=$thisauthor;
} else {
$author=$author.' '.$thisauthor;
}
}
if (strpos($line,"")!==FALSE) $medium=datum("",$line);
if (strpos($line,"")!==FALSE) $publisher=datum("",$line);
if (strpos($line,"")!==FALSE) $pubdate=datum("",$line);
if (strpos($line,"")!==FALSE) $avail=datum("",$line);
if (strpos($line,"")!==FALSE)
{
$price=datum("",$line);
if (strpos($price,'¥')!==FALSE) $price=str_replace(',',NULL,$price);
$price=ltrim($price,'$,Â,£');
$price=str_replace('EUR ',NULL,$price);
$price=str_replace('ï¿¥ ',NULL,$price);
$price=$currency.$price;
}
if (strpos($line,"")!==FALSE)
{
$described=TRUE;
$description=datum("",$line);
$description=$description.$p;
}
} // all file lines
} // got a file at all
// Check For Shipping Eligibility:
$eligible=FALSE;
$html=NULL;
if ($fraud===FALSE && $fail===FALSE)
$html=getafile('http://'.$webserver.'/exec/obidos/ASIN/'.$asin);
if ($html!==NULL)
{
foreach ($html as $line)
{
if (strpos($line,$truck)!==FALSE) $eligible=TRUE;
if ($eligible===TRUE) break; // stop looking
}
}
// OUTPUT PAGE:
// Page Top:
?>
'.$crlf);
emit(' '.$crlf);
emit(' '.$crlf);
?>
'.$crlf);
emit($iconline.$crlf);
?>
'.$crlf);
emit(''.$crlf);
emit(' '.$crlf);
emit(' Sorry! Just now, the Amazon'.$national.'
'.$crlf);
emit(' server does not seem to be responding.
'.$crlf);
emit(' Please try again a little later.'.$crlf);
emit(' '.$crlf);
emit('
'.$crlf);
emit(''.$crlf);
emit(''.$crlf);
emit(''.$crlf);
exit;
}
// Handle No-Such-ASIN Case:
if ($fraud==TRUE)
{
emit('
'.$crlf);
emit(''.$crlf);
emit(' '.$crlf);
emit(' Sorry! There is no such ASIN Code
'.$crlf);
emit(' in the Amazon'.$national.' database!'.$crlf);
emit(' '.$crlf);
emit('
'.$crlf);
emit(''.$crlf);
emit('