view goodreads/bkp/working/getGoodreadsShelves.php @ 45:8bc395c87c6f

less built-in use of full site address
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sun, 06 Jan 2019 08:09:47 -0500
parents 077b0a0a3e6d
children 385ddd7c4b55 a67bf725e87b
line wrap: on
line source

<?php
include "UTFUtil.php";

$userID=$_GET['userID'];
$grID=$_GET['grID'];
if( $userID == "" || $grID == "")
{
	echo "<html>
		<link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\">
		<head>
		<title>YourNextRead Export Unsuccessful</title>
		</head>
		<body>

		<h1>YourNextRead</h1>
		<p>Whoops, there seems to be a problem exporting your lists. Please try again later or <a href=\"mailto:feedback@yournextread.com\">email us</a> and we will investigate!</p>
		<p>Click <a href=\"http://www.yournextread.com\">here</a> to go back to YourNextRead</p>

		<p>www.YourNextRead.com</p>

		</body>
		</html>";
}
else
{
$url= "http://www.goodreads.com/shelf/list?format=xml&key=8vxmKmAn8AVolobtvBbMIg&user_id=" . $grID;
//echo $url;

	$crl = curl_init();
	$timeout = 5;
	curl_setopt ($crl, CURLOPT_URL,$url);
	curl_setopt ($crl, CURLOPT_ENCODING , "gzip");
	curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
	$ret = curl_exec($crl);	
	$ret = preg_replace("/[^[:alnum:][:punct:][:space:]]/","",$ret);
	//echo $ret;		
	
	include "../../private/db.php"; 
	
	$xml = new SimpleXMLElement(convert_utf8($ret));
	for($i=0;$i<sizeof($xml->shelves->user_shelf);$i++){

		$shelfName= $xml->shelves->user_shelf[$i]->name;
		//echo $shelfName;
		
		$url = "http://www.goodreads.com/review/list/$grID?shelf=$shelfName&format=xml&key=8vxmKmAn8AVolobtvBbMIg";
		curl_setopt ($crl, CURLOPT_URL,$url);
		$ret1 = curl_exec($crl);

		$ret1 = preg_replace("/[^[:alnum:][:punct:][:space:]]/"," ",$ret1);
		$ret1 = convert_utf8($ret1);
		$xml1 = new SimpleXMLElement($ret1);
		for($j=0;$j<sizeof($xml1->books->book);$j++){
			//echo $xml1->books->book[$j]->isbn . "\n";
			$isbn = trim($xml1->books->book[$j]->isbn);
			$picURL = trim($xml1->books->book[$j]->image_url);
			$title = trim($xml1->books->book[$j]->title);
			//echo $title;
			$add = "CALL insertUserSave($userID,\"Goodreads: $shelfName\",'$isbn','$picURL',\"$title\")"; 
			//echo $add;
			$run = mysqli_query($link, $add); //add the book to the list in usersave
		}
	}
	curl_close($crl);
	
	echo 
	"<html>
		<link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\">
		<head>
		<title>Goodreads Import Successful</title>
		</head>
		<body>

		<h1>YourNextRead</h1>
		<meta http-equiv=\"refresh\" content=\"7; url=http://www.YourNextRead.com/\"> 
		<p>Thank you! Your Goodreads Lists have successfully been imported to your YourNextRead account</p>
		<p>Click <a href=\"javascript:window.history.go(-2)\">here</a> to go back to YourNextRead</p>

		<p>www.YourNextRead.com</p>

		</body>
	</html>";
	
}
?>