strQuery);
$url = $EBayURL;
$url .= '&satitle=' . $searchTerm;
$this->EBayCategory($this->strDffCatNum);
$catNum = $this->strCatNum;
$url .= '&sacat=' . $catNum;
$url .= '&saslop=1&afmp=&fss=0';
// echo $url;
// $url = 'http://rss.api.ebay.com/ws/rssapi?FeedName=SearchResults&siteId=0&language=en-US&output=RSS20&catref=C5&sacqy=&sacur=0&fsop=1&fsoo=1&from=R6&sacqyop=ge&saslc=0&floc=1&saprclo=&saprchi=&saaff=afcj&ftrv=1&ftrt=1&fcl=3&afcj=1939749&frpp=50&nojspr=y&satitle=Jerry%20Garcia&sacat=11233&saslop=1&afmp=&fss=0';
$ebayRetCode = $this->CallEBayECS($url, 10);
if ($ebayRetCode == false)
{
echo "EBay Error: " . $this->getDataError . '\n';
}
else
{
$this->DisplayEBayContent();
}
// $this->DisplayEBayContent();
}
// Returns the response as a string or false on error
function CallEBayECS($url, $timeout)
{
// Parse the URL into parameters for fsockopen
$UrlArr = parse_url($url);
$host = $UrlArr['host'];
$port = (isset($UrlArr['port'])) ? $UrlArr['port'] : 80;
$path = $UrlArr['path'];
$query = (isset($UrlArr['query'])) ? '?' . $UrlArr['query'] : '';
$path .= $query;
// Zero out the error response
$errno = null;
$errstr = '';
$this->getDataError = '';
// Open the connection to News Source
$fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
// Failed to open the URL
if (!is_resource($fp))
{
$this->getDataError = "Fsockopen error number = $errno Details = $errstr";
return false;
}
// Send an HTTP GET header and Host header
if (!(fwrite($fp, 'GET '. $path .' HTTP/1.0' . "\r\n". 'Host: ' . $host . "\r\n\r\n")))
{
fclose($fp);
$this->getDataError = "Fwrite error. Could not write GET and Host headers";
return false;
}
// Block on the socket port, waiting for response from News Source
if (function_exists('socket_set_timeout'))
{
@socket_set_timeout($fp, $timeout);
socket_set_blocking($fp, true);
// echo 'Set Timeout Exists';
}
// Get the HTTP response code from CNET
$line = fgets($fp , 1024);
if ($line == false)
{
fclose($fp);
$this->getDataError = "Fgets error. Did not receive any data back from News Source";
return false;
}
// HTTP return code of 200 means success
if (!(strstr($line, '200')))
{
fclose($fp);
$this->getDataError = "HTTP error. Did not receive 200 return code from News Source. Instead, received this: $line";
return false;
}
// Find blank line between header and data
do
{
$line = fgets($fp , 1024);
if ($line == false)
{
fclose($fp);
$this->getDataError = "Fgets: did not receive enough data back from News Source";
return false;
}
if (strlen($line) < 3)
{
break;
}
} while (true);
$xml='';
// Fetch the data from News Source
while ($line = fread($fp, 8192))
{
if ($line == false)
{
fclose($fp);
$this->getDataError = "Fread: error reading data from News Source";
return false;
}
$xml .= $line;
}
fclose($fp);
$this->NewsXML = $xml;
return true;
// echo '
';
// echo 'News Response:';
// echo $this->NewsXML;
// echo '
';
}
function DisplayEBayContent()
{
$p = xml_parser_create();
xml_parse_into_struct($p, $this->NewsXML, $this->NewsArray, $index);
// xml_parse_into_struct($p, $this->NewsXML, $values, $index);
xml_parser_free($p);
/*
echo '';
echo "Index array\n";
print_r($index);
echo '
';
echo '';
echo "\nVals array\n";
print_r($this->NewsArray);
echo '
';
*/
$this->intNewsItems = 0;
$this->NewsHTML .= '';
$this->EBayHeading();
foreach ($index as $key=>$val)
{
if ($key == "ITEM")
{
$items = $val;
for ($i=0; $i < count($items); $i++)
{
if ($this->NewsArray[$items[$i]]['type'] == 'open')
{
$this->intNewsItems++;
if ($this->intNewsItems <= $this->intNewsLimit)
{
$this->ParseRSSFeed($items[$i]);
}
}
}
}
else
{
continue;
}
}
$this->NewsHTML .= '
';
if ($this->blnDisplayFooter == TRUE)
{
$this->NewsHTML .= '';
}
}
function ParseRSSFeed($i)
{
$strSwitch = 0;
$title = '';
$description = '';
$category = '';
$pubdate = '';
$bidCount = 0;
$buyItNowPrice = 0;
$currentPrice = 0;
$link = '';
for ($j=$i; $strSwitch < 1; $j++)
{
if ($j < count($this->NewsArray))
{
switch (strtoupper($this->NewsArray[$j]['tag']))
{
case 'TITLE':
$title = $this->NewsArray[$j]['value'];
break;
case 'DESCRIPTION':
$description = $this->NewsArray[$j]['value'];
$imageURL = $this->ParseImageURL($this->NewsArray[$j]['value']);
$endDate = $this->ParseEndDate($this->NewsArray[$j]['value']);
$bidNowLink = $this->ParseBidNow($this->NewsArray[$j]['value']);
$buyNowLink = $this->ParseBuyNow($this->NewsArray[$j]['value'], $bidNowLink);
$watchListLink = $this->ParseWatchList($this->NewsArray[$j]['value'], $bidNowLink);
break;
case 'CATEGORY':
$category = $this->NewsArray[$j]['value'];
break;
case 'RX:BUYITNOWPRICE':
$buyItNowPrice = $this->NewsArray[$j]['value'];
break;
case 'RX:CURRENTPRICE':
$currentPrice = $this->NewsArray[$j]['value'];
break;
case 'RX:BIDCOUNT':
$bidCount = $this->NewsArray[$j]['value'];
break;
case 'PUBDATE':
$pubdate = $this->NewsArray[$j]['value'];
break;
case 'LINK':
$link = $this->NewsArray[$j]['value'];
break;
case 'ITEM':
if ($this->NewsArray[$j]['type'] == 'close')
{
$strSwitch = 1;
}
break;
default:
break;
}
}
else
{
$strSwitch = 1;
}
}
$this->NewsHTML .= '';
$this->NewsHTML .= '
' . $title . '
';
setlocale(LC_MONETARY, 'en_US');
$this->NewsHTML .= '
';
$this->NewsHTML .= '
Current Bid: $' . money_format('%i', $currentPrice/100) . '
';
if ($buyItNowPrice <> 0)
{
$this->NewsHTML .= '
Buy it Now: $' . money_format('%i', $buyItNowPrice/100) . '
';
}
else
{
$this->NewsHTML .= '
';
}
$this->NewsHTML .= '
Bid Count: ' . $bidCount . '
';
$this->NewsHTML .= '
';
$this->NewsHTML .= '
';
if ($bidNowLink <> "")
{
$this->NewsHTML .= '
';
}
else
{
$this->NewsHTML .= '
';
}
if ($buyNowLink <> "")
{
$this->NewsHTML .= '
';
}
else
{
$this->NewsHTML .= '
';
}
$this->NewsHTML .= '
';
$this->NewsHTML .= '
';
$this->NewsHTML .= '
';
}
function EBayCategory($dffCategory)
{
/* "101" => "2984", //baby
"1392" => "11232", //"Movies DVDs Blue Ray Disc and VHS",
"1407" => "11233", // "Music CD's MP3's",
"1437" => "99, //"Office Products & Supplies",
"1456" => "625, //"Photography",
"1546" => "26395", //"Health & Beauty",
"1838" => "316", //"Services",
"193" => "267", //"Books & Magazines",
"2093" => "382", //"Sports & Fitness",
"2133" => "220", //"Toys & Games",
"2327" => "3252", //"Travel",
"2334" => "1249", //"Video Games",
"2546" => "99", //"Building Supplies",
"271" => "6000", // "Cars & Trucks",
"2850" => "99", //"Pet Supplies",
"292" => "11450", //"Clothing & Accessories",
"3190" => "99", // "Restaurant Supplies",
"322" => "1", //"Collectibles & Art",
"3309" => "281", //"Jewelry & Watches",
"340" => "58058", //"Computer Hardware",
"3988" => "12576", // "Industrial & Commercial",
"681" => "58058", //"Computer Software",
"788" => "11700", //"Flowers & Plants",
"801" => "99", //"Food, Wine & Gifts",
"824" => "293", //"Electronics",
"929" => "11700"); //"Home & Garden");
*/
$Category = array( "101" => "2984",
"1392" => "11232",
"1407" => "11233",
"1437" => "99",
"1456" => "625",
"1546" => "26395",
"1838" => "316",
"193" => "267",
"2093" => "382",
"2133" => "220",
"2327" => "3252",
"2334" => "1249",
"2546" => "99",
"271" => "6000",
"2850" => "99",
"292" => "11450",
"3190" => "99",
"322" => "1",
"3309" => "281",
"340" => "58058",
"3988" => "12576",
"681" => "58058",
"788" => "11700",
"801" => "99",
"824" => "293",
"929" => "11700");
$this->strCatNum = $Category[$dffCategory];
return;
}
function ParseImageURL($fullDescription)
{
$sPos = strpos($fullDescription, 'src=');
$ePos = strpos($fullDescription, '">', $sPos);
$imgURL = substr($fullDescription, $sPos + 4, $ePos - ($sPos +3));
return $imgURL;
}
function ParseEndDate($fullDescription)
{
$sPos = strpos($fullDescription, 'End Date:');
$ePos = strpos($fullDescription, '
Bid now', $sPos);
if ($ePos == 0)
{
$bidNowLink = "";
}
else
{
$bidNowLink = substr($fullDescription, $sPos + 6, $ePos - ($sPos + 5));
}
return $bidNowLink;
}
function ParseBuyNow($fullDescription, $bidNowLink)
{
$buyNowLink = "";
if ($bidNowLink == "")
{
$tPos = strpos($fullDescription, "End Date:");
$sPos = strpos($fullDescription, 'href="', $tPos);
$ePos = strpos($fullDescription, '">Buy it now', $sPos);
$buyNowLink = substr($fullDescription, $sPos + 6, $ePos - ($sPos + 5));
}
else
{
$barCount = substr_count($fullDescription, "|");
if ($barCount > 1)
{
$tPos = strpos($fullDescription, "Bid now");
$sPos = strpos($fullDescription, 'href="', $tPos);
$ePos = strpos($fullDescription, '">Buy it now', $sPos);
$buyNowLink = substr($fullDescription, $sPos + 6, $ePos - ($sPos + 5));
}
}
return $buyNowLink;
}
function ParseWatchList($fullDescription, $bidNowLink)
{
$barCount = substr_count($fullDescription, "|");
if ($barCount > 1)
{
$tPos = strpos($fullDescription, "Buy it now");
$sPos = strpos($fullDescription, 'href="', $tPos);
$ePos = strpos($fullDescription, '">Add to', $sPos);
$watchListLink = substr($fullDescription, $sPos + 6, $ePos - ($sPos + 5));
}
else
{
if ($bidNowLink == "")
{
$tPos = strpos($fullDescription, "Buy it now");
$sPos = strpos($fullDescription, 'href="', $tPos);
$ePos = strpos($fullDescription, '">Add to', $sPos);
$watchListLink = substr($fullDescription, $sPos + 6, $ePos - ($sPos + 5));
}
else
{
$tPos = strpos($fullDescription, "Bid now");
$sPos = strpos($fullDescription, 'href="', $tPos);
$ePos = strpos($fullDescription, '">Add to', $sPos);
$watchListLink = substr($fullDescription, $sPos + 6, $ePos - ($sPos + 5));
}
}
return $watchListLink;
}
function EBayHeading()
{
$this->NewsHTML .= '
';
}
}
?>