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

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