function swp_check_registration_status()
{
    // Fetch the User's Options Array
    $swp_user_options = swp_get_user_options();
    // Fetch URL of the home page
    $homeURL = get_home_url();
    // Create a Registration Code from the Domain Name
    $regCode = md5($homeURL);
    // IF the plugin thinks that it is already registered....
    if (is_swp_registered()) {
        // Construct the request URL
        $url = 'https://warfareplugins.com/registration-api/?activity=check_registration&emailAddress=' . $swp_user_options['emailAddress'] . '&domain=' . $homeURL . '&registrationCode=' . md5($homeURL);
        // Send the link and load the response
        $response = swp_file_get_contents_curl($url);
        // If the response is negative, unregister the plugin....
        if ($response == 'false') {
            // Set the premium code to null
            $swp_user_options['premiumCode'] = '';
            // Update the options array with the premium code nulled
            update_option('socialWarfareOptions', $swp_user_options);
        }
        // If the codes didn't match, but a premium code does exist
    } elseif (isset($swp_user_options['premiumCode'])) {
        // Attemp to unregister this from the Warfare Plugins Server
        $url = 'https://warfareplugins.com/registration-api/?activity=unregister&emailAddress=' . $swp_user_options['emailAddress'] . '&premiumCode=' . $swp_user_options['premiumCode'];
        // Parse the response
        $response = swp_file_get_contents_curl($url);
        $response = json_decode($response, true);
        // If it unregistered, let's try to auto-reregister it....
        if ($response['status'] == 'Success') {
            // Attempt to reregister it
            $url = 'https://warfareplugins.com/registration-api/?activity=register&emailAddress=' . $swp_user_options['emailAddress'] . '&domain=' . get_home_url() . '&registrationCode=' . $regCode;
            // Parse the response
            $response = swp_file_get_contents_curl($url);
            $response = json_decode($response, true);
            // IF the registration attempt was successful....
            if ($response['status'] == 'Success') {
                // Save our updated options
                $swp_user_options['premiumCode'] == $response['premiumCode'];
                // Update the options storing in our new updated Premium Code
                update_option('socialWarfareOptions', $swp_user_options);
                return true;
                // IF the registration attempt was NOT successful
            } else {
                // Set the premium code to null
                $swp_user_options['premiumCode'] = '';
                // Update the options array with the premium code nulled
                update_option('socialWarfareOptions', $swp_user_options);
                return false;
            }
            // IF it wasn't able to unregister
        } else {
            // Set the premium code to null
            $swp_user_options['premiumCode'] = '';
            // Update the options array with the premium code nulled
            update_option('socialWarfareOptions', $swp_user_options);
            return false;
        }
    }
}
Ejemplo n.º 2
0
/**
 * **************************************************************
 *                                                                *
 *   #4: Parse the Response to get the share count	             *
 *                                                                *
 ******************************************************************/
function swp_format_facebook_response($response)
{
    $url = get_permalink(get_the_ID());
    // Parse the original request for shares
    $response = json_decode($response, true);
    // Create a second request for likes and comments
    $request_url = 'https://graph.facebook.com/?id=' . $url . '&fields=og_object{likes.summary(true),comments.summary(true)}';
    $next_response = swp_file_get_contents_curl($request_url);
    $next_response = json_decode($next_response, true);
    // Fetch our counts for all three
    $shares = isset($response['share']['share_count']) ? intval($response['share']['share_count']) : 0;
    $likes = isset($next_response['og_object']['likes']['summary']['total_count']) ? intval($next_response['og_object']['likes']['summary']['total_count']) : 0;
    $comments = isset($next_response['og_object']['comments']['summary']['total_count']) ? intval($next_response['og_object']['comments']['summary']['total_count']) : 0;
    $total_activity = $shares + $likes + $comments;
    if (_swp_is_debug('facebook')) {
        var_dump($facebook_id);
        var_dump($response);
        var_dump($next_response);
        var_dump($shares);
        var_dump($total_activity);
    }
    return $total_activity;
}
Ejemplo n.º 3
0
function swp_make_bitly_url($url, $network, $access_token)
{
    // Fetch the user's options
    $options = swp_get_user_options();
    /* Create a link to check if the permalink has already been shortened.
    	$bitly_lookup_url = 'https://api-ssl.bitly.com/v3/user/link_lookup?url='.urlencode($url).'&access_token='.$access_token;
    
    	// Fetch a response from the Bitly Lookup API
    	$bitly_lookup_response = swp_file_get_contents_curl( $bitly_lookup_url );
    
    	// Parse the JSON formatted response from the Bitly Lookup API
    	$bitly_lookup_response = json_decode( $bitly_lookup_response , true );
    
    	// If the lookup returned a valid, previously generated short link....
    	if( isset( $bitly_lookup_response['data']['link_lookup'][0]['link'] ) && true == false ):
    
    		// Store the short url to return to the plugin
    		$short_url = $bitly_lookup_response['data']['link_lookup'][0]['link'];
    
    	// If the lookup did not return a valid short link....
    	else:*/
    // Set the format to json
    $format = 'json';
    // Create a link to reach the Bitly API
    $bitly_api = 'https://api-ssl.bitly.com/v3/shorten?access_token=' . $access_token . '&uri=' . urlencode($url) . '&format=' . $format;
    // Fetch a response from the Bitly Shortening API
    $data = swp_file_get_contents_curl($bitly_api);
    // Parse the JSON formated response into an array
    $data = json_decode($data, true);
    // If the shortening succeeded....
    if (isset($data['data']['url'])) {
        // Store the short URL to return to the plugin
        $short_url = $data['data']['url'];
        // If the shortening failed....
    } else {
        // Return a status of false
        $short_url = false;
    }
    // endif;
    return $short_url;
}
function swp_fetch_linkedIn_shares($url)
{
    $url = rawurlencode($url);
    $json_string = swp_file_get_contents_curl('https://www.linkedin.com/countserv/count/share?url=' . $url . '&format=json');
    $json = json_decode($json_string, true);
    return isset($json['count']) ? intval($json['count']) : 0;
}
function swp_ajax_passthrough()
{
    // Pass the URL request via cURL
    $response = swp_file_get_contents_curl(urldecode($_POST['url']));
    // Echo the response to the screen
    echo $response;
    // Kill WordPress
    wp_die();
}