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

Source for file liteDetails.class.php

Documentation is available at liteDetails.class.php

  1. <?php
  2. /**
  3. * This file contains the two classes which store details of products returned by AWS.
  4. *
  5. * The two classes are {@link LiteDetails}, which stores information obtained by making a 'lite'
  6. * request; and {@link HeavyDetails}, which is created when making a 'heavy' request.
  7. *
  8. * Apparently the lite/heavy request types are going to change in AWS4, so this may
  9. * change (drastically?) in future releases.
  10. *
  11. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  12. * @copyright 2004 (c) Mauricio Diaz Orlich
  13. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  14. * @version 0.3RC1
  15. *
  16. * @package amazOOP
  17. * @subpackage Details
  18. */
  19.  
  20. /**
  21. * This file is included because it contains class {@link AmazonItem}, which is
  22. * the parent of class {@link LiteDetails} contained in this file.
  23. * @access private
  24. */
  25. require_once(CORE_PATH . 'item.class.php');
  26.  
  27. /**
  28. * The LiteDetails class is used to store information on products returned when
  29. * doing a lite request to AWS.
  30. *
  31. * All string values are encoded with native PHP function rawurlencode(). But are returned
  32. * decoded by the corresponding accessor methods, which you are encouraged to use.
  33. *
  34. * As of version 0.3RC1 this is a list of the information returned by AWS that is
  35. * supported by amazOOP:
  36. * - <i>Artists</i> of a CD or casset ({@link getArtists()})
  37. * - <i>ASIN</i> of a product ({@link getASIN()})
  38. * - <i>Authors</i> of a book ({@link getAuthors()})
  39. * - Current <i>Availability</i> of a product ({@link getAvailability()})
  40. * - <i>Catalog</i> of a product ({@link getCatalog()})
  41. * - URLs of a <i>Product's image</i> ({@link getImage()})
  42. * - <i>List Price</i> of a product ({@link getListPrice()})
  43. * - <i>Manufacturer</i> of a product ({@link getManufacturer()})
  44. * - <i>Amazon's Price</i> for a product ({@link getOurPrice()})
  45. * - <i>Product's name</i> ({@link getProductName()})
  46. * - <i>Release Date</i> of a product to the market ({@link getReleaseDate()})
  47. * - <i>URL</i> of the product's details page on Amazon ({@link getURL()})
  48. * - Lowest <i>Used Price</i> at Amazon Marketplace. Note, however, that Third Party searches
  49. * are not yet supported by amazOOP. ({@link getUsedPrice()})
  50. * - <i>Merchant ID</i> of a Third Party Seller ({@link getMerchantId()})
  51. *
  52. * @link http://www.amazon.com/gp/aws/landing.html Amazon Web Services SDK
  53. *
  54. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  55. * @copyright 2004 (c) Mauricio Diaz Orlich
  56. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  57. * @version 0.3RC1
  58. *
  59. * @package amazOOP
  60. */
  61. class LiteDetails extends AmazonItem {
  62. /*Do not check for alternative images
  63. Check with product's merchant
  64. Check with other Amazon sites (+ all of the above)
  65. Check if store is in Store List (+ all of the above)
  66. Check all stores in List (+ all of the above)*/
  67. /**#@+
  68. * @access private
  69. */
  70.  
  71. /**
  72. * Link to product detail page at Amazon.
  73. * @var string
  74. */
  75. var $url;
  76. /**
  77. * Product category (book, music, etc.).
  78. * @var string
  79. */
  80. var $catalog;
  81. /**
  82. * Date the product was, or will be, released to market.
  83. * @var string
  84. */
  85. var $releaseDate;
  86. /**
  87. * Manufacturer of product. Can represent publishers (for books), labels (for music) or studios (for films).
  88. * @var string
  89. */
  90. var $manufacturer;
  91. /**
  92. * Lowest price of the used product in Amazon Marketplace
  93. * @var string
  94. */
  95. var $usedPrice;
  96. /**
  97. * Indicates if any errors were encountered while processing the service request.
  98. * @var string
  99. */
  100. var $status;
  101. /**
  102. * Current product availability at Amazon
  103. * @var string
  104. */
  105. var $availability;
  106. /**
  107. * ID of Third Party Seller
  108. * @var string
  109. */
  110. var $merchantid;
  111.  
  112. /**
  113. * Product image or cover art.
  114. * Amazon returns 3 URLs for a small, medium and large image, which are stored in this array.
  115. * @var array
  116. */
  117. var $imageUrls;
  118. /**
  119. * Author(s) of a book.
  120. * @var array
  121. */
  122. var $authors;
  123. /**
  124. * Musician(s) or artist(s) of a CD or cassette.
  125. * @var array
  126. */
  127. var $artists;
  128. /**#@-*/
  129.  
  130. /**#@+
  131. * This feature is not properly documented in the SDK, therefore I don't use it.
  132. * @var string
  133. * @access private
  134. */
  135. var $minPrice;
  136. var $maxPrice;
  137. var $minSalePrice;
  138. var $maxSalePrice;
  139. var $shipDate;
  140. var $multiMerchant;
  141. var $merchantSku;
  142. /**#@-*/
  143.  
  144.  
  145. /**
  146. * Can generate a hyperlink to the product details page at Amazon, or simply
  147. * return the URL to this page.
  148. *
  149. * @param string|boolean$makeLink is used to indicate whether a link should be created.
  150. * Accepted values are:
  151. * - false: no link is created, only the URL is returned
  152. * - "name": a link is created displaying the name of the product
  153. * between the anchor tags (<a>)
  154. * - "small": a link is created displaying the small version
  155. * of the product's image
  156. * - "medium": a link is created displaying the medium version
  157. * of the product's image
  158. * - "large": a link is created displaying the large version
  159. * of the product's image
  160. * - "special": a link is created using the string provided through
  161. * the $special parameter
  162. * @param string $linkAttributes any additional attributes to be added to the anchor tag (<a>)
  163. * such as style, onmouseover, etc.
  164. * @param string $additionalArguments when $makeLink is set to "special", the value of this parameter
  165. * is used as text for the link created. If $makeLink is set to any of the images, this parameter is
  166. * used to add information to the IMG tag, such as border (which is 0 if not specified), alignment,
  167. * etc.
  168. * @param string $type this experimental feature allows to obtain links for pages designed
  169. * for specific browsers in Amazon (i.e. WAP browsers, PDAs, etc.) the default is "html" for
  170. * a classic Amazon page. Accepted values are:
  171. * - "html": link to the classic Amazon.com product details page
  172. * - "wap": link to a WAP version of the Amazon.com product details page
  173. * - "pda": link version adapted for PDAs of the Amazon.com product details page
  174. * - "text": link to the text-only version of the Amazon.com product details page
  175. * NOTE that types different than "html" have only been tested to work with the "us" locale.
  176. *
  177. * @return string|booleanEither the URL to the details page of the product on Amazon, or the generated
  178. * hyperlink. Or false if the URL is not set.
  179. */
  180. function getURL($makeLink = false, $linkAttributes = "", $additionalArguments = "", $type = "html"){
  181. global $_AMAZOOP_ASSOC_IDS;
  182.  
  183. if(getAmazoopConfig('close_tag_character') == "xhtml")
  184. $tagClose = " />";
  185. else
  186. $tagClose = ">";
  187.  
  188. // Return false if the URL is not set
  189. if(!isset($this->url))
  190. return false;
  191.  
  192. $sites = array( "us" => "com",
  193. "uk" => "co.uk",
  194. "de" => "de",
  195. "fr" => "fr",
  196. "jp" => "co.jp");
  197.  
  198. $url = "";
  199.  
  200. switch($type){
  201. case "wap":
  202. $url = "http://www.amazon." . $sites[$this->locale] . "/exec/obidos/redirect?tag=" . $_AMAZOOP_ASSOC_IDS[$this->locale] . "%26creative=" . _AMAZOOP_DEV_TOKEN . "%26camp=2025%26link_code=xm2%26path=ct/text/vnd.wap.wml/-/tg/aa/xml/glance-xml/-/" . $this->getASIN();
  203. break;
  204. case "pda":
  205. $url = "http://www.amazon." . $sites[$this->locale] . "/exec/obidos/redirect?tag=" . $_AMAZOOP_ASSOC_IDS[$this->locale] . "%26creative=" . _AMAZOOP_DEV_TOKEN . "%26camp=2025%26link_code=xm2%26path=dt/upda-1.0-anywhere/tg/aa/upda/item/-/" . $this->getASIN();
  206. break;
  207. case "text":
  208. $url = "http://www.amazon." . $sites[$this->locale] . "/exec/obidos/redirect?tag=" . $_AMAZOOP_ASSOC_IDS[$this->locale] . "%26creative=" . _AMAZOOP_DEV_TOKEN . "%26camp=2025%26link_code=xm2%26path=tg/detail/-/" . $this->getASIN() . "/t?v=glance";
  209. break;
  210. case "wishlist":
  211. $url = "http://www.amazon." . $sites[$this->locale] . "/exec/obidos/redirect?tag=" . $_AMAZOOP_ASSOC_IDS[$this->locale] . "%26creative=" . _AMAZOOP_DEV_TOKEN . "%26path=http%3A//www.amazon." . $sites[$this->locale] . "/gp/registry/registry.html%3Fid%3D" . "3MBWIMW5ILITP";
  212. break;
  213. default:
  214. $url = rawurldecode($this->url);
  215. break;
  216.  
  217. }
  218.  
  219. // If there are attributes to be added to the anchor tag, add a space before them
  220. if($linkAttributes != "")
  221. $linkAttributes = " " . $linkAttributes;
  222.  
  223. // Test what kind of link should be created and create the appropiate response
  224. switch($makeLink){
  225. case "name":
  226. $res = "<a href=\"" . $url . "\"" . $linkAttributes . ">" . $this->getProductName() . "</a>";
  227. break;
  228. case "small":
  229. case "medium":
  230. case "large":
  231. $image = $this->getImage($makeLink, true, $additionalArguments);
  232. /*if(strpos($additionalArguments, "border") === false)
  233. $additionalArguments = "border=\"0\" " . $additionalArguments;*/
  234. //$res = "<a href=\"" . $url . "\"" . $linkAttributes . "><img src=\"" . $image['url'] . "\" width=\"" . $image['width'] . "\" height=\"" . $image['height'] . "\" alt=\"". $this->getProductName() . "\" " . $additionalArguments . $tagClose . "</a>";
  235. $res = "<a href=\"" . $url . "\"" . $linkAttributes . ">" . $image . "</a>";
  236. break;
  237. case "special":
  238. $res = "<a href=\"" . $url . "\"" . $linkAttributes . ">" . $additionalArguments . "</a>";
  239. break;
  240. default:
  241. // The decoded version of the URL should be returned
  242. $res = $url;
  243. }
  244.  
  245. return $res;
  246. }
  247.  
  248.  
  249. /**
  250. * Decodes the catalog. The catalog determines which "aile" of the Amazon store
  251. * this product belongs to. This seems to be in English in all locales.
  252. *
  253. * @return string|booleanThe product's catalog. Or false if the catalog is not set.
  254. */
  255. function getCatalog(){
  256. if(!isset($this->catalog))
  257. return false;
  258. else
  259. return rawurldecode($this->catalog);
  260. }
  261.  
  262. /**
  263. * Displays the authors of a book.
  264. *
  265. * You can specify how many authors you want to display, what character(s) should
  266. * separate each name and what should be appended at the end of the list if there are
  267. * more authors than were displayed.
  268. *
  269. * Additionally, since version 0.2, you can add a template that will be applied to
  270. * each name. This allows to create links, and apply other html transformation to each
  271. * name in the list.
  272. *
  273. * @param integer $howmany indicates how many authors you want to display. If the value is
  274. * zero or is greater than the total number of available authors, all authors are displayed.
  275. * @param string $separator determines what character(s) separate each name. The default value is
  276. * a comma followed by a space.
  277. * @param string $etc is the text appended to the end of a partial list of authors. The default
  278. * value is "et al.", but it could be something like "etc.", "and others", etc.
  279. * @param string $template a template to be applied to each name on the list. The default value
  280. * is "%name%" wich will display the name unmodified. You can submit templates such as
  281. * "<b>%name%</b>", which will display each name in bold characters, but not the separators, or
  282. * something like "<a href=\"/author/%rawName%\">%name%</a>", which will create a link to a page
  283. * using the URL encoded author's name.
  284. *
  285. * @return string|booleanA list of authors. Or false if there are no authors.
  286. *
  287. */
  288. function getAuthors($howmany = 0, $separator = ", ", $etc = "et al.", $template = "%name%"){
  289. $res = "";
  290.  
  291. if(!isset($this->authors) || sizeof($this->authors) == 0)
  292. return false;
  293.  
  294. // If no size was specified or if too many authors were requested
  295. if($howmany == 0 || $howmany > sizeof($this->authors))
  296. // The total number of authors will be returned
  297. $howmany = sizeof($this->authors);
  298.  
  299. for($i = 0; $i < $howmany; $i++){
  300. // Each author is displayed
  301. $author = $this->authors[$i];
  302. $temp = preg_replace("/(%name%)/e", "rawurldecode(\$author)", $template);
  303. $res .= preg_replace("/(%rawName%)/e", "\$author", $temp);
  304.  
  305. // Unless it's the last item, append the separator
  306. if($i < sizeof($this->authors)-1)
  307. $res .= $separator;
  308. }
  309.  
  310. // If not all authors were displayed, append the $etc text
  311. if($howmany < sizeof($this->authors))
  312. $res .= $etc;
  313.  
  314. // The list is returned
  315. return $res;
  316. }
  317.  
  318. /**
  319. * Displays the musicians of a CD or cassette.
  320. *
  321. * You can specify how many artists you want to display, what character(s) should
  322. * separate each name and what should be appended at the end of the list if there are
  323. * more artists than were displayed.
  324. *
  325. * Additionally, since version 0.2, you can add a template that will be applied to
  326. * each name. This allows to create links, and apply other html transformation to each
  327. * name in the list.
  328. *
  329. * @param integer $howmany indicates how many artists you want to display. If the value is
  330. * zero or is greater than the total number of available artists, all artists are displayed.
  331. * @param string $separator determines what character(s) separate each name. The default value is
  332. * a comma followed by a space.
  333. * @param string $etc is the text appended to the end of a partial list of artists. The default
  334. * value is "et al.", but it could be something like "etc.", "and others", etc.
  335. * @param string $template a template to be applied to each name on the list. The default value
  336. * is "%name%" wich will display the name unmodified. You can submit templates such as
  337. * "<b>%name%</b>", which will display each name in bold characters, but not the separators, or
  338. * something like "<a href=\"/artist/%rawName%\">%name%</a>", which will create a link to a page
  339. * using the URL encoded artist's name.
  340. *
  341. * @return string|booleanA list of artists. Or false if there are no artists.
  342. *
  343. */
  344. function getArtists($howmany = 0, $separator = ", ", $etc = "et al.", $template = "%name%"){
  345. $res = "";
  346.  
  347. if(!isset($this->artists) || sizeof($this->artists) == 0)
  348. return false;
  349.  
  350. // If no size was specified or if too many artists were requested
  351. if($howmany == 0 || $howmany > sizeof($this->artists))
  352. // The total number of artists will be returned
  353. $howmany = sizeof($this->artists);
  354.  
  355. for($i = 0; $i < $howmany; $i++){
  356. // Each artist is displayed
  357. $artist = $this->artists[$i];
  358. $temp = preg_replace("/(%name%)/e", "rawurldecode(\$artist)", $template);
  359. $res .= preg_replace("/(%rawName%)/e", "\$artist", $temp);
  360.  
  361. // Unless it's the last item, append the separator
  362. if($i < sizeof($this->artists)-1)
  363. $res .= $separator;
  364. }
  365.  
  366. // If not all artists were displayed, append the $etc text
  367. if($howmany < sizeof($this->artists))
  368. $res .= $etc;
  369.  
  370. // The list is returned
  371. return $res;
  372. }
  373.  
  374. /**
  375. * Decoded version of the date the product was or is supposed to be released to the
  376. * market.
  377. *
  378. * @return string|booleanProduct's release date. Or false if no date is set.
  379. */
  380. function getReleaseDate(){
  381. if(!isset($this->releaseDate))
  382. return false;
  383. else
  384. return rawurldecode($this->releaseDate);
  385. }
  386.  
  387. /**
  388. * Manufacturer of product. Can represent publishers (for books), labels (for music)
  389. * or studios (for films).
  390. *
  391. * Additionally, since version 0.2, you can add a template that will be applied to
  392. * the name. This allows to create links, and apply other html transformation to the
  393. * manufacturer's name.
  394. *
  395. * @param string $template a template to be applied to the manufacturer's name. The default value
  396. * is "%name%" wich will display the name unmodified. You can submit templates such as
  397. * "<b>%name%</b>", which will display the name in bold characters, or something like
  398. * "<a href=\"/artist/%rawName%\">%name%</a>", which will create a link to a page
  399. * using the URL encoded manufacturer's name.
  400. *
  401. * @return string|booleanProduct's manufactuer. Or false if no manufacturer is set.
  402. */
  403. function getManufacturer($template = "%name%"){
  404. if(!isset($this->manufacturer))
  405. return false;
  406. else{
  407. $manufact = $this->manufacturer;
  408. $temp = preg_replace("/(%name%)/e", "rawurldecode(\$manufact)", $template);
  409. $res = preg_replace("/(%rawName%)/e", "\$manufact", $temp);
  410. return $res;
  411. }
  412. }
  413.  
  414. /**
  415. * This function will return either the IMG or the URL for the specified image size.
  416. *
  417. * If the image returned by Amazon is a "non-image" (i.e. 1x1 transparent gif) the default
  418. * image for the specified size is returned. The URLs for the default images are stored in
  419. * {@link $defaultImages}, which is located in the {@link config.inc.php} file.
  420. *
  421. * This function alse tries go around some AWS bugs:
  422. * - when a product is imported (e.g. English books in Amazon.co.jp) their images
  423. * should be accessed using Amazon.com's store code (01) instead of Amazon.co.jp's (09).
  424. * If an image is not returned, amazOOP tries different store codes to go around this.
  425. * For more information on this problem, read
  426. * {@link http://www.amazon.com/gp/browse.html/ref=sc_bb_l_0/?%5Fencoding=UTF8&node=3434651&no=3435361&me=A36L942TSJ2AJA#misc this}
  427. * - when a product is provided by a Third Party Seller (such as products in the apparel,
  428. * gourmet, sports, jewelry and watch catalogs, which by the way are not officially supported)
  429. * the image's name should include the merchant's ID, but AWS doesn't return it like that,
  430. * therefore amazOOP tries to go around this by, first, trying to use the merchant ID AWS provides
  431. * (if a merchant ID is provided) or, second, tries a list of frequently used merchant IDs
  432. * which can be configured in {@link stores.inc.php}. Be aware that this is a crude and time-expensive
  433. * hack to go around this and can be turned off. To avoid going through the whole list of merchants,
  434. * what you should do is erase everything but the first 5 entries from array {@link $storeCodes}, which is
  435. * in file {@link stores.inc.php}.
  436. *
  437. * @param string $size the image's size. Can be "small", "medium" or "large"
  438. * @param boolean $makeTag whether the IMG tag should be created or not
  439. * @param string $addAttr additional attributes to be included in the IMG tag if it was created.
  440. *
  441. * @return string|arrayeither an IMG tag to display the requested image, or an array with the following
  442. * information:
  443. * - 'url': the URL of the image
  444. * - 'width': the image's width
  445. * - 'height': the image's height
  446. *
  447. */
  448. function getImage($size = "small", $makeTag = false, $addAttr = ""){
  449. global $_AMAZOOP_STORE_CODES, $_AMAZOOP_DEFAULT_IMAGES, $allowgetimagesize, $allowsettimelimit;
  450.  
  451. if(getAmazoopConfig('close_tag_character') == "xhtml")
  452. $tagClose = " />";
  453. else
  454. $tagClose = ">";
  455.  
  456. $checkAlternatives = getAmazoopConfig('check_alternative_images');
  457. $asis = (($checkAlternatives & IMAGE_AS_IS) != 0);
  458. $nosize = (($checkAlternatives & IMAGE_NO_SIZE) != 0);// || !$allowgetimagesize;
  459. $checkAlternatives = $checkAlternatives & (~IMAGE_AS_IS) & (~IMAGE_NO_SIZE);
  460.  
  461. if($allowsettimelimit) set_time_limit(60);
  462.  
  463. $image = array();
  464.  
  465. if(!isset($this->imageUrl) || !isset($this->imageUrl[$size])){
  466. $AWSSource = "default";
  467. $imageExists = false;
  468. }
  469. else{
  470. $AWSSource = rawurldecode($this->imageUrl[$size]);
  471. $imageExists = $asis || imageExists($AWSSource);
  472. }
  473.  
  474. if(!$imageExists){
  475. if($AWSSource != "default" && $checkAlternatives > IMAGE_ALTERNATIVES_0){
  476. if($checkAlternatives >= IMAGE_ALTERNATIVES_1 && isset($this->merchantid)){
  477. $temp = preg_replace ("(\.[0-9]+\.)", ".01-" . $_AMAZOOP_STORE_CODES[rawurldecode($this->merchantid)] . ".", $AWSSource);
  478. if(imageExists($temp)){
  479. if($nosize){
  480. $image['width'] = 0;
  481. $image['height'] = 0;
  482. }
  483. else{
  484. $img = getimagesize($temp);
  485. $image['width'] = $img[0];
  486. $image['height'] = $img[1];
  487. }
  488. $image['url'] = $temp;
  489. }
  490. }
  491.  
  492. if(!isset($image['url']) && $checkAlternatives >= IMAGE_ALTERNATIVES_2){
  493. $amazonStores = array("us" => "01", "uk" => "02", "de" => "03", "fr" => "08", "jp" => "09");
  494. foreach($amazonStores as $code){
  495. $temp = preg_replace ("(\.[0-9]+\.)", "." . $code . ".", $AWSSource);
  496. if(imageExists($temp)){
  497. if($nosize){
  498. $image['width'] = 0;
  499. $image['height'] = 0;
  500. }
  501. else{
  502. $img = getimagesize($temp);
  503. $image['width'] = $img[0];
  504. $image['height'] = $img[1];
  505. }
  506. $image['url'] = $temp;
  507. break;
  508. }
  509. }
  510. }
  511.  
  512. if(!isset($image['url']) && $checkAlternatives >= IMAGE_ALTERNATIVES_3){
  513. $temparr = array_change_key_case($_AMAZOOP_STORE_CODES, CASE_LOWER);
  514. if(array_key_exists(strtolower(rawurldecode($this->manufacturer)), $temparr)){
  515. $temp = preg_replace ("(\.[0-9]+\.)", "." . $temparr[strtolower(rawurldecode($this->manufacturer))] . ".", $AWSSource);
  516. if(imageExists($temp)){
  517. if($nosize){
  518. $image['width'] = 0;
  519. $image['height'] = 0;
  520. }
  521. else{
  522. $img = getimagesize($temp);
  523. $image['width'] = $img[0];
  524. $image['height'] = $img[1];
  525. }
  526. $image['url'] = $temp;
  527. }
  528. }
  529. }
  530.  
  531. if(!isset($image['url']) && $checkAlternatives >= IMAGE_ALTERNATIVES_4) {
  532. foreach($_AMAZOOP_STORE_CODES as $code){
  533. $temp = preg_replace ("(\.[0-9]+\.)", "." . $code . ".", $AWSSource);
  534. if(imageExists($temp)){
  535. if($nosize){
  536. $image['width'] = 0;
  537. $image['height'] = 0;
  538. }
  539. else{
  540. $img = getimagesize($temp);
  541. $image['width'] = $img[0];
  542. $image['height'] = $img[1];
  543. }
  544. $image['url'] = $temp;
  545. break;
  546. }
  547. }
  548. }
  549. }
  550.  
  551. if(!isset($image['url'])){
  552. $image = $_AMAZOOP_DEFAULT_IMAGES[$size];
  553. $image['url'] = "http://" . getAmazoopConfig('address') . $image['url'];
  554. }
  555. }
  556. else{
  557. if($nosize){
  558. $image['width'] = 0;
  559. $image['height'] = 0;
  560. }
  561. else{
  562. $img = getimagesize($AWSSource);
  563. $image['width'] = $img[0];
  564. $image['height'] = $img[1];
  565. }
  566. $image['url'] = $AWSSource;
  567. }
  568.  
  569. if($makeTag){
  570. if(strpos($addAttr, "border") === false)
  571. $addAttr = " border=\"0\" " . $addAttr;
  572. elseif($addAttr != "")
  573. $addAttr = " " . $addAttr;
  574.  
  575. if($image['width'] != 0)
  576. $dimension = ' width="' . $image['width'] . '" height="' . $image['height'] . '" ';
  577. else
  578. $dimension = "";
  579.  
  580. $res = '<img src="' . $image['url'] . '"' . $dimension . $addAttr . $tagClose;
  581. }
  582. else
  583. $res = $image;
  584.  
  585. if($allowsettimelimit) set_time_limit(30);
  586. return $res;
  587. }
  588.  
  589. /**
  590. * The lowest used price in Amazon Marketplace.
  591. *
  592. * @return string|booleanthe lowest used price for a product
  593. * in Amazon Marketplace. Or false if no used price was returned.
  594. *
  595. */
  596. function getUsedPrice(){
  597. if(isset($this->usedPrice) && $this->usedPrice != "")
  598. return rawurldecode($this->usedPrice);
  599. else
  600. return false;
  601. }
  602.  
  603. /**
  604. * Indicates if any errors were encountered while processing the service request.
  605. *
  606. * @return string|booleanThe request status. Or false there is no status set.
  607. */
  608. function getStatus(){
  609. if(isset($this->status) && $this->status != "")
  610. return rawurldecode($this->status);
  611. else
  612. return false;
  613. }
  614.  
  615. /**
  616. * Shows the product current availability as indicated by Amazon.
  617. *
  618. * Apparently in AWS4 availability will come (at last!) as a code and as a string.
  619. * When (if) this happens, this function will receive a boolean parameter to determine
  620. * which format you want.
  621. *
  622. * @return string|bolleanThe product's availabiity. Or false there is no availability set.
  623. */
  624. function getAvailability(){
  625. if(isset($this->availability))
  626. return rawurldecode($this->availability);
  627. else
  628. return false;
  629. }
  630.  
  631. /**
  632. * A remote "Add to Cart" form for the current product.
  633. *
  634. * This function will genereate an "Add to Cart" form for the current
  635. * product.
  636. *
  637. * @param string $text is the text that should be used in the button. If a blank
  638. * string is submitted, the default value is used.
  639. * @param boolean $img if set to true, instead of a regular button an image is used.
  640. * The image's URL is set in {@link $buyNowImg} in the {@link config.inc.php}. If this is set
  641. * to true, the $text parameter is used as the ALT text for the image.
  642. *
  643. * @return string An "Add to Cart" form for this product.
  644. *
  645. * @since version 0.2 the $locale parameter has been dropped. It must not be used anymore.
  646. */
  647. function buyNow($text = "", $img = false, $addAttributes = ""){
  648. global $_AMAZOOP_ASSOC_IDS, $_AMAZOOP_BUYNOW_BUTTONS;
  649.  
  650. if(getAmazoopConfig('close_tag_character') == "xhtml")
  651. $closeTag = " />";
  652. else
  653. $closeTag = ">";
  654.  
  655. $sites = array( "us" => "com",
  656. "uk" => "co.uk",
  657. "de" => "de",
  658. "fr" => "fr",
  659. "jp" => "co.jp");
  660.  
  661. if($text == ""){
  662. if($this->locale == "us")
  663. $text = "buy now from Amazon.com";
  664. else if($this->locale == "uk")
  665. $text = "buy now from Amazon.co.uk";
  666. else if($this->locale == "de")
  667. $text = "Jetzt bei Amazon.de kaufen";
  668. else if($this->locale == "jp")
  669. //$text = "Amazon.co.jpからのこれを?。買いなさい";
  670. $text = "Buy now from Amazon.co.jp";
  671. }
  672.  
  673. $res = "<form method=\"post\"";
  674. if(getAmazoopConfig("open_links_in") == "new")
  675. $res .= " target=\"_blank\"";
  676. $res .= " action=\"http://www.amazon." . $sites[$this->locale] . "/exec/obidos/dt/assoc/handle-buy-box=$this->asin\">\n";
  677. $res .= " <input type=\"hidden\" name=\"asin.$this->asin\" value=\"1\"" . $closeTag . "\n";
  678. $res .= " <input type=\"hidden\" name=\"tag-value\" value=\"" . $_AMAZOOP_ASSOC_IDS[$this->locale] . "\"" . $closeTag . "\n";
  679. $res .= " <input type=\"hidden\" name=\"tag_value\" value=\"" . $_AMAZOOP_ASSOC_IDS[$this->locale] . "\"" . $closeTag . "\n";
  680. $res .= " <input type=\"hidden\" name=\"dev-tag-value\" value=\"" . _AMAZOOP_DEV_TOKEN . "\"" . $closeTag . "\n";
  681.  
  682. if(!$img)
  683. $res .= " <input type=\"submit\" name=\"submit.add-to-cart\" value=\"$text\"" . $addAttributes . $closeTag . "\n";
  684. else{
  685. $res .= " <input type=\"image\" name=\"submit.add-to-cart\" src=\"" . $_AMAZOOP_BUYNOW_BUTTONS[$this->locale]['url'] . "\" width=\"" . $_AMAZOOP_BUYNOW_BUTTONS[$this->locale]['width'] . "\" height=\"" . $_AMAZOOP_BUYNOW_BUTTONS[$this->locale]['height'] . "\" border=\"0\" alt=\"" . $text . "\"" . $closeTag . "";
  686. }
  687. $res .= "</form>\n";
  688.  
  689. return $res;
  690. }
  691.  
  692. /**
  693. * The merchant ID of a Third Party Seller.
  694. * This appears when a product is not offerd by Amazon, only by a Third Party Seller.
  695. *
  696. * @return string|booleanThe merchant ID, or false if none is set.
  697. */
  698. function getMerchantId(){
  699. if(isset($this->merchantid))
  700. return rawurldecode($this->merchantid);
  701. else
  702. return false;
  703. }
  704. }
  705. ?>
 
Documentation generated on Sat, 21 Aug 2004 17:40:38 +0200 by phpDocumentor 1.3.0RC3
hosted by
SourceForge.net Logo