Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('BING_API_KEY', '');
- define('YAHOO_API_KEY', '');
- define('GOOGLE_API_KEY', '');
- function pete_curl_get($url, $params){$post_params = array();
- foreach ($params as $key => &$val) {
- if (is_array($val)) $val = implode(',', $val);
- $post_params[] = $key.'='.urlencode($val);
- }
- $post_string = implode('&', $post_params);
- $fullurl = $url."?".$post_string;
- $ch = curl_init();curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_URL, $fullurl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040608'); //kamu bisa pake user agent yang lain, lihat listnya di sini www.user-agents.org
- $result = curl_exec($ch);curl_close($ch);
- return $result;
- }
- function perform_bing_web_search($termstring){$searchurl = 'http://api.bing.net/json.aspx?';
- $searchurl .= 'AppId='.'ABCDEFG'; //ganti ABCDEFG dengan kode api BING http://www.bing.com/developers/appids.aspx
- $searchurl .= '&Query='.urlencode($termstring);
- $searchurl .= '&Sources=Web';
- $searchurl .= '&Web.Count=10'; //jumlah list situs yang dihasilkan
- $searchurl .= '&Web.Offset=0';
- $searchurl .= '&Web.Options=DisableHostCollapsing+DisableQueryAlterations';
- $searchurl .= '&JsonType=raw';
- $response = pete_curl_get($searchurl, array());
- $responseobject = json_decode($response, true);if ($responseobject['SearchResponse']['Web']['Total']==0)return array();
- $allresponseresults = $responseobject['SearchResponse']['Web']['Results'];
- $result = array();
- foreach ($allresponseresults as $responseresult){$result[] = array('url' => $responseresult['Url'],'title' => $responseresult['Title'],'abstract' => $responseresult['Description'],);
- }return $result;
- }
- function perform_google_web_search($termstring)
- {
- $start = 0;
- $result = array();
- while ($start<10) //kamu bisa ganti angka "10" untuk jumlah list yang ditampilkan
- {
- $searchurl = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0';
- $searchurl .= '&key='.'ABCDEFG'; //ganti ABCDEFG dengan kode api Google http://code.google.com/apis/ajaxsearch/signup.html
- $searchurl .= '&start='.$start;
- $searchurl .= '&rsz=large'; //kamu bisa pake "small" untuk menampilkan hanya 4 (maksimal) pencarian
- $searchurl .= '&filter=0'; //kamu bisa ganti "filter=1" untuk mem-filter hasil pencarian
- $searchurl .= '&q='.urlencode($termstring);
- $response = pete_curl_get($searchurl, array());
- $responseobject = json_decode($response, true);
- if (count($responseobject['responseData']['results'])==0)
- break;
- $allresponseresults = $responseobject['responseData']['results'];
- foreach ($allresponseresults as $responseresult)
- {
- $result[] = array(
- 'url' => $responseresult['url'],
- 'title' => $responseresult['title'],
- 'abstract' => $responseresult['content'],
- );
- }
- $start += 8;
- }
- return $result;
- }
- function perform_boss_web_search($termstring)
- {
- $searchurl = 'http://boss.yahooapis.com/ysearch/web/v1/';
- $searchurl .= urlencode($termstring);
- $searchparams = array(
- 'appid' => 'ABCDEFG', //ganti ABCDEFG dengan kode api Yahoo Boss https://developer.apps.yahoo.com/projects/projects
- 'format' => 'json',
- 'count' => '10',
- );
- $response = pete_curl_get($searchurl, $searchparams);
- $responseobject = json_decode($response, true);
- error_log(print_r($responseobject, true));
- if ($responseobject['ysearchresponse']['totalhits']==0)
- return array();
- $allresponseresults = $responseobject['ysearchresponse']['resultset_web'];
- $result = array();
- foreach ($allresponseresults as $responseresult)
- {
- $result[] = array(
- 'url' => $responseresult['url'],
- 'title' => $responseresult['title'],
- 'abstract' => $responseresult['abstract'],
- );
- }
- return $result;
- }if (isset($_REQUEST['s'])) {
- $termstring = urldecode($_REQUEST['s']);
- } else {
- $termstring = '';}
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement