- <?php
-
- /**
- * This file contains small, somewhat less important classes, that are created
- * when searching products through AWS.
- *
- * The classes that hold the most important information are {@link LiteDetails},
- * and {@link HeavyDetails}, which can be found in the {@link details.class.php} file.
- *
- * @author Mauricio Diaz <madd0@users.sourceforge.net>
- * @copyright 2004 (c) Mauricio Diaz Orlich
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @version 0.3RC1
- *
- * @package amazOOP
- */
-
- /**
- * This is an abstract class from which the classes that are returned when querying AWS are created.
- *
- * As an abstract class, it should never be instantiated. You should take a look at {@link ProductInfo}
- * and {@link BlendedSearch} instead.
- *
- * @author Mauricio Diaz <madd0@users.sourceforge.net>
- * @copyright 2004 (c) Mauricio Diaz Orlich
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @version 0.3RC2
- *
- * @package amazOOP
- * @subpackage Responses
- */
- class AmazonResponse{
- /**#@+
- * @access private
- */
- /**
- * This is to indicate what type of search was made.
- * @var boolean
- */
- var $productInfo;
- /**
- * This is to indicate what type of search was made.
- * @var boolean
- */
- var $blendedSearch;
- /**
- * This is to indicate what type of search was made.
- * @var boolean
- */
- var $shoppingCart;
-
- /**
- * The error message that is returned if the call fails.
- * @var string
- */
- var $errorMsg;
- /**
- * Details about current request.
- * @var array
- */
- var $request;
- /**
- * Number of product lines in current BlendedSearch.
- * @var integer
- */
- var $itemCount = 0;
- /**#@-*/
-
- /**
- * Test to determine if the top node of the search is a {@link ProductInfo} node.
- *
- * This function is used to determine if the search returned a {@link ProductInfo}
- * node, as opposed to a {@link BlendedSearch} node.
- *
- * @return boolean this function returns true when called from this a {@link ProductInfo}
- * class and false when called from a {@link BlendedSearch} class.
- */
- function isProductInfo(){
- return $this->productInfo;
- }
-
- /**
- * Test to determine if the top node of the search is a {@link BlendedSearch} node.
- *
- * This function is used to determine if the search returned a {@link BlendedSearch}
- * node, as opposed to a {@link ProductInfo} node.
- *
- * @return boolean this function returns false when called from this a {@link ProductInfo}
- * class and true when called from a {@link BlendedSearch} class.
- */
- function isBlendedSearch(){
- return $this->blendedSearch;
- }
-
- /**
- * Test to determine if the top node of the search is a {@link ShoppingCartResponse} node.
- *
- * This function is used to determine if the search returned a {@link ShoppingCartResponse}
- * node, as opposed to a {@link ProductInfo} node, or a {@link BlendedSearch} node.
- *
- * @return boolean this function returns true when called from a {@link ShoppingCartResponse}
- * class, and false when called from a {@link ProductInfo}, or a {@link BlendedSearch} class.
- *
- * @since version 0.3RC2
- *
- */
- function isShoppingCart(){
- return $this->shoppingCart;
- }
-
- /**
- * An error message returned by AWS.
- *
- * Currently this function returns a string with the error message returned by
- * AWS, if any. Hopefully, the next release of AWS will provide a numerical form
- * of the error messages also.
- *
- * @return string|booleanthe error message returned by AWS, or false if the is
- * no error message.
- */
- function getErrorMessage(){
- if(isset($this->errorMsg) && $this->errorMsg != "")
- return rawurldecode($this->errorMsg);
- else
- return false;
- }
-
- /**
- * Gets an argument from the Request node of the AWS feed.
- *
- * These arguments include arguments submitted to Amazon when requesting
- * a new feed, plus some additional information added by AWS, such as
- * Request IDs.
- *
- * @return string|booleanthe value of the requested argument or false
- * if it does not exist.
- *
- * @modified 2004-05-15 15:44
- */
- function requestArgument($arg){
- if(isset($this->request[strtoupper($arg)]))
- return $this->request[strtoupper($arg)];
- else
- return false;
- }
- }
-
- /**
- * This is one of the classes returned when querying AWS.
- *
- * This class is returned when you do one of the following queries:
- * - Actor
- * - Artist
- * - ASIN (*)
- * - ISBN (*)
- * - Author
- * - BrowseNode
- * - Director
- * - Keywords
- * - Manufacturer
- * - Power (not supported yet)
- * - Similarity
- * - UPC (*)
- *
- * (*) Will return at the most one product detail
- *
- * This class is also part of the results of a BlendedSearch
- *
- * @see AmazonQuery::query()
- * @see AmazonQuery::getCategory()
- *
- * @author Mauricio Diaz <madd0@users.sourceforge.net>
- * @copyright 2004 (c) Mauricio Diaz Orlich
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @version 0.3RC1
- *
- * @package amazOOP
- * @subpackage Responses
- */
- class ProductInfo extends AmazonResponse {
- /**#@+
- * @access private
- */
-
- /**
- * Number of results (products) generated by search.
- * A search may genereate a large number of results,
- * nevertheless only a maximum of ten will be returned in each query.
- * To obtain the next set of results, you must requet the next page
- * of your serach.
- * @var integer
- */
- var $totalResults;
- /**
- * Number of pages of results generated by search.
- * @var integer
- */
- var $totalPages;
-
- /**
- * An array of product [details]. The objects in the array can be of type
- * {@link LiteDetails} or {@link HeavyDetails}, depending of what type of
- * query you are doing.
- * @var LiteDetails|HeavyDetails.
- * @see LiteDetails
- * @see HeavyDetails
- * @see AmazonQuery::query()
- */
- var $details;
-
- /**#@-*/
-
- /**
- * Default constructor.
- *
- * Prepares the class.
- */
- function ProductInfo(){
- $this->productInfo = true;
- $this->blendedSearch = false;
- $this->shoppingCart = false;
- }
-
- /**
- * The number of the first result returned.
- *
- * For example, if you are on page one, the first result is result number 1,
- * if you are in page 3, the first result is result 21, and so on...
- *
- * @return integer the number of the first result generated by the search.
- *
- * @see resultsHigh()
- */
- function resultsLow(){
- if($this->requestArgument('page')){
- $page = $this->requestArgument('page');
- return ((($page-1)*10)+1);
- }
- else
- return 0;
- }
-
- /**
- * The number of the last result returned.
- *
- * For example, if you are on page one, the last result can be result number 10,
- * or a lower number. If you are in page 3, the last result is result can be 30,
- * or a lower number, and so on...
- *
- * @return integer the number of the last result generated by the search.
- *
- * @see resultsLow()
- */
- function resultsHigh(){
- if($this->requestArgument('page')){
- return (($this->resultsLow()+$this->itemCount)-1);
- }
- else
- return 0;
- }
-
- /**
- * Number of results (products) generated by a search.
- * A search may genereate a large number of results,
- * nevertheless only a maximum of ten will be returned in each query.
- * To obtain the next set of results, you must requet the next page
- * of your serach.
- *
- * @return integer the total number of results generated by the search.
- */
- function getTotalResults(){
- if(isset($this->totalResults) && $this->totalResults != "")
- return rawurldecode($this->totalResults);
- elseif(!$this->getErrorMessage())
- return 1;
- else
- return 0;
- }
-
- /**
- * Number of pages of results generated by a search.
- *
- * @return integer the number of pages of results generated by the search.
- */
- function getTotalPages(){
- if(isset($this->totalPages) && $this->totalPages != "")
- return rawurldecode($this->totalPages);
- elseif(!$this->getErrorMessage())
- return 1;
- else
- return 0;
- }
-
- /**
- * Gets one of the objects containing product details.
- *
- * This object can be of type {@link LiteDetails} or {@link HeavyDetails}, depending
- * on what type of search you are making.
- *
- * @param integer $number the object you want to get from the list. If set to 0 (default),
- * a random object from the list is returned.
- *
- * @return LiteDetails|HeavyDetails|booleanthe details of the requested product from the list,
- * or false if the requested position of the list does not contain product details.
- *
- * @see LiteDetails
- * @see HeavyDetails
- */
- function getDetails($number = 0){
- if($number == 0)
- $number = rand(1, $this->itemCount);
-
- if(isset($this->details[$number-1])){
- $details = &$this->details[$number-1];
-
- $details->locale = $this->requestArgument('LOCALE');
- return $this->details[$number-1];
- }
- else
- return false;
- }
- }
-
- /**
- * This is one of the classes returned when querying AWS.
- *
- * This class is only returned when you query AWS doing a BlendedSearch.
- *
- * @see AmazonQuery::query()
- *
- * @author Mauricio Diaz <madd0@users.sourceforge.net>
- * @copyright 2004 (c) Mauricio Diaz Orlich
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @version 0.3RC1
- *
- * @package amazOOP
- * @subpackage Responses
- */
- class BlendedSearch extends AmazonResponse {
- /**#@+
- * @access private
- */
- /**
- * Array of product lines.
- * @var array
- */
- var $productLines;
-
- /**#@-*/
-
- /**
- * Default constructor.
- *
- * Prepares the class.
- */
- function BlendedSearch(){
- $this->productInfo = false;
- $this->blendedSearch = true;
- $this->shoppingCart = false;
- }
-
- /**
- * Gets one of the product lines returned by the Blended search.
- *
- * A Product Line is an object wich contains a {@link ProductLine::getMode() mode} and
- * a {@link ProductInfo} object.
- *
- * Product lines are returned by AWS in no particular order. As far as I know, up to 15
- * product lines can be returned in each search.
- *
- * @param integer $number the product line you want to get from the list. If set to 0 (default),
- * a random product line from the list is returned.
- *
- * @return ProductLine|booleanthe requested product line from the list,
- * or false if the requested position of the list does not contain a product line.
- *
- * @see ProductLine
- */
- function getProductLine($number = 0){
- if($number == 0)
- $number = rand(1, $this->itemCount);
-
- if(isset($this->productLines[$number-1])){
- return $this->productLines[$number-1];
- }
- else
- return false;
- }
-
- }
-
- /**
- * This class contains a mode and a {@link ProductInfo} object.
- *
- * This class generated when you do a {@link BlendedSearch}. It contains a
- * {@link getMode() mode} corresponding to the AWS mode, and a {@link ProductInfo}
- * object which contains one or more product details of {@link LiteDetails} or
- * {@link HeavyDeatils} type, depending on the type you requested from Amazon.
- *
- * @see BlendedSearch
- * @see ProductInfo
- *
- * @author Mauricio Diaz <madd0@users.sourceforge.net>
- * @copyright 2004 (c) Mauricio Diaz Orlich
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @version 0.3RC1
- *
- * @package amazOOP
- */
- class ProductLine {
- /**#@+
- * @access private
- */
- /**
- * The product line's mode
- * @var string
- */
- var $mode;
- /**
- * A {@link ProductInfo} object containing detailed information about
- * the products returned by the search.
- * @var ProductInfo
- */
- var $productInfo;
- /**#@-*/
-
- /**
- * Gets the mode for this product line.
- *
- * @return string this product line's mode.
- */
- function getMode(){
- return rawurldecode($this->mode);
- }
- /**
- * Gets the {@link ProductInfo} object containing more the products
- * returned by the search on this product line's mode.
- */
- function getProductInfo(){
- return $this->productInfo;
- }
- }
-
- /**
- * This class contains information about the product's ranking
- * as well as customer and editorial reviews.
- *
- * @author Mauricio Diaz <madd0@users.sourceforge.net>
- * @copyright 2004 (c) Mauricio Diaz Orlich
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @version 0.3RC1
- *
- * @package amazOOP
- */
- class Reviews{
- /**#@+
- * @access private
- */
- /**
- * The average review given by Amazon customers.
- * This is a number between 0 and 5. Where 0 doesn't necessariliy mean
- * that the product is terrible, it can also mean that it hasn't been
- * reviewed yet.
- * @var float
- */
- var $avgReview;
- /**
- * The total number of reviews this item has received.
- * @var integer
- */
- var $totalReviews;
- /**
- * An array holding {@link CustomerReview} objects which obviously contain
- * customer reviews.
- * @var CustomerReview
- */
- var $customerReviews;
- /**#@-*/
-
- /**
- * Gets the average review given by Amazon customers.
- *
- * This is a number between 0 and 5. Where 0 doesn't necessariliy mean
- * that the product is terrible, it can also mean that it hasn't been
- * reviewed yet.
- *
- * @return float the average review given to the product by Amazon customers.
- */
- function getAvgReview(){
- if(isset($this->avgReview) && $this->avgReview != "")
- return $this->avgReview;
- else
- return 0;
- }
-
- /**
- * Gets the total number of reviews this item has received.
- *
- * @return integer the total number of reviews received by the product.
- */
- function getTotalReviews(){
- if(isset($this->totalReviews) && $this->totalReviews != "")
- return $this->totalReviews;
- else
- return 0;
- }
-
- /**
- * Gets a Customer Review for the current product.
- *
- * A Customer Review is an object of type {@link CustomerReview} which contains the following
- * information:
- * - The customer's rating in the scale of 0-5
- * - A summary of the customer's review
- * - The customer's review
- *
- * Currently, AWS returns 0-3 reviews for each product.
- *
- * @param integer $number the product line you want to get from the list. If set to 0 (default),
- * a random product line from the list is returned.
- *
- * @return CustomerReview|booleanthe requested customer review from the list,
- * or false if the requested position of the list does not contain a review.
- *
- * @see CustomerReview
- */
- function getCustomerReview($number = 0){
- if($number == 0)
- $number = rand(1, sizeof($this->customerReviews));
-
- if(isset($this->customerReviews[$number-1])){
- return $this->customerReviews[$number-1];
- }
- else
- return false;
- }
- }
-
- /**
- * This class hold Amazon customer reviews.
- *
- * Each review consists of a 0-5 rating, a one-line summary of the review, and
- * the customer review.
- *
- * @author Mauricio Diaz <madd0@users.sourceforge.net>
- * @copyright 2004 (c) Mauricio Diaz Orlich
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @version 0.3RC1
- *
- * @package amazOOP
- */
- class CustomerReview{
- /**#@+
- * @access private
- */
- /**
- * The customer's rating in the scale of 0-5
- * @var float
- */
- var $rating;
- /**
- * A one-line summary of the customer's review
- * @var string
- */
- var $summary;
- /**
- * The whole review
- * @var string
- */
- var $comment;
- /**#@-*/
-
- /**
- * Gets the customer's rating for this product
- *
- * @return float the customer's rating in the scale of 0-5
- */
- function getRating(){
- if(isset($this->rating) && $this->rating != "")
- return $this->rating;
- else
- return 0;
- }
-
- /**
- * Get the summary of the customer's review.
- *
- * The summary consists of one line describing the review.
- *
- * @return string the summary of the customer's review.
- */
- function getSummary(){
- return rawurldecode($this->summary);
- }
-
- /**
- * Gets the customer's review for this product.
- *
- * @param integer $words the number of words you want to get, or 0 if you want
- * the whole review.
- * @param string $end the character(s) to be appended at the end of the review
- * in case the whole text is not returned.
- *
- * @return string the customer's review for the current product, or at
- * least the number of words requested.
- */
- function getReview($words = 0, $end = "..."){
- if($words == 0)
- return rawurldecode($this->comment);
- else{
- $wordArray = preg_split("/[\s]/", rawurldecode($this->comment));
-
- $res = "";
- $words = min($words, sizeof($wordArray));
- for($i = 0; $i < $words; $i++){
- $res .= $wordArray[$i];
- if($i != $words-1)
- $res .= " ";
- }
- if($words < sizeof($wordArray))
- $res .= $end;
- return $res;
- }
- }
- }
-
- /**
- * This class contains information about a Browse Node.
- *
- * According to the AWS documentation, when a product returns a list of browse nodes,
- * all it returns is the name of browse nodes in which the product appears. However,
- * lately a node ID has also been returned, corresponding to the actual browse node
- * used at Amazon.
- *
- * Use this information as you wish.
- *
- * @author Mauricio Diaz <madd0@users.sourceforge.net>
- * @copyright 2004 (c) Mauricio Diaz Orlich
- * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
- * @version 0.3RC1
- *
- * @package amazOOP
- */
- class BrowseNode{
- /**#@+
- * @access private
- */
- /**
- * The node ID of the current node. This is what is needed to query AWS
- * @var integer
- */
- var $nodeId;
- /**
- * The node's name. Nice to know, but not very useful
- * @var string
- */
- var $nodeName;
- /**#@-*/
-
- /**
- * Checks whether AWS returned a node ID.
- *
- * @return boolean true if a node ID was returned, false otherwise.
- */
- function hasNodeId(){
- return (isset($this->nodeId) && $this->nodeId != "");
- }
-
- /**
- * The node ID of the current node. This is what is needed to query AWS.
- *
- * @return integer|booleanthe node's ID, or false if no ID exists.
- */
- function getNodeId(){
- if($this->hasNodeId())
- return $this->nodeId;
- else
- return false;
- }
-
- /**
- * The node's name. Nice to know, but not very useful...
- *
- * @param boolean $decoded whether you want the node's name to be returned
- * decoded or URL encoded.
- *
- * @return string|booleanthe node's name, or false if no name is set.
- */
- function getNodeName($decoded = true){
- if(isset($this->nodeName) && $this->nodeName != "")
- if($decoded)
- return rawurldecode($this->nodeName);
- else
- return $this->nodeName;
- else
- return false;
- }
- }
-
- ?>