Twitter Widget Pro - Version 1.3.1

Version Description

Download this release

Release Info

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

Code changes from version 1.3.0 to 1.3.1

Files changed (2) hide show
  1. readme.txt +2 -2
  2. wp-twitter-widget.php +63 -39
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: aaroncampbell
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%40xavisys%2ecom&item_name=Twitter%20Widget%20Pro&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8
4
  Tags: twitter, widget, feed
5
  Requires at least: 2.7
6
- Tested up to: 2.7.1
7
- Stable tag: 1.3.0
8
 
9
  A widget that properly handles twitter feeds, including parsing @username and URLs into links. Requires PHP5.
10
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%40xavisys%2ecom&item_name=Twitter%20Widget%20Pro&no_shipping=0&no_note=1&tax=0&currency_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8
4
  Tags: twitter, widget, feed
5
  Requires at least: 2.7
6
+ Tested up to: 2.8
7
+ Stable tag: 1.3.1
8
 
9
  A widget that properly handles twitter feeds, including parsing @username and URLs into links. Requires PHP5.
10
 
wp-twitter-widget.php CHANGED
@@ -3,15 +3,19 @@
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.3.0
7
  * Author: Aaron D. Campbell
8
  * Author URI: http://xavisys.com/
9
  */
10
 
11
- define('TWP_VERSION', '1.3.0');
12
 
13
  /**
14
  * Changelog:
 
 
 
 
15
  * 04/10/2009: 1.3.0
16
  * - Updated to use HTTP class and phased out Snoopy
17
  * - No longer relies on user having a caching solution in place. Caches for 5 minutes using blog options
@@ -151,7 +155,7 @@ class wpTwitterWidget
151
  $feedUrl = $this->_getFeedUrl($widgetOptions);
152
  $resp = wp_remote_request($feedUrl, array('timeout' => $widgetOptions['fetchTimeOut']));
153
 
154
- if ( $resp['response']['code'] >= 200 && $resp['response']['code'] < 300 ) {
155
  if (function_exists('json_decode')) {
156
  return json_decode($resp['body']);
157
  } else {
@@ -277,6 +281,7 @@ class wpTwitterWidget
277
 
278
  $options[$number]['hiderss'] = (isset($options[$number]['hiderss']) && $options[$number]['hiderss']);
279
  $options[$number]['avatar'] = (isset($options[$number]['avatar']) && $options[$number]['avatar']);
 
280
 
281
 
282
  try {
@@ -305,40 +310,51 @@ class wpTwitterWidget
305
  $options[$number]['title'] = "Twitter: {$options[$number]['username']}";
306
  }
307
  echo $before_title . $options[$number]['title'] . $after_title;
 
308
  if (is_a($tweets, 'wpTwitterWidgetException')) {
309
- echo '<ul><li class="wpTwitterWidgetError">' . $tweets->getMessage() . '</li></ul>';
310
  } else if (count($tweets) == 0) {
311
- echo '<ul><li class="wpTwitterWidgetEmpty">' . __('No Tweets Available') . '</li></ul>';
312
  } else {
 
 
 
 
 
 
 
 
 
313
  ?>
314
- <ul><?php
315
- if (!empty($tweets) && $options[$number]['avatar']) {
316
- echo '<li>';
317
- echo $this->_getProfileImage($tweets[0]->user);
318
- echo '<div class="clear" />';
319
- echo '</li>';
320
- }
321
- foreach ($tweets as $tweet) {
322
- // Set our "ago" string which converts the date to "# ___(s) ago"
323
- $tweet->ago = $this->_timeSince(strtotime($tweet->created_at), $options[$number]['showts']);
324
- ?>
325
- <li>
326
- <span class="entry-content"><?php echo apply_filters( 'widget_twitter_content', $tweet->text ); ?></span>
327
- <span class="entry-meta">
328
- <a href="http://twitter.com/<?php echo $tweet->user->screen_name; ?>/statuses/<?php echo $tweet->id; ?>">
329
- <?php echo $tweet->ago; ?>
330
- </a> from <?php
331
- echo str_replace('&', '&amp;', $tweet->source);
332
- if (isset($tweet->in_reply_to)) {
333
- echo $this->_getReplyTo($tweet->in_reply_to);
334
- } ?>
335
- </span>
336
- </li>
337
  <?php
338
- } ?></ul>
 
 
 
 
 
 
 
 
 
 
 
 
339
  <?php
340
  }
341
- echo '</div>' . $after_widget;
342
  }
343
 
344
  /**
@@ -398,10 +414,12 @@ profileImage;
398
  extract( $widget_args, EXTR_SKIP );
399
 
400
  $options = get_option('widget_twitter');
 
401
  if ( !is_array($options) )
402
  $options = array();
403
 
404
  if ( !$updated && !empty($_POST['sidebar']) ) {
 
405
  $sidebar = (string) $_POST['sidebar'];
406
 
407
  $sidebars_widgets = wp_get_sidebars_widgets();
@@ -442,6 +460,7 @@ profileImage;
442
  $options[$number]['username'] = attribute_escape($options[$number]['username']);
443
  $options[$number]['hiderss'] = (bool) $options[$number]['hiderss'];
444
  $options[$number]['avatar'] = (bool) $options[$number]['avatar'];
 
445
  }
446
  $this->_showForm($options[$number]);
447
  }
@@ -483,15 +502,17 @@ profileImage;
483
  */
484
  private function _showForm($args) {
485
 
486
- $defaultArgs = array( 'title' => '',
487
- 'errmsg' => '',
488
- 'fetchTimeOut' => '2',
489
- 'username' => '',
490
- 'hiderss' => false,
491
- 'avatar' => false,
492
- 'items' => 10,
493
- 'showts' => 60 * 60 * 24,
494
- 'number' => '%i%' );
 
 
495
  $args = wp_parse_args( $args, $defaultArgs );
496
  extract( $args );
497
  ?>
@@ -539,6 +560,9 @@ profileImage;
539
  <p>
540
  <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>
541
  </p>
 
 
 
542
  <?php
543
  }
544
 
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.3.1
7
  * Author: Aaron D. Campbell
8
  * Author URI: http://xavisys.com/
9
  */
10
 
11
+ define('TWP_VERSION', '1.3.1');
12
 
13
  /**
14
  * Changelog:
15
+ * 04/22/2009: 1.3.1
16
+ * - Added error handling after wp_remote_request call
17
+ * - Added link to Twitter Widget Pro page and option to turn it off per widget
18
+ *
19
  * 04/10/2009: 1.3.0
20
  * - Updated to use HTTP class and phased out Snoopy
21
  * - No longer relies on user having a caching solution in place. Caches for 5 minutes using blog options
155
  $feedUrl = $this->_getFeedUrl($widgetOptions);
156
  $resp = wp_remote_request($feedUrl, array('timeout' => $widgetOptions['fetchTimeOut']));
157
 
158
+ if ( !is_wp_error($resp) && $resp['response']['code'] >= 200 && $resp['response']['code'] < 300 ) {
159
  if (function_exists('json_decode')) {
160
  return json_decode($resp['body']);
161
  } else {
281
 
282
  $options[$number]['hiderss'] = (isset($options[$number]['hiderss']) && $options[$number]['hiderss']);
283
  $options[$number]['avatar'] = (isset($options[$number]['avatar']) && $options[$number]['avatar']);
284
+ $options[$number]['showXavisysLink'] = (!isset($options[$number]['showXavisysLink']) || $options[$number]['showXavisysLink']);
285
 
286
 
287
  try {
310
  $options[$number]['title'] = "Twitter: {$options[$number]['username']}";
311
  }
312
  echo $before_title . $options[$number]['title'] . $after_title;
313
+ echo '<ul>';
314
  if (is_a($tweets, 'wpTwitterWidgetException')) {
315
+ echo '<li class="wpTwitterWidgetError">' . $tweets->getMessage() . '</li>';
316
  } else if (count($tweets) == 0) {
317
+ echo '<li class="wpTwitterWidgetEmpty">' . __('No Tweets Available') . '</li>';
318
  } else {
319
+ if (!empty($tweets) && $options[$number]['avatar']) {
320
+ echo '<li>';
321
+ echo $this->_getProfileImage($tweets[0]->user);
322
+ echo '<div class="clear" />';
323
+ echo '</li>';
324
+ }
325
+ foreach ($tweets as $tweet) {
326
+ // Set our "ago" string which converts the date to "# ___(s) ago"
327
+ $tweet->ago = $this->_timeSince(strtotime($tweet->created_at), $options[$number]['showts']);
328
  ?>
329
+ <li>
330
+ <span class="entry-content"><?php echo apply_filters( 'widget_twitter_content', $tweet->text ); ?></span>
331
+ <span class="entry-meta">
332
+ <a href="http://twitter.com/<?php echo $tweet->user->screen_name; ?>/statuses/<?php echo $tweet->id; ?>">
333
+ <?php echo $tweet->ago; ?>
334
+ </a> from <?php
335
+ echo str_replace('&', '&amp;', $tweet->source);
336
+ if (isset($tweet->in_reply_to)) {
337
+ echo $this->_getReplyTo($tweet->in_reply_to);
338
+ } ?>
339
+ </span>
340
+ </li>
 
 
 
 
 
 
 
 
 
 
 
341
  <?php
342
+ }
343
+ }
344
+
345
+ if ($options[$number]['showXavisysLink']) {
346
+ ?>
347
+ <li class="xavisys-link">
348
+ <span class="xavisys-link-text">
349
+ Powered by
350
+ <a href="http://xavisys.com/2008/04/wordpress-twitter-widget/">
351
+ WordPress Twitter Widget Pro
352
+ </a>
353
+ </span>
354
+ </li>
355
  <?php
356
  }
357
+ echo '</ul></div>' . $after_widget;
358
  }
359
 
360
  /**
414
  extract( $widget_args, EXTR_SKIP );
415
 
416
  $options = get_option('widget_twitter');
417
+
418
  if ( !is_array($options) )
419
  $options = array();
420
 
421
  if ( !$updated && !empty($_POST['sidebar']) ) {
422
+ echo 'HERE!!!!!';
423
  $sidebar = (string) $_POST['sidebar'];
424
 
425
  $sidebars_widgets = wp_get_sidebars_widgets();
460
  $options[$number]['username'] = attribute_escape($options[$number]['username']);
461
  $options[$number]['hiderss'] = (bool) $options[$number]['hiderss'];
462
  $options[$number]['avatar'] = (bool) $options[$number]['avatar'];
463
+ $options[$number]['showXavisysLink'] = (!isset($options[$number]['showXavisysLink']) || $options[$number]['showXavisysLink']);
464
  }
465
  $this->_showForm($options[$number]);
466
  }
502
  */
503
  private function _showForm($args) {
504
 
505
+ $defaultArgs = array( 'title' => '',
506
+ 'errmsg' => '',
507
+ 'fetchTimeOut' => '2',
508
+ 'username' => '',
509
+ 'hiderss' => false,
510
+ 'avatar' => false,
511
+ 'showXavisysLink' => true,
512
+ 'items' => 10,
513
+ 'showts' => 60 * 60 * 24,
514
+ 'number' => '%i%' );
515
+
516
  $args = wp_parse_args( $args, $defaultArgs );
517
  extract( $args );
518
  ?>
560
  <p>
561
  <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>
562
  </p>
563
+ <p>
564
+ <label for="twitter-showXavisysLink-<?php echo $number; ?>"><input class="checkbox" type="checkbox" id="twitter-showXavisysLink-<?php echo $number; ?>" name="widget-twitter[<?php echo $number; ?>][showXavisysLink]"<?php checked($showXavisysLink, true); ?> /> <?php _e('Show Link to Twitter Widget Pro'); ?></label>
565
+ </p>
566
  <?php
567
  }
568