Rotating Tweets (Twitter widget and shortcode) - Version 1.6.8

Version Description

  • Shrinking cache size to reduce memory problems.

=

Download this release

Release Info

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

Code changes from version 1.6.7 to 1.6.8

Files changed (4) hide show
  1. lib/WP_OAuth.php +5 -1
  2. lib/wp_twitteroauth.php +3 -3
  3. readme.txt +10 -5
  4. rotatingtweets.php +26 -10
lib/WP_OAuth.php CHANGED
@@ -380,7 +380,11 @@ class WP_OAuthRequest {
380
  public function get_normalized_http_url() {
381
  $parts = parse_url($this->http_url);
382
 
383
- $port = @$parts['port'];
 
 
 
 
384
  $scheme = $parts['scheme'];
385
  $host = $parts['host'];
386
  $path = @$parts['path'];
380
  public function get_normalized_http_url() {
381
  $parts = parse_url($this->http_url);
382
 
383
+ if(isset($parts['port'])):
384
+ $port = @$parts['port'];
385
+ else:
386
+ $port = 0;
387
+ endif;
388
  $scheme = $parts['scheme'];
389
  $host = $parts['host'];
390
  $path = @$parts['path'];
lib/wp_twitteroauth.php CHANGED
@@ -201,7 +201,7 @@ if(!class_exists('rotatingtweets_TwitterOauth')):
201
  */
202
  function http($url, $method, $postfields = NULL) {
203
 
204
- if(WP_DEBUG && ! is_admin()) echo "<!-- wp_remote_request() variables in lib/wp_twitteroauth.php: \n\n\$url = ".esc_url($url)."\n";
205
  if(!empty($method)):
206
  $args['method']=$method;
207
  endif;
@@ -220,9 +220,9 @@ if(!class_exists('rotatingtweets_TwitterOauth')):
220
  endif;
221
  echo "\n-->\n";
222
  endif;
223
-
224
  $response = wp_remote_request($url,$args);
225
- if(WP_DEBUG && ! is_admin()) echo "<!-- wp_remote_request() in lib/wp_twitteroauth.php successfully completed -->\n";
226
  return($response);
227
 
228
  /*
201
  */
202
  function http($url, $method, $postfields = NULL) {
203
 
204
+ if(WP_DEBUG && ! is_admin()) echo "<!-- wp_remote_request() variables in lib/wp_twitteroauth.php: \n"; // $url = ".esc_url($url)."\n";
205
  if(!empty($method)):
206
  $args['method']=$method;
207
  endif;
220
  endif;
221
  echo "\n-->\n";
222
  endif;
223
+ $startwrrtime = microtime(true);
224
  $response = wp_remote_request($url,$args);
225
+ if(WP_DEBUG && ! is_admin()) echo "<!-- wp_remote_request() in lib/wp_twitteroauth.php successfully completed in ".number_format(microtime(true)-$startwrrtime,4)." seconds -->\n";
226
  return($response);
227
 
228
  /*
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: shortcode,widget,twitter,rotating,rotate,rotator,tweet,tweets,animation,jquery,jquery cycle,cycle,multilingual,responsive
5
  Requires at least: 2.6
6
  Tested up to: 3.8
7
- Stable tag: 1.6.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -62,7 +62,7 @@ Possible variables for the shortcode include:
62
  * **Required settings** - at least one of the following three settings is required for the short-code to function:
63
  * `screen_name` = Twitter user name
64
  * `url` = Twitter user URL. If `screen_name` is empty and this link is valid, `screen_name` will be set to the user name included in `url`
65
- * `search` = a term to search for
66
  * **Twitter options**
67
  * `include_rts` = `'0'` or `'1'` - include retweets - optional - default is `'0'`
68
  * `exclude_replies` = `'0'` or `'1'` - exclude replies - optional - default is `'0'`
@@ -109,7 +109,7 @@ Try something like:
109
  `<?php echo do_shortcode( "[rotatingtweets screen_name='your_twitter']" ) ?>`
110
 
111
  = How can I pull information from two accounts into one widget =
112
- The easiest way is to use a search term like `'from:account1 OR from:account2'`. There's a list of advanced Twitter search options at https://support.twitter.com/articles/71577-using-advanced-search
113
 
114
  = How often does the plug-in call Twitter =
115
  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.
@@ -163,10 +163,15 @@ into your CSS - changing `123px;` to the width you're aiming at - either via put
163
  You can do this by going to the `rotatingtweets/css` directory and renaming `rotatingtweets-sample.css` to `rotatingtweets.css` and putting it in the `wp-content/uploads/` directory. This displays a Twitter bird to the left of your tweets. Any CSS you put into `rotatingtweets.css` won't be overwritten when the plug-in is upgraded to the latest version.
164
 
165
  == Upgrade notice ==
166
- = 1.6.7 =
167
- * Fix next/prev buttons for v. 2 of Javascript. Add next/prev 'tweets' option to documentation. Fix bug on admin page when WP_DEBUG is set.
168
 
169
  == Changelog ==
 
 
 
 
 
170
  = 1.6.7 =
171
  * Fix next/prev buttons for v. 2 of Javascript.
172
  * Add next/prev `np_pos='tweets'` option to documentation.
4
  Tags: shortcode,widget,twitter,rotating,rotate,rotator,tweet,tweets,animation,jquery,jquery cycle,cycle,multilingual,responsive
5
  Requires at least: 2.6
6
  Tested up to: 3.8
7
+ Stable tag: 1.6.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
62
  * **Required settings** - at least one of the following three settings is required for the short-code to function:
63
  * `screen_name` = Twitter user name
64
  * `url` = Twitter user URL. If `screen_name` is empty and this link is valid, `screen_name` will be set to the user name included in `url`
65
+ * `search` = a term to search for. There's a useful guide to using Twitter's search function at https://support.twitter.com/articles/71577-using-advanced-search
66
  * **Twitter options**
67
  * `include_rts` = `'0'` or `'1'` - include retweets - optional - default is `'0'`
68
  * `exclude_replies` = `'0'` or `'1'` - exclude replies - optional - default is `'0'`
109
  `<?php echo do_shortcode( "[rotatingtweets screen_name='your_twitter']" ) ?>`
110
 
111
  = How can I pull information from two accounts into one widget =
112
+ The easiest way is to list more than one account in the 'Twitter name' box in the widget or use something like `screen_name = 'account1 account2'` in the shortcode.
113
 
114
  = How often does the plug-in call Twitter =
115
  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.
163
  You can do this by going to the `rotatingtweets/css` directory and renaming `rotatingtweets-sample.css` to `rotatingtweets.css` and putting it in the `wp-content/uploads/` directory. This displays a Twitter bird to the left of your tweets. Any CSS you put into `rotatingtweets.css` won't be overwritten when the plug-in is upgraded to the latest version.
164
 
165
  == Upgrade notice ==
166
+ = 1.6.8 =
167
+ * Shrinking cache size to reduce memory problems.
168
 
169
  == Changelog ==
170
+ = 1.6.8 =
171
+ * Shrinking cache size to reduce memory problems.
172
+ * Improved diagnostics.
173
+ * Clarified instructions.
174
+
175
  = 1.6.7 =
176
  * Fix next/prev buttons for v. 2 of Javascript.
177
  * Add next/prev `np_pos='tweets'` option to documentation.
rotatingtweets.php CHANGED
@@ -2,13 +2,13 @@
2
  /*
3
  Plugin Name: Rotating Tweets (Twitter widget & shortcode)
4
  Description: Replaces a shortcode such as [rotatingtweets screen_name='your_twitter_name'], or a widget, with a rotating tweets display
5
- Version: 1.6.7
6
  Text Domain: rotatingtweets
7
  Author: Martin Tod
8
  Author URI: http://www.martintod.org.uk
9
  License: GPL2
10
  */
11
- /* Copyright 2013 Martin Tod email : martin@martintod.org.uk)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License, version 2, as
@@ -49,7 +49,9 @@ class rotatingtweets_Widget extends WP_Widget {
49
  $title = apply_filters('widget_title', $instance['title']);
50
  $positive_variables = array('screen_name','shorten_links','include_rts','exclude_replies','links_in_new_window','tweet_count','show_follow','timeout','rotation_type','show_meta_reply_retweet_favorite','official_format','show_type','list_tag','search');
51
  foreach($positive_variables as $var) {
52
- $newargs[$var] = @$instance['tw_'.$var];
 
 
53
  }
54
  $negative_variables = array('meta_timestamp','meta_screen_name','meta_via');
55
  foreach($negative_variables as $var) {
@@ -80,7 +82,7 @@ class rotatingtweets_Widget extends WP_Widget {
80
  break;
81
  case 2:
82
  $tweets = rotatingtweets_get_tweets($newargs['screen_name'],$newargs['include_rts'],$newargs['exclude_replies'],false,$newargs['search']);
83
- $newargs['screen_name'] = '';
84
  break;
85
  case 3:
86
  $tweets = rotatingtweets_get_tweets($newargs['screen_name'],$newargs['include_rts'],$newargs['exclude_replies'],false,false,$newargs['list_tag']);
@@ -871,7 +873,7 @@ function rotatingtweets_shrink_cache() {
871
  $numberidentities = count($option);
872
  if(WP_DEBUG) echo "<!-- There are currently ".$numberidentities." identities cached -->";
873
  # If there are fewer than 10 sets of information cached - just return (for speed)
874
- if($numberidentities < 10) return;
875
  # Now make sure that we don't overwrite 'live' tweets
876
  $minageindays = 1000000;
877
  $totalcachesize = 0;
@@ -885,7 +887,12 @@ function rotatingtweets_shrink_cache() {
885
  $totalcachesize = $totalcachesize + $cachesize;
886
  endif;
887
  };
 
 
 
 
888
  if(WP_DEBUG) echo "\n<!-- The youngest age of any cache is ".number_format($minageindays*24*60,2)." minutes (".number_format($minageindays,8)." days) and total cache size is ".$totalcachesize.". -->";
 
889
  # Set the goal of deleting all the tweets more than 30 days older than the most recent tweets
890
  $targetageindays = $minageindays + 30;
891
  # Now run through and delete
@@ -900,6 +907,8 @@ function rotatingtweets_shrink_cache() {
900
 
901
  # Get the latest data from Twitter (or from a cache if it's been less than 2 minutes since the last load)
902
  function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_replies,$tw_get_favorites = FALSE,$tw_search = FALSE,$tw_list = FALSE ) {
 
 
903
  # Check cache
904
  rotatingtweets_shrink_cache();
905
  # Clear up variables
@@ -949,10 +958,12 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
949
  if(isset($option[$stringname]['json'][0])):
950
  if(WP_DEBUG) echo "<!-- option[$stringname] exists -->";
951
  if(is_array($option[$stringname]['json'][0])):
952
- if(WP_DEBUG) echo "<!-- option[$stringname]['json'][0] is an array -->";
953
  $latest_json = $option[$stringname]['json'];
954
  $latest_json_date = $option[$stringname]['datetime'];
955
  $timegap = time()-$latest_json_date;
 
 
 
956
  elseif(is_object($option[$stringname]['json'][0])):
957
  if(WP_DEBUG) echo "<!-- option[$stringname]['json'][0] is an object -->";
958
  unset($option[$stringname]);
@@ -964,13 +975,17 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
964
  echo "<!-- option[$stringname] does not exist -->";
965
  endif;
966
  else:
 
 
 
967
  unset($option);
968
  endif;
969
  # Checks if it is time to call Twitter directly yet or if it should use the cache
970
  if($timegap > $cache_delay):
971
- $apioptions = array('screen_name'=>$tw_screen_name,'include_entities'=>1,'count'=>70,'include_rts'=>$tw_include_rts,'exclude_replies'=>$tw_exclude_replies);
972
  if($tw_search) {
973
  $apioptions['q']=$tw_search;
 
974
  $twitterdata = rotatingtweets_call_twitter_API('search/tweets',$apioptions);
975
  } elseif($tw_get_favorites) {
976
  $twitterdata = rotatingtweets_call_twitter_API('favorites/list',$apioptions);
@@ -985,13 +1000,15 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
985
  if(!is_wp_error($twitterdata)):
986
  $twitterjson = json_decode($twitterdata['body'],TRUE);
987
  if(WP_DEBUG):
988
- echo "<!-- Rotating Tweets - got new data -->";
 
989
  endif;
990
  else:
991
  set_transient('rotatingtweets_wp_error',$twitterdata->get_error_messages(), 120);
992
  endif;
993
  elseif(WP_DEBUG):
994
- echo "<!-- Rotating Tweets - used cache - ".($cache_delay - $timegap)." seconds remaining -->";
 
995
  endif;
996
  # Checks for errors in the reply
997
  if(!empty($twitterjson['errors'])):
@@ -1019,7 +1036,6 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
1019
  update_option($optionname,$option);
1020
  endif;
1021
  elseif(!empty($twitterjson)):
1022
- # If there's regular data, then update the cache and return the data
1023
  unset($firstentry);
1024
  if(isset($twitterjson['statuses'])):
1025
  if(WP_DEBUG):
2
  /*
3
  Plugin Name: Rotating Tweets (Twitter widget & shortcode)
4
  Description: Replaces a shortcode such as [rotatingtweets screen_name='your_twitter_name'], or a widget, with a rotating tweets display
5
+ Version: 1.6.8
6
  Text Domain: rotatingtweets
7
  Author: Martin Tod
8
  Author URI: http://www.martintod.org.uk
9
  License: GPL2
10
  */
11
+ /* Copyright 2014 Martin Tod email : martin@martintod.org.uk)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License, version 2, as
49
  $title = apply_filters('widget_title', $instance['title']);
50
  $positive_variables = array('screen_name','shorten_links','include_rts','exclude_replies','links_in_new_window','tweet_count','show_follow','timeout','rotation_type','show_meta_reply_retweet_favorite','official_format','show_type','list_tag','search');
51
  foreach($positive_variables as $var) {
52
+ if(isset($instance['tw_'.$var])):
53
+ $newargs[$var] = $instance['tw_'.$var];
54
+ endif;
55
  }
56
  $negative_variables = array('meta_timestamp','meta_screen_name','meta_via');
57
  foreach($negative_variables as $var) {
82
  break;
83
  case 2:
84
  $tweets = rotatingtweets_get_tweets($newargs['screen_name'],$newargs['include_rts'],$newargs['exclude_replies'],false,$newargs['search']);
85
+ // $newargs['screen_name'] = ''; // Originally put in to avoid confusion when people have a 'follow' button and a search tweet
86
  break;
87
  case 3:
88
  $tweets = rotatingtweets_get_tweets($newargs['screen_name'],$newargs['include_rts'],$newargs['exclude_replies'],false,false,$newargs['list_tag']);
873
  $numberidentities = count($option);
874
  if(WP_DEBUG) echo "<!-- There are currently ".$numberidentities." identities cached -->";
875
  # If there are fewer than 10 sets of information cached - just return (for speed)
876
+ // if($numberidentities < 10) return;
877
  # Now make sure that we don't overwrite 'live' tweets
878
  $minageindays = 1000000;
879
  $totalcachesize = 0;
887
  $totalcachesize = $totalcachesize + $cachesize;
888
  endif;
889
  };
890
+ if($totalcachesize == 0):
891
+ if(WP_DEBUG) echo "<!-- Cache failed to read successfully -->";
892
+ return;
893
+ endif;
894
  if(WP_DEBUG) echo "\n<!-- The youngest age of any cache is ".number_format($minageindays*24*60,2)." minutes (".number_format($minageindays,8)." days) and total cache size is ".$totalcachesize.". -->";
895
+ if($numberidentities < 10) return;
896
  # Set the goal of deleting all the tweets more than 30 days older than the most recent tweets
897
  $targetageindays = $minageindays + 30;
898
  # Now run through and delete
907
 
908
  # Get the latest data from Twitter (or from a cache if it's been less than 2 minutes since the last load)
909
  function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_replies,$tw_get_favorites = FALSE,$tw_search = FALSE,$tw_list = FALSE ) {
910
+ # Set timer
911
+ $rt_starttime = microtime(true);
912
  # Check cache
913
  rotatingtweets_shrink_cache();
914
  # Clear up variables
958
  if(isset($option[$stringname]['json'][0])):
959
  if(WP_DEBUG) echo "<!-- option[$stringname] exists -->";
960
  if(is_array($option[$stringname]['json'][0])):
 
961
  $latest_json = $option[$stringname]['json'];
962
  $latest_json_date = $option[$stringname]['datetime'];
963
  $timegap = time()-$latest_json_date;
964
+ if(WP_DEBUG):
965
+ echo "<!-- option[$stringname]['json'][0] is an array - $timegap seconds since last load -->";
966
+ endif;
967
  elseif(is_object($option[$stringname]['json'][0])):
968
  if(WP_DEBUG) echo "<!-- option[$stringname]['json'][0] is an object -->";
969
  unset($option[$stringname]);
975
  echo "<!-- option[$stringname] does not exist -->";
976
  endif;
977
  else:
978
+ if(WP_DEBUG):
979
+ echo "\n<!-- var option is NOT an array -->";
980
+ endif;
981
  unset($option);
982
  endif;
983
  # Checks if it is time to call Twitter directly yet or if it should use the cache
984
  if($timegap > $cache_delay):
985
+ $apioptions = array('screen_name'=>$tw_screen_name,'include_entities'=>1,'count'=>40,'include_rts'=>$tw_include_rts,'exclude_replies'=>$tw_exclude_replies);
986
  if($tw_search) {
987
  $apioptions['q']=$tw_search;
988
+ // $apioptions['result_type']='recent';
989
  $twitterdata = rotatingtweets_call_twitter_API('search/tweets',$apioptions);
990
  } elseif($tw_get_favorites) {
991
  $twitterdata = rotatingtweets_call_twitter_API('favorites/list',$apioptions);
1000
  if(!is_wp_error($twitterdata)):
1001
  $twitterjson = json_decode($twitterdata['body'],TRUE);
1002
  if(WP_DEBUG):
1003
+ $rt_time_taken = number_format(microtime(true)-$rt_starttime,4);
1004
+ echo "<!-- Rotating Tweets - got new data - time taken: $rt_time_taken seconds -->";
1005
  endif;
1006
  else:
1007
  set_transient('rotatingtweets_wp_error',$twitterdata->get_error_messages(), 120);
1008
  endif;
1009
  elseif(WP_DEBUG):
1010
+ $rt_time_taken = number_format(microtime(true)-$rt_starttime,4);
1011
+ echo "<!-- Rotating Tweets - used cache - ".($cache_delay - $timegap)." seconds remaining - time taken: $rt_time_taken seconds -->";
1012
  endif;
1013
  # Checks for errors in the reply
1014
  if(!empty($twitterjson['errors'])):
1036
  update_option($optionname,$option);
1037
  endif;
1038
  elseif(!empty($twitterjson)):
 
1039
  unset($firstentry);
1040
  if(isset($twitterjson['statuses'])):
1041
  if(WP_DEBUG):