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. $php_self htmlspecialchars($_SERVER['PHP_SELF']);
  52. echo <<< EOT
  53. <form action="{$php_self}" method="get">
  54. <table border="0">
  55. <tr>
  56.     <td>
  57.     Locale
  58.     <select name="locale">
  59. EOT;
  60.  
  61. $locales = array('US''UK''DE''JP''FR''CA');
  62. foreach($locales as $v{
  63.     echo '<option value="' $v ($v == $_GET['locale''" selected="selected"' '''">' $v '</option>';
  64. }
  65.  
  66. echo <<< EOT
  67.     </select>
  68.     <td>
  69. </tr>
  70. <tr>
  71.     <td>
  72.     Search Index <select name="SearchIndex">
  73. EOT;
  74.  
  75. // The list of all available search indexes can be found on the
  76. // "Amazon ECS API Reference - Search Index Values"
  77. // (http://www.amazon.com/gp/aws/sdk/main.html/?s=AWSEcommerceService&v=2005-07-26&p=ApiReference/SearchIndexValues).
  78. $search_indexes = array('Apparel''Baby''Beauty''Books''Classical''DigitalMusic',
  79.                         'DVD''Electronics''ForeignBooks''GourmetFood''HealthPersonalCare',
  80.                         'HomeGarden''Jewelry''Kitchen''Magazines''Merchants',
  81.                         'Miscellaneous''Music''MusicalInstruments''MusicTracks',
  82.                         'OfficeProducts''OutdoorLiving''PCHardware''PetSupplies',
  83.                         'Photo''Restaurants''Software''SoftwareVideoGames',
  84.                         'SportingGoods''Tools''Toys''VHS''Video''VideoGames',
  85.                         'Wireless''WirelessAccessories''Blended');
  86. foreach($search_indexes as $v{
  87.     echo '<option value="' $v ($v == $_GET['SearchIndex''" selected="selected"' '''">' $v '</option>';
  88. }
  89.  
  90. echo <<< EOT
  91.     </select>
  92.     </td>
  93. </tr>
  94. <tr>
  95.     <td>Keywords <input type="text" name="Keywords" value="{$cleaned['Keywords']}" /></td>
  96. </tr>
  97. <tr>
  98.     <td>
  99.     <table border="0">
  100.     <tr>
  101.         <td>Title<br/><input type="text" name="Title" value="{$cleaned['Title']}" /></td>
  102.         <td>Artist<br/><input type="text" name="Artist" value="{$cleaned['Artist']}" /></td>
  103.         <td>Author<br/><input type="text" name="Author" value="{$cleaned['Author']}" /></td>
  104.         <td>Actor<br/><input type="text" name="Actor" value="{$cleaned['Actor']}" /></td>
  105.     </tr>
  106.     <tr>
  107.         <td>Director<br/><input type="text" name="Director" value="{$cleaned['Director']}" /></td>
  108.         <td>Manufacturer<br/><input type="text" name="Manufacturer" value="{$cleaned['Manufacturer']}" /></td>
  109.         <td>MusicLabel<br/><input type="text" name="MusicLabel" value="{$cleaned['MusicLabel']}" /></td>
  110.         <td>Composer<br/><input type="text" name="Composer" value="{$cleaned['Composer']}" /></td>
  111.     </tr>
  112.     <tr>
  113.         <td>Publisher<br/><input type="text" name="Publisher" value="{$cleaned['Publisher']}" /></td>
  114.         <td>Brand<br/><input type="text" name="Brand" value="{$cleaned['Brand']}" /></td>
  115.         <td>Conductor<br/><input type="text" name="Conductor" value="{$cleaned['Conductor']}" /></td>
  116.         <td>Orchestra<br/><input type="text" name="Orchestra" value="{$cleaned['Orchestra']}" /></td>
  117.     </tr>
  118.     </table>
  119.     </td>
  120. </tr>
  121. <tr>
  122.     <td>Power <input type="text" name="Power" value="{$cleaned['Power']}" size="80" /></td>
  123. </tr>
  124. <tr>
  125.     <td>BrowseNode <input type="text" name="BrowseNode" value="{$cleaned['BrowseNode']}" /></td>
  126. </tr>
  127. <tr>
  128.     <td>AudienceRating <input type="text" name="AudienceRating" value="{$cleaned['AudienceRating']}" /></td>
  129. </tr>
  130. <tr>
  131.     <td>
  132.     TextStream <br/>
  133.     <textarea name="TextStream" cols="64" rows="4">{$cleaned['TextStream']}</textarea>
  134.     </td>
  135. </tr>
  136. <tr>
  137.     <td>ItemPage <input type="text" name="ItemPage" value="{$cleaned['ItemPage']}" /></td>
  138. </tr>
  139. <tr>
  140.     <td>Sort <input type="text" name="Sort" value="{$cleaned['Sort']}" /></td>
  141. </tr>
  142. <tr>
  143.     <td>MinimumPrice <input type="text" name="MinimumPrice" value="{$cleaned['MinimumPrice']}" /></td>
  144. </tr>
  145. <tr>
  146.     <td>MaximumPrice <input type="text" name="MaximumPrice" value="{$cleaned['MaximumPrice']}" /></td>
  147. </tr>
  148. <tr>
  149.     <td>
  150.     Condition
  151.     <select name="Condition">
  152. EOT;
  153.  
  154. $conditions = array('''New''All''Used''Refurbished''Collectible');
  155.  
  156. foreach ($conditions as $v{
  157.     echo '<option value="' $v ($v == $_GET['Condition''" selected="selected"' '''">' $v '</option>';
  158. }
  159.  
  160. echo <<< EOT
  161.     </select>
  162.     </td>
  163. </tr>
  164. <tr>
  165.     <td>
  166.     ResponseGroup<br/>
  167. EOT;
  168.  
  169. $response_groups = array('Request''ItemIds''Small''Medium''Large''OfferFull''Offers',
  170.                          'OfferSummary''Variations''VariationMinimum''VariationSummary',
  171.                          'ItemAttributes''Tracks''Accessories''EditorialReview',
  172.                          'SalesRank''BrowseNodes''Images''Similarities''ListmaniaLists',
  173.                          'SearchBins''Subjects');
  174. $checked_groups is_array($_GET['ResponseGroup']$_GET['ResponseGroup': array($_GET['ResponseGroup']);
  175. foreach ($response_groups as $v{
  176.     echo '<input type="checkbox" name="ResponseGroup[]" value="' $v '" ' (in_array($v$checked_groups'checked="checked"' '''/>' $v ' ';
  177. }
  178.  
  179. echo <<< EOT
  180.     </td>
  181. </tr>
  182. <tr>
  183.     <td><input type="submit" value="Search" /></td>
  184. </tr>
  185. </table>
  186. </form>
  187.  
  188. EOT;
  189.  
  190. // examples
  191. echo <<< EOT
  192. <table border="0">
  193. <tr>
  194.     <td>Examples:</td>
  195.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Books&Keywords=php&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small">Keywords</a></td>
  196.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Books&Keywords=php&ItemPage=2&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Medium">ItemPage</a></td>
  197.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Blended&Keywords=teletubbies&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small">Blended</a></td>
  198.     <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>
  199.     <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>
  200.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=Electronics&BrowseNode=301187&Sort=salesrank&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=ItemAttributes">Sort</a></td>
  201.     <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>
  202.     <td><a href="{$_SERVER['PHP_SELF']}?SearchIndex=DVD&AudienceRating=PG-13&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=ItemAttributes">AudienceRating</a></td>
  203. </tr>
  204. </table>
  205.  
  206. <hr/>
  207. EOT;
  208.  
  209. if (!$_GET{
  210.     echo '</body></html>';
  211.     exit();
  212. }
  213.  
  214. $amazon = new Services_AmazonECS4($subid$associd);
  215.  
  216. if (isset($_GET['locale'])) {
  217.     $result $amazon->setLocale($_GET['locale']);
  218.     if (PEAR::isError($result)) {
  219.         report_error('Invalid locale');
  220.     }
  221. }
  222.  
  223. // ItemSearch
  224. $search_index $_GET['SearchIndex'];
  225. $options = array();
  226. $options['ResponseGroup'is_array($_GET['ResponseGroup']implode(','$_GET['ResponseGroup']$_GET['ResponseGroup'];
  227. $accepted_options = array('Keywords''Title''Artist''Author''Actor''Director',
  228.                           'Manufacturer''MusicLabel''Composer''Publisher''Brand',
  229.                           'Conductor''Orchestra''Power''BrowseNode''AudienceRating',
  230.                           'TextStream''ItemPage''Sort''MinimumPrice''MaximumPrice''Condition');
  231. foreach ($_GET as $k => $v{
  232.     if (!empty($v&& in_array($k$accepted_options)) {
  233.         $options[$k$v;
  234.     }
  235. }
  236.  
  237. $result $amazon->ItemSearch($search_index$options);
  238.  
  239. $lasturl $amazon->getLastUrl();
  240. echo '<p>REST request:<br/>';
  241. echo '<a href="' htmlspecialchars($lasturl'" target="_blank">' .
  242.       ereg_replace('&amp;''<br/>&amp;'htmlspecialchars($lasturl)) '</a></p>';
  243.  
  244. if (PEAR::isError($result)) {
  245.     echo '<p>Error:<br/>';
  246.     echo htmlspecialchars($result->message);
  247.     echo '</p>';
  248. else {
  249.     echo '<p>Processing Time: ' $amazon->getProcessingTime('sec</p>';
  250.     echo '<p>Result:';
  251.     var_dump($result);
  252.     echo '</p>';
  253. }
  254.  
  255. echo '</body></html>';
  256.  
  257. ?>

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