comparison php/read/similar.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 ae1459564f66
comparison
equal deleted inserted replaced
5:55445b456ad0 6:077b0a0a3e6d
1 <?php
2
3 function dbConnect($go)
4 {
5 if($go == 1)
6 {
7 return "../../private/db.php";
8 }
9 else
10 {
11 return "../../../private/db.php";
12 }
13 }
14
15 function addAmazonSimilarBooks($isbn1, $loc, $go)
16 {
17 include dbConnect($go);
18
19 $queryLoc = "CALL getLocation('$loc')"; //"select locname from location where LocID = $loc";
20 $res = mysqli_query($link, $queryLoc) or exit( mysqli_error( $link ));
21 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
22 include dbConnect($go);
23
24 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC);
25 $locale=$rows['locname'];
26
27 $Adefault=array(
28 'language' =>'en', //what language to render the page in
29 'locale' =>$locale, //which server's products? available: ca,de,fr,jp,uk,us
30 'page' =>1,
31 'operation' =>'SimilarityLookup',
32 'searchparameter' =>'ItemId', //what kind of search?
33 'searchparameterdata'=>$isbn1, //what to search for?
34 );
35
36
37 $Aassociates_id=array(
38 'uk' => 'bookwhack-21',
39 'us' => 'your02b-20',
40 'ca' => 'book009-20',
41 'de' => 'book04c-21',
42 'fr' => 'book07f-21',
43 );
44
45 $Aserver=array(
46 'ca' => array(
47 'ext' => 'ca' , //Canadian normal server
48 'nor' => 'http://www.amazon.ca' , //Canadian normal server
49 'xml' => 'http://xml.amazon.com' , //Canadian xml server
50 ),
51 'de' => array(
52 'ext' => 'de' , //German normal server
53 'nor' => 'http://www.amazon.de' , //German normal server
54 'xml' => 'http://xml-eu.amazon.com', //German xml server
55 ),
56 'fr' => array(
57 'ext' => 'fr' , //French normal server
58 'nor' => 'http://www.amazon.fr' , //French normal server
59 'xml' => 'http://xml-eu.amazon.com', //French xml server
60 ),
61 'jp' => array(
62 'ext' => 'jp' , //Japanese normal server, not co.jp!
63 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server
64 'xml' => 'http://xml.amazon.com' , //Japanese xml server
65 ),
66 'uk' => array(
67 'ext' => 'co.uk' , //UK normal server
68 'nor' => 'http://www.amazon.co.uk' , //UK normal server
69 'xml' => 'http://xml-eu.amazon.com', //UK xml server
70 ),
71 'us' => array(
72 'ext' => 'com' , //USA normal server
73 'nor' => 'http://www.amazon.com' , //USA normal server
74 'xml' => 'http://xml.amazon.com' , //USA xml server
75 ),
76 );
77
78 include "aws_signed_request.php";
79 $public_key ="AKIAJBXEHTNCU6LLFNIA";
80 $private_key="Dgyv7aR6uGe3OtY95Dj6hHpDS/UEtyboMWpJchYA";
81
82 //for all parameters see if the user has overruled it or use the default
83 foreach ($Adefault as $i=>$d) {
84 $$i=isset($_GET[$i])?$_GET[$i]:$d;
85 }
86
87 $parameters=array(
88 'Operation' =>$operation ,
89 //'Keywords' =>urlencode($search) ,
90 //'SearchIndex' =>$searchindex , //Books for example.
91 "$searchparameter"=>$searchparameterdata ,
92 'ItemPage' =>$page , //which page?
93 'AssociateTag' =>$Aassociates_id[$locale],
94 'ResponseGroup' =>'Small' , //Small, Medium, Large or SellerListing, Similarities
95 'Availability'=>'Available',
96 );
97
98 $ext=$Aserver[$locale]['ext'];
99
100 $url=aws_signed_request($ext,$parameters,$public_key,$private_key);
101 //echo $url;
102
103 $crl = curl_init();
104 $timeout = 5;
105 curl_setopt ($crl, CURLOPT_URL,$url);
106 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
107 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
108 $ret = curl_exec($crl);
109 curl_close($crl);
110 //echo $ret;
111
112 $xml = new SimpleXMLElement($ret);
113
114 //$isbn1 = $xml->Items->Request->SimilarityLookupRequest->ItemId;
115 //echo $isbn1;
116
117 $result = "";
118 for($i=0;$i<sizeof($xml->Items->Item);$i++){
119 foreach($xml->Items->Item[$i]->ASIN as $isbn2){
120 // echo $isbn2;
121
122 $group = $xml->Items->Item[$i]->ItemAttributes->ProductGroup;
123
124 //foreach one of these, create a new request to check whether its a book.
125 //if it is then add it to the return (or add it to the database)
126 if($group == 'Book')
127 {
128 $query1 = "CALL b_getLinkID('$isbn1', '$isbn2', $loc)"; // "select ScoreID from scoretable where BookID1 = '$isbn1' and BookID2 = '$isbn2' and LocID = $loc";
129 //echo $query1;
130 $data1 = mysqli_query($link, $query1) or exit( mysqli_error( $link ));
131 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
132 include dbConnect($go);
133
134 if ( mysqli_num_rows( $data1 ) < 1 )
135 {
136 $queryL = "CALL b_addNewLink('$isbn1','$isbn2',0,$loc)";
137 //echo $queryL;
138 $results1 = mysqli_query($link, $queryL);
139
140 $rows=mysqli_fetch_array($results1, MYSQLI_ASSOC);
141 $linkid=$rows['LinkID'];
142
143 //reset connection
144 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
145 include dbConnect($go);
146
147 //$scoreQuery = "CALL b_insertTempScore('$isbn1','$isbn2',$loc,$linkid,0)";
148 //echo $scoreQuery;
149 //$scoreFinal = mysqli_query($link, $scoreQuery);
150 $result .= "<type>0</type>";
151 $result .= "<isbn>" . $isbn2 . "</isbn>";
152 $result .= "<linkID>" . trim($linkid) . "</linkID>";
153 }
154 }
155 }
156 }
157
158 return $result;
159 }
160
161 ?>