static function fetchAmazonInfosForBookRest($book, $amazon_version = '2011-08-01') { global $booklibrary_configuration, $my, $acl; //****************************** Added by OrdaSoft ********************************** $param_ws = mosBooklibraryWS::getWsParamById($book->informationFrom); if ($param_ws == "COM") { $endpoint = "http://ecs.amazonaws.com/onca/xml"; } else { if ($param_ws == "UK") { $endpoint = "http://ecs.amazonaws.co.uk/onca/xml"; } else { if ($param_ws == "CA") { $endpoint = "http://ecs.amazonaws.ca/onca/xml"; } else { if ($param_ws == "DE") { $endpoint = "http://ecs.amazonaws.de/onca/xml"; } else { if ($param_ws == "JP") { $endpoint = "http://ecs.amazonaws.jp/onca/xml"; } else { if ($param_ws == "FR") { $endpoint = "http://ecs.amazonaws.fr/onca/xml"; } else { if ($param_ws == "ES") { $endpoint = "http://webservices.amazon.es/onca/xml"; } else { if ($param_ws == "IT") { $endpoint = "http://webservices.amazon.it/onca/xml"; } else { if ($param_ws == "CN") { $endpoint = "http://webservices.amazon.cn/onca/xml"; } else { if ($param_ws == "IN") { $endpoint = "http://webservices.amazon.in/onca/xml"; } else { if ($param_ws == "BR") { $endpoint = "http://webservices.amazon.com.br/onca/xml"; } else { if ($param_ws == "US") { $endpoint = "http://webservices.amazon.com/onca/xml"; } } } } } } } } } } } } if ($booklibrary_configuration['ws']['amazon']['secret_key'] == "") { $secret_key = "ooTVCJy06UNXeMujmlyso9Wj4VD1flgEPsCx5HYY"; } else { $secret_key = $booklibrary_configuration['ws']['amazon']['secret_key']; } $request = "{$endpoint}?" . "Service=AWSECommerceService" . "&Operation=ItemLookup" . "&Condition=All" . "&Version={$amazon_version}" . "&AWSAccessKeyId=" . $booklibrary_configuration['ws']['amazon']['devtag'] . "&AssociateTag=" . $booklibrary_configuration['ws']['amazon']['tag'] . "&SearchIndex=Books" . "&ResponseGroup=Large" . "&IdType=ISBN" . "&ItemId={$book->isbn}"; // Get a nice array of elements to work with $uri_elements = parse_url($request); // Grab our request elements $request = $uri_elements['query']; // Throw them into an array parse_str($request, $parameters); // Add the new required paramters $parameters['Timestamp'] = gmdate("Y-m-d\\TH:i:s\\Z"); $parameters['Version'] = $amazon_version; // The new authentication requirements need the keys to be sorted ksort($parameters); // Create our new request foreach ($parameters as $parameter => $value) { // We need to be sure we properly encode the value of our parameter $parameter = str_replace("%7E", "~", rawurlencode($parameter)); $value = str_replace("%7E", "~", rawurlencode($value)); $request_array[] = $parameter . '=' . $value; } // Put our & symbol at the beginning of each of our request variables and put it in a string $new_request = implode('&', $request_array); // Create our signature string $signature_string = "GET\n{$uri_elements['host']}\n{$uri_elements['path']}\n{$new_request}"; if (function_exists("hash_hmac")) { $signature = urlencode(base64_encode(hash_hmac('sha256', $signature_string, $secret_key, true))); } elseif (function_exists("mhash")) { $signature = urlencode(base64_encode(mhash(MHASH_SHA256, $signature_string, $secret_key))); } // Create our signature using hash_hmac // new request $request = "http://{$uri_elements['host']}{$uri_elements['path']}?{$new_request}&Signature={$signature}"; // Load the call and capture the document returned by the Shopping API // if((int)ini_get('allow_url_fopen')==1) // $result = simplexml_load_file($request); // else // { // $retVal = "Error: variable 'allow_url_fopen' in php.ini set 'Off'. Fetch information require this variable On"; // return $retVal; // } $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $request); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0'); // grab URL and pass it to the browser $result = curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); $result = simplexml_load_string($result); //echo '<pre>';var_dump($result); echo '</pre>';exit; //Errors test -- 1 if (array_key_exists('Errors', $result->OperationRequest)) { $retVal = "faultcode: {$result->OperationRequest->Errors->Error->Code}, faultstring: {$result->OperationRequest->Errors->Error->Message}"; return $retVal; } //Errors test -- 2 if (array_key_exists('Errors', $result->Items->Request)) { $retVal = "faultcode: {$result->Items->Request->Errors->Error->Code}, faultstring: {$result->Items->Request->Errors->Error->Message}"; return $retVal; } //Body -- Output in joomla form //ProductName $book->title = (string) $result->Items->Item->ItemAttributes->Title; //ImageUrlMedium $book->imageURL = (string) $result->Items->Item->MediumImage->URL; //URL $book->URL = (string) $result->Items->Item->DetailPageURL; //Number Of Pages $book->numberOfPages = (int) $result->Items->Item->ItemAttributes->NumberOfPages; //Manufacturer if (array_key_exists('Manufacturer', $result->Items->Item->ItemAttributes)) { $book->manufacturer = (string) $result->Items->Item->ItemAttributes->Manufacturer; } //Author $i = 0; $book->authors = ""; foreach ($result->Items->Item->ItemAttributes->Author as $item) { if ($i > 0) { $book->authors .= ', '; } $book->authors .= $item; $i++; } //Rating // if (array_key_exists('CustomerReviews', $result->Items->Item)) { // $book->rating = (string)($result->Items->Item->CustomerReviews->AverageRating * 2); // } //PublicationDate if (array_key_exists('PublicationDate', $result->Items->Item->ItemAttributes)) { $book->release_Date = (string) $result->Items->Item->ItemAttributes->PublicationDate; } //ReleaseDate if (array_key_exists('ReleaseDate', $result->Items->Item->ItemAttributes)) { $book->release_Date = (string) $result->Items->Item->ItemAttributes->ReleaseDate; } //Edition if (array_key_exists('Edition', $result->Items->Item->ItemAttributes)) { $book->edition = (string) $result->Items->Item->ItemAttributes->Edition; } //Price no partner if (array_key_exists('Offer', $result->Items->Item->Offers) && array_key_exists('FormattedPrice', $result->Items->Item->Offers->Offer->OfferListing->Price)) { $book->price = substr_replace((string) $result->Items->Item->Offers->Offer->OfferListing->Price->Amount, '.', -2, 0); $book->priceunit = (string) $result->Items->Item->Offers->Offer->OfferListing->Price->CurrencyCode; $mas = $book->price; //$mas = ereg_replace("\xC2\xA3", "GBP ", $mas); //for funt //$mas = ereg_replace("\xEF\xBF\xA5", "JPY", $mas); //for ena $book->price = $mas; } else { $book->price = "Does not exist anymore!"; } //echo '<pre>';var_dump($book);echo '</pre>';exit; //************************ begin add for Book Description ********************* if ($booklibrary_configuration['merge_description']['use']) { if (checkAccessBL($booklibrary_configuration['merge_description']['registrationlevel'], 'RECURSE', userGID_BL($my->id), $acl)) { $book->comment = $book->comment . "<br /><p></p> "; } else { $book->comment = ""; } } else { $book->comment = ""; } if ($result->Items->Item->EditorialReviews->EditorialReview) { foreach ($result->Items->Item->EditorialReviews->EditorialReview as $item) { $book->comment .= "<strong>" . $item->Source . "</strong><br />"; $book->comment .= $item->Content . "<br />"; } } //************************ end add for Book Description ************************ return $book; }