You are here

function ZencoderCURL::ZencoderCURL in Video 7

File

modules/video_zencoder/includes/Zencoder.php, line 191

Class

ZencoderCURL

Code

function ZencoderCURL($url, $json, $options = array()) {

  // Add library details to request
  $this->options[CURLOPT_HTTPHEADER][] = "Zencoder-Library-Name: " . ZENCODER_LIBRARY_NAME;
  $this->options[CURLOPT_HTTPHEADER][] = "Zencoder-Library-Version: " . ZENCODER_LIBRARY_VERSION;

  // If posting data
  if ($json) {
    $this->options[CURLOPT_POST] = 1;
    $this->options[CURLOPT_POSTFIELDS] = $json;
  }

  // Add cURL options to defaults (can't use array_merge)
  foreach ($options as $option_key => $option) {
    $this->options[$option_key] = $option;
  }

  // Initialize session
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  // Set transfer options
  curl_setopt_array($ch, $this->options);

  // Execute session and store returned results
  $this->results = curl_exec($ch);

  // Store the HTTP status code given (201, 404, etc.)
  $this->status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

  // Check for cURL error
  if (curl_errno($ch)) {
    $this->error = 'cURL connection error (' . curl_errno($ch) . '): ' . htmlspecialchars(curl_error($ch)) . ' <a href="http://www.google.com/search?q=' . urlencode("curl error " . curl_error($ch)) . '">Search</a>';
    $this->connected = false;
  }
  else {
    $this->connected = true;
  }

  // Close session
  curl_close($ch);
}