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="
$count_share
"; } $api_link .= "
Share on Facebookshare
$counter_share
"; break; case 'twitter': if( $counter_enable_options ==='1' ){ $count_tweets=$this->get_tweets( $url, $cache_period ); $counter_tweets="
$count_tweets
"; } if(isset( $twitter_user) && $twitter_user !='' ){ $url=$url."@$twitter_user"; }else{ $url=$url; } $api_link .= "
Share on Twittertweet
$counter_tweets
"; break; case 'google-plus': if($counter_enable_options ==='1'){ $count_googleplus=$this->get_plusones( $url, $cache_period ); $counter_googleplus="
$count_googleplus
"; } $link = 'https://plus.google.com/share?url='.$url; $api_link .="
Share on Google Plusshare
$counter_googleplus
"; break; case 'pinterest': $count=0; if($counter_enable_options ==='1'){ $count_pinterest=$this->get_pinterest( $url, $cache_period ); $counter_pinterest="
$count_pinterest
"; } global $post; if(has_post_thumbnail()){ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); $link = 'http://pinterest.com/pin/create/bookmarklet/?media='.$image[0].'&url='.$url.'&title='.get_the_title().'&description='.$post->post_excerpt; $api_link .="
Share on $keyshare
$counter_pinterest
"; }else{ } break; case 'linkedin': if($counter_enable_options ==='1'){ $count=$this->get_linkedin( $url, $cache_period ); $counter_linkedin="
$count
"; } $link = "http://www.linkedin.com/shareArticle?mini=true&ro=true&trk=JuizSocialPostSharer&title=".$text."&url=".$url; $api_link .="
Share on $keyshare
$counter_linkedin
"; break; case 'digg': if( $counter_enable_options ==='1' ){ $count_digg=0; $counter_digg="
$count_digg
"; } $link = "http://digg.com/submit?phase=2%20&url=".$url."&title=".$text; $api_link .="
Share on $keyshare
$counter_digg
"; break; case 'email': if ( strpos( $options['apss_email_body'], '%%' ) || strpos( $options['apss_email_subject'], '%%' ) ) { $link = 'mailto:?subject='.$options['apss_email_subject'].'&body='.$options['apss_email_body']; $link = preg_replace( array( '#%%title%%#', '#%%siteurl%%#', '#%%permalink%%#', '#%%url%%#' ), array( get_the_title(), get_site_url(), get_permalink(), $url ), $link ); } else { $link = 'mailto:?subject='.$options['apss_email_subject'].'&body='.$options['apss_email_body'].": ".$url; } $api_link .="
Send a mailmail
"; break; case 'print': $api_link .="
Printprint
"; break; default: echo "should not reach here"; } } } $share_shows_in_options=$options['share_options']; if(in_array('posts', $share_shows_in_options)){ if($options['share_positions']=='below_content'){ return $content."
$api_link
"; } if($options['share_positions']=='above_content'){ return "
$api_link
".$content; } if($options['share_positions']=='on_both'){ return "
$api_link
".$content."
$api_link
"; } }else if(in_array('pages', $share_shows_in_options) && is_page()){ if($options['share_positions']=='below_content'){ return $content."
$api_link
"; } if($options['share_positions']=='above_content'){ return "
$api_link
".$content; } if($options['share_positions']=='on_both'){ return "
$api_link
".$content."
$api_link
"; } }else if(in_array('archives', $share_shows_in_options) && is_archive()){ if($options['share_positions']=='below_content'){ return $content."
$api_link
"; } if($options['share_positions']=='above_content'){ return "
$api_link
".$content; } if($options['share_positions']=='on_both'){ return "
$api_link
".$content."
$api_link
"; } }else if(in_array('categories', $share_shows_in_options) && is_category()){ if($options['share_positions']=='below_content'){ return $content."
$api_link
"; } if($options['share_positions']=='above_content'){ return "
$api_link
".$content; } if($options['share_positions']=='on_both'){ return "
$api_link
".$content."
$api_link
"; } }else{ return $content; } } function register_admin_assets(){ /** * Backend CSS * */ if(isset($_GET['page']) && $_GET['page']=='apss-share'){ wp_enqueue_style( 'aps-admin-css', APSS_CSS_DIR . '/backend.css',false,APSS_VERSION ); //registering plugin admin css wp_enqueue_style( 'fontawesome-css', APSS_CSS_DIR . '/font-awesome.min.css',false,APSS_VERSION ); /** * Backend JS * */ wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'apss-admin-js', APSS_JS_DIR . '/backend.js', array('jquery', 'jquery-ui-sortable', 'wp-color-picker'),APSS_VERSION );//registering plugin's admin js } } /** * Registers Frontend Assets * */ function register_frontend_assets() { wp_enqueue_style( 'apss-font-awesome',APSS_CSS_DIR.'/font-awesome.min.css',array(),APSS_VERSION ); wp_enqueue_style( 'apss-font-opensans','http://fonts.googleapis.com/css?family=Open+Sans',array(),false); wp_enqueue_style( 'apss-frontend-css', APSS_CSS_DIR . '/frontend.css', array( 'apss-font-awesome' ), APSS_VERSION ); } /** * Funciton to print array in pre format * */ function print_array($array) { echo "
";
            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 ); 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(); }