\n"; echo " \n"; echo " \n\n"; If ($keywords == "") { $keywords = "Cheap Holiday Deals"; } $yfeed = new CnYahooFeed("distinct_xml_uk_synd_glosupportltd", "weather2travel.com", "uk"); $feeds = $yfeed->getResults($keywords, 5); foreach ($feeds as $feed) { $AdvertTitle = $feed["title"]; $AdvertURL = $feed["clickUrl"]; $AdvertSite = $feed["siteHost"]; $AdvertDesc = $feed["description"]; $AdvertTitle = ConvertToHTML($AdvertTitle); $AdvertDesc = ConvertToHTML($AdvertDesc); echo "
\n"; echo " ".$AdvertTitle."
\n"; echo " ".$AdvertDesc."
\n"; echo " ".$AdvertSite."
\n"; echo "
\n\n"; } echo "\n"; //echo " \n"; //echo " \n"; //echo " \n"; echo " \n"; echo " Sponsored Listings\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " "; PrintAffiliateBanner($rootpath,$PageType,$ResortID,$RegionCode,$RegionType,$ResortName,$RegionName,468,60); echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; /** * Lib for fething Yahoo! feeds. * * Version: 1.1.0 * Requires PHP 5.x, curl */ class CnYahooFeed { const BASE_URL = "http://xml.uk.overture.com/d/search/p/standard/eu/xml/rlb/"; private $type = null; private $partner = null; private $market = null; /** * @param string $partner Partner source tag ("distinct_xml_uk_synd_smth") * @param string $type Domain for which listings are shown ("domain.co.uk") * @param string $mkt Geographical market ("uk") */ public function __construct($partner, $type, $market = "uk") { $this->partner = $partner; $this->type = $type; $this->market = $market; } /** * Fetches Yahoo! feeds and returns results as accosiative arrays. * * @return Array Array of associative arrays containing following keys: title, description, siteHost, clickUrl. * * @param string $keywords The keywords for which listings will be shown ("cheap flights to malaga") * @param int $maxCount Number of listings, (default 3) */ public function getResults($keywords, $maxCount = 3) { $affilParams = array(); $affilParams["ip"] = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : (isset($_SERVER["HTTP_CLIENT_IP"]) ? $_SERVER["HTTP_CLIENT_IP"] : ""); if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) { $affilParams["xfip"] = $_SERVER["HTTP_X_FORWARDED_FOR"]; } $affilParams["ua"] = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : ""; if ( isset($_SERVER["HTTP_REFERER"]) ) { $affilParams["uref"] = $_SERVER["HTTP_REFERER"]; } print_r($affilParams); $serveUri = "http://" . (isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : "localhost") . (isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : "/"); return $this->getResultsImpl( self::BASE_URL, $this->market, $maxCount, "clean", $this->partner, $this->type, $keywords, http_build_query($affilParams), $serveUri ); } /** * Fetches Yahoo! feeds and returns results as associative arrays. * * @return Array Array of associative arrays containing following keys: title, description, host, url. * * @param string $feed Root YSM url including scheme and feed folder and without ending '/' ("http://xml.uk.overture.com/d/search/p/standard/eu/xml/rlb/") * @param string $mkt Geographical market, "uk" * @param int $maxCount Number of listings, 5 * @param string $adultFilter Filter adult content ("clean") * @param string $partner Partner source tag ("distinct_xml_uk_synd_smth") * @param string $type Domain for which listings are shown ("domain.co.uk") * @param string $keywords The keywords for which listings will be shown ("cheap flights to malaga") * @param string $affilData Parameter consists of the user's IP address and browser user agent ( "ip=16.143.215.234&ua=Mozilla ... +.NET+CLR+3.5.30729%29&26uref=domain.com" ) * @param string $serveUrl Url encoded web address of the root domain and page where listings are being served from ("http://www.domain.com/contact.html") */ private function getResultsImpl( $feed, $mkt, $maxCount, $adultFilter, $partner, $type, $keywords, $affilData, $serveUrl) { $params = array( "mkt" => $mkt, "adultFilter" => $adultFilter, "Partner" => $partner, "type" => $type, "maxCount" => $maxCount, "Keywords" => $keywords, "affilData" => $affilData, "serveUrl" => $serveUrl ); $url = $feed . "?" . http_build_query($params); echo "

" . $url . "

"; $feed = $this->getUrl($url); echo strlen($url); if ( $feed === false || empty($feed) ) { return array(); } $p = new YreslibFeedParser(); $res = $p->parse($feed); if ( $res === false ) { return array(); } return $res; } /** * Retrieves content with curl library * * @param string $url Any absolute URL * @return string Content of the requested page */ private function getUrl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $data = curl_exec($ch); if ($data === false) { echo "

Data fetch error: " . curl_error($ch) . "

"; print_r(curl_getinfo($ch)); } echo "
" . htmlentities($data) . "
"; curl_close($ch); return $data; } } /** * Yahoo! feeds parsing helper */ class YreslibFeedParser { var $_buff = null; var $_state = "init"; var $_hasError = false; function parse($feed) { $this->_buff = array(); $this->_state = "init"; $this->_hasError = false; $xmlParser = xml_parser_create(); xml_set_element_handler($xmlParser, array(&$this, "_xml_start_element_handler"), array(&$this, "_xml_end_element_handler")); xml_set_character_data_handler($xmlParser, array(&$this, "_xml_character_data_handler")); $res = xml_parse($xmlParser, $feed); xml_parser_free($xmlParser); if ( !$res ) { return false; } return $this->_buff; } function _xml_start_element_handler($parser, $name, $attribs) { switch ($name) { case "LISTING": if ( $this->_state == "init" ) { $this->_state = "listing"; $link = array( "title" => $attribs["TITLE"], "description" => $attribs["DESCRIPTION"], "siteHost" => $attribs["SITEHOST"] ); array_push($this->_buff, $link); } else { $this->_hasError = true; } break; case "CLICKURL": if ( $this->_state == "listing" ) { $this->_state = "clickurl"; } else { $this->_hasError = true; } break; default: // ignore other tags } } function _xml_end_element_handler($parser, $name) { switch ( $name ) { case "CLICKURL": if ( $this->_state == "clickurl" ) { $this->_state = "listing"; } else { $this->_hasError = true; } break; case "LISTING": if ( $this->_state == "listing" ) { $this->_state = "init"; } else { $this->_hasError = true; } break; default: // ignore other closing tags } } function _xml_character_data_handler($parser, $data) { switch ( $this->_state ) { case "clickurl": $this->_buff[count($this->_buff) - 1]["clickUrl"] = $data; break; default: // ignore all other data } } } Function ConvertToHTML($StringValue) { $strlength = strlen($StringValue); $strcount = 0; $NewString = ""; while ($strcount < $strlength){ $midstring = substr($StringValue,$strcount,1); //echo "[".$midstring."]"; If ($midstring == "Â") { } ElseIf ($midstring == "£") { $NewString = $NewString."£"; } Else { $NewString = $NewString.htmlentities($midstring); } $strcount = $strcount+1; } return $NewString; } ?>