/**
  * Used from an external API call to wp admin ajax to handle
  * freemius installations and uninstallations
  *
  */
 public static function maybe_a_freemius_webhook()
 {
     $input = @file_get_contents('php://input');
     $event_json = json_decode($input);
     if (!isset($event_json->id)) {
         self::ajax_fail('Hey man! This be no webhook.');
         exit;
     }
     require_once EDD_SEGMENT_PATH . '/controllers/add-ons/freemius-sdk/Freemius.php';
     $fs = new Freemius_Api('plugin', EDD_SEG_IO_FREEMIUS_PLUGIN_ID, EDD_SEG_IO_FREEMIUS_PUBLIC_KEY, EDD_SEG_IO_FREEMIUS_PRIVATE_KEY);
     $fs_event = $fs->Api("/events/{$event_json->id}.json");
     $props = array('email' => $fs_event->objects->user->email, 'name' => $fs_event->objects->user->first . ' ' . $fs_event->objects->user->last, 'site_url' => $fs_event->objects->install->url);
     switch ($fs_event->type) {
         case 'install.installed':
             self::new_install($props);
             break;
         case 'install.uninstalled':
             $fs_uninstall = $fs->Api("/installs/{$fs_event->install_id}/uninstall.json");
             $props['uninstall_code'] = $fs_uninstall->reason_id;
             $props['uninstall_reason'] = $fs_uninstall->reason;
             $props['uninstall_reason_info'] = $fs_uninstall->reason_info;
             self::new_uninstall($props);
             break;
     }
     http_response_code(200);
     exit;
 }
 static function total_time()
 {
     if (class_exists('Freemius_Api')) {
         $logger = Freemius_Api::GetLogger();
     } else {
         $logger = array();
     }
     $total_time = 0.0;
     foreach ($logger as $l) {
         $total_time += $l['total'];
     }
     return number_format(100 * $total_time, 2) . ' ' . __fs('ms');
 }
Beispiel #3
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;
 }
 function get_url($path = '')
 {
     return $this->_api->GetUrl($path);
 }
Beispiel #5
0
 function get_url($path = '')
 {
     return Freemius_Api::GetUrl($path, $this->_api->IsSandbox());
 }
Beispiel #6
0
 /**
  * Set clock diff for all API calls.
  *
  * @since 1.0.3
  * @param $pSeconds
  */
 public static function SetClockDiff($pSeconds)
 {
     self::$_clock_diff = $pSeconds;
 }
<?php

/**
 * @package     Freemius
 * @copyright   Copyright (c) 2015, Freemius, Inc.
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.1.7.3
 */
if (!defined('ABSPATH')) {
    exit;
}
if (class_exists('Freemius_Api')) {
    $logger = Freemius_Api::GetLogger();
} else {
    $logger = array();
}
$counters = array('GET' => 0, 'POST' => 0, 'PUT' => 0, 'DELETE' => 0);
$show_body = false;
foreach ($logger as $log) {
    $counters[$log['method']]++;
    if (!is_null($log['body'])) {
        $show_body = true;
    }
}
$pretty_print = $show_body && defined('JSON_PRETTY_PRINT') && version_compare(phpversion(), '5.3', '>=');
$root_path_len = strlen(ABSPATH);
?>
<h1><?php 
_efs('API');
?>
</h1>
Beispiel #8
0
 /**
  * Set API connection protocol.
  *
  * @since 1.0.4
  */
 public static function SetHttp()
 {
     self::$_protocol = 'http';
 }
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.0.3
 */
// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);
if (!isset($event_json->id)) {
    http_response_code(200);
    exit;
}
/**
 * Freemius PHP SDK can be downloaded from GitHub:
 *  https://github.com/Freemius/php-sdk
 */
require_once '/path/to/freemius/sdk/Freemius.php';
$fs = new Freemius_Api('plugin', 'YOUR_PLUGIN_ID', 'YOUR_PLUGIN_PUBLIC_KEY', 'YOUR_PLUGIN_SECRET_KEY');
$fs_event = $fs->Api("/events/{$event_json->id}.json");
switch ($fs_event->type) {
    case 'install.installed':
        $user = $fs_event->objects->user;
        $email = $user->email;
        $first = $user->first;
        $last = $user->last;
        /**
         * MailChimp SDK for API v3  can be downloaded from here:
         *  https://github.com/drewm/mailchimp-api
         */
        require_once '/path/to/mailchimp-api/api-v3/MailChimp.php';
        // Subscribe to mailchimp list.
        $blog_subscribers_list = 'LIST_ID';
        $mc = new MailChimp('API_KEY');