comparison goodreads/bkp/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
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 $xml = new SimpleXMLElement(convert_utf8($ret));
22 for($i=0;$i<sizeof($xml->shelves->user_shelf);$i++){
23
24 $shelfName= $xml->shelves->user_shelf[$i]->name;
25 //echo $shelfName;
26
27 $url = "http://www.goodreads.com/review/list/$grID?shelf=$shelfName&format=xml&key=8vxmKmAn8AVolobtvBbMIg";
28 curl_setopt ($crl, CURLOPT_URL,$url);
29 $ret1 = curl_exec($crl);
30
31 $ret1 = preg_replace("/[^[:alnum:][:punct:][:space:]]/"," ",$ret1);
32 $ret1 = convert_utf8($ret1);
33 $xml1 = new SimpleXMLElement($ret1);
34 for($j=0;$j<sizeof($xml1->books->book);$j++){
35 //echo $xml1->books->book[$j]->isbn . "\n";
36 $isbn = trim($xml1->books->book[$j]->isbn);
37 $picURL = trim($xml1->books->book[$j]->image_url);
38 $title = trim($xml1->books->book[$j]->title);
39 //echo $title;
40 $add = "CALL insertUserSave($userID,\"Goodreads: $shelfName\",'$isbn','$picURL',\"$title\")";
41 //echo $add;
42 $run = mysqli_query($link, $add); //add the book to the list in usersave
43 }
44 }
45 curl_close($crl);
46
47 echo "<html>
48 <link rel=\"stylesheet\" type=\"text/css\" href=\"../user/style.css\">
49 <head>
50 <title>Goodreads Import Successful</title>
51 </head>
52 <body>
53
54 <h1>YourNextRead</h1>
55 <p>Thank you! Your Goodreads Lists have successfully been imported to your YourNextRead account</p>
56 <p>Click <a href=\"javascript:window.history.go(-2)\">here</a> to go back to YourNextRead</p>
57
58 <p>www.YourNextRead.com</p>
59
60 </body>
61 </html>";
62
63
64 function convert_utf8($str){
65 if(!seems_utf8($str))
66 return mb_convert_encoding($str, 'UTF-8');
67 return $str;
68 }
69 function seems_utf8($Str) {
70 for ($i=0; $i<strlen($Str); $i++) {
71 if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
72 elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
73 elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
74 elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
75 elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
76 elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
77 else return false; # Does not match any model
78 for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
79 if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
80 return false;
81 }
82 }
83 return true;
84 }
85 ?>
86
87
88