Ejemplo n.º 1
0
 /**
  * Gets raw html content using adeurl and any trailing url.
  *
  * @param string $trailing - required
  *
  * @return bool - true if page has content
  */
 private function getUrl($trailing = "")
 {
     if (!empty($trailing)) {
         $this->_ch = curl_init(self::ADE . $trailing);
     }
     if (!empty($this->directLink)) {
         $this->_ch = curl_init($this->directLink);
         $this->directLink = "";
     }
     curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($this->_ch, CURLOPT_HEADER, 0);
     curl_setopt($this->_ch, CURLOPT_VERBOSE, 0);
     curl_setopt($this->_ch, CURLOPT_USERAGENT, "Firefox/2.0.0.1");
     curl_setopt($this->_ch, CURLOPT_FAILONERROR, 1);
     curl_setopt_array($this->_ch, Utility::curlSslContextOptions());
     $this->_response = curl_exec($this->_ch);
     if (!$this->_response) {
         curl_close($this->_ch);
         return false;
     }
     curl_close($this->_ch);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Gets Raw Html
  *
  * @param string $fetchURL
  * @param bool $usePost
  *
  * @return bool
  */
 private function getUrl($fetchURL, $usePost = false)
 {
     if (isset($fetchURL)) {
         $this->_ch = curl_init($fetchURL);
     }
     if ($usePost === true) {
         curl_setopt($this->_ch, CURLOPT_POST, 1);
         curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $this->_postParams);
     }
     curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($this->_ch, CURLOPT_HEADER, 0);
     curl_setopt($this->_ch, CURLOPT_VERBOSE, 0);
     curl_setopt($this->_ch, CURLOPT_USERAGENT, "Firefox/2.0.0.1");
     curl_setopt($this->_ch, CURLOPT_FAILONERROR, 1);
     if (isset($this->cookie)) {
         curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->cookie);
         curl_setopt($this->_ch, CURLOPT_COOKIEFILE, $this->cookie);
     }
     curl_setopt_array($this->_ch, Utility::curlSslContextOptions());
     $this->_response = curl_exec($this->_ch);
     if (!$this->_response) {
         curl_close($this->_ch);
         return false;
     }
     curl_close($this->_ch);
     $this->_html->load($this->_response);
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Get Raw html of webpage
  *
  * @param bool $usepost
  *
  * @return bool
  */
 private function getUrl($usepost = false)
 {
     if (isset($this->_trailUrl)) {
         $ch = curl_init(self::ADMURL . $this->_trailUrl);
     } else {
         $ch = curl_init(self::IF18);
     }
     if ($usepost === true) {
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_postParams);
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_VERBOSE, 0);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_USERAGENT, "Firefox/2.0.0.1");
     curl_setopt($ch, CURLOPT_FAILONERROR, 1);
     if (isset($this->cookie)) {
         curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
         curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
     }
     curl_setopt_array($ch, Utility::curlSslContextOptions());
     $this->_response = curl_exec($ch);
     if (!$this->_response) {
         curl_close($ch);
         return false;
     }
     curl_close($ch);
     $this->_html->load($this->_response);
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Makes the call to the API
  *
  * @param string $function			API specific function name for in the URL
  * @param array $params				Unencoded parameters for in the URL
  * @param string $session_id		Session_id for authentication to the API for specific API methods
  * @param const $method				TMDb::GET or TMDb:POST (default TMDb::GET)
  * @return TMDb result array
  */
 private function _makeCall($function, $params = NULL, $session_id = NULL, $method = TMDb::GET)
 {
     $params = !is_array($params) ? array() : $params;
     $auth_array = array('api_key' => $this->_apikey);
     if ($session_id !== NULL) {
         $auth_array['session_id'] = $session_id;
     }
     $url = $this->_apischeme . TMDb::API_URL . '/' . TMDb::API_VERSION . '/' . $function . '?' . http_build_query($auth_array, '', '&');
     if ($method === TMDb::GET) {
         if (isset($params['language']) and $params['language'] === FALSE) {
             unset($params['language']);
         }
         if (isset($params['include_adult'])) {
             $params['include_adult'] = $params['include_adult'] ? 'true' : 'false';
         }
         $url .= !empty($params) ? '&' . http_build_query($params, '', '&') : '';
     }
     $results = '{}';
     if (extension_loaded('curl')) {
         $headers = array('Accept: application/json');
         $ch = curl_init();
         if ($method == TMDB::POST) {
             $json_string = json_encode($params);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $json_string);
             $headers[] = 'Content-Type: application/json';
             $headers[] = 'Content-Length: ' . strlen($json_string);
         } elseif ($method == TMDb::HEAD) {
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
             curl_setopt($ch, CURLOPT_NOBODY, 1);
         }
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_HEADER, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $this->incRequests();
         curl_setopt_array($ch, Utility::curlSslContextOptions());
         $response = curl_exec($ch);
         $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
         $header = substr($response, 0, $header_size);
         $body = substr($response, $header_size);
         $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         $error_number = curl_errno($ch);
         $error_message = curl_error($ch);
         // If temp banned, you need to wait for 10 sec
         if ($http_status == 503 or $http_status == 0) {
             if ($this->_retries < 3) {
                 $this->_retries += 1;
                 echo "\nTMDB limits exceeded, sleeping for 10 seconds.";
                 usleep(10 * 1000 * 1000);
                 return $this->_makeCall($function, $params, $session_id, $method);
             }
         }
         $this->_retries = 0;
         if ($error_number > 0) {
             throw new TMDbException('Method failed: ' . $function . ' - HTTP Status ' . $http_status . ' Curl Errno ' . $error_number . ' Curl Error ' . $error_message);
         }
         curl_close($ch);
     } else {
         throw new TMDbException('CURL-extension not loaded');
     }
     $results = json_decode($body, TRUE);
     if (strpos($function, 'authentication/token/new') !== FALSE) {
         $parsed_headers = $this->_http_parse_headers($header);
         $results['Authentication-Callback'] = $parsed_headers['Authentication-Callback'];
     }
     if ($results !== NULL) {
         return $results;
     } elseif ($method == TMDb::HEAD) {
         return $this->_http_parse_headers($header);
     } else {
         throw new TMDbException('Server error on "' . $url . '": ' . $response);
     }
 }