/** * Share Counts API Connectivity check * */ public static function share_counts_api_connectivity_check() { // if we already checked and it is successful, then do not call the API again $share_counts_connect_check = self::get_option('share_counts_connect_check'); if (isset($share_counts_connect_check) && $share_counts_connect_check == 'SUCCESS') { return $share_counts_connect_check; } $services_config = ShareaholicSeqShareCount::get_services_config(); $services = array_keys($services_config); $param_string = implode('&services[]=', $services); $share_counts_api_url = admin_url('admin-ajax.php') . '?action=shareaholic_share_counts_api&url=https%3A%2F%2Fwww.google.com%2F&services[]=' . $param_string; $cache_key = 'share_counts_api_connectivity_check'; $response = get_transient($cache_key); if (!$response) { $response = ShareaholicCurl::get($share_counts_api_url, array(), '', true); } $response_status = self::get_share_counts_api_status($response); // if this was the first time we are doing this and it failed, disable // the share counts API if (empty($share_counts_connect_check) && $response_status == 'FAIL') { self::update_options(array('disable_internal_share_counts_api' => 'on')); } if ($response_status == 'SUCCESS') { set_transient($cache_key, $response, SHARE_COUNTS_CHECK_CACHE_LENGTH); } self::update_options(array('share_counts_connect_check' => $response_status)); return $response_status; }
/** * This is a wrapper for the Recommendations API * */ public static function recommendations_status_check() { if (self::get_option('api_key') != NULL) { $recommendations_url = Shareaholic::REC_API_URL . "/v4/recommend?url=" . urlencode(get_bloginfo('url')) . "&internal=6&sponsored=0&api_key=" . self::get_option('api_key'); $cache_key = 'recommendations_status_check-' . md5($recommendations_url); $response = get_transient($cache_key); if (!$response) { $response = ShareaholicCurl::get($recommendations_url); if (!is_wp_error($response)) { set_transient($cache_key, $response, RECOMMENDATIONS_STATUS_CHECK_CACHE_LENGTH); } } if (is_array($response) && array_key_exists('response', $response)) { $body = $response['body']; if (is_array($body) && array_key_exists('internal', $body) && !empty($body['internal'])) { return "ready"; } else { return "processing"; } } else { return "unknown"; } } }