Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: scott
- * Date: 3/4/19
- * Time: 3:42 PM
- */
- class KeywordClass
- {
- public function accessEspo($url,$action,$user,$password){
- $credentials = $user.':'.$password;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_USERPWD, $credentials);
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_URL, $url . $action);
- curl_setopt($curl, CURLOPT_HEADER, false);
- $result = curl_exec($curl);
- $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- curl_close($curl);
- if($httpCode < 400){
- $json = json_decode($result, TRUE);
- }
- else{
- echo $url.$action;
- echo 'something went wrong!<BR>';
- echo $httpCode;
- }
- return($json);
- }
- public function getNumResults($searchquery) {
- $googleAPIKey = "xxxxxxx"; //Google API Key for JSON
- $googleSearchEngineID = "xxxxxxxxx"; //Google Custom Search engine ID
- $encodedquery = urlencode($searchquery);
- $URL = "https://www.googleapis.com/customsearch/v1?";
- $action = "key=".$googleAPIKey."&cx=".$googleSearchEngineID."&q=".$encodedquery;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_URL, $URL . $action);
- $result = curl_exec($ch);
- $response = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
- curl_close($ch);
- if ($response == 200) {
- $decodedjson = json_decode($result, true);
- $numberresults = $decodedjson['queries']['request'][0]['totalResults'];
- return $numberresults;
- }
- else {return "HTTP Response Error: ".curl_getinfo($ch, CURLINFO_RESPONSE_CODE);}
- }
- public function editEspo($url,$action,$params,$user,$password){
- $credentials = $user.':'.$password;
- $curl = curl_init();
- //curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_USERPWD, $credentials);
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_URL, $url . $action);
- curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
- curl_setopt($curl, CURLOPT_POST, true);
- $result = curl_exec($curl);
- $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- curl_close($curl);
- if($httpCode < 400){
- $json = json_decode($result, TRUE);
- }
- else{
- echo $url.$action;
- echo '<BR>';
- echo 'something went wrong!<BR>';
- echo $httpCode;
- echo '<BR>';
- }
- return($json);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment