Th8.us (19 characters). Customize under Settings > Tweet This. Author: Richard X. Thripp Version: 1.5 Author URI: http://richardxthripp.thripp.com/ Text Domain: tweet-this */ /** * Tweet This is a plugin for WordPress 1.5 - 2.8.2. Also: WordPress MU. * Copyright 2008-2009 Richard X. Thripp (email : richardxthripp@thripp.com) * Freely released under Version 2 of the GNU General Public License as * published by the Free Software Foundation, or, at your option, any later * version. */ /** * This is Tweet This v1.5, build 020, 2009-07-30. */ /** * Definitions and assignments. plugin_basename does not exist in WP 1.5, * so a check is necessary. If it does not exist, I assume the Tweet This * directory is named `tweet-this`. */ define('TT_ABSPATH', ABSPATH . 'wp-content/plugins/tweet-this/'); define('TT_URLPATH', get_settings('siteurl') .'/wp-content/plugins/' . 'tweet-this/'); define('TT_VERSION', '1.5'); /** * Do not edit these here, but rather, in the tt-config.php file. */ if(file_exists(TT_ABSPATH . 'tt-config.php')) require(TT_ABSPATH . 'tt-config.php'); if(TT_DIRECTORY == '' || !file_exists(TT_ABSPATH . 'tt-config.php')) define('TT_DIRECTORY', 'tweet-this'); if(TT_PREFIX == '' || !file_exists(TT_ABSPATH . 'tt-config.php')) define('TT_PREFIX', '

'); if(TT_SUFFIX == '' || !file_exists(TT_ABSPATH . 'tt-config.php')) define('TT_SUFFIX', '

'); if(TT_SEPARATOR == '' || !file_exists(TT_ABSPATH . 'tt-config.php')) define('TT_SEPARATOR', '  '); /** * Easy access to Tweet This options stored in an array in wp_options table. */ function tt_option($key) { if(TT_OVERRIDE_OPTIONS == 'true') $options = unserialize(TT_SPECIAL_OPTIONS); else $options = get_option('tweet_this_settings'); if($key == 'nw') { if($options['tt_new_window'] == 'true') return 'target="_blank" '; else return ''; } elseif($key == 'nf') { if($options['tt_nofollow'] == 'true') return 'rel="nofollow" '; else return ''; } elseif($key == 'tt_alignment') { if($options['tt_alignment'] == '') return 'left'; else return $options['tt_alignment']; } else return $options[$key]; } /** * Connects to external URL via curl and returns file. */ function tt_read_file($url) { if(ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') == 'on' || ini_get('allow_url_fopen') == 'On') { $file = @file_get_contents($url); if($file == false) { $handle = fopen($url, 'r'); $file = fread($handle, 4096); fclose($handle); } } else { if(function_exists('curl_init')) { $ch = curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5); $file = curl_exec($ch); curl_close($ch); } } if($file != false && $file != '') return $file; } /** * Retrieves the shortened URL for a post, taking into account the user's * settings. No arguments. Works on the current post. * Must be used within the loop. */ function get_tweet_this_short_url() { global $id; $purl = get_permalink(); $cached_url = get_post_meta($id, 'tweet_this_url', true); if($cached_url && $cached_url != 'getnew') return $cached_url; else { $u = tt_option('tt_url_service'); if(ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') == 'on' || ini_get('allow_url_fopen') == 'On' || function_exists('curl_init')) $u = $u; else $u = 'local'; switch($u) { case 'adjix': { if(tt_option('tt_adjix_api_key') == '') $adid = ''; else $adid = '&partnerID=' . tt_option('tt_adjix_api_key'); if(tt_option('tt_ad_vu') != 'true') $s = ''; else $s = '&ultraShort=y'; $url = tt_read_file('http://api.adjix.com/shrinkLink' . '?url=' . $purl . $adid . $s); } break; case 'bit.ly': $url = tt_read_file('http://bit.ly/api?url=' . $purl); break; case 'h3o.de': $url = tt_read_file('http://h3o.de/api/index.php?' . 'url=' . $purl); break; case 'hex.io': $url = str_replace('www.', '', tt_read_file('http://' . 'www.hex.io/api-create.php?url=' . $purl)); break; case 'idek.net': $url = tt_read_file('http://idek.net/c.php?idek-api=' . 'true&idek-ref=Tweet+This&idek-url=' . $purl); break; case 'is.gd': $url = tt_read_file('http://is.gd/api.php?longurl=' . $purl); break; case 'lin.cr': $url = tt_read_file('http://lin.cr/?mode=api&full=1' . '&l=' . $purl); break; case 'metamark': $url = tt_read_file('http://metamark.net/api/rest/' . 'simple?long_url=' . $purl); break; case 'ri.ms': $url = tt_read_file('http://ri.ms/api-create.php?' . 'url=' . $purl); break; case 'snurl': $url = tt_read_file('http://snurl.com/site/snip?r=' . 'simple&link=' . $purl); break; case 'tinyurl': $url = tt_read_file('http://tinyurl.com/' . 'api-create.php?url=' . $purl); break; case 'urlb.at': $url = tt_read_file('http://urlb.at/api/rest/?url=' . urlencode($purl)); break; case 'tweetburner': { if(function_exists('curl_init')) { $ch = curl_init('http://tweetburner.com/links'); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,'link[url]=$purl'); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5); $url = curl_exec($ch); curl_close($ch); } else $u = 'local'; } break; case 'local': { global $id; $url = get_bloginfo('url') . '/?p=' . $id; } break; default: $url = tt_read_file('http://th8.us/api.php?url=' . $purl . '&client=Tweet+This+v' . TT_VERSION . '&format=simple'); } if(tt_option('tt_url_www') == 'true' && $u != 'tweetburner') { $url = str_replace('http://www.', 'www.', $url); $url = str_replace('http://', 'www.', $url); } if($u != 'local' && (strlen($url) > 30 || $url == 'Error' || $url == 'www.' || $url == 'http://')) $url = get_bloginfo('url') . '/?p=' . $id; if(tt_option('tt_30') == 'true' && strlen($purl) < 30) { $url = $purl; if(tt_option('tt_url_www') == 'true') { $url = str_replace('http://www.', 'www.', $url); $url = str_replace('http://', 'www.', $url); } } if($cached_url == 'getnew') update_post_meta($id, 'tweet_this_url', $url, 'getnew'); else add_post_meta($id, 'tweet_this_url', $url, true); } return $url; } /** * Echoes the above function for convenience. */ function tweet_this_short_url() { echo get_tweet_this_short_url(); } /** * Parses the post title. Replaces special WordPress characters with their * generic components, because if this is not done you'll get HTML codes in * your tweet text. Also truncates the title with an ellipse if it is too long, * and URL encodes the title. The short URL lengths are hard-coded to determine * where the truncation must take place (not the best method). */ function get_tweet_this_trim_title() { $title = get_the_title(); $special = array('"', '"', '&', '&', ''', ''', '<', '<', '>', '>', ' ', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ', '–', '—', '‘', '’', '“', '”', '…', '™', '″', '&', '>', '<', '"', '’', '“', '”'); $normal = array('"', '"', '&', '&', '\'', '\'', '<', '<', '>', '>', ' ', '¡', '¢', '£', '¤', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '', '®', '¯', '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ', '--', '--', '\'', '\'', '"', '\'\'', '...', '\'', '"', '&', '>', '<', '"', '\'', '"', '"'); $title = str_replace($special, $normal, $title) . ' '; if(tt_option('tt_tweet_text') == '') $tt_len = '13'; else $tt_len = strlen(tt_option('tt_tweet_text')); $u = tt_option('tt_url_service'); switch($u) { case 'ri.ms': $url_len = '17'; break; case 'hex.io': case 'is.gd': case 'lin.cr': $url_len = '18'; break; case 'urlb.at': $url_len = '19'; break; case 'idek.net': default: $url_len = '20'; break; case 'adjix': case 'bit.ly': case 'metamark': $url_len = '21'; break; case 'h3o.de': case 'tweetburner': $url_len = '22'; break; case 'snurl': $url_len = '23'; break; case 'tinyurl': $url_len = '26'; break; case 'local': $url_len = strlen(get_bloginfo('url')) + 7; break; } if(tt_option('tt_url_www') == 'true') $url_len = ($url_len - 3); $len1 = (135 - $tt_len - $url_len); $len2 = ($len1 - 5); $len3 = ($len1 + 5); $title = substr($title, 0, $len1); $title = substr($title, 0, strrpos($title,' ')); if(strlen($title) > $len2 && strlen($title) < $len3) $title = $title . ' ...'; $title = urlencode($title); return $title; } /** * Echoes the above function for convenience. */ function tweet_this_trim_title() { echo get_tweet_this_trim_title(); } /** * Since the WordPress function is_preview doesn't exist before 2.0, * this check is necessary. */ function tt_is_preview() { if(function_exists('is_preview')) is_preview(); } /** * Returns the text for the Tweet This link, which can be specified in * Settings > Tweet This. Default is "Tweet This Post." */ function tweet_this_link_text($link_text = '', $service = 'twitter') { if($link_text == '') { if($service == 'twitter' || $service == '') { if(tt_option('tt_link_text') == '') $link_text = __('Tweet This Post', 'tweet-this'); else $link_text = tt_option('tt_link_text'); } elseif($service == 'plurk') { if(tt_option('tt_plurk_link_text') == '') $link_text = __('Plurk This Post', 'tweet-this'); else $link_text = tt_option('tt_plurk_link_text'); } elseif($service == 'buzz') { if(tt_option('tt_buzz_link_text') == '') $link_text = __('Buzz This Post', 'tweet-this'); else $link_text = tt_option('tt_buzz_link_text'); } elseif($service == 'delicious') { if(tt_option('tt_delicious_link_text') == '') $link_text = __('Delicious', 'tweet-this'); else $link_text = tt_option('tt_delicious_link_text'); } elseif($service == 'digg') { if(tt_option('tt_digg_link_text') == '') $link_text = __('Digg This Post', 'tweet-this'); else $link_text = tt_option('tt_digg_link_text'); } elseif($service == 'facebook') { if(tt_option('tt_facebook_link_text') == '') $link_text = __('Facebook', 'tweet-this'); else $link_text = tt_option('tt_facebook_link_text'); } elseif($service == 'myspace') { if(tt_option('tt_myspace_link_text') == '') $link_text = __('MySpace', 'tweet-this'); else $link_text = tt_option('tt_myspace_link_text'); } elseif($service == 'ping') { if(tt_option('tt_ping_link_text') == '') $link_text = __('Ping This Post', 'tweet-this'); else $link_text = tt_option('tt_ping_link_text'); } elseif($service == 'reddit') { if(tt_option('tt_reddit_link_text') == '') $link_text = __('Reddit', 'tweet-this'); else $link_text = tt_option('tt_reddit_link_text'); } elseif($service == 'su') { if(tt_option('tt_su_link_text') == '') $link_text = __('Stumble This Post', 'tweet-this'); else $link_text = tt_option('tt_su_link_text'); } } $link_s = array('[TITLE]', '[URL]'); $link_r = array(get_the_title(), get_tweet_this_short_url()); $link_text = str_replace($link_s, $link_r, $link_text); return $link_text; } /** * Returns the pop-up title attribute for the Tweet This link, which can be * specified in Settings > Tweet This. Default is "Post to Twitter." */ function tweet_this_title_text($title_text = '', $service = 'twitter') { if($title_text == '') { if($service == 'twitter' || $service == '') { if(tt_option('tt_title_text') == '') $title_text = __('Post to Twitter', 'tweet-this'); else $title_text = tt_option('tt_title_text'); } elseif($service == 'plurk') { if(tt_option('tt_plurk_title_text') == '') $title_text = __('Post to Plurk', 'tweet-this'); else $title_text = tt_option('tt_plurk_title_text'); } elseif($service == 'buzz') { if(tt_option('tt_buzz_title_text') == '') $title_text = __('Post to Yahoo Buzz', 'tweet-this'); else $title_text = tt_option('tt_buzz_title_text'); } elseif($service == 'delicious') { if(tt_option('tt_delicious_title_text') == '') $title_text = __('Post to Delicious', 'tweet-this'); else $title_text = tt_option('tt_delicious_title_text'); } elseif($service == 'digg') { if(tt_option('tt_digg_title_text') == '') $title_text = __('Post to Digg', 'tweet-this'); else $title_text = tt_option('tt_digg_title_text'); } elseif($service == 'facebook') { if(tt_option('tt_facebook_title_text') == '') $title_text = __('Post to Facebook', 'tweet-this'); else $title_text = tt_option('tt_facebook_title_text'); } elseif($service == 'myspace') { if(tt_option('tt_myspace_title_text') == '') $title_text = __('Post to MySpace', 'tweet-this'); else $title_text = tt_option('tt_myspace_title_text'); } elseif($service == 'ping') { if(tt_option('tt_ping_title_text') == '') $title_text = __('Post to Ping.fm', 'tweet-this'); else $title_text = tt_option('tt_ping_title_text'); } elseif($service == 'reddit') { if(tt_option('tt_reddit_title_text') == '') $title_text = __('Post to Reddit', 'tweet-this'); else $title_text = tt_option('tt_reddit_title_text'); } elseif($service == 'su') { if(tt_option('tt_su_title_text') == '') $title_text = __('Post to StumbleUpon', 'tweet-this'); else $title_text = tt_option('tt_su_title_text'); } } $title_s = array('[TITLE]', '[URL]'); $title_r = array(get_the_title(), get_tweet_this_short_url()); $title_text = str_replace($title_s, $title_r, $title_text); return $title_text; } /** * Determines whether the Tweet This link can be displayed on the current post. * If true, this function returns what you put in. If false, it returns blank. * This function is complicated because the user can specify that links be * hidden on posts and/or only shown on single posts, and this can be * over-ridden for individual posts and pages. */ function tt_display_limits($item) { if(!tt_is_preview()) { if(tt_option('tt_limit_to_posts') == 'true') { if(tt_option('tt_limit_to_single') == 'true') { if(is_single()) return $item; } else { if(!is_page()) return $item; } } if(tt_option('tt_limit_to_single') == 'true') { if(tt_option('tt_limit_to_posts') == 'true') { if(is_single()) return $item; } else { if(is_single() || is_page()) return $item; } } if(tt_option('tt_limit_to_posts') != 'true' && tt_option('tt_limit_to_single') != 'true') return $item; } } /** * Generates the Twitter URL; the direct URL to tweet a post to Twitter, * taking into account the user's settings. */ function get_tweet_this_url($tweet_text = '', $service = '') { if($tweet_text == '') { if($service == 'twitter' || $service == '') { if(tt_option('tt_tweet_text') == '') $tweet_text = '[TITLE] [URL]'; else $tweet_text = tt_option('tt_tweet_text'); $path = 'http://twitter.com/home/?status='; } elseif($service == 'plurk') { if(tt_option('tt_plurk_text') == '') $tweet_text = '[TITLE] [URL]'; else $tweet_text = tt_option('tt_plurk_text'); $path = 'http://plurk.com/?status='; } } $tweet_s = array('[TITLE]', '[URL]', ' '); $tweet_r = array(get_tweet_this_trim_title(), get_tweet_this_short_url(), '+'); $tweet_text = str_replace($tweet_s, $tweet_r, $tweet_text); $item = $path . $tweet_text; return tt_display_limits($item); } /** * Echoes the above function for convenience. */ function tweet_this_url($tweet_text = '') { echo get_tweet_this_url($tweet_text); } /** * This is the core function of the plugin. Generates the Tweet This links, * including images, text, a title attributes, and new window and nofollow * preferences. Relies on a myriad of other functions, and takes a slew of * arguments to be used for every social networking service Tweet This offers. * This function can also be manually placed into the theme with the * arguments customized to your liking, and "Insert Tweet This links" * disabled in the options (so they don't appear twice). */ function get_tweet_this($service = 'twitter', $tweet_text = '', $link_text = '', $title_text = '', $icon_file = '', $a_class = '', $img_class = '', $img_alt = '') { if($a_class == '') { if(tt_option('tt_link_css_class') == '') $a_class = 'tt'; else $a_class = tt_option('tt_link_css_class'); } if($img_class == '') { if(tt_option('tt_img_css_class') == '') $img_class = 'nothumb'; else $img_class = tt_option('tt_img_css_class'); } $url = get_tweet_this_url($tweet_text, $service); $title = tweet_this_title_text($title_text, $service); $link = tweet_this_link_text($link_text, $service); if($service == 'twitter' || $service == '') { if($img_alt == '') $img_alt = __('Post to Twitter', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_twitter_icon') == '') $icon_file = 'tt-twitter.png'; else $icon_file = tt_option('tt_twitter_icon'); } } if($service == 'plurk') { if($img_alt == '') $img_alt = __('Post to Plurk', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_plurk_icon') == '') $icon_file = 'tt-plurk.png'; else $icon_file = tt_option('tt_plurk_icon'); } } if($service == 'buzz') { if($img_alt == '') $img_alt = __('Post to Yahoo Buzz', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_buzz_icon') == '') $icon_file = 'tt-buzz.png'; else $icon_file = tt_option('tt_buzz_icon'); } $url = 'http://buzz.yahoo.com/submit?submitUrl=' . get_permalink() . '&submitHeadline=' . get_tweet_this_trim_title(); } if($service == 'delicious') { if($img_alt == '') $img_alt = __('Post to Delicious', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_delicious_icon') == '') $icon_file = 'tt-delicious.png'; else $icon_file = tt_option('tt_delicious_icon'); } $url = 'http://delicious.com/post?url=' . get_permalink() . '&title=' . get_tweet_this_trim_title(); } if($service == 'digg') { if($img_alt == '') $img_alt = __('Post to Digg', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_digg_icon') == '') $icon_file = 'tt-digg.png'; else $icon_file = tt_option('tt_digg_icon'); } $url = 'http://digg.com/submit?url=' . get_permalink() . '&title=' . get_tweet_this_trim_title(); } if($service == 'facebook') { if($img_alt == '') $img_alt = __('Post to Facebook', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_facebook_icon') == '') $icon_file = 'tt-facebook.png'; else $icon_file = tt_option('tt_facebook_icon'); } $url = 'http://www.facebook.com/share.php?u=' . get_permalink() . '&t=' . get_tweet_this_trim_title(); } if($service == 'myspace') { if($img_alt == '') $img_alt = __('Post to MySpace', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_myspace_icon') == '') $icon_file = 'tt-myspace.png'; else $icon_file = tt_option('tt_myspace_icon'); } $url = 'http://www.myspace.com/Modules/PostTo/Pages/' . '?l=3&u=' . get_permalink() . '&t=' . get_tweet_this_trim_title() . '&c=%3Cp%3E' . 'Powered+by+%3Ca+href%3D%22http%3A%2F%2F' . 'richardxthripp.thripp.com%2Ftweet-this%22%3E' . 'Tweet+This%3C%2Fa%3E%3C%2Fp%3E'; } if($service == 'ping') { if($img_alt == '') $img_alt = __('Post to Ping.fm', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_ping_icon') == '') $icon_file = 'tt-ping.png'; else $icon_file = tt_option('tt_ping_icon'); } $url = 'http://ping.fm/ref/?method=microblog&title=' . get_tweet_this_trim_title() . '&link=' . get_permalink(); } if($service == 'reddit') { if($img_alt == '') $img_alt = __('Post to Reddit', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_reddit_icon') == '') $icon_file = 'tt-reddit.png'; else $icon_file = tt_option('tt_reddit_icon'); } $url = 'http://reddit.com/submit?url=' . get_permalink() . '&title=' . get_tweet_this_trim_title(); } if($service == 'su') { if($img_alt == '') $img_alt = __('Post to StumbleUpon', 'tweet-this'); if($icon_file == '') { if(tt_option('tt_su_icon') == '') $icon_file = 'tt-su.png'; else $icon_file = tt_option('tt_su_icon'); } $url = 'http://stumbleupon.com/submit?url=' . get_permalink() . '&title=' . get_tweet_this_trim_title(); } $icon = TT_URLPATH . 'icons/' . $icon_file; if($icon_file != 'noicon') $item = '' .
			$img_alt . ''; if(tt_option('tt_link_text') != '[BLANK]' && $link_text != '[BLANK]') $item .= ' ' . $link . ''; return tt_display_limits($item); } /** * Echoes the above function for convenience. */ function tweet_this($service = 'twitter', $tweet_text = '', $link_text = '', $title_text = '', $icon_file = '', $a_class = '', $img_class = '', $img_alt = '') { echo get_tweet_this($service, $tweet_text, $link_text, $title_text, $icon_file, $a_class, $img_class, $img_alt); } /** * This function parses the RSS feed from Twitter for tweets containing the * cached shortened URLs. The tweets are then displayed in a list below each * post if "Display 'Tweets about this post' list below Tweet This links" is * checked under Settings > Tweet This. */ function tt_twitter_rss() { // ***** BEGIN RSS FUNCTION ***** // if(TT_TWITTER_RSS == 'true') { require_once(ABSPATH . WPINC . '/rss.php'); $h = array('http://www.', 'http://', 'www.'); $h2 = array('', '', ''); $url = 'http://search.twitter.com/search.atom?q=' . str_replace($h, $h2, get_tweet_this_short_url()); $limit = tt_option('tt_rss_limit'); if($limit == '') $limit = '10'; $rss = fetch_rss($url); if($rss) { global $i; $i = 1; $text = ''; foreach($rss->items as $item) { $href = $item['link']; $title = $item['title']; $user_1 = array('http://twitter.com/', '/'); $user_2 = array('', ''); $user = str_replace($user_1, $user_2, $href); $user = preg_replace('/statuses.+/', '', $user); $date = $item['published']; $text .= '
' . $user . ' at ' . $date . ': ' . $title . ''; if($i == $limit) break; $i = $i + 1; } } return $text;} // ****** END RSS FUNCTION ****** // } /** * The function that inserts the Tweet This links, including the other social * networking services. Relies on many other functions. */ function insert_tweet_this($content) { global $id; $tweet_this_hide = get_post_meta($id, 'tweet_this_hide', true); if($tweet_this_hide && $tweet_this_hide != 'false') $content = $content; else { if(tt_option('tt_auto_display') == 'true' || tt_option('tt_plurk') == 'true' || tt_option('tt_buzz') == 'true' || tt_option('tt_delicious') == 'true' || tt_option('tt_digg') == 'true' || tt_option('tt_facebook') == 'true' || tt_option('tt_digg') == 'true' || tt_option('tt_ping') == 'true' || tt_option('tt_reddit') == 'true' || tt_option('tt_su') == 'true') $content .= tt_display_limits(TT_PREFIX); if(tt_option('tt_auto_display') == 'true') $content .= get_tweet_this('twitter'); if(tt_option('tt_plurk') == 'true') $content .= TT_SEPARATOR . get_tweet_this('plurk'); if(tt_option('tt_buzz') == 'true') $content .= TT_SEPARATOR . get_tweet_this('buzz'); if(tt_option('tt_delicious') == 'true') $content .= TT_SEPARATOR . get_tweet_this('delicious'); if(tt_option('tt_digg') == 'true') $content .= TT_SEPARATOR . get_tweet_this('digg'); if(tt_option('tt_facebook') == 'true') $content .= TT_SEPARATOR . get_tweet_this('facebook'); if(tt_option('tt_myspace') == 'true') $content .= TT_SEPARATOR . get_tweet_this('myspace'); if(tt_option('tt_ping') == 'true') $content .= TT_SEPARATOR . get_tweet_this('ping'); if(tt_option('tt_reddit') == 'true') $content .= TT_SEPARATOR . get_tweet_this('reddit'); if(tt_option('tt_su') == 'true') $content .= TT_SEPARATOR . get_tweet_this('su'); if(tt_option('tt_auto_display') == 'true' || tt_option('tt_plurk') == 'true' || tt_option('tt_buzz') == 'true' || tt_option('tt_delicious') == 'true' || tt_option('tt_digg') == 'true' || tt_option('tt_facebook') == 'true' || tt_option('tt_myspace') == 'true' || tt_option('tt_ping') == 'true' || tt_option('tt_reddit') == 'true' || tt_option('tt_su') == 'true') $content .= tt_display_limits(TT_SUFFIX); $h = array('http://www.', 'http://', 'www.'); $h2 = array('', '', ''); global $i; $url = str_replace($h, $h2, get_tweet_this_short_url()); // ***** BEGIN RSS FUNCTION ***** // if(TT_TWITTER_RSS == 'true') { $item = '

' . __('Tweets about this post', 'tweet-this') . ':' . tt_twitter_rss() . '

'; if(tt_option('tt_rss') == 'true' && $i > 1) { if(tt_option('tt_rss_lts') == 'true') { if(is_single() || is_page()) $content .= tt_display_limits($item); else $content = $content; } else $content .= tt_display_limits($item); } } // ****** END RSS FUNCTION ****** // } return $content; } /** * This is the CSS that is inserted using the wp_head hook. */ function tweet_this_css() { echo ''; } /** * This function is called to update the options stored in the database when * the user changes them. */ function update_tt_options() { if(isset($_REQUEST['tt'])) $new_options = $_REQUEST['tt']; $booleans = array('tt_30', 'tt_limit_to_single', 'tt_limit_to_posts', 'tt_rss_lts', 'tt_url_www', 'tt_rss', 'tt_auto_display', 'tt_plurk', 'tt_buzz', 'tt_delicious', 'tt_digg', 'tt_facebook', 'tt_myspace', 'tt_ping', 'tt_reddit', 'tt_su', 'tt_ad_vu', 'tt_footer', 'tt_ads', 'tt_new_window', 'tt_nofollow'); foreach($booleans as $key) $new_options[$key] = $new_options[$key] ? 'true' : 'false'; if(tt_option('tt_url_service') != $new_options['tt_url_service'] || tt_option('tt_url_www') != $new_options['tt_url_www'] || tt_option('tt_30') != $new_options['tt_30']) global_flush_tt_cache(); update_option('tweet_this_settings', $new_options); echo '

' . __('Tweet This options saved.', 'tweet-this') . '

'; } /** * Outputs the list of image options for each social networking service in the * options form under Settings > Tweet This. Spaghetti code. */ function tt_image_selection($s) { $l = '/wp-content/plugins/tweet-this/icons/tt-'; $c = ' checked="checked"'; $u = get_option('siteurl'); $z = '.png" /> tt-' . $s . $z .
		$s . '_icon] tt-' . $s .
		'-big1' . $z . $s . '_icon] tt-' . $s .
		'-big2' . $z . $s . '_icon] tt-' . $s .
		'-big3' . $z . $s . '_icon] tt-' . $s .
		'-big4' . $z . $s . '_icon] tt-' .
		$s . '-micro3' . $z . $s . '_icon] tt-' .
		$s . '-micro4' . $z . $s . '_icon] No icon.

'; if($s == 'twitter') { echo '

'; } } /** * Outputs the select option for each URL service when fed the correct * arguments. Used for the options form under Settings > Tweet This. */ function tt_url_service($id, $title, $chars, $special = '') { echo ''; } /** * This is the options form accessible under Settings > Tweet This. It uses the * two functions above to economize on size. */ function print_tt_form() { require(TT_ABSPATH . 'lib/tt-options.php'); } /** * Adds the default Tweet This options to the database upon activation of the * plugin or resetting of the options. Cleans up some old records from * Tweet This v1.1 if they are still present. */ function tweet_this_install() { $add_options = array('tt_30' => 'false', 'tt_url_service' => 'th8.us', 'tt_alignment' => 'left', 'tt_limit_to_single' => 'false', 'tt_limit_to_posts' => 'false', 'tt_rss' => 'false', 'tt_rss_limit' => '10', 'tt_rss_lts' => 'false', 'tt_url_www' => 'false', 'tt_footer' => 'false', 'tt_ads' => 'false', 'tt_new_window' => 'false', 'tt_nofollow' => 'false', 'tt_img_css_class' => 'nothumb', 'tt_link_css_class' => 'tt', 'tt_adjix_api_key' => '', 'tt_ad_vu' => 'true', 'tt_auto_display' => 'true', 'tt_tweet_text' => '[TITLE] [URL]', 'tt_link_text' => __('Tweet This Post', 'tweet-this'), 'tt_title_text' => __('Post to Twitter', 'tweet-this'), 'tt_twitter_icon' => 'tt-twitter.png', 'tt_plurk' => 'false', 'tt_plurk_text' => '[TITLE] [URL]', 'tt_plurk_link_text' => __('Plurk This Post', 'tweet-this'), 'tt_plurk_title_text' => __('Post to Plurk', 'tweet-this'), 'tt_plurk_icon' => 'tt-plurk.png', 'tt_buzz' => 'false', 'tt_buzz_link_text' => __('Buzz This Post', 'tweet-this'), 'tt_buzz_title_text' => __('Post to Yahoo Buzz', 'tweet-this'), 'tt_buzz_icon' => 'tt-buzz.png', 'tt_delicious' => 'false', 'tt_delicious_link_text' => __('Delicious', 'tweet-this'), 'tt_delicious_title_text' => __('Post to Delicious', 'tweet-this'), 'tt_delicious_icon' => 'tt-delicious.png', 'tt_digg' => 'false', 'tt_digg_link_text' => __('Digg This Post', 'tweet-this'), 'tt_digg_title_text' => __('Post to Digg', 'tweet-this'), 'tt_digg_icon' => 'tt-digg.png', 'tt_facebook' => 'false', 'tt_facebook_link_text' => __('Facebook', 'tweet-this'), 'tt_facebook_title_text' => __('Post to Facebook', 'tweet-this'), 'tt_facebook_icon' => 'tt-facebook.png', 'tt_myspace' => 'false', 'tt_myspace_link_text' => __('MySpace', 'tweet-this'), 'tt_myspace_title_text' => __('Post to MySpace', 'tweet-this'), 'tt_myspace_icon' => 'tt-myspace.png', 'tt_ping' => 'false', 'tt_ping_link_text' => __('Ping This Post', 'tweet-this'), 'tt_ping_title_text' => __('Post to Ping.fm', 'tweet-this'), 'tt_ping_icon' => 'tt-ping.png', 'tt_reddit' => 'false', 'tt_reddit_link_text' => __('Reddit', 'tweet-this'), 'tt_reddit_title_text' => __('Post to Reddit', 'tweet-this'), 'tt_reddit_icon' => 'tt-reddit.png', 'tt_su' => 'false', 'tt_su_link_text' => __('Stumble This Post', 'tweet-this'), 'tt_su_title_text' => __('Post to StumbleUpon', 'tweet-this'), 'tt_su_icon' => 'tt-su.png'); foreach($add_options as $key => $value) { if($old = get_option($key)) { $add_options[$key] = $old; delete_option($key); } } if(get_option('tweet_this_settings') == '') add_option('tweet_this_settings', $add_options); delete_option('tt_add_title'); delete_option('tt_big_icon'); delete_option('tt_icon'); delete_option('tt_small_icon'); delete_option('tweet_this_import_key'); } /** * Inserts the options page into the menu under Settings > Tweet This. */ function tweet_this_add_options() { if(function_exists('add_options_page')) { add_options_page(__('Tweet This Options', 'tweet-this'), __('Tweet This', 'tweet-this'), 8, __FILE__, 'tweet_this_options'); } } /** * Simple function that prints the options form and updates the options. * From testing, I determined that the only way to get imported options to * show up properly in the form is by refreshing the options page twice. * Once is easy, but twice requires persistent data, so I created a * separate options key in the database for the import phase. */ function tweet_this_options() { if($_REQUEST['submit']) update_tt_options(); elseif($_REQUEST['reset']) { delete_option('tweet_this_settings'); global_flush_tt_cache(); tweet_this_install(); } elseif($_REQUEST['import']) { global $wpdb; $import_options = $_POST['import_content']; if(substr($import_options, 0, 1) == 'a') { $wpdb->query("UPDATE $wpdb->options SET option_value = '$import_options' WHERE option_name = 'tweet_this_settings'"); update_option('tweet_this_import_key', 'phase2'); echo '

' . __('Importing Tweet This options. ' . 'Please wait...', 'tweet-this') . '

'; global_flush_tt_cache(); $show_form = 'false'; } else echo '

' . __('There is something wrong with the' . ' provided options. Import aborted.', 'tweet-this') . '

'; } elseif(get_option('tweet_this_import_key') == 'phase2') { echo '

' . __('Still importing Tweet This options. Please ' . 'wait...', 'tweet-this') . '

'; update_option('tweet_this_import_key', 'phase3'); $show_form = 'false'; } elseif(get_option('tweet_this_import_key') == 'phase3') { update_option('tweet_this_import_key', 'phase1'); echo '

' . __('Tweet This options imported successfully!', 'tweet-this') . '

'; } if($show_form != 'false') print_tt_form(); } /** * Sets one cached URL to "getnew". get_tweet_this_short_url() regenerates * the shortened URL based on the the user's settings. This is used when * the user edits a post or changes permalinks. */ function flush_tt_cache($post_id) { $cached_tt_url = get_post_meta($post_id, 'tweet_this_url', true); if($cached_tt_url && $cached_tt_url != 'getnew') { update_post_meta($post_id, 'tweet_this_url', 'getnew'); } } /** * Deletes a cached URL. Triggered when you delete a post. */ function delete_tt_cache() { global $id; delete_post_meta($id, 'tweet_this_url'); } /** * Sets every shortened URL in the database to "getnew", triggering a reindex * the first time each post is viewed again. This is used when you change * permalink structures or URL services, since the old URLs can no longer be * trusted. Meta keys are reused to prevent artifical inflation of ID counter. */ function global_flush_tt_cache() { global $wpdb; $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = 'getnew' WHERE meta_key = 'tweet_this_url'"); } /** * Deletes every cached URL upon deactivating the plugin. Dangerous function. * I realize some people would prefer not to have their cached URLs deleted * when deactivating, as this also inflates the meta key ID counter, but * people who are removing Tweet This permanently do not want hundreds of * cached URLs to remain in the database, so this function stays. */ function global_delete_tt_cache() { global $wpdb; $wpdb->query("DELETE FROM $wpdb->postmeta " . "WHERE meta_key = 'tweet_this_url'"); delete_option('tweet_this_import_key'); } /** * Loads the textdomain. For internationalization. */ function tweet_this_init() { load_plugin_textdomain('tweet-this', 'wp-content/plugins/tweet-this/languages'); } /** * The footer advertisement for Tweet This. This is inserted into your blog if * "Insert Tweet This message in footer" is checked under Settings > Tweet This * (default is checked). */ function tweet_this_footer() { printf(__('

Twitter links powered by ' . 'Tweet' . ' This v%1$s, a WordPress plugin for Twitter.

', 'tweet-this'), TT_VERSION); } /** * Inserts Google AdSense ad using my publisher ID into the body of your blog * if "Insert Google AdSense ads to support Tweet This" is checked in * Settings > Tweet This (default is unchecked). These ads pull in $50 a month * for me, paying half the hosting bill for my URL shortening service, Th8.us, * and my blog. */ function tweet_this_ad_body($content) { if(is_single() || is_page()) $content .= '

'; return $content; } /** * An ad is also inserted into the footer if the ads option is checked. */ function tweet_this_ad_footer() { echo '

'; } /** * Miscellaneous insertions and actions to update the database of cached URLs * as you publish, edit, and delete posts and pages. */ if(tt_option('tt_footer') == 'true') add_action('wp_footer', 'tweet_this_footer'); if(tt_option('tt_ads') == 'true') { add_action('the_content', 'tweet_this_ad_body'); add_action('wp_footer', 'tweet_this_ad_footer');} add_action('init', 'tweet_this_init'); if(TT_HIDE_MENU != 'true') add_action('admin_menu', 'tweet_this_add_options'); add_action('publish_post', 'flush_tt_cache'); add_action('publish_future_post', 'flush_tt_cache'); add_action('save_post', 'flush_tt_cache'); add_action('edit_post', 'flush_tt_cache'); add_action('delete_post', 'delete_tt_cache'); add_action('generate_rewrite_rules', 'global_flush_tt_cache'); add_action('wp_head', 'tweet_this_css'); add_filter('the_content', 'insert_tweet_this'); /** * Activation / deactivation hooks. */ if(function_exists('register_activation_hook')) register_activation_hook(__FILE__, 'tweet_this_install'); if(function_exists('register_deactivation_hook')) register_deactivation_hook(__FILE__, 'global_delete_tt_cache'); ?>