/** * Shortcode for Social Sharing. */ function the_champ_sharing_shortcode($params) { // notify if sharing is disabled if (the_champ_social_sharing_enabled()) { global $theChampSharingOptions; extract(shortcode_atts(array('style' => '', 'type' => 'horizontal', 'left' => '0', 'top' => '100', 'url' => '', 'count' => 0), $params)); if ($type == 'horizontal' && !the_champ_horizontal_sharing_enabled() || $type == 'vertical' && !the_champ_vertical_sharing_enabled()) { return; } global $post; $targetUrl = $url ? $url : get_permalink($post->ID); $html = '<div class="the_champ_sharing_container the_champ_' . $type . '_sharing" super-socializer-data-href="' . $targetUrl . '" '; $verticalOffsets = ''; if ($type == 'vertical') { $verticalOffsets = 'left: ' . $left . 'px; top: ' . $top . 'px;'; } // style if ($style != "" || $verticalOffsets != '') { $html .= 'style="'; if (strpos($style, 'background') === false) { $html .= 'box-shadow: none;'; } $html .= $verticalOffsets; $html .= $style; $html .= '"'; } $html .= '>'; $html .= the_champ_prepare_sharing_html($targetUrl, $type, $count); $html .= '</div>'; if ($count) { $html .= '<script>theChampLoadEvent( function(){ // sharing counts theChampCallAjax(function(){ theChampGetSharingCounts(' . ($type == 'horizontal' ? 1 : 0) . ', ' . ($type == 'vertical' ? 1 : 0) . '); }); } );</script>'; } return $html; } }
/** * Shortcode for Social Sharing. */ function the_champ_sharing_shortcode($params) { // notify if sharing is disabled if (the_champ_social_sharing_enabled()) { global $theChampSharingOptions; extract(shortcode_atts(array('style' => '', 'type' => 'horizontal', 'left' => '0', 'right' => '0', 'top' => '100', 'url' => '', 'count' => 0, 'align' => 'left', 'title' => '', 'total_shares' => 'OFF'), $params)); if ($type == 'horizontal' && !the_champ_horizontal_sharing_enabled() || $type == 'vertical' && !the_champ_vertical_sharing_enabled()) { return; } global $post; if ($url) { $targetUrl = $url; $postId = 0; } elseif (is_front_page()) { $targetUrl = site_url(); $postId = 0; } elseif (get_permalink($post->ID)) { $targetUrl = get_permalink($post->ID); $postId = $post->ID; } else { $targetUrl = html_entity_decode(esc_url(the_champ_get_http() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"])); $postId = 0; } // if bit.ly url shortener enabled, generate bit.ly short url $shortUrl = ''; if (isset($theChampSharingOptions['use_shortlinks']) && function_exists('wp_get_shortlink')) { $shortUrl = wp_get_shortlink(); // if bit.ly integration enabled, generate bit.ly short url } elseif (isset($theChampSharingOptions['bitly_enable']) && isset($theChampSharingOptions['bitly_username']) && $theChampSharingOptions['bitly_username'] != '' && isset($theChampSharingOptions['bitly_key']) && $theChampSharingOptions['bitly_key'] != '') { $shortUrl = the_champ_generate_sharing_bitly_url($targetUrl, $postId); } $alignmentOffset = 0; if ($left) { $alignmentOffset = $left; } elseif ($right) { $alignmentOffset = $right; } $html = '<div class="the_champ_sharing_container the_champ_' . $type . '_sharing' . ($type == 'vertical' && isset($theChampSharingOptions['hide_mobile_sharing']) ? ' the_champ_hide_sharing' : '') . ($type == 'vertical' && isset($theChampSharingOptions['bottom_mobile_sharing']) ? ' the_champ_bottom_sharing' : '') . '" ss-offset="' . $alignmentOffset . '" super-socializer-data-href="' . $targetUrl . '" '; $verticalOffsets = ''; if ($type == 'vertical') { $verticalOffsets = $align . ': ' . ${$align} . 'px; top: ' . $top . 'px;width:' . ((isset($theChampSharingOptions['vertical_sharing_size']) ? $theChampSharingOptions['vertical_sharing_size'] : '35') + 4) . "px;"; } // style if ($style != "" || $verticalOffsets != '') { $html .= 'style="'; if (strpos($style, 'background') === false) { $html .= '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;'; } $html .= $verticalOffsets; $html .= $style; $html .= '"'; } $html .= '>'; if ($type == 'horizontal' && $title != '') { $html .= '<div style="font-weight:bold">' . ucfirst($title) . '</div>'; } $html .= the_champ_prepare_sharing_html($shortUrl == '' ? $targetUrl : $shortUrl, $type, $count, $total_shares == 'ON' ? 1 : 0, ''); $html .= '</div>'; if ($count || $total_shares == 'ON') { $html .= '<script>theChampLoadEvent( function(){ // sharing counts theChampCallAjax(function(){ theChampGetSharingCounts(); }); } );</script>'; } return $html; } }
/** This is rendered widget content */ function widget($args, $instance) { // return if sharing is disabled if (!the_champ_social_sharing_enabled() || !the_champ_horizontal_sharing_enabled()) { return; } extract($args); if ($instance['hide_for_logged_in'] == 1 && is_user_logged_in()) { return; } global $theChampSharingOptions, $post; if (isset($instance['target_url'])) { if ($instance['target_url'] == 'default') { $sharingUrl = is_home() ? site_url() : get_permalink($post->ID); } elseif ($instance['target_url'] == 'homepage') { $sharingUrl = site_url(); } elseif ($instance['target_url'] == 'custom') { $sharingUrl = isset($instance['target_url_custom']) ? trim($instance['target_url_custom']) : get_permalink($post->ID); } } else { $sharingUrl = get_permalink($post->ID); } echo "<div class='the_champ_sharing_container the_champ_horizontal_sharing' super-socializer-data-href='" . $sharingUrl . "'>"; echo $before_widget; if (!empty($instance['title'])) { $title = apply_filters('widget_title', $instance['title']); echo $before_title . $title . $after_title; } if (!empty($instance['before_widget_content'])) { echo '<div>' . $instance['before_widget_content'] . '</div>'; } // if bit.ly integration enabled, generate bit.ly short url if (isset($theChampSharingOptions['bitly_enable']) && isset($theChampSharingOptions['bitly_username']) && isset($theChampSharingOptions['bitly_username']) && $theChampSharingOptions['bitly_username'] != '' && isset($theChampSharingOptions['bitly_key']) && $theChampSharingOptions['bitly_key'] != '') { $shortUrl = the_champ_generate_sharing_bitly_url(site_url()); if ($shortUrl) { $sharingUrl = $shortUrl; } } echo the_champ_prepare_sharing_html($sharingUrl, 'horizontal', isset($instance['show_counts'])); if (!empty($instance['after_widget_content'])) { echo '<div>' . $instance['after_widget_content'] . '</div>'; } echo '</div>'; if (isset($instance['show_counts'])) { echo '<script>theChampLoadEvent( function(){ // sharing counts theChampCallAjax(function(){ theChampGetSharingCounts(1, 0); }); } );</script>'; } echo $after_widget; }
/** * Check if Facebook Like/Recommend is enabled */ function the_champ_facebook_like_rec_enabled() { global $theChampCounterOptions, $theChampSharingOptions; if (the_champ_social_counter_enabled() && (the_champ_horizontal_counter_enabled() && isset($theChampCounterOptions['horizontal_providers']) && (in_array('facebook_like', $theChampCounterOptions['horizontal_providers']) || in_array('facebook_recommend', $theChampCounterOptions['horizontal_providers'])) || the_champ_vertical_counter_enabled() && isset($theChampCounterOptions['vertical_providers']) && (in_array('facebook_like', $theChampCounterOptions['vertical_providers']) || in_array('facebook_recommend', $theChampCounterOptions['vertical_providers']))) || the_champ_social_sharing_enabled() && (the_champ_horizontal_sharing_enabled() && isset($theChampSharingOptions['horizontal_re_providers']) && (in_array('facebook_like', $theChampSharingOptions['horizontal_re_providers']) || in_array('facebook_recommend', $theChampSharingOptions['horizontal_re_providers'])) || the_champ_vertical_sharing_enabled() && isset($theChampSharingOptions['vertical_re_providers']) && (in_array('facebook_like', $theChampSharingOptions['vertical_re_providers']) || in_array('facebook_recommend', $theChampSharingOptions['vertical_re_providers'])))) { return true; } return false; }