curPageURL(); $text= get_the_title(); $cache_period = ($options['cache_period'] != '') ? $options['cache_period']*60*60 : 24 * 60 * 60 ; $counter_share=''; $count_share=''; $counter_tweets=''; $counter_googleplus=''; $counter_pinterest=''; $counter_linkedin=''; $counter_digg=''; foreach( $options['social_networks'] as $key=>$value ){ if( intval($value)=='1' ){ switch($key){ case 'facebook': if($counter_enable_options ==='1'){ $count_share=$this->get_fb( $url, $cache_period ); $counter_share="
";
print_r($array);
echo "";
}
//function to restore the default setting of a plugin
function apss_restore_default_settings(){
$nonce = $_REQUEST['_wpnonce'];
if(!empty($_GET) && wp_verify_nonce( $nonce, 'apss-restore-default-settings-nonce' ))
{
//restore the default plugin activation settings from the activation page.
include( 'inc/backend/activation.php' );
$_SESSION['apss_message'] = __( 'Settings restored Successfully.', APSS_TEXT_DOMAIN );
wp_redirect( admin_url().'admin.php?page=apss-share' );
exit;
}else{
die( 'No script kiddies please!' );
}
}
////////////////////////////////////for count //////////////////////////////////////////////////////
//for facebook url share count
function get_fb( $url, $cache_period ) {
$facebook_count=get_transient('apss_fb_count');
if(false===$facebook_count){
$json_string = $this->get_json_values( 'http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls='.$url );
$json = json_decode( $json_string, true );
$facebook_count = isset( $json[0]['total_count'] )?intval( $json[0]['total_count'] ):0;
set_transient('apss_fb_count', $facebook_count, $cache_period);
return $facebook_count;
}else{
return $facebook_count;
}
}
//for twitter url share count
function get_tweets( $url, $cache_period ) {
$tweet_count = get_transient('apss_tweets_count');
if(false===$tweet_count){
$json_string = $this->get_json_values( 'http://urls.api.twitter.com/1/urls/count.json?url=' . $url );
$json = json_decode( $json_string, true );
$tweet_count = isset( $json['count'])?intval($json['count'] ):0;
set_transient('apss_tweets_count', $tweet_count, $cache_period);
return $tweet_count;
}else{
return $tweet_count;
}
}
//for google plus url share count
function get_plusones( $url, $cache_period ) {
$plusones_count = get_transient('apss_google_plus_count');
if(false === $plusones_count){
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, "https://clients6.google.com/rpc");
curl_setopt( $curl, CURLOPT_POST, true);
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"'.rawurldecode($url).'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-type: application/json' ));
$curl_results = curl_exec ( $curl );
curl_close ( $curl );
$json = json_decode( $curl_results, true );
$plusones_count = isset( $json[0]['result']['metadata']['globalCounts']['count'])?intval( $json[0]['result']['metadata']['globalCounts']['count'] ):0;
set_transient('apss_google_plus_count', $plusones_count, $cache_period );
return $plusones_count;
}else{
return $plusones_count;
}
}
//for pinterest url share count
function get_pinterest( $url, $cache_period ){
$pinterest_count = get_transient('apss_pin_count');
if(false===$pinterest_count){
$json_string = $this->get_json_values( 'http://api.pinterest.com/v1/urls/count.json?url='.$url );
$json_string = preg_replace( '/^receiveCount\((.*)\)$/', "\\1", $json_string );
$json = json_decode( $json_string, true );
$pinterest_count = isset( $json['count'])? intval( $json['count'] ) : 0;
set_transient('apss_pin_count', $pinterest_count, $cache_period );
return $pinterest_count;
}else{
return $pinterest_count;
}
}
//for linkedin url share count
function get_linkedin( $url, $cache_period ) {
$linkedin_count=get_transient('apss_linkedin_count');
if(false===$linkedin_count){
$json_string = $this->get_json_values( "https://www.linkedin.com/countserv/count/share?url=$url&format=json" );
$json = json_decode( $json_string, true );
$linkedin_count = isset( $json['count'])?intval($json['count'] ):0;
set_transient('apss_linkedin_count', $linkedin_count, $cache_period);
return $linkedin_count;
}else{
return $linkedin_count;
}
}
//function to return json values from social media urls
private function get_json_values( $url ){
$args=array( 'timeout' => 10 );
$response = wp_remote_get( $url, $args );
if(is_wp_error($response)){
//echo 'Error Found ( '.$response->get_error_message().' )';
}else{
return $response['body'];
}
}
////////////////////////////////////for count ends here/////////////////////////////////////////////
/**
* Clears the social share counter cache
*/
function apss_clear_cache() {
if (!empty($_GET) && wp_verify_nonce($_GET['_wpnonce'], 'apss-clear-cache-nonce')) {
$transient_array = array('apss_tweets_count', 'apss_linkedin_count', 'apss_fb_count', 'apss_pin_count', 'apss_google_plus_count', 'apss_stumble_count', 'apss_delicious_count', 'apss_reddit_count');
foreach ($transient_array as $transient) {
delete_transient($transient);
}
$_SESSION['apss_message'] = __( 'Cache cleared Successfully', APSS_TEXT_DOMAIN );
wp_redirect( admin_url() . 'admin.php?page=apss-share' );
}
}
}//APSS_Class termination
$apss_object = new APSS_Class();
}