Rotating Tweets (Twitter widget and shortcode) - Version 0.471

Version Description

Includes fix for the major bug causing crashes when Twitter goes down. Also improved error checking if Twitter has returned an empty value or is rate-limited.

=

Download this release

Release Info

Developer mpntod
Plugin Icon wp plugin Rotating Tweets (Twitter widget and shortcode)
Version 0.471
Comparing to
See all releases

Code changes from version 0.46 to 0.471

Files changed (4) hide show
  1. readme.txt +20 -9
  2. rotatingtweets.php +13 -10
  3. screenshot-2.png +0 -0
  4. screenshot-3.png +0 -0
readme.txt CHANGED
@@ -1,14 +1,14 @@
1
  === Rotating Tweets widget and shortcode ===
2
  Contributors: mpntod
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XCNM4QSVHYT8
4
- Tags: shortcode,widget,twitter,rotating,rotate,rotator,tweet,tweets
5
  Requires at least: 2.6
6
  Tested up to: 3.4
7
- Stable tag: 0.46
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Replaces a shortcode such as [rotatingtweets screen_name='your_twitter_name'], or a widget, with a rotating tweets display
12
 
13
  == Description ==
14
  * Replaces a [shortcode](http://codex.wordpress.org/Shortcode) such as `[rotatingtweets screen_name='your_twitter_name']`, or a [widget](http://codex.wordpress.org/WordPress_Widgets), with a rotating display of your most recent tweets
@@ -21,10 +21,19 @@ Replaces a shortcode such as [rotatingtweets screen_name='your_twitter_name'], o
21
 
22
  If you'd like to see what it looks like in action, you can [see the plug-in working here](http://www.martintod.org.uk/2012/05/29/new-twitter-plugin-to-show-tweets-in-rotation/).
23
  == Installation ==
 
24
  1. Upload the contents of `rotatingtweets.zip` to the `/wp-content/plugins/` directory or use the Wordpress installer
25
  1. Activate the plugin through the 'Plugins' menu in WordPress
26
  1. Place a shortcode such `[rotatingtweets screen_name='mpntod']` in your post or page, or use a widget
27
 
 
 
 
 
 
 
 
 
28
  Possible variables for the shortcode include:
29
 
30
  * `screen_name` = Twitter user name - required
@@ -34,17 +43,19 @@ Possible variables for the shortcode include:
34
  * `show_follow` = `'0'` or `'1'` - show follow button - optional - default is `'0'`
35
  * `timeout` = time that each tweet is shown in milliseconds - optional - default is `'4000'` (i.e. 4 seconds)
36
 
37
- But you may just decide to use the 'Rotating Tweets' widget!
38
-
39
  == Frequently Asked Questions ==
40
  = How often does the plug-in call Twitter =
41
  In most cases, each use (or "instance") of this plug-in gets data from Twitter every 2 minutes. The exception is when two or more instances share the same settings (screen name etc.), in which case they share the same data rather than each calling it separately.
42
 
43
  == Upgrade notice ==
44
- = 0.46 =
45
  Includes fix for the major bug causing crashes when Twitter goes down. Also improved error checking if Twitter has returned an empty value or is rate-limited.
46
 
47
  == Changelog ==
 
 
 
 
48
  = 0.46 =
49
  Properly handles rate-limiting by Twitter
50
 
@@ -88,6 +99,6 @@ Fixed a problem with cacheing
88
  First published version
89
 
90
  == Screenshots ==
91
- 1. This animation is slightly faster than the default setting, but gives a sense of what you get:
92
- 2. You can add rotating tweets to a post like this:
93
- 3. Or add them via a widget:
1
  === Rotating Tweets widget and shortcode ===
2
  Contributors: mpntod
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XCNM4QSVHYT8
4
+ Tags: shortcode,widget,twitter,rotating,rotate,rotator,tweet,tweets,animation,jquery
5
  Requires at least: 2.6
6
  Tested up to: 3.4
7
+ Stable tag: 0.471
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Widget and/or shortcode to show your latest tweets one at a time an animated rotation
12
 
13
  == Description ==
14
  * Replaces a [shortcode](http://codex.wordpress.org/Shortcode) such as `[rotatingtweets screen_name='your_twitter_name']`, or a [widget](http://codex.wordpress.org/WordPress_Widgets), with a rotating display of your most recent tweets
21
 
22
  If you'd like to see what it looks like in action, you can [see the plug-in working here](http://www.martintod.org.uk/2012/05/29/new-twitter-plugin-to-show-tweets-in-rotation/).
23
  == Installation ==
24
+ = Installation =
25
  1. Upload the contents of `rotatingtweets.zip` to the `/wp-content/plugins/` directory or use the Wordpress installer
26
  1. Activate the plugin through the 'Plugins' menu in WordPress
27
  1. Place a shortcode such `[rotatingtweets screen_name='mpntod']` in your post or page, or use a widget
28
 
29
+ = Set-up =
30
+ Options include:
31
+
32
+ 1. Going to the Widgets menu on the admin page and adding the Rotating Tweets widget. Options include the name of the Twitter account to show, whether to show retweets and the speed of rotation.
33
+ 1. Using the basic Rotating Tweets shortcode, for example `[rotatingtweets screen_name='mpntod']`
34
+ 1. Using a more complicated Rotating Tweets shortcode, for example `[rotatingtweets screen_name='mpntod' include_rts='1' tweet_count='7' timeout='3000']`
35
+
36
+ = Variables =
37
  Possible variables for the shortcode include:
38
 
39
  * `screen_name` = Twitter user name - required
43
  * `show_follow` = `'0'` or `'1'` - show follow button - optional - default is `'0'`
44
  * `timeout` = time that each tweet is shown in milliseconds - optional - default is `'4000'` (i.e. 4 seconds)
45
 
 
 
46
  == Frequently Asked Questions ==
47
  = How often does the plug-in call Twitter =
48
  In most cases, each use (or "instance") of this plug-in gets data from Twitter every 2 minutes. The exception is when two or more instances share the same settings (screen name etc.), in which case they share the same data rather than each calling it separately.
49
 
50
  == Upgrade notice ==
51
+ = 0.471 =
52
  Includes fix for the major bug causing crashes when Twitter goes down. Also improved error checking if Twitter has returned an empty value or is rate-limited.
53
 
54
  == Changelog ==
55
+ = 0.471 =
56
+ Making sure that cache never gets overwritten unless new, valid twitter data has been downloaded.
57
+ Dealing with the problem that someone in a long conversation may not get enough valid tweets to show by asking for only 20 tweets from Twitter.
58
+
59
  = 0.46 =
60
  Properly handles rate-limiting by Twitter
61
 
99
  First published version
100
 
101
  == Screenshots ==
102
+ 1. This animation shows rotating tweets inserted into a blog-post via a short code. It is slightly faster than the default setting, but gives a sense of what you get.
103
+ 2. You can add rotating tweets via a Widget:
104
+ 3. Or by using a shortcode:
rotatingtweets.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Rotating Tweets widget & shortcode
4
  Description: Replaces a shortcode such as [rotatingtweets userid='your_twitter_name'], or a widget, with a rotating tweets display
5
- Version: 0.46
6
  Author: Martin Tod
7
  Author URI: http://www.martintod.org.uk
8
  License: GPL2
@@ -177,7 +177,6 @@ add_shortcode( 'rotatingtweets', 'rotatingtweets_display' );
177
  # Get the latest data from Twitter (or from a cache if it's been less than 2 minutes since the last load)
178
  function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_replies,$tw_tweet_count) {
179
  # Clear up variables
180
- # $check_regex = "%^[A-Za-z0-9_]+$%";
181
  $cache_delay = 120;
182
  if($tw_include_rts != 1) $tw_include_rts = 0;
183
  if($tw_exclude_replies != 1) $tw_exclude_replies = 0;
@@ -186,11 +185,11 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
186
  $stringname = $tw_screen_name.$tw_include_rts.$tw_exclude_replies;
187
  $optionname = "rotatingtweets-cache";
188
  $option = get_option($optionname);
189
- $latest_json = $option[$stringname][json];
190
- $latest_json_date = $option[$stringname][datetime];
191
  $timegap = time()-$latest_json_date;
192
  if($timegap > $cache_delay):
193
- $callstring = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=".urlencode($tw_screen_name)."&include_entities=1&count=20&include_rts=".$tw_include_rts."&exclude_replies=".$tw_exclude_replies;
194
  $twitterdata = wp_remote_request($callstring);
195
  if(!is_wp_error($twitterdata)):
196
  $twitterjson = json_decode($twitterdata['body']);
@@ -198,7 +197,7 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
198
  endif;
199
  if(!empty($twitterjson->errors)):
200
  # If there's an error, reset the cache timer to make sure we don't hit Twitter too hard and get rate limited.
201
- $option[$stringname][datetime]=time();
202
  update_option($optionname,$option);
203
  elseif(!empty($twitterjson->error)):
204
  # If Twitter is being rate limited, delays the next load until the reset time
@@ -210,10 +209,14 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
210
  endif;
211
  elseif(!empty($twitterjson)):
212
  # If there's regular data, then update the cache and return the data
213
- $latest_json = $twitterjson;
214
- $option[$stringname]['json']=$latest_json;
215
- $option[$stringname]['datetime']=time();
216
- update_option($optionname,$option);
 
 
 
 
217
  endif;
218
  return($latest_json);
219
  }
2
  /*
3
  Plugin Name: Rotating Tweets widget & shortcode
4
  Description: Replaces a shortcode such as [rotatingtweets userid='your_twitter_name'], or a widget, with a rotating tweets display
5
+ Version: 0.471
6
  Author: Martin Tod
7
  Author URI: http://www.martintod.org.uk
8
  License: GPL2
177
  # Get the latest data from Twitter (or from a cache if it's been less than 2 minutes since the last load)
178
  function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_replies,$tw_tweet_count) {
179
  # Clear up variables
 
180
  $cache_delay = 120;
181
  if($tw_include_rts != 1) $tw_include_rts = 0;
182
  if($tw_exclude_replies != 1) $tw_exclude_replies = 0;
185
  $stringname = $tw_screen_name.$tw_include_rts.$tw_exclude_replies;
186
  $optionname = "rotatingtweets-cache";
187
  $option = get_option($optionname);
188
+ $latest_json = $option[$stringname]['json'];
189
+ $latest_json_date = $option[$stringname]['datetime'];
190
  $timegap = time()-$latest_json_date;
191
  if($timegap > $cache_delay):
192
+ $callstring = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=".urlencode($tw_screen_name)."&include_entities=1&count=70&include_rts=".$tw_include_rts."&exclude_replies=".$tw_exclude_replies;
193
  $twitterdata = wp_remote_request($callstring);
194
  if(!is_wp_error($twitterdata)):
195
  $twitterjson = json_decode($twitterdata['body']);
197
  endif;
198
  if(!empty($twitterjson->errors)):
199
  # If there's an error, reset the cache timer to make sure we don't hit Twitter too hard and get rate limited.
200
+ $option[$stringname]['datetime']=time();
201
  update_option($optionname,$option);
202
  elseif(!empty($twitterjson->error)):
203
  # If Twitter is being rate limited, delays the next load until the reset time
209
  endif;
210
  elseif(!empty($twitterjson)):
211
  # If there's regular data, then update the cache and return the data
212
+ unset($firstentry);
213
+ if(is_array($twitterjson)) $firstentry = $twitterjson[0];
214
+ if(!empty($firstentry->text)):
215
+ $latest_json = $twitterjson;
216
+ $option[$stringname]['json']=$latest_json;
217
+ $option[$stringname]['datetime']=time();
218
+ update_option($optionname,$option);
219
+ endif;
220
  endif;
221
  return($latest_json);
222
  }
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file