Rotating Tweets (Twitter widget and shortcode) - Version 1.3.18

Version Description

Improved and clearer error messages - plus fix for search problems. If your version of Rotating Tweets < 0.700, includes important upgrade needed for Rotating Tweets to keep working after March 2013.

=

Download this release

Release Info

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

Code changes from version 1.3.17 to 1.3.18

css/rotatingtweets-sample.css ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Rename this file to rotatingtweets.css and upload it to /wp-content/uploads/rotatingtweets.css and it will automatically be included in the rotatingtweets CSS by the plug in */
2
+ /* It shouldn't be overwritten when the plug-in is upgraded! */
3
+ /* This particular CSS makes a bird appear to the left of your tweets - you can find more birds at https://dev.twitter.com/docs/image-resources */
4
+ div.rotatingtweets_format_0 p.rtw_main {
5
+ background-image: url('../plugins/rotatingtweets/images/bird_blue_32.png');
6
+ background-repeat:no-repeat;
7
+ background-position:0 7px;
8
+ padding-left: 38px;
9
+ min-height: 36px;
10
+ }
11
+ div.rotatingtweets_format_0 p.rtw_meta {
12
+ padding-left: 38px;
13
+ }
css/style.css CHANGED
@@ -1,6 +1,10 @@
1
  /* First - sort out the fonts */
 
 
 
2
  div.rotatingtweet {
3
  font-size: 100%;
 
4
  }
5
  p.rtw_meta,div.rtw_meta,div.rtw_meta_wide,div.rtw_name,div.rtw_id,div.rtw_time_short,div.rtw_rt_meta {
6
  font-size: 0.8em;
1
  /* First - sort out the fonts */
2
+ .widget_rotatingtweets_widget {
3
+ width: 100%;
4
+ }
5
  div.rotatingtweet {
6
  font-size: 100%;
7
+ word-wrap: break-word;
8
  }
9
  p.rtw_meta,div.rtw_meta,div.rtw_meta_wide,div.rtw_name,div.rtw_id,div.rtw_time_short,div.rtw_rt_meta {
10
  font-size: 0.8em;
css/yourstyle-sample.css DELETED
@@ -1,9 +0,0 @@
1
- /* Rename this file to yourstyle.css and it will automatically be included in the rotatingtweets CSS by the plug in */
2
- /* It shouldn't be overwritten when the plug-in is upgraded! */
3
- /* This particular CSS makes a bird appear to the left of your tweets - you can find more birds at https://dev.twitter.com/docs/image-resources */
4
- div.rotatingtweet {
5
- background-image: url('../images/bird_blue_32.png');
6
- background-repeat:no-repeat;
7
- background-position:0 2px;
8
- padding-left: 38px;
9
- }
 
 
 
 
 
 
 
 
 
js/rotating_tweet.js CHANGED
@@ -16,10 +16,7 @@ jQuery(document).ready(function() {
16
  if(rotate_fx == null){rotate_fx = 'scrollUp'};
17
  var rt_height_px = 'auto';
18
  /* Now find the widget container width */
19
- var rt_target_width = jQuery(this).closest('.widget_rotatingtweets_widget').width();
20
- if( rt_target_width == null ) {
21
- var rt_target_width = jQuery(this).closest('.widget').width();
22
- }
23
  var rt_fit = 1;
24
  if( rt_target_width == null ) {
25
  rt_fit = 0;
@@ -38,6 +35,8 @@ jQuery(document).ready(function() {
38
  timeout: rotate_timeout,
39
  cleartypeNoBg: true,
40
  width: rt_target_width,
 
 
41
  fx: rotate_fx,
42
  fit: rt_fit
43
  });
@@ -69,6 +68,8 @@ jQuery(document).ready(function() {
69
  width: rt_target_width,
70
  cleartypeNoBg: true,
71
  fit: rt_fit,
 
 
72
  fx: rotate_fx
73
  });
74
  }
16
  if(rotate_fx == null){rotate_fx = 'scrollUp'};
17
  var rt_height_px = 'auto';
18
  /* Now find the widget container width */
19
+ var rt_target_width = jQuery(this).parent().width();
 
 
 
20
  var rt_fit = 1;
21
  if( rt_target_width == null ) {
22
  rt_fit = 0;
35
  timeout: rotate_timeout,
36
  cleartypeNoBg: true,
37
  width: rt_target_width,
38
+ prev: jQuery(rotate_id).find('.rtw_prev'),
39
+ next: jQuery(rotate_id).find('.rtw_next'),
40
  fx: rotate_fx,
41
  fit: rt_fit
42
  });
68
  width: rt_target_width,
69
  cleartypeNoBg: true,
70
  fit: rt_fit,
71
+ prev: jQuery(rotate_id).find('.rtw_prev'),
72
+ next: jQuery(rotate_id).find('.rtw_next'),
73
  fx: rotate_fx
74
  });
75
  }
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
5
  Requires at least: 2.6
6
  Tested up to: 3.5
7
- Stable tag: 1.3.17
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -74,8 +74,9 @@ Possible variables for the shortcode include:
74
  * `url_length` = sets the length that the URL should be trimmed to...
75
  * `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`
76
  * `search` = a term to search for
 
77
 
78
- although, unless you are using `search`, the only one you *have* to have is `screen_name`.
79
 
80
  == Credits ==
81
  Most of this is my own work, but special thanks are owed to:
@@ -91,7 +92,7 @@ Most of this is my own work, but special thanks are owed to:
91
  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.
92
 
93
  = How can I add a Twitter bird to the left of my tweets? =
94
- You can do this by going to the `rotatingtweets/css` directory and renaming `yourstyle-sample.css` to `yourstyle.css`. This displays a Twitter bird to the left of your tweets. Any CSS you put into `yourstyle.css` won't be overwritten when the plug-in is upgraded to the latest version.
95
 
96
  = The Rotating Tweets are not rotating. What can I do? =
97
  This normally happens if there is more than one copy of `jQuery` installed on a page - or more than one copy of `jQuery.cycle`.
@@ -118,10 +119,13 @@ If there is only one copy of `jquery` and of `jquery.cycle` on your page, the be
118
  1. Read the diagnostics and look for any problems that relate to JavaScript. This will normally tell you which JavaScript (if any) is having problems.
119
 
120
  == Upgrade notice ==
121
- = 1.3.17 =
122
- Includes an important upgrade needed for Rotating Tweets to keep working after March 2013. Fixed problem display in Chrome.
123
 
124
  == Changelog ==
 
 
 
125
  = 1.3.17 =
126
  Adds the opportunity to show lists. Tackles a very odd box height problem that has just appeared in Chrome (but not Firefox or IE).
127
 
4
  Tags: shortcode,widget,twitter,rotating,rotate,rotator,tweet,tweets,animation,jquery,jquery cycle,cycle,multilingual
5
  Requires at least: 2.6
6
  Tested up to: 3.5
7
+ Stable tag: 1.3.18
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
74
  * `url_length` = sets the length that the URL should be trimmed to...
75
  * `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`
76
  * `search` = a term to search for
77
+ * `list` = `'list-slug'` - the 'slug' used by someone's list (something like `my-list`)
78
 
79
+ although, except when using `search`, the only variable you *have* to have is `screen_name`.
80
 
81
  == Credits ==
82
  Most of this is my own work, but special thanks are owed to:
92
  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.
93
 
94
  = How can I add a Twitter bird to the left of my tweets? =
95
+ 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.
96
 
97
  = The Rotating Tweets are not rotating. What can I do? =
98
  This normally happens if there is more than one copy of `jQuery` installed on a page - or more than one copy of `jQuery.cycle`.
119
  1. Read the diagnostics and look for any problems that relate to JavaScript. This will normally tell you which JavaScript (if any) is having problems.
120
 
121
  == Upgrade notice ==
122
+ = 1.3.18 =
123
+ Improved and clearer error messages - plus fix for search problems. If your version of Rotating Tweets < 0.700, includes important upgrade needed for Rotating Tweets to keep working after March 2013.
124
 
125
  == Changelog ==
126
+ = 1.3.18 =
127
+ Improved and clearer error messages. Removed search bug. 'Next' and 'Prev' buttons.
128
+
129
  = 1.3.17 =
130
  Adds the opportunity to show lists. Tackles a very odd box height problem that has just appeared in Chrome (but not Firefox or IE).
131
 
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.3.17
6
  Text Domain: rotatingtweets
7
  Author: Martin Tod
8
  Author URI: http://www.martintod.org.uk
@@ -371,6 +371,7 @@ function rotatingtweets_display_shortcode( $atts, $content=null, $code="", $prin
371
  'show_meta_screen_name' => TRUE,
372
  'show_meta_via' => TRUE,
373
  'show_meta_reply_retweet_favorite' => FALSE,
 
374
  'rotation_type' => 'scrollUp',
375
  'official_format' => FALSE,
376
  'links_in_new_window' => FALSE,
@@ -381,7 +382,7 @@ function rotatingtweets_display_shortcode( $atts, $content=null, $code="", $prin
381
  'ratelimit' => FALSE
382
  ), $atts ) ;
383
  extract($args);
384
- if(empty($screen_name) && !empty($url)):
385
  $screen_name = rotatingtweets_link_to_screenname($url);
386
  $args['screen_name'] = $screen_name;
387
  if(WP_DEBUG) {
@@ -559,6 +560,7 @@ function rotatingtweets_call_twitter_API($command,$options = NULL,$api = NULL )
559
  if(!is_wp_error($result)):
560
  $data = json_decode($result['body'],true);
561
  if(!empty($data['errors'])):
 
562
  update_option('rotatingtweets_api_error',$data['errors']);
563
  else:
564
  delete_option('rotatingtweets_api_error');
@@ -567,6 +569,7 @@ function rotatingtweets_call_twitter_API($command,$options = NULL,$api = NULL )
567
  $errorstring = array();
568
  $errorstring[0]['code']= $result->get_error_code();
569
  $errorstring[0]['message']= $result->get_error_message();
 
570
  update_option('rotatingtweets_api_error',$errorstring);
571
  endif;
572
  return($result);
@@ -575,12 +578,12 @@ function rotatingtweets_call_twitter_API($command,$options = NULL,$api = NULL )
575
  # Get the latest data from Twitter (or from a cache if it's been less than 2 minutes since the last load)
576
  function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_replies,$tw_get_favorites = FALSE,$tw_search = FALSE,$tw_list = FALSE ) {
577
  # Clear up variables
578
- $tw_screen_name = urlencode(trim(remove_accents(str_replace('@','',$tw_screen_name))));
579
  if($tw_list):
580
- $tw_list = urlencode(strtolower(sanitize_file_name( $tw_list )));
581
  endif;
582
  if($tw_search) {
583
- $tw_search = urlencode(trim($tw_search));
584
  }
585
  $cache_delay = 120;
586
  if($tw_include_rts != 1) $tw_include_rts = 0;
@@ -588,7 +591,7 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
588
 
589
  # Get the option strong
590
  if($tw_search) {
591
- $stringname = 'search-'.$tw_include_rts.$tw_exclude_replies.$tw_search;
592
  } elseif ($tw_get_favorites) {
593
  $stringname = $tw_screen_name.$tw_include_rts.$tw_exclude_replies.'favorites';
594
  } elseif ($tw_list) {
@@ -602,7 +605,7 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
602
  $timegap = $cache_delay + 1;
603
  if(is_array($option)):
604
  if(WP_DEBUG):
605
- echo "<!-- var option is an array -->";
606
  endif;
607
  if(isset($option[$stringname]['json'][0])):
608
  if(WP_DEBUG) echo "<!-- option[$stringname] exists -->";
@@ -618,6 +621,8 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
618
  if(WP_DEBUG) echo "<!-- option[$stringname]['json'][0] is neither an object nor an array! -->";
619
  unset($option[$stringname]);
620
  endif;
 
 
621
  endif;
622
  else:
623
  unset($option);
@@ -667,9 +672,17 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
667
  # If there's regular data, then update the cache and return the data
668
  unset($firstentry);
669
  if(isset($twitterjson['statuses'])):
 
 
 
670
  $twitterjson = $twitterjson['statuses'];
 
 
 
 
 
671
  endif;
672
- if(is_array($twitterjson)) $firstentry = $twitterjson[0];
673
  if(!empty($firstentry['text'])):
674
  if(WP_DEBUG):
675
  echo "<!-- Storing cache entry for $stringname in $optionname -->";
@@ -695,7 +708,7 @@ function rotatingtweets_get_rate_data() {
695
  // $ratedata = wp_remote_request($callstring);
696
  if(!is_wp_error($ratedata)):
697
  $rate = json_decode($ratedata['body'],TRUE);
698
- if($rate['resources']['statuses']['/statuses/user_timeline']['limit']>0):
699
  $newrate['hourly_limit']=$rate['resources']['statuses']['/statuses/user_timeline']['limit'];
700
  $newrate['remaining_hits']=$rate['resources']['statuses']['/statuses/user_timeline']['remaining'];
701
  $newrate['reset_time_in_seconds']=$rate['resources']['statuses']['/statuses/user_timeline']['reset'];
@@ -806,35 +819,52 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
806
  # Create an ID that has all the relevant info in - rotation type and speed of rotation
807
  $id = uniqid('rotatingtweets_'.$timeout.'_'.$rotation_type.'_');
808
  if(WP_DEBUG):
809
- $result = "\n<div class='rotatingtweets wp_debug' id='$id'>";
810
  else:
811
- $result = "\n<div class='rotatingtweets' id='$id'>";
812
  endif;
813
  $error = get_option('rotatingtweets_api_error');
814
  if(!empty($error)):
815
- $result .= "\n<!-- Error: ".esc_attr($error[0]['code'])." - ".esc_attr($error[0]['message'])." -->";
816
  endif;
817
  if(empty($json)):
818
  $result .= "\n\t<div class = 'rotatingtweet'><p class='rtw_main'>". __('Problem retrieving data from Twitter','rotatingtweets'). "</p></div>";
819
  if(!empty($error)):
820
- $result .= "\n<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>".sprintf(__('Error code: %1$s - %2$s','rotatingtweets'), esc_attr($error[0]['code']), esc_attr($error[0]['message'])). "</p></div>";
821
- endif;
822
- $rate = rotatingtweets_get_rate_data();
823
- # Check if the problem is rate limiting
824
- if($rate['hourly_limit']>0 && $rate['remaining_hits'] == 0):
825
- $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". sprintf(__('This website is currently <a href=\'%s\'>rate-limited by Twitter</a>.','rotatingtweets'),'https://dev.twitter.com/docs/rate-limiting-faq') . "</p></div>";
826
- $waittimevalue = intval(($rate['reset_time_in_seconds'] - time())/60);
827
- $waittime = sprintf(_n('Next attempt to get data will be in %d minute','Next attempt to get data will be in %d minutes',$waittimevalue,'rotatingtweets'),$waittimevalue);
828
- if($waittimevalue == 0) $waittime = __("Next attempt to get data will be in less than a minute",'rotatingtweets');
829
- $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>{$waittime}.</p></div>";
830
- else:
831
- $error_messages = get_transient('rotatingtweets_wp_error');
832
- if($error_messages):
833
- foreach($error_messages as $error_message):
834
- $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". __('Wordpress error message','rotatingtweets').": ".$error_message['message'].".</p></div>";
835
- endforeach;
836
- endif;
837
- $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". sprintf(__('Please check the Twitter name in the widget or shortcode, <a href=\'%2$s\'>Rotating Tweets settings</a> or the <a href=\'%1$s\'>Twitter API status</a>.','rotatingtweets'),'https://dev.twitter.com/status',admin_url().'options-general.php?page=rotatingtweets')."</p></div>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
838
  endif;
839
  else:
840
  $tweet_counter = 0;
@@ -881,7 +911,9 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
881
  endif;
882
  if(!empty($rt_data)):
883
  $rt_user = $rt_data['user'];
884
- if($args['official_format']):
 
 
885
  $main_text = $rt_data['text'];
886
  $retweeter = $user;
887
  $tweetuser = $rt_user;
@@ -968,6 +1000,10 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
968
  if(!empty($meta)) $meta .= ' &middot; ';
969
  $meta .= rotatingtweets_intents($twitter_object,$twitterlocale, 0,$targetvalue);
970
  endif;
 
 
 
 
971
  if(!empty($meta)) $result .= "\n\t\t<p class='rtw_meta'>".ucfirst($meta)."</p>";
972
  break;
973
  case 1:
@@ -984,6 +1020,9 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
984
  if(isset($retweeter)) {
985
  $result .= " &middot; ".rotatingtweets_user_intent($retweeter,$twitterlocale,sprintf(__('Retweeted by %s','rotatingtweets'),$retweeter['name']),$targetvalue);
986
  }
 
 
 
987
  $result .= "\n</div>";
988
  break;
989
  case 2:
@@ -1000,8 +1039,11 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
1000
  if(isset($retweeter)) {
1001
  $result .= "\n\t\t<div class='rtw_rt_meta'>".rotatingtweets_user_intent($retweeter,$twitterlocale,"<img src='".plugins_url('images/retweet_on.png',__FILE__)."' width='16' height='16' alt='".sprintf(__('Retweeted by %s','rotatingtweets'),$retweeter['name'])."' />".sprintf(__('Retweeted by %s','rotatingtweets'),$retweeter['name']),$targetvalue)."</div>";
1002
  }
1003
- $result .= "\n\t\t<div class='rtw_meta'><span class='rtw_expand' style='display:none;'>".__('Expand','rotatingtweets')."</span><span class='rtw_intents'>".rotatingtweets_intents($twitter_object,$twitterlocale, 2,$targetvalue).'</span>';
1004
- $result .= "</div></div></div>";
 
 
 
1005
  break;
1006
  case 3:
1007
  # This one uses the twitter standard approach for embedding via their javascript API - unfortunately I can't work out how to make it work with the rotating tweet javascript! If anyone can work out how to calculate the height of a oEmbed Twitter tweet, I will be very grateful! :-)
@@ -1019,6 +1061,27 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
1019
  $result .= rotatingtweets_timestamp_link($twitter_object,'long',$targetvalue);
1020
  $result .= "\n</div>";
1021
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1022
  }
1023
  else:
1024
  $result .= "\n\t\t<p class='rtw_main'>".__("Problem retrieving data from Twitter.",'rotatingtweets')."</p></div>";
@@ -1073,10 +1136,21 @@ function rotatingtweets_enqueue_scripts() {
1073
  wp_enqueue_script( 'rotating_tweet', plugins_url('js/rotating_tweet.js', __FILE__),array('jquery','jquery-cycle'),FALSE,FALSE );
1074
  break;
1075
  endswitch;
1076
- wp_enqueue_style( 'rotating_tweet', plugins_url('css/style.css', __FILE__));
1077
- if(file_exists( plugin_dir_path(__FILE__).'css/yourstyle.css' )):
1078
- wp_enqueue_style( 'rotating_tweet_yourstyle', plugins_url('css/yourstyle.css', __FILE__));
1079
- endif;
 
 
 
 
 
 
 
 
 
 
 
1080
  }
1081
 
1082
  function rotatingtweets_enqueue_admin_scripts($hook) {
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.3.18
6
  Text Domain: rotatingtweets
7
  Author: Martin Tod
8
  Author URI: http://www.martintod.org.uk
371
  'show_meta_screen_name' => TRUE,
372
  'show_meta_via' => TRUE,
373
  'show_meta_reply_retweet_favorite' => FALSE,
374
+ 'show_meta_prev_next' => FALSE,
375
  'rotation_type' => 'scrollUp',
376
  'official_format' => FALSE,
377
  'links_in_new_window' => FALSE,
382
  'ratelimit' => FALSE
383
  ), $atts ) ;
384
  extract($args);
385
+ if(empty($screen_name) && empty($search) && !empty($url)):
386
  $screen_name = rotatingtweets_link_to_screenname($url);
387
  $args['screen_name'] = $screen_name;
388
  if(WP_DEBUG) {
560
  if(!is_wp_error($result)):
561
  $data = json_decode($result['body'],true);
562
  if(!empty($data['errors'])):
563
+ $data['errors'][0]['type'] = 'Twitter';
564
  update_option('rotatingtweets_api_error',$data['errors']);
565
  else:
566
  delete_option('rotatingtweets_api_error');
569
  $errorstring = array();
570
  $errorstring[0]['code']= $result->get_error_code();
571
  $errorstring[0]['message']= $result->get_error_message();
572
+ $errorstring[0]['type'] = 'Wordpress';
573
  update_option('rotatingtweets_api_error',$errorstring);
574
  endif;
575
  return($result);
578
  # Get the latest data from Twitter (or from a cache if it's been less than 2 minutes since the last load)
579
  function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_replies,$tw_get_favorites = FALSE,$tw_search = FALSE,$tw_list = FALSE ) {
580
  # Clear up variables
581
+ $tw_screen_name = trim(remove_accents(str_replace('@','',$tw_screen_name)));
582
  if($tw_list):
583
+ $tw_list = strtolower(sanitize_file_name( $tw_list ));
584
  endif;
585
  if($tw_search) {
586
+ $tw_search = trim($tw_search);
587
  }
588
  $cache_delay = 120;
589
  if($tw_include_rts != 1) $tw_include_rts = 0;
591
 
592
  # Get the option strong
593
  if($tw_search) {
594
+ $stringname = 'search-'.$tw_include_rts.$tw_exclude_replies.'-'.sanitize_file_name($tw_search);
595
  } elseif ($tw_get_favorites) {
596
  $stringname = $tw_screen_name.$tw_include_rts.$tw_exclude_replies.'favorites';
597
  } elseif ($tw_list) {
605
  $timegap = $cache_delay + 1;
606
  if(is_array($option)):
607
  if(WP_DEBUG):
608
+ echo "\n<!-- var option is an array -->";
609
  endif;
610
  if(isset($option[$stringname]['json'][0])):
611
  if(WP_DEBUG) echo "<!-- option[$stringname] exists -->";
621
  if(WP_DEBUG) echo "<!-- option[$stringname]['json'][0] is neither an object nor an array! -->";
622
  unset($option[$stringname]);
623
  endif;
624
+ elseif(WP_DEBUG):
625
+ echo "<!-- option[$stringname] does not exist -->";
626
  endif;
627
  else:
628
  unset($option);
672
  # If there's regular data, then update the cache and return the data
673
  unset($firstentry);
674
  if(isset($twitterjson['statuses'])):
675
+ if(WP_DEBUG):
676
+ echo "<!-- using [statuses] -->";
677
+ endif;
678
  $twitterjson = $twitterjson['statuses'];
679
+ elseif(isset($twitterjson['results'])):
680
+ if(WP_DEBUG):
681
+ echo "<!-- using [results] -->";
682
+ endif;
683
+ $twitterjson = $twitterjson['results'];
684
  endif;
685
+ if(is_array($twitterjson) && isset($twitterjson[0] )) $firstentry = $twitterjson[0];
686
  if(!empty($firstentry['text'])):
687
  if(WP_DEBUG):
688
  echo "<!-- Storing cache entry for $stringname in $optionname -->";
708
  // $ratedata = wp_remote_request($callstring);
709
  if(!is_wp_error($ratedata)):
710
  $rate = json_decode($ratedata['body'],TRUE);
711
+ if(isset($rate['resources']['statuses']['/statuses/user_timeline']['limit']) && $rate['resources']['statuses']['/statuses/user_timeline']['limit']>0):
712
  $newrate['hourly_limit']=$rate['resources']['statuses']['/statuses/user_timeline']['limit'];
713
  $newrate['remaining_hits']=$rate['resources']['statuses']['/statuses/user_timeline']['remaining'];
714
  $newrate['reset_time_in_seconds']=$rate['resources']['statuses']['/statuses/user_timeline']['reset'];
819
  # Create an ID that has all the relevant info in - rotation type and speed of rotation
820
  $id = uniqid('rotatingtweets_'.$timeout.'_'.$rotation_type.'_');
821
  if(WP_DEBUG):
822
+ $result = "\n<div class='rotatingtweets wp_debug rotatingtweets_format_".+intval($args['official_format'])."' id='$id'>";
823
  else:
824
+ $result = "\n<div class='rotatingtweets rotatingtweets_format_".+intval($args['official_format'])."' id='$id'>";
825
  endif;
826
  $error = get_option('rotatingtweets_api_error');
827
  if(!empty($error)):
828
+ $result .= "\n<!-- ".esc_html($error[0]['type'])." error: ".esc_html($error[0]['code'])." - ".esc_html($error[0]['message'])." -->";
829
  endif;
830
  if(empty($json)):
831
  $result .= "\n\t<div class = 'rotatingtweet'><p class='rtw_main'>". __('Problem retrieving data from Twitter','rotatingtweets'). "</p></div>";
832
  if(!empty($error)):
833
+ $result .= "\n<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>".sprintf(__('%3$s error code: %1$s - %2$s','rotatingtweets'), esc_html($error[0]['code']), esc_html($error[0]['message']),esc_html($error[0]['type'])). "</p></div>";
834
+ switch($error[0]['code']) {
835
+ case 88:
836
+ $rate = rotatingtweets_get_rate_data();
837
+ # Check if the problem is rate limiting
838
+ if(isset($rate['hourly_limit']) && $rate['hourly_limit']>0 && $rate['remaining_hits'] == 0):
839
+ $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". sprintf(__('This website is currently <a href=\'%s\'>rate-limited by Twitter</a>.','rotatingtweets'),'https://dev.twitter.com/docs/rate-limiting-faq') . "</p></div>";
840
+ $waittimevalue = intval(($rate['reset_time_in_seconds'] - time())/60);
841
+ $waittime = sprintf(_n('Next attempt to get data will be in %d minute','Next attempt to get data will be in %d minutes',$waittimevalue,'rotatingtweets'),$waittimevalue);
842
+ if($waittimevalue == 0) $waittime = __("Next attempt to get data will be in less than a minute",'rotatingtweets');
843
+ $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>{$waittime}.</p></div>";
844
+ endif;
845
+ break;
846
+ case 32:
847
+ $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". sprintf(__('Please check your <a href=\'%s\'>Rotating Tweets settings</a>.','rotatingtweets'),admin_url().'options-general.php?page=rotatingtweets')."</p></div>";
848
+ break;
849
+ case 34:
850
+ $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". __('Please check the Twitter screen name or list slug in the widget or shortcode.','rotatingtweets')."</p></div>";
851
+ break;
852
+ default:
853
+ switch($error[0]['type']) {
854
+ case 'Twitter':
855
+ $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". sprintf(__('Please check the Twitter name in the widget or shortcode, <a href=\'%2$s\'>Rotating Tweets settings</a> or the <a href=\'%1$s\'>Twitter API status</a>.','rotatingtweets'),'https://dev.twitter.com/status',admin_url().'options-general.php?page=rotatingtweets')."</p></div>";
856
+ break;
857
+ case 'Wordpress':
858
+ $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". sprintf(__('Please check your PHP and server settings.','rotatingtweets'),'https://dev.twitter.com/status',admin_url().'options-general.php?page=rotatingtweets')."</p></div>";
859
+ break;
860
+ default:
861
+ $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". sprintf(__('Please check the Twitter name in the widget or shortcode, <a href=\'%2$s\'>Rotating Tweets settings</a> or the <a href=\'%1$s\'>Twitter API status</a>.','rotatingtweets'),'https://dev.twitter.com/status',admin_url().'options-general.php?page=rotatingtweets')."</p></div>";
862
+ break;
863
+ }
864
+ break;
865
+ }
866
+ elseif(!empty($args['search'])):
867
+ $result .= "\n<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>".sprintf(__('No Tweet results for search <a href="%2$s"><strong>%1$s</strong></a>','rotatingtweets'),esc_html($args['search']),esc_url('https://twitter.com/search?q='.urlencode($args['search']))). "</p></div>";
868
  endif;
869
  else:
870
  $tweet_counter = 0;
911
  endif;
912
  if(!empty($rt_data)):
913
  $rt_user = $rt_data['user'];
914
+ // These versions remove RT and use the original text
915
+ $rt_replace_array = array(1,2,3);
916
+ if(in_array($args['official_format'],$rt_replace_array)):
917
  $main_text = $rt_data['text'];
918
  $retweeter = $user;
919
  $tweetuser = $rt_user;
1000
  if(!empty($meta)) $meta .= ' &middot; ';
1001
  $meta .= rotatingtweets_intents($twitter_object,$twitterlocale, 0,$targetvalue);
1002
  endif;
1003
+ if(isset($args['show_meta_prev_next']) && $args['show_meta_prev_next']):
1004
+ if(!empty($meta)) $meta .= ' &middot; ';
1005
+ $meta .= '<a href="#" class="rtw_prev">prev</a> &middot; <a href="#" class="rtw_next">next</a>';
1006
+ endif;
1007
  if(!empty($meta)) $result .= "\n\t\t<p class='rtw_meta'>".ucfirst($meta)."</p>";
1008
  break;
1009
  case 1:
1020
  if(isset($retweeter)) {
1021
  $result .= " &middot; ".rotatingtweets_user_intent($retweeter,$twitterlocale,sprintf(__('Retweeted by %s','rotatingtweets'),$retweeter['name']),$targetvalue);
1022
  }
1023
+ if(isset($args['show_meta_prev_next']) && $args['show_meta_prev_next']):
1024
+ $result .= ' &middot; <a href="#" class="rtw_prev">prev</a> &middot; <a href="#" class="rtw_next">next</a>';
1025
+ endif;
1026
  $result .= "\n</div>";
1027
  break;
1028
  case 2:
1039
  if(isset($retweeter)) {
1040
  $result .= "\n\t\t<div class='rtw_rt_meta'>".rotatingtweets_user_intent($retweeter,$twitterlocale,"<img src='".plugins_url('images/retweet_on.png',__FILE__)."' width='16' height='16' alt='".sprintf(__('Retweeted by %s','rotatingtweets'),$retweeter['name'])."' />".sprintf(__('Retweeted by %s','rotatingtweets'),$retweeter['name']),$targetvalue)."</div>";
1041
  }
1042
+ $result .= "\n\t\t<div class='rtw_meta'><span class='rtw_expand' style='display:none;'>".__('Expand','rotatingtweets')."</span><span class='rtw_intents'>".rotatingtweets_intents($twitter_object,$twitterlocale, 2,$targetvalue);
1043
+ if(isset($args['show_meta_prev_next']) && $args['show_meta_prev_next']):
1044
+ $result .= ' &middot; <a href="#" class="rtw_prev">prev</a> &middot; <a href="#" class="rtw_next">next</a>';
1045
+ endif;
1046
+ $result .= "</span></div></div></div>";
1047
  break;
1048
  case 3:
1049
  # This one uses the twitter standard approach for embedding via their javascript API - unfortunately I can't work out how to make it work with the rotating tweet javascript! If anyone can work out how to calculate the height of a oEmbed Twitter tweet, I will be very grateful! :-)
1061
  $result .= rotatingtweets_timestamp_link($twitter_object,'long',$targetvalue);
1062
  $result .= "\n</div>";
1063
  break;
1064
+ case 5:
1065
+ # This is an adjuster Rotating Tweets display routine
1066
+ $result .= "\n\t\t<p class='rtw_main'><img src='".plugins_url('images/bird_16_black.png', __FILE__)."' alt='Twitter' />&nbsp;&nbsp; $main_text ";
1067
+ $meta = '';
1068
+ if($args['show_meta_timestamp']):
1069
+ $meta .= rotatingtweets_timestamp_link($twitter_object,'default',$targetvalue);
1070
+ endif;
1071
+ if($args['show_meta_screen_name']):
1072
+ if(!empty($meta)) $meta .= ' ';
1073
+ $meta .= sprintf(__('from <a href=\'%1$s\' title=\'%2$s\'>%2$s\'s Twitter</a>','rotatingtweets'),'https://twitter.com/intent/user?user_id='.$user['id'],$user['name']);
1074
+ endif;
1075
+ if($args['show_meta_via']):
1076
+ if(!empty($meta)) $meta .= ' ';
1077
+ $meta .=sprintf(__("via %s",'rotatingtweets'),$twitter_object['source']);
1078
+ endif;
1079
+ if($args['show_meta_reply_retweet_favorite']):
1080
+ if(!empty($meta)) $meta .= ' &middot; ';
1081
+ $meta .= rotatingtweets_intents($twitter_object,$twitterlocale, 0,$targetvalue);
1082
+ endif;
1083
+ if(!empty($meta)) $result .= "\n\t\t<span class='rtw_meta'>".ucfirst($meta)."</span></p>";
1084
+ break;
1085
  }
1086
  else:
1087
  $result .= "\n\t\t<p class='rtw_main'>".__("Problem retrieving data from Twitter.",'rotatingtweets')."</p></div>";
1136
  wp_enqueue_script( 'rotating_tweet', plugins_url('js/rotating_tweet.js', __FILE__),array('jquery','jquery-cycle'),FALSE,FALSE );
1137
  break;
1138
  endswitch;
1139
+ wp_enqueue_style( 'rotatingtweets', plugins_url('css/style.css', __FILE__));
1140
+ $uploads = wp_upload_dir();
1141
+ $personalstyle = array(
1142
+ plugin_dir_path(__FILE__).'css/yourstyle.css' => plugins_url('css/yourstyle.css', __FILE__),
1143
+ $uploads['basedir'].'/rotatingtweets.css' => $uploads['baseurl'].'/rotatingtweets.css'
1144
+ );
1145
+ $scriptname = 'rotatingtweet-yourstyle';
1146
+ $scriptcounter = '';
1147
+ foreach($personalstyle as $dir => $url):
1148
+ if(file_exists( $dir )):
1149
+ wp_enqueue_style( $scriptname, $url);
1150
+ $scriptname = 'rotating-tweet-yourstyle-';
1151
+ $scriptcounter ++;
1152
+ endif;
1153
+ endforeach;
1154
  }
1155
 
1156
  function rotatingtweets_enqueue_admin_scripts($hook) {