You are here

private function ShareaholicCurlMultiShareCount::curl_setopts in Share Buttons, Related Posts, Content Analytics - Shareaholic 8

Same name and namespace in other branches
  1. 7.3 lib/social-share-counts/curl_multi_share_count.php \ShareaholicCurlMultiShareCount::curl_setopts()
1 call to ShareaholicCurlMultiShareCount::curl_setopts()
ShareaholicCurlMultiShareCount::get_counts in lib/social-share-counts/curl_multi_share_count.php
This function should get all the counts for the supported services

File

lib/social-share-counts/curl_multi_share_count.php, line 112

Class

ShareaholicCurlMultiShareCount
A class that implements ShareaholicShareCounts This class will get the share counts by calling the social services via curl_multi

Code

private function curl_setopts($curl_handle, $config, $service) {

  // set the url to make the curl request
  curl_setopt($curl_handle, CURLOPT_URL, str_replace('%s', $this->url, $config[$service]['url']));
  $timeout = isset($this->options['timeout']) ? $this->options['timeout'] : 6;

  // other necessary settings:
  // CURLOPT_HEADER means include header in output, which we do not want
  // CURLOPT_RETURNTRANSER means return output as string or not
  curl_setopt_array($curl_handle, array(
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_TIMEOUT => $timeout,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
  ));

  // set the http method: default is GET
  if ($config[$service]['method'] === 'POST') {
    curl_setopt($curl_handle, CURLOPT_POST, 1);
  }

  // set the body and headers
  $headers = isset($config[$service]['headers']) ? $config[$service]['headers'] : array();
  $body = isset($config[$service]['body']) ? $config[$service]['body'] : NULL;
  if (isset($body)) {
    if (isset($headers['Content-Type']) && $headers['Content-Type'] === 'application/json') {
      $data_string = json_encode($body);
      curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string),
      ));
      curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $data_string);
    }
  }

  // set the useragent
  $useragent = isset($config[$service]['User-Agent']) ? $config[$service]['User-Agent'] : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0';
  curl_setopt($curl_handle, CURLOPT_USERAGENT, $useragent);
}