Twitter Widget Pro - Version 1.2.0

Version Description

Download this release

Release Info

Developer aaroncampbell
Plugin Icon wp plugin Twitter Widget Pro
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.4 to 1.2.0

Files changed (2) hide show
  1. readme.txt +9 -6
  2. wp-twitter-widget.php +91 -28
readme.txt CHANGED
@@ -4,17 +4,16 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%4
4
  Tags: twitter, widget, feed
5
  Requires at least: 2.5
6
  Tested up to: 2.5.1
7
- Stable tag: 1.1.4
8
 
9
- A widget that properly handles twitter feeds (single user or including friends), including parsing @username and URLs into links. Requires PHP5.
10
 
11
  == Description ==
12
 
13
  A widget that properly handles twitter feeds, including @username and link
14
- parsing. Feeds can be for a single user, or can include all their friends'
15
- tweets as well (like their Twitter home page does). It supports displaying
16
- profiles images, and even lets you control whether to display the time and date
17
- of a tweet or how log ago it happened (about 5 hours ago, etc). Requires PHP5.
18
 
19
  == Installation ==
20
 
@@ -31,3 +30,7 @@ Yes, Twitter Widget Pro employs the multi-widget pattern, which allows you to no
31
  = Can I follow more than one feed? =
32
 
33
  Absolutely, each instance of the widget can have different settings and track different feeds.
 
 
 
 
4
  Tags: twitter, widget, feed
5
  Requires at least: 2.5
6
  Tested up to: 2.5.1
7
+ Stable tag: 1.2.0
8
 
9
+ A widget that properly handles twitter feeds, including parsing @username and URLs into links. Requires PHP5.
10
 
11
  == Description ==
12
 
13
  A widget that properly handles twitter feeds, including @username and link
14
+ parsing. It supports displaying profiles images, and even lets you control
15
+ whether to display the time and date of a tweet or how log ago it happened
16
+ (about 5 hours ago, etc). Requires PHP5.
 
17
 
18
  == Installation ==
19
 
30
  = Can I follow more than one feed? =
31
 
32
  Absolutely, each instance of the widget can have different settings and track different feeds.
33
+
34
+ = Why can't I display a friends feed anymore? =
35
+
36
+ Aparently the database queries required to display the friends feed was causing twitter to crash, so they removed it. Unfortunately, this is outside my control.
wp-twitter-widget.php CHANGED
@@ -2,14 +2,21 @@
2
  /**
3
  * Plugin Name: Twitter Widget Pro
4
  * Plugin URI: http://xavisys.com/wordpress-twitter-widget/
5
- * Description: A widget that properly handles twitter feeds, including @username and link parsing, feeds that include friends or just one user, and can even display profile images for the users. Requires PHP5.
6
- * Version: 1.1.4
7
  * Author: Aaron D. Campbell
8
  * Author URI: http://xavisys.com/
9
  */
10
 
 
 
11
  /**
12
  * Changelog:
 
 
 
 
 
13
  * 05/14/2008: 1.1.4
14
  * - Added an error if there was a problem connecting to Twitter.
15
  * - Added some text if there are no tweets.
@@ -122,7 +129,10 @@ class wpTwitterWidget
122
  }
123
  } else {
124
  // Failed to fetch url;
125
- throw new wpTwitterWidgetException(__('Could not connect to Twitter'));
 
 
 
126
  }
127
  }
128
 
@@ -143,7 +153,7 @@ class wpTwitterWidget
143
  } else {
144
  $count = '';
145
  }
146
- return sprintf('http://twitter.com/statuses/%1$s_timeline/%2$s.%3$s%4$s',$widgetOptions['feed'], $widgetOptions['username'], $type, $count);
147
  }
148
 
149
  /**
@@ -217,13 +227,13 @@ class wpTwitterWidget
217
  */
218
  private function _getTweets($widgetOptions) {
219
  // Get cache of feed if it exists
220
- $tweets = wp_cache_get($widgetOptions['feed'] . $widgetOptions['username'], 'widget_twitter');
221
  // If there is no cache
222
  if ($tweets == false) {
223
  try {
224
  $tweets = $this->_parseFeed($widgetOptions);
225
  // Cache for 60 seconds, Tweets are supposed to be current, so we don't cache for very long
226
- wp_cache_set($widgetOptions['feed'] . $widgetOptions['username'], $tweets, 'widget_twitter', 60);
227
  } catch (wpTwitterWidgetException $e) {
228
  throw $e;
229
  }
@@ -251,9 +261,6 @@ class wpTwitterWidget
251
  }
252
 
253
  // Validate our options
254
- if (!isset($options[$number]['feed']) || !in_array($options[$number]['feed'], array('user', 'friends'))) {
255
- $options[$number]['feed'] = 'user';
256
- }
257
  $options[$number]['items'] = (int) $options[$number]['items'];
258
  if ( $options[$number]['items'] < 1 || 20 < $options[$number]['items'] ) {
259
  $options[$number]['items'] = 10;
@@ -299,7 +306,7 @@ class wpTwitterWidget
299
  } else {
300
  ?>
301
  <ul><?php
302
- if ( $options[$number]['feed'] == 'user' && !empty($tweets) && $options[$number]['avatar']) {
303
  echo '<li>';
304
  echo $this->_getProfileImage($tweets[0]->user);
305
  echo '<div class="clear" />';
@@ -310,14 +317,6 @@ class wpTwitterWidget
310
  $tweet->ago = $this->_timeSince(strtotime($tweet->created_at), $options[$number]['showts']);
311
  ?>
312
  <li>
313
- <?php
314
- if ( $options[$number]['feed'] == 'friends' ) {
315
- if ( $options[$number]['avatar']) {
316
- echo $this->_getProfileImage($tweet->user);
317
- }
318
- echo $this->_getUserName($tweet->user);
319
- }
320
- ?>
321
  <span class="entry-content"><?php echo apply_filters( 'widget_twitter_content', $tweet->text ); ?></span>
322
  <span class="entry-meta">
323
  <a href="http://twitter.com/<?php echo $tweet->user->screen_name; ?>/statuses/<?php echo $tweet->id; ?>">
@@ -417,6 +416,7 @@ profileImage;
417
  if ( !isset($widget_twitter['username']) && isset($options[$widget_number]) ) // user clicked cancel
418
  continue;
419
  $widget_twitter['title'] = strip_tags(stripslashes($widget_twitter['title']));
 
420
  $options[$widget_number] = $widget_twitter;
421
  }
422
 
@@ -427,12 +427,10 @@ profileImage;
427
  if ( -1 != $number ) {
428
  $options[$number]['number'] = $number;
429
  $options[$number]['title'] = attribute_escape($options[$number]['title']);
 
430
  $options[$number]['username'] = attribute_escape($options[$number]['username']);
431
  $options[$number]['hiderss'] = (bool) $options[$number]['hiderss'];
432
  $options[$number]['avatar'] = (bool) $options[$number]['avatar'];
433
- if (!isset($options[$number]['feed']) || !in_array($options[$number]['feed'], array('user', 'friends'))) {
434
- $options[$number]['feed'] = 'user';
435
- }
436
  }
437
  $this->_showForm($options[$number]);
438
  }
@@ -475,10 +473,10 @@ profileImage;
475
  private function _showForm($args) {
476
 
477
  $defaultArgs = array( 'title' => '',
 
478
  'username' => '',
479
  'hiderss' => false,
480
  'avatar' => false,
481
- 'feed' => 'user',
482
  'items' => 10,
483
  'showts' => 60 * 60 * 24,
484
  'number' => '%i%' );
@@ -492,7 +490,6 @@ profileImage;
492
  <p>
493
  <label for="twitter-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
494
  <input class="widefat" id="twitter-title-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
495
- <input type="hidden" name="widget-twitter[<?php echo $number; ?>][submit]" value="1" />
496
  </p>
497
  <p>
498
  <label for="twitter-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
@@ -504,6 +501,10 @@ profileImage;
504
  ?>
505
  </select>
506
  </p>
 
 
 
 
507
  <p>
508
  <label for="twitter-showts-<?php echo $number; ?>"><?php _e('Show date/time of Tweet (rather than 2 ____ ago):'); ?></label>
509
  <select id="twitter-showts-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][showts]">
@@ -516,15 +517,11 @@ profileImage;
516
  <option value="-1" <?php echo selected($showts, '-1'); ?>>Never</a>
517
  </select>
518
  </p>
519
- <p>
520
- <label for="twitter-feed-<?php echo $number; ?>-user"><input class="checkbox" type="radio" id="twitter-feed-<?php echo $number; ?>-user" name="widget-twitter[<?php echo $number; ?>][feed]" value="user"<?php checked($feed, 'user'); ?> /> <?php _e('Just User'); ?></label><br />
521
- <label for="twitter-feed-<?php echo $number; ?>-friends"><input class="checkbox" type="radio" id="twitter-feed-<?php echo $number; ?>-friends" name="widget-twitter[<?php echo $number; ?>][feed]" value="friends"<?php checked($feed, 'friends'); ?> /> <?php _e('With Friends'); ?></label>
522
- </p>
523
  <p>
524
  <label for="twitter-hiderss-<?php echo $number; ?>"><input class="checkbox" type="checkbox" id="twitter-hiderss-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][hiderss]"<?php checked($hiderss, true); ?> /> <?php _e('Hide RSS Icon and Link'); ?></label>
525
  </p>
526
  <p>
527
- <label for="twitter-avatar-<?php echo $number; ?>"><input class="checkbox" type="checkbox" id="twitter-avatar-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][avatar]"<?php checked($avatar, true); ?> /> <?php _e('Show Profile Image(s)'); ?></label>
528
  </p>
529
  <?php
530
  }
@@ -574,6 +571,70 @@ profileImage;
574
 
575
  return "about {$print} ago";
576
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
  }
578
  // Instantiate our class
579
  $wpTwitterWidget = new wpTwitterWidget();
@@ -584,3 +645,5 @@ $wpTwitterWidget = new wpTwitterWidget();
584
  add_action('widgets_init', array($wpTwitterWidget, 'register'));
585
  add_filter('widget_twitter_content', array($wpTwitterWidget, 'linkTwitterUsers'));
586
  add_filter('widget_twitter_content', array($wpTwitterWidget, 'linkUrls'));
 
 
2
  /**
3
  * Plugin Name: Twitter Widget Pro
4
  * Plugin URI: http://xavisys.com/wordpress-twitter-widget/
5
+ * Description: A widget that properly handles twitter feeds, including @username and link parsing, and can even display profile images for the users. Requires PHP5.
6
+ * Version: 1.2.0
7
  * Author: Aaron D. Campbell
8
  * Author URI: http://xavisys.com/
9
  */
10
 
11
+ define('TWP_VERSION', '1.2.0');
12
+
13
  /**
14
  * Changelog:
15
+ * 06/09/2008: 1.2.0
16
+ * - Removed friends feed option, twitter removed this functionality
17
+ * - Added an option to set your own message to display when twitter is down
18
+ * - Added optional anonymous statistics collection
19
+ *
20
  * 05/14/2008: 1.1.4
21
  * - Added an error if there was a problem connecting to Twitter.
22
  * - Added some text if there are no tweets.
129
  }
130
  } else {
131
  // Failed to fetch url;
132
+ if (empty($widgetOptions['errmsg'])) {
133
+ $widgetOptions['errmsg'] = 'Could not connect to Twitter';
134
+ }
135
+ throw new wpTwitterWidgetException(__($widgetOptions['errmsg']));
136
  }
137
  }
138
 
153
  } else {
154
  $count = '';
155
  }
156
+ return sprintf('http://twitter.com/statuses/user_timeline/%1$s.%2$s%3$s', $widgetOptions['username'], $type, $count);
157
  }
158
 
159
  /**
227
  */
228
  private function _getTweets($widgetOptions) {
229
  // Get cache of feed if it exists
230
+ $tweets = wp_cache_get($widgetOptions['username'], 'widget_twitter');
231
  // If there is no cache
232
  if ($tweets == false) {
233
  try {
234
  $tweets = $this->_parseFeed($widgetOptions);
235
  // Cache for 60 seconds, Tweets are supposed to be current, so we don't cache for very long
236
+ wp_cache_set($widgetOptions['username'], $tweets, 'widget_twitter', 60);
237
  } catch (wpTwitterWidgetException $e) {
238
  throw $e;
239
  }
261
  }
262
 
263
  // Validate our options
 
 
 
264
  $options[$number]['items'] = (int) $options[$number]['items'];
265
  if ( $options[$number]['items'] < 1 || 20 < $options[$number]['items'] ) {
266
  $options[$number]['items'] = 10;
306
  } else {
307
  ?>
308
  <ul><?php
309
+ if (!empty($tweets) && $options[$number]['avatar']) {
310
  echo '<li>';
311
  echo $this->_getProfileImage($tweets[0]->user);
312
  echo '<div class="clear" />';
317
  $tweet->ago = $this->_timeSince(strtotime($tweet->created_at), $options[$number]['showts']);
318
  ?>
319
  <li>
 
 
 
 
 
 
 
 
320
  <span class="entry-content"><?php echo apply_filters( 'widget_twitter_content', $tweet->text ); ?></span>
321
  <span class="entry-meta">
322
  <a href="http://twitter.com/<?php echo $tweet->user->screen_name; ?>/statuses/<?php echo $tweet->id; ?>">
416
  if ( !isset($widget_twitter['username']) && isset($options[$widget_number]) ) // user clicked cancel
417
  continue;
418
  $widget_twitter['title'] = strip_tags(stripslashes($widget_twitter['title']));
419
+ $widget_twitter['errmsg'] = strip_tags(stripslashes($widget_twitter['errmsg']));
420
  $options[$widget_number] = $widget_twitter;
421
  }
422
 
427
  if ( -1 != $number ) {
428
  $options[$number]['number'] = $number;
429
  $options[$number]['title'] = attribute_escape($options[$number]['title']);
430
+ $options[$number]['errmsg'] = attribute_escape($options[$number]['errmsg']);
431
  $options[$number]['username'] = attribute_escape($options[$number]['username']);
432
  $options[$number]['hiderss'] = (bool) $options[$number]['hiderss'];
433
  $options[$number]['avatar'] = (bool) $options[$number]['avatar'];
 
 
 
434
  }
435
  $this->_showForm($options[$number]);
436
  }
473
  private function _showForm($args) {
474
 
475
  $defaultArgs = array( 'title' => '',
476
+ 'errmsg' => '',
477
  'username' => '',
478
  'hiderss' => false,
479
  'avatar' => false,
 
480
  'items' => 10,
481
  'showts' => 60 * 60 * 24,
482
  'number' => '%i%' );
490
  <p>
491
  <label for="twitter-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
492
  <input class="widefat" id="twitter-title-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
 
493
  </p>
494
  <p>
495
  <label for="twitter-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
501
  ?>
502
  </select>
503
  </p>
504
+ <p>
505
+ <label for="twitter-errmsg-<?php echo $number; ?>"><?php _e('What to display when Twitter is down (optional):'); ?></label>
506
+ <input class="widefat" id="twitter-errmsg-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][errmsg]" type="text" value="<?php echo $errmsg; ?>" />
507
+ </p>
508
  <p>
509
  <label for="twitter-showts-<?php echo $number; ?>"><?php _e('Show date/time of Tweet (rather than 2 ____ ago):'); ?></label>
510
  <select id="twitter-showts-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][showts]">
517
  <option value="-1" <?php echo selected($showts, '-1'); ?>>Never</a>
518
  </select>
519
  </p>
 
 
 
 
520
  <p>
521
  <label for="twitter-hiderss-<?php echo $number; ?>"><input class="checkbox" type="checkbox" id="twitter-hiderss-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][hiderss]"<?php checked($hiderss, true); ?> /> <?php _e('Hide RSS Icon and Link'); ?></label>
522
  </p>
523
  <p>
524
+ <label for="twitter-avatar-<?php echo $number; ?>"><input class="checkbox" type="checkbox" id="twitter-avatar-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][avatar]"<?php checked($avatar, true); ?> /> <?php _e('Show Profile Image'); ?></label>
525
  </p>
526
  <?php
527
  }
571
 
572
  return "about {$print} ago";
573
  }
574
+
575
+ function activatePlugin() {
576
+ // If the wga-id has not been generated, generate one and store it.
577
+ $o = get_option('twitter_widget_pro');
578
+ $id = $this->get_id();
579
+ if (!isset($o['user_agreed_to_send_system_information'])) {
580
+ $o['user_agreed_to_send_system_information'] = 'true';
581
+ update_option('twitter_widget_pro', $o);
582
+ }
583
+ }
584
+
585
+ function get_id() {
586
+ $o = get_option('twitter_widget_pro');
587
+ if (!isset($o['id'])) {
588
+ $o['id'] = sha1( get_bloginfo('url') . mt_rand() );
589
+ update_option('twitter_widget_pro', $o);
590
+ }
591
+ return $o['id'];
592
+ }
593
+ /**
594
+ * if user agrees to send system information and the last sent info is outdated outputs a bunch of stuff that sends sysinfo without interrupting
595
+ */
596
+ function outputSendInfoForm()
597
+ {
598
+ $o = get_option('wga');
599
+ if ($o['user_agreed_to_send_system_information'] == 'true') {
600
+ $lastSent = get_option('twp-sysinfo');
601
+ $sysinfo = $this->get_sysinfo();
602
+ //if (serialize($lastSent) != serialize($sysinfo)) {
603
+ ?>
604
+ <iframe id="hidden_frame" name="hidden_frame" style="width:0px; height:0px; border: 0px" src="about:blank"></iframe>
605
+ <form id="twp_send_info_form" target="hidden_frame" method="post" action="http://xavisys.com/plugin-info.php">
606
+ <?php
607
+ foreach($sysinfo as $k=>$v)
608
+ {
609
+ ?>
610
+ <input type="hidden" name="<?php echo attribute_escape($k); ?>" value="<?php echo attribute_escape($v);?>"></input>
611
+ <?php
612
+ }
613
+ ?>
614
+ </form>
615
+ <script type='text/javascript'>
616
+ jQuery('#twp_send_info_form').submit();
617
+ </script>
618
+ <?php
619
+ update_option('twp-sysinfo', $sysinfo);
620
+ //}
621
+ }
622
+ }
623
+ function get_sysinfo()
624
+ {
625
+ global $wpdb;
626
+ $s = array();
627
+ $s['plugin'] = 'Twitter Widget Pro';
628
+ $s['id'] = $this->get_id();
629
+ $s['version'] = TWP_VERSION;
630
+
631
+ $s['php_version'] = phpversion();
632
+ $s['mysql_version'] = @mysql_get_server_info($wpdb->dbh);
633
+ $s['server_software'] = $_SERVER["SERVER_SOFTWARE"];
634
+ $s['memory_limit'] = ini_get('memory_limit');
635
+
636
+ return $s;
637
+ }
638
  }
639
  // Instantiate our class
640
  $wpTwitterWidget = new wpTwitterWidget();
645
  add_action('widgets_init', array($wpTwitterWidget, 'register'));
646
  add_filter('widget_twitter_content', array($wpTwitterWidget, 'linkTwitterUsers'));
647
  add_filter('widget_twitter_content', array($wpTwitterWidget, 'linkUrls'));
648
+ add_action('activate_twitter-widget-pro/wp-twitter-widget.php', array($wpTwitterWidget, 'activatePlugin'));
649
+ add_action('admin_footer', array($wpTwitterWidget, 'outputSendInfoForm'));