DetectSmartphone();
$iPad = $uagent_obj->DetectIpad();
$proceed = true;
$launchScript = "";
//print_r($_SERVER);
if (isset($_SERVER['HTTP_REFERER']) || isset($_GET['facebook']))
{
$pos = strpos($_SERVER['HTTP_REFERER'], "apps.facebook.com");
if($pos !== false || isset($_GET['facebook']))
{
//we are in facebook canvas so react appropriately
include_once '../facebook.php';
$facebook = new Facebook(array(
'appId' => '128245333876633',
'secret' => 'f51afc7e04289db62448edd8b70d83bf',
'cookie' => true,
'domain' => 'yournextpresent.com'
));
$session = $facebook->getSession();
if (!$session) {
$proceed = false;
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'email,user_birthday,publish_stream'
));
echo "";
}
else
{
$launchScript = "";
}
}
}
echo "";
if($proceed)
{
echo "
";
echo "";
echo "";
echo "";
echo "";
if(isset($_GET['_escaped_fragment_'])) {
$isbn = $_GET['_escaped_fragment_'];
if($isbn == ""){
echo "";
echo "YourNextRead: Book Recommendations (USA)";
echo "";
if($iPhone && !$iPad)
{
echo "";
echo "";
}
else
{
echo "";
echo $launchScript;//"";
}
echo "";
echo "";
//we are at the launch page
echo "Get started, search for a book you like... or choose from one of the lists below:
";
$ret = 1;
$bookLists = include "../php/read/getAllSavedBooks.php";
$xml = new SimpleXMLElement($bookLists);
$numOfLists = sizeof($xml->List) - 1; //-1 for zero indexing
$randomFourLists = uniqueRand(4,0,$numOfLists);
foreach ($randomFourLists as $id) {
$ListName = $xml->List[$id]->SavedListName;
echo "$ListName
";
for($i=0;$iList[$id]->ListDetails->Book);$i++){
$bookTitle = $xml->List[$id]->ListDetails->Book[$i]->BookTitle;
$isbn = $xml->List[$id]->ListDetails->Book[$i]->ISBN;
echo "$bookTitle ";
}
}
}
else
{
try{
$isbn = substr($isbn, 5);
$chars = explode("/",$isbn);
$isbn = $chars[0];
$ret = 1;
$countryCode = 0;
include "../../private/db.php";
$query = "CALL b_getBookInfo('$isbn', $countryCode)";
//echo $query;
$res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
include "../xml/aws_signed_request.php";
include "../xml/getAmazonInfo.php";
if ( mysqli_num_rows( $res ) > 0 )
{
$rows=mysqli_fetch_array($res, MYSQLI_ASSOC);
$title = $rows["Title"];
$author = $rows["Author"];
}
else
{
$bookDetails = getAmazonDet($isbn,1,'us');
$bookXML = new SimpleXMLElement($bookDetails);
$title = $bookXML->Items->Item[0]->ItemAttributes->Title;
$author = $bookXML->Items->Item[0]->ItemAttributes->Author;
}
$linkedBooks = include "../php/read/getLinkedBooks.php";
$xml = new SimpleXMLElement($linkedBooks);
$recommended = "";
$linkedRecommended = "";
for($i=0;$iisbn);$i++){
$linkedISBN = $xml->isbn[$i];
include "../../private/db.php";
$query = "CALL b_getBookInfo('$linkedISBN', $countryCode)";
//echo $query;
$res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
set_error_handler(function () {
global $bookLDetails, $linkedISBN;
file_put_contents('/var/ywww/debug/phpDebug',
"Caught other one?: ".$linkedISBN,
FILE_APPEND);
//file_put_contents('/var/ywww/debug/phpDebug',
// print_r($bookLDetails, TRUE)."\n",
// FILE_APPEND);
} );
if ( mysqli_num_rows( $res ) > 0 )
{
$rows=mysqli_fetch_array($res, MYSQLI_ASSOC);
$titleL = $rows["Title"];
$authorL = $rows["Author"];
mysqli_close($link);
}
else
{
$bookLDetails = getAmazonDet($linkedISBN,1,'us');
$bookLXML = new SimpleXMLElement($bookLDetails);
// HST added this
if (preg_match("",$bookLDetails)) {
$resName=$bookLXML->getName();
$code=$bookLXML->Error->Code;
file_put_contents('/var/ywww/debug/phpDebug',"Losing 2: $resName, ".
$code."\n",FILE_APPEND);
if ($code=='RequestThrottled') {
usleep(200000); // Try to reduce throttling until we get a
// principled solution in place
}
$titleL = "";
}
else {
$titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title;
$authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author;
}
}
restore_error_handler();
if($titleL != "")
{
$recommended .= " $titleL by $authorL,";
$underAuthor = str_replace(" ","_",$authorL);
$underTitle = str_replace(" ","_",$titleL);
$linkedRecommended .= "$titleL by $authorL, ";
}
}
$vote = "Vote on these recommendations!";
echo "";
echo "YourNextRead (USA) Recommended Books for $title by $author";
echo "";
if($iPhone && !$iPad)
{
echo "";
echo "";
}
else
{
echo "";
echo $launchScript;//"";
}
echo "";
echo "";
echo "Recommended Books for $title by $author:";
echo $linkedRecommended . "
";
echo "" . $vote . "
";
echo "Change to YourNextRead Germany, ";
echo "Change to YourNextRead Canada, ";
echo "Change to YourNextRead France, ";
echo "Change to YourNextRead USA";
echo ", See this on YourNextPresent, ";
echo "Switch to YourNextFilm, ";
echo "Switch to YourNextGame";
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
}
}
else
{
echo "";
echo "YourNextRead: Book Recommendations (USA)";
//the title will get changed dynamically in the GWT code
echo "";
if($iPhone && !$iPad)
{
echo "";
echo "";
}
else
{
echo "";
echo $launchScript;//"";
}
echo "";
echo "";
echo "
";
echo "";
}
}
?>