Location: PHPKode > scripts > ebay mine > project_lib/category_url.php
<?php 

/**
 * 
 * This is a structure class to hold and build the curl url string for walking categories
 * @author Chris
 *
 */
class category_url {
	
	/**
	 * Keywords or item number
	 * @access private
	 * @var string 
	 */
	private $_nkw = '';

	/**
	 * Include or exclude type <br /> 1 = All words, any order <br /> 2 = Any words, any order <br /> 3 = Exact words, exact order <br /> 4 = Exact words, any order
	 * @access private
	 * @var integer 
	 */
	private $_in_kw = '';
	
	/**
	 * Exclude keywords
	 * @access private
	 * @var string 
	 */
	private $_ex_kw = '';
	
	/**
	 * Category ID [Defaults to consumer electronics]  <br /> See <a href="http://listings.ebay.com/_W0QQloctZShowCatIdsQQsacatZQ2d1QQsalocationZatsQQsocmdZListingCategoryList">Cateogry List on eBay</a>
	 * @access private
	 * @var integer
	 */	
	private $_sacat;
	
	/**
	 * Search including completed items <br /> 1 for yes [default] <br /> empty for no
	 * @access private
	 * @var bool
	 */	
	private $LH_Complete = '1';
	
	/**
	 * Search using a price range.  <br /> 1 for yes <br /> empty for no [default]
	 * @access private
	 * @var bool 
	 */	
	private $_mPrRngCbx = '';
	
	/**
	 * Price range floor <br /> Be sure to set $_mPrRngCbx to use!
	 * @access private
	 * @var integer 
	 */	
	private $_udlo = ''; 
	
	/**
	 * Price range ceiling <br /> Be sure to set $_mPrRngCbx to use!
	 * @access private
	 * @var integer 
	 */	
	private $_udhi = '';
	
	/**
	 * Buying format is Auction <br /> 1 for yes <br /> empty for no [default] 
	 * @access private
	 * @var bool 
	 */	
	private $LH_Auction = '';

	/**
	 * Buying format is Buy It Now <br /> 1 for yes <br /> empty for no [default] 
	 * @access private
	 * @var bool 
	 */	
	private $LH_BIN = '';
	
	/**
	 * Buying format is Classified ads <br /> 1 for yes <br /> empty for no [default] 
	 * @access private
	 * @var bool 
	 */
	private $LH_CAds = '';
	
	/**
	 * Not Sure (hidden field)
	 * @access private
	 * @var string 
	 */	
	private $_okw = '';
	
	/**
	 * Not Sure ((hidden field)
	 * @access private
	 * @var string 
	 */	
	private $_oexkw = '';
	
	/**
	 * Use Advanced Search [default 1]
	 * @access private
	 * @var bool 
	 */	
	private $_adv = '1';
	
	/**
	 * Sale currency
	 * @access private
	 * @var string 
	 */	
	private $LH_SALE_CURRENCY = '0';
	
	/**
	 * Sort Order <br /> [default] 1 = Time: ending soonest <br /> 10 = Time: newly listed <br /> 2 = Price: lowest first <br /> 3 = Price: highest first <br /> 7 = Distance: nearest first <br /> 12 = Best Match
	 * @access private
	 * @var integer 
	 */	
	private $_sop = '1';
	
	/**
	 * Show Items 1 = All [default]
	 * @access private
	 * @var integer 
	 */	
	private $_dmd = '1';
	
	/**
	 * Results per page [default 200]
	 * @access private
	 * @var integer 
	 */	
	private $_ipg = '200';

	/**
	 * Result page number [default 1]
	 * @access private
	 * @var integer 
	 */		
	private $_pgn = '1';
	
	private $_trksid;
	private $rt;
	private $_fln;
	private $_ssov;
	private $LH_TopRatedSellers;

	private $extended_keys = array();
	
	/**
	 * 
	 * Add Keyword or Item Number search
	 * @param string $keywords
	 * 
	 * @return string Current Keyword Search
	 */
	public function setKeywordsOrItemNumber( $keywords ) {
		$this->_nkw = $keywords;
		return $this->_nkw;
	}
	
	/**
	 * 
	 * Set the search keywords type to all words in any order <br /> Make sure to call setKeywordsOrItemNumber to set search string!
	 */
	public function setSearchAllWordsAnyOrder() {
		$this->_in_kw = 1;
	}

	/**
	 * 
	 * Set the search keywords type to any words in any order <br /> Make sure to call setKeywordsOrItemNumber to set search string!
	 */	
	public function setSearchAnyWordsAnyOrder() {
		$this->_in_kw = 2;
	}
	
	/**
	 * 
	 * Set the search keywords type to exact words in exact order <br /> Make sure to call setKeywordsOrItemNumber to set search string!
	 */
	public function setSearchExactWordsExactOrder() {
		$this->_in_kw = 3;
	}
	
	/**
	 * 
	 * Set the search keywords type to exact words in any order. <br /> Make sure to call setKeywordsOrItemNumber to set search string!
	 */	
	public function setSearchExactWordsAnyOrder() {
		$this->_in_kw= 4;
	}
	
	/**
	 * 
	 * Search excluding these keywords
	 * @param string $keywords
	 * @return string current keywords
	 */
	public function excludeKeywordsFromSearch( $keywords ) {
		$this->_ex_kw = $keywords;
		return $this->_ex_kw;
	}
	
	/**
	 * 
	 * Set category id to search within <br /> See $_sacat doc for ID number references link.
	 * @param integer $id
	 * @return integer Current Category Id
	 */
	public function setCategoryId( $id ) {
		$this->_sacat = $id;
		
		return $this->_sacat;
	}
	
	/**
	 * 
	 * Set the search to return only completed items.
	 */
	public function setSearchCompletedItems() {
		$this->LH_Complete = 1;
	}
	
	/**
	 * 
	 * Set price range search.  Min, Max, or Both can be set.
	 * @param integer $floor minimum price
	 * @param integer $ceiling maximum price
	 */
	public function setPriceRange( $floor = null, $ceiling = null ) {
		$this->_mPrRngCbx = 1;
		
		if( !is_null( $floor ) ) {
			$this->_udlo = $floor;
		}
		
		if( !is_null( $ceiling ) ) {
			$this->_udhi = $ceiling;
		}
	}
	
	/**
	 * 
	 * Set search filter for Auctions - this can be combinded with the other format set functions.
	 */
	public function setAuction() {
		$this->LH_Auction = 1;
	}
	
	/**
	 * 
	 * Set search filter for Buy It Now - this can be combinded with the other format set functions.
	 */
	public function setBuyItNow() {
		$this->LH_BIN = 1; 
	}
	
	/**
	 * 
	 * Set search filter for Classified Ads - this can be combinded with the other format set functions.
	 */
	public function setClassifiedAds() {
		$this->LH_CAds = 1;
	}
	
	/**
	 * 
	 * Set the sort order to Time, ending soonest.
	 */
	public function setSortOrderTimeEndingSoonest() {
		$this->_sop = 1;
	}
	
	/**
	 * 
	 * Set the sort order to Time, newly listed.
	 */
	public function setSortOrderTimeNewlyListed() {
		$this->_sop = 10;
	}
	
	public function setSortOrderEndDateRecentFirst() {
		$this->_sop = 13;
	}
	
	public function setSortOrderDateListedOldestFirst() {
		$this->_sop = 14;
	}
	
	/**
	 * 
	 * Set the sort order to Price, lowest.
	 */
	public function setSortOrderPriceLowest() {
		$this->_sop = 2;
	}
	
	/**
	 * 
	 * Set the sort order to Price, highest.
	 */
	public function setSortOrderPriceHighest() {
		$this->_sop = 3;
	}
	
	/**
	 * 
	 * Set the page number of search results to be displayed.
	 * @param integer $page_number
	 */
	public function setPageNumber( $page_number ) {
		$this->_pgn = $page_number;
	}
	
	/**
	 * 
	 * Set the page ahead.
	 */
	public function nextPage() {
		$this->_pgn++;
	}
	
	/**
	 * 
	 * Set the page to the prvious.
	 */
	public function previousPage() {
		$this->_pgn--;
	}
	
	/**
	 * 
	 * Returns complete eBay url that will yeild search results
	 * 
	 * @return string URL
	 */
	public function getURL() {
		$return_url = "http://completed.shop.ebay.com/i.html?";
		
		$get_vars = get_object_vars( $this ) + $this->extended_keys;
		foreach( $get_vars as $varname => $value ) {
			if( !is_array( $value ) ) {
				$return_url .= $varname . "=" . $value . "&";
			}
		}
		
		return $return_url;
	}
	
	/**
	 * 
	 * This function returns an associative array of the key value pairs used to create the query string for this search URL object.
	 * @return ArrayObject keyvalue pairs
	 */
	private function getFullKeyList() {
		$get_vars = get_object_vars( $this );
		
		$return_array = array();
		
		foreach( $get_vars as $varname => $value ) {
			if( !is_array( $value ) ) {
				array_push( $return_array, $varname );
			}
		}
		
		return $return_array;
	}
	
	/**
	 * 
	 * This function compairs the passed in URL with the current URL used for the search.  <br /> It returns an associative array with key value pairs that are different from the current search url.
	 * @param string $URL URL to compair with
	 */
	public function diffURL( $URL ) {
		$query_string = parse_url( $URL, PHP_URL_QUERY );
		
		if ( $query_string != '' ) {
			$query_key_values = explode( ';', $query_string );
			$query_hash = array();
		
		
			foreach( $query_key_values as $keyval ) {
				list( $key, $value ) = explode( '=', $keyval );
				$value = str_replace( '&amp', '', $value );
				$query_hash[$key] = $value;
			}
			
			$return_keyvals = array();
			
			foreach( $query_hash as $key => $value ) {
				if ( !in_array( $key, $this->getFullKeyList() ) ) {
					$return_keyvals[$key] = $value;
				}
			}
		}
	}
}

?>
Return current item: ebay mine