Exemplo n.º 1
0
 function get_url($path = '')
 {
     return $this->_api->GetUrl($path);
 }
Exemplo n.º 2
0
 /**
  * @param string        $pCanonizedPath
  * @param string        $pMethod
  * @param array         $pParams
  * @param null|resource $pCurlHandler
  * @param bool          $pIsSandbox
  * @param null|callable $pBeforeExecutionFunction
  *
  * @return object[]|object|null
  *
  * @throws \Freemius_Exception
  */
 private static function MakeStaticRequest($pCanonizedPath, $pMethod = 'GET', $pParams = array(), $pCurlHandler = null, $pIsSandbox = false, $pBeforeExecutionFunction = null)
 {
     if (!FS_SDK__HAS_CURL) {
         self::ThrowNoCurlException();
     }
     // Connectivity errors simulation.
     if (FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE) {
         self::ThrowCloudFlareDDoSException();
     } else {
         if (FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL) {
             self::ThrowSquidAclException();
         }
     }
     if (!$pCurlHandler) {
         $pCurlHandler = curl_init();
     }
     $opts = self::$CURL_OPTS;
     if (!isset($opts[CURLOPT_HTTPHEADER]) || !is_array($opts[CURLOPT_HTTPHEADER])) {
         $opts[CURLOPT_HTTPHEADER] = array();
     }
     if ('POST' === $pMethod || 'PUT' === $pMethod) {
         if (is_array($pParams) && 0 < count($pParams)) {
             $opts[CURLOPT_HTTPHEADER][] = 'Content-Type: application/json';
             $opts[CURLOPT_POST] = count($pParams);
             $opts[CURLOPT_POSTFIELDS] = json_encode($pParams);
         }
         $opts[CURLOPT_RETURNTRANSFER] = true;
     }
     $opts[CURLOPT_URL] = Freemius_Api::GetUrl($pCanonizedPath, $pIsSandbox);
     $opts[CURLOPT_CUSTOMREQUEST] = $pMethod;
     $resource = explode('?', $pCanonizedPath);
     // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
     // for 2 seconds if the server does not support this header.
     $opts[CURLOPT_HTTPHEADER][] = 'Expect:';
     if ('https' === substr(strtolower($pCanonizedPath), 0, 5)) {
         $opts[CURLOPT_SSL_VERIFYHOST] = false;
         $opts[CURLOPT_SSL_VERIFYPEER] = false;
     }
     if (false !== $pBeforeExecutionFunction && is_callable($pBeforeExecutionFunction)) {
         $opts = call_user_func($pBeforeExecutionFunction, $resource[0], $opts);
     }
     curl_setopt_array($pCurlHandler, $opts);
     $result = curl_exec($pCurlHandler);
     /*if (curl_errno($ch) == 60) // CURLE_SSL_CACERT
     		{
     			self::errorLog('Invalid or no certificate authority found, using bundled information');
     			curl_setopt($ch, CURLOPT_CAINFO,
     			dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
     			$result = curl_exec($ch);
     		}*/
     // With dual stacked DNS responses, it's possible for a server to
     // have IPv6 enabled but not have IPv6 connectivity.  If this is
     // the case, curl will try IPv4 first and if that fails, then it will
     // fall back to IPv6 and the error EHOSTUNREACH is returned by the
     // operating system.
     if (false === $result && empty($opts[CURLOPT_IPRESOLVE])) {
         $matches = array();
         $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
         if (preg_match($regex, curl_error($pCurlHandler), $matches)) {
             if (strlen(@inet_pton($matches[1])) === 16) {
                 //						self::errorLog('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.');
                 self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
                 curl_setopt($pCurlHandler, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
                 $result = curl_exec($pCurlHandler);
             }
         }
     }
     if ($result === false) {
         self::ThrowCurlException($pCurlHandler);
     }
     curl_close($pCurlHandler);
     if (empty($result)) {
         return null;
     }
     $decoded = json_decode($result);
     if (is_null($decoded)) {
         if (preg_match('/Please turn JavaScript on/i', $result) && preg_match('/text\\/javascript/', $result)) {
             self::ThrowCloudFlareDDoSException($result);
         } else {
             if (preg_match('/Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect./', $result) && preg_match('/squid/', $result)) {
                 self::ThrowSquidAclException($result);
             } else {
                 $decoded = (object) array('error' => (object) array('type' => 'Unknown', 'message' => $result, 'code' => 'unknown', 'http' => 402));
             }
         }
     }
     return $decoded;
 }
Exemplo n.º 3
0
 function get_url($path = '')
 {
     return Freemius_Api::GetUrl($path, $this->_api->IsSandbox());
 }