From 93d0a0529706099b51dfa76ed17d380404b796e4 Mon Sep 17 00:00:00 2001 From: Jesper Johansen Date: Sun, 7 Jul 2013 23:58:30 +0200 Subject: [PATCH] Remove the Tweet Button extension The share button shortcodes should never have been in the theme in the first place. The Twitter share button now uses an anchor link and javascript instead of the PHP version or an iframe. --- functions.php | 4 - functions/shortcodes.php | 73 +++++++---------- functions/tweet_button.php | 162 ------------------------------------- 3 files changed, 31 insertions(+), 208 deletions(-) delete mode 100644 functions/tweet_button.php diff --git a/functions.php b/functions.php index 5965127..cb82880 100644 --- a/functions.php +++ b/functions.php @@ -80,7 +80,6 @@ function cakifo_theme_setup() { add_theme_support( 'cakifo-shortcodes' ); add_theme_support( 'cakifo-colorbox' ); - add_theme_support( 'cakifo-twitter-button' ); /* Load Theme Settings */ if ( is_admin() ) { @@ -288,9 +287,6 @@ function cakifo_load_theme_support() { /* Load the Colorbox Script extention if supported. */ require_if_theme_supports( 'cakifo-colorbox', $template_directory . 'functions/colorbox.php' ); - - /* Load the Twitter Button extention if supported */ - require_if_theme_supports( 'cakifo-twitter-button', $template_directory . 'functions/tweet_button.php' ); } add_action( 'after_setup_theme', 'cakifo_load_theme_support', 12 ); diff --git a/functions/shortcodes.php b/functions/shortcodes.php index e632472..40bdca6 100644 --- a/functions/shortcodes.php +++ b/functions/shortcodes.php @@ -166,55 +166,44 @@ function cakifo_entry_facebook_link_shortcode( $attr ) { * @since Cakifo 1.0.0 */ function cakifo_entry_twitter_link_shortcode( $attr ) { + + static $first = true; + $attr = shortcode_atts( array( 'href' => get_permalink(), 'text' => the_title_attribute( 'echo=0' ), - 'layout' => 'horizontal', // horizontal, vertical, none - 'via' => hybrid_get_setting( 'twitter_username' ), - 'width' => 55, // Only need to use if there's no add_theme_support( 'cakifo-twitter-button' ) - 'height' => 20, // Only need to use if there's no add_theme_support( 'cakifo-twitter-button' ) + 'layout' => 'horizontal', // horizontal, vertical, non + 'via' => '', 'before' => '', 'after' => '', ), $attr, 'entry-twitter-link' ); - /* Load the PHP tweet button script if the theme supports it */ - if ( current_theme_supports( 'cakifo-twitter-button' ) ) : - - return cakifo_tweet_button( - array( - 'before' => $attr['before'], - 'after' => $attr['after'], - 'layout' => $attr['layout'], - 'href' => $attr['href'], - 'counturl' => $attr['href'], - 'text' => $attr['text'], - 'layout' => $attr['layout'], - 'via' => $attr['via'] - ) - ); - - /* Else, load the Twitter iframe */ - else : - - // Set the height to 62px if the layout is vertical and the height is the default value - if ( 'vertical' == $attr['layout'] && 20 == $attr['height'] ) - $attr['height'] = 62; - - // Set width to 110px if the layout is horizontal and the width is the default value - if ( 'horizontal' == $attr['layout'] && 55 == $attr['width'] ) - $attr['width'] = 110; - - // Build the query - $query_args = array( - 'url' => esc_url( $attr['href'] ), - 'via' => esc_attr( $attr['via'] ), - 'text' => esc_attr( $attr['text'] ), - 'count' => esc_attr( $attr['layout'] ) - ); - - return $attr['before'] . '' . $attr['after']; - - endif; + // Only add the script once + $script = ( $first ) ? "" : ""; + + $first = false; + + // Build the query + $query_args = array( + 'url' => esc_url( $attr['href'] ), + 'counturl' => esc_url( $attr['href'] ), + 'text' => esc_attr( $attr['text'] ), + 'count' => esc_attr( $attr['layout'] ), + ); + + /* Use the shortlink as the share URL if it exists. */ + $shortlink = wp_get_shortlink(); + + if ( ! empty( $shortlink ) ) { + $query_args['url'] = esc_url( $shortlink ); + } + + /* Set 'via' attribute. */ + if ( ! empty( $attr['via'] ) ) { + $query_args['via'] = esc_attr( $attr['via'] ); + } + + return $attr['before'] . '' . $attr['after'] . $script; } /** diff --git a/functions/tweet_button.php b/functions/tweet_button.php deleted file mode 100644 index 9385069..0000000 --- a/functions/tweet_button.php +++ /dev/null @@ -1,162 +0,0 @@ - - * @link http://nicolasgallagher.com/custom-tweet-button-for-wordpress/ - * @version 1.2.1 - * @since Cakifo 1.3.0 - * - * Copyright 2010-2012 Nicolas Gallagher - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/** - * Display the tweet button - * - * @since Cakifo 1.3.0 - * @param array $args Array with arguments - * @staticvar integer $i Used to count how many times the function has been referenced - * @return string The tweet button - */ -function cakifo_tweet_button( $args = array() ) { - - /** - * Count how many times the function has been referenced - * @var integer - */ - static $i = 0; - $i++; - - /** - * Default values for the button - * @var array - */ - $defaults = array( - 'before' => '', - 'after' => '', - 'href' => wp_get_shortlink(), - 'via' => hybrid_get_setting( 'twitter_username' ), - 'text' => the_title_attribute( 'echo=0' ), - 'related' => '', - 'layout' => 'vertical', // none, horizontal, vertical - 'counturl' => get_permalink(), - ); - - // Merge them - $args = wp_parse_args( $args, $defaults ); - - /** - * Set up variables - */ - $post_id = get_queried_object_id(); - $url = trailingslashit( $args['href'] ); - $counturl = trailingslashit( $args['counturl'] ); - $cache_interval = 60; - $refresh_interval = 3660; - $retweet_count = null; - $count = 0; - $counter = ''; - - // Retweet data (Twitter API) - $retweet_meta = get_post_meta( $post_id, "retweet_{$i}_cache", true ); - - if ( ! empty( $retweet_meta ) ) { - $retweet_pieces = explode( ':', $retweet_meta ); - $retweet_timestamp = (int) $retweet_pieces[0]; - $retweet_count = (int) $retweet_pieces[1]; - } - - // Expire retweet cache - if ( $retweet_count === null || time() > $retweet_timestamp + $cache_interval ) : - - $retweet_response = wp_remote_get( 'http://urls.api.twitter.com/1/urls/count.json?url=' . $counturl ); - - if ( ! is_wp_error( $retweet_response ) ) : - - $retweet_data = json_decode( wp_remote_retrieve_body( $retweet_response ), true ); - - if ( isset( $retweet_data['count'] ) && isset( $retweet_data['url'] ) && $retweet_data['url'] === $counturl ) : - - if ( (int) $retweet_data['count'] >= $retweet_count || time() > $retweet_timestamp + $refresh_interval ) : - - $retweet_count = $retweet_data['count']; - - if ( empty( $retweet_meta ) ) - add_post_meta( $post_id, "retweet_{$i}_cache", time() . ':' . $retweet_count ); - else - update_post_meta( $post_id, "retweet_{$i}_cache", time() . ':' . $retweet_count ); - - endif; - - endif; - - endif; // $retweet_response - - endif; // expire retweet cache - - /** - * Check for "retweet_count_start" custom field - * - * Manually set the starting number of retweets for a post that existed before the Tweet Button was created - * the number can be roughly calculated by subtracting the twitter API's retweet count - * from the estimated number of retweets according to the topsy, backtype, or tweetmeme services - */ - $retweet_count_start = get_post_meta( $post_id, "retweet_{$i}_count_start", true ); - - /* Calculate the total count to display */ - $count = $retweet_count + (int) $retweet_count_start; - - if ( $count > 9999 ) { - $count = $count / 1000; - $count = number_format( $count, 1 ) . 'K'; - } else { - $count = number_format( $count ); - } - - /** - * Construct the tweet button query string - */ - $query = http_build_query( - array( - 'text' => $args['text'], - 'url' => $url, - 'counturl' => $args['counturl'], - 'via' => ( $args['via'] ) ? $args['via'] : '', - 'related' => ( $args['related'] ) ? $args['related'] : '', - ), - '', '&' // Make sure that the ampersands are encoded - ); - - if ( $args['layout'] != 'none' ) - $counter = '' . $count . ''; - - /* HTML for the tweet button */ - $twitter_share = ' -
- ' . $counter . ' -
- '; - - return $args['before'] . $twitter_share . $args['after']; -}