From db4135d1477dab1821584387eda5b6eef6aa3827 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sun, 27 Mar 2016 16:18:22 +0200 Subject: [PATCH] Remove AmazonProductAPI class. --- Changelog | 3 + libs/AmazonProductAPI.php | 305 -------------------------------------- newznab/MiscSorter.php | 1 - 3 files changed, 3 insertions(+), 306 deletions(-) delete mode 100644 libs/AmazonProductAPI.php diff --git a/Changelog b/Changelog index eab2750f8..ec1b41c00 100755 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +2016-03-27 DariusIII + * Upd: Remove unused AmazonProductAPI class. + + Upd: Remove commented out AmazonProductAPI usage from MiscSorter class. 2016-03-23 DariusIII * Upd: Update scripts to handle the new dev branch * Fix: Fix Undefined index isadmin on profile pages. diff --git a/libs/AmazonProductAPI.php b/libs/AmazonProductAPI.php deleted file mode 100644 index f5c10616c..000000000 --- a/libs/AmazonProductAPI.php +++ /dev/null @@ -1,305 +0,0 @@ -public_key = (string) $pubk; - $this->private_key = (string) $privk; - $this->associate_tag = (string) $asstag; - } - - /** - * Check if the xml received from Amazon is valid - * - * @param mixed $response xml response to check - * - * @return bool false if the xml is invalid - * @throws Exception - */ - private function verifyXmlResponse($response) - { - if ($response === False) - { - throw new Exception("Could not connect to Amazon"); - } - else - { - if (isset($response->Items->Item->ItemAttributes->Title)) - { - return ($response); - } - else - { - throw new Exception("Invalid xml response."); - } - } - } - - - /** - * Query Amazon with the issued parameters - * - * @param array $parameters parameters to query around - * @return simpleXmlObject xml query response - */ - private function queryAmazon($parameters) - { - return aws_signed_request("com", $parameters, $this->public_key, $this->private_key, $this->associate_tag); - } - - - /** - * Return details of products searched by various types - * - * @param string $search search term - * @param string $category search category - * @param string $searchType type of search - * @return mixed simpleXML object - */ - public function searchProducts($search, $category, $searchType = "UPC", $searchNode="") - { - $allowedTypes = array("UPC", "TITLE", "ARTIST", "KEYWORD", "NODE"); - $allowedCategories = array("Music", "DVD", "VideoGames", "MP3Downloads"); - - switch($searchType) - { - case "UPC" : $parameters = array("Operation" => "ItemLookup", - "ItemId" => $search, - "SearchIndex" => $category, - "IdType" => "UPC", - "ResponseGroup" => "Medium"); - break; - - case "TITLE" : $parameters = array("Operation" => "ItemSearch", - //"Title" => $search, - "Keywords" => $search, - "SearchIndex" => $category, - "ResponseGroup" => "Large"); - break; - - //same as TITLE but add BrowseNodeID param - case "NODE" : $parameters = array("Operation" => "ItemSearch", - //"Title" => $search, - "Keywords" => $search, - "SearchIndex" => $category, - "BrowseNode" => $searchNode, - "ResponseGroup" => "Large"); - break; - - } - - $xml_response = $this->queryAmazon($parameters); - - return $this->verifyXmlResponse($xml_response); - - } - - - /** - * Return details of a product searched by UPC - * - * @param int $upc_code UPC code of the product to search - * @param string $product_type type of the product - * @return mixed simpleXML object - */ - public function getItemByUpc($upc_code, $product_type) - { - $parameters = array("Operation" => "ItemLookup", - "ItemId" => $upc_code, - "SearchIndex" => $product_type, - "IdType" => "UPC", - "ResponseGroup" => "Medium"); - - $xml_response = $this->queryAmazon($parameters); - - return $this->verifyXmlResponse($xml_response); - - } - - - /** - * Return details of a product searched by ASIN - * - * @param int $asin_code ASIN code of the product to search - * @return mixed simpleXML object - */ - public function getItemByAsin($asin_code) - { - $parameters = array("Operation" => "ItemLookup", - "ItemId" => $asin_code, - "ResponseGroup" => "Medium"); - - $xml_response = $this->queryAmazon($parameters); - - return $this->verifyXmlResponse($xml_response); - } - - - /** - * Return details of a product searched by keyword - * - * @param string $keyword keyword to search - * @param string $product_type type of the product - * @return mixed simpleXML object - */ - public function getItemByKeyword($keyword, $product_type) - { - $parameters = array("Operation" => "ItemSearch", - "Keywords" => $keyword, - "SearchIndex" => $product_type); - - $xml_response = $this->queryAmazon($parameters); - - return $this->verifyXmlResponse($xml_response); - } - -} - - -function aws_signed_request($region, $params, $public_key, $private_key, $associate_tag = "") -{ - - $method = "GET"; - $host = "ecs.amazonaws.".$region; // must be in small case - $uri = "/onca/xml"; - - - $params["Service"] = "AWSECommerceService"; - $params["AWSAccessKeyId"] = $public_key; - if ($associate_tag != "") - $params["AssociateTag"] = $associate_tag; - - $params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z"); - $params["Version"] = "2009-03-31"; - - /* The params need to be sorted by the key, as Amazon does this at - their end and then generates the hash of the same. If the params - are not in order then the generated hash will be different thus - failing the authetication process. - */ - ksort($params); - - $canonicalized_query = array(); - - foreach ($params as $param=>$value) - { - $param = str_replace("%7E", "~", rawurlencode($param)); - $value = str_replace("%7E", "~", rawurlencode($value)); - $canonicalized_query[] = $param."=".$value; - } - - $canonicalized_query = implode("&", $canonicalized_query); - - $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query; - - /* calculate the signature using HMAC with SHA256 and base64-encoding. - The 'hash_hmac' function is only available from PHP 5 >= 5.1.2. - */ - $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True)); - - /* encode the signature for the request */ - $signature = str_replace("%7E", "~", rawurlencode($signature)); - - /* create request */ - $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature; - //echo $request;die(); - - /* I prefer using CURL */ - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL,$request); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 15); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); - - $xml_response = curl_exec($ch); - - /* If cURL doesn't work for you, then use the 'file_get_contents' - function as given below. - */ - //$xml_response = file_get_contents($request); - - if ($xml_response === False) - { - return False; - } - else - { - /* parse XML */ - $parsed_xml = @simplexml_load_string($xml_response); - return ($parsed_xml === False) ? False : $parsed_xml; - } -} \ No newline at end of file diff --git a/newznab/MiscSorter.php b/newznab/MiscSorter.php index 8fade62b0..fc9c002c5 100644 --- a/newznab/MiscSorter.php +++ b/newznab/MiscSorter.php @@ -379,7 +379,6 @@ class MiscSorter echo $e->getMessage(); } - //$amazon = new AmazonProductAPI($this->pdo->getSetting('amazonpubkey, $this->pdo->getSetting('amazonprivkey, $this->pdo->getSetting('amazonassociatetag); $amalookup = new Lookup(); $apaiIo = new ApaiIO($conf);