options = $options; $this->version = $version; } /** * Hook the plugin function on 'init' event. * * @since 1.0.0 */ public function init() { // Javascript for front-end of website add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) ); // inline style for front-end of website add_action( 'wp_enqueue_scripts', array( $this, 'frontend_inline_style' ) ); // stylesheet files for front-end of website add_action( 'wp_enqueue_scripts', array( $this, 'frontend_css' ) ); if ( isset( $this->options['amp_enable'] ) && function_exists( 'is_amp_endpoint' ) ) { add_action( 'wp_print_styles', array( $this, 'frontend_amp_css' ) ); add_action( 'amp_post_template_css', array( $this, 'frontend_amp_css' ) ); } } /** * Javascript files to load at front end. * * @since 1.0.0 */ public function frontend_scripts() { if ( ! ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) && ! ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) ) { $in_footer = isset( $this->options['footer_script'] ) ? true : false; $inline_script = 'function heateorSssLoadEvent(e) {var t=window.onload;if (typeof window.onload!="function") {window.onload=e}else{window.onload=function() {t();e()}}}; '; global $post; if ( $post ) { $sharing_meta = get_post_meta( $post->ID, '_heateor_sss_meta', true ); if ( is_front_page() || ! isset( $sharing_meta['sharing'] ) || $sharing_meta['sharing'] != 1 || ! isset( $sharing_meta['vertical_sharing'] ) || $sharing_meta['vertical_sharing'] != 1 ) { $inline_script .= 'var heateorSssSharingAjaxUrl = \''. get_admin_url() .'admin-ajax.php\', heateorSssCloseIconPath = \''. plugins_url( '../images/close.png', __FILE__ ) .'\', heateorSssPluginIconPath = \''. plugins_url( '../images/logo.png', __FILE__ ) .'\', heateorSssHorizontalSharingCountEnable = '. ( isset( $this->options['hor_enable'] ) && ( isset( $this->options['horizontal_counts'] ) || isset( $this->options['horizontal_total_shares'] ) ) ? 1 : 0 ) .', heateorSssVerticalSharingCountEnable = '. ( isset( $this->options['vertical_enable'] ) && ( isset( $this->options['vertical_counts'] ) || isset( $this->options['vertical_total_shares'] ) ) ? 1 : 0 ) .', heateorSssSharingOffset = '. ( isset( $this->options['alignment'] ) && $this->options['alignment'] != '' && isset( $this->options[$this->options['alignment'].'_offset'] ) && $this->options[$this->options['alignment'].'_offset'] != '' ? $this->options[$this->options['alignment'].'_offset'] : 0 ) . '; var heateorSssMobileStickySharingEnabled = ' . ( isset( $this->options['vertical_enable'] ) && isset( $this->options['bottom_mobile_sharing'] ) && $this->options['horizontal_screen_width'] != '' ? 1 : 0 ) . ';'; $inline_script .= 'var heateorSssCopyLinkMessage = "' . htmlspecialchars( __( 'Link copied.', 'sassy-social-share' ), ENT_QUOTES ) . '";'; if ( isset( $this->options['horizontal_counts'] ) && isset( $this->options['horizontal_counter_position'] ) ) { $inline_script .= in_array( $this->options['horizontal_counter_position'], array( 'inner_left', 'inner_right' ) ) ? 'var heateorSssReduceHorizontalSvgWidth = true;' : ''; $inline_script .= in_array( $this->options['horizontal_counter_position'], array( 'inner_top', 'inner_bottom' ) ) ? 'var heateorSssReduceHorizontalSvgHeight = true;' : ''; } if ( isset( $this->options['vertical_counts'] ) ) { $inline_script .= isset( $this->options['vertical_counter_position'] ) && in_array( $this->options['vertical_counter_position'], array( 'inner_left', 'inner_right' ) ) ? 'var heateorSssReduceVerticalSvgWidth = true;' : ''; $inline_script .= ! isset( $this->options['vertical_counter_position'] ) || in_array( $this->options['vertical_counter_position'], array( 'inner_top', 'inner_bottom' ) ) ? 'var heateorSssReduceVerticalSvgHeight = true;' : ''; } $inline_script .= 'var heateorSssUrlCountFetched = [], heateorSssSharesText = \''. htmlspecialchars(__('Shares', 'sassy-social-share'), ENT_QUOTES) .'\', heateorSssShareText = \''. htmlspecialchars(__('Share', 'sassy-social-share'), ENT_QUOTES) .'\';'; $inline_script .= 'function heateorSssPopup(e) {window.open(e,"popUpWindow","height=400,width=600,left=400,top=100,resizable,scrollbars,toolbar=0,personalbar=0,menubar=no,location=no,directories=no,status")}'; if ( $this->facebook_like_recommend_enabled() || $this->facebook_share_enabled() ) { $inline_script .= 'function heateorSssInitiateFB() {FB.init({appId:"",channelUrl:"",status:!0,cookie:!0,xfbml:!0,version:"v3.0"})}window.fbAsyncInit=function() {heateorSssInitiateFB(),' . ( defined( 'HEATEOR_SOCIAL_SHARE_MYCRED_INTEGRATION_VERSION' ) && $this->facebook_like_recommend_enabled() ? 1 : 0 ) . '&&(FB.Event.subscribe("edge.create",function(e) {heateorSsmiMycredPoints("Facebook_like_recommend","",e?e:"")}),FB.Event.subscribe("edge.remove",function(e) {heateorSsmiMycredPoints("Facebook_like_recommend","",e?e:"","Minus point(s) for undoing Facebook like-recommend")}) ),'. ( defined( 'HEATEOR_SHARING_GOOGLE_ANALYTICS_VERSION' ) ? 1 : 0 ) .'&&(FB.Event.subscribe("edge.create",function(e) {heateorSsgaSocialPluginsTracking("Facebook","Like",e?e:"")}),FB.Event.subscribe("edge.remove",function(e) {heateorSsgaSocialPluginsTracking("Facebook","Unlike",e?e:"")}) )},function(e) {var n,i="facebook-jssdk",o=e.getElementsByTagName("script")[0];e.getElementById(i)||(n=e.createElement("script"),n.id=i,n.async=!0,n.src="//connect.facebook.net/'. ( $this->options['language'] ? $this->options['language'] : 'en_US' ) .'/sdk.js",o.parentNode.insertBefore(n,o) )}(document);'; } if ( current_filter() == 'amp_post_template_head' ) { // default post url global $post; $post_url = html_entity_decode( esc_url( $this->get_http_protocol() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ) ); if ( $this->options['horizontal_target_url'] == 'default' ) { $post_url = get_permalink( $post->ID ); if ( $post_url == '' ) { $post_url = html_entity_decode( esc_url( $this->get_http_protocol() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ) ); } } elseif ( $this->options['horizontal_target_url'] == 'home' ) { $post_url = home_url(); } elseif ( $this->options['horizontal_target_url'] == 'custom' ) { $post_url = $this->options['horizontal_target_url_custom'] ? $this->options['horizontal_target_url_custom'] : get_permalink( $post->ID ); } $sharing_url = $this->get_short_url( $post_url, $post->ID ); $post_title = $post->post_title; $post_title = $this->sanitize_post_title( $post_title ); $inline_script .= 'var heateorSssAmpTargetUrl = \''. $post_url .'\'; heateorSssLoadEvent( function(){ var moreIcons = document.getElementsByClassName("heateorSssMoreBackground"); for(var i = 0; i < moreIcons.length; i++){ moreIcons[i].onclick = function(){ heateorSssMoreSharingPopup(null, \''. ( $sharing_url ? $sharing_url : $post_url) .'\', \''. $post_title .'\', \''. $this->sanitize_post_title( $this->wpseo_twitter_title( $post ) ) .'\') } } var printIcons = document.getElementsByClassName("heateorSssPrintBackground"); for(var i = 0; i < printIcons.length; i++){ printIcons[i].onclick = function(){ window.print(); } } var pinterestIcons = document.getElementsByClassName("heateorSssPinterestBackground"); for(var i = 0; i < pinterestIcons.length; i++){ pinterestIcons[i].onclick = function(){ var e = document.createElement(\'script\');e.setAttribute(\'type\',\'text/javascript\');e.setAttribute(\'charset\',\'UTF-8\');e.setAttribute(\'src\',\'//assets.pinterest.com/js/pinmarklet.js?r=\'+Math.random()*99999999);document.body.appendChild(e); } } } ); function heateorSssCapitaliseFirstLetter(e) { return e.charAt(0).toUpperCase() + e.slice(1) } /** * Search sharing services */ function heateorSssFilterSharing(val) { var sharingServices = document.getElementById(\'heateor_sss_sharing_more_content\').getElementsByTagName(\'a\'); for(var i = 0; i < sharingServices.length; i++){ if (sharingServices[i].innerText.toLowerCase().indexOf(val.toLowerCase()) != -1) { sharingServices[i].parentNode.style.display = \'block\'; //jQuery(this).parent().css(\'display\', \'block\'); } else { sharingServices[i].parentNode.style.display = \'none\'; } } }; function heateorSssMoreSharingPopup(elem, postUrl, postTitle, twitterTitle){ postUrl = encodeURIComponent(postUrl); concate = \'\'; var heateorSssMoreSharingServices = { facebook: { title: "Facebook", locale: "en-US", redirect_url: "http://www.facebook.com/sharer.php?u=" + postUrl + "&t=" + postTitle + "&v=3", }, twitter: { title: "Twitter", locale: "en-US", redirect_url: "http://twitter.com/intent/tweet?text=" + (twitterTitle ? twitterTitle : postTitle) + " " + postUrl, }, linkedin: { title: "Linkedin", locale: "en-US", redirect_url: "http://www.linkedin.com/shareArticle?mini=true&url=" + postUrl + "&title=" + postTitle, }, pinterest: { title: "Pinterest", locale: "en-US", redirect_url: "https://pinterest.com/pin/create/button/?url=" + postUrl + "&media=${media_link}&description=" + postTitle, bookmarklet_url: "javascript:void((function(){var e=document.createElement(\'script\');e.setAttribute(\'type\',\'text/javascript\');e.setAttribute(\'charset\',\'UTF-8\');e.setAttribute(\'src\',\'//assets.pinterest.com/js/pinmarklet.js?r=\'+Math.random()*99999999);document.body.appendChild(e)})());" }, CopyLink: { title: "Copy Link", locale: "en-US", redirect_url: "", bookmarklet_url: "" }, Diaspora: { title: "Diaspora", locale: "en-US", redirect_url: "https://joindiaspora.com/bookmarklet?url=" + postUrl + "&title=" + postTitle + "&v=1" }, Douban: { title: "Douban", locale: "en-US", redirect_url: "https://www.douban.com/share/service?name="+postTitle+"&href="+postUrl+"&image=&updated=&bm=&url="+postUrl+"&title="+postTitle+"&sel=" }, Draugiem: { title: "Draugiem", locale: "en-US", redirect_url: "https://www.draugiem.lv/say/ext/add.php?link="+postUrl+"&title="+postTitle }, Facebook_Messenger: { title: "Facebook Messenger", locale: "en-US", redirect_url: "https://www.facebook.com/dialog/send?app_id=1904103319867886&display=popup&link="+postUrl+"&redirect_uri="+postUrl }, Google_Classroom: { title: "Google Classroom", locale: "en-US", redirect_url: "https://classroom.google.com/u/0/share?url="+postUrl }, Kik: { title: "Kik", locale: "en-US", redirect_url: "https://www.kik.com/send/article/?app_name=Share&text=&title="+postTitle+"&url="+postUrl }, Papaly: { title: "Papaly", locale: "en-US", redirect_url: "https://papaly.com/api/share.html?url="+postUrl+"&title="+postTitle }, Polyvore: { title: "Polyvore", locale: "en-US", bookmarklet_url: "javascript:(function(){function e(a){var c=window;if(c.PolyvoreClipper){c.PolyvoreClipper.run()}else{var b=a.createElement(\'script\');c._polyvoreMode=\'prod\';c._polyvoreHost=\'www.polyvore.com\';b.src=\'http://akwww.polyvorecdn.com/rsrc/clipper.js?\'+Math.floor((new Date()).getTime()/86400000);a.body.appendChild(b)}}try{e(document)}catch(g){}for(var f=0;f
    \'; for(var i in heateorSssMoreSharingServices){ var tempTitle = heateorSssCapitaliseFirstLetter(heateorSssMoreSharingServices[i].title.replace(/[_. ]/g, "")); heateorSssMoreSharingServicesHtml += \'
  • \' + heateorSssMoreSharingServices[i].title + \'
  • \'; } heateorSssMoreSharingServicesHtml += concate; var mainDiv = document.createElement(\'div\'); mainDiv.innerHTML = heateorSssMoreSharingServicesHtml; mainDiv.setAttribute(\'id\', \'heateor_sss_sharing_more_providers\'); var bgDiv = document.createElement(\'div\'); bgDiv.setAttribute(\'id\', \'heateor_sss_popup_bg\'); document.body.appendChild(mainDiv); document.body.appendChild(bgDiv); document.getElementById(\'heateor_sss_sharing_popup_close\').onclick = function(){ mainDiv.parentNode.removeChild(mainDiv); bgDiv.parentNode.removeChild(bgDiv); } }'; } $inline_script .= ';var heateorSssWhatsappShareAPI = "' . $this->whatsapp_share_api() . '";'; wp_enqueue_script( 'heateor_sss_sharing_js', plugins_url( 'js/sassy-social-share-public.js', __FILE__ ), array( 'jquery' ), $this->version, $in_footer ); wp_add_inline_script( 'heateor_sss_sharing_js', $inline_script, $position = 'before' ); } } } } /** * Determine which Whatsapp share url to use * * @since 3.2.13 */ private function whatsapp_share_api() { if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { // detect the device for Whatsapp share API $iphone = strpos( $_SERVER['HTTP_USER_AGENT'], "iPhone" ); $android = strpos( $_SERVER['HTTP_USER_AGENT'], "Android" ); $palmpre = strpos( $_SERVER['HTTP_USER_AGENT'], "webOS" ); $berry = strpos( $_SERVER['HTTP_USER_AGENT'], "BlackBerry" ); $ipod = strpos( $_SERVER['HTTP_USER_AGENT'], "iPod" ); // check if is a mobile if ( $iphone || $android || $palmpre || $ipod || $berry == true ) { return 'api'; } else { return 'web'; } } return 'api'; } /** * Check if Facebook Like/Recommend is enabled * * @since 1.0.0 */ private function facebook_like_recommend_enabled() { if ( ( isset( $this->options['hor_enable'] ) && isset( $this->options['horizontal_re_providers'] ) && ( in_array( 'facebook_like', $this->options['horizontal_re_providers'] ) || in_array( 'facebook_recommend', $this->options['horizontal_re_providers'] ) ) ) || ( isset( $this->options['vertical_enable'] ) && isset( $this->options['vertical_re_providers'] ) && ( in_array( 'facebook_like', $this->options['vertical_re_providers'] ) || in_array( 'facebook_recommend', $this->options['vertical_re_providers'] ) ) ) ) { return true; } return false; } /** * Check if Facebook Share is enabled * * @since 2.4 */ private function facebook_share_enabled() { if ( ( isset( $this->options['hor_enable'] ) && isset( $this->options['horizontal_re_providers'] ) && ( in_array( 'facebook_share', $this->options['horizontal_re_providers'] ) ) ) || ( isset( $this->options['vertical_enable'] ) && isset( $this->options['vertical_re_providers'] ) && ( in_array( 'facebook_share', $this->options['vertical_re_providers'] ) ) ) ) { return true; } return false; } /** * Generate bitly short url for sharing buttons * * @since 1.0.0 */ public function generate_bitly_url( $url, $post_id = 0 ) { $bitlyUrl = get_post_meta( $post_id, '_heateor_sss_bitly_url', true ); if ( $bitlyUrl ) { return $bitlyUrl; } else { //generate the URL $bitly = 'http://api.bit.ly/v3/shorten?format=txt&login=' . $this->options['bitly_username'] . '&apiKey=' . $this->options['bitly_key'] . '&longUrl=' . urlencode( $url ); $response = wp_remote_get( $bitly, array( 'timeout' => 15 ) ); if ( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ) { $short_url = trim( wp_remote_retrieve_body( $response ) ); update_post_meta( $post_id, '_heateor_sss_bitly_url', $short_url ); return $short_url; } } return false; } /** * Get short url. * * @since 1.0.0 */ public function get_short_url( $url, $post_id ) { $short_url = ''; if ( isset( $this->short_urls[$url] ) ) { // short url already calculated for this post ID $short_url = $this->short_urls[$url]; } elseif ( isset( $this->options['use_shortlinks'] ) && function_exists( 'wp_get_shortlink' ) ) { $short_url = wp_get_shortlink(); if ( $short_url ) { $this->short_urls[$url] = $short_url; } // if bit.ly integration enabled, generate bit.ly short url } elseif ( isset( $this->options['bitly_enable'] ) && $this->options['bitly_username'] != '' && $this->options['bitly_key'] != '' ) { $short_url = $this->generate_bitly_url( $url, $post_id ); if ( $short_url ) { $this->short_urls[$url] = $short_url; } } return $short_url; } /** * Check if current page is AMP * * @since 2.1 */ public function is_amp_page() { if ( ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) || ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) ) { return true; } return false; } /** * Sanitize post title * * @since 2.5.1 */ public function sanitize_post_title( $post_title ) { $post_title = html_entity_decode( $post_title, ENT_QUOTES, 'UTF-8' ); $post_title = rawurlencode( $post_title ); $post_title = str_replace( '#', '%23', $post_title ); $post_title = esc_html( $post_title ); return $post_title; } /** * Get Yoast SEO post meta Twitter title * * @since 2.5.1 */ public function wpseo_twitter_title( $post ) { if ( $post && ( $this->is_plugin_active( 'wordpress-seo/wp-seo.php' ) || $this->is_plugin_active( 'wordpress-seo-premium/wp-seo.php' ) ) && ( $wpseo_twitter_title = WPSEO_Meta::get_value( 'twitter-title', $post->ID ) ) ) { return $wpseo_twitter_title; } return ''; } /** * Render sharing interface html * * @since 1.0.0 */ public function prepare_sharing_html( $post_url, $sharing_type = 'horizontal', $display_count, $total_shares, $standard_widget = false ) { global $post; if ( NULL === $post ) { $post = get_post( $this->share_count_transient_id ); } if ( ! is_object( $post ) ) { return ''; } if ( ( $sharing_type == 'vertical' && ! is_singular() ) || $standard_widget ) { $post_title = get_bloginfo( 'name' ) . " - " . get_bloginfo( 'description' ); if ( is_category() ) { $post_title = esc_attr( wp_strip_all_tags( stripslashes( single_cat_title( '', false ) ), true ) ); } elseif ( is_tag() ) { $post_title = esc_attr( wp_strip_all_tags( stripslashes( single_tag_title( '', false ) ), true ) ); } elseif ( is_tax() ) { $post_title = esc_attr( wp_strip_all_tags( stripslashes( single_term_title( '', false ) ), true ) ); } elseif ( is_search() ) { $post_title = esc_attr( wp_strip_all_tags( stripslashes( __( 'Search for' ) .' "' .get_search_query() .'"' ), true ) ); } elseif ( is_author() ) { $post_title = esc_attr( wp_strip_all_tags( stripslashes( get_the_author_meta( 'display_name', get_query_var( 'author' ) ) ), true ) ); } elseif ( is_archive() ) { if ( is_day() ) { $post_title = esc_attr( wp_strip_all_tags( stripslashes( get_query_var( 'day' ) . ' ' .single_month_title( ' ', false ) . ' ' . __( 'Archives' ) ), true ) ); } elseif ( is_month() ) { $post_title = esc_attr( wp_strip_all_tags( stripslashes( single_month_title( ' ', false ) . ' ' . __( 'Archives' ) ), true ) ); } elseif ( is_year() ) { $post_title = esc_attr( wp_strip_all_tags( stripslashes( get_query_var( 'year' ) . ' ' . __( 'Archives' ) ), true ) ); } } } else { $post_title = $post->post_title; } $original_post_title = html_entity_decode( $post_title, ENT_QUOTES, 'UTF-8' ); $post_title = $this->sanitize_post_title( $post_title ); $output = apply_filters( 'heateor_sss_sharing_interface_filter', '', $this, $post_title, $original_post_title, $post_url, $sharing_type, $this->options, $post, $display_count, $total_shares ); if ( $output != '' ) { return $output; } $html = ''; $sharing_meta = get_post_meta( $post->ID, '_heateor_sss_meta', true ); if ( isset( $this->options[$sharing_type.'_re_providers'] ) ) { $sharing_networks_object = new Sassy_Social_Share_Sharing_Networks( $this->options ); if ( $this->is_amp_page() ) { $sharing_networks = $sharing_networks_object->fetch_amp_sharing_networks(); } else { $sharing_networks = $sharing_networks_object->fetch_sharing_networks( $sharing_type ); } $html = $this->is_amp_page() ? '' : '
      '; $icon_height = $this->options[$sharing_type . '_sharing_shape'] != 'rectangle' ? $this->options[$sharing_type . '_sharing_size'] : $this->options[$sharing_type . '_sharing_height']; $style = 'style="width:' . ( $this->options[$sharing_type . '_sharing_shape'] != 'rectangle' ? $this->options[$sharing_type . '_sharing_size'] : $this->options[$sharing_type . '_sharing_width'] ) . 'px;height:' . $icon_height . 'px;'; $counter_container_init_html = 'options['language'] != '' ? $this->options['language'] : ''; $like_button_count_container = ''; if ( $display_count ) { $like_button_count_container = $counter_container_init_html . '"> ' . $counter_container_end_html; } // share count if ( $saved_share_count = $this->get_saved_share_counts( $this->share_count_transient_id, $post_url ) ) { $share_counts = $saved_share_count; } elseif ( false !== ( $cached_share_count = $this->get_cached_share_count( $this->share_count_transient_id ) ) ) { $share_counts = $cached_share_count; } else { $share_counts = ' '; } $counter_placeholder = ''; $counter_placeholder_value = ''; $inner_style_conditional = ''; if ( $display_count ) { if ( ! isset( $this->options[$sharing_type . '_counter_position'] ) ) { $counter_position = $sharing_type == 'horizontal' ? 'top' : 'inner_top'; } else { $counter_position = $this->options[$sharing_type . '_counter_position']; } switch ( $counter_position ) { case 'left': $inner_style_conditional = 'display:block;'; $counter_placeholder = '>', '>' . $counter_container_init_html . ' heateor_sss_%network%_count"> ' . $counter_container_end_html, $counter_placeholder ); } $twitter_username = $this->options['twitter_username'] != '' ? $this->options['twitter_username'] : ''; $total_share_count = 0; $share_count = array(); $to_be_replaced = array(); $replace_by = array(); if ( $this->is_amp_page() ) { $icon_width = $this->options[$sharing_type . '_sharing_shape'] != 'rectangle' ? $this->options[$sharing_type . '_sharing_size'] : $this->options[$sharing_type . '_sharing_width']; $to_be_replaced[] = '%img_url%'; $to_be_replaced[] = '%width%'; $to_be_replaced[] = '%height%'; $replace_by[] = plugins_url( '../images/amp', __FILE__ ); $replace_by[] = $icon_width; $replace_by[] = $icon_height; } $wpseo_post_title = $post_title; $decoded_post_title = esc_html( str_replace( array( '%23', '%27', '%22', '%21', '%3A' ), array( '#', "'", '"', '!', ':' ), urlencode( $original_post_title ) ) ); if ( $wpseo_twitter_title = $this->wpseo_twitter_title( $post ) ) { $wpseo_post_title = $this->sanitize_post_title( $wpseo_twitter_title ); $decoded_post_title = esc_html( str_replace( array( '%23', '%27', '%22', '%21', '%3A' ), array( '#', "'", '"', '!', ':' ), urlencode( html_entity_decode( $wpseo_twitter_title, ENT_QUOTES, 'UTF-8' ) ) ) ); } foreach ( $this->options[$sharing_type.'_re_providers'] as $provider ) { $share_count[$provider] = $share_counts == ' ' ? '' : ( isset( $share_counts[$provider] ) ? $share_counts[$provider] : '' ); $isset_starting_share_count = isset( $sharing_meta[$provider . '_' . $sharing_type . '_count'] ) && $sharing_meta[$provider . '_' . $sharing_type . '_count'] != '' ? true : false; $total_share_count += intval( $share_count[$provider] ) + ( $isset_starting_share_count ? $sharing_meta[$provider . '_' . $sharing_type . '_count'] : 0) ; $sharing_networks[$provider] = str_replace( $to_be_replaced, $replace_by, $sharing_networks[$provider] ); $li_items .= str_replace( array( '%padding%', '%network%', '%ucfirst_network%', '%like_count_container%', '%post_url%', '%encoded_post_url%', '%post_title%', '%wpseo_post_title%', '%decoded_post_title%', '%twitter_username%', '%via_twitter_username%', '%language%', '%buffer_username%', '%style%', '%inner_style%', '%li_class%', $counter_placeholder, '%title%', '%amp_email%', '%amp_whatsapp%' ), array( ( $this->options[$sharing_type . '_sharing_shape'] == 'rectangle' ? $this->options[$sharing_type . '_sharing_height'] : $this->options[$sharing_type . '_sharing_size'] ) * 21/100, $provider, ucfirst( str_replace( array( ' ', '_', '.' ), '', $provider ) ), $like_button_count_container, $post_url, urlencode( $post_url ), $post_title, $wpseo_post_title, $decoded_post_title, $twitter_username, $twitter_username ? 'via=' . $twitter_username . '&' : '', $language, $this->options['buffer_username'] != '' ? $this->options['buffer_username'] : '', $style, $inner_style . ( $share_count[$provider] || ( $isset_starting_share_count && $share_counts != ' ' ) ? $inner_style_conditional : '' ), $li_class, str_replace( '%network%', $provider, $isset_starting_share_count ? str_replace( '> ', ' sss_st_count="' . $sharing_meta[$provider . '_' . $sharing_type . '_count'] . '"' . ( $share_counts == ' ' ? '> ' : ' style="visibility:visible;' . ( $inner_style_conditional ? 'display:block;' : '' ) . '">' . $this->round_off_counts( intval( $share_count[$provider] ) + $sharing_meta[$provider . '_' . $sharing_type . '_count'] ) ) , $counter_placeholder_value ) : str_replace( '> ', $share_count[$provider] ? ' style="visibility:visible;' . ( $inner_style_conditional ? 'display:block;' : '' ) . '">' . $this->round_off_counts( intval( $share_count[$provider] ) ) : '> ', $counter_placeholder_value ) ), ucfirst( str_replace( '_', ' ', $provider ) ), '', '' ), $sharing_networks[$provider] ); } if ( isset( $this->options[$sharing_type . '_more'] ) && ! $this->is_amp_page() ) { $li_items .= '
    • '; if ( $display_count ) { $li_items .= $counter_container_init_html . '"> ' . $counter_container_end_html; } if ( $this->is_amp_page() ) { $li_items .= '
    • '; } else { $li_items .= ''; } } $total_shares_html = ''; if ( $total_shares && ! $this->is_amp_page() ) { $total_shares_html = '
    • '; if ( $display_count) { $total_shares_html .= $counter_container_init_html . '"> ' . $counter_container_end_html; } if ( $sharing_type == 'horizontal' ) { $add_style = ';margin-left:9px !important;'; } else { $add_style = ';margin-bottom:9px !important;'; } $add_style .= ( $total_share_count && $share_counts != ' ' ? 'visibility:visible;' : '' ) . '"'; $style = str_replace( ';"', $add_style, $style ); $total_shares_html .= '' . ( $total_share_count ? '
      ' . $this->round_off_counts( intval( $total_share_count ) ) . '
      ' . ( $total_share_count < 2 ? __( 'Share', 'sassy-social-share' ) : __( 'Shares', 'sassy-social-share' ) ) . '
      ' : '' ) . '
    • '; } if ( $sharing_type == 'vertical' ) { $html .= $total_shares_html . $li_items; } else { $html .= $li_items . $total_shares_html; } $html .= $this->is_amp_page() ? '' : '
    '; $html .= '
    '; } return $html; } /** * Roud off share counts * * @since 1.7 * @param integer $sharingCount Share counts */ public function round_off_counts( $sharing_count ) { if ( $sharing_count > 999 && $sharing_count < 10000 ) { $sharing_count = round( $sharing_count/1000, 1 ) . 'K'; } elseif ( $sharing_count > 9999 && $sharing_count < 100000 ) { $sharing_count = round( $sharing_count/1000, 1 ) . 'K'; } else if ( $sharing_count > 99999 && $sharing_count < 1000000 ) { $sharing_count = round( $sharing_count/1000, 1 ) . 'K'; } else if ( $sharing_count > 999999 ) { $sharing_count = round( $sharing_count/1000000, 1 ) . 'M'; } return $sharing_count; } /** * Get cached share counts for given post ID * * @since 1.7 * @param integer $post_id ID of the post to fetch cached share counts for */ public function get_cached_share_count( $post_id ) { $share_count_transient = get_transient( 'heateor_sss_share_count_' . $post_id ); do_action( 'heateor_sss_share_count_transient_hook', $share_count_transient, $post_id ); return $share_count_transient; } /** * Get saved share counts for given post ID * * @since 1.3.1 */ public function get_saved_share_counts( $post_id, $post_url ) { $share_counts = false; if ( $post_id == 'custom' ) { $share_counts = maybe_unserialize( get_option( 'heateor_sss_custom_url_shares' ) ); } elseif ( $post_url == home_url() ) { $share_counts = maybe_unserialize( get_option( 'heateor_sss_homepage_shares' ) ); } elseif ( $post_id > 0 ) { $share_counts = get_post_meta( $post_id, '_heateor_sss_shares_meta', true ); } return $share_counts; } /** * Get http/https protocol at the website * * @since 1.0.0 */ public function get_http_protocol() { if ( isset( $_SERVER['HTTPS'] ) && ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ) { return "https://"; } else { return "http://"; } } /** * Remove render sharing action from Excerpts, as it gets nasty due to strip_tags() * * @since 2.0 */ public function remove_render_sharing( $content ) { if ( is_home() ) { remove_action( 'the_content', array( $this, 'render_sharing' ), 99 ); } return $content; } /** * Apply share url filter to customize share target url * * @since 3.0 */ public function apply_target_share_url_filter( $post_url, $sharing_type = 'horizontal', $standard_widget = false ) { $post_url = apply_filters( 'heateor_sss_target_share_url_filter', $post_url, $sharing_type, $standard_widget ); return $post_url; } /** * Enable sharing interface at selected areas * * @since 1.0.0 */ public function render_sharing( $content ) { // if sharing is disabled on AMP, return content as is if ( ! isset( $this->options['amp_enable'] ) && $this->is_amp_page() ) { return $content; } global $post; if ( ! is_object( $post ) ) { return $content; } // hook to bypass sharing $disable_sharing = apply_filters( 'heateor_sss_disable_sharing', $post, $content ); // if $disable_sharing value is 1, return content without sharing interface if ( $disable_sharing === 1 ) { return $content; } $sharing_meta = get_post_meta( $post->ID, '_heateor_sss_meta', true ); $sharing_bp_activity = false; if ( current_filter() == 'bp_activity_entry_meta' ) { if ( isset( $this->options['bp_activity'] ) ) { $sharing_bp_activity = true; } } $post_types = get_post_types( array( 'public' => true ), 'names', 'and' ); $post_types = array_diff( $post_types, array( 'post', 'page' ) ); // sharing interface if ( isset( $this->options['hor_enable'] ) && ! ( isset( $sharing_meta['sharing'] ) && $sharing_meta['sharing'] == 1 && ( ! is_front_page() || ( is_front_page() && 'page' == get_option( 'show_on_front' ) ) ) ) ) { $post_id = $post -> ID; // default post url $post_url = get_permalink( $post->ID ); $share_count_url = $post_url; if ( $sharing_bp_activity ) { $post_url = bp_get_activity_thread_permalink(); $share_count_url = $post_url; $post_id = 0; } else { if ( $this->options['horizontal_target_url'] == 'default' ) { if ( ( isset( $_SERVER['QUERY_STRING'] ) && $_SERVER['QUERY_STRING'] ) || $post_url == '' ) { $post_url = html_entity_decode( esc_url( $this->get_http_protocol() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ) ); } if ( $share_count_url == '' ) { $share_count_url = $post_url; } } elseif ( $this->options['horizontal_target_url'] == 'home' ) { $post_url = home_url(); $share_count_url = $post_url; $post_id = 0; } elseif ( $this->options['horizontal_target_url'] == 'custom' ) { $post_url = $this->options['horizontal_target_url_custom'] ? $this->options['horizontal_target_url_custom'] : get_permalink( $post->ID ); $share_count_url = $post_url; $post_id = 0; } } $custom_post_url = $this->apply_target_share_url_filter( $post_url, 'horizontal', false ); if ( $custom_post_url != $post_url ) { $post_url = $custom_post_url; $share_count_url = $post_url; } $sharing_url = $this->get_short_url( $post_url, $post->ID ); // share count transient ID $this->share_count_transient_id = $this->get_share_count_transient_id( $post_url ); $sharing_div = $this->prepare_sharing_html( $sharing_url ? $sharing_url : $post_url, 'horizontal', isset( $this->options['horizontal_counts'] ), isset( $this->options['horizontal_total_shares'] ) ); $sharing_container_style = ''; $sharing_title_style = 'style="font-weight:bold"'; if ( $this->options['hor_sharing_alignment'] == 'right' ) { $sharing_container_style = 'style="float: right"'; } $horizontal_div = "
    is_amp_page() ? "" : "heateor-sss-data-href='" . ( isset( $share_count_url ) && $share_count_url ? $share_count_url : $post_url ) . "'" ) . ( ( $this->get_cached_share_count( $this->share_count_transient_id ) === false || $this->is_amp_page() ) ? '' : 'heateor-sss-no-counts="1"' ) . ">
    " . ucfirst( $this->options['title'] ) . "
    " . $sharing_div . "
    "; if ( $sharing_bp_activity ) { echo $horizontal_div; } // show horizontal sharing if ( ( isset( $this->options['home'] ) && is_front_page() ) || ( isset( $this->options['category'] ) && is_category() ) || ( isset( $this->options['archive'] ) && is_archive() ) || ( isset( $this->options['post'] ) && is_single() && isset( $post -> post_type ) && $post -> post_type == 'post' ) || ( isset( $this->options['page'] ) && is_page() && isset( $post -> post_type ) && $post -> post_type == 'page' ) || ( isset( $this->options['excerpt'] ) && (is_home() || current_filter() == 'the_excerpt' ) ) || ( isset( $this->options['bb_reply'] ) && current_filter() == 'bbp_get_reply_content' ) || ( isset( $this->options['bb_forum'] ) && ( isset( $this->options['top'] ) && current_filter() == 'bbp_template_before_single_forum' || isset( $this->options['bottom'] ) && current_filter() == 'bbp_template_after_single_forum' ) ) || ( isset( $this->options['bb_topic'] ) && ( isset( $this->options['top'] ) && in_array( current_filter(), array( 'bbp_template_before_single_topic', 'bbp_template_before_lead_topic' ) ) || isset( $this->options['bottom'] ) && in_array( current_filter(), array( 'bbp_template_after_single_topic', 'bbp_template_after_lead_topic' ) ) ) ) || ( isset( $this->options['woocom_shop'] ) && current_filter() == 'woocommerce_after_shop_loop_item' ) || ( isset( $this->options['woocom_product'] ) && current_filter() == 'woocommerce_share' ) || ( isset( $this->options['woocom_thankyou'] ) && current_filter() == 'woocommerce_thankyou' ) || (current_filter() == 'bp_before_group_header' && isset( $this->options['bp_group'] ) ) ) { if ( in_array( current_filter(), array( 'bbp_template_before_single_topic', 'bbp_template_before_lead_topic', 'bbp_template_before_single_forum', 'bbp_template_after_single_topic', 'bbp_template_after_lead_topic', 'bbp_template_after_single_forum', 'woocommerce_after_shop_loop_item', 'woocommerce_share', 'woocommerce_thankyou', 'bp_before_group_header' ) ) ) { echo '
    ' . $horizontal_div . '
    '; } else { if ( isset( $this->options['top'] ) && isset( $this->options['bottom'] ) ) { $content = $horizontal_div . '
    ' . $content . '
    ' . $horizontal_div; } else { if ( isset( $this->options['top'] ) ) { $content = $horizontal_div.$content; } elseif ( isset( $this->options['bottom'] ) ) { $content = $content.$horizontal_div; } } } } elseif ( count( $post_types ) ) { foreach ( $post_types as $post_type ) { if ( isset( $this->options[$post_type] ) && ( is_single() || is_page() ) && isset( $post -> post_type ) && $post -> post_type == $post_type ) { if ( isset( $this->options['top'] ) && isset( $this->options['bottom'] ) ) { $content = $horizontal_div . '
    ' . $content.'
    '.$horizontal_div; } else { if ( isset( $this->options['top'] ) ) { $content = $horizontal_div.$content; } elseif ( isset( $this->options['bottom'] ) ) { $content = $content.$horizontal_div; } } } } } } if ( isset( $this->options['vertical_enable'] ) && ! ( isset( $sharing_meta['vertical_sharing'] ) && $sharing_meta['vertical_sharing'] == 1 && ( ! is_front_page() || ( is_front_page() && 'page' == get_option( 'show_on_front' ) ) ) ) ) { $post_id = $post -> ID; $post_url = get_permalink( $post->ID ); $share_count_url = $post_url; if ( $this->options['vertical_target_url'] == 'default' ) { $post_url = get_permalink( $post->ID ); if ( ! is_singular() ) { $post_url = html_entity_decode( esc_url( $this->get_http_protocol() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ) ); $post_id = 0; $share_count_url = $post_url; } elseif ( ( isset( $_SERVER['QUERY_STRING'] ) && $_SERVER['QUERY_STRING'] ) || $post_url == '' ) { $post_url = html_entity_decode( esc_url( $this->get_http_protocol() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ) ); } if ( $share_count_url == '' ) { $share_count_url = $post_url; } } elseif ( $this->options['vertical_target_url'] == 'home' ) { $post_url = home_url(); $share_count_url = $post_url; $post_id = 0; } elseif ( $this->options['vertical_target_url'] == 'custom' ) { $post_url = $this->options['vertical_target_url_custom'] ? $this->options['vertical_target_url_custom'] : get_permalink( $post->ID ); $share_count_url = $post_url; $post_id = 0; } $custom_post_url = $this->apply_target_share_url_filter( $post_url, 'vertical', false ); if ( $custom_post_url != $post_url ) { $post_url = $custom_post_url; $share_count_url = $post_url; } $sharing_url = $this->get_short_url( $post_url, $post->ID ); $vertical_sharing_width = ( $this->options['vertical_sharing_shape'] == 'rectangle' ? $this->options['vertical_sharing_width'] : $this->options['vertical_sharing_size'] ); if ( isset( $this->options['vertical_counts'] ) && isset( $this->options['vertical_counter_position'] ) && in_array( $this->options['vertical_counter_position'], array( 'left', 'right' ) ) ) { $vertical_sharing_width += $vertical_sharing_width*60/100; } // share count transient ID $this->share_count_transient_id = $this->get_share_count_transient_id( $post_url ); $sharing_div = $this->prepare_sharing_html( $sharing_url ? $sharing_url : $post_url, 'vertical', isset( $this->options['vertical_counts'] ), isset( $this->options['vertical_total_shares'] ) ); $offset = ( $this->options['alignment'] != '' && $this->options[$this->options['alignment'].'_offset'] != '' ? $this->options['alignment'] . ': ' . $this->options[$this->options['alignment'].'_offset'] . 'px;' : '' ) . ( $this->options['top_offset'] != '' ? 'top: '.$this->options['top_offset'] . 'px;' : '' ); $vertical_div = "
    options['vertical_bg'] : '-webkit-box-shadow:none;box-shadow:none;' ) . "' " . ( $this->is_amp_page() ? "" : "heateor-sss-data-href='" . ( isset( $share_count_url ) && $share_count_url ? $share_count_url : $post_url ) . "'" ) . ( ( $this->get_cached_share_count( $this->share_count_transient_id ) === false || $this->is_amp_page() ) ? "" : 'heateor-sss-no-counts="1"' ) . ">" . $sharing_div . "
    "; // show vertical sharing if ( ( isset( $this->options['vertical_home'] ) && is_front_page() ) || ( isset( $this->options['vertical_category'] ) && is_category() ) || ( isset( $this->options['vertical_archive'] ) && is_archive() ) || ( isset( $this->options['vertical_post'] ) && is_single() && isset( $post -> post_type ) && $post -> post_type == 'post' ) || ( isset( $this->options['vertical_page'] ) && is_page() && isset( $post -> post_type ) && $post -> post_type == 'page' ) || ( isset( $this->options['vertical_excerpt'] ) && (is_home() || current_filter() == 'the_excerpt' ) ) || ( isset( $this->options['vertical_bb_forum'] ) && current_filter() == 'bbp_template_before_single_forum' ) || ( isset( $this->options['vertical_bb_topic'] ) && in_array( current_filter(), array( 'bbp_template_before_single_topic', 'bbp_template_before_lead_topic' ) ) ) || (current_filter() == 'bp_before_group_header' && isset( $this->options['vertical_bp_group'] ) ) ) { if ( in_array( current_filter(), array( 'bbp_template_before_single_topic', 'bbp_template_before_lead_topic', 'bbp_template_before_single_forum', 'bp_before_group_header' ) ) ) { echo $vertical_div; } else { if ( is_front_page() ) { if ( current_filter() == 'the_content' ) { $var = $this->vertical_home_count; } elseif ( is_home() || current_filter() == 'the_excerpt' ) { $var = $this->vertical_excerpt_count; } if ( $var == 0 ) { if ( $this->options['vertical_target_url'] == 'default' ) { $post_url = home_url(); $share_count_url = $post_url; $custom_post_url = $this->apply_target_share_url_filter( $post_url, 'vertical', false ); if ( $custom_post_url != $post_url ) { $post_url = $custom_post_url; $share_count_url = $post_url; } $sharing_url = $this->get_short_url( $post_url, 0 ); // share count transient ID $this->share_count_transient_id = 0; $sharing_div = $this->prepare_sharing_html( $sharing_url ? $sharing_url : $post_url, 'vertical', isset( $this->options['vertical_counts'] ), isset( $this->options['vertical_total_shares'] ) ); $vertical_div = "
    options['vertical_bg'] : '-webkit-box-shadow:none;box-shadow:none;' ) . "' " . ( $this->is_amp_page() ? "" : "heateor-sss-data-href='" . ( isset( $share_count_url ) && $share_count_url ? $share_count_url : $post_url ) . "'" ) . ( ( $this->get_cached_share_count( 0 ) === false || $this->is_amp_page() ) ? "" : 'heateor-sss-no-counts="1"' ) . ">" . $sharing_div . "
    "; } $content = $content . $vertical_div; if ( current_filter() == 'the_content' ) { $this->vertical_home_count++; } elseif ( is_home() || current_filter() == 'the_excerpt' ) { $this->vertical_excerpt_count++; } } } else { $content = $content . $vertical_div; } } } elseif ( count( $post_types ) ) { foreach ( $post_types as $post_type ) { if ( isset( $this->options['vertical_' . $post_type] ) && ( is_single() || is_page() ) && isset( $post -> post_type ) && $post -> post_type == $post_type ) { $content = $content . $vertical_div; } } } } return $content; } /** * Return ajax response * * @since 1.0.0 */ private function ajax_response( $response ) { $response = apply_filters( 'heateor_sss_ajax_response_filter', $response ); die( json_encode( $response ) ); } /** * Fetch Facebook access token * * @since 3.2.20 */ private function fetch_fb_access_token() { if ( $this->options['fb_key'] && $this->options['fb_secret'] ) { return $this->options['fb_key'] . '|' . $this->options['fb_secret']; } return false; } /** * Get share counts for sharing networks * * @since 1.0.0 */ public function fetch_share_counts() { if ( isset( $_GET['urls'] ) && count( $_GET['urls'] ) > 0 ) { $target_urls = array_unique( $_GET['urls'] ); foreach ( $target_urls as $k => $v ) { $target_urls[$k] = esc_attr( $v ); } } else { $this->ajax_response( array( 'status' => 0, 'message' => __( 'Invalid request' ) ) ); } $horizontal_sharing_networks = isset( $this->options['horizontal_re_providers'] ) ? $this->options['horizontal_re_providers'] : array(); $vertical_sharing_networks = isset( $this->options['vertical_re_providers'] ) ? $this->options['vertical_re_providers'] : array(); $sharing_networks = array_unique( array_merge( $horizontal_sharing_networks, $vertical_sharing_networks ) ); if ( count( $sharing_networks ) == 0 ) { $this->ajax_response( array( 'status' => 0, 'message' => __( 'Providers not selected' ) ) ); } $response_data = array(); $ajax_response = array(); $multiplier = 60; if ( $this->options['share_count_cache_refresh_count'] != '' ) { switch ( $this->options['share_count_cache_refresh_unit'] ) { case 'seconds': $multiplier = 1; break; case 'minutes': $multiplier = 60; break; case 'hours': $multiplier = 3600; break; case 'days': $multiplier = 3600*24; break; default: $multiplier = 60; break; } $transient_expiration_time = $multiplier * $this->options['share_count_cache_refresh_count']; } $target_urls_array = array(); $target_urls_array[] = $target_urls; $target_urls_array = apply_filters( 'heateor_sss_target_share_urls', $target_urls_array ); $share_count_transient_array = array(); if ( in_array( 'facebook', $sharing_networks ) ) { $ajax_response['facebook_urls'] = $target_urls_array; } foreach ( $target_urls_array as $target_urls ) { $share_count_transients = array(); foreach ( $target_urls as $target_url ) { $share_count_transient = array(); foreach ( $sharing_networks as $provider ) { switch ( $provider ) { case 'facebook': $fb_access_token = $this->fetch_fb_access_token(); if ( $fb_access_token ) { $url = "https://graph.facebook.com/?access_token=" . $fb_access_token . "&fields=engagement&id=" . $target_url; } else { $url = ''; } break; case 'twitter': $url = "https://counts.twitcount.com/counts.php?url=" . $target_url; break; case 'linkedin': $url = 'https://www.linkedin.com/countserv/count/share?url=' . $target_url . '&format=json'; break; case 'reddit': $url = 'https://www.reddit.com/api/info.json?url=' . $target_url; break; case 'pinterest': $url = 'https://api.pinterest.com/v1/urls/count.json?callback=heateorSss&url=' . $target_url; break; case 'buffer': $url = 'https://api.bufferapp.com/1/links/shares.json?url=' . $target_url; break; case 'vkontakte': $url = 'https://vk.com/share.php?act=count&url=' . $target_url; break; case 'Odnoklassniki': $url = 'https://connect.ok.ru/dk?st.cmd=extLike&tp=json&ref='. $target_url; break; case 'Fintel': $url = 'https://fintel.io/api/pageStats?url='. $target_url; break; default: $url = ''; } if ( $url == '' ) { continue; } $response = wp_remote_get( $url, array( 'timeout' => 15, 'user-agent' => 'Sassy-Social-Share' ) ); if ( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ) { $body = wp_remote_retrieve_body( $response ); if ( $provider == 'pinterest' ) { $body = str_replace( array( 'heateorSss(', ')' ), '', $body ); } if ( $provider != 'vkontakte' ) { $body = json_decode( $body ); } switch ( $provider ) { case 'facebook': if ( ! empty( $body -> engagement ) && isset( $body -> engagement -> share_count ) ) { $share_count_transient['facebook'] = ( isset( $body -> engagement -> reaction_count ) ? $body -> engagement -> reaction_count : 0 ) + ( isset( $body -> engagement -> comment_count ) ? $body -> engagement -> comment_count : 0 ) + $body -> engagement -> share_count; } else { $share_count_transient['facebook'] = 0; } break; case 'twitter': if ( ! empty( $body -> count ) ) { $share_count_transient['twitter'] = $body -> count; } else { $share_count_transient['twitter'] = 0; } break; case 'linkedin': if ( ! empty( $body -> count ) ) { $share_count_transient['linkedin'] = $body -> count; } else { $share_count_transient['linkedin'] = 0; } break; case 'reddit': $share_count_transient['reddit'] = 0; if ( ! empty( $body -> data -> children ) ) { $children = $body -> data -> children; $ups = $downs = 0; foreach ( $children as $child ) { $ups += ( int ) $child->data->ups; $downs += ( int ) $child->data->downs; } $score = $ups - $downs; if ( $score < 0 ) { $score = 0; } $share_count_transient['reddit'] = $score; } break; case 'pinterest': if ( ! empty( $body -> count ) ) { $share_count_transient['pinterest'] = $body -> count; } else { $share_count_transient['pinterest'] = 0; } break; case 'buffer': if ( ! empty( $body -> shares ) ) { $share_count_transient['buffer'] = $body -> shares; } else { $share_count_transient['buffer'] = 0; } break; case 'vkontakte': if ( ! empty( $body ) ) { $share_count_transient['vkontakte'] = (int) str_replace( array( 'VK.Share.count(0, ', ' );' ), '', $body ); } else { $share_count_transient['vkontakte'] = 0; } break; case 'Odnoklassniki': if ( ! empty( $body ) && isset( $body -> count ) ) { $share_count_transient['Odnoklassniki'] = $body -> count; } else { $share_count_transient['Odnoklassniki'] = 0; } break; case 'Fintel': if ( ! empty( $body ) && isset( $body -> points ) ) { $share_count_transient['Fintel'] = $body -> points; } else { $share_count_transient['Fintel'] = 0; } break; } } else { $share_count_transient[$provider] = 0; } } $share_count_transients[] = $share_count_transient; } $share_count_transient_array[] = $share_count_transients; } $final_share_count_transient = array(); for ( $i = 0; $i < count( $target_urls_array[0] ); $i++ ) { $final_share_count_transient = $share_count_transient_array[0][$i]; for ( $j = 1; $j < count( $share_count_transient_array ); $j++ ) { foreach ( $final_share_count_transient as $key => $val ) { $final_share_count_transient[$key] += $share_count_transient_array[$j][$i][$key]; } } $response_data[$target_urls_array[0][$i]] = $final_share_count_transient; if ( $this->options['share_count_cache_refresh_count'] != '' ) { set_transient( 'heateor_sss_share_count_' . $this->get_share_count_transient_id( $target_urls_array[0][$i] ), $final_share_count_transient, $transient_expiration_time ); // update share counts saved in the database $this->update_share_counts( $target_urls_array[0][$i], $final_share_count_transient ); } } do_action( 'heateor_sss_share_count_ajax_hook', $response_data ); $ajax_response['status'] = 1; $ajax_response['message'] = $response_data; $this->ajax_response( $ajax_response ); } /** * Save share counts in post-meta * * @since 3.1.3 */ public function update_share_counts( $target_url, $share_counts ) { $post_id = $this->get_share_count_transient_id( $target_url ); if ( ! isset( $share_counts['facebook'] ) ) { $saved_share_count = $this->get_saved_share_counts( $post_id, $target_url ); if ( is_array( $saved_share_count ) && isset( $saved_share_count['facebook'] ) ) { $share_counts['facebook'] = $saved_share_count['facebook']; } } if ( $post_id == 'custom' ) { update_option( 'heateor_sss_custom_url_shares', maybe_serialize( $share_counts ) ); } elseif ( $target_url == home_url() ) { update_option( 'heateor_sss_homepage_shares', maybe_serialize( $share_counts ) ); } elseif ( $post_id > 0 ) { update_post_meta( $post_id, '_heateor_sss_shares_meta', $share_counts ); } } /** * Save Facebook share counts in transient * * @since 2.4.2 */ public function save_facebook_shares() { if ( isset( $_GET['share_counts'] ) && is_array( $_GET['share_counts'] ) && count( $_GET['share_counts'] ) > 0 ) { $target_urls = $_GET['share_counts']; foreach ( $target_urls as $k => $v ) { $target_urls[$k] = esc_attr( trim( $v ) ); } } else { $this->ajax_response( array( 'status' => 0, 'message' => __( 'Invalid request' ) ) ); } $multiplier = 60; if ( $this->options['share_count_cache_refresh_count'] != '' ) { switch ( $this->options['share_count_cache_refresh_unit'] ) { case 'seconds': $multiplier = 1; break; case 'minutes': $multiplier = 60; break; case 'hours': $multiplier = 3600; break; case 'days': $multiplier = 3600*24; break; default: $multiplier = 60; break; } $transient_expiration_time = $multiplier * $this->options['share_count_cache_refresh_count']; } foreach ( $target_urls as $key => $value ) { $transient_id = $this->get_share_count_transient_id( $key ); $share_count_transient = get_transient( 'heateor_sss_share_count_' . $transient_id ); if ( $share_count_transient !== false ) { $share_count_transient['facebook'] = $value; if ( $this->options['share_count_cache_refresh_count'] != '' ) { $saved_share_count = $this->get_saved_share_counts( $transient_id, $key ); $saved_share_count['facebook'] = $value; set_transient( 'heateor_sss_share_count_' . $transient_id, $share_count_transient, $transient_expiration_time ); $this->update_share_counts( $key, $saved_share_count ); } } } die; } /** * Get ID of the share count transient * * @since 1.0.0 */ public function get_share_count_transient_id( $target_url ) { if ( $this->options['horizontal_target_url_custom'] == $target_url || $this->options['vertical_target_url_custom'] == $target_url ) { $post_id = 'custom'; } else { $post_id = url_to_postid( $target_url ); } return $post_id; } /** * Check if plugin is active * * @since 2.5.1 */ private function is_plugin_active( $plugin_file ) { return in_array( $plugin_file, apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ); } /** * Inline style to load at front end. * * @since 2.0 */ public function frontend_inline_style() { if ( current_filter() == 'wp_enqueue_scripts' ) { $important = ''; ?>version ); $default_svg = false; if ( isset( $this->options['hor_enable'] ) ) { if ( isset( $this->options['horizontal_more'] ) ) { $default_svg = true; } if ( $this->options['horizontal_font_color_default'] != '' ) { wp_enqueue_style( 'heateor_sss_sharing_svg', plugins_url( 'admin/css/sassy-social-share-default-svg-horizontal.css', dirname( __FILE__ ) ), false, $this->version ); } else { $default_svg = true; } if ( $this->options['horizontal_font_color_hover'] != '' ) { wp_enqueue_style( 'heateor_sss_sharing_svg_hover', plugins_url( 'admin/css/sassy-social-share-hover-svg-horizontal.css', dirname( __FILE__ ) ), false, $this->version ); } } if ( isset( $this->options['vertical_enable'] ) ) { if ( isset( $this->options['vertical_more'] ) ) { $default_svg = true; } if ( $this->options['vertical_font_color_default'] != '' ) { wp_enqueue_style( 'heateor_sss_vertical_sharing_svg', plugins_url( 'admin/css/sassy-social-share-default-svg-vertical.css', dirname( __FILE__ ) ), false, $this->version ); } else { $default_svg = true; } if ( $this->options['vertical_font_color_hover'] != '' ) { wp_enqueue_style( 'heateor_sss_vertical_sharing_svg_hover', plugins_url( 'admin/css/sassy-social-share-hover-svg-vertical.css', dirname( __FILE__ ) ), false, $this->version ); } } if ( $default_svg ) { wp_enqueue_style( 'heateor_sss_sharing_default_svg', plugins_url( 'admin/css/sassy-social-share-svg.css', dirname( __FILE__ ) ), false, $this->version ); } } /** * Stylesheets to load at front end for AMP. * * @since 2.0 */ public function frontend_amp_css() { $css = ''; if ( current_action() == 'wp_print_styles' ) { $css .= ''; } echo $css; } /** * Append myCRED referral ID to share and like button urls * * @since 3.0 */ public function append_mycred_referral_id( $post_url, $sharing_type, $standard_widget ) { $mycred_referral_id = do_shortcode( '[mycred_affiliate_id]' ); if ( $mycred_referral_id ) { $connector = strpos( urldecode( $post_url ), '?' ) === false ? '?' : '&'; $post_url .= $connector . 'mref=' . $mycred_referral_id; } return $post_url; } }