Rotating Tweets (Twitter widget and shortcode) - Version 1.7.17

Version Description

Download this release

Release Info

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

Code changes from version 1.7.16 to 1.7.17

Files changed (2) hide show
  1. readme.txt +5 -16
  2. rotatingtweets.php +50 -7
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,page builder
5
  Requires at least: 3.2
6
  Tested up to: 4.3
7
- Stable tag: 1.7.16
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -24,20 +24,6 @@ Twitter widget and shortcode to show your latest tweets one at a time an animate
24
  * Compatible with [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/).
25
  * **Multi-lingual** - now set up to be multi-lingual. The Twitter 'follow' button is automatically translated to match your site's language setting [if Twitter has made the appropriate language available](https://dev.twitter.com/docs/api/1.1/get/help/languages). Also uses [Wordpress's multi-lingual capability](http://codex.wordpress.org/I18n_for_WordPress_Developers) to enable translation of all the other text used by the plug-in via [language packs](https://translate.wordpress.org/projects/wp-plugins/rotatingtweets).
26
 
27
- Currently the following languages are available:
28
-
29
- * US English *(complete)*
30
- * British English *(complete - mainly changing 'favorite' to 'favourite'!)*
31
- * Brazilian Portuguese *(complete - many thanks to Wilmerson Felipe for his help on this)*
32
- * German *(almost complete - many thanks to Nils Kroneberg for his help on this)*
33
- * Spanish *(complete - many thanks to Alberto Lario for his help on this)*
34
- * Italian *(complete - many thanks to [Mattia Migliorini](https://profiles.wordpress.org/deshack/) at [deshack](http://deshack.net/) for his help on this)*
35
- * Dutch *(public facing translation complete - many thanks to Natasja Weijer for her help on this)*
36
- * French *(almost complete - many thanks to [Alexandre Trudel](http://wordpress.org/support/profile/alexandretrudel) for his help on this)*
37
- * Serbian *(complete - many thanks to Borisa Djuraskovic at [Web Hosting Hub](http://www.webhostinghub.com/) for his help on this)*
38
-
39
- If you have made the plug-in work in your language, please send the translations you'd like to see or, even better, the relevant [gettext PO and MO files](http://codex.wordpress.org/I18n_for_WordPress_Developers) to [me](http://www.martintod.org.uk/contact-martin/) and I will then share them with everyone else. You can download [the latest POT file](http://plugins.svn.wordpress.org/rotatingtweets/trunk/languages/rotatingtweets.pot), and [PO files in each language](http://plugins.svn.wordpress.org/rotatingtweets/trunk/languages/) from this site. You may find [Poedit](http://www.poedit.net/) rather useful for translation and creation of PO and MO files - although the PO files themselves are quite simple text files and can be edited in Notepad or [Notepad++](http://notepad-plus-plus.org/).
40
-
41
  If you'd like to see what the plug-in 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/).
42
 
43
  == Installation ==
@@ -188,9 +174,12 @@ You can do this by going to the `rotatingtweets/css` directory and renaming `rot
188
 
189
  == Upgrade notice ==
190
  = 1.7.16 =
191
- * Minor bug fixes - on caching and displaying error message in `WP_DEBUG` mode.
192
 
193
  == Changelog ==
 
 
 
194
  = 1.7.16 =
195
  * Fixed undefined variable error for `show_media` in `WP_DEBUG` mode
196
  * Fix for caching bug
4
  Tags: shortcode,widget,twitter,rotating,rotate,rotator,tweet,tweets,animation,jquery,jquery cycle,cycle,multilingual,responsive,page builder
5
  Requires at least: 3.2
6
  Tested up to: 4.3
7
+ Stable tag: 1.7.17
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
24
  * Compatible with [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/).
25
  * **Multi-lingual** - now set up to be multi-lingual. The Twitter 'follow' button is automatically translated to match your site's language setting [if Twitter has made the appropriate language available](https://dev.twitter.com/docs/api/1.1/get/help/languages). Also uses [Wordpress's multi-lingual capability](http://codex.wordpress.org/I18n_for_WordPress_Developers) to enable translation of all the other text used by the plug-in via [language packs](https://translate.wordpress.org/projects/wp-plugins/rotatingtweets).
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  If you'd like to see what the plug-in 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/).
28
 
29
  == Installation ==
174
 
175
  == Upgrade notice ==
176
  = 1.7.16 =
177
+ * Move to Wordpress-hosted translation packs.
178
 
179
  == Changelog ==
180
+ = 1.7.16 =
181
+ * Move to [Wordpress-hosted translation packs](https://translate.wordpress.org/projects/wp-plugins/rotatingtweets).
182
+
183
  = 1.7.16 =
184
  * Fixed undefined variable error for `show_media` in `WP_DEBUG` mode
185
  * Fix for caching bug
rotatingtweets.php CHANGED
@@ -2,7 +2,7 @@
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.7.16
6
  Text Domain: rotatingtweets
7
  Author: Martin Tod
8
  Author URI: http://www.martintod.org.uk
@@ -593,10 +593,10 @@ function rotatingtweets_display_shortcode( $atts, $content=null, $code="", $prin
593
  'shuffle'=>0,
594
  'merge_cache'=>TRUE,
595
  'rtw_display_order'=>'info,main,media,meta',
596
- 'collection_id' => 0
597
  ), $atts, 'rotatingtweets' ) ;
598
  extract($args);
599
- if(empty($screen_name) && empty($search) && !empty($url)):
600
  $screen_name = rotatingtweets_link_to_screenname($url);
601
  $args['screen_name'] = $screen_name;
602
  if(WP_DEBUG) {
@@ -612,7 +612,7 @@ function rotatingtweets_display_shortcode( $atts, $content=null, $code="", $prin
612
  rotatingtweets_enqueue_scripts();
613
  $returnstring = rotatingtweets_get_transient($args['text_cache_id']);
614
  if(strlen($returnstring)==0):
615
- $tweets = rotatingtweets_get_tweets($screen_name,$include_rts,$exclude_replies,$get_favorites,$search,$list,$args['merge_cache']);
616
  $returnstring = rotating_tweets_display($tweets,$args,$print);
617
  elseif(WP_DEBUG):
618
  $returnstring .= "<!-- Transient ".$args['text_cache_id']." loaded -->";
@@ -1014,13 +1014,16 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
1014
  $rt_namesarray = false;
1015
  foreach($possibledividers as $possibledivider):
1016
  if(strpos($tw_screen_name,$possibledivider) !== false ):
1017
- $rt_namesarray = explode(' ',$tw_screen_name);
1018
  $tw_search = 'from:'.implode(' OR from:',$rt_namesarray);
1019
  endif;
1020
  endforeach;
1021
  else:
1022
  $tw_search = trim($tw_search);
1023
  endif;
 
 
 
1024
  $cache_delay = rotatingtweets_get_cache_delay();
1025
  if($tw_include_rts != 1) $tw_include_rts = 0;
1026
  if($tw_exclude_replies != 1) $tw_exclude_replies = 0;
@@ -1028,6 +1031,8 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
1028
  # Get the option strong
1029
  if($tw_search) {
1030
  $stringname = 'search-'.$tw_include_rts.$tw_exclude_replies.'-'.$tw_search;
 
 
1031
  } elseif ($tw_get_favorites) {
1032
  $stringname = $tw_screen_name.$tw_include_rts.$tw_exclude_replies.'favorites';
1033
  } elseif ($tw_list) {
@@ -1076,10 +1081,14 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
1076
  # Checks if it is time to call Twitter directly yet or if it should use the cache
1077
  if($timegap > $cache_delay):
1078
  $apioptions = array('screen_name'=>$tw_screen_name,'include_entities'=>1,'count'=>40,'include_rts'=>$tw_include_rts,'exclude_replies'=>$tw_exclude_replies);
 
1079
  if($tw_search) {
1080
  $apioptions['q']=$tw_search;
1081
  // $apioptions['result_type']='recent';
1082
  $twitterdata = rotatingtweets_call_twitter_API('search/tweets',$apioptions);
 
 
 
1083
  } elseif($tw_get_favorites) {
1084
  $twitterdata = rotatingtweets_call_twitter_API('favorites/list',$apioptions);
1085
  } elseif($tw_list) {
@@ -1091,7 +1100,11 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
1091
  $twitterdata = rotatingtweets_call_twitter_API('statuses/user_timeline',$apioptions);
1092
  }
1093
  if(!is_wp_error($twitterdata)):
1094
- $twitterjson = json_decode($twitterdata['body'],TRUE);
 
 
 
 
1095
  if(WP_DEBUG):
1096
  $rt_time_taken = number_format(microtime(true)-$rt_starttime,4);
1097
  echo "<!-- Rotating Tweets - got new data - time taken: $rt_time_taken seconds -->";
@@ -1167,6 +1180,35 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
1167
  return;
1168
  endif;
1169
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1170
  function rotatingtweet_combine_jsons($a,$b) {
1171
  $tweet_keys = array();
1172
  foreach($a as $item) {
@@ -2081,7 +2123,8 @@ function rotating_tweets_display($json,$args,$print=FALSE) {
2081
  }
2082
  # Load the language files - needs to come after the widget_init line - and possibly the shortcode one too!
2083
  function rotatingtweets_init() {
2084
- load_plugin_textdomain( 'rotatingtweets', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
 
2085
  }
2086
  add_action('plugins_loaded', 'rotatingtweets_init');
2087
 
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.7.17
6
  Text Domain: rotatingtweets
7
  Author: Martin Tod
8
  Author URI: http://www.martintod.org.uk
593
  'shuffle'=>0,
594
  'merge_cache'=>TRUE,
595
  'rtw_display_order'=>'info,main,media,meta',
596
+ 'collection' => FALSE
597
  ), $atts, 'rotatingtweets' ) ;
598
  extract($args);
599
+ if(empty($screen_name) && empty($search) && !empty($url) && empty($collection)):
600
  $screen_name = rotatingtweets_link_to_screenname($url);
601
  $args['screen_name'] = $screen_name;
602
  if(WP_DEBUG) {
612
  rotatingtweets_enqueue_scripts();
613
  $returnstring = rotatingtweets_get_transient($args['text_cache_id']);
614
  if(strlen($returnstring)==0):
615
+ $tweets = rotatingtweets_get_tweets($screen_name,$include_rts,$exclude_replies,$get_favorites,$search,$list,$args['merge_cache'],$collection);
616
  $returnstring = rotating_tweets_display($tweets,$args,$print);
617
  elseif(WP_DEBUG):
618
  $returnstring .= "<!-- Transient ".$args['text_cache_id']." loaded -->";
1014
  $rt_namesarray = false;
1015
  foreach($possibledividers as $possibledivider):
1016
  if(strpos($tw_screen_name,$possibledivider) !== false ):
1017
+ $rt_namesarray = explode($possibledivider,$tw_screen_name);
1018
  $tw_search = 'from:'.implode(' OR from:',$rt_namesarray);
1019
  endif;
1020
  endforeach;
1021
  else:
1022
  $tw_search = trim($tw_search);
1023
  endif;
1024
+ if($tw_collection):
1025
+ $tw_collection = trim($tw_collection);
1026
+ endif;
1027
  $cache_delay = rotatingtweets_get_cache_delay();
1028
  if($tw_include_rts != 1) $tw_include_rts = 0;
1029
  if($tw_exclude_replies != 1) $tw_exclude_replies = 0;
1031
  # Get the option strong
1032
  if($tw_search) {
1033
  $stringname = 'search-'.$tw_include_rts.$tw_exclude_replies.'-'.$tw_search;
1034
+ } elseif($tw_collection) {
1035
+ $stringname = 'collection-'.$tw_collection;
1036
  } elseif ($tw_get_favorites) {
1037
  $stringname = $tw_screen_name.$tw_include_rts.$tw_exclude_replies.'favorites';
1038
  } elseif ($tw_list) {
1081
  # Checks if it is time to call Twitter directly yet or if it should use the cache
1082
  if($timegap > $cache_delay):
1083
  $apioptions = array('screen_name'=>$tw_screen_name,'include_entities'=>1,'count'=>40,'include_rts'=>$tw_include_rts,'exclude_replies'=>$tw_exclude_replies);
1084
+ $twitterusers = FALSE;
1085
  if($tw_search) {
1086
  $apioptions['q']=$tw_search;
1087
  // $apioptions['result_type']='recent';
1088
  $twitterdata = rotatingtweets_call_twitter_API('search/tweets',$apioptions);
1089
+ } elseif($tw_collection) {
1090
+ $twitterdata = rotatingtweets_call_twitter_API('collections/entries',$apioptions);
1091
+ $twitterusers = rotatingtweets_call_twitter_API('collections/show',$apioptions);
1092
  } elseif($tw_get_favorites) {
1093
  $twitterdata = rotatingtweets_call_twitter_API('favorites/list',$apioptions);
1094
  } elseif($tw_list) {
1100
  $twitterdata = rotatingtweets_call_twitter_API('statuses/user_timeline',$apioptions);
1101
  }
1102
  if(!is_wp_error($twitterdata)):
1103
+ if($twitterusers) {
1104
+ $twitterjson = rotatingtweets_transform_collection_data($twitterdata,$twitterusers);
1105
+ } else {
1106
+ $twitterjson = json_decode($twitterdata['body'],TRUE);
1107
+ }
1108
  if(WP_DEBUG):
1109
  $rt_time_taken = number_format(microtime(true)-$rt_starttime,4);
1110
  echo "<!-- Rotating Tweets - got new data - time taken: $rt_time_taken seconds -->";
1180
  return;
1181
  endif;
1182
  }
1183
+ /* Collections use a different format to the standard API. This is an attempt to convert from one to the other! */
1184
+ function rotatingtweets_transform_collection_data($twittertweets,$twitterusers) {
1185
+ $tweetobject = json_decode($twittertweets['body'],TRUE);
1186
+ if(isset($tweetobject['errors'])):
1187
+ return ($tweetobject);
1188
+ endif;
1189
+ if(WP_DEBUG):
1190
+ echo "<!--- Collection Tweets object ";
1191
+ print_r($tweetobject);
1192
+ endif;
1193
+ $userobject = json_decode($twitterusers['body'],TRUE);
1194
+ if(WP_DEBUG):
1195
+ echo "\n\n--- Collection Users object \n\n";
1196
+ print_r($userobject);
1197
+ endif;
1198
+ $pretweets = $tweets['objects']['tweets'];
1199
+ $posttweets = array();
1200
+ foreach($pretweets as $tweet):
1201
+ $tweet['user'] = $userobject['objects']['users'][$tweet['user']['id_str']] ;
1202
+ $posttweets[] = $tweet;
1203
+ endforeach;
1204
+ $return = array( 'results' => $posttweets );
1205
+ if(WP_DEBUG):
1206
+ echo "\n\n--- Combined object \n\n";
1207
+ print_r($return);
1208
+ echo "\n--->";
1209
+ endif;
1210
+ return $return;
1211
+ }
1212
  function rotatingtweet_combine_jsons($a,$b) {
1213
  $tweet_keys = array();
1214
  foreach($a as $item) {
2123
  }
2124
  # Load the language files - needs to come after the widget_init line - and possibly the shortcode one too!
2125
  function rotatingtweets_init() {
2126
+ // load_plugin_textdomain( 'rotatingtweets', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
2127
+ load_plugin_textdomain( 'rotatingtweets' );
2128
  }
2129
  add_action('plugins_loaded', 'rotatingtweets_init');
2130