You are here

public function GoogleCSEServices::getResponse in Google Custom Search Engine 8.2

Same name and namespace in other branches
  1. 8.3 src/GoogleCSEServices.php \Drupal\google_cse\GoogleCSEServices::getResponse()

Given the url with the search we try to do, get response from Google.

Parameters

string $url: The Google URL to query.

Return value

string The response from Google.

1 call to GoogleCSEServices::getResponse()
GoogleCSEServices::service in src/GoogleCSEServices.php
Sends query to Google's Custom Search Engine and returns response.

File

src/GoogleCSEServices.php, line 194

Class

GoogleCSEServices
Additional functions as services for Google CSE.

Namespace

Drupal\google_cse

Code

public function getResponse($url) {
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);

  // Return into a variable.
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  if ($this->moduleHandler
    ->moduleExists('proxy_settings') && ($proxy_host = proxy_settings_host('google_cse_adv'))) {
    if ($proxy_port = proxy_settings_port('google_cse_adv')) {
      curl_setopt($curl, CURLOPT_PROXY, $proxy_host . ':' . $proxy_port);
    }
    else {
      curl_setopt($curl, CURLOPT_PROXY, $proxy_host);
    }
    if ($user = proxy_settings_username('google_cse_adv') && ($password = proxy_settings_password('google_cse_adv'))) {
      curl_setopt($curl, CURLOPT_PROXYUSERPWD, $user . ':' . $password);
    }
  }
  $response[] = curl_exec($curl);
  curl_close($curl);
  return $response;
}