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

Documentation generated on Mon, 11 Mar 2019 15:46:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.