Rotating Tweets (Twitter widget and shortcode) - Version 0.711

Version Description

Includes an important upgrade needed for Rotating Tweets to keep working after March 2013. Supports version 1.1 of the Twitter API. Fixed problem with cacheing.

=

Download this release

Release Info

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

Code changes from version 0.709 to 0.711

Files changed (2) hide show
  1. readme.txt +6 -3
  2. rotatingtweets.php +49 -20
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: 0.709
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -82,10 +82,13 @@ In most cases, each use (or "instance") of this plug-in gets data from Twitter e
82
  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.
83
 
84
  == Upgrade notice ==
85
- = 0.709 =
86
- Includes an important upgrade needed for Rotating Tweets to keep working after March 2013. Supports version 1.1 of the Twitter API.
87
 
88
  == Changelog ==
 
 
 
89
  = 0.709 =
90
  Tidying up error reporting.
91
 
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: 0.711
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
82
  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.
83
 
84
  == Upgrade notice ==
85
+ = 0.711 =
86
+ Includes an important upgrade needed for Rotating Tweets to keep working after March 2013. Supports version 1.1 of the Twitter API. Fixed problem with cacheing.
87
 
88
  == Changelog ==
89
+ = 0.711 =
90
+ Fixed up a significant problem with cacheing.
91
+
92
  = 0.709 =
93
  Tidying up error reporting.
94
 
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: 0.709
6
  Text Domain: rotatingtweets
7
  Author: Martin Tod
8
  Author URI: http://www.martintod.org.uk
@@ -335,6 +335,15 @@ function rotatingtweets_timestamp_link($twitter_object,$timetype = 'default',$ta
335
  function rotatingtweets_display($atts) {
336
  rotatingtweets_display_shortcode($atts,null,'',TRUE);
337
  };
 
 
 
 
 
 
 
 
 
338
  # Processes the shortcode
339
  function rotatingtweets_display_shortcode( $atts, $content=null, $code="", $print=FALSE ) {
340
  // $atts ::= twitter_id,include_rts,exclude_replies, $tweet_count,$show_follow
@@ -349,7 +358,8 @@ function rotatingtweets_display_shortcode( $atts, $content=null, $code="", $prin
349
  $no_show_screen_name :: [boolean] remove screen name from follow button
350
  */
351
  $args = shortcode_atts( array(
352
- 'screen_name' => 'twitter',
 
353
  'include_rts' => FALSE,
354
  'exclude_replies' => FALSE,
355
  'tweet_count' => 5,
@@ -368,6 +378,14 @@ function rotatingtweets_display_shortcode( $atts, $content=null, $code="", $prin
368
  'ratelimit' => FALSE
369
  ), $atts ) ;
370
  extract($args);
 
 
 
 
 
 
 
 
371
  # Makes sure the scripts are listed
372
  rotatingtweets_enqueue_scripts();
373
  $tweets = rotatingtweets_get_tweets($screen_name,$include_rts,$exclude_replies);
@@ -511,7 +529,7 @@ function rotatingtweets_call_twitter_API($command,$options = NULL,$api = NULL )
511
  $connection = new wp_TwitterOAuth($api['key'], $api['secret'], $api['token'], $api['token_secret'] );
512
  // $result = $connection->get('statuses/user_timeline', $options);
513
  if(WP_DEBUG):
514
- echo "\n<!-- Using OAuth - version 1.1 of API -- $command -->\n";
515
  endif;
516
  $result = $connection->get($command , $options);
517
  else:
@@ -528,7 +546,7 @@ function rotatingtweets_call_twitter_API($command,$options = NULL,$api = NULL )
528
  endif;
529
  $apicall = "http://api.twitter.com/1/".$command.".json";
530
  if(!empty($string)) $apicall .= "?".implode('&',$string);
531
- if(WP_DEBUG) echo "<!-- Using version 1 of API - calling string $apicall -->";
532
  $result = wp_remote_request($apicall);
533
  endif;
534
  if(!is_wp_error($result)):
@@ -558,15 +576,28 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
558
  $optionname = "rotatingtweets-cache";
559
  $option = get_option($optionname);
560
  # Attempt to deal with 'Cannot use string offset as an array' error
561
- if(is_array($option) && is_array($option[$stringname]['json'][0])):
562
- $latest_json = $option[$stringname]['json'];
563
- $latest_json_date = $option[$stringname]['datetime'];
564
- $timegap = time()-$latest_json_date;
565
- # Now check that it's got arrays and not objects
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
566
  else:
567
- # Clears the cache and forces a reload
568
- $timegap = $cache_delay + 1;
569
- $option=array();
570
  endif;
571
  # Checks if it is time to call Twitter directly yet or if it should use the cache
572
  if($timegap > $cache_delay):
@@ -602,6 +633,9 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
602
  unset($firstentry);
603
  if(is_array($twitterjson)) $firstentry = $twitterjson[0];
604
  if(!empty($firstentry['text'])):
 
 
 
605
  $latest_json = $twitterjson;
606
  $option[$stringname]['json']=$latest_json;
607
  $option[$stringname]['datetime']=time();
@@ -681,11 +715,6 @@ function rotatingtweets_get_twitter_language() {
681
  endif;
682
  endif;
683
  if(empty($latest_languages)) $latest_languages = $fallback;
684
- if(WP_DEBUG):
685
- echo "<!-- \n";
686
- print_r($option);
687
- echo "\n-->";
688
- endif;
689
  return($latest_languages);
690
  }
691
 
@@ -737,7 +766,7 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
737
  $result = "\n<div class='rotatingtweets' id='$id'>";
738
  $error = get_option('rotatingtweets_api_error');
739
  if(!empty($error)):
740
- $result .= "\n<!-- Error: ".$error[0]['code']." - ".$error[0]['message']." -->";
741
  endif;
742
  if(empty($json)):
743
  $result .= "\n\t<div class = 'rotatingtweet'><p class='rtw_main'>". __('Problem retrieving data from Twitter','rotatingtweets'). "</p></div>";
@@ -756,7 +785,7 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
756
  $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". __('Wordpress error message','rotatingtweets').": ".$error_message.".</p></div>";
757
  endforeach;
758
  endif;
759
- $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". __('Please check the Twitter name used in the settings.','rotatingtweets')."</p></div>";
760
  endif;
761
  else:
762
  $tweet_counter = 0;
@@ -911,7 +940,7 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
911
  $result .= "\n\t\t<div class='rtw_wide'>";
912
  $result .= "\n\t\t<div class='rtw_wide_icon'>".rotatingtweets_user_intent($tweetuser,$twitterlocale,'icon',$targetvalue)."</div>";
913
  $result .= "\n\t\t<div class='rtw_wide_block'><div class='rtw_info'>";
914
- $result .= "\n\t\t\t<div class='rtw_time_short'>".rotatingtweets_timestamp_link($twitter_object,'short',$targetvalue).'</a></div>';
915
  $result .= "\n\t\t\t<div class='rtw_name'>".rotatingtweets_user_intent($tweetuser,$twitterlocale,'name',$targetvalue)."</div>";
916
  $result .= "\n\t\t\t<div class='rtw_id'>".rotatingtweets_user_intent($tweetuser,$twitterlocale,'screen_name',$targetvalue)."</div>";
917
  $result .= "\n\t\t</div>";
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: 0.711
6
  Text Domain: rotatingtweets
7
  Author: Martin Tod
8
  Author URI: http://www.martintod.org.uk
335
  function rotatingtweets_display($atts) {
336
  rotatingtweets_display_shortcode($atts,null,'',TRUE);
337
  };
338
+ #
339
+ function rotatingtweets_link_to_screenname($link) {
340
+ $match = '%(http://|https://|)(www\.|)twitter\.com/(#!\/|)([0-9a-z\_]+)%i';
341
+ if(preg_match($match,$link,$result)):
342
+ return($result[4]);
343
+ else:
344
+ return FALSE;
345
+ endif;
346
+ }
347
  # Processes the shortcode
348
  function rotatingtweets_display_shortcode( $atts, $content=null, $code="", $print=FALSE ) {
349
  // $atts ::= twitter_id,include_rts,exclude_replies, $tweet_count,$show_follow
358
  $no_show_screen_name :: [boolean] remove screen name from follow button
359
  */
360
  $args = shortcode_atts( array(
361
+ 'screen_name' => '',
362
+ 'url' => 'http://twitter.com/twitter',
363
  'include_rts' => FALSE,
364
  'exclude_replies' => FALSE,
365
  'tweet_count' => 5,
378
  'ratelimit' => FALSE
379
  ), $atts ) ;
380
  extract($args);
381
+ if(empty($screen_name) && !empty($url)):
382
+ $screen_name = rotatingtweets_link_to_screenname($url);
383
+ $args['screen_name'] = $screen_name;
384
+ if(WP_DEBUG) {
385
+ echo "<!-- $url => $screen_name -->";
386
+ }
387
+ endif;
388
+ if(empty($screen_name)) $screen_name = 'twitter';
389
  # Makes sure the scripts are listed
390
  rotatingtweets_enqueue_scripts();
391
  $tweets = rotatingtweets_get_tweets($screen_name,$include_rts,$exclude_replies);
529
  $connection = new wp_TwitterOAuth($api['key'], $api['secret'], $api['token'], $api['token_secret'] );
530
  // $result = $connection->get('statuses/user_timeline', $options);
531
  if(WP_DEBUG):
532
+ echo "\n<!-- Using OAuth - version 1.1 of API -- ".esc_attr($command)." -->\n";
533
  endif;
534
  $result = $connection->get($command , $options);
535
  else:
546
  endif;
547
  $apicall = "http://api.twitter.com/1/".$command.".json";
548
  if(!empty($string)) $apicall .= "?".implode('&',$string);
549
+ if(WP_DEBUG) echo "<!-- Using version 1 of API - calling string ".esc_attr($apicall)." -->";
550
  $result = wp_remote_request($apicall);
551
  endif;
552
  if(!is_wp_error($result)):
576
  $optionname = "rotatingtweets-cache";
577
  $option = get_option($optionname);
578
  # Attempt to deal with 'Cannot use string offset as an array' error
579
+ $timegap = $cache_delay + 1;
580
+ if(is_array($option)):
581
+ if(WP_DEBUG):
582
+ echo "<!-- var option is an array -->";
583
+ endif;
584
+ if(isset($option[$stringname])):
585
+ if(WP_DEBUG) echo "<!-- option[$stringname] exists -->";
586
+ if(is_array($option[$stringname]['json'][0])):
587
+ if(WP_DEBUG) echo "<!-- option[$stringname]['json'][0] is an array -->";
588
+ $latest_json = $option[$stringname]['json'];
589
+ $latest_json_date = $option[$stringname]['datetime'];
590
+ $timegap = time()-$latest_json_date;
591
+ elseif(is_object($option[$stringname]['json'][0])):
592
+ if(WP_DEBUG) echo "<!-- option[$stringname]['json'][0] is an object -->";
593
+ unset($option[$stringname]);
594
+ else:
595
+ if(WP_DEBUG) echo "<!-- option[$stringname]['json'][0] is neither an object nor an array! -->";
596
+ unset($option[$stringname]);
597
+ endif;
598
+ endif;
599
  else:
600
+ unset($option);
 
 
601
  endif;
602
  # Checks if it is time to call Twitter directly yet or if it should use the cache
603
  if($timegap > $cache_delay):
633
  unset($firstentry);
634
  if(is_array($twitterjson)) $firstentry = $twitterjson[0];
635
  if(!empty($firstentry['text'])):
636
+ if(WP_DEBUG):
637
+ echo "<!-- Storing cache entry for $stringname in $optionname -->";
638
+ endif;
639
  $latest_json = $twitterjson;
640
  $option[$stringname]['json']=$latest_json;
641
  $option[$stringname]['datetime']=time();
715
  endif;
716
  endif;
717
  if(empty($latest_languages)) $latest_languages = $fallback;
 
 
 
 
 
718
  return($latest_languages);
719
  }
720
 
766
  $result = "\n<div class='rotatingtweets' id='$id'>";
767
  $error = get_option('rotatingtweets_api_error');
768
  if(!empty($error)):
769
+ $result .= "\n<!-- Error: ".esc_attr($error[0]['code'])." - ".esc_attr($error[0]['message'])." -->";
770
  endif;
771
  if(empty($json)):
772
  $result .= "\n\t<div class = 'rotatingtweet'><p class='rtw_main'>". __('Problem retrieving data from Twitter','rotatingtweets'). "</p></div>";
785
  $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". __('Wordpress error message','rotatingtweets').": ".$error_message.".</p></div>";
786
  endforeach;
787
  endif;
788
+ $result .= "\n\t<div class = 'rotatingtweet' style='display:none'><p class='rtw_main'>". sprintf(__('Please check the Rotating Tweets settings or the <a href=\'%s\'>Twitter API status</a>.','rotatingtweets'),'https://dev.twitter.com/status')."</p></div>";
789
  endif;
790
  else:
791
  $tweet_counter = 0;
940
  $result .= "\n\t\t<div class='rtw_wide'>";
941
  $result .= "\n\t\t<div class='rtw_wide_icon'>".rotatingtweets_user_intent($tweetuser,$twitterlocale,'icon',$targetvalue)."</div>";
942
  $result .= "\n\t\t<div class='rtw_wide_block'><div class='rtw_info'>";
943
+ $result .= "\n\t\t\t<div class='rtw_time_short'>".rotatingtweets_timestamp_link($twitter_object,'short',$targetvalue).'</div>';
944
  $result .= "\n\t\t\t<div class='rtw_name'>".rotatingtweets_user_intent($tweetuser,$twitterlocale,'name',$targetvalue)."</div>";
945
  $result .= "\n\t\t\t<div class='rtw_id'>".rotatingtweets_user_intent($tweetuser,$twitterlocale,'screen_name',$targetvalue)."</div>";
946
  $result .= "\n\t\t</div>";