Mercurial > hg > ywww
diff goodreads/addToGRShelf.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 diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/goodreads/addToGRShelf.php Thu Feb 16 22:29:02 2017 +0000 @@ -0,0 +1,74 @@ +<?php +include "UTFUtil.php"; + +$userID=$_GET['userID']; +$listName=urldecode($_GET['listName']); +//echo $userID; +//echo $listName; + +include "../../private/db.php"; +$ynrList = "CALL b_getUserSavedList($userID,\"$listName\")"; +//echo $ynrList; +//echo $add; +$results = mysqli_query($link, $ynrList) or exit( mysqli_error( $link )); + +require_once('GoodreadsAPI.php'); +session_start(); +$access_token = $_SESSION['access_token']; + +if($access_token == "") +{ + $back=$_GET['backLocation']; + + session_start(); + $_SESSION['backLocation'] = $back; + + $connection = new GoodreadsAPI(CONSUMER_KEY, CONSUMER_SECRET); + $request_token = $connection->getRequestToken(CALLBACK_URL); + + $_SESSION['oauth_token'] = $request_token['oauth_token']; + $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; + + $authorize_url = $connection->getLoginURL($request_token); + echo $authorize_url; +} +else +{ + //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)) { + $isbn = trim($line["ISBN"]); + if($isbn != "") + { + $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; + if(trim($book_id) != "") + { + $content = $obj->doPost('http://www.goodreads.com/shelf/add_to_shelf.xml', array("name" => "$listName", "book_id" => "$book_id")); + //print_r($content); + sleep(0.5); + } + } + } + } + + unset ($obj); + + echo trim($listName); +} +?>