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

Source for file aq.php

Documentation is available at aq.php

  1. <?php
  2. /**
  3. * This file contains the class used to query AWS.
  4. *
  5. * This is the only file that should be included when adding amazOOP to a PHP script.
  6. *
  7. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  8. * @copyright 2004 (c) Mauricio Diaz Orlich
  9. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  10. * @version 0.3
  11. *
  12. * @package amazOOP
  13. */
  14.  
  15. /**
  16. * For security, only this file should be included in your scripts.
  17. * @access private
  18. */
  19. define('_AMAZOOP', true);
  20.  
  21. $core_path = dirname(__FILE__) . '/';
  22.  
  23. if(!is_dir($core_path))
  24. $core_path = './';
  25. elseif($core_path && !preg_match('/\/$/', $core_path))
  26. $core_path .= '/';
  27.  
  28. $allowsettimelimit = function_exists('set_time_limit');
  29. $allowgetimagesize = function_exists('getimagesize');
  30.  
  31. define('CORE_PATH', $core_path);
  32.  
  33. /**
  34. * By inserting this document, all required functions as well as user preferences
  35. * from other files (e.g. {@link userdata.inc.php}) are included to be used here.
  36. * @access private
  37. */
  38. require_once(CORE_PATH . "aq.lib.php");
  39.  
  40. /**
  41. * The AmazonQuery class is the software's main class.
  42. *
  43. * It is through this class that amazOOP connects to
  44. * {@link http://www.amazon.com/gp/browse.html/?node=3434641 Amazon Web Services} to obtain product
  45. * information, make searches, etc. This class is also in charge of creating objects
  46. * out of {@link http://www.amazon.com/gp/browse.html/?node=3434641 AWS} responses
  47. * and handles the cache.
  48. *
  49. * An {@link AmazonQuery} object can be used for {@tutorial manual.isbn.pkg lite} searches, using
  50. * {@link liteQuery()}, {@tutorial manual.asin.pkg heavy} searches, using {@link heavyQuery()}, or
  51. * queries to a {@tutorial manual.cart.pkg Remote Shopping Cart}, using one of the functions for this
  52. * purpose ({@link newCart()}, {@link addToCart()}, {@link modifyCart}, {@link removeFromCart()},
  53. * {@link clearCart()} and {@link getCart()}).
  54. *
  55. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  56. * @copyright 2004 (c) Mauricio Diaz Orlich
  57. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  58. * @version 0.3
  59. *
  60. * @package amazOOP
  61. */
  62. class AmazonQuery{
  63.  
  64. /**
  65. * Creates a new object ready to query {@link http://www.amazon.com/gp/browse.html/?node=3434641 AWS}.
  66. *
  67. * An {@link AmazonQuery} object can be used for {@tutorial manual.isbn.pkg lite} searches, using
  68. * {@link liteQuery()}, {@tutorial manual.asin.pkg heavy} searches, using {@link heavyQuery()}, or
  69. * queries to a {@tutorial manual.cart.pkg Remote Shopping Cart}, using one of the functions for this
  70. * purpose ({@link newCart()}, {@link addToCart()}, {@link modifyCart}, {@link removeFromCart()},
  71. * {@link clearCart()} and {@link getCart()}).
  72. *
  73. * @return AmazonQuery
  74. */
  75. function AmazonQuery(){
  76.  
  77. }
  78.  
  79. /**
  80. * Queries an {@tutorial advanced.categories.pkg amazOOP category} for all its products.
  81. *
  82. * <b>Example:</b>
  83. * <code>
  84. * $books = $aq->getCategory("books", "uk");
  85. *
  86. * for($i = 1; $book = $books->getDetails($i); $i++){
  87. * echo $book->getProductName() . "<br>";
  88. *
  89. * echo $book->getAuthors(2) . "<br>";
  90. * }
  91. * </code>
  92. *
  93. * @param string $category the category you want to search. Read {@tutorial advanced.categories.pkg}
  94. * amazOOP category} to learn all about amazOOP categories and how to customize them.
  95. *
  96. * @param string $locale determines what Amazon site should be queried. Valid values are:
  97. * - "us": queries the Amazon.com catalog
  98. * - "uk": queries the Amazon.co.uk catalog
  99. * - "jp": queries the Amazon.co.jp catalog
  100. * - "de": queries the Amazon.de catalog
  101. *
  102. * @param string $type "lite" or "heavy", determines how much information you
  103. * want from AWS.
  104. * For more information on what type of information each type of request returns, take a look
  105. * at {@link LiteDetails} and {@link HeavyDetails}.
  106. *
  107. * @param integer $page indicates the page of results you want. Each page contains 10 results.
  108. *
  109. * @param string $sort indicates what parameter determines the sorting of results. Available sort
  110. * types are described in document {@tutorial manual.sort.pkg}.
  111. *
  112. * @return ProductInfo a {@link ProductInfo} object containing zero or more results returned by AWS.
  113. *
  114. * @see ProductInfo
  115. *
  116. * @tutorial advanced.categories.pkg
  117. * @tutorial manual.sort.pkg
  118. * @tutorial manual.search.pkg
  119. *
  120. */
  121. function getCategory($category = "books", $locale = "us", $type = "lite", $page = 1, $sort = "Bestselling"){
  122. // Obtain the node number based on the specified $category
  123. $node = getBrowseNode($locale, $category);
  124.  
  125. // Query AWS
  126. return $this->query($node, "BrowseNode", $category, $locale, $type, $page, $sort);
  127. }
  128.  
  129. /**
  130. * Queries an AWS Browse Node, that has not been specified as an {@tutorial advanced.categories.pkg amazOOP category}
  131. * for all its products.
  132. *
  133. * @param integer $bn the browse node you want to search.
  134. * Read the {@tutorial advanced.browsenodes.pkg tutorial on Browse Nodes} to learn all about AWS
  135. * browse nodes.
  136. *
  137. * @param string $mode when requesting products from a browse node, you have to specify a "mode". You should
  138. * read the {@tutorial advanced.browsenodes.pkg tutorial on Browse Nodes} to learn more about modes.
  139. *
  140. * @param string $locale determines what Amazon site should be queried. Valid locales are:
  141. * - "us": queries the Amazon.com catalog
  142. * - "uk": queries the Amazon.co.uk catalog
  143. * - "jp": queries the Amazon.co.jp catalog
  144. * - "de": queries the Amazon.de catalog
  145. *
  146. * @param string $type "lite" or "heavy", determines how much information you want from AWS.
  147. * For more information on what type of information each type of request returns, take a look
  148. * at {@link LiteDetails} and {@link HeavyDetails}.
  149. *
  150. * @param integer $page indicates the page of results you want. Each page contains 10 results.
  151. *
  152. * @param string $sort indicates what parameter determines the sorting of results. Available sort
  153. * types are described in document {@tutorial manual.sort.pkg}.
  154. *
  155. * @return ProductInfo a {@link ProductInfo} object containing zero or more results returned by AWS.
  156. *
  157. * @see ProductInfo
  158. *
  159. * @tutorial advanced.browsenodes.pkg
  160. * @tutorial advanced.categories.pkg
  161. * @tutorial manual.sort.pkg
  162. * @tutorial manual.search.pkg
  163. */
  164. function getBrowseNode($bn, $mode, $locale = "us", $type = "lite", $page = 1, $sort = "Bestselling"){
  165. // Query AWS
  166. return $this->query($bn, "BrowseNode", $mode, $locale, $type, $page, $sort);
  167. }
  168.  
  169. /**
  170. * Queries AWS as instructed.
  171. *
  172. * This is the "low-level" method used to query AWS. Methods such as {@link getCategory()},
  173. * {@link getBrowseNode()}, {@link liteQuery()}, or {@link heavyQuery()}, all call this method.
  174. * As a matter of fact, you should rather use one of the aforementioned methods unless you feel
  175. * quite confortable with amazOOP.
  176. *
  177. * @param string $keywords the use of this paramater may vary depending of the type of search
  178. * you are making: for a BrowseNode search, it would refer to the desired BrowseNode, in the
  179. * case of an ASIN serach, it would refer to the desired ASIN, and so on...
  180. *
  181. * @param string $searchType one of the search types offered by AWS. Refer to the document
  182. * {@tutorial manual.search.pkg} for a list of valid search types.
  183. *
  184. * @param string $mode one of the modes proposed by AWS. Read the document
  185. * {@tutorial advanced.browsenodes.pkg} for an explanation of modes.
  186. *
  187. * @param string $locale determines what Amazon site should be queried. Valid locales are:
  188. * - "us": queries the Amazon.com catalog
  189. * - "uk": queries the Amazon.co.uk catalog
  190. * - "jp": queries the Amazon.co.jp catalog
  191. * - "de": queries the Amazon.de catalog
  192. *
  193. * @param string $type "lite" or "heavy", determines how much information you want from AWS.
  194. *
  195. * @param integer $page indicates the page of results you want. Each page contains 10 results.
  196. *
  197. * @param string $sort indicates what parameter determines the sorting of results. Available sort
  198. * types are described in document {@tutorial manual.sort.pkg}.
  199. *
  200. * @return mixed This function can return one of the following three types, depending on the query
  201. * made:
  202. * - {@link ProductInfo}: this is returned by most types of queries. This object contains zero
  203. * or more {@link LiteDetails} or {@link HeavyDetails} objects, depending on the $type requested. For more
  204. * information on what types of queries return {@link ProductInfo} objects, read the tutorial
  205. * {@tutorial manual.search.pkg}.
  206. * - {@link BlendedSearch}: only Blended searches return this type of object. Each {@link BlendedSearch}
  207. * object contains zero or more {@link ProductInfo} objects. For more information about Blended searches
  208. * read the tutorial {@tutorial manual.search.pkg}.
  209. * - {@link ShoppingCart}: returned when interacting with a Remote Shopping Cart. Read the tutorial
  210. * {@tutorial manual.cart.pkg} for more information about Remote Shoppng Carts.
  211. *
  212. * @see ProductInfo
  213. * @see BlendedSearch
  214. * @see ShoppingCart
  215. *
  216. * @tutorial manual.search.pkg
  217. * @tutorial manual.sort.pkg
  218. * @tutorial advanced.browsenodes.pkg
  219. * @tutorial advanced.categories.pkg
  220. */
  221. function query($keywords, $searchType, $mode = "books", $locale = "us", $type = "lite", $page = 1, $sort = "Bestselling"){
  222. global $_AMAZOOP_SEARCH_TYPES, $_AMAZOOP_SORTING, $_AMAZOOP_SITES;
  223.  
  224. $start_time = explode(" ", microtime());
  225. $start_time = $start_time[1] + $start_time[0];
  226.  
  227. $cached = false;
  228. $cacheDate = "day";
  229.  
  230. // If someone sent blank strings as parameters, recover default values
  231. if($mode == "")
  232. $mode = "books";
  233. if($type == "")
  234. $type = "lite";
  235. if($page == "")
  236. $page = 1;
  237. if($sort == "")
  238. $sort = "Bestselling";
  239. if($locale == "")
  240. $locale = "us";
  241.  
  242. // If there's no information about available sorting types for this mode
  243. // use default type (i.e. Bestselling), otherwise use specified type
  244. //-if(!isset($modes[$locale][$mode]))
  245. if(!getMode($locale, $mode))
  246. $sortType = "+salesrank";
  247. else{
  248. //-if(!isset($sorting[$modes[$locale][$mode]]) || !isset($sorting[$modes[$locale][$mode]][$sort])){
  249. if(!isset($_AMAZOOP_SORTING[getMode($locale, $mode)]) || !isset($_AMAZOOP_SORTING[getMode($locale, $mode)][$sort])){
  250. if(isset($_AMAZOOP_SORTING['all'][$sort]))
  251. $sortType = $_AMAZOOP_SORTING['all'][$sort];
  252. else
  253. $sortType = "+salesrank";
  254. }
  255. else
  256. $sortType = $_AMAZOOP_SORTING[getMode($locale, $mode)][$sort];
  257. }
  258.  
  259. // build a request to send to AWS using provided data
  260. $request = $_AMAZOOP_SITES[$locale];
  261. $request .= "&t=" . getAssociateID($locale);
  262. $request .= "&dev-t=" . _AMAZOOP_DEV_TOKEN;
  263. $request .= "&" . $_AMAZOOP_SEARCH_TYPES[$searchType] ."=";
  264. $request .= rawurlencode($keywords);
  265. $request .= "&type=" . $type;
  266. $request .= "&sort=" . $sortType;
  267. if($mode != "all"){
  268. if($this->getRequestMode($mode, $searchType, $locale))
  269. $request .= $this->getRequestMode($mode, $searchType, $locale);
  270. else
  271. $request .= "&mode=$mode";
  272. }
  273. $request .= "&page=" . $page;
  274. //$request .= "&offer=All";
  275. //$request .= "&variations=yes";
  276.  
  277. // If this query exists in cache, use the cached version
  278. if($cachedResult = $this->verifyQueryInCache(rawurlencode($keywords) . "," . $_AMAZOOP_SEARCH_TYPES[$searchType] . "," . $mode . "," . $type . "," . $page . "," . $sortType . "," . $locale)){
  279. //echo "I got it in cache<br>";
  280. $result = $cachedResult;
  281. $cached = true;
  282. }
  283. // Otherwise,
  284. else{
  285. // Create a new AmazonParser to parse AWS info
  286. $amazonParser = new AmazonParser();
  287.  
  288. // Parse request and obtain new object based on AWS response
  289. $result = $amazonParser->parse($request, $type);
  290.  
  291. unset($amazonParser);
  292. }
  293.  
  294. // If for some reason parsing failed, try again...
  295. //while(!is_object($result))
  296. // $result = $amazonParser->parse($request, $type);
  297. if(!$result || !is_object($result)){
  298. $error = "Amazon did not return data when queried for: ";
  299. $error .= $request;
  300. $error .= "; I will try again";
  301. trigger_error($error);
  302. sleep(1);
  303. $amazonParser = new AmazonParser();
  304. $result = $amazonParser->parse($request, $type);
  305. }
  306. else if(isset($result->errorMsg) && $result->errorMsg == "We%20encountered%20an%20error%20processing%20your%20request.%20Please%20retry."){
  307. $error = "Data was obtained from Amazon, but contained an error: ";
  308. $error .= rawurldecode($result->errorMsg);
  309. $error .= "; request was: " . $request;
  310. if(method_exists($result, 'requestArgument'))
  311. $error .= "; and Request ID was: " . rawurldecode($result->requestArgument('RequestId'));
  312. trigger_error($error);
  313. sleep(1);
  314. $amazonParser = new AmazonParser();
  315. $result = $amazonParser->parse($request, $type);
  316. }
  317.  
  318. if(!$result || !is_object($result) ||
  319. (isset($result->errorMsg) && $result->errorMsg == "We%20encountered%20an%20error%20processing%20your%20request.%20Please%20retry.")){
  320. trigger_error("Nothing was obtained from Amazon, will try to use cached data");
  321. if($temp = $this->verifyQueryInCache(rawurlencode($keywords) . "," . $_AMAZOOP_SEARCH_TYPES[$searchType] . "," . $mode . "," . $type . "," . $page . "," . $sortType . "," . $locale, 'week')){
  322. $result = $temp;
  323. $cached = true;
  324. $cacheDate = 'week';
  325. }
  326. }
  327. else{
  328. $cacheDate = 'hour';
  329. // Cache the new result you got
  330. if(!$cached){
  331. $signature = rawurlencode($keywords) . "," . $_AMAZOOP_SEARCH_TYPES[$searchType] . "," . $mode . "," . $type . "," . $page . "," . $sortType . "," . $locale;
  332. $this->makeFile($result, $signature);
  333. }
  334. }
  335.  
  336. $this->removeOldEntries(getAmazoopConfig('cache_directory'), $cacheDate);
  337.  
  338.  
  339. $log = array();
  340. if($cached)
  341. $log[] = "From cache: " . $request;
  342. else
  343. $log[] = "Requested: " . $request;
  344. if($result->requestArgument('REQUESTID'))
  345. $log[] = "Request ID: " . trim($result->requestArgument('REQUESTID'));
  346. $log[] = "Remote IP: " . $_SERVER["REMOTE_ADDR"];
  347. if(isset($_SERVER["HTTP_USER_AGENT"]))
  348. $log[] = "User Agent: " . $_SERVER["HTTP_USER_AGENT"];
  349.  
  350. $end_time = explode (" ", microtime());
  351. $end_time = $end_time[1] + $end_time[0];
  352.  
  353. $log[] = "Query completed in: " . number_format (1000*($end_time - $start_time), 2) . " milliseconds";
  354. logRequest($log);
  355.  
  356. // Done! Return the object containing AWS result
  357. return $result;
  358. }
  359.  
  360. /**
  361. * Makes a "lite" request to AWS.
  362. *
  363. * Products obtained from a lite request are stored in objects of type {@link LiteDetails}, and
  364. * can contain all the attributes defined in this kind of objects, athough this is not necessarily
  365. * the case.
  366. *
  367. * Although this function can return {@link ProductInfo} or {@link BlendedSearch} objects
  368. * based on the kind of search you are doing, these objects will only contain {@link LiteDetails}
  369. * objects, and in no case {@link HeavyDetails} objects.
  370. *
  371. * @param string $keywords the use of this paramater may vary depending of the type of search
  372. * you are making: for a BrowseNode search, it would refer to the desired BrowseNode, in the
  373. * case of an ASIN serach, it would refer to the desired ASIN, and so on...
  374. *
  375. * @param string $searchType one of the search types offered by AWS. Refer to the document
  376. * {@tutorial manual.search.pkg} for a list of valid search types.
  377. *
  378. * @param string $mode an amazOOP category. To learn more about amazOOP categories read the tutorial
  379. * {@tutorial advanced.categories.pkg}.
  380. *
  381. * @param string $locale determines what Amazon site should be queried. Valid locales are:
  382. * - "us": queries the Amazon.com catalog
  383. * - "uk": queries the Amazon.co.uk catalog
  384. * - "jp": queries the Amazon.co.jp catalog
  385. * - "de": queries the Amazon.de catalog
  386. *
  387. * @param integer $page indicates the page of results you want. Each page contains 10 results.
  388. *
  389. * @param string $sort indicates what parameter determines the sorting of results. Available sort
  390. * types are described in document {@tutorial manual.sort.pkg}.
  391. *
  392. * @return mixed This function can return one of the following two types, depending on the query
  393. * made:
  394. * - {@link ProductInfo}: this is returned by most types of queries. This object contains zero
  395. * or more {@link LiteDetails} objects. For more information on what types of queries return
  396. * {@link ProductInfo} objects, read the tutorial {@tutorial manual.search.pkg}.
  397. *
  398. * - {@link BlendedSearch}: only Blended searches return this type of object. Each {@link BlendedSearch}
  399. * object contains zero or more {@link ProductInfo} objects. For more information about Blended searches
  400. * read the tutorial {@tutorial manual.search.pkg}.
  401. *
  402. * @see ProductInfo
  403. * @see BlendedSearch
  404. * @see ShoppingCart
  405. *
  406. * @tutorial manual.isbn.pkg
  407. * @tutorial manual.search.pkg
  408. * @tutorial manual.sort.pkg
  409. * @tutorial advanced.browsenodes.pkg
  410. * @tutorial advanced.categories.pkg
  411. */
  412. function liteQuery($keywords, $searchType, $mode = "books", $locale = "us", $page = 1, $sort = "Bestselling"){
  413. return $this->query($keywords, $searchType, $mode, $locale, "lite", $page, $sort);
  414. }
  415.  
  416. /**
  417. * Makes a "heavy" request to AWS.
  418. *
  419. * Products obtained from a heavy request are stored in objects of type {@link HeavyDetails}, and
  420. * can contain all the attributes defined in this kind of objects, athough this is not necessarily
  421. * the case.
  422. *
  423. * Although this function can return {@link ProductInfo} or {@link BlendedSearch} objects
  424. * based on the kind of search you are doing, these objects will only contain {@link HeavyDetails}
  425. * objects, and in no case {@link LiteDetails} objects.
  426. *
  427. * @param string $keywords the use of this paramater may vary depending of the type of search
  428. * you are making: for a BrowseNode search, it would refer to the desired BrowseNode, in the
  429. * case of an ASIN serach, it would refer to the desired ASIN, and so on...
  430. *
  431. * @param string $searchType one of the search types offered by AWS. Refer to the document
  432. * {@tutorial manual.search.pkg} for a list of valid search types.
  433. *
  434. * @param string $mode an amazOOP category. To learn more about amazOOP categories read the tutorial
  435. * {@tutorial advanced.categories.pkg}.
  436. *
  437. * @param string $locale determines what Amazon site should be queried. Valid locales are:
  438. * - "us": queries the Amazon.com catalog
  439. * - "uk": queries the Amazon.co.uk catalog
  440. * - "jp": queries the Amazon.co.jp catalog
  441. * - "de": queries the Amazon.de catalog
  442. *
  443. * @param integer $page indicates the page of results you want. Each page contains 10 results.
  444. *
  445. * @param string $sort indicates what parameter determines the sorting of results. Available sort
  446. * types are described in document {@tutorial manual.sort.pkg}.
  447. *
  448. * @return mixed This function can return one of the following two types, depending on the query
  449. * made:
  450. * - {@link ProductInfo}: this is returned by most types of queries. This object contains zero
  451. * or more {@link HeavyDetails} objects. For more information on what types of queries return
  452. * {@link ProductInfo} objects, read the tutorial {@tutorial manual.search.pkg}.
  453. *
  454. * - {@link BlendedSearch}: only Blended searches return this type of object. Each {@link BlendedSearch}
  455. * object contains zero or more {@link ProductInfo} objects. For more information about Blended searches
  456. * read the tutorial {@tutorial manual.search.pkg}.
  457. *
  458. * @see ProductInfo
  459. * @see BlendedSearch
  460. * @see ShoppingCart
  461. *
  462. * @tutorial manual.asin.pkg
  463. * @tutorial manual.search.pkg
  464. * @tutorial manual.sort.pkg
  465. * @tutorial advanced.browsenodes.pkg
  466. * @tutorial advanced.categories.pkg
  467. */
  468. function heavyQuery($keywords, $searchType, $mode = "books", $locale = "us", $page = 1, $sort = "Bestselling"){
  469. return $this->query($keywords, $searchType, $mode, $locale, "heavy", $page, $sort);
  470. }
  471.  
  472.  
  473. /**
  474. * Generates an RSS 2.0 feed for a Browse Node from Amazon.
  475. *
  476. * You should read the tutorial
  477. *
  478. * <b>WARNING!!!</b> This is an experimental feature. Use it, tweak it, and send feedback!!!
  479. *
  480. * @param string $browseNode a browse node from Amazon. Not all Amazon browse nodes will return
  481. * information. Take a look at
  482. * {@link http://www.amazon.com/gp/browse.html/ref=sc_bb_l_0/?%5Fencoding=UTF8&node=3434651&no=3435361&me=A36L942TSJ2AJA#browse this document}
  483. * for more info
  484. * @param string $mode one of the modes proposed by AWS. The names were simplified, an array in
  485. * {@link config.inc.php} holds the associations.
  486. * @param string $locale determines what Amazon site should be queried. {@link config.inc.php}
  487. * contains an array of available locales.
  488. *
  489. * @return string The XML document containing the RSS feed.
  490. *
  491. * @link http://www.amazon.com/gp/aws/landing.html AWS SDK
  492. * @link http://backend.userland.com/rss RSS 2.0
  493. *
  494. * @modified 2004-05-21 10:04
  495. */
  496. function rssFeed($browseNode, $mode = "books", $locale = "us", $page = 1){
  497. global $_AMAZOOP_RSS, $_AMAZOOP_SEARCH_TYPES;
  498.  
  499. $searchType = "BrowseNode";
  500. $type = "heavy";
  501. $sortType = "+salesrank";
  502.  
  503. $signature = $browseNode . "," . $_AMAZOOP_SEARCH_TYPES[$searchType] . "," . $mode . "," . $type . "," . $page . "," . $sortType . "," . $locale . ",rss";
  504. $cached = false;
  505. $xml = "";
  506.  
  507. if($cachedResult = $this->verifyQueryInCache($signature, "day", true)){
  508. $xml = $cachedResult;
  509. $cached = true;
  510. }
  511. else{
  512. $itemTag = false;
  513. $item = array();
  514. $res = array();
  515.  
  516. $exten = array( "us" => "com",
  517. "uk" => "co.uk",
  518. "de" => "de",
  519. "fr" => "fr",
  520. "jp" => "co.jp");
  521.  
  522. $amazonURL = "http://www.amazon." . $exten[$locale] . "/exec/obidos/tg/browse/-/". $browseNode;
  523.  
  524. $amazonTitle = "";
  525. $append = false;
  526.  
  527. $ifp = fopen($amazonURL, 'r');
  528.  
  529. while($line = fgets($ifp)){
  530. if(!(strpos($line, "<title>") === false))
  531. $append = true;
  532.  
  533. if($append)
  534. $amazonTitle .= trim($line);
  535.  
  536. if(!(strpos($line, "</title>") === false))
  537. break;
  538. }
  539. fclose($ifp);
  540.  
  541. $amazonTitle = preg_replace("/.*\<title\>/", "", $amazonTitle);
  542. $amazonTitle = preg_replace("/\<\/title\>.*/", "", $amazonTitle);
  543. $amazonTitle = htmlentities($amazonTitle);
  544.  
  545. if($locale == "jp")
  546. $amazonTitle = explode("co.jp", $amazonTitle);
  547. else
  548. $amazonTitle = explode(":", $amazonTitle);
  549.  
  550. $amazonTitle[1] = explode("/", $amazonTitle[1]);
  551.  
  552. $feedTitle = "";
  553. for($i = 0; $i < sizeof($amazonTitle[1]); $i++){
  554. $feedTitle .= $amazonTitle[1][$i];
  555. if($i < sizeof($amazonTitle[1]) - 1)
  556. $feedTitle .= " > ";
  557. }
  558.  
  559. $_AMAZOOP_RSS['title'] .= "Bestselling " . $feedTitle;
  560. $_AMAZOOP_RSS['description'] .= "Bestselling " . $feedTitle . " provided by The Madd0 Mall in association with " . $amazonTitle[0];
  561.  
  562. //$result = $this->query($browseNode, $searchType, $mode, $locale, $type);
  563. $result = $this->getBrowseNode($browseNode, $mode, $locale, $type);
  564.  
  565. $fp = fopen(getAmazoopConfig('XML_template'), 'r');
  566.  
  567. while($line = fgets($fp)){
  568. if(preg_match("/%.*%/", $line)){
  569. $tag = trim(preg_replace("/(%)(.*)(%)/e", "handleTag('$2', \$locale)", $line));
  570. if($tag != "stop" && $tag != "resume" && !$itemTag){
  571. $res[] = $tag;
  572. }
  573. else if($tag == "stop")
  574. $itemTag = !$itemTag;
  575. else if($tag == "resume"){
  576. $itemTag = !$itemTag;
  577. $i = 0;
  578. while($details = $result->getDetails($i)){
  579. foreach($item as $itemTemplate){
  580. if(preg_match("/%.*%/", $itemTemplate)){
  581. $tag = trim(preg_replace("/(%)(.*)(%)/e", "handleTag('$2', \$locale, \$details)", $itemTemplate));
  582. $res[] = $tag;
  583. }
  584. else
  585. $res[] = trim($itemTemplate);
  586. }
  587. $i++;
  588. }
  589. }
  590. else{
  591. $item[] = $line;
  592. }
  593. }
  594. else if(!$itemTag)
  595. $res[] = trim($line);
  596. else
  597. $item[] = $line;
  598. }
  599.  
  600. fclose($fp);
  601.  
  602. foreach($res as $line)
  603. $xml .= $line . "\n";
  604.  
  605. $this->makeFile($xml, $signature, true);
  606. }
  607.  
  608. $this->removeOldEntries(getAmazoopConfig('cache_directory'), 'day');
  609.  
  610. $log = array();
  611. if($cached)
  612. $log[0] = "From cache: ";
  613. else
  614. $log[0] = "Requested: ";
  615. $log[0] .= $signature;
  616. //$log[1] = "Request ID: " . trim($result->request->args['REQUESTID']);
  617. logRequest($log);
  618.  
  619. return $xml;
  620. }
  621.  
  622.  
  623.  
  624. /**
  625. *
  626. * Checks whether the query that is about to be made already exists in the cache.
  627. * If the file exists, it checks whether it is necessary to refresh it or not based
  628. * on the {@link $cacheRefreshTime} specified in {@link config.inc.php}.
  629. * If the query has been made but needs to be refreshed, the file is deleted.
  630. *
  631. * @param string $query a string automatically generated by AmazonQuery with the
  632. * necessary information to verify whether a query has already been made.
  633. * @param string $expDate the time after which the stored information expires.
  634. * Possible values are "hour", "day", "week", "month"
  635. * @param boolean $rss indicates whether the file stored is an RSS feed
  636. *
  637. * @return ProductInfo|BlendedSearch|booleanThis function returns the cached object
  638. * or false if the query is not cached or needs to be refreshed.
  639. *
  640. * @see config.inc.php
  641. *
  642. * @access private
  643. */
  644. function verifyQueryInCache($query, $expDate = "hour", $rss = false){
  645. /**
  646. * These are times you can choose from to keep information in the cache.
  647. * According to AWS license some information can be stored up to 3 months,
  648. * but pricing and availability has to be refreshed hourly. Since to get
  649. * this information you have to get it all anyway, it's better to refresh
  650. * the whole thing hourly.
  651. */
  652. $cacheRefreshTime = array('hour' => 3600,
  653. 'day' => 86400,
  654. 'week' => 604800,
  655. 'month' => 18144000);
  656.  
  657. $cacheDir = getAmazoopConfig('cache_directory');
  658.  
  659. if(getAmazoopConfig('file_separator') == "windows")
  660. $fileSeparator = "\\";
  661. else
  662. $fileSeparator = "/";
  663.  
  664. if(!$rss)
  665. $ext = ".aoc";
  666. else
  667. $ext = ".arc";
  668.  
  669. // Generates the file name
  670. $fileName = $cacheDir . $fileSeparator . md5($query) . $ext;
  671.  
  672. // Checks whether the file exists (i.e. the query has been made)
  673. if(file_exists($fileName)){
  674. // If the query has been made it checks whether it is still valid
  675. if(time() - filectime($fileName) <= $cacheRefreshTime[$expDate]){
  676. // If it is, it opens the file
  677. $fp = fopen($fileName, "r");
  678. // Gets the object's size
  679. $size = (int)fread($fp,5);
  680. // Goes to the end of the object
  681. fseek($fp, $size, SEEK_CUR);
  682. // Reads the query that was stored with the object
  683. $cacheQuery = fread($fp, 1024);
  684.  
  685. // Checks whether it corresponds to the query you are making
  686. if($query == $cacheQuery){
  687. // If it does, it reads the object
  688. fseek($fp, 5);
  689. $object = fread($fp, $size);
  690. // Closes the file
  691. fclose($fp);
  692. // And returns the object
  693. if(!$rss)
  694. return unserialize($object);
  695. else
  696. return $object;
  697. }
  698. else{
  699. // If it doesn't, it closes the file
  700. fclose($fp);
  701. // It deletes it
  702. unlink($fileName);
  703. }
  704. }
  705. else{
  706. // If the file is no longer valid it is deleted
  707. unlink($fileName);
  708. }
  709. }
  710.  
  711. // False is returned, i.e. the query was not cached or was no longer valid
  712. return false;
  713. }
  714.  
  715. /**
  716. * Removes files from cache that are older than {@link $cacheRefreshTime}
  717. *
  718. * @param string $dirPath directory where files should be looked for
  719. * @param string $expDate the time after which the stored information expires.
  720. * Possible values are "hour", "day", "week", "month"
  721. * @param string $ext the extention of the files that should be checked
  722. *
  723. * @access private
  724. */
  725. function removeOldEntries($dirPath, $expDate = 'hour', $ext = ".aoc"){
  726. $cacheRefreshTime = array('hour' => 3600,
  727. 'day' => 86400,
  728. 'week' => 604800,
  729. 'month' => 18144000);
  730.  
  731. if(getAmazoopConfig('file_separator') == "windows")
  732. $fileSeparator = "\\";
  733. else
  734. $fileSeparator = "/";
  735.  
  736. $dir = opendir($dirPath) or
  737. die ("Could not open directory \"" . $dirPath . "\"");
  738. while ($file = readdir($dir))
  739. if ($file != "." && $file != ".." && strstr($file, $ext)){
  740. $completePath = $dirPath . $fileSeparator . trim($file);
  741. if(file_exists($completePath) &&
  742. (time() - filectime($completePath) > $cacheRefreshTime[$expDate]))
  743. unlink($completePath);
  744. }
  745. closedir($dir);
  746. }
  747.  
  748. /**
  749. * Creates a file as follows:
  750. * - 5 bytes containing the size of the serialized object
  751. * - the serialized object
  752. * - the query made to AWS.
  753. *
  754. * @param object $object the object to be stored
  755. * @param string $query a string automatically generated by AmazonQuery with the necessary information
  756. * to verify whether a query has already been made.
  757. * @param boolean $rss indicates whether the file stored is an RSS feed
  758. *
  759. * @access private
  760. */
  761. function makeFile($object, $query, $rss = false){
  762.  
  763. $cacheDir = getAmazoopConfig('cache_directory');
  764.  
  765. if(getAmazoopConfig('file_separator') == "windows")
  766. $fileSeparator = "\\";
  767. else
  768. $fileSeparator = "/";
  769.  
  770. if(!$rss)
  771. $ext = ".aoc";
  772. else
  773. $ext = ".arc";
  774.  
  775. // Creates the file's name by hashing the query
  776. $fileName = $cacheDir . $fileSeparator . md5($query) . $ext;
  777.  
  778. // Creates the new file
  779. $fp = fopen($fileName, "w");
  780.  
  781. if(!$rss)
  782. // Seralizes the object
  783. $string = serialize($object);
  784. else
  785. $string = $object;
  786. // Obtains it size long of 5 bytes
  787. $size = $this->make5Bytes(strlen($string));
  788. // Writes the size
  789. fwrite($fp, $size);
  790. // Writes the object
  791. fwrite($fp, $string);
  792. // Writes th query
  793. fwrite($fp, $query);
  794. // Closes the file
  795. fclose($fp);
  796. }
  797.  
  798. /**
  799. * Adds 0s to the left of $number to make it 5 bytes long
  800. *
  801. * @param integer $number the number to be treated
  802. *
  803. * @return string A number with enough 0 to the left to make it 5 bytes long.
  804. *
  805. * @access private
  806. */
  807. function make5Bytes($number){
  808. if($number < 10)
  809. $number = "0000" . $number;
  810. else if($number < 100)
  811. $number = "000" . $number;
  812. else if($number < 1000)
  813. $number = "00" . $number;
  814. else if($number < 10000)
  815. $number = "0" . $number;
  816. else
  817. $number = "". $number;
  818.  
  819. return $number;
  820. }
  821.  
  822. /**
  823. * Depending on the type of search made, a mode may be needed. Also, certain searches
  824. * don't make sense with certain nodes (e.g. search for an Actor in books) and modes
  825. * have different names in different locales.
  826. *
  827. * This function verifies that the requested amazOOP node makes sense with the requested search
  828. * type and converts it to a proper AWS node.
  829. *
  830. * @param string $currMode the requested mode
  831. * @param string $searchType the requested search
  832. * @param string $locale the locale used
  833. *
  834. * @return string The string tobe appended to the AWS request containing a mode that makes sense
  835. * with the search type used.
  836. *
  837. * @link http://www.amazon.com/gp/aws/landing.html AWS SDK
  838. * @see config.inc.php
  839. *
  840. * @access private
  841. */
  842. function getRequestMode($currMode, $searchType, $locale){
  843. // Changes the amazOOP mode into an AWS mode
  844. if(!($currMode = getMode($locale, $currMode)))
  845. return false;
  846.  
  847. // These search types don't need a mode
  848. if($searchType == "ASIN" || $searchType == "ISBN"
  849. || $searchType == "Blended"
  850. || $searchType == "Power")
  851. // So blank is returned
  852. return "";
  853.  
  854. // These search types make sense with any mode
  855. else if($searchType == "BrowseNode" || $searchType == "Keywords"
  856. || $searchType == "Similarity")
  857. // So it is assumed that the original mode is alright
  858. return "&mode=" . $currMode;
  859.  
  860. // These search type only make sense when looking for books
  861. else if($searchType == "Author" || $searchType == "Publisher"){
  862. if(strpos($currMode, "books") === false)
  863. // So if a movie mode was not selected, the default value is returned
  864. return "&mode=books";
  865. else
  866. // Otherwise return what was requested
  867. return "&mode=" . $currMode;
  868. }
  869.  
  870. // These search types only make sense when lookin for movies
  871. else if($searchType == "Actor" || $searchType == "Director"){
  872. if(strpos($currMode, "dvd") === false &&
  873. strpos($currMode, "vhs") === false &&
  874. strpos($currMode, "video") === false)
  875. // So if a movie mode was not selected, the default value is returned
  876. return "&mode=dvd";
  877. else
  878. // Otherwise return what was requested
  879. return "&mode=" . $currMode;
  880. }
  881.  
  882. // These serach types only make sense when looking in music
  883. else if($searchType == "Artist" || $searchType == "UPC"){
  884. if(strpos($currMode, "music") === false &&
  885. strpos($currMode, "classical") === false)
  886. // So if a music mode was not selected, the default value is returned
  887. return "&mode=music";
  888. else
  889. // Otherwise return what was requested
  890. return "&mode=" . $currMode;
  891. }
  892.  
  893. // These seach type only makes sense in certain modes
  894. else if($searchType == "Manufacturer"){
  895. if(strpos($currMode, "ce") === false &&
  896. strpos($currMode, "electronics") === false &&
  897. strpos($currMode, "kitchen") === false &&
  898. strpos($currMode, "videogames") === false &&
  899. strpos($currMode, "software") === false &&
  900. strpos($currMode, "photo") === false &&
  901. strpos($currMode, "pc-hardware") === false)
  902. // If none of them is selected, the default value is returned
  903. return "&mode=electronics";
  904. else
  905. // Otherwise return what was requested
  906. return "&mode=" . $currMode;
  907. }
  908.  
  909. }
  910.  
  911. /**
  912. * A variant of {@link query()} used specifically to query a
  913. * {@tutorial manual.cart.pkg Remote Shopping Cart}.
  914. *
  915. * Like {@link query()}, this is a "low-level" function, therefore most users will prefer to
  916. * use the {@tutorial manual.cart.pkg Remote Shopping Cart} with {@link newCart()},
  917. * {@link addToCart()}, {@link modifyCart}, {@link removeFromCart()}, {@link clearCart()}
  918. * and {@link getCart()}.
  919. *
  920. * @param string $action The action you want to perform with a Shopping Cart. Valid values are:
  921. * - "add": adds items to a shopping cart, or creates a new shopping cart if none is provided
  922. * - "modify": modifies the quantity of an item in the shopping cart
  923. * - "remove": removes an item from the shopping cart
  924. * - "clear": clears a shopping cart
  925. * - "get": retrieves the items from a shopping cart
  926. *
  927. * @param array $items This can be a simple or a bi-dimensional array. It is simple if you want to
  928. * remove items from a shopping cart, in which case this is simply an array of Item IDs. But it is
  929. * a bi-dimensional array if you want to add or modify items in a shopping cart. In this case each
  930. * item of the array is another array containing an ASIN (if you are adding a product), or an Item ID
  931. * (if you are modifying the cart), and the desired quantity of this product.
  932. *
  933. * @param string $locale The Amazon site in which the cart is stored.
  934. *
  935. * @param string $cartID The Cart ID is the unique identifier for a given shopping cart.
  936. *
  937. * @param string $HMAC The HMAC is a security token that must be passed back to Amazon Web Services
  938. * for using an existing cart. This token is uniquely associated with each cart.
  939. *
  940. * @param boolean $similar If this parameter is set to "true" (default) the {@link ShoppingCart}
  941. * Shopping Cart} will contain a list of ASINs related to the objects it contains.
  942. *
  943. * @return ShoppingCart Unlike {@link query()}, this function only returns objects of type {@link }
  944. * ShoppingCart}. Read the tutorial {@tutorial manual.cart.pkg} for more information about
  945. * Remote Shoppng Carts.
  946. *
  947. * @see ShoppingCart
  948. *
  949. * @tutorial manual.cart.pkg
  950. */
  951. function queryRemoteShoppingCart($action = "get", $items = "", $locale = "us", $cartID = "", $HMAC = "", $similar = true){
  952. global $_AMAZOOP_SEARCH_TYPES, $_AMAZOOP_SITES;
  953.  
  954. $start_time = explode(" ", microtime());
  955. $start_time = $start_time[1] + $start_time[0];
  956.  
  957. // build a request to send to AWS using provided data
  958. $request = $_AMAZOOP_SITES[$locale];
  959. $request .= "&t=" . getAssociateID($locale);
  960. $request .= "&dev-t=" . _AMAZOOP_DEV_TOKEN;
  961. $request .= "&ShoppingCart=" . $action;
  962.  
  963. if($action == "add"){
  964. foreach($items as $item)
  965. $request .= "&Asin." . $item[0] . "=" . $item[1];
  966. }
  967. elseif($action == "modify"){
  968. foreach($items as $item)
  969. $request .= "&Item." . $item[0] . "=" . $item[1];
  970. }
  971. elseif($action == "remove"){
  972. foreach($items as $item)
  973. $request .= "&Item." . $item;
  974. }
  975.  
  976. if($action != "add" && ($cartID == "" || $HMAC == "")){
  977. $error = "You MUST specify a CartID AND a HMAC for any action other than \"add\"";
  978. $error .= "; You tried to \"" . $action . "\"";
  979. trigger_error($error);
  980. return false;
  981. }
  982.  
  983. if($cartID != "")
  984. $request .= "&CartId=" . $cartID;
  985. if($HMAC != "")
  986. $request .= "&Hmac=" . $HMAC;
  987.  
  988. if($similar)
  989. $request .= "&sims=true";
  990.  
  991. // Create a new AmazonParser to parse AWS info
  992. $amazonParser = new AmazonParser();
  993.  
  994. // Parse request and obtain new object based on AWS response
  995. $result = $amazonParser->parse($request);
  996.  
  997. unset($amazonParser);
  998.  
  999.  
  1000. // If for some reason parsing failed, try again...
  1001. //while(!is_object($result))
  1002. // $result = $amazonParser->parse($request, $type);
  1003. if(!$result || !is_object($result)){
  1004. $error = "Amazon did not return data when queried for: ";
  1005. $error .= $request;
  1006. $error .= "; I will try again";
  1007. trigger_error($error);
  1008. sleep(1);
  1009. $amazonParser = new AmazonParser();
  1010. $result = $amazonParser->parse($request);
  1011. }
  1012. elseif($result->getErrorMessage()){
  1013. $error = "Data was obtained from Amazon, but contained an error: ";
  1014. $error .= $result->getErrorMessage();
  1015. $error .= "; request was: " . $request . "; and Request ID was: " . rawurldecode($result->requestArgument('REQUESTID'));
  1016. trigger_error($error);
  1017. sleep(1);
  1018. $amazonParser = new AmazonParser();
  1019. $result = $amazonParser->parse($request);
  1020. }
  1021.  
  1022. $log = array();
  1023. $log[] = "Requested: " . $request;
  1024. if($result)
  1025. $log[] = "Request ID: " . trim($result->requestArgument('RequestId'));
  1026. $log[] = "Remote IP: " . $_SERVER["REMOTE_ADDR"];
  1027. if(isset($_SERVER["HTTP_USER_AGENT"]))
  1028. $log[] = "User Agent: " . $_SERVER["HTTP_USER_AGENT"];
  1029.  
  1030. $end_time = explode (" ", microtime());
  1031. $end_time = $end_time[1] + $end_time[0];
  1032.  
  1033. $log[] = "Query completed in: " . number_format (1000*($end_time - $start_time), 2) . " milliseconds";
  1034. logRequest($log);
  1035.  
  1036. // Done! Return the object containing AWS result
  1037. return $result;
  1038. }
  1039.  
  1040. /**
  1041. * Add an item, or a list of items to an new {@link manual.cart.pkg Remote Shopping Cart}.
  1042. *
  1043. * This function is used to add items to an <i>new</i> Remote Shopping Cart. To add items to an
  1044. * existing shopping cart take a look at {@link addToCart()}.
  1045. *
  1046. * You must recover the new cart's ID and HMAC by using methods {@link ShoppingCart::getCartID()}
  1047. * getCartID()} and {@link ShoppingCart::getHMAC() getHMAC()}, in order to modify it using functions
  1048. * {@link addToCart()}, {@link modifyCart}, {@link removeFromCart()}, {@link clearCart()}
  1049. * and {@link getCart()}.
  1050. *
  1051. * <b>Example:</b>
  1052. * <code>
  1053. * $items = array();
  1054. * $items[] = array("B00005JMEW", 1);
  1055. * $items[] = array("1932273271", 2);
  1056. *
  1057. * $cart = $aq->newCart($items, "jp");
  1058. * </code>
  1059. *
  1060. * @param array $items Each element of this array is another array containing the ASIN of the
  1061. * product you wish to add to the cart in position 0, and the quantity in position 1.
  1062. * As of the writing of this document, only US shopping carts support multiple items.
  1063. *
  1064. * @param string $locale The locale where the Remote Shopping Cart is stored. Valid values
  1065. * are:
  1066. * - "us"
  1067. * - "uk"
  1068. * - "de"
  1069. * - "jp"
  1070. *
  1071. * @param boolean $similar If set to "true", the {@link ShoppingCart} object returned will contain
  1072. * a list of ASINs related to the contents of the cart.
  1073. *
  1074. * @return ShoppingCart A new shopping cart containing the items added.
  1075. */
  1076. function newCart($items, $locale = "us", $similar = true){
  1077. return $this->queryRemoteShoppingCart("add", $items, $locale, "", "", $similar);
  1078. }
  1079.  
  1080. /**
  1081. * Add an item, or a list of items to an existing {@link manual.cart.pkg Remote Shopping Cart}.
  1082. *
  1083. * This function is used to add items to an <i>existing</i> Remote Shopping Cart. To create a new
  1084. * shopping cart take a look at {@link newCart()}.
  1085. *
  1086. * If you do not provide the $cartID and $HMAC parameters, or if these are
  1087. * equal to a blank string, this function behaves exactly like {@link newCart()}.
  1088. *
  1089. * <b>Example:</b>
  1090. * <code>
  1091. * $items = array();
  1092. * $items[] = array("B00005JMEW", 1);
  1093. * $items[] = array("1932273271", 2);
  1094. *
  1095. * $cart = $aq->addToCart($items, "us", $_SESSION['cartID'], $_SESSION['HMAC']);
  1096. * </code>
  1097. *
  1098. * @param array $items Each element of this array is another array containing the ASIN of the
  1099. * product you wish to add to the cart in position 0, and the quantity in position 1.
  1100. * As of the writing of this document, only US shopping carts support multiple items.
  1101. *
  1102. * @param string $locale The locale where the Remote Shopping Cart is stored. Valid values
  1103. * are:
  1104. * - "us"
  1105. * - "uk"
  1106. * - "de"
  1107. * - "jp"
  1108. *
  1109. * @param string $cartID The unique ID of the cart you whish to add items to. You can find the
  1110. * cart ID of a {@link ShoppingCart} object using its {@link ShoppingCart::getCartID() getCartID()} method.
  1111. *
  1112. * @param string $HMAC A unique code associated to a Remote Shopping Cart.You can find the
  1113. * HMAC of a {@link ShoppingCart} object using its {@link ShoppingCart::getHMAC() getHMAC()} method.
  1114. *
  1115. * @param boolean $similar If set to "true", the {@link ShoppingCart} object returned will contain
  1116. * a list of ASINs related to the contents of the cart.
  1117. *
  1118. * @return ShoppingCart A shopping cart containing the items added, plus any other items already
  1119. * in it.
  1120. */
  1121. function addToCart($items, $locale = "us", $cartID = "", $HMAC = "", $similar = true){
  1122. return $this->queryRemoteShoppingCart("add", $items, $locale, $cartID, $HMAC, $similar);
  1123. }
  1124.  
  1125. /**
  1126. * Modifies the quantities of items in an existing {@link manual.cart.pkg Remote Shopping Cart}.
  1127. *
  1128. * This function is used to modify the quantities of items you have <i>already added</i> to a
  1129. * Remote Shopping Cart. To create a add new items to a cart take a look at {@link addToCart()}.
  1130. *
  1131. * You must provide an array of items to be modified. This array must contain Item IDs of products
  1132. * already in the shopping cart, associated with their new quantities.
  1133. *
  1134. * <b>Example:</b>
  1135. * <code>
  1136. * $noOfModItems = $_POST['noOfItems'];
  1137. * $items = array();
  1138. *
  1139. * for($i = 0; $i < $noOfModItems; $i++)
  1140. * $items[] = array($_POST['itemID'.$i], $_POST['qty'.$i]);
  1141. *
  1142. * $cart = $aq->modifyCart($items, "us", $_POST['cartID'], $_POST['HMAC']);
  1143. * </code>
  1144. *
  1145. * @param array $items Each element of this array is another array containing the Item ID of a
  1146. * product in the cart in position 0, and the new quantity in position 1.
  1147. * As of the writing of this document, only US shopping carts support multiple items.
  1148. *
  1149. * @param string $locale The locale where the Remote Shopping Cart is stored. Valid values
  1150. * are:
  1151. * - "us"
  1152. * - "uk"
  1153. * - "de"
  1154. * - "jp"
  1155. *
  1156. * @param string $cartID The unique ID of the cart you whish to add items to. You can find the
  1157. * cart ID of a {@link ShoppingCart} object using its {@link ShoppingCart::getCartID() getCartID()} method.
  1158. *
  1159. * @param string $HMAC A unique code associated to a Remote Shopping Cart.You can find the
  1160. * HMAC of a {@link ShoppingCart} object using its {@link ShoppingCart::getHMAC() getHMAC()} method.
  1161. *
  1162. * @param boolean $similar If set to "true", the {@link ShoppingCart} object returned will contain
  1163. * a list of ASINs related to the contents of the cart.
  1164. *
  1165. * @return ShoppingCart A shopping cart containing the modified items, plus any other items already
  1166. * in it.
  1167. */
  1168. function modifyCart($items, $locale = "us", $cartID = "", $HMAC = "", $similar = true){
  1169. return $this->queryRemoteShoppingCart("modify", $items, $locale, $cartID, $HMAC, $similar);
  1170. }
  1171.  
  1172. /**
  1173. * Removes items from an existing {@link manual.cart.pkg Remote Shopping Cart}.
  1174. *
  1175. * You must provide an array of items to be removed. This array must contain Item IDs of the products
  1176. * you wish to remove from the shopping cart.
  1177. *
  1178. * <b>Example:</b>
  1179. * <code>
  1180. * $items = array();
  1181. *
  1182. * for($i = 0; $i < $_POST['noOfItems']; $i++)
  1183. * $items[] = $_POST['itemID'.$i];
  1184. *
  1185. * $cart = $aq->removeFromCart($items, "us", $_POST['cartID'], $_POST['HMAC']);
  1186. * </code>
  1187. *
  1188. * @param array $items Each element of this array is an Item ID of a
  1189. * product in the cart.
  1190. *
  1191. * @param string $locale The locale where the Remote Shopping Cart is stored. Valid values
  1192. * are:
  1193. * - "us"
  1194. * - "uk"
  1195. * - "de"
  1196. * - "jp"
  1197. *
  1198. * @param string $cartID The unique ID of the cart you whish to add items to. You can find the
  1199. * cart ID of a {@link ShoppingCart} object using its {@link ShoppingCart::getCartID() getCartID()} method.
  1200. *
  1201. * @param string $HMAC A unique code associated to a Remote Shopping Cart.You can find the
  1202. * HMAC of a {@link ShoppingCart} object using its {@link ShoppingCart::getHMAC() getHMAC()} method.
  1203. *
  1204. * @param boolean $similar If set to "true", the {@link ShoppingCart} object returned will contain
  1205. * a list of ASINs related to the contents of the cart.
  1206. *
  1207. * @return ShoppingCart A shopping cart without the removed items.
  1208. */
  1209. function removeFromCart($items, $locale = "us", $cartID = "", $HMAC = "", $similar = true){
  1210. return $this->queryRemoteShoppingCart("remove", $items, $locale, $cartID, $HMAC, $similar);
  1211. }
  1212.  
  1213. /**
  1214. * Retrieve the contents of an existing {@link manual.cart.pkg Remote Shopping Cart}.
  1215. *
  1216. * This function is used to retrieve an <i>existing</i> Remote Shopping Cart. Note that every other
  1217. * action ({@link newCart() new}, {@link addToCart() add}, {@link modifyCart() modify}, {@link }
  1218. * removeFromCart() remove} and {@link clearCart() clear}) will also return the contents from the
  1219. * cart, therefore you only need to use this function if you want to retrieve a cart without mofifying it.
  1220. *
  1221. * <b>Example:</b>
  1222. * <code>
  1223. * $cart = $aq->getCart($_COOKIE['cartID'], $_COOKIE['HMAC'], "de");
  1224. * </code>
  1225. *
  1226. * @param string $cartID The unique ID of the cart you whish to add items to. You can find the
  1227. * cart ID of a {@link ShoppingCart} object using its {@link ShoppingCart::getCartID() getCartID()} method.
  1228. *
  1229. * @param string $HMAC A unique code associated to a Remote Shopping Cart.You can find the
  1230. * HMAC of a {@link ShoppingCart} object using its {@link ShoppingCart::getHMAC() getHMAC()} method.
  1231. *
  1232. * @param string $locale The locale where the Remote Shopping Cart is stored. Valid values
  1233. * are:
  1234. * - "us"
  1235. * - "uk"
  1236. * - "de"
  1237. * - "jp"
  1238. *
  1239. * @param boolean $similar If set to "true", the {@link ShoppingCart} object returned will contain
  1240. * a list of ASINs related to the contents of the cart.
  1241. *
  1242. * @return ShoppingCart A the contents of the requested shopping cart.
  1243. */
  1244. function getCart($cartID, $HMAC, $locale = "us", $similar = true){
  1245. return $this->queryRemoteShoppingCart("get", "", $locale, $cartID, $HMAC, $similar);
  1246. }
  1247.  
  1248. /**
  1249. * Clears a {@tutorial manual.cart.pkg Remote Shopping Cart}.
  1250. *
  1251. * @param string $cartID The unique identifier of the cart you want to clear.
  1252. *
  1253. * @param string $HMAC A unique code associated to the cart ID.
  1254. *
  1255. * @param string $locale The locale where the Remote Shopping Cart is stored. Valid values
  1256. * are:
  1257. * - "us"
  1258. * - "uk"
  1259. * - "de"
  1260. * - "jp"
  1261. *
  1262. * @param boolean $similar If set to "true", the {@link ShoppingCart} object returned will contain
  1263. * a list of ASINs related to the contents of the cart.
  1264. *
  1265. * @return ShoppingCart An empty shopping cart.
  1266. */
  1267. function clearCart($cartID, $HMAC, $locale = "us", $similar = true){
  1268. return $this->queryRemoteShoppingCart("clear", "", $locale, $cartID, $HMAC, $similar);
  1269. }
  1270. }
  1271. ?>
 
Documentation generated on Sat, 21 Aug 2004 17:40:19 +0200 by phpDocumentor 1.3.0RC3
hosted by
SourceForge.net Logo