Пример #1
0
/** 
 * Shortcode for Social Counter.
 */
function the_champ_counter_shortcode($params)
{
    // notify if counter is disabled
    if (the_champ_social_counter_enabled()) {
        extract(shortcode_atts(array('style' => '', 'type' => 'horizontal', 'left' => '0', 'right' => '0', 'top' => '100', 'url' => '', 'align' => 'left', 'title' => ''), $params));
        if ($type == 'horizontal' && !the_champ_horizontal_counter_enabled() || $type == 'vertical' && !the_champ_vertical_counter_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;
        }
        $alignmentOffset = 0;
        if ($left) {
            $alignmentOffset = $left;
        } elseif ($right) {
            $alignmentOffset = $right;
        }
        global $theChampCounterOptions;
        $html = '<div class="the_champ_counter_container the_champ_' . $type . '_counter' . ($type == 'vertical' && isset($theChampCounterOptions['hide_mobile_likeb']) ? ' the_champ_hide_sharing' : '') . '" ss-offset="' . $alignmentOffset . '" ';
        $verticalOffsets = '';
        if ($type == 'vertical') {
            $verticalOffsets = $align . ': ' . ${$align} . 'px; top: ' . $top . '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>';
        }
        $counterUrl = $targetUrl;
        if (isset($theChampCounterOptions['use_shortlinks']) && function_exists('wp_get_shortlink')) {
            $counterUrl = wp_get_shortlink();
            // if bit.ly integration enabled, generate bit.ly short url
        } elseif (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
            $shortUrl = the_champ_generate_counter_bitly_url($targetUrl, $postId);
            if ($shortUrl) {
                $counterUrl = $shortUrl;
            }
        }
        $html .= the_champ_prepare_counter_html($targetUrl, $type, $counterUrl);
        $html .= '</div>';
        return $html;
    }
}
Пример #2
0
/**
 * Enable sharing interface at selected areas.
 */
function the_champ_render_sharing($content)
{
    global $post;
    // hook to bypass sharing
    $disable = apply_filters('the_champ_bypass_sharing', $post, $content);
    // if $disable value is 1, return content without sharing interface
    if ($disable === 1) {
        return $content;
    }
    $sharingMeta = get_post_meta($post->ID, '_the_champ_meta', true);
    global $theChampSharingOptions, $theChampCounterOptions;
    $sharingBpActivity = false;
    $counterBpActivity = false;
    if (current_filter() == 'bp_activity_entry_meta') {
        if (isset($theChampSharingOptions['bp_activity'])) {
            $sharingBpActivity = true;
        }
        if (isset($theChampCounterOptions['bp_activity'])) {
            $counterBpActivity = true;
        }
    }
    $post_types = get_post_types(array('public' => true), 'names', 'and');
    $post_types = array_diff($post_types, array('post', 'page'));
    if (isset($theChampCounterOptions['enable'])) {
        //counter interface
        if (isset($theChampCounterOptions['hor_enable']) && !(isset($sharingMeta['counter']) && $sharingMeta['counter'] == 1 && (!is_front_page() || is_front_page() && 'page' == get_option('show_on_front')))) {
            $postId = $post->ID;
            if ($counterBpActivity) {
                $counterPostUrl = bp_get_activity_thread_permalink();
            } elseif (isset($theChampCounterOptions['horizontal_target_url'])) {
                if ($theChampCounterOptions['horizontal_target_url'] == 'default') {
                    $counterPostUrl = get_permalink($post->ID);
                    if ($counterPostUrl == '') {
                        $counterPostUrl = html_entity_decode(esc_url(the_champ_get_http() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
                    }
                } elseif ($theChampCounterOptions['horizontal_target_url'] == 'home') {
                    $counterPostUrl = site_url();
                    $postId = 0;
                } elseif ($theChampCounterOptions['horizontal_target_url'] == 'custom') {
                    $counterPostUrl = isset($theChampCounterOptions['horizontal_target_url_custom']) ? trim($theChampCounterOptions['horizontal_target_url_custom']) : get_permalink($post->ID);
                    $postId = 0;
                }
            } else {
                $counterPostUrl = get_permalink($post->ID);
            }
            $counterUrl = $counterPostUrl;
            if (isset($theChampCounterOptions['use_shortlinks']) && function_exists('wp_get_shortlink')) {
                $counterUrl = wp_get_shortlink();
                // if bit.ly integration enabled, generate bit.ly short url
            } elseif (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
                $shortUrl = the_champ_generate_counter_bitly_url($counterPostUrl, $postId);
                if ($shortUrl) {
                    $counterUrl = $shortUrl;
                }
            }
            $sharingDiv = the_champ_prepare_counter_html($counterPostUrl, 'horizontal', $counterUrl);
            $sharingContainerStyle = '';
            $sharingTitleStyle = 'style="font-weight:bold"';
            if (isset($theChampCounterOptions['hor_counter_alignment'])) {
                if ($theChampCounterOptions['hor_counter_alignment'] == 'right') {
                    $sharingContainerStyle = 'style="float: right"';
                } elseif ($theChampCounterOptions['hor_counter_alignment'] == 'center') {
                    $sharingContainerStyle = 'style="float: right;position: relative;left: -50%;text-align: left;"';
                    $sharingTitleStyle = 'style="font-weight: bold;list-style: none;position: relative;left: 50%;"';
                }
            }
            $horizontalDiv = "<div style='clear: both'></div><div " . $sharingContainerStyle . " class='the_champ_counter_container the_champ_horizontal_counter'><div " . $sharingTitleStyle . ">" . ucfirst($theChampCounterOptions['title']) . "</div>" . $sharingDiv . "</div><div style='clear: both'></div>";
            if ($counterBpActivity) {
                echo $horizontalDiv;
            }
            // show horizontal counter
            if (isset($theChampCounterOptions['home']) && is_front_page() || isset($theChampCounterOptions['category']) && is_category() || isset($theChampCounterOptions['archive']) && is_archive() || isset($theChampCounterOptions['post']) && is_single() && isset($post->post_type) && $post->post_type == 'post' || isset($theChampCounterOptions['page']) && is_page() && isset($post->post_type) && $post->post_type == 'page' || isset($theChampCounterOptions['excerpt']) && (is_home() || current_filter() == 'the_excerpt') || isset($theChampCounterOptions['bb_reply']) && current_filter() == 'bbp_get_reply_content' || isset($theChampCounterOptions['bb_forum']) && (isset($theChampCounterOptions['top']) && current_filter() == 'bbp_template_before_single_forum' || isset($theChampCounterOptions['bottom']) && current_filter() == 'bbp_template_after_single_forum') || isset($theChampCounterOptions['bb_topic']) && (isset($theChampCounterOptions['top']) && in_array(current_filter(), array('bbp_template_before_single_topic', 'bbp_template_before_lead_topic')) || isset($theChampCounterOptions['bottom']) && in_array(current_filter(), array('bbp_template_after_single_topic', 'bbp_template_after_lead_topic'))) || isset($theChampCounterOptions['woocom_shop']) && current_filter() == 'woocommerce_after_shop_loop_item' || isset($theChampCounterOptions['woocom_product']) && current_filter() == 'woocommerce_share' || isset($theChampCounterOptions['woocom_thankyou']) && current_filter() == 'woocommerce_thankyou' || current_filter() == 'bp_before_group_header' && isset($theChampCounterOptions['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 '<div style="clear:both"></div>' . $horizontalDiv . '<div style="clear:both"></div>';
                } else {
                    if (isset($theChampCounterOptions['top']) && isset($theChampCounterOptions['bottom'])) {
                        $content = $horizontalDiv . '<br/>' . $content . '<br/>' . $horizontalDiv;
                    } else {
                        if (isset($theChampCounterOptions['top'])) {
                            $content = $horizontalDiv . $content;
                        } elseif (isset($theChampCounterOptions['bottom'])) {
                            $content = $content . $horizontalDiv;
                        }
                    }
                }
            } elseif (count($post_types)) {
                foreach ($post_types as $post_type) {
                    if (isset($theChampCounterOptions[$post_type]) && (is_single() || is_page()) && isset($post->post_type) && $post->post_type == $post_type) {
                        if (isset($theChampCounterOptions['top']) && isset($theChampCounterOptions['bottom'])) {
                            $content = $horizontalDiv . '<br/>' . $content . '<br/>' . $horizontalDiv;
                        } else {
                            if (isset($theChampCounterOptions['top'])) {
                                $content = $horizontalDiv . $content;
                            } elseif (isset($theChampCounterOptions['bottom'])) {
                                $content = $content . $horizontalDiv;
                            }
                        }
                    }
                }
            }
        }
        if (isset($theChampCounterOptions['vertical_enable']) && !(isset($sharingMeta['vertical_counter']) && $sharingMeta['vertical_counter'] == 1 && (!is_front_page() || is_front_page() && 'page' == get_option('show_on_front')))) {
            $postId = $post->ID;
            if (isset($theChampCounterOptions['vertical_target_url'])) {
                if ($theChampCounterOptions['vertical_target_url'] == 'default') {
                    $counterPostUrl = get_permalink($post->ID);
                    if ($counterPostUrl == '') {
                        $counterPostUrl = html_entity_decode(esc_url(the_champ_get_http() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
                    }
                } elseif ($theChampCounterOptions['vertical_target_url'] == 'home') {
                    $counterPostUrl = site_url();
                    $postId = 0;
                } elseif ($theChampCounterOptions['vertical_target_url'] == 'custom') {
                    $counterPostUrl = isset($theChampCounterOptions['vertical_target_url_custom']) ? trim($theChampCounterOptions['vertical_target_url_custom']) : get_permalink($post->ID);
                    $postId = 0;
                }
            } else {
                $counterPostUrl = get_permalink($post->ID);
            }
            $counterUrl = $counterPostUrl;
            if (isset($theChampCounterOptions['use_shortlinks']) && function_exists('wp_get_shortlink')) {
                $counterUrl = wp_get_shortlink();
                // if bit.ly integration enabled, generate bit.ly short url
            } elseif (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
                $shortUrl = the_champ_generate_counter_bitly_url($counterPostUrl, $postId);
                if ($shortUrl) {
                    $counterUrl = $shortUrl;
                }
            }
            $sharingDiv = the_champ_prepare_counter_html($counterPostUrl, 'vertical', $counterUrl);
            $offset = (isset($theChampCounterOptions['alignment']) && $theChampCounterOptions['alignment'] != '' && isset($theChampCounterOptions[$theChampCounterOptions['alignment'] . '_offset']) ? $theChampCounterOptions['alignment'] . ': ' . ($theChampCounterOptions[$theChampCounterOptions['alignment'] . '_offset'] == '' ? 0 : $theChampCounterOptions[$theChampCounterOptions['alignment'] . '_offset']) . 'px;' : '') . (isset($theChampCounterOptions['top_offset']) ? 'top: ' . ($theChampCounterOptions['top_offset'] == '' ? 0 : $theChampCounterOptions['top_offset']) . 'px;' : '');
            $verticalDiv = "<div class='the_champ_counter_container the_champ_vertical_counter" . (isset($theChampCounterOptions['hide_mobile_likeb']) ? ' the_champ_hide_sharing' : '') . "' style='" . $offset . (isset($theChampCounterOptions['vertical_bg']) && $theChampCounterOptions['vertical_bg'] != '' ? 'background-color: ' . $theChampCounterOptions['vertical_bg'] . ';' : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "'>" . $sharingDiv . "</div>";
            // show vertical counter
            if (isset($theChampCounterOptions['vertical_home']) && is_front_page() || isset($theChampCounterOptions['vertical_category']) && is_category() || isset($theChampCounterOptions['vertical_archive']) && is_archive() || isset($theChampCounterOptions['vertical_post']) && is_single() && isset($post->post_type) && $post->post_type == 'post' || isset($theChampCounterOptions['vertical_page']) && is_page() && isset($post->post_type) && $post->post_type == 'page' || isset($theChampCounterOptions['vertical_excerpt']) && (is_home() || current_filter() == 'the_excerpt') || isset($theChampCounterOptions['vertical_bb_forum']) && current_filter() == 'bbp_template_before_single_forum' || isset($theChampCounterOptions['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($theChampCounterOptions['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 $verticalDiv;
                } else {
                    if (is_front_page()) {
                        global $theChampVerticalCounterHomeCount, $theChampVerticalCounterExcerptCount;
                        if (current_filter() == 'the_content') {
                            $var = 'theChampVerticalCounterHomeCount';
                        } elseif (is_home() || current_filter() == 'the_excerpt') {
                            $var = 'theChampVerticalCounterExcerptCount';
                        }
                        if (${$var} == 0) {
                            if (isset($theChampCounterOptions['vertical_target_url']) && $theChampCounterOptions['vertical_target_url'] == 'default') {
                                $counterPostUrl = site_url();
                                $counterUrl = $counterPostUrl;
                                if (isset($theChampCounterOptions['use_shortlinks']) && function_exists('wp_get_shortlink')) {
                                    $counterUrl = wp_get_shortlink();
                                    // if bit.ly integration enabled, generate bit.ly short url
                                } elseif (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
                                    $shortUrl = the_champ_generate_counter_bitly_url($counterPostUrl, 0);
                                    if ($shortUrl) {
                                        $counterUrl = $shortUrl;
                                    }
                                }
                                $sharingDiv = the_champ_prepare_counter_html($counterPostUrl, 'vertical', $counterUrl);
                                $verticalDiv = "<div class='the_champ_counter_container the_champ_vertical_counter" . (isset($theChampCounterOptions['hide_mobile_likeb']) ? ' the_champ_hide_sharing' : '') . "' style='" . $offset . (isset($theChampCounterOptions['vertical_bg']) && $theChampCounterOptions['vertical_bg'] != '' ? 'background-color: ' . $theChampCounterOptions['vertical_bg'] . ';' : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "'>" . $sharingDiv . "</div>";
                            }
                            $content = $content . $verticalDiv;
                            ${$var}++;
                        }
                    } else {
                        $content = $content . $verticalDiv;
                    }
                }
            } elseif (count($post_types)) {
                foreach ($post_types as $post_type) {
                    if (isset($theChampCounterOptions['vertical_' . $post_type]) && (is_single() || is_page()) && isset($post->post_type) && $post->post_type == $post_type) {
                        $content = $content . $verticalDiv;
                    }
                }
            }
        }
    }
    if (isset($theChampSharingOptions['enable'])) {
        // sharing interface
        if (isset($theChampSharingOptions['hor_enable']) && !(isset($sharingMeta['sharing']) && $sharingMeta['sharing'] == 1 && (!is_front_page() || is_front_page() && 'page' == get_option('show_on_front')))) {
            $postId = $post->ID;
            if ($sharingBpActivity) {
                $postUrl = bp_get_activity_thread_permalink();
                $postId = 0;
            } elseif (isset($theChampSharingOptions['horizontal_target_url'])) {
                if ($theChampSharingOptions['horizontal_target_url'] == 'default') {
                    $postUrl = get_permalink($post->ID);
                    if ($postUrl == '') {
                        $postUrl = html_entity_decode(esc_url(the_champ_get_http() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
                    }
                } elseif ($theChampSharingOptions['horizontal_target_url'] == 'home') {
                    $postUrl = site_url();
                    $postId = 0;
                } elseif ($theChampSharingOptions['horizontal_target_url'] == 'custom') {
                    $postUrl = isset($theChampSharingOptions['horizontal_target_url_custom']) ? trim($theChampSharingOptions['horizontal_target_url_custom']) : get_permalink($post->ID);
                    $postId = 0;
                }
            } else {
                $postUrl = get_permalink($post->ID);
            }
            $sharingUrl = $postUrl;
            if (isset($theChampSharingOptions['use_shortlinks']) && function_exists('wp_get_shortlink')) {
                $sharingUrl = 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($postUrl, $postId);
                if ($shortUrl) {
                    $sharingUrl = $shortUrl;
                }
            }
            $shareCountTransientId = heateor_ss_get_share_count_transient_id($postUrl);
            $sharingDiv = the_champ_prepare_sharing_html($sharingUrl, 'horizontal', isset($theChampSharingOptions['horizontal_counts']), isset($theChampSharingOptions['horizontal_total_shares']), $shareCountTransientId);
            $sharingContainerStyle = '';
            $sharingTitleStyle = 'style="font-weight:bold"';
            if (isset($theChampSharingOptions['hor_sharing_alignment'])) {
                if ($theChampSharingOptions['hor_sharing_alignment'] == 'right') {
                    $sharingContainerStyle = 'style="float: right"';
                } elseif ($theChampSharingOptions['hor_sharing_alignment'] == 'center') {
                    $sharingContainerStyle = 'style="float: right;position: relative;left: -50%;text-align: left;"';
                    $sharingTitleStyle = 'style="font-weight: bold;list-style: none;position: relative;left: 50%;"';
                }
            }
            $horizontalDiv = "<div style='clear: both'></div><div " . $sharingContainerStyle . " class='the_champ_sharing_container the_champ_horizontal_sharing' super-socializer-data-href='" . $postUrl . "'" . (heateor_ss_get_cached_share_count($shareCountTransientId) === false ? "" : 'super-socializer-no-counts="1"') . "><div class='the_champ_sharing_title' " . $sharingTitleStyle . " >" . ucfirst($theChampSharingOptions['title']) . "</div>" . $sharingDiv . "</div><div style='clear: both'></div>";
            if ($sharingBpActivity) {
                echo $horizontalDiv;
            }
            // show horizontal sharing
            if (isset($theChampSharingOptions['home']) && is_front_page() || isset($theChampSharingOptions['category']) && is_category() || isset($theChampSharingOptions['archive']) && is_archive() || isset($theChampSharingOptions['post']) && is_single() && isset($post->post_type) && $post->post_type == 'post' || isset($theChampSharingOptions['page']) && is_page() && isset($post->post_type) && $post->post_type == 'page' || isset($theChampSharingOptions['excerpt']) && (is_home() || current_filter() == 'the_excerpt') || isset($theChampSharingOptions['bb_reply']) && current_filter() == 'bbp_get_reply_content' || isset($theChampSharingOptions['bb_forum']) && (isset($theChampSharingOptions['top']) && current_filter() == 'bbp_template_before_single_forum' || isset($theChampSharingOptions['bottom']) && current_filter() == 'bbp_template_after_single_forum') || isset($theChampSharingOptions['bb_topic']) && (isset($theChampSharingOptions['top']) && in_array(current_filter(), array('bbp_template_before_single_topic', 'bbp_template_before_lead_topic')) || isset($theChampSharingOptions['bottom']) && in_array(current_filter(), array('bbp_template_after_single_topic', 'bbp_template_after_lead_topic'))) || isset($theChampSharingOptions['woocom_shop']) && current_filter() == 'woocommerce_after_shop_loop_item' || isset($theChampSharingOptions['woocom_product']) && current_filter() == 'woocommerce_share' || isset($theChampSharingOptions['woocom_thankyou']) && current_filter() == 'woocommerce_thankyou' || current_filter() == 'bp_before_group_header' && isset($theChampSharingOptions['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 '<div style="clear:both"></div>' . $horizontalDiv . '<div style="clear:both"></div>';
                } else {
                    if (isset($theChampSharingOptions['top']) && isset($theChampSharingOptions['bottom'])) {
                        $content = $horizontalDiv . '<br/>' . $content . '<br/>' . $horizontalDiv;
                    } else {
                        if (isset($theChampSharingOptions['top'])) {
                            $content = $horizontalDiv . $content;
                        } elseif (isset($theChampSharingOptions['bottom'])) {
                            $content = $content . $horizontalDiv;
                        }
                    }
                }
            } elseif (count($post_types)) {
                foreach ($post_types as $post_type) {
                    if (isset($theChampSharingOptions[$post_type]) && (is_single() || is_page()) && isset($post->post_type) && $post->post_type == $post_type) {
                        if (isset($theChampSharingOptions['top']) && isset($theChampSharingOptions['bottom'])) {
                            $content = $horizontalDiv . '<br/>' . $content . '<br/>' . $horizontalDiv;
                        } else {
                            if (isset($theChampSharingOptions['top'])) {
                                $content = $horizontalDiv . $content;
                            } elseif (isset($theChampSharingOptions['bottom'])) {
                                $content = $content . $horizontalDiv;
                            }
                        }
                    }
                }
            }
        }
        if (isset($theChampSharingOptions['vertical_enable']) && !(isset($sharingMeta['vertical_sharing']) && $sharingMeta['vertical_sharing'] == 1 && (!is_front_page() || is_front_page() && 'page' == get_option('show_on_front')))) {
            $postId = $post->ID;
            if (isset($theChampSharingOptions['vertical_target_url'])) {
                if ($theChampSharingOptions['vertical_target_url'] == 'default') {
                    $postUrl = get_permalink($post->ID);
                    if ($postUrl == '') {
                        $postUrl = html_entity_decode(esc_url(the_champ_get_http() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
                    }
                } elseif ($theChampSharingOptions['vertical_target_url'] == 'home') {
                    $postUrl = site_url();
                    $postId = 0;
                } elseif ($theChampSharingOptions['vertical_target_url'] == 'custom') {
                    $postUrl = isset($theChampSharingOptions['vertical_target_url_custom']) ? trim($theChampSharingOptions['vertical_target_url_custom']) : get_permalink($post->ID);
                    $postId = 0;
                }
            } else {
                $postUrl = get_permalink($post->ID);
            }
            $sharingUrl = $postUrl;
            if (isset($theChampSharingOptions['use_shortlinks']) && function_exists('wp_get_shortlink')) {
                $sharingUrl = wp_get_shortlink();
                // if bit.ly integration enabled, generate bit.ly short url
            } elseif (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($postUrl, $postId);
                if ($shortUrl) {
                    $sharingUrl = $shortUrl;
                }
            }
            $shareCountTransientId = heateor_ss_get_share_count_transient_id($postUrl);
            $sharingDiv = the_champ_prepare_sharing_html($sharingUrl, 'vertical', isset($theChampSharingOptions['vertical_counts']), isset($theChampSharingOptions['vertical_total_shares']), $shareCountTransientId);
            $offset = (isset($theChampSharingOptions['alignment']) && $theChampSharingOptions['alignment'] != '' && isset($theChampSharingOptions[$theChampSharingOptions['alignment'] . '_offset']) && $theChampSharingOptions[$theChampSharingOptions['alignment'] . '_offset'] != '' ? $theChampSharingOptions['alignment'] . ': ' . $theChampSharingOptions[$theChampSharingOptions['alignment'] . '_offset'] . 'px;' : '') . (isset($theChampSharingOptions['top_offset']) && $theChampSharingOptions['top_offset'] != '' ? 'top: ' . $theChampSharingOptions['top_offset'] . 'px;' : '');
            $verticalDiv = "<div class='the_champ_sharing_container the_champ_vertical_sharing" . (isset($theChampSharingOptions['hide_mobile_sharing']) ? ' the_champ_hide_sharing' : '') . (isset($theChampSharingOptions['bottom_mobile_sharing']) ? ' the_champ_bottom_sharing' : '') . "' style='width:" . ($theChampSharingOptions['vertical_sharing_size'] + 4) . "px;" . $offset . (isset($theChampSharingOptions['vertical_bg']) && $theChampSharingOptions['vertical_bg'] != '' ? 'background-color: ' . $theChampSharingOptions['vertical_bg'] : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "' super-socializer-data-href='" . $postUrl . "'" . (heateor_ss_get_cached_share_count($shareCountTransientId) === false ? "" : 'super-socializer-no-counts="1"') . ">" . $sharingDiv . "</div>";
            // show vertical sharing
            if (isset($theChampSharingOptions['vertical_home']) && is_front_page() || isset($theChampSharingOptions['vertical_category']) && is_category() || isset($theChampSharingOptions['vertical_archive']) && is_archive() || isset($theChampSharingOptions['vertical_post']) && is_single() && isset($post->post_type) && $post->post_type == 'post' || isset($theChampSharingOptions['vertical_page']) && is_page() && isset($post->post_type) && $post->post_type == 'page' || isset($theChampSharingOptions['vertical_excerpt']) && (is_home() || current_filter() == 'the_excerpt') || isset($theChampSharingOptions['vertical_bb_forum']) && current_filter() == 'bbp_template_before_single_forum' || isset($theChampSharingOptions['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($theChampSharingOptions['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 $verticalDiv;
                } else {
                    if (is_front_page()) {
                        global $theChampVerticalHomeCount, $theChampVerticalExcerptCount;
                        if (current_filter() == 'the_content') {
                            $var = 'theChampVerticalHomeCount';
                        } elseif (is_home() || current_filter() == 'the_excerpt') {
                            $var = 'theChampVerticalExcerptCount';
                        }
                        if (${$var} == 0) {
                            if (isset($theChampSharingOptions['vertical_target_url']) && $theChampSharingOptions['vertical_target_url'] == 'default') {
                                $postUrl = site_url();
                                $sharingUrl = $postUrl;
                                if (isset($theChampSharingOptions['use_shortlinks']) && function_exists('wp_get_shortlink')) {
                                    $sharingUrl = wp_get_shortlink();
                                    // if bit.ly integration enabled, generate bit.ly short url
                                } elseif (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($postUrl, 0);
                                    if ($shortUrl) {
                                        $sharingUrl = $shortUrl;
                                    }
                                }
                                $shareCountTransientId = heateor_ss_get_share_count_transient_id($postUrl);
                                $sharingDiv = the_champ_prepare_sharing_html($sharingUrl, 'vertical', isset($theChampSharingOptions['vertical_counts']), isset($theChampSharingOptions['vertical_total_shares']), $shareCountTransientId);
                                $verticalDiv = "<div class='the_champ_sharing_container the_champ_vertical_sharing" . (isset($theChampSharingOptions['hide_mobile_sharing']) ? ' the_champ_hide_sharing' : '') . (isset($theChampSharingOptions['bottom_mobile_sharing']) ? ' the_champ_bottom_sharing' : '') . "' style='width:" . ($theChampSharingOptions['vertical_sharing_size'] + 4) . "px;" . $offset . (isset($theChampSharingOptions['vertical_bg']) && $theChampSharingOptions['vertical_bg'] != '' ? 'background-color: ' . $theChampSharingOptions['vertical_bg'] : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "' super-socializer-data-href='" . $postUrl . "'" . (heateor_ss_get_cached_share_count($shareCountTransientId) === false ? "" : 'super-socializer-no-counts="1"') . ">" . $sharingDiv . "</div>";
                            }
                            $content = $content . $verticalDiv;
                            ${$var}++;
                        }
                    } else {
                        $content = $content . $verticalDiv;
                    }
                }
            } elseif (count($post_types)) {
                foreach ($post_types as $post_type) {
                    if (isset($theChampSharingOptions['vertical_' . $post_type]) && (is_single() || is_page()) && isset($post->post_type) && $post->post_type == $post_type) {
                        $content = $content . $verticalDiv;
                    }
                }
            }
        }
    }
    return $content;
}
Пример #3
0
 /** This is rendered widget content */
 function widget($args, $instance)
 {
     // return if counter is disabled
     if (!the_champ_social_counter_enabled() || !the_champ_vertical_counter_enabled()) {
         return;
     }
     extract($args);
     if ($instance['hide_for_logged_in'] == 1 && is_user_logged_in()) {
         return;
     }
     global $theChampCounterOptions, $post;
     if (isset($instance['target_url'])) {
         if ($instance['target_url'] == 'default') {
             $counterUrl = is_home() ? site_url() : get_permalink($post->ID);
         } elseif ($instance['target_url'] == 'homepage') {
             $counterUrl = site_url();
         } elseif ($instance['target_url'] == 'custom') {
             $counterUrl = isset($instance['target_url_custom']) ? trim($instance['target_url_custom']) : get_permalink($post->ID);
         }
     } else {
         $counterUrl = get_permalink($post->ID);
     }
     echo "<div class='the_champ_counter_container the_champ_vertical_counter' style='" . (isset($instance['alignment']) && $instance['alignment'] != '' && isset($instance[$instance['alignment'] . '_offset']) ? $instance['alignment'] . ': ' . ($instance[$instance['alignment'] . '_offset'] == '' ? 0 : $instance[$instance['alignment'] . '_offset']) . 'px;' : '') . (isset($instance['top_offset']) ? 'top: ' . ($instance['top_offset'] == '' ? 0 : $instance['top_offset']) . 'px;' : '') . (isset($instance['vertical_bg']) && $instance['vertical_bg'] != '' ? 'background-color: ' . $instance['vertical_bg'] . ';' : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "' >";
     // if bit.ly integration enabled, generate bit.ly short url
     $shortUrl = $counterUrl;
     if (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
         $tempShortUrl = the_champ_generate_counter_bitly_url($counterUrl);
         if ($tempShortUrl) {
             $shortUrl = $tempShortUrl;
         }
     }
     //echo $before_widget;
     echo the_champ_prepare_counter_html($counterUrl, 'vertical', $shortUrl);
     echo "</div>";
     //echo $after_widget;
 }
Пример #4
0
/**
 * Enable sharing interface at selected areas.
 */
function the_champ_render_sharing($content)
{
    global $post;
    // hook to bypass sharing
    $disable = apply_filters('the_champ_bypass_sharing', $post, $content);
    // if $disable value is 1, return content without sharing interface
    if ($disable === 1) {
        return $content;
    }
    $sharingMeta = get_post_meta($post->ID, '_the_champ_meta', true);
    global $theChampSharingOptions, $theChampCounterOptions;
    $sharingBpActivity = false;
    $counterBpActivity = false;
    if (current_filter() == 'bp_activity_entry_meta') {
        if (isset($theChampSharingOptions['bp_activity'])) {
            $sharingBpActivity = true;
        }
        if (isset($theChampCounterOptions['bp_activity'])) {
            $counterBpActivity = true;
        }
    }
    if (isset($theChampCounterOptions['enable'])) {
        //counter interface
        if (isset($theChampCounterOptions['hor_enable']) && !(isset($sharingMeta['counter']) && $sharingMeta['counter'] == 1 && !is_front_page())) {
            if ($counterBpActivity) {
                $counterPostUrl = bp_get_activity_thread_permalink();
            } elseif (isset($theChampCounterOptions['horizontal_target_url'])) {
                if ($theChampCounterOptions['horizontal_target_url'] == 'default') {
                    $counterPostUrl = get_permalink($post->ID);
                } elseif ($theChampCounterOptions['horizontal_target_url'] == 'home') {
                    $counterPostUrl = site_url();
                } elseif ($theChampCounterOptions['horizontal_target_url'] == 'custom') {
                    $counterPostUrl = isset($theChampCounterOptions['horizontal_target_url_custom']) ? trim($theChampCounterOptions['horizontal_target_url_custom']) : get_permalink($post->ID);
                }
            } else {
                $counterPostUrl = get_permalink($post->ID);
            }
            $counterUrl = $counterPostUrl;
            // if bit.ly integration enabled, generate bit.ly short url
            if (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
                $shortUrl = the_champ_generate_counter_bitly_url($counterPostUrl);
                if ($shortUrl) {
                    $counterUrl = $shortUrl;
                }
            }
            $sharingDiv = the_champ_prepare_counter_html($counterPostUrl, 'horizontal', $counterUrl);
            $sharingContainerStyle = '';
            $sharingTitleStyle = 'style="font-weight:bold"';
            if (isset($theChampCounterOptions['hor_counter_alignment'])) {
                if ($theChampCounterOptions['hor_counter_alignment'] == 'right') {
                    $sharingContainerStyle = 'style="float: right"';
                } elseif ($theChampCounterOptions['hor_counter_alignment'] == 'center') {
                    $sharingContainerStyle = 'style="float: right;position: relative;left: -50%;text-align: left;"';
                    $sharingTitleStyle = 'style="font-weight: bold;list-style: none;position: relative;left: 50%;"';
                }
            }
            $horizontalDiv = "<div style='clear: both'></div><div " . $sharingContainerStyle . " class='the_champ_counter_container the_champ_horizontal_counter'><div " . $sharingTitleStyle . ">" . ucfirst($theChampCounterOptions['title']) . "</div>" . $sharingDiv . "</div><div style='clear: both'></div>";
            if ($counterBpActivity) {
                echo $horizontalDiv;
            }
            // show horizontal counter
            if (isset($theChampCounterOptions['home']) && is_front_page() || isset($theChampCounterOptions['category']) && is_category() || isset($theChampCounterOptions['post']) && is_single() && isset($post->post_type) && $post->post_type == 'post' || isset($theChampCounterOptions['page']) && is_page() && isset($post->post_type) && $post->post_type == 'page' || isset($theChampCounterOptions['excerpt']) && is_front_page() && current_filter() == 'get_the_excerpt' || isset($theChampCounterOptions['bb_reply']) && current_filter() == 'bbp_get_reply_content' || isset($theChampCounterOptions['bb_forum']) && (isset($theChampCounterOptions['top']) && current_filter() == 'bbp_template_before_single_forum' || isset($theChampCounterOptions['bottom']) && current_filter() == 'bbp_template_after_single_forum') || isset($theChampCounterOptions['bb_topic']) && (isset($theChampCounterOptions['top']) && in_array(current_filter(), array('bbp_template_before_single_topic', 'bbp_template_before_lead_topic')) || isset($theChampCounterOptions['bottom']) && in_array(current_filter(), array('bbp_template_after_single_topic', 'bbp_template_after_lead_topic')))) {
                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'))) {
                    echo '<div style="clear:both"></div>' . $horizontalDiv . '<div style="clear:both"></div>';
                } else {
                    if (isset($theChampCounterOptions['top']) && isset($theChampCounterOptions['bottom'])) {
                        $content = $horizontalDiv . '<br/>' . $content . '<br/>' . $horizontalDiv;
                    } else {
                        if (isset($theChampCounterOptions['top'])) {
                            $content = $horizontalDiv . $content;
                        } elseif (isset($theChampCounterOptions['bottom'])) {
                            $content = $content . $horizontalDiv;
                        }
                    }
                }
            }
        }
        if (isset($theChampCounterOptions['vertical_enable']) && !(isset($sharingMeta['vertical_counter']) && $sharingMeta['vertical_counter'] == 1 && !is_front_page())) {
            if (isset($theChampCounterOptions['vertical_target_url'])) {
                if ($theChampCounterOptions['vertical_target_url'] == 'default') {
                    $counterPostUrl = get_permalink($post->ID);
                } elseif ($theChampCounterOptions['vertical_target_url'] == 'home') {
                    $counterPostUrl = site_url();
                } elseif ($theChampCounterOptions['vertical_target_url'] == 'custom') {
                    $counterPostUrl = isset($theChampCounterOptions['vertical_target_url_custom']) ? trim($theChampCounterOptions['vertical_target_url_custom']) : get_permalink($post->ID);
                }
            } else {
                $counterPostUrl = get_permalink($post->ID);
            }
            $counterUrl = $counterPostUrl;
            // if bit.ly integration enabled, generate bit.ly short url
            if (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
                $shortUrl = the_champ_generate_counter_bitly_url($counterPostUrl);
                if ($shortUrl) {
                    $counterUrl = $shortUrl;
                }
            }
            $sharingDiv = the_champ_prepare_counter_html($counterPostUrl, 'vertical', $counterUrl);
            $verticalDiv = "<div class='the_champ_counter_container the_champ_vertical_counter' style='" . (isset($theChampCounterOptions['alignment']) && $theChampCounterOptions['alignment'] != '' && isset($theChampCounterOptions[$theChampCounterOptions['alignment'] . '_offset']) ? $theChampCounterOptions['alignment'] . ': ' . ($theChampCounterOptions[$theChampCounterOptions['alignment'] . '_offset'] == '' ? 0 : $theChampCounterOptions[$theChampCounterOptions['alignment'] . '_offset']) . 'px;' : '') . (isset($theChampCounterOptions['top_offset']) ? 'top: ' . ($theChampCounterOptions['top_offset'] == '' ? 0 : $theChampCounterOptions['top_offset']) . 'px;' : '') . (isset($theChampCounterOptions['vertical_bg']) && $theChampCounterOptions['vertical_bg'] != '' ? 'background-color: ' . $theChampCounterOptions['vertical_bg'] . ';' : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "'>" . $sharingDiv . "</div>";
            // show vertical counter
            if (isset($theChampCounterOptions['vertical_home']) && is_front_page() || isset($theChampCounterOptions['vertical_category']) && is_category() || isset($theChampCounterOptions['vertical_post']) && is_single() && isset($post->post_type) && $post->post_type == 'post' || isset($theChampCounterOptions['vertical_page']) && is_page() && isset($post->post_type) && $post->post_type == 'page' || isset($theChampCounterOptions['vertical_excerpt']) && is_front_page() && current_filter() == 'get_the_excerpt' || isset($theChampCounterOptions['vertical_bb_forum']) && current_filter() == 'bbp_template_before_single_forum' || isset($theChampCounterOptions['vertical_bb_topic']) && in_array(current_filter(), array('bbp_template_before_single_topic', 'bbp_template_before_lead_topic'))) {
                if (in_array(current_filter(), array('bbp_template_before_single_topic', 'bbp_template_before_lead_topic', 'bbp_template_before_single_forum'))) {
                    echo $verticalDiv;
                } else {
                    if (is_front_page()) {
                        global $theChampVerticalCounterHomeCount, $theChampVerticalCounterExcerptCount;
                        if (current_filter() == 'the_content') {
                            $var = 'theChampVerticalCounterHomeCount';
                        } elseif (current_filter() == 'get_the_excerpt') {
                            $var = 'theChampVerticalCounterExcerptCount';
                        }
                        if (${$var} == 0) {
                            if (isset($theChampCounterOptions['vertical_target_url']) && $theChampCounterOptions['vertical_target_url'] == 'default') {
                                $counterPostUrl = site_url();
                                $counterUrl = $counterPostUrl;
                                // if bit.ly integration enabled, generate bit.ly short url
                                if (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
                                    $shortUrl = the_champ_generate_counter_bitly_url($counterPostUrl);
                                    if ($shortUrl) {
                                        $counterUrl = $shortUrl;
                                    }
                                }
                                $sharingDiv = the_champ_prepare_counter_html($counterPostUrl, 'vertical', $counterUrl);
                                $verticalDiv = "<div class='the_champ_counter_container the_champ_vertical_counter' style='" . (isset($theChampCounterOptions['alignment']) && $theChampCounterOptions['alignment'] != '' && isset($theChampCounterOptions[$theChampCounterOptions['alignment'] . '_offset']) ? $theChampCounterOptions['alignment'] . ': ' . ($theChampCounterOptions[$theChampCounterOptions['alignment'] . '_offset'] == '' ? 0 : $theChampCounterOptions[$theChampCounterOptions['alignment'] . '_offset']) . 'px;' : '') . (isset($theChampCounterOptions['top_offset']) ? 'top: ' . ($theChampCounterOptions['top_offset'] == '' ? 0 : $theChampCounterOptions['top_offset']) . 'px;' : '') . (isset($theChampCounterOptions['vertical_bg']) && $theChampCounterOptions['vertical_bg'] != '' ? 'background-color: ' . $theChampCounterOptions['vertical_bg'] . ';' : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "'>" . $sharingDiv . "</div>";
                            }
                            $content = $content . $verticalDiv;
                            ${$var}++;
                        }
                    } else {
                        $content = $content . $verticalDiv;
                    }
                }
            }
        }
    }
    if (isset($theChampSharingOptions['enable'])) {
        // sharing interface
        if (isset($theChampSharingOptions['hor_enable']) && !(isset($sharingMeta['sharing']) && $sharingMeta['sharing'] == 1 && !is_front_page())) {
            if ($sharingBpActivity) {
                $postUrl = bp_get_activity_thread_permalink();
            } elseif (isset($theChampSharingOptions['horizontal_target_url'])) {
                if ($theChampSharingOptions['horizontal_target_url'] == 'default') {
                    $postUrl = get_permalink($post->ID);
                } elseif ($theChampSharingOptions['horizontal_target_url'] == 'home') {
                    $postUrl = site_url();
                } elseif ($theChampSharingOptions['horizontal_target_url'] == 'custom') {
                    $postUrl = isset($theChampSharingOptions['horizontal_target_url_custom']) ? trim($theChampSharingOptions['horizontal_target_url_custom']) : get_permalink($post->ID);
                }
            } else {
                $postUrl = get_permalink($post->ID);
            }
            $sharingUrl = $postUrl;
            // 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($postUrl);
                if ($shortUrl) {
                    $sharingUrl = $shortUrl;
                }
            }
            $sharingDiv = the_champ_prepare_sharing_html($sharingUrl, 'horizontal', isset($theChampSharingOptions['horizontal_counts']));
            $sharingContainerStyle = '';
            $sharingTitleStyle = 'style="font-weight:bold"';
            if (isset($theChampSharingOptions['hor_sharing_alignment'])) {
                if ($theChampSharingOptions['hor_sharing_alignment'] == 'right') {
                    $sharingContainerStyle = 'style="float: right"';
                } elseif ($theChampSharingOptions['hor_sharing_alignment'] == 'center') {
                    $sharingContainerStyle = 'style="float: right;position: relative;left: -50%;text-align: left;"';
                    $sharingTitleStyle = 'style="font-weight: bold;list-style: none;position: relative;left: 50%;"';
                }
            }
            $horizontalDiv = "<div style='clear: both'></div><div " . $sharingContainerStyle . " class='the_champ_sharing_container the_champ_horizontal_sharing' super-socializer-data-href='" . $postUrl . "'><div " . $sharingTitleStyle . " >" . ucfirst($theChampSharingOptions['title']) . "</div>" . $sharingDiv . "</div><div style='clear: both'></div>";
            if ($sharingBpActivity) {
                echo $horizontalDiv;
            }
            // show horizontal sharing
            if (isset($theChampSharingOptions['home']) && is_front_page() || isset($theChampSharingOptions['category']) && is_category() || isset($theChampSharingOptions['post']) && is_single() && isset($post->post_type) && $post->post_type == 'post' || isset($theChampSharingOptions['page']) && is_page() && isset($post->post_type) && $post->post_type == 'page' || isset($theChampSharingOptions['excerpt']) && is_front_page() && current_filter() == 'get_the_excerpt' || isset($theChampSharingOptions['bb_reply']) && current_filter() == 'bbp_get_reply_content' || isset($theChampSharingOptions['bb_forum']) && (isset($theChampSharingOptions['top']) && current_filter() == 'bbp_template_before_single_forum' || isset($theChampSharingOptions['bottom']) && current_filter() == 'bbp_template_after_single_forum') || isset($theChampSharingOptions['bb_topic']) && (isset($theChampSharingOptions['top']) && in_array(current_filter(), array('bbp_template_before_single_topic', 'bbp_template_before_lead_topic')) || isset($theChampSharingOptions['bottom']) && in_array(current_filter(), array('bbp_template_after_single_topic', 'bbp_template_after_lead_topic')))) {
                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'))) {
                    echo '<div style="clear:both"></div>' . $horizontalDiv . '<div style="clear:both"></div>';
                } else {
                    if (isset($theChampSharingOptions['top']) && isset($theChampSharingOptions['bottom'])) {
                        $content = $horizontalDiv . '<br/>' . $content . '<br/>' . $horizontalDiv;
                    } else {
                        if (isset($theChampSharingOptions['top'])) {
                            $content = $horizontalDiv . $content;
                        } elseif (isset($theChampSharingOptions['bottom'])) {
                            $content = $content . $horizontalDiv;
                        }
                    }
                }
            }
        }
        if (isset($theChampSharingOptions['vertical_enable']) && !(isset($sharingMeta['vertical_sharing']) && $sharingMeta['vertical_sharing'] == 1 && !is_front_page())) {
            if (isset($theChampSharingOptions['vertical_target_url'])) {
                if ($theChampSharingOptions['vertical_target_url'] == 'default') {
                    $postUrl = get_permalink($post->ID);
                } elseif ($theChampSharingOptions['vertical_target_url'] == 'home') {
                    $postUrl = site_url();
                } elseif ($theChampSharingOptions['vertical_target_url'] == 'custom') {
                    $postUrl = isset($theChampSharingOptions['vertical_target_url_custom']) ? trim($theChampSharingOptions['vertical_target_url_custom']) : get_permalink($post->ID);
                }
            } else {
                $postUrl = get_permalink($post->ID);
            }
            $sharingUrl = $postUrl;
            // 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($postUrl);
                if ($shortUrl) {
                    $sharingUrl = $shortUrl;
                }
            }
            $sharingDiv = the_champ_prepare_sharing_html($sharingUrl, 'vertical', isset($theChampSharingOptions['vertical_counts']));
            $verticalDiv = "<div class='the_champ_sharing_container the_champ_vertical_sharing' style='" . (isset($theChampSharingOptions['alignment']) && $theChampSharingOptions['alignment'] != '' && isset($theChampSharingOptions[$theChampSharingOptions['alignment'] . '_offset']) && $theChampSharingOptions[$theChampSharingOptions['alignment'] . '_offset'] != '' ? $theChampSharingOptions['alignment'] . ': ' . $theChampSharingOptions[$theChampSharingOptions['alignment'] . '_offset'] . 'px;' : '') . (isset($theChampSharingOptions['top_offset']) && $theChampSharingOptions['top_offset'] != '' ? 'top: ' . $theChampSharingOptions['top_offset'] . 'px;' : '') . (isset($theChampSharingOptions['vertical_bg']) && $theChampSharingOptions['vertical_bg'] != '' ? 'background-color: ' . $theChampSharingOptions['vertical_bg'] : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "' super-socializer-data-href='" . $postUrl . "'>" . $sharingDiv . "</div>";
            // show vertical sharing
            if (isset($theChampSharingOptions['vertical_home']) && is_front_page() || isset($theChampSharingOptions['vertical_category']) && is_category() || isset($theChampSharingOptions['vertical_post']) && is_single() && isset($post->post_type) && $post->post_type == 'post' || isset($theChampSharingOptions['vertical_page']) && is_page() && isset($post->post_type) && $post->post_type == 'page' || isset($theChampSharingOptions['vertical_excerpt']) && is_front_page() && current_filter() == 'get_the_excerpt' || isset($theChampSharingOptions['vertical_bb_forum']) && current_filter() == 'bbp_template_before_single_forum' || isset($theChampSharingOptions['vertical_bb_topic']) && in_array(current_filter(), array('bbp_template_before_single_topic', 'bbp_template_before_lead_topic'))) {
                if (in_array(current_filter(), array('bbp_template_before_single_topic', 'bbp_template_before_lead_topic', 'bbp_template_before_single_forum'))) {
                    echo $verticalDiv;
                } else {
                    if (is_front_page()) {
                        global $theChampVerticalHomeCount, $theChampVerticalExcerptCount;
                        if (current_filter() == 'the_content') {
                            $var = 'theChampVerticalHomeCount';
                        } elseif (current_filter() == 'get_the_excerpt') {
                            $var = 'theChampVerticalExcerptCount';
                        }
                        if (${$var} == 0) {
                            if (isset($theChampSharingOptions['vertical_target_url']) && $theChampSharingOptions['vertical_target_url'] == 'default') {
                                $postUrl = site_url();
                                $sharingUrl = $postUrl;
                                // 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($postUrl);
                                    if ($shortUrl) {
                                        $sharingUrl = $shortUrl;
                                    }
                                }
                                $sharingDiv = the_champ_prepare_sharing_html($sharingUrl, 'vertical', isset($theChampSharingOptions['vertical_counts']));
                                $verticalDiv = "<div class='the_champ_sharing_container the_champ_vertical_sharing' style='" . (isset($theChampSharingOptions['alignment']) && $theChampSharingOptions['alignment'] != '' && isset($theChampSharingOptions[$theChampSharingOptions['alignment'] . '_offset']) && $theChampSharingOptions[$theChampSharingOptions['alignment'] . '_offset'] != '' ? $theChampSharingOptions['alignment'] . ': ' . $theChampSharingOptions[$theChampSharingOptions['alignment'] . '_offset'] . 'px;' : '') . (isset($theChampSharingOptions['top_offset']) && $theChampSharingOptions['top_offset'] != '' ? 'top: ' . $theChampSharingOptions['top_offset'] . 'px;' : '') . (isset($theChampSharingOptions['vertical_bg']) && $theChampSharingOptions['vertical_bg'] != '' ? 'background-color: ' . $theChampSharingOptions['vertical_bg'] : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "' super-socializer-data-href='" . $postUrl . "'>" . $sharingDiv . "</div>";
                            }
                            $content = $content . $verticalDiv;
                            ${$var}++;
                        }
                    } else {
                        $content = $content . $verticalDiv;
                    }
                }
            }
        }
    }
    return $content;
}
Пример #5
0
 /** This is rendered widget content */
 public function widget($args, $instance)
 {
     // return if counter is disabled
     if (!the_champ_social_counter_enabled() || !the_champ_vertical_counter_enabled()) {
         return;
     }
     extract($args);
     if ($instance['hide_for_logged_in'] == 1 && is_user_logged_in()) {
         return;
     }
     global $theChampCounterOptions, $post;
     $postId = $post->ID;
     if (isset($instance['target_url'])) {
         if ($instance['target_url'] == 'default') {
             if (is_home()) {
                 $counterUrl = site_url();
                 $postId = 0;
             } elseif (get_permalink($post->ID)) {
                 $counterUrl = get_permalink($post->ID);
             } else {
                 $counterUrl = html_entity_decode(esc_url(the_champ_get_http() . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]));
             }
         } elseif ($instance['target_url'] == 'homepage') {
             $counterUrl = site_url();
             $postId = 0;
         } elseif ($instance['target_url'] == 'custom') {
             $counterUrl = isset($instance['target_url_custom']) ? trim($instance['target_url_custom']) : get_permalink($post->ID);
             $postId = 0;
         }
     } else {
         $counterUrl = get_permalink($post->ID);
     }
     $ssOffset = 0;
     if (isset($instance['alignment']) && isset($instance[$instance['alignment'] . '_offset'])) {
         $ssOffset = $instance[$instance['alignment'] . '_offset'];
     }
     echo "<div class='the_champ_counter_container the_champ_vertical_counter" . (isset($theChampCounterOptions['hide_mobile_likeb']) ? ' the_champ_hide_sharing' : '') . "' ss-offset='" . $ssOffset . "' style='" . (isset($instance['alignment']) && $instance['alignment'] != '' && isset($instance[$instance['alignment'] . '_offset']) ? $instance['alignment'] . ': ' . ($instance[$instance['alignment'] . '_offset'] == '' ? 0 : $instance[$instance['alignment'] . '_offset']) . 'px;' : '') . (isset($instance['top_offset']) ? 'top: ' . ($instance['top_offset'] == '' ? 0 : $instance['top_offset']) . 'px;' : '') . (isset($instance['vertical_bg']) && $instance['vertical_bg'] != '' ? 'background-color: ' . $instance['vertical_bg'] . ';' : '-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;') . "' >";
     // if bit.ly integration enabled, generate bit.ly short url
     $shortUrl = $counterUrl;
     if (isset($theChampCounterOptions['use_shortlinks']) && function_exists('wp_get_shortlink')) {
         $shortUrl = wp_get_shortlink();
         // if bit.ly integration enabled, generate bit.ly short url
     } elseif (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
         $tempShortUrl = the_champ_generate_counter_bitly_url($counterUrl, $postId);
         if ($tempShortUrl) {
             $shortUrl = $tempShortUrl;
         }
     }
     //echo $before_widget;
     echo the_champ_prepare_counter_html($counterUrl, 'vertical', $shortUrl);
     echo "</div>";
     //echo $after_widget;
 }
Пример #6
0
/** 
 * Shortcode for Social Counter.
 */
function the_champ_counter_shortcode($params)
{
    // notify if counter is disabled
    if (the_champ_social_counter_enabled()) {
        extract(shortcode_atts(array('style' => '', 'type' => 'horizontal', 'left' => '0', 'top' => '100', 'url' => ''), $params));
        if ($type == 'horizontal' && !the_champ_horizontal_counter_enabled() || $type == 'vertical' && !the_champ_vertical_counter_enabled()) {
            return;
        }
        global $post;
        $targetUrl = $url ? $url : get_permalink($post->ID);
        $html = '<div class="the_champ_counter_container the_champ_' . $type . '_counter" ';
        $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 .= '>';
        global $theChampCounterOptions;
        $counterUrl = $targetUrl;
        // if bit.ly integration enabled, generate bit.ly short url
        if (isset($theChampCounterOptions['bitly_enable']) && isset($theChampCounterOptions['bitly_username']) && isset($theChampCounterOptions['bitly_username']) && $theChampCounterOptions['bitly_username'] != '' && isset($theChampCounterOptions['bitly_key']) && $theChampCounterOptions['bitly_key'] != '') {
            $shortUrl = the_champ_generate_counter_bitly_url($targetUrl);
            if ($shortUrl) {
                $counterUrl = $shortUrl;
            }
        }
        $html .= the_champ_prepare_counter_html($targetUrl, $type, $counterUrl);
        $html .= '</div>';
        return $html;
    }
}