comparison goodreads/getGoodreadsShelves.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 if( $userID == "" || $grID == "")
7 {
8 echo "<html>
9 <link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\">
10 <head>
11 <title>YourNextRead Export Unsuccessful</title>
12 </head>
13 <body>
14
15 <h1>YourNextRead</h1>
16 <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>
17 <p>Click <a href=\"http://www.yournextread.com\">here</a> to go back to YourNextRead</p>
18
19 <p>www.YourNextRead.com</p>
20
21 </body>
22 </html>";
23 }
24 else
25 {
26 $url= "http://www.goodreads.com/shelf/list?format=xml&key=8vxmKmAn8AVolobtvBbMIg&user_id=" . $grID;
27 //echo $url;
28
29 $crl = curl_init();
30 $timeout = 5;
31 curl_setopt ($crl, CURLOPT_URL,$url);
32 curl_setopt ($crl, CURLOPT_ENCODING , "gzip");
33 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
34 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
35 $ret = curl_exec($crl);
36 $ret = preg_replace("/[^[:alnum:][:punct:][:space:]]/","",$ret);
37 //echo $ret;
38
39 include "../../private/db.php";
40 require_once('GoodreadsAPI.php');
41 session_start();
42 $access_token = $_SESSION['access_token'];
43 //print_r($access_token);
44 $obj = new GoodreadsApi(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
45
46 $xml = new SimpleXMLElement(convert_utf8($ret));
47 for($i=0;$i<sizeof($xml->shelves->user_shelf);$i++){
48
49 $shelfName= $xml->shelves->user_shelf[$i]->name;
50 //echo $shelfName;
51
52 $ret1 = $obj->doGet('http://www.goodreads.com/review/list.xml?v=2', array("id" => "$grID","shelf" => "$shelfName"));
53
54 //$url = "http://www.goodreads.com/review/list/$grID?shelf=$shelfName&format=xml&key=8vxmKmAn8AVolobtvBbMIg";
55 //echo $url;
56 //curl_setopt ($crl, CURLOPT_URL,$url);
57 //$ret1 = curl_exec($crl);
58
59 $ret1 = preg_replace("/[^[:alnum:][:punct:][:space:]]/"," ",$ret1);
60 $ret1 = convert_utf8($ret1);
61 //echo "%%" . $ret1 . "**";
62 $xml1 = new SimpleXMLElement($ret1);
63 //echo sizeof($xml1->reviews->review);
64 for($j=0;$j<sizeof($xml1->reviews->review);$j++){
65 //echo $xml1->reviews[$j]->review->book->isbn . "\n";
66 $isbn = trim($xml1->reviews->review[$j]->book->isbn);
67 $picURL = trim($xml1->reviews->review[$j]->book->image_url);
68 $title = trim($xml1->reviews->review[$j]->book->title);
69 //echo $title;
70 $add = "CALL b_insertSaveList($userID,\"$shelfName\",'$isbn','$picURL',\"$title\")";
71 //echo $add;
72 $run = mysqli_query($link, $add); //add the book to the list in usersave
73 if($shelfName == "read")
74 {
75 $add = "CALL b_insertSaveList($userID,\"MyMap\",'$isbn','$picURL',\"$title\")";
76 //echo $add;
77 $run = mysqli_query($link, $add); //add the book to the list in usersave
78 }
79 }
80 }
81 //curl_close($crl);
82 //session_start();
83 $backLoc = "http://www.yournextread.com/" . urldecode($_SESSION['backLocation']);
84
85 echo
86 "<html>
87 <link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\">
88 <head>
89 <title>Goodreads Import Successful</title>
90 </head>
91 <body>
92
93 <h1>YourNextRead</h1>
94 <p>Thank you! Your Goodreads Lists have successfully been imported to your YourNextRead account</p>
95 <p>Click <a href=\"$backLoc\">here</a> to go back to YourNextRead</p>
96
97 <p><a href=\"http://www.YourNextRead.com\">www.YourNextRead.com</a></p>
98
99 </body>
100 </html>";
101
102 }
103 ?>
104
105
106