Pownce for Wordpress by Cavemonkey50. Author: Ricardo González Author URI: http://rick.jinlabs.com/ */ /* Copyright 2007 Ricardo González Castro (rick[in]jinlabs.com) 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 */ define('MAGPIE_CACHE_ON', 1); //2.7 Cache Bug define('MAGPIE_CACHE_AGE', 180); define('MAGPIE_INPUT_ENCODING', 'UTF-8'); define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); $twitter_options['widget_fields']['title'] = array('label'=>'Title:', 'type'=>'text', 'default'=>''); $twitter_options['widget_fields']['username'] = array('label'=>'Username:', 'type'=>'text', 'default'=>''); $twitter_options['widget_fields']['num'] = array('label'=>'Number of links:', 'type'=>'text', 'default'=>'5'); $twitter_options['widget_fields']['update'] = array('label'=>'Show timestamps:', 'type'=>'checkbox', 'default'=>true); $twitter_options['widget_fields']['linked'] = array('label'=>'Linked:', 'type'=>'text', 'default'=>'#'); $twitter_options['widget_fields']['hyperlinks'] = array('label'=>'Discover Hyperlinks:', 'type'=>'checkbox', 'default'=>true); $twitter_options['widget_fields']['twitter_users'] = array('label'=>'Discover @replies:', 'type'=>'checkbox', 'default'=>true); $twitter_options['widget_fields']['encode_utf8'] = array('label'=>'UTF8 Encode:', 'type'=>'checkbox', 'default'=>false); $twitter_options['prefix'] = 'twitter'; // Display Twitter messages function twitter_messages($username = '', $num = 5, $list = false, $update = true, $linked = '#', $hyperlinks = true, $twitter_users = true, $encode_utf8 = false) { global $twitter_options; include_once(ABSPATH . WPINC . '/rss.php'); $messages = fetch_rss('http://twitter.com/statuses/user_timeline/'.$username.'.rss'); if ($list) echo ''; } // Link discover stuff function hyperlinks($text) { // Props to Allen Shaw & webmancers.com // match protocol://address/path/file.extension?some=variable&another=asf% //$text = preg_replace("/\b([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)\b/i","$1", $text); $text = preg_replace('/\b([a-zA-Z]+:\/\/[\w_.\-]+\.[a-zA-Z]{2,6}[\/\w\-~.?=&%#+$*!]*)\b/i',"$1", $text); // match www.something.domain/path/file.extension?some=variable&another=asf% //$text = preg_replace("/\b(www\.[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)\b/i","$1", $text); $text = preg_replace('/\b(?$1", $text); // match name@address $text = preg_replace("/\b([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})\b/i","$1", $text); //mach #trendingtopics. Props to Michael Voigt $text = preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)#{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1#$2$3 ", $text); return $text; } function twitter_users($text) { $text = preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)@{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1@$2$3 ", $text); return $text; } // Twitter widget stuff function widget_twitter_init() { if ( !function_exists('register_sidebar_widget') ) return; $check_options = get_option('widget_twitter'); if ($check_options['number']=='') { $check_options['number'] = 1; update_option('widget_twitter', $check_options); } function widget_twitter($args, $number = 1) { global $twitter_options; // $args is an array of strings that help widgets to conform to // the active theme: before_widget, before_title, after_widget, // and after_title are the array keys. Default tags: li and h2. extract($args); // Each widget can store its own options. We keep strings here. include_once(ABSPATH . WPINC . '/rss.php'); $options = get_option('widget_twitter'); // fill options with default values if value is not set $item = $options[$number]; foreach($twitter_options['widget_fields'] as $key => $field) { if (! isset($item[$key])) { $item[$key] = $field['default']; } } $messages = fetch_rss('http://twitter.com/statuses/user_timeline/'.$item['username'].'.rss'); // These lines generate our output. echo $before_widget . $before_title . ''. $item['title'] . '' . $after_title; twitter_messages($item['username'], $item['num'], true, $item['update'], $item['linked'], $item['hyperlinks'], $item['twitter_users'], $item['encode_utf8']); echo $after_widget; } // This is the function that outputs the form to let the users edit // the widget's title. It's an optional feature that users cry for. function widget_twitter_control($number) { global $twitter_options; // Get our options and see if we're handling a form submission. $options = get_option('widget_twitter'); if ( isset($_POST['twitter-submit']) ) { foreach($twitter_options['widget_fields'] as $key => $field) { $options[$number][$key] = $field['default']; $field_name = sprintf('%s_%s_%s', $twitter_options['prefix'], $key, $number); if ($field['type'] == 'text') { $options[$number][$key] = strip_tags(stripslashes($_POST[$field_name])); } elseif ($field['type'] == 'checkbox') { $options[$number][$key] = isset($_POST[$field_name]); } } update_option('widget_twitter', $options); } foreach($twitter_options['widget_fields'] as $key => $field) { $field_name = sprintf('%s_%s_%s', $twitter_options['prefix'], $key, $number); $field_checked = ''; if ($field['type'] == 'text') { $field_value = htmlspecialchars($options[$number][$key], ENT_QUOTES); } elseif ($field['type'] == 'checkbox') { $field_value = 1; if (! empty($options[$number][$key])) { $field_checked = 'checked="checked"'; } } printf('

', $field_name, __($field['label']), $field_name, $field_name, $field['type'], $field_value, $field['type'], $field_checked); } echo ''; } function widget_twitter_setup() { $options = $newoptions = get_option('widget_twitter'); if ( isset($_POST['twitter-number-submit']) ) { $number = (int) $_POST['twitter-number']; $newoptions['number'] = $number; } if ( $options != $newoptions ) { update_option('widget_twitter', $newoptions); widget_twitter_register(); } } function widget_twitter_page() { $options = $newoptions = get_option('widget_twitter'); ?>

300, 'height' => 300); $class = array('classname' => 'widget_twitter'); for ($i = 1; $i <= 9; $i++) { $name = sprintf(__('Twitter #%d'), $i); $id = "twitter-$i"; // Never never never translate an id wp_register_sidebar_widget($id, $name, $i <= $options['number'] ? 'widget_twitter' : /* unregister */ '', $class, $i); wp_register_widget_control($id, $name, $i <= $options['number'] ? 'widget_twitter_control' : /* unregister */ '', $dims, $i); } add_action('sidebar_admin_setup', 'widget_twitter_setup'); add_action('sidebar_admin_page', 'widget_twitter_page'); } widget_twitter_register(); } // Run our code later in case this loads prior to any required plugins. add_action('widgets_init', 'widget_twitter_init'); ?>