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

Source for file amazon_example1.php

Documentation is available at amazon_example1.php

  1. <?php
  2. //
  3. // Example of usage for Services_Amazon_ECS4
  4. //
  5. // * VERY IMPORTANT *
  6. // YOU NEED TO CHANGE THE DEVELOPERS TOKEN 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/Amazon.php';
  12.  
  13. echo <<<EOT
  14. <html>
  15. <head>
  16.     <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
  17.     <title>Services_Amazon example</title>
  18. </head>
  19. <body>
  20. EOT;
  21.  
  22. if(substr(Services_Amazon::getApiVersion()01!= 1{
  23.     echo 'This script was written to work with Services_Amazon 1 API';
  24.     exit();
  25. }
  26.  
  27. $amazon   &new Services_Amazon('XXXXXXXXXX''catdevnull-20');
  28. $products = null;
  29. $message  'No Results';
  30. $keyword  '';
  31.  
  32. if(isset($_GET['keyword']&& isset($_GET['mode'])) {
  33.     $mode $_GET['mode'];
  34.     if(empty($mode)) {
  35.         $mode = null;
  36.     }
  37.     
  38.     $page = 1;
  39.     if(isset($_GET['page'])) {
  40.         $page $_GET['page'];
  41.     }
  42.     
  43.     if(empty($_GET['keyword'])) {
  44.         $message 'Must search for something.';
  45.     else {
  46.         $keyword  $_GET['keyword'];
  47.         $products $amazon->searchKeyword($keyword$mode$page);
  48.  
  49.         if(PEAR::isError($products)) {
  50.             $message  $products->message;
  51.             $products = null;
  52.         }
  53.     }
  54. }
  55.  
  56. $modes Services_Amazon::getModes();
  57.  
  58. echo <<< EOT
  59. <form action="{$_SERVER['PHP_SELF']}" method="get">
  60. <table border="0">
  61. <tr>
  62.     <td>
  63.     <select name="mode">
  64. EOT;
  65.  
  66. foreach($modes as $mode => $name{
  67.     echo '<option value="' $mode ($mode == $_GET['mode''" selected="selected"' '''">' htmlentities($name'</option>';
  68. }
  69.  
  70. echo <<< EOT
  71.     </select>
  72.     </td>
  73.     <td><input type="text" name="keyword" value="$keyword" /></td>
  74.     <td><input type="submit" value="Search" /></td>
  75. </table>
  76. </form>
  77.  
  78. <table border="0">
  79. EOT;
  80.  
  81. if(!is_null($products)) {
  82.     $pages $products['pages'];
  83.     $page  $products['page'];
  84.     unset($products['pages']);
  85.     unset($products['page']);
  86.     
  87.     if($pages != 1{
  88.         echo '<tr><td colspan="2">';
  89.         if($page != 1{
  90.             if(is_null($mode)) {
  91.                 $mode '';
  92.             }
  93.             echo '<a href="' $_SERVER['PHP_SELF''?mode=' $_GET['mode''&keyword=' $_GET['keyword''&page=' ($page - 1.  '">&laquo; Previous Page</a> ';
  94.         }
  95.         echo 'Page ' $page ' of ' $pages '';
  96.         if($page != $pages{
  97.             if(is_null($mode)) {
  98.                 $mode '';
  99.             }
  100.             echo ' <a href="' $_SERVER['PHP_SELF''?mode=' $_GET['mode''&keyword=' $_GET['keyword''&page=' ($page + 1.  '">Next Page &raquo;</a>';
  101.         }
  102.         echo '</td></tr>';
  103.     }
  104.     
  105.     foreach($products as $product{
  106.         $creator '';
  107.         if(is_array($product['authors'])) {
  108.             $creator 'by ' implode(', '$product['authors']);
  109.         elseif(is_array($product['artists'])) {
  110.             $creator 'by ' implode(', '$product['artists']);        
  111.         }
  112.         
  113.         $price '';
  114.         if($product['listprice'!= $product['ourprice']{
  115.             $price '<strike>' $product['listprice''</strike> ' $product['ourprice'];
  116.         else {
  117.             $price $product['listprice'];
  118.         }
  119.         
  120.         echo <<<EOT
  121. <tr>
  122.     <td valign="top"><a href="{$product['url']}"><img src="{$product['imagesmall']}" border="0" alt="" /></a></td>
  123.     <td valign="top">
  124.     <b>{$product['name']}</b> $creator<br />
  125.     Category: {$product['type']}<br />
  126.     Release Date: {$product['release']}<br />
  127.     Price: $price<br />
  128.     Manufacturer: {$product['manufacturer']}<br />
  129.     ASIN: {$product['asin']}
  130.     </td>
  131. </tr>
  132. EOT;
  133.     }
  134.     
  135.     if($pages != 1{
  136.         echo '<tr><td colspan="2">';
  137.         if($page != 1{
  138.             if(is_null($mode)) {
  139.                 $mode '';
  140.             }
  141.             echo '<a href="' $_SERVER['PHP_SELF''?mode=' $_GET['mode''&keyword=' $_GET['keyword''&page=' ($page - 1.  '">&laquo; Previous Page</a> ';
  142.         }
  143.         echo 'Page ' $page ' of ' $pages '';
  144.         if($page != $pages{
  145.             if(is_null($mode)) {
  146.                 $mode '';
  147.             }
  148.             echo ' <a href="' $_SERVER['PHP_SELF''?mode=' $_GET['mode''&keyword=' $_GET['keyword''&page=' ($page + 1.  '">Next Page &raquo;</a>';
  149.         }
  150.         echo '</td></tr>';
  151.     }
  152. else {
  153.     echo '<tr><td><i>' $message '</i></td></tr>';
  154. }
  155.  
  156. echo <<< EOT
  157. </table>
  158. </body>
  159. </html>
  160. EOT;
  161. ?>

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