view goodreads/getGoodreadsShelves2.php @ 50:99a730ffeaf6

more parameterisation
author Charlie Root
date Sun, 27 Jan 2019 14:24:02 -0500
parents a67bf725e87b
children
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
{

	require_once('GoodreadsAPI.php');
	session_start();
	$access_token = $_SESSION['access_token'];
	//print_r($access_token);
	$obj = new GoodreadsApi(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
	$ret = $obj->doGet('http://www.goodreads.com/review/list.xml?v=2', array("id" => "$grID"));
	//print_r($content);

//$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 "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";
		//echo $url;
		curl_setopt ($crl, CURLOPT_URL,$url);
		$ret1 = curl_exec($crl);

		$ret1 = preg_replace("/[^[:alnum:][:punct:][:space:]]/"," ",$ret1);
		$ret1 = convert_utf8($ret1);
		//echo "%%" . $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,\"$shelfName\",'$isbn','$picURL',\"$title\")"; 
			//echo $add;
			$run = mysqli_query($link, $add); //add the book to the list in usersave
		}
	}
	//curl_close($crl);
	//session_start();
	$backLoc = "http://www.yournextread.com/" . urldecode($_SESSION['backLocation']);
	
	echo 
	"<html>
		<link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\">
		<head>
		<title>Goodreads Import Successful</title>
		</head>
		<body>

		<h1>YourNextRead</h1>
		<p>Thank you! Your Goodreads Lists have successfully been imported to your YourNextRead account</p>
		<p>Click <a href=\"$backLoc\">here</a> to go back to YourNextRead</p>

		<p><a href=\"http://www.YourNextRead.com\">www.YourNextRead.com</a></p>

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