/** * 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 (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; } }
/** * 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; } }
/** * Check if Facebook Like/Recommend is enabled */ function the_champ_facebook_like_rec_enabled() { global $theChampCounterOptions; 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'])))) { return true; } return false; }
/** This is rendered widget content */ function widget($args, $instance) { // return if sharing is disabled if (!the_champ_social_counter_enabled() || !the_champ_horizontal_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_horizontal_counter'>"; 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 $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 the_champ_prepare_counter_html($counterUrl, 'horizontal', $shortUrl); if (!empty($instance['after_widget_content'])) { echo '<div>' . $instance['after_widget_content'] . '</div>'; } echo "</div>"; echo $after_widget; }