Mercurial > hg > ywww
comparison goodreads/bkp/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 | |
3 $userID=$_GET['userID']; | |
4 $grID=$_GET['grID']; | |
5 | |
6 $url= "http://www.goodreads.com/shelf/list?format=xml&key=8vxmKmAn8AVolobtvBbMIg&user_id=" . $grID; | |
7 //echo $url; | |
8 | |
9 $crl = curl_init(); | |
10 $timeout = 5; | |
11 curl_setopt ($crl, CURLOPT_URL,$url); | |
12 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); | |
13 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
14 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
15 $ret = curl_exec($crl); | |
16 $ret = preg_replace("/[^[:alnum:][:punct:][:space:]]/","",$ret); | |
17 //echo $ret; | |
18 | |
19 include "../../private/db.php"; | |
20 | |
21 $shelves = array(); | |
22 | |
23 $xml = new SimpleXMLElement(convert_utf8($ret)); | |
24 for($i=0;$i<sizeof($xml->shelves->user_shelf);$i++){ | |
25 | |
26 $shelfName= $xml->shelves->user_shelf[$i]->name; | |
27 //echo $shelfName; | |
28 $shelves[$i] = $shelfName; | |
29 | |
30 /*$url = "http://www.goodreads.com/review/list/$grID?shelf=$shelfName&format=xml&key=8vxmKmAn8AVolobtvBbMIg"; | |
31 curl_setopt ($crl, CURLOPT_URL,$url); | |
32 $ret1 = curl_exec($crl); | |
33 | |
34 $ret1 = preg_replace("/[^[:alnum:][:punct:][:space:]]/"," ",$ret1); | |
35 $ret1 = convert_utf8($ret1); | |
36 $xml1 = new SimpleXMLElement($ret1); | |
37 for($j=0;$j<sizeof($xml1->books->book);$j++){ | |
38 //echo $xml1->books->book[$j]->isbn . "\n"; | |
39 $isbn = trim($xml1->books->book[$j]->isbn); | |
40 $picURL = trim($xml1->books->book[$j]->image_url); | |
41 $title = trim($xml1->books->book[$j]->title); | |
42 //echo $title; | |
43 $add = "CALL insertUserSave($userID,\"$shelfName\",'$isbn','$picURL',\"$title\")"; | |
44 //echo $add; | |
45 $run = mysqli_query($link, $add); //add the book to the list in usersave | |
46 }*/ | |
47 } | |
48 curl_close($crl); | |
49 | |
50 $ynrLists = "CALL getAllSavedBooksByUser($userID)"; | |
51 //echo $add; | |
52 $results = mysqli_query($link, $ynrLists) or exit( mysqli_error( $link )); | |
53 | |
54 require_once('GoodreadsAPI.php'); | |
55 session_start(); | |
56 $access_token = $_SESSION['access_token']; | |
57 print_r($access_token); | |
58 $obj = new GoodreadsApi(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); | |
59 | |
60 while($line = mysqli_fetch_assoc($results)) { | |
61 $shelf = trim($line["SavedListName"]); | |
62 $isbn = trim($line["ISBN"]); | |
63 if($isbn != "") | |
64 { | |
65 if (!in_array($shelf, $shelves)) | |
66 { | |
67 $url= "http://www.goodreads.com/book/isbn?isbn=" . $isbn . "&key=8vxmKmAn8AVolobtvBbMIg"; | |
68 //echo $url; | |
69 $crl = curl_init(); | |
70 $timeout = 5; | |
71 curl_setopt ($crl, CURLOPT_URL,$url); | |
72 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); | |
73 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
74 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
75 $ret = curl_exec($crl); | |
76 curl_close($crl); | |
77 | |
78 $ret = preg_replace("/[^[:alnum:][:punct:][:space:]]/","",$ret); | |
79 if(trim($ret) != "") | |
80 { | |
81 $xml = new SimpleXMLElement(convert_utf8($ret)); | |
82 $book_id = $xml->book->id; | |
83 echo $shelf . ":" . $book_id; | |
84 $content = $obj->doPost('http://www.goodreads.com/shelf/add_to_shelf.xml', array("name" => "$shelf", "book_id" => "$book_id")); | |
85 print_r($content); | |
86 echo "$$"; | |
87 } | |
88 } | |
89 } | |
90 } | |
91 | |
92 unset ($obj); | |
93 | |
94 /*echo "<html> | |
95 <link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\"> | |
96 <head> | |
97 <title>Goodreads Import Successful</title> | |
98 </head> | |
99 <body> | |
100 | |
101 <h1>YourNextRead</h1> | |
102 <meta http-equiv=\"refresh\" content=\"7; url=http://www.YourNextRead.com/\"> | |
103 <p>Thank you! Your Goodreads Lists have successfully been imported to your YourNextRead account</p> | |
104 <p>Click <a href=\"javascript:window.history.go(-2)\">here</a> to go back to YourNextRead</p> | |
105 | |
106 <p>www.YourNextRead.com</p> | |
107 | |
108 </body> | |
109 </html>"; | |
110 */ | |
111 | |
112 function convert_utf8($str){ | |
113 if(!seems_utf8($str)) | |
114 return mb_convert_encoding($str, 'UTF-8'); | |
115 return $str; | |
116 } | |
117 function seems_utf8($Str) { | |
118 for ($i=0; $i<strlen($Str); $i++) { | |
119 if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb | |
120 elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb | |
121 elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb | |
122 elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb | |
123 elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb | |
124 elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b | |
125 else return false; # Does not match any model | |
126 for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? | |
127 if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80)) | |
128 return false; | |
129 } | |
130 } | |
131 return true; | |
132 } | |
133 ?> | |
134 | |
135 | |
136 |