Mercurial > hg > ywww
comparison goodreads/bkp/working/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 |
comparison
equal
deleted
inserted
replaced
5:55445b456ad0 | 6:077b0a0a3e6d |
---|---|
1 <?php | |
2 include "UTFUtil.php"; | |
3 | |
4 $userID=$_GET['userID']; | |
5 $grID=$_GET['grID']; | |
6 | |
7 if( $userID == "" || $grID == "") | |
8 { | |
9 echo "<html> | |
10 <link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\"> | |
11 <head> | |
12 <title>YourNextRead Export Unsuccessful</title> | |
13 </head> | |
14 <body> | |
15 | |
16 <h1>YourNextRead</h1> | |
17 <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> | |
18 <p>Click <a href=\"http://www.yournextread.com\">here</a> to go back to YourNextRead</p> | |
19 | |
20 <p>www.YourNextRead.com</p> | |
21 | |
22 </body> | |
23 </html>"; | |
24 } | |
25 else | |
26 { | |
27 $url= "http://www.goodreads.com/shelf/list?format=xml&key=8vxmKmAn8AVolobtvBbMIg&user_id=" . $grID; | |
28 //echo $url; | |
29 | |
30 $crl = curl_init(); | |
31 $timeout = 5; | |
32 curl_setopt ($crl, CURLOPT_URL,$url); | |
33 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); | |
34 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
35 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
36 $ret = curl_exec($crl); | |
37 $ret = preg_replace("/[^[:alnum:][:punct:][:space:]]/","",$ret); | |
38 //echo $ret; | |
39 | |
40 include "../../private/db.php"; | |
41 | |
42 $shelves = array(); | |
43 | |
44 $xml = new SimpleXMLElement(convert_utf8($ret)); | |
45 for($i=0;$i<sizeof($xml->shelves->user_shelf);$i++){ | |
46 | |
47 $shelfName= $xml->shelves->user_shelf[$i]->name; | |
48 //echo $shelfName; | |
49 $shelves[$i] = $shelfName; | |
50 } | |
51 curl_close($crl); | |
52 | |
53 $ynrLists = "CALL getAllSavedBooksByUser($userID)"; | |
54 //echo $add; | |
55 $results = mysqli_query($link, $ynrLists) or exit( mysqli_error( $link )); | |
56 | |
57 require_once('GoodreadsAPI.php'); | |
58 session_start(); | |
59 $access_token = $_SESSION['access_token']; | |
60 //print_r($access_token); | |
61 $obj = new GoodreadsApi(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); | |
62 | |
63 while($line = mysqli_fetch_assoc($results)) { | |
64 $shelf = trim($line["SavedListName"]); | |
65 $isbn = trim($line["ISBN"]); | |
66 if($isbn != "") | |
67 { | |
68 if (!in_array($shelf, $shelves)) | |
69 { | |
70 $url= "http://www.goodreads.com/book/isbn?isbn=" . $isbn . "&key=8vxmKmAn8AVolobtvBbMIg"; | |
71 //echo $url; | |
72 $crl = curl_init(); | |
73 $timeout = 5; | |
74 curl_setopt ($crl, CURLOPT_URL,$url); | |
75 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); | |
76 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
77 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
78 $ret = curl_exec($crl); | |
79 curl_close($crl); | |
80 | |
81 $ret = preg_replace("/[^[:alnum:][:punct:][:space:]]/","",$ret); | |
82 if(trim($ret) != "") | |
83 { | |
84 $xml = new SimpleXMLElement(convert_utf8($ret)); | |
85 $book_id = $xml->book->id; | |
86 //echo $shelf . ":" . $book_id; | |
87 if(trim($book_id) != "") | |
88 { | |
89 $content = $obj->doPost('http://www.goodreads.com/shelf/add_to_shelf.xml', array("name" => "$shelf", "book_id" => "$book_id")); | |
90 //print_r($content); | |
91 //echo "$$"; | |
92 sleep(1.1); | |
93 } | |
94 } | |
95 } | |
96 } | |
97 } | |
98 | |
99 unset ($obj); | |
100 | |
101 echo "<html> | |
102 <link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\"> | |
103 <head> | |
104 <title>YourNextRead Export Successful</title> | |
105 </head> | |
106 <body> | |
107 | |
108 <h1>YourNextRead</h1> | |
109 <meta http-equiv=\"refresh\" content=\"7; url=http://www.YourNextRead.com/\"> | |
110 <p>Thank you! Your YourNextRead Lists have successfully been imported to your Goodreads account</p> | |
111 <p>Click <a href=\"javascript:window.history.go(-2)\">here</a> to go back to YourNextRead</p> | |
112 | |
113 <p>www.YourNextRead.com</p> | |
114 | |
115 </body> | |
116 </html>"; | |
117 } | |
118 ?> | |
119 | |
120 | |
121 |