Advertisement
Guest User

Mike

a guest
Feb 10th, 2010
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.65 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ?>
  4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  5. <HTML>
  6. <HEAD>
  7. <TITLE></TITLE>
  8. <META NAME="Generator" CONTENT="TextPad 4.6">
  9. <META NAME="Author" CONTENT="?">
  10. <META NAME="Keywords" CONTENT="?">
  11. <META NAME="Description" CONTENT="?">
  12. <LINK REL='stylesheet' TYPE='text/css' HREF='weather2travel.css'>
  13. </HEAD>
  14.  
  15. <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
  16.  
  17. <?php
  18.  
  19.     //require("includes/common_functions.php");
  20.     require("includes/database_functions.php");
  21.     require("includes/affiliate_functions.php");
  22.  
  23.     $rootpath = "";
  24.     $keywords = "";
  25.     $PageType = "";
  26.     $ResortID = 0;
  27.     $RegionCode = "";
  28.     $RegionType = 0;
  29.     $ResortName = "";
  30.     $RegionName = "";
  31.  
  32.     echo "<TABLE border='0' CELLSPACING='0' CELLPADDING='0' width='468' align='center'>\n";
  33.     echo " <TR>\n";
  34.     echo "   <TD>\n\n";
  35.  
  36.         If ($keywords == "") {
  37.             $keywords = "Cheap Holiday Deals";
  38.         }
  39.  
  40.  
  41.         $yfeed = new CnYahooFeed("distinct_xml_uk_synd_glosupportltd", "weather2travel.com", "uk");
  42.         $feeds = $yfeed->getResults($keywords, 5);
  43.  
  44.         foreach ($feeds as $feed) {
  45.  
  46.             $AdvertTitle = $feed["title"];
  47.             $AdvertURL = $feed["clickUrl"];
  48.             $AdvertSite = $feed["siteHost"];
  49.             $AdvertDesc = $feed["description"];
  50.  
  51.             $AdvertTitle = ConvertToHTML($AdvertTitle);
  52.             $AdvertDesc = ConvertToHTML($AdvertDesc);
  53.  
  54.             echo "<div class=\"yitem\">\n";
  55.             echo "  <a href=\"".$AdvertURL."\" title=\"".$AdvertTitle."\" name=\"".$AdvertTitle."\" target=\"new window 1\" class=\"ytitle\" onmouseover=\"self.status='http://".strtolower($AdvertSite)."'; return true;\" onmouseout=\"self.status=''; return true;\">".$AdvertTitle."</a><br />\n";
  56.             echo "  <a href=\"".$AdvertURL."\" title=\"".$AdvertTitle."\" name=\"".$AdvertTitle."\" target=\"new window 2\" class=\"ydesc\" onmouseover=\"self.status='http://".strtolower($AdvertSite)."'; return true;\" onmouseout=\"self.status=''; return true;\">".$AdvertDesc."</a><br />\n";
  57.             echo "  <a href=\"".$AdvertURL."\" title=\"".$AdvertTitle."\" name=\"".$AdvertTitle."\" target=\"new window 3\" class=\"yurl\" onmouseover=\"self.status='http://".strtolower($AdvertSite)."'; return true;\" onmouseout=\"self.status=''; return true;\">".$AdvertSite."</a><br />\n";
  58.             echo "</div>\n\n";
  59.         }
  60.        
  61.     echo "</TD>\n";
  62.     //echo " <TR>\n";
  63.     //echo "   <TD><img src='".$rootpath."images/weather-travel.gif' width='1' height='5' border='0' alt=''></TD>\n";
  64.     //echo " </TR>\n";
  65.     echo " <TR>\n";
  66.     echo "   <TD align='right'><FONT face='verdana,helvetica,arial,ms sans serif' size='2' color='#000000'><SPAN class='size11s14'>Sponsored Listings</span></font></TD>\n";
  67.     echo " </TR>\n";
  68.  
  69.     echo " </TR>\n";
  70.     echo " <TR>\n";
  71.     echo "   <TD><img src='".$rootpath."images/weather-travel.gif' width='1' height='10' border='0' alt=''></TD>\n";
  72.     echo " </TR>\n";
  73.     echo " </TR>\n";
  74.     echo " <TR>\n";
  75.     echo "   <TD><img src='".$rootpath."images/weather-travel.gif' width='1' height='10' border='0' alt=''></TD>\n";
  76.     echo " </TR>\n";
  77.     echo " <TR>\n";
  78.     echo "    <TD bgcolor='#EEEEEE'>";
  79.  
  80.         PrintAffiliateBanner($rootpath,$PageType,$ResortID,$RegionCode,$RegionType,$ResortName,$RegionName,468,60);
  81.  
  82.     echo "</td>\n";
  83.     echo "  </tr>\n";
  84.     echo " <TR>\n";
  85.     echo "   <TD><img src='".$rootpath."images/weather-travel.gif' width='1' height='10' border='0' alt=''></TD>\n";
  86.     echo " </TR>\n";
  87.     echo "</table>\n";
  88.  
  89.  
  90.  
  91. /**
  92.  * Lib for fething Yahoo! feeds.
  93.  *
  94.  * Version: 1.1.0
  95.  * Requires PHP 5.x, curl
  96.  */
  97.  
  98. class CnYahooFeed
  99. {
  100.     const BASE_URL = "http://xml.uk.overture.com/d/search/p/standard/eu/xml/rlb/";
  101.     private $type    = null;
  102.     private $partner = null;
  103.     private $market  = null;
  104.  
  105.     /**
  106.      * @param string $partner Partner source tag ("distinct_xml_uk_synd_smth")
  107.      * @param string $type Domain for which listings are shown ("domain.co.uk")
  108.      * @param string $mkt Geographical market ("uk")
  109.      */
  110.     public function  __construct($partner, $type, $market = "uk")
  111.     {
  112.         $this->partner = $partner;
  113.         $this->type    = $type;
  114.         $this->market  = $market;
  115.     }
  116.  
  117.     /**
  118.      * Fetches Yahoo! feeds and returns results as accosiative arrays.
  119.      *
  120.      * @return Array Array of associative arrays containing following keys: title, description, siteHost, clickUrl.
  121.      *
  122.      * @param string $keywords The keywords for which listings will be shown ("cheap flights to malaga")
  123.      * @param int $maxCount Number of listings, (default 3)
  124.      */
  125.     public function getResults($keywords, $maxCount = 3)
  126.     {
  127.         $affilParams = array();
  128.         $affilParams["ip"]   = isset($_SERVER["REMOTE_ADDR"])
  129.                              ? $_SERVER["REMOTE_ADDR"]
  130.                              : (isset($_SERVER["HTTP_CLIENT_IP"]) ? $_SERVER["HTTP_CLIENT_IP"] : "");
  131.         if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )
  132.         {
  133.             $affilParams["xfip"] = $_SERVER["HTTP_X_FORWARDED_FOR"];
  134.         }
  135.         $affilParams["ua"]   = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : "";
  136.         if ( isset($_SERVER["HTTP_REFERER"]) )
  137.         {
  138.             $affilParams["uref"] = $_SERVER["HTTP_REFERER"];
  139.         }
  140.        
  141.         print_r($affilParams);
  142.        
  143.         $serveUri = "http://" . (isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : "localhost") . (isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : "/");
  144.         return $this->getResultsImpl(
  145.             self::BASE_URL,
  146.             $this->market, $maxCount, "clean", $this->partner,
  147.             $this->type, $keywords,
  148.             http_build_query($affilParams),
  149.             $serveUri
  150.         );
  151.     }
  152.  
  153.     /**
  154.      * Fetches Yahoo! feeds and returns results as associative arrays.
  155.      *
  156.      * @return Array Array of associative arrays containing following keys: title, description, host, url.
  157.      *
  158.      * @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/")
  159.      * @param string $mkt Geographical market, "uk"
  160.      * @param int $maxCount Number of listings, 5
  161.      * @param string $adultFilter Filter adult content ("clean")
  162.      * @param string $partner Partner source tag ("distinct_xml_uk_synd_smth")
  163.      * @param string $type Domain for which listings are shown ("domain.co.uk")
  164.      * @param string $keywords The keywords for which listings will be shown ("cheap flights to malaga")
  165.      * @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" )
  166.      * @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")
  167.      */
  168.     private function getResultsImpl(
  169.         $feed,
  170.         $mkt, $maxCount, $adultFilter, $partner, $type,
  171.         $keywords, $affilData, $serveUrl)
  172.     {
  173.         $params = array(
  174.             "mkt"         => $mkt,
  175.             "adultFilter" => $adultFilter,
  176.             "Partner"     => $partner,
  177.             "type"        => $type,
  178.             "maxCount"    => $maxCount,
  179.             "Keywords"    => $keywords,
  180.             "affilData"   => $affilData,
  181.             "serveUrl"    => $serveUrl
  182.         );
  183.  
  184.         $url = $feed . "?" . http_build_query($params);
  185.        
  186.         echo "<p>" . $url . "</p>";
  187.         $feed = $this->getUrl($url);
  188.         echo strlen($url);
  189.        
  190.         if ( $feed === false || empty($feed) )
  191.         {
  192.             return array();
  193.         }
  194.  
  195.         $p = new YreslibFeedParser();
  196.         $res = $p->parse($feed);
  197.         if ( $res === false )
  198.         {
  199.             return array();
  200.         }
  201.         return $res;
  202.     }
  203.  
  204.     /**
  205.      * Retrieves content with curl library
  206.      *
  207.      * @param string $url Any absolute URL
  208.      * @return string Content of the requested page
  209.      */
  210.     private function getUrl($url)
  211.     {
  212.         $ch = curl_init();
  213.         curl_setopt($ch, CURLOPT_URL, $url);
  214.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  215.         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  216.         $data = curl_exec($ch);
  217.                
  218.         if ($data === false) {
  219.             echo "<p>Data fetch error: " . curl_error($ch) . "</p>";
  220.             print_r(curl_getinfo($ch));
  221.         }
  222.        
  223.         echo "<pre>" . htmlentities($data) . "</pre>";
  224.  
  225.         curl_close($ch);
  226.         return $data;
  227.     }
  228. }
  229.  
  230. /**
  231.  * Yahoo! feeds parsing helper
  232.  */
  233. class YreslibFeedParser
  234. {
  235.     var $_buff  = null;
  236.     var $_state = "init";
  237.     var $_hasError = false;
  238.  
  239.     function parse($feed)
  240.     {
  241.         $this->_buff  = array();
  242.         $this->_state = "init";
  243.         $this->_hasError = false;
  244.  
  245.         $xmlParser = xml_parser_create();
  246.         xml_set_element_handler($xmlParser, array(&$this, "_xml_start_element_handler"), array(&$this, "_xml_end_element_handler"));
  247.         xml_set_character_data_handler($xmlParser, array(&$this, "_xml_character_data_handler"));
  248.         $res = xml_parse($xmlParser, $feed);
  249.         xml_parser_free($xmlParser);
  250.  
  251.         if ( !$res )
  252.         {
  253.             return false;
  254.         }
  255.         return $this->_buff;
  256.     }
  257.  
  258.     function _xml_start_element_handler($parser, $name, $attribs)
  259.     {
  260.         switch ($name)
  261.         {
  262.             case "LISTING":
  263.                 if ( $this->_state == "init" )
  264.                 {
  265.                         $this->_state = "listing";
  266.                         $link = array(
  267.                             "title"       => $attribs["TITLE"],
  268.                             "description" => $attribs["DESCRIPTION"],
  269.                             "siteHost"    => $attribs["SITEHOST"]
  270.                         );
  271.                         array_push($this->_buff, $link);
  272.                 }
  273.                 else
  274.                 {
  275.                     $this->_hasError = true;
  276.                 }
  277.             break;
  278.             case "CLICKURL":
  279.                 if ( $this->_state == "listing" )
  280.                 {
  281.                     $this->_state = "clickurl";
  282.                 }
  283.                 else
  284.                 {
  285.                     $this->_hasError = true;
  286.                 }
  287.             break;
  288.             default:
  289.                 // ignore other tags
  290.         }
  291.     }
  292.  
  293.     function _xml_end_element_handler($parser, $name)
  294.     {
  295.         switch ( $name )
  296.         {
  297.             case "CLICKURL":
  298.                 if ( $this->_state == "clickurl" )
  299.                 {
  300.                     $this->_state = "listing";
  301.                 }
  302.                 else
  303.                 {
  304.                     $this->_hasError = true;
  305.                 }
  306.             break;
  307.             case "LISTING":
  308.                 if ( $this->_state == "listing" )
  309.                 {
  310.                     $this->_state = "init";
  311.                 }
  312.                 else
  313.                 {
  314.                     $this->_hasError = true;
  315.                 }
  316.             break;
  317.             default:
  318.                 // ignore other closing tags
  319.         }
  320.     }
  321.  
  322.     function _xml_character_data_handler($parser, $data)
  323.     {
  324.         switch ( $this->_state )
  325.         {
  326.             case "clickurl":
  327.                 $this->_buff[count($this->_buff) - 1]["clickUrl"] = $data;
  328.             break;
  329.             default:
  330.                 // ignore all other data
  331.         }
  332.     }
  333. }
  334.  
  335.  
  336.  
  337. Function ConvertToHTML($StringValue) {
  338.  
  339.     $strlength = strlen($StringValue);
  340.     $strcount = 0;
  341.     $NewString = "";
  342.  
  343.     while ($strcount < $strlength){
  344.  
  345.         $midstring = substr($StringValue,$strcount,1);
  346.  
  347.         //echo "[".$midstring."]";
  348.  
  349.         If ($midstring == "Â") {
  350.  
  351.         } ElseIf ($midstring == "£") {
  352.             $NewString = $NewString."&pound;";
  353.         } Else {
  354.             $NewString = $NewString.htmlentities($midstring);
  355.         }
  356.  
  357.         $strcount = $strcount+1;
  358.  
  359.     }
  360.  
  361.     return $NewString;
  362.  
  363. }
  364.  
  365.  
  366. ?>
  367.  
  368.  
  369. </BODY>
  370. </HTML>
  371.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement