options = $options; $this->version = $version; } /** * Hook the plugin function on 'init' event. * * @since 1.0 */ public function init() { // Javascript for front-end of website add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) ); // 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 */ 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 ) { if ( ! isset( $this->options['js_when_needed'] ) || ( ( ( isset( $this->options['home'] ) || isset( $this->options['vertical_home'] ) ) && is_front_page() ) || ( ( isset( $this->options['category'] ) || isset($this->options['vertical_category'] ) ) && is_category() ) ||( ( isset( $this->options['archive'] ) || isset( $this->options['vertical_archive'] ) ) && is_archive() ) || ( ( isset( $this->options['post'] ) || isset( $this->options['vertical_post'] ) ) && is_single() && isset( $post->post_type ) && $post->post_type == 'post' ) || ( ( isset( $this->options['page'] ) || isset( $this->options['vertical_page'] ) ) && is_page() && ! is_front_page() && isset( $post->post_type ) && $post->post_type == 'page' ) || ( ( isset( $this->options['excerpt'] ) || isset( $this->options['vertical_excerpt'] ) ) && ( is_home() || current_filter() == 'the_excerpt' ) ) || ( ( isset( $this->options['bb_forum'] ) || isset( $this->options['vertical_bb_forum'] ) ) && current_filter() == 'bbp_template_before_single_forum' ) || ( ( isset( $this->options['bb_topic'] ) || 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['bp_group'] ) || isset( $this->options['vertical_bb_group'] ) ) ) ) ) { $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'] != '' ? intval( $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) .'\'' . ( isset( $this->options['native_sharing'] ) ? ', heateorSssNativeSharing = 1' : '' ) . ';'; $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:"v23.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_GB' ) .'/sdk.js",o.parentNode.insertBefore(n,o) )}(document);'; } 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' ); } } } } } /** * Check if webpage is being visited in a mobile device * * @since 3.3.9 */ public function check_if_mobile() { 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 it's a mobile if ( $iphone || $android || $palmpre || $ipod || $berry == true ) { return true; } } return false; } /** * Check if Facebook Like/Recommend is enabled * * @since 1.0 */ public 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 */ public 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 */ 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 { $generic_access_token = $this->options['bitly_access_token']; // generate the bit.ly URL $bitly_api = 'https://api-ssl.bitly.com/v4/bitlinks'; $payload = wp_json_encode( array( 'long_url' => $url ) ); $response = wp_remote_post( $bitly_api, array( 'body' => $payload, 'headers' => array( 'Authorization' => 'Bearer ' . $generic_access_token, 'Content-Type' => 'application/json', 'Content-Length' => strlen( $payload ) ), 'timeout' => 60, 'httpversion' => '1.0', 'sslverify' => false, 'data_format' => 'body' ) ); if ( ! is_wp_error( $response ) ) { $short_url_object = json_decode( wp_remote_retrieve_body( $response ) ); if ( isset( $short_url_object->link ) ) { $short_url = esc_url_raw( $short_url_object->link ); update_post_meta( $post_id, '_heateor_sss_bitly_url', $short_url ); return $short_url; } } } return false; } /** * Get short url. * * @since 1.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_access_token'] != '' ) { $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 */ public function prepare_sharing_html( $post_url, $sharing_type, $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 ); } $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 = '