include("xml.php");
class CurlRequest
{
private $ch;
/**
* Init curl session
*
* $params = array('url' => '',
* 'host' => '',
* 'header' => '',
* 'method' => '',
* 'referer' => '',
* 'cookie' => '',
* 'post_fields' => '',
* ['login' => '',]
* ['password' => '',]
* 'timeout' => 0
* );
*/
public function init($params)
{
$this->ch = curl_init();
$user_agent = 'Mozilla/5.0 (Windows; U;Windows NT 5.1; ru; rv:1.8.0.9) Gecko/20061206 Firefox/1.5.0.9';
$header = array(
"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
"Accept-Language: ru-ru,ru;q=0.7,en-us;q=0.5,en;q=0.3",
"Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7",
"Keep-Alive: 300");
if (isset($params['host']) && $params['host']) $header[]="Host: ".$host;
if (isset($params['header']) && $params['header']) $header[]=$params['header'];
@curl_setopt ( $this -> ch , CURLOPT_RETURNTRANSFER , 1 );
@curl_setopt ( $this -> ch , CURLOPT_VERBOSE , 1 );
@curl_setopt ( $this -> ch , CURLOPT_HEADER , 1 );
if ($params['method'] == "HEAD") @curl_setopt($this -> ch,CURLOPT_NOBODY,1);
@curl_setopt ( $this -> ch, CURLOPT_FOLLOWLOCATION, 1);
@curl_setopt ( $this -> ch , CURLOPT_HTTPHEADER, $header );
if ($params['referer']) @curl_setopt ($this -> ch , CURLOPT_REFERER, $params['referer'] );
@curl_setopt ( $this -> ch , CURLOPT_USERAGENT, $user_agent);
if ($params['cookie']) @curl_setopt ($this -> ch , CURLOPT_COOKIE, $params['cookie']);
if ( $params['method'] == "POST" )
{
curl_setopt( $this -> ch, CURLOPT_POST, true );
curl_setopt( $this -> ch, CURLOPT_POSTFIELDS, $params['post_fields'] );
}
@curl_setopt( $this -> ch, CURLOPT_URL, $params['url']);
@curl_setopt ( $this -> ch , CURLOPT_SSL_VERIFYPEER, 0 );
@curl_setopt ( $this -> ch , CURLOPT_SSL_VERIFYHOST, 0 );
if (isset($params['login']) & isset($params['password']))
@curl_setopt($this -> ch , CURLOPT_USERPWD,$params['login'].':'.$params['password']);
@curl_setopt ( $this -> ch , CURLOPT_TIMEOUT, $params['timeout']);
}
/**
* Make curl request
*
* @return array 'header','body','curl_error','http_code','last_url'
*/
public function exec()
{
$response = curl_exec($this->ch);
$error = curl_error($this->ch);
$result = array( 'header' => '',
'body' => '',
'curl_error' => '',
'http_code' => '',
'last_url' => '');
if ( $error != "" )
{
$result['curl_error'] = $error;
return $result;
}
$header_size = curl_getinfo($this->ch,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] = substr( $response, $header_size );
$result['http_code'] = curl_getinfo($this -> ch,CURLINFO_HTTP_CODE);
$result['last_url'] = curl_getinfo($this -> ch,CURLINFO_EFFECTIVE_URL);
return $result;
}
}
//////////////////////////////////////////////////////////////////////////////
//function DoSearch($service, $query, $language = 'en', $num_results = 10, $start_at = 0)
function DoSearch($service, $query, $language, $num_results, $start_at, $searchin)
{
$excludedsites = '-site:xavier.se -site:xu.edu -site:xavier.edu -site:cstv.com -site:xula.edu';
$results = array("numresults" => 0);
$search = new CurlRequest();
if ($service == "twittersearch")
{
$url = 'http://search.twitter.com/search.atom?lang='. $language .'&q='. urlencode($query);
if ($num_results > 0)
{
$url .= '&rpp='. $num_results;
}
$method = 'GET';
$referer = '';
$post_fields = '';
$login = '';
$password = '';
$footer = '';
}
else if ($service == "yahoo")
{
$url = 'http://boss.yahooapis.com/ysearch/web/v1/'. urlencode($query .' '. $excludedsites) .'?format=xml&appid=Y5KeN0DV34Gwr0Hv1NVnulsrPQhX27WcRQOGMnT.c7PiITngQTGQgrexq3RiIlAAp.gt&start='. $start_at .'&count='. $num_results .'&lang='. $language;
$method = 'GET';
$referer = '';
$post_fields = '';
$login = '';
$password = '';
}
else if ($service == "xavier")
{
// $url = 'http://boss.yahooapis.com/ysearch/web/v1/'. urlencode($query .' site:xaviermedia.com site:xaviermedia.net site:xavierseek.com -site:xavier.se -site:xu.edu -site:xavier.edu') .'?format=xml&appid=Y5KeN0DV34Gwr0Hv1NVnulsrPQhX27WcRQOGMnT.c7PiITngQTGQgrexq3RiIlAAp.gt&start='. $start_at .'&count='. $num_results .'';
$url = 'http://boss.yahooapis.com/ysearch/web/v1/'. urlencode($query .' (site:xaviermedia.com OR site:xaviermedia.com OR site:xaviermedia.se OR site:xaviermedia.co.uk) '. $excludedsites) .'?format=xml&appid=Y5KeN0DV34Gwr0Hv1NVnulsrPQhX27WcRQOGMnT.c7PiITngQTGQgrexq3RiIlAAp.gt&start='. $start_at .'&count='. $num_results .'';
$method = 'GET';
$referer = '';
$post_fields = '';
$login = '';
$password = '';
$service = 'yahoo';
}
else if ($service == "news")
{
$url = 'http://boss.yahooapis.com/ysearch/news/v1/'. urlencode($query .' '. $excludedsites) .'?format=xml&appid=Y5KeN0DV34Gwr0Hv1NVnulsrPQhX27WcRQOGMnT.c7PiITngQTGQgrexq3RiIlAAp.gt&start='. $start_at .'&count='. $num_results .'&lang='. $language;
$method = 'GET';
$referer = '';
$post_fields = '';
$login = '';
$password = '';
}
else if ($service == "images")
{
$url = 'http://boss.yahooapis.com/ysearch/images/v1/'. urlencode($query .' '. $excludedsites) .'?format=xml&appid=Y5KeN0DV34Gwr0Hv1NVnulsrPQhX27WcRQOGMnT.c7PiITngQTGQgrexq3RiIlAAp.gt&start='. $start_at .'&count='. $num_results .'&lang='. $language;
$method = 'GET';
$referer = '';
$post_fields = '';
$login = '';
$password = '';
}
else if ($service == "spelling")
{
$url = 'http://boss.yahooapis.com/ysearch/spelling/v1/'. urlencode($query) .'?appid=Y5KeN0DV34Gwr0Hv1NVnulsrPQhX27WcRQOGMnT.c7PiITngQTGQgrexq3RiIlAAp.gt&format=xml';
$method = 'GET';
$referer = '';
$post_fields = '';
$login = '';
$password = '';
}
else if ($service == "twitter")
{
$url = 'http://twitter.com/account/rate_limit_status.xml';
$method = 'GET';
$referer = '';
$post_fields = '';
$login = 'xaviermedia';
$password = 'sc6241';
}
$params = array('url' => $url,
'host' => '',
'header' => '',
'method' => $method, // 'POST','HEAD'
'referer' => $referer,
'cookie' => '',
'post_fields' => $post_fields,// 'var1=value&var2=value
'timeout' => 20
);
if ($login != '')
{
$params["login"] = $login;
$params["password"] = $password;
}
$search->init($params);
$result = $search->exec();
$data = str_replace("&","ooOoo",$result['body']);
$data = str_replace('','',$data);
$data = str_replace('','',$data);
///// Start XML
$xml = xmlize($data);
$results["html"] = '';
$results["xml"] = '';
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////// Twitter Search http://search.twitter.com ///////////////////////////////////
if ($service == "twittersearch")
{
$entries = count($xml[feed]["#"]["entry"]);
$results["numresults"] = $entries;
// echo '
'. var_dump($xml[feed]) .''; if ($entries > 0) { for($j = 0; $j < $entries; $j++) { $title = str_replace("ooOoo","&",$xml[feed]["#"]["entry"][$j]["#"]["title"][0]["#"]); $str = stristr($title,'http://'); if ($str === FALSE) { $str = stristr($title,' www.'); if ($str === FALSE) { } else { $str = substr($str,1,strlen($str)); $strnum = strlen($str); $space = stristr($str,' '); if ($space === FALSE) { $url = $str; } else { $strnum = strlen($str); $spacenum = strlen($space); $url = substr($str,0,($strnum-$spacenum)); } $title = str_replace($url,''. $url .'', $title); } } else { $space = stristr($str,' '); if ($space === FALSE) { $url = $str; } else { $strnum = strlen($str); $spacenum = strlen($space); $url = substr($str,0,($strnum-$spacenum)); } $title = str_replace($url,''. $url .'', $title); } $picture = $xml[feed]["#"]["entry"][$j]["#"]["link"][1]["@"]["href"]; $author = $xml[feed]["#"]["entry"][$j]["#"]["author"][0]["#"]["name"][0]["#"]; $t = explode(' ',$author); $results["html"] .= '
![]() |
'. $title .' Reply | |||
Did you mean '. $spellingsuggestion .'? | ![]() |
![]() |
||
'. $title .'
'. $abstract .'
'. $dispurl .' [Look up site]
'. $title .'
'. $abstract .'
'. $dispurl .'
';
}
$results["html"] .= str_replace("ooOoo","&",' '. $title .' | ';
if ($i % 2 == 1)
{
$results["html"] .= '