Mercurial > hg > ywww
view goodreads/syncGoodreadsShelves.php @ 6:077b0a0a3e6d
remaining originals according to dependency walk
author | Robert Boland <robert@markup.co.uk> |
---|---|
date | Thu, 16 Feb 2017 22:29:02 +0000 |
parents | |
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"; $shelves = array(); $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; $shelves[$i] = $shelfName; } curl_close($crl); $ynrLists = "CALL b_getAllSavedBooksByUser($userID)"; //echo $add; $results = mysqli_query($link, $ynrLists) or exit( mysqli_error( $link )); 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']); while($line = mysqli_fetch_assoc($results)) { $shelf = trim($line["SavedListName"]); $isbn = trim($line["ISBN"]); if($isbn != "") { if (!in_array($shelf, $shelves)) { $url= "http://www.goodreads.com/book/isbn?isbn=" . $isbn . "&key=8vxmKmAn8AVolobtvBbMIg"; //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); curl_close($crl); $ret = preg_replace("/[^[:alnum:][:punct:][:space:]]/","",$ret); if(trim($ret) != "") { $xml = new SimpleXMLElement(convert_utf8($ret)); $book_id = $xml->book->id; //echo $shelf . ":" . $book_id; if(trim($book_id) != "") { $content = $obj->doPost('http://www.goodreads.com/shelf/add_to_shelf.xml', array("name" => "$shelf", "book_id" => "$book_id")); //print_r($content); //echo "$$"; sleep(1); } } } } } unset ($obj); $backLoc = "http://www.yournextread.com/" . urldecode($_SESSION['backLocation']); echo "<html> <link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\"> <head> <title>YourNextRead Export Successful</title> </head> <body> <h1>YourNextRead</h1> <p>Thank you! Your YourNextRead Lists have successfully been imported to your Goodreads 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>"; } ?>