View file yahoo/includes/classes/compare_shopping_search_class.php

File size: 4.56Kb
<?

  /*

* Animated Collapsible DIV- © Dynamic Drive DHTML code library (www.pokazuha.tv)

* This notice MUST stay intact for legal use

* Visit Dynamic Drive at http://www.pokazuha.tv/ for this script and 100s more

* Last Update	: Tuesday, November 13 2005


*/

class CompareShoppingSearch
{
  var $m_url = 'froogle?q={keyword}&pid={pid}';
  var $m_host = "64.233.187.99";

  var $m_settings;
  var $m_total_found_string;
  var $m_total_found_int;
  var $m_keywords;
  var $m_pager;
  var $m_pid;
  var $m_is_no_resuls = 0;

  function CompareShoppingSearch($settings,$keywords)
  {
    $this->m_settings = $settings;
    $this->m_keywords = $keywords;
    $this->m_pid = $_GET['pid'];
  }
  function file_get_contents($url)
  {
    $out = "GET /$url HTTP/1.1\r\n";
    $out .= "Host: {$this->m_host}\r\n";
    $out .= "User-Agent: Mozilla 4.0\r\n";
    $out .= "Connection: close\r\n\r\n";

    $h = fsockopen($this->m_host,80);
    fwrite($h,$out);
    for($a = 0,$r = '';!$a;)
    {
       $b = fread($h,8192);
       $r .= $b;
       $a = (($b=='') ? 1 : 0);
    }
    fclose($h);
    return $r;
  }

  function get_url()
  {
    if (_DEBUG == 1)
      return 'www/Froogle Search monitor compare.htm';
    else
    {
      $this->m_url = str_replace('{keyword}',$this->m_keywords,$this->m_url);
      $this->m_url = str_replace('{pid}',$this->m_pid,$this->m_url);
      $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'lh';
      if ($sort == 'hl')
         $scoring = '&scoring=pd';
      else
         $scoring = '';
      $this->m_url .= $scoring;
      return $this->m_url;
    }
  }
  function get_total_found_string($content)
  {
    if ($this->m_is_no_resuls == 1)
      return "";
    preg_match('|(<span class="noFound">.*<span class="ofSoMany">(.*)</span>)|Ui',$content,$ret);
    $this->m_total_found_int = (int)str_replace(',','',$ret[2]);
    return $ret[1];
  }

  function get_results()
  {
    $url = $this->get_url();
    $content = $this->file_get_contents($url);
    $content = str_replace("\r\n"," ",$content);
    $content = str_replace("\n"," ",$content);

    $ret_data = '
    <div style="padding-left:20px;padding-top:20px;">
    <a href="javascript: history.go(-1);">« Back</a>
    ';
    $pid = $_GET['pid'];
    $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'lh';
    if ($sort == 'lh')
        $sort_string = '<b>Low to high</b> - <a href="?type=compare&search='.htmlspecialchars($this->m_keywords).'&pid='.$pid.'&sort=hl">High to low</a>';
    else
       $sort_string = '<a href="?type=compare&search='.htmlspecialchars($this->m_keywords).'&pid='.$pid.'&sort=lh">Low to high</a> - <b>High to low</b>';
    //Get
   if ($cnt = preg_match_all('|<TABLE cellSpacing=0 cellPadding=0>(.*)</TABLE><br>|Ui',$content,$ret))
    {
      $ret_data .= '<div align="right"><b><font color="#FF8040">Sort by price:</font></b>&nbsp;'.$sort_string.'</div>';
      foreach($ret[0] as $index=>$value)
      {
        $value = preg_replace('|<form.*>.*</form>|Ui','',$value);
        $value = preg_replace('|<DIV class=x>.*</div>|Ui','',$value);
        preg_match_all('|<a.*>(<img.*>.*)</a>|Ui',$value,$td);
        foreach($td[0] as $i=>$td_data)
        {
          $value = str_replace($td[0][$i],$td[1][$i],$value);
        }
        $value = str_replace("/froogle_image","http://64.233.187.99/froogle_image",$value);
        $value = str_replace("/froogle/images/image_not_available.gif","http://64.233.187.99/froogle/images/image_not_available.gif",$value);
        $br = explode("<br>",$value);
        if (count($br) < 2)
           $br = explode("<BR>",$value);
        //Title
        preg_match('|<a.*href=".*\?q=(.*)".*>(.*)</a>|Ui',$br[0],$title_value);
        $href = 'href="http://64.233.187.99/froogle_url?q='.($title_value[1]).'" onMouseOver="window.status=\''.($title_value[1]).'\';return true" onMouseOut="window.status=\'\';return true"';
        $ret_data .= str_replace($title_value[0],'<a '.$href.' target="_new">'.$title_value[2].'</a>',$br[0])."<br>";
        //Price
        preg_match('|<FONT.*size=-1>(.*) - <A|Ui',$br[1],$price);
        $ret_data .= $price[1].'</FONT><br>';
        //Description
        $ret_data .= $br[2].'<br>';
        //Url
        preg_match('|<FONT color=#3366cc>.*</font>|Ui',$br[3],$url);
        $ret_data .= $url[0].'<br>';
        $ret_data .= '</td></tr></TABLE><br>';
      }

    }
    else
     {
        $this->m_is_no_resuls = 1;
        return $this->m_settings->get_noresults_string();
     }
    return $ret_data;
  }
}
?>