Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Mike

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