diff -r 53cff4b4a802 -r bde1974c263b web/wp-content/plugins/twitter-tools/twitter-tools-bitly.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/twitter-tools/twitter-tools-bitly.php Wed Feb 03 15:37:20 2010 +0000 @@ -0,0 +1,193 @@ +agent = 'Twitter Tools http://alexking.org/projects/wordpress'; + $snoop->fetch($api); + $result = $json->decode($snoop->results); + $url = $result->results->{$url}->shortUrl; + } + return $url; +} +add_filter('tweet_blog_post_url', 'aktt_bitly_shorten_url'); + +function aktt_bitly_shorten_tweet($tweet) { + if (strpos($tweet->tw_text, 'http') !== false) { + preg_match_all('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $tweet->tw_text, $urls); + if (isset($urls[0]) && count($urls[0])) { + foreach ($urls[0] as $url) { +// borrowed from WordPress's make_clickable code + if ( in_array(substr($url, -1), array('.', ',', ';', ':', ')')) === true ) { + $url = substr($url, 0, strlen($url)-1); + } + $tweet->tw_text = str_replace($url, aktt_bitly_shorten_url($url), $tweet->tw_text); + } + } + } + return $tweet; +} +add_filter('aktt_do_tweet', 'aktt_bitly_shorten_tweet'); + +function aktt_bitly_request_handler() { + if (!empty($_GET['cf_action'])) { + switch ($_GET['cf_action']) { + + } + } + if (!empty($_POST['cf_action'])) { + switch ($_POST['cf_action']) { + + case 'aktt_bitly_update_settings': + aktt_bitly_save_settings(); + wp_redirect(trailingslashit(get_bloginfo('wpurl')).'wp-admin/options-general.php?page=twitter-tools.php&updated=true'); + die(); + break; + } + } +} +add_action('init', 'aktt_bitly_request_handler'); + +$aktt_bitly_settings = array( + 'aktt_bitly_api_login' => array( + 'type' => 'string', + 'label' => __('Bit.ly Username', 'twitter-tools-bitly'), + 'default' => '', + 'help' => '', + ), + 'aktt_bitly_api_key' => array( + 'type' => 'string', + 'label' => __('Bit.ly API key', 'twitter-tools-bitly'), + 'default' => '', + 'help' => '', + ), +); + +function aktt_bitly_setting($option) { + $value = get_option($option); + if (empty($value)) { + global $aktt_bitly_settings; + $value = $aktt_bitly_settings[$option]['default']; + } + return $value; +} + +if (!function_exists('cf_settings_field')) { + function cf_settings_field($key, $config) { + $option = get_option($key); + if (empty($option) && !empty($config['default'])) { + $option = $config['default']; + } + $label = ''; + $help = ''.$config['help'].''; + switch ($config['type']) { + case 'select': + $output = $label.''.$help; + break; + case 'textarea': + $output = $label.''.$help; + break; + case 'string': + case 'int': + default: + $output = $label.''.$help; + break; + } + return '