diff -r 000000000000 -r 03b0d1493584 web/wp-content/plugins/twitter-tools-bitly-links/twitter-tools-bitly-links.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/twitter-tools-bitly-links/twitter-tools-bitly-links.php Wed Dec 23 17:55:33 2009 +0000 @@ -0,0 +1,184 @@ +Twitter Tools posts to Twitter be API-created bit.ly links so you can track the number of clicks and such via your bit.ly account. Requires PHP 5.2.0+. +Author: Viper007Bond +Author URI: http://www.viper007bond.com/ + +**************************************************************************/ + +class TwitterToolsBitlyLinks { + + // Initalize the plugin by registering the hooks + function __construct() { + // Twitter Tools v2.0+ supports this natively. Don't do anything if that sub-plugin is active. + if ( function_exists('aktt_bitly_shorten_url') ) + return false; + + // Load localization domain + load_plugin_textdomain( 'twitter-tools-bitly-links', false, '/twitter-tools-bitly-links/localization' ); + + // This plugin requires PHP 5.2.0+ and WordPress 2.7+ + if ( function_exists('json_decode') && function_exists('wp_remote_retrieve_body') ) { + // Register options + add_option( 'viper_ttbl_login' ); + add_option( 'viper_ttbl_apikey' ); + + // Register hooks + add_action( 'admin_menu', array(&$this, 'register_settings_page') ); + add_action( 'wp_ajax_viper_ttbl_check', array(&$this, 'ajax_authentication_check') ); + add_filter( 'whitelist_options', array(&$this, 'whitelist_options') ); + add_filter( 'tweet_blog_post_url', array(&$this, 'modify_url') ); + + // Make sure the user has filled in their login and API key + $login = trim( get_option('viper_ttbl_login') ); + $apikey = trim( get_option('viper_ttbl_apikey') ); + if ( ( !$login || !$apikey ) && current_user_can('manage_options') ) + add_action( 'admin_notices', array(&$this, 'settings_warn') ); + } + + // Old version of PHP or WordPress? Let the user know. + elseif ( current_user_can('activate_plugins') ) { + add_action( 'admin_notices', array(&$this, 'old_version_warning') ); + } + } + + + // Register the settings page + function register_settings_page() { + add_options_page( __('Twitter Tools: bit.ly Links', 'twitter-tools-bitly-links'), __('Twitter Tools: bit.ly', 'twitter-tools-bitly-links'), 'manage_options', 'twitter-tools-bitly-links', array(&$this, 'settings_page') ); + } + + + // Whitelist the options to allow saving via options.php + function whitelist_options( $whitelist_options ) { + $whitelist_options['twitter-tools-bitly-links'] = array( 'viper_ttbl_login', 'viper_ttbl_apikey' ); + + return $whitelist_options; + } + + + // Warn about an old version of PHP or WordPress + function old_version_warning() { + global $wp_version; + echo '

' . sprintf( __( 'Twitter Tools: bit.ly Links: You do not meet the minimum requirements of PHP %1$s and WordPress %2$s. You are currently using PHP %3$s and WordPress %4$s.', 'vipers-video-quicktags' ), '5.2.0', '2.7', PHP_VERSION, $wp_version ) . "

\n"; + } + + + // Display a notice telling the user to fill in their bit.ly details + function settings_warn() { + echo '

' . sprintf( __( 'Twitter Tools: bit.ly Links: You must fill in your bit.ly details on the settings page in order for this plugin to function.', 'vipers-video-quicktags' ), admin_url('options-general.php?page=twitter-tools-bitly-links') ) . "

\n"; + } + + + // Modify the URL being sent to Twitter by Twitter Tools + function modify_url( $url ) { + + // Make sure the user has filled in their login and API key + $login = urlencode( strtolower( trim( get_option('viper_ttbl_login') ) ) ); + $apikey = urlencode( trim( get_option('viper_ttbl_apikey') ) ); + if ( empty($login) || empty($apikey) ) + return $url; + + // Tell bit.ly to shorten the URL for us + $response = wp_remote_retrieve_body( wp_remote_get( "http://api.bit.ly/shorten?version=2.0.1&format=json&history=1&login={$login}&apiKey={$apikey}&longUrl=" . urlencode( $url ) ) ); + + if ( empty($response) ) + return $url; + + // Decode the response from bit.ly + if ( !$response = json_decode( $response, true ) ) + return $url; + + if ( !isset($response['errorCode']) || 0 != $response['errorCode'] || empty($response['results']) || empty($response['results'][$url]) || empty($response['results'][$url]['shortUrl']) ) + return $url; + + return $response['results'][$url]['shortUrl']; + } + + + // Settings page + function settings_page() { ?> + + + +
+ +

+ +
+ + + + + + + + + + + + + + + +
+ + account page.', 'twitter-tools-bitly-links' ), 'http://bit.ly/account/' ); ?> +
Checking...
+ +

+ +

+ +
+
+ +' . __('Failed to test credentials. Hmm.', 'twitter-tools-bitly-links') . '' ); + + // Decode the response from bit.ly + if ( !$response = json_decode( $response, true ) ) + exit( '' . __('Failed to parse bit.ly API response. Hmm.', 'twitter-tools-bitly-links') . '' ); + + if ( !isset($response['errorCode']) || 0 != $response['errorCode'] ) + exit( '' . __('Your credentials are invalid. Please double-check them.', 'twitter-tools-bitly-links') . '' ); + + exit( '' . __('Your credentials are valid.', 'twitter-tools-bitly-links') . '' ); + } +} + +// Start this plugin once all other plugins are fully loaded +add_action( 'init', 'TwitterToolsBitlyLinks' ); function TwitterToolsBitlyLinks() { global $TwitterToolsBitlyLinks; $TwitterToolsBitlyLinks = new TwitterToolsBitlyLinks(); } + +?> \ No newline at end of file