Mercurial > hg > ywww
comparison 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 |
comparison
equal
deleted
inserted
replaced
5:55445b456ad0 | 6:077b0a0a3e6d |
---|---|
1 <?php | |
2 include "UTFUtil.php"; | |
3 | |
4 $userID=$_GET['userID']; | |
5 $listName=urldecode($_GET['listName']); | |
6 //echo $userID; | |
7 //echo $listName; | |
8 | |
9 include "../../private/db.php"; | |
10 $ynrList = "CALL b_getUserSavedList($userID,\"$listName\")"; | |
11 //echo $ynrList; | |
12 //echo $add; | |
13 $results = mysqli_query($link, $ynrList) or exit( mysqli_error( $link )); | |
14 | |
15 require_once('GoodreadsAPI.php'); | |
16 session_start(); | |
17 $access_token = $_SESSION['access_token']; | |
18 | |
19 if($access_token == "") | |
20 { | |
21 $back=$_GET['backLocation']; | |
22 | |
23 session_start(); | |
24 $_SESSION['backLocation'] = $back; | |
25 | |
26 $connection = new GoodreadsAPI(CONSUMER_KEY, CONSUMER_SECRET); | |
27 $request_token = $connection->getRequestToken(CALLBACK_URL); | |
28 | |
29 $_SESSION['oauth_token'] = $request_token['oauth_token']; | |
30 $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; | |
31 | |
32 $authorize_url = $connection->getLoginURL($request_token); | |
33 echo $authorize_url; | |
34 } | |
35 else | |
36 { | |
37 //print_r($access_token); | |
38 $obj = new GoodreadsApi(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); | |
39 | |
40 while($line = mysqli_fetch_assoc($results)) { | |
41 $isbn = trim($line["ISBN"]); | |
42 if($isbn != "") | |
43 { | |
44 $url= "http://www.goodreads.com/book/isbn?isbn=" . $isbn . "&key=8vxmKmAn8AVolobtvBbMIg"; | |
45 //echo $url; | |
46 $crl = curl_init(); | |
47 $timeout = 5; | |
48 curl_setopt ($crl, CURLOPT_URL,$url); | |
49 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); | |
50 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
51 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
52 $ret = curl_exec($crl); | |
53 curl_close($crl); | |
54 | |
55 $ret = preg_replace("/[^[:alnum:][:punct:][:space:]]/","",$ret); | |
56 if(trim($ret) != "") | |
57 { | |
58 $xml = new SimpleXMLElement(convert_utf8($ret)); | |
59 $book_id = $xml->book->id; | |
60 if(trim($book_id) != "") | |
61 { | |
62 $content = $obj->doPost('http://www.goodreads.com/shelf/add_to_shelf.xml', array("name" => "$listName", "book_id" => "$book_id")); | |
63 //print_r($content); | |
64 sleep(0.5); | |
65 } | |
66 } | |
67 } | |
68 } | |
69 | |
70 unset ($obj); | |
71 | |
72 echo trim($listName); | |
73 } | |
74 ?> |