query = $q; if ($n > 10) $this->result_num = round($n / 10) * 10; else $this->result_num = $n; } function exclude_site($site) { array_push($this->excluded_sites,$site); } function search_msn() { $this->msn_results = array(); $i = 0; $query = $this->query; foreach($this->excluded_sites AS $site) { $query .= " -site:$site"; } if ($this->result_num < 50) $result_num = $this->result_num; else $result_num = 50; for ($x = 0; $x < $this->result_num; $x+=50) { $parameters = array( 'AppID' => $this->msn_appid, 'Query' => $query, 'CultureInfo' => 'en-US', 'SafeSearch' => 'Off', 'Requests' => array ( 'SourceRequest' => array ( 'Source' => 'Web', 'Offset' => $x, 'Count' => $result_num, 'ResultFields' => 'All' ) ) ); $soapclient = new soapclient("http://soap.search.msn.com/webservices.asmx"); $result = $soapclient->call('Search', array('Request' => $parameters), "http://schemas.microsoft.com/MSNSearch/2005/09/fex"); $this->totals[msn] = $result[Responses][SourceResponse][Total]; if ($result[Responses][SourceResponse][Total] == 0) return; foreach($result[Responses][SourceResponse][Results] AS $element_array) { $url = str_replace('http://','',$element_array[Url]); if (substr($url,-1,1) == '/') $url = substr($url,0,strlen($url) - 1); $this->msn_results[$i][url] = $url; $this->msn_results[$i][title] = $element_array[Title]; $this->msn_results[$i][desc] = $element_array[Description]; $this->msn_results[$i][engine] = 'msn'; $this->msn_results[$i][position] = $i + 1; array_push($this->search_results,$this->msn_results[$i]); $i++; } } } function search_jeeves() { $this->jeeves_results = array(); $loop_num = $this->result_num / 10; $i = 0; for ($x = 1; $x <= $loop_num; $x++) { $raw_page = file_get_contents("http://web.ask.com/web?q=" . $this->query . "&page=$x"); $page_array = explode("\n",$raw_page); foreach ($page_array AS $line) { if ((is_numeric(strpos($line,'class="T10"'))) && (is_numeric(strpos($line,'id="r')))) { $url = str_replace('http://','',trim(strip_tags($line))); if (substr($url,-1,1) == '/') $url = substr($url,0,strlen($url) - 1); $this->jeeves_results[$i][url] = $url; $this->jeeves_results[$i][engine] = 'jeeves'; $this->jeeves_results[$i][position] = $i + 1; $i++; } elseif ((is_numeric(strpos($line,'class="L4"'))) && (is_numeric(strpos($line,'id="r')))) { $title = trim(strip_tags($line)); $this->jeeves_results[$i][title] = $title; } elseif ((is_numeric(strpos($line,'class="T1"'))) && (is_numeric(strpos($line,'id="r')))) { $desc = trim(strip_tags($line)); $this->jeeves_results[$i][desc] = $desc; } elseif (is_numeric(strpos($line,'Results 1-10 of'))) { $total = trim(str_replace(array('Results 1-10 of',','),'',$line)); $this->totals[jeeves] = $total; } array_push($this->search_results,$this->jeeves_results[$i]); } } } function get_text($start,$end, $haystack) { if ((!$start) || (!$end) || (!$haystack)) return false; $temp = explode($start,$haystack); $temp = explode($end,$temp[1]); return $temp[0]; } function search_teoma() { $this->teoma_results = array(); $loop_num = $this->result_num / 10; for ($x = 1; $x <= $loop_num; $x++) { $raw_page = file_get_contents("http://s.teoma.com/search?q=" . $this->query . "&page=$x"); $page_array = explode('
',$raw_page); $this->totals[jeeves] = str_replace(',','',get_text('Showing 1-10 of about ',':',$page_array)); $start = ($x - 1) * 10; $stop = $start + 10; $j = 1; for ($i = $start; $i < $stop; $i++) { $this->teoma_results[$i][title] = get_text('"cs()">','
',$page_array[$j]); $this->teoma_results[$i][engine] = 'jeeves'; $this->teoma_results[$i][position] = $i+1; $this->teoma_results[$i][desc] = get_text('
','
',$page_array[$j]); $url = get_text('te_id=&u=','"',$page_array[$j]); if (substr($url,-1,1) == '/') $url = substr($url,0,strlen($url) - 1); $this->teoma_results[$i][url] = $url; $j++; array_push($this->search_results,$this->teoma_results[$i]); } } } function search_google() { $this->google_results = array(); $i = 0; if ($this->result_num < 10) $result_num = $this->result_num; else $result_num = 10; for ($x = 0; $x < $this->result_num; $x+=10) { $parameters = array( "key" => $this->google_key, "q" => $this->query, "start" => $x, "maxResults" => $result_num, "filter" => "false", "restrict" => "", "safeSearch" => "false", "lr" => "lang_en", "ie" => "", "oe" => "" ); $soapclient = new soapclient("http://api.google.com/GoogleSearch.wsdl"); // [1] $result = $soapclient->call("doGoogleSearch", $parameters); $this->totals[google] = $result[estimatedTotalResultsCount]; if (!is_array($result)) return; foreach($result[resultElements] AS $element_array) { $url = str_replace('http://','',$element_array[URL]); if (substr($url,-1,1) == '/') $url = substr($url,0,strlen($url) - 1); $this->google_results[$i][url] = $url; $this->google_results[$i][title] = $element_array[title]; $this->google_results[$i][desc] = $element_array[snippet]; $this->google_results[$i][engine] = 'google'; $this->google_results[$i][position] = $i + 1; array_push($this->search_results,$this->google_results[$i]); $i++; } } } function search_yahoo () { $this->yahoo_results = array(); $i = 0; if ($this->result_num > 50) { $result_num = 50; $query_num = round($this->result_num / 50); $final_num = $this->result_num - $query_num * 50; if ($final_num > 0) $query_num++; } else { $result_num = $this->result_num; $query_num = 1; $final_num = $result_num; } $query = str_replace(' ','%20',$this->query); foreach($this->excluded_sites AS $site) { $query .= "%20-site:$site"; } for ($count = 1; $count <= $query_num; $count++) { if ($count == $query_num) $result_num = $final_num; $start = 50 * ($count - 1); $final_query = 'http://api.search.yahoo.com/WebSearchService/V1/webSearch?query=' . $query . '&results=' . $result_num . '&start=' . $start . '&appid=' . $this->yahoo_appid; $site_results = file_get_contents($final_query); $dom = domxml_open_mem($site_results,DOMXML_LOAD_PARSING,$error); if ($dom) { $root = $dom->document_element(); $this->totals[yahoo] = $root->get_attribute('totalResultsAvailable'); $node = $root->first_child(); while($node) { $subnode = $node->first_child(); while ($subnode) { if ($subnode->tagname == 'Url') { $url = str_replace('http://','',trim($subnode->get_content())); if (substr($url,-1,1) == '/') $url = substr($url,0,strlen($url) - 1); $this->yahoo_results[$i][url] = $url; } elseif ($subnode->tagname == 'Title') { $title = str_replace('http://','',trim($subnode->get_content())); $this->yahoo_results[$i][title] = $title; } elseif ($subnode->tagname == 'Summary') { $desc = str_replace('http://','',trim($subnode->get_content())); $this->yahoo_results[$i][desc] = $desc; } $subnode = $subnode->next_sibling(); } $this->yahoo_results[$i][engine] = 'yahoo'; $this->yahoo_results[$i][position] = $i + 1; array_push($this->search_results,$this->yahoo_results[$i]); $i++; $node = $node->next_sibling(); } } } } }