array('3198031' => 'Video Games', '2206275011' => 'Home & Garden', '667823011' => 'Electronics', '917972' => 'Movies & TV', '916522' => 'Livres', '916520' => 'Books', '916514' => 'Music', '3198021' => 'Software', '2242989011' => 'Sports & Outdoors', '916518' => 'Video'), 'cn' => array('42692071' => 'Baby', '80207071' => 'Appliances', '647070051' => 'Toys', '658390051' => 'Books', '746776051' => 'Beauty', '754386051' => 'Music', '755653051' => 'Photo', '816482051' => 'Jewelry', '836312051' => 'Sports & Outdoors', '852803051' => 'Health & Personal Care', '863872051' => 'Software', '897415051' => 'Video Games', '899280051' => 'Miscellaneous', '1947899051' => 'Automotive', '1952920051' => 'Home Improvement', '1953164051' => 'Watches', '2016116051' => 'Electronics', '2016126051' => 'Home & Garden', '2016136051' => 'Video', '2016156051' => 'Apparel', '2029189051' => 'Shoes', '2127215051' => 'Grocery', '2127221051' => 'Office Products', ), 'de' => array('186606' => 'Books', '78191031' => 'Automotive', '77028031' => 'Clothing & Accessories', '355007011' => 'Baby Products', '340843031' => 'Computer & Accessories', '80084031' => 'DIY', '213083031' => 'Lighting', '284266' => 'Movies & TV', '64187031' => 'Health & Personal Care', '530484031' => 'Kindle Store', '3167641' => 'Home & Kitchen', '908823031' => 'Appliances', '52044011' => 'Foreign Language Books', '10925031' => 'Garden', '300992' => 'Video Games', '301927' => 'Software', '340852031' => 'Pet Supplies', '562066' => 'Electronics & Photo', '16435051' => 'Sports & Leisure', '77195031' => 'MP3 Downloads', '255882' => 'Music', '340849031' => 'Musical Instruments', '84230031' => 'Beauty', '355006011' => 'Shoes & Handbags', '12950651' => 'Toys', '327472011' => 'Jewelry', '193707031' => 'Watches', '1161658' => 'Magazines'), 'es' => array('599370031' => 'Electronics', '818936031' => 'Kindle Store', '599379031' => 'Movies & TV', '599376031' => 'Software', '599364031' => 'Books', '599373031' => 'Music', '599382031' => 'Video Games', '599367031' => 'Foreign Language Books'), 'fr' => array('193710031' => 'Jewelry', '52042011' => 'Foreign Language Books', '672108031' => 'Kindle Store', '215934031' => 'Shoes', '57004031' => 'Video Games', '206617031' => 'Baby Products', '908826031' => 'Appliances', '197861031' => 'Health & Personal Care', '340858031' => 'Computers', '13921051' => 'Electronics', '340861031' => 'Music Instruments', '322086011' => 'Toys', '301061' => 'Books', '60649031' => 'Watches', '530488' => 'Software', '197858031' => 'Beauty', '325614031' => 'Sports & Leisure', '77196031' => 'MP3 Downloads', '405322' => 'Video', '340855031' => 'Clothing & Accessories'), 'it' => array('524015031' => 'Home & Kitchen', '412606031' => 'Movies & TV', '523997031' => 'Toys', '412609031' => 'Electronics', '818937031' => 'Kindle Store', '635016031' => 'Gardens & Gardening', '411663031' => 'Books', '433842031' => 'Foreign Language Books', '524009031' => 'Watches', '412600031' => 'Music', '524006031' => 'Shoes', '412612031' => 'Software', '524012031' => 'Sports & Leisure', '412603031' => 'Video Games'), 'jp' => array('465610' => 'Books', '561972' => 'Video', '562002' => 'DVD', '562032' => 'Classical', '637630' => 'Software', '637872' => 'Video Games', '3210991' => 'Electronics', '3839151' => 'Kitchen', '11965861' => 'Musical Instruments', '13331821' => 'Baby', '14315361' => 'Sporting Goods', '52391051' => 'Beauty', '57239051' => 'Grocery', '85896051' => 'Jewelry', '161669011' => 'Health & Personal Care', '361299011' => 'Clothing & Accessories', '388316011' => 'Foreign Language Books', '2016926051' => 'Shoes', '2017304051' => 'Automotive', '2128134051' => 'MP3 Downloads'), 'uk' => array('65801031' => 'Health & Personal Care', '117332031' => 'Beauty', '560798' => 'Electronics & Photo', '59624031' => 'Baby Products', '248877031' => 'Automotive', '83450031' => 'Clothing', '266239' => 'Books', '79903031' => 'DIY & Tools', '341677031' => 'Kindle Store', '3146281' => 'Home & Garden', '283920' => 'Video', '340834031' => 'Grocery', '193716031' => 'Jewellery', '77197031' => 'MP3 Downloads', '908798031' => 'Large Appliances', '229816' => 'Music', '340831031' => 'Computer & Accessories', '340837031' => 'Musical Instruments & DJ', '300703' => 'PC & Video Games', '340840031' => 'Pet Supplies', '318949011' => 'Sports & Leisure', '355005011' => 'Shoes & Accessories', '468292' => 'Toys & Games', '328228011' => 'Watches', '300435' => 'Software', ), 'us' => array('2619525011' => 'Appliances', '2617941011' => 'Arts, Crafts & Sewing', '283155' => 'Books', '172282' => 'Electronics', '2238192011' => 'Gift Cards', '3760901' => 'Health & Personal Care', '228013' => 'Home Improvement', '3367581' => 'Jewelry', '284507' => 'Kitchen & Dining', '5174' => 'Music', '2972638011' => 'Patio, Lawn & Garden', '377110011' => 'Watches', ) ); $locale_endpoints = array( 'ca' => 'http://ecs.amazonaws.ca/onca/xml', 'cn' => 'http://webservices.amazon.cn/onca/xml', 'de' => 'http://ecs.amazonaws.de/onca/xml', 'es' => 'http://webservices.amazon.es/onca/xml', 'fr' => 'http://ecs.amazonaws.fr/onca/xml', 'it' => 'http://webservices.amazon.it/onca/xml', 'jp' => 'http://ecs.amazonaws.jp/onca/xml', 'uk' => 'http://ecs.amazonaws.co.uk/onca/xml', 'us' => 'http://webservices.amazon.com/onca/xml' ); function item_search($keywords, $search_index, $searchBNID, $item_page, $accessKeyID, $secretKey, $associate_tag, $response_group, $currentTimeStamp, $locale) { # $query_parameters = array( # 'AssociateTag' => $associate_tag, # 'Condition' => 'All', # 'ItemPage' => $item_page, # 'Keywords' => urlencode($keywords), # 'MerchantId' => 'All', # 'BrowseNode' => $searchBNID, # 'Operation' => 'ItemSearch', # 'Availability' => 'Available', # 'MinimumPrice' => '001', # 'ResponseGroup' => 'OfferFull,ItemAttributes,SalesRank', # 'SearchIndex' => $search_index, ); global $locale_endpoints; $urlLocale = (array)$locale_endpoints[$locale]; $nodeURLwork = $urlLocale[0] . "?Service=AWSECommerceService&AWSAccessKeyId=" . $accessKeyID . "&AssociateTag=" . $associate_tag . "&Operation=ItemSearch&BrowseNode=" . $searchBNID . "&Condition=All" . "&ItemPage=" . $item_page . "&Keywords='" . $keywords . "'&MerchantId=All" . "&Availability=Available" . "&MinimumPrice=001" . "&SearchIndex=" . $search_index . "&ResponseGroup=" . $response_group . "&Timestamp=" . $currentTimeStamp; $nodeURL = signAmazonUrl($nodeURLwork, $secretKey); $nodeURL = rtrim($nodeURL); $nodeURLresponse = @file_get_contents($nodeURL); if (count($nodeURLresponse) == 0) return ""; $nodeURLresponse = xml2array($nodeURLresponse); return $nodeURLresponse; } function get_locale_browse_node_indexes($locale) { global $locale_browse_node_indexes; $indexes = (array)$locale_browse_node_indexes[$locale]; asort($indexes); return $indexes; } function signAmazonUrl($url, $secret_key) { $original_url = $url; $url = urldecode($url); $urlparts = parse_url($url); foreach (split('&', $urlparts['query']) as $part) { if (strpos($part, '=')) { list($name, $value) = split('=', $part, 2); } else { $name = $part; $value = ''; } $params[$name] = $value; } if (empty($params['Timestamp'])) { $params['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z'); } ksort($params); $canonical = ''; foreach ($params as $key => $val) { $canonical .= "$key=".rawurlencode(utf8_encode($val))."&"; } $canonical = preg_replace("/&$/", '', $canonical); $canonical = str_replace(array(' ', '+', ',', ';'), array('%20', '%2B', urlencode(','), urlencode(';')), $canonical); $string_to_sign = "GET\n{$urlparts['host']}\n{$urlparts['path']}\n$canonical"; $signature = base64_encode(hash_hmac('sha256', $string_to_sign, $secret_key, true)); $url = "{$urlparts['scheme']}://{$urlparts['host']}{$urlparts['path']}?$canonical&Signature=".rawurlencode($signature); return $url; } function xml2array($contents, $get_attributes=1, $priority = 'tag') { if(!$contents) return array(); if(!function_exists('xml_parser_create')) { //print "'xml_parser_create()' function not found!"; return array(); } //Get the XML parser of PHP - PHP must have this module for the parser to work $parser = xml_parser_create(''); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, trim($contents), $xml_values); xml_parser_free($parser); if(!$xml_values) return;//Hmm... //Initializations $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; //Refference //Go through the tags. $repeated_tag_index = array();//Multiple tags with same name will be turned into an array foreach($xml_values as $data) { unset($attributes,$value);//Remove existing values, or there will be trouble //This command will extract these variables into the foreach scope // tag(string), type(string), level(int), attributes(array). extract($data);//We could use the array by itself, but this cooler. $result = array(); $attributes_data = array(); if(isset($value)) { if($priority == 'tag') $result = $value; else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode } //Set the attributes too. if(isset($attributes) and $get_attributes) { foreach($attributes as $attr => $val) { if($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' } } //See tag status and do the needed. if($type == "open") {//The starting of the tag '' $parent[$level-1] = &$current; if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag $current[$tag] = $result; if($attributes_data) $current[$tag. '_attr'] = $attributes_data; $repeated_tag_index[$tag.'_'.$level] = 1; $current = &$current[$tag]; } else { //There was another element with the same tag name if(isset($current[$tag][0])) {//If there is a 0th element it is already an array $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; $repeated_tag_index[$tag.'_'.$level]++; } else {//This section will make the value an array if multiple tags with the same name appear together $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array $repeated_tag_index[$tag.'_'.$level] = 2; if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } } $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1; $current = &$current[$tag][$last_item_index]; } } elseif($type == "complete") { //Tags that ends in 1 line '' //See if the key is already taken. if(!isset($current[$tag])) { //New Key $current[$tag] = $result; $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data; } else { //If taken, put all things inside a list(array) if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array... // ...push the new element into that array. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; if($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } $repeated_tag_index[$tag.'_'.$level]++; } else { //If it is not an array... $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $get_attributes) { if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } if($attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } } $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken } } } elseif($type == 'close') { //End of tag '' $current = &$parent[$level-1]; } } return($xml_array); } ?>