Services_Amazon
[ class tree: Services_Amazon ] [ index: Services_Amazon ] [ all elements ]

Source for file amazon_ecs4_itemsearch.php

Documentation is available at amazon_ecs4_itemsearch.php

  1. <?php
  2. //
  3. // Example of usage for Services_AmazonECS4
  4. //
  5. // * VERY IMPORTANT *
  6. // YOU NEED TO CHANGE THE SUBSCRIPTION ID TO SOMETHING OTHER THEN XXXXXXXXXX
  7. // YOU ALSO SHOULD CHANGE THE ASSOSCIATE ID TO YOUR OWN
  8. // * VERY IMPORTANT *
  9.  
  10. require_once 'PEAR.php';
  11. require_once 'Services/AmazonECS4.php';
  12.  
  13. // An Amazon Subscription ID
  14. $subid 'XXXXXXXXXX';
  15. // An Amazon Associate ID
  16. $associd '';
  17.  
  18. function safestripslashes($value)
  19. {
  20.     return get_magic_quotes_gpc(stripslashes($value$value;
  21. }
  22.  
  23. function report_error($msg)
  24. {
  25.     echo "<p><i>{$msg}</i><p></body></html>";
  26.     exit();
  27. }
  28.  
  29. echo <<<EOT
  30. <html>
  31. <head>
  32.     <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
  33.     <title>Services_AmazonECS4 example - ItemSearch Operation</title>
  34. </head>
  35. <body>
  36. <h1>Services_AmazonECS4 example - ItemSearch Operation</h1>
  37. <p>
  38. <a href="http://www.amazon.com/gp/aws/sdk/" target="_blank">Amazon.com Help: Documentation</a><br />
  39. <a href="http://www.amazon.com/gp/aws/sdk/main.html/?s=AWSEcommerceService&v=2005-07-26&p=ApiReference/ItemSearchOperation" target="_blank">Amazon ECS4.0 API Reference - ItemSearch Operation</a>
  40. </p>
  41. EOT;
  42.  
  43. if ($_GET{
  44.     foreach ($_GET as $k => $v{
  45.         if (!is_array($v)) {
  46.             $cleaned[$khtmlspecialchars(safestripslashes($v));
  47.         }
  48.     }
  49. }
  50.  
  51. echo <<< EOT
  52. <form action="{$_SERVER['PHP_SELF']}" method="get">
  53. <table border="0">
  54. <tr>
  55.     <td>
  56.     Locale
  57.     <select name="locale">
  58. EOT;
  59.  
  60. $locales = array('US''UK''DE''JP''FR''CA');
  61. foreach($locales as $v{
  62.     echo '<option value="' $v ($v == $_GET['locale''" selected="selected"' '''">' $v '</option>';
  63. }
  64.  
  65. echo <<< EOT
  66.     </select>
  67.     <td>
  68. </tr>
  69. <tr>
  70.     <td>
  71.     Search Index <select name="SearchIndex">
  72. EOT;
  73.  
  74. // The list of all available search indexes can be found on the
  75. // "Amazon ECS API Reference - Search Index Values"
  76. // (http://www.amazon.com/gp/aws/sdk/main.html/?s=AWSEcommerceService&v=2005-07-26&p=ApiReference/SearchIndexValues).
  77. $search_indexes = array('Apparel''Baby''Beauty''Books''Classical''DigitalMusic',
  78.                         'DVD''Electronics''ForeignBooks''GourmetFood''HealthPersonalCare',
  79.                         'HomeGarden''Jewelry''Kitchen''Magazines''Merchants',
  80.                         'Miscellaneous''Music''MusicalInstruments''MusicTracks',
  81.                         'OfficeProducts''OutdoorLiving''PCHardware''PetSupplies',
  82.                         'Photo''Restaurants''Software''SoftwareVideoGames',
  83.                         'SportingGoods''Tools''Toys''VHS''Video''VideoGames',
  84.                         'Wireless''WirelessAccessories''Blended');
  85. foreach($search_indexes as $v{
  86.     echo '<option value="' $v ($v == $_GET['SearchIndex''" selected="selected"' '''">' $v '</option>';
  87. }
  88.  
  89. echo <<< EOT
  90.     </select>
  91.     </td>
  92. </tr>
  93. <tr>
  94.     <td>Keywords <input type="text" name="Keywords" value="{$cleaned['Keywords']}" /></td>
  95. </tr>
  96. <tr>
  97.     <td>
  98.     <table border="0">
  99.     <tr>
  100.         <td>Title<br/><input type="text" name="Title" value="{$cleaned['Title']}" /></td>
  101.         <td>Artist<br/><input type="text" name="Artist" value="{$cleaned['Artist']}" /></td>
  102.         <td>Author<br/><input type="text" name="Author" value="{$cleaned['Author']}" /></td>
  103.         <td>Actor<br/><input type="text" name="Actor" value="{$cleaned['Actor']}" /></td>
  104.     </tr>
  105.     <tr>
  106.         <td>Director<br/><input type="text" name="Director" value="{$cleaned['Director']}" /></td>
  107.         <td>Manufacturer<br/><input type="text" name="Manufacturer" value="{$cleaned['Manufacturer']}" /></td>
  108.         <td>MusicLabel<br/><input type="text" name="MusicLabel" value="{$cleaned['MusicLabel']}" /></td>
  109.         <td>Composer<br/><input type="text" name="Composer" value="{$cleaned['Composer']}" /></td>
  110.     </tr>
  111.     <tr>
  112.         <td>Publisher<br/><input type="text" name="Publisher" value="{$cleaned['Publisher']}" /></td>
  113.         <td>Brand<br/><input type="text" name="Brand" value="{$cleaned['Brand']}" /></td>
  114.         <td>Conductor<br/><input type="text" name="Conductor" value="{$cleaned['Conductor']}" /></td>
  115.         <td>Orchestra<br/><input type="text" name="Orchestra" value="{$cleaned['Orchestra']}" /></td>
  116.     </tr>
  117.     </table>
  118.     </td>
  119. </tr>
  120. <tr>
  121.     <td>Power <input type="text" name="Power" value="{$cleaned['Power']}" size="80" /></td>
  122. </tr>
  123. <tr>
  124.     <td>BrowseNode <input type="text" name="BrowseNode" value="{$cleaned['BrowseNode']}" /></td>
  125. </tr>
  126. <tr>
  127.     <td>AudienceRating <input type="text" name="AudienceRating" value="{$cleaned['AudienceRating']}" /></td>
  128. </tr>
  129. <tr>
  130.     <td>
  131.     TextStream <br/>
  132.     <textarea name="TextStream" cols="64" rows="4">{$cleaned['TextStream']}</textarea>
  133.     </td>
  134. </tr>
  135. <tr>
  136.     <td>ItemPage <input type="text" name="ItemPage" value="{$cleaned['ItemPage']}" /></td>
  137. </tr>
  138. <tr>
  139.     <td>Sort <input type="text" name="Sort" value="{$cleaned['Sort']}" /></td>
  140. </tr>
  141. <tr>
  142.     <td>MinimumPrice <input type="text" name="MinimumPrice" value="{$cleaned['MinimumPrice']}" /></td>
  143. </tr>
  144. <tr>
  145.     <td>MaximumPrice <input type="text" name="MaximumPrice" value="{$cleaned['MaximumPrice']}" /></td>
  146. </tr>
  147. <tr>
  148.     <td>
  149.     Condition
  150.     <select name="Condition">
  151. EOT;
  152.  
  153. $conditions = array('''New''All''Used''Refurbished''Collectible');
  154.  
  155. foreach ($conditions as $v{
  156.     echo '<option value="' $v ($v == $_GET['Condition''" selected="selected"' '''">' $v '</option>';
  157. }
  158.  
  159. echo <<< EOT
  160.     </select>
  161.     </td>
  162. </tr>
  163. <tr>
  164.     <td>
  165.     ResponseGroup<br/>
  166. EOT;
  167.  
  168. $response_groups = array('Request''ItemIds''Small''Medium''Large''OfferFull''Offers',
  169.                          'OfferSummary''Variations''VariationMinimum''VariationSummary',
  170.                          'ItemAttributes''Tracks''Accessories''EditorialReview',
  171.                          'SalesRank''BrowseNodes''Images''Similarities''ListmaniaLists',
  172.                          'SearchBins''Subjects');
  173. $checked_groups is_array($_GET['ResponseGroup']$_GET['ResponseGroup': array($_GET['ResponseGroup']);
  174. foreach ($response_groups as $v{
  175.     echo '<input type="checkbox" name="ResponseGroup[]" value="' $v '" ' (in_array($v$checked_groups'checked="checked"' '''/>' $v ' ';
  176. }
  177.  
  178. echo <<< EOT
  179.     </td>
  180. </tr>
  181. <tr>
  182.     <td><input type="submit" value="Search" /></td>
  183. </tr>
  184. </table>
  185. </form>
  186.  
  187. EOT;
  188.  
  189. // examples
  190. echo <<< EOT
  191. <table border="0">
  192. <tr>
  193.     <td>Examples:</td>
  194.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Books&Keywords=php&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small">Keywords</a></td>
  195.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Books&Keywords=php&ItemPage=2&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Medium">ItemPage</a></td>
  196.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Blended&Keywords=teletubbies&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small">Blended</a></td>
  197.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Books&Power=%28subject%3A+sushi+or+pizza%29+and+pubdate%3A+after+2000&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=ItemAttributes">Power</a></td>
  198.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Electronics&BrowseNode=595046&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small&ResponseGroup%5B%5D=ItemAttributes">BrowseNode</a></td>
  199.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Electronics&BrowseNode=301187&Sort=salesrank&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=ItemAttributes">Sort</a></td>
  200.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Books&Keywords=programming&MinimumPrice=5000&MaximumPrice=10000&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small&ResponseGroup%5B%5D=OfferSummary">Price</a></td>
  201.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=DVD&AudienceRating=PG-13&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=ItemAttributes">AudienceRating</a></td>
  202. </tr>
  203. </table>
  204.  
  205. <hr/>
  206. EOT;
  207.  
  208. if (!$_GET{
  209.     echo '</body></html>';
  210.     exit();
  211. }
  212.  
  213. $amazon = new Services_AmazonECS4($subid$associd);
  214.  
  215. if (isset($_GET['locale'])) {
  216.     $result $amazon->setLocale($_GET['locale']);
  217.     if (PEAR::isError($result)) {
  218.         report_error('Invalid locale');
  219.     }
  220. }
  221.  
  222. // ItemSearch
  223. $search_index $_GET['SearchIndex'];
  224. $options = array();
  225. $options['ResponseGroup'is_array($_GET['ResponseGroup']implode(','$_GET['ResponseGroup']$_GET['ResponseGroup'];
  226. $accepted_options = array('Keywords''Title''Artist''Author''Actor''Director',
  227.                           'Manufacturer''MusicLabel''Composer''Publisher''Brand',
  228.                           'Conductor''Orchestra''Power''BrowseNode''AudienceRating',
  229.                           'TextStream''ItemPage''Sort''MinimumPrice''MaximumPrice''Condition');
  230. foreach ($_GET as $k => $v{
  231.     if (!empty($v&& in_array($k$accepted_options)) {
  232.         $options[$k$v;
  233.     }
  234. }
  235.  
  236. $result $amazon->ItemSearch($search_index$options);
  237.  
  238. $lasturl $amazon->getLastUrl();
  239. echo '<p>REST request:<br/>';
  240. echo '<a href="' htmlspecialchars($lasturl'" target="_blank">' .
  241.       ereg_replace('&amp;''<br/>&amp;'htmlspecialchars($lasturl)) '</a></p>';
  242.  
  243. if (PEAR::isError($result)) {
  244.     echo '<p>Error:<br/>';
  245.     echo htmlspecialchars($result->message);
  246.     echo '</p>';
  247. else {
  248.     echo '<p>Processing Time: ' $amazon->getProcessingTime('sec</p>';
  249.     echo '<p>Result:';
  250.     var_dump($result);
  251.     echo '</p>';
  252. }
  253.  
  254. echo '</body></html>';
  255.  
  256. ?>

Documentation generated on Mon, 11 Mar 2019 14:12:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.