Rotating Tweets (Twitter widget and shortcode) - Version 0.709

Version Description

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

=

Download this release

Release Info

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

Code changes from version 0.707 to 0.709

Files changed (2) hide show
  1. readme.txt +5 -2
  2. rotatingtweets.php +35 -10
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.707
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.707 =
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.707 =
90
  Fixes major bug resulting from upgrade to handle Twitter API v 1.1
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.709
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.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
+
92
  = 0.707 =
93
  Fixes major bug resulting from upgrade to handle Twitter API v 1.1
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.707
6
  Text Domain: rotatingtweets
7
  Author: Martin Tod
8
  Author URI: http://www.martintod.org.uk
@@ -395,10 +395,10 @@ function rotatingtweets_settings_check() {
395
  $msgString = __('Please update <a href="%2$s">your settings for Rotating Tweets</a>. The Twitter API will <a href="%1$s">be changing in March 2013</a> and new settings are needed for Rotating Tweets to continue working after the API changes.','rotatingtweets');
396
  endif;
397
  // add_settings_error( 'rotatingtweets_settings_needed', esc_attr('rotatingtweets_settings_needed'), sprintf($msgString,'https://dev.twitter.com/calendar',$optionslink), 'error');
398
- echo "<div class='error'><p>".sprintf($msgString,'https://dev.twitter.com/calendar',$optionslink)."</p></div>";
399
  elseif($error[0]['code'] == 32 ):
400
  // add_settings_error( 'rotatingtweets_settings_needed', esc_attr('rotatingtweets_settings_needed'), sprintf(__('Please update <a href="%1$s">your settings for Rotating Tweets</a>. Currently Twitter cannot authenticate you with the details you have given.','rotatingtweets'),$optionslink), 'error');
401
- echo "<div class='error'><p>".sprintf(__('Please update <a href="%1$s">your settings for Rotating Tweets</a>. Currently Twitter cannot authenticate you with the details you have given.','rotatingtweets'),$optionslink)."</p></div>";
402
  endif;
403
  };
404
  add_action( 'admin_notices', 'rotatingtweets_settings_check' );
@@ -416,7 +416,13 @@ function rotatingtweets_call_twitter_API_options() {
416
  if ( !current_user_can( 'manage_options' ) ) {
417
  wp_die( __( 'You do not have sufficient permissions to access this page.','rotatingtweets' ) );
418
  }
419
- echo sprintf(__('<p>Twitter <a href="%3$s">recently announced</a> that they will be changing the way that they allow people to use the information in their tweets.</p><p>Please take the following steps to make sure that Rotating Tweets continues working:</p><h3>Step 1:</h3><p>Go to the <a href="%1$s">My applications page</a> on the Twitter website to set up your website as a new Twitter \'application\'. You may need to log-in using your Twitter user name and password.</p><h3>Step 2:</h3><p>If you don\'t already have a suitable \'application\' that you can use for your website, set one up on the <a href="%2$s">Create an Application page</a>.</p> <p>It\'s normally best to use the name, description and website URL of the website where you plan to use Rotating Tweets.</p><p>You don\'t need a Callback URL.</p><h3>Step 3:</h3><p>After clicking <strong>Create your Twitter application</strong>, on the following page, click on <strong>Create my access token</strong>.</p><h3>Step 4:</h3><p>Copy the <strong>Consumer key</strong>, <strong>Consumer secret</strong>, <strong>Access token</strong> and <strong>Access token secret</strong> from your Twitter application page into the settings below.</p><h3>Step 5:</h3><p>Click on <strong>Save Changes</strong>. If there are any problems, you will get an error message from Twitter which should help diagnose the problem.</p>','rotatingtweets'),'https://dev.twitter.com/apps','https://dev.twitter.com/apps/new','https://dev.twitter.com/blog/changes-coming-to-twitter-api');
 
 
 
 
 
 
420
  echo '<form method="post" action="options.php">';
421
  settings_fields( 'rotatingtweets_options' );
422
  do_settings_sections('rotatingtweets_api_settings');
@@ -456,33 +462,43 @@ function rotatingtweets_api_explanation() {
456
  // validate our options
457
  function rotatingtweets_api_validate($input) {
458
  $options = get_option('rotatingtweets-api-settings');
 
459
  // Check 'key'
460
  $options['key'] = trim($input['key']);
461
  if(!preg_match('/^[a-z0-9]+$/i', $options['key'])) {
462
  $options['key'] = '';
 
 
463
  }
464
  // Check 'secret'
465
  $options['secret'] = trim($input['secret']);
466
  if(!preg_match('/^[a-z0-9]+$/i', $options['secret'])) {
467
  $options['secret'] = '';
 
 
468
  }
469
  // Check 'token'
470
  $options['token'] = trim($input['token']);
471
  if(!preg_match('/^[0-9]+\-[a-z0-9]+$/i', $options['token'])) {
472
  $options['token'] = '';
 
 
473
  }
474
  // Check 'token_secret'
475
  $options['token_secret'] = trim($input['token_secret']);
476
  if(!preg_match('/^[a-z0-9]+$/i', $options['token_secret'])) {
477
  $options['token_secret'] = '';
 
 
478
  }
479
  // Now a proper test
480
- $test = rotatingtweets_call_twitter_API('statuses/user_timeline',NULL,$options);
481
- $error = get_option('rotatingtweets_api_error');
482
- if(!empty($error)):
483
- add_settings_error( 'rotatingtweets', esc_attr('rotatingtweets-api-'.$error[0]['code']), sprintf(__('Error message received from Twitter: %1$s. <a href="%2$s">Please check your API key, secret, token and secret token on the Twitter website</a>.','rotatingtweets'),$error[0]['message'],'https://dev.twitter.com/apps'), 'error' );
 
 
484
  endif;
485
-
486
  return $options;
487
  }
488
  /*
@@ -522,6 +538,11 @@ function rotatingtweets_call_twitter_API($command,$options = NULL,$api = NULL )
522
  else:
523
  delete_option('rotatingtweets_api_error');
524
  endif;
 
 
 
 
 
525
  endif;
526
  return($result);
527
  }
@@ -602,7 +623,7 @@ function rotatingtweets_get_rate_data() {
602
  $newrate['hourly_limit']=$rate['resources']['statuses']['/statuses/user_timeline']['limit'];
603
  $newrate['remaining_hits']=$rate['resources']['statuses']['/statuses/user_timeline']['remaining'];
604
  $newrate['reset_time_in_seconds']=$rate['resources']['statuses']['/statuses/user_timeline']['reset'];
605
- return($newrate);
606
  else:
607
  return($rate);
608
  endif;
@@ -714,6 +735,10 @@ function rotating_tweets_display($json,$args,$print=TRUE) {
714
  # Create an ID that has all the relevant info in - rotation type and speed of rotation
715
  $id = uniqid('rotatingtweets_'.$timeout.'_'.$rotation_type.'_');
716
  $result = "\n<div class='rotatingtweets' id='$id'>";
 
 
 
 
717
  if(empty($json)):
718
  $result .= "\n\t<div class = 'rotatingtweet'><p class='rtw_main'>". __('Problem retrieving data from Twitter','rotatingtweets'). "</p></div>";
719
  $rate = rotatingtweets_get_rate_data();
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
395
  $msgString = __('Please update <a href="%2$s">your settings for Rotating Tweets</a>. The Twitter API will <a href="%1$s">be changing in March 2013</a> and new settings are needed for Rotating Tweets to continue working after the API changes.','rotatingtweets');
396
  endif;
397
  // add_settings_error( 'rotatingtweets_settings_needed', esc_attr('rotatingtweets_settings_needed'), sprintf($msgString,'https://dev.twitter.com/calendar',$optionslink), 'error');
398
+ echo "<div class='error'><p><strong>".sprintf($msgString,'https://dev.twitter.com/calendar',$optionslink)."</strong></p></div>";
399
  elseif($error[0]['code'] == 32 ):
400
  // add_settings_error( 'rotatingtweets_settings_needed', esc_attr('rotatingtweets_settings_needed'), sprintf(__('Please update <a href="%1$s">your settings for Rotating Tweets</a>. Currently Twitter cannot authenticate you with the details you have given.','rotatingtweets'),$optionslink), 'error');
401
+ echo "<div class='error'><p><strong>".sprintf(__('Please update <a href="%1$s">your settings for Rotating Tweets</a>. Currently Rotating Tweets cannot authenticate you with Twitter using the details you have given.','rotatingtweets'),$optionslink)."</strong></p></div>";
402
  endif;
403
  };
404
  add_action( 'admin_notices', 'rotatingtweets_settings_check' );
416
  if ( !current_user_can( 'manage_options' ) ) {
417
  wp_die( __( 'You do not have sufficient permissions to access this page.','rotatingtweets' ) );
418
  }
419
+ echo sprintf(__('<p>Twitter <a href="%s">recently announced</a> that they will be changing the way that they allow people to use the information in their tweets.</p><p>Please take the following steps to make sure that Rotating Tweets continues working:</p>','rotatingtweets'),'https://dev.twitter.com/blog/changes-coming-to-twitter-api');
420
+ echo sprintf(__('<h3>Step 1:</h3><p>Go to the <a href="%s">My applications page</a> on the Twitter website to set up your website as a new Twitter \'application\'. You may need to log-in using your Twitter user name and password.</p>','rotatingtweets'),'https://dev.twitter.com/apps');
421
+ echo sprintf(__('<h3>Step 2:</h3><p>If you don\'t already have a suitable \'application\' that you can use for your website, set one up on the <a href="%s">Create an Application page</a>.</p> <p>It\'s normally best to use the name, description and website URL of the website where you plan to use Rotating Tweets.</p><p>You don\'t need a Callback URL.</p>','rotatingtweets'),'https://dev.twitter.com/apps/new');
422
+ _e('<h3>Step 3:</h3><p>After clicking <strong>Create your Twitter application</strong>, on the following page, click on <strong>Create my access token</strong>.</p>','rotatingtweets');
423
+ _e('<h3>Step 4:</h3><p>Copy the <strong>Consumer key</strong>, <strong>Consumer secret</strong>, <strong>Access token</strong> and <strong>Access token secret</strong> from your Twitter application page into the settings below.</p>','rotatingtweets');
424
+ _e('<h3>Step 5:</h3><p>Click on <strong>Save Changes</strong>. If there are any problems, you will get an error message from Twitter which should help diagnose the problem.</p>','rotatingtweets');
425
+ _e('<p><em>Even though you are only entering one set of Twitter API data, Rotating Tweets will continue to support multiple widgets and shortcodes pulling from a variety of different Twitter accounts.</em></p>','rotatingtweets');
426
  echo '<form method="post" action="options.php">';
427
  settings_fields( 'rotatingtweets_options' );
428
  do_settings_sections('rotatingtweets_api_settings');
462
  // validate our options
463
  function rotatingtweets_api_validate($input) {
464
  $options = get_option('rotatingtweets-api-settings');
465
+ $error = 0;
466
  // Check 'key'
467
  $options['key'] = trim($input['key']);
468
  if(!preg_match('/^[a-z0-9]+$/i', $options['key'])) {
469
  $options['key'] = '';
470
+ $error = 1;
471
+ add_settings_error( 'rotatingtweets', esc_attr('rotatingtweets-api-key'), __('Error: Twitter API Consumer Key not correctly formatted.','rotatingtweets'));
472
  }
473
  // Check 'secret'
474
  $options['secret'] = trim($input['secret']);
475
  if(!preg_match('/^[a-z0-9]+$/i', $options['secret'])) {
476
  $options['secret'] = '';
477
+ $error = 1;
478
+ add_settings_error( 'rotatingtweets', esc_attr('rotatingtweets-api-secret'), __('Error: Twitter API Consumer Secret not correctly formatted.','rotatingtweets'));
479
  }
480
  // Check 'token'
481
  $options['token'] = trim($input['token']);
482
  if(!preg_match('/^[0-9]+\-[a-z0-9]+$/i', $options['token'])) {
483
  $options['token'] = '';
484
+ $error = 1;
485
+ add_settings_error( 'rotatingtweets', esc_attr('rotatingtweets-api-token'), __('Error: Twitter API Access Token not correctly formatted.','rotatingtweets'));
486
  }
487
  // Check 'token_secret'
488
  $options['token_secret'] = trim($input['token_secret']);
489
  if(!preg_match('/^[a-z0-9]+$/i', $options['token_secret'])) {
490
  $options['token_secret'] = '';
491
+ $error = 1;
492
+ add_settings_error( 'rotatingtweets', esc_attr('rotatingtweets-api-token-secret'), __('Error: Twitter API Access Token Secret not correctly formatted.','rotatingtweets'));
493
  }
494
  // Now a proper test
495
+ if(empty($error)):
496
+ $test = rotatingtweets_call_twitter_API('statuses/user_timeline',NULL,$options);
497
+ $error = get_option('rotatingtweets_api_error');
498
+ if(!empty($error)):
499
+ add_settings_error( 'rotatingtweets', esc_attr('rotatingtweets-api-'.$error[0]['code']), sprintf(__('Error message received from Twitter: %1$s. <a href="%2$s">Please check your API key, secret, token and secret token on the Twitter website</a>.','rotatingtweets'),$error[0]['message'],'https://dev.twitter.com/apps'), 'error' );
500
+ endif;
501
  endif;
 
502
  return $options;
503
  }
504
  /*
538
  else:
539
  delete_option('rotatingtweets_api_error');
540
  endif;
541
+ else:
542
+ $errorstring = array();
543
+ $errorstring[0]['code']= $result->get_error_code();
544
+ $errorstring[0]['message']= $result->get_error_message();
545
+ update_option('rotatingtweets_api_error',$errorstring);
546
  endif;
547
  return($result);
548
  }
623
  $newrate['hourly_limit']=$rate['resources']['statuses']['/statuses/user_timeline']['limit'];
624
  $newrate['remaining_hits']=$rate['resources']['statuses']['/statuses/user_timeline']['remaining'];
625
  $newrate['reset_time_in_seconds']=$rate['resources']['statuses']['/statuses/user_timeline']['reset'];
626
+ return($newrate);
627
  else:
628
  return($rate);
629
  endif;
735
  # Create an ID that has all the relevant info in - rotation type and speed of rotation
736
  $id = uniqid('rotatingtweets_'.$timeout.'_'.$rotation_type.'_');
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>";
744
  $rate = rotatingtweets_get_rate_data();