oAuth Twitter Feed for Developers - Version 2.1

Version Description

  • Change default and prefered method of calling to username, then count (For backwards compatibility, both will work)
  • Only include OAuth if an OAuthRequest class isn't already defined. This should stop some errors some folks have with other plugins.
  • Bug Fixes
Download this release

Release Info

Developer stormuk
Plugin Icon wp plugin oAuth Twitter Feed for Developers
Version 2.1
Comparing to
See all releases

Code changes from version 2.0.3 to 2.1

README.md CHANGED
@@ -27,7 +27,7 @@ Now, anywhere in your theme files you can call the `getTweets()` function to ret
27
  You can then loop over the array and do whatever you want with it.
28
 
29
  `<?php
30
- $tweets = getTweets($number_of_tweets, $twitter_screenname_to_load, $optional_array_of_any_additional_twitter_api_parameters);
31
  var_dump($tweets);
32
 
33
  foreach($tweets as $tweet){
@@ -60,7 +60,7 @@ Uses Abraham Williams's Twitter OAuth class.
60
  About
61
  =====
62
 
63
- Version: 2.0.3
64
 
65
  Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
66
 
27
  You can then loop over the array and do whatever you want with it.
28
 
29
  `<?php
30
+ $tweets = getTweets($twitter_screenname_to_load, $number_of_tweets, $optional_array_of_any_additional_twitter_api_parameters);
31
  var_dump($tweets);
32
 
33
  foreach($tweets as $tweet){
60
  About
61
  =====
62
 
63
+ Version: 2.1
64
 
65
  Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
66
 
StormTwitter.class.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- * Version 2.0.3
4
  * The base class for the storm twitter feed for developers.
5
  * This class provides all the things needed for the wordpress plugin, but in theory means you don't need to use it with wordpress.
6
  * What could go wrong?
@@ -30,8 +30,12 @@ class StormTwitter {
30
  return print_r($this->defaults, true);
31
  }
32
 
33
- //I'd prefer to put username before count, but for backwards compatibility it's not really viable. :(
34
- function getTweets($count = 20,$screenname = false,$options = false) {
 
 
 
 
35
  if ($count > 20) $count = 20;
36
  if ($count < 1) $count = 1;
37
 
@@ -54,15 +58,20 @@ class StormTwitter {
54
  //If we're here, we need to load.
55
  $result = $this->oauthGetTweets($screenname,$options);
56
 
57
- if (isset($result['errors'])) {
58
- if (is_array($results) && isset($result['errors'][0]) && isset($result['errors'][0]['message'])) {
59
  $last_error = $result['errors'][0]['message'];
60
  } else {
61
  $last_error = $result['errors'];
62
  }
63
- return array('error'=>'Twitter said: '.$last_error);
64
  } else {
65
- return $this->cropTweets($result,$count);
 
 
 
 
 
66
  }
67
 
68
  }
@@ -161,4 +170,4 @@ class StormTwitter {
161
  return $result;
162
 
163
  }
164
- }
1
  <?php
2
  /*
3
+ * Version 2.1
4
  * The base class for the storm twitter feed for developers.
5
  * This class provides all the things needed for the wordpress plugin, but in theory means you don't need to use it with wordpress.
6
  * What could go wrong?
30
  return print_r($this->defaults, true);
31
  }
32
 
33
+ function getTweets($screenname = false,$count = 20,$options = false) {
34
+ // BC: $count used to be the first argument
35
+ if (is_int($screenname)) {
36
+ list($screenname, $count) = array($count, $screenname);
37
+ }
38
+
39
  if ($count > 20) $count = 20;
40
  if ($count < 1) $count = 1;
41
 
58
  //If we're here, we need to load.
59
  $result = $this->oauthGetTweets($screenname,$options);
60
 
61
+ if (is_array($result) && isset($result['errors'])) {
62
+ if (is_array($result) && isset($result['errors'][0]) && isset($result['errors'][0]['message'])) {
63
  $last_error = $result['errors'][0]['message'];
64
  } else {
65
  $last_error = $result['errors'];
66
  }
67
+ return array('error'=>'Twitter said: '.json_encode($last_error));
68
  } else {
69
+ if (is_array($result)) {
70
+ return $this->cropTweets($result,$count);
71
+ } else {
72
+ $last_error = 'Something went wrong with the twitter request: '.json_encode($result);
73
+ return array('error'=>$last_error);
74
+ }
75
  }
76
 
77
  }
170
  return $result;
171
 
172
  }
173
+ }
oauth/twitteroauth.php CHANGED
@@ -7,7 +7,8 @@
7
  */
8
 
9
  /* Load OAuth lib. You can find it at http://oauth.net */
10
- require_once('OAuth.php');
 
11
 
12
  /**
13
  * Twitter OAuth class
7
  */
8
 
9
  /* Load OAuth lib. You can find it at http://oauth.net */
10
+ // This is a pretty scary fix, but many people already load OAuth libraries, so, lets see if OAuthRequest is already defined. If it is, lets not bother loading...
11
+ if (!class_exists('OAuthRequest')) require_once('OAuth.php');
12
 
13
  /**
14
  * Twitter OAuth class
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: stormuk, lgladdy
3
  Donate link: http://www.stormconsultancy.co.uk/
4
  Tags: twitter, oauth, feed, tweets
5
  Requires at least: 3.4
6
- Tested up to: 3.5
7
- Stable tag: 2.0.3
8
- Version: 2.0.3
9
  License: MIT
10
  License URI: http://opensource.org/licenses/MIT
11
 
@@ -66,7 +66,7 @@ Uses Abraham Williams's Twitter OAuth class.
66
 
67
  == About ==
68
 
69
- Version: 2.0.3
70
 
71
  Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
72
 
@@ -100,6 +100,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
100
 
101
  == Changelog ==
102
 
 
 
 
 
 
103
  = 2.0.3 =
104
  * Further defensive code against twitter abnormalities
105
 
3
  Donate link: http://www.stormconsultancy.co.uk/
4
  Tags: twitter, oauth, feed, tweets
5
  Requires at least: 3.4
6
+ Tested up to: 3.8
7
+ Stable tag: 2.1.0
8
+ Version: 2.1.0
9
  License: MIT
10
  License URI: http://opensource.org/licenses/MIT
11
 
66
 
67
  == About ==
68
 
69
+ Version: 2.1
70
 
71
  Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
72
 
100
 
101
  == Changelog ==
102
 
103
+ = 2.1 =
104
+ * Change default and prefered method of calling to username, then count (For backwards compatibility, both will work)
105
+ * Only include OAuth if an OAuthRequest class isn't already defined. This should stop some errors some folks have with other plugins.
106
+ * Bug Fixes
107
+
108
  = 2.0.3 =
109
  * Further defensive code against twitter abnormalities
110
 
twitter-feed-for-developers-settings.php CHANGED
@@ -39,7 +39,7 @@ function tdf_settings_output() {
39
  echo '<p>Most of this configuration can found on the application overview page on the <a href="http://dev.twitter.com/apps">http://dev.twitter.com</a> website.</p>';
40
  echo '<p>When creating an application for this plugin, you don\'t need to set a callback location and you only need read access.</p>';
41
  echo '<p>You will need to generate an oAuth token once you\'ve created the application. The button for that is on the bottom of the application overview page.</p>';
42
- echo '<p>Once configured, you then need to call getTweets() anywhere in your template. getTweets supports 3 parameters - the number of tweets to load (max 20), the username of the twitter feed you want to load, and any additional parameters you want to send to Twitter. An example code usage is shown under the debug information below.</p>';
43
  echo '<p>The format of the response from getTweets will either be an array of arrays containing tweet objects, as described on the official Twitter documentation <a href="https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline">here</a>, or an 1D array containing an "error" key, with a value of the error that occurred.</p>';
44
 
45
  echo '<hr />';
39
  echo '<p>Most of this configuration can found on the application overview page on the <a href="http://dev.twitter.com/apps">http://dev.twitter.com</a> website.</p>';
40
  echo '<p>When creating an application for this plugin, you don\'t need to set a callback location and you only need read access.</p>';
41
  echo '<p>You will need to generate an oAuth token once you\'ve created the application. The button for that is on the bottom of the application overview page.</p>';
42
+ echo '<p>Once configured, you then need to call getTweets() anywhere in your template. getTweets supports 3 parameters - the username of the twitter feed you want to load, the number of tweets to load (max 20), and any additional parameters you want to send to Twitter. An example code usage is shown under the debug information below.</p>';
43
  echo '<p>The format of the response from getTweets will either be an array of arrays containing tweet objects, as described on the official Twitter documentation <a href="https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline">here</a>, or an 1D array containing an "error" key, with a value of the error that occurred.</p>';
44
 
45
  echo '<hr />';
twitter-feed-for-developers.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: oAuth Twitter Feed for Developers
4
  Description: Twitter API 1.1 compliant plugin that provides a function to get an array of tweets from the auth'd users Twitter feed for use in themes.
5
- Version: 2.0.3
6
  License: MIT
7
  License URI: http://opensource.org/licenses/MIT
8
  Author: Storm Consultancy (Liam Gladdy)
@@ -14,7 +14,7 @@ require('StormTwitter.class.php');
14
  require('twitter-feed-for-developers-settings.php');
15
 
16
  /* implement getTweets */
17
- function getTweets($count = 20, $username = false, $options = false) {
18
 
19
  $config['key'] = get_option('tdf_consumer_key');
20
  $config['secret'] = get_option('tdf_consumer_secret');
2
  /*
3
  Plugin Name: oAuth Twitter Feed for Developers
4
  Description: Twitter API 1.1 compliant plugin that provides a function to get an array of tweets from the auth'd users Twitter feed for use in themes.
5
+ Version: 2.1
6
  License: MIT
7
  License URI: http://opensource.org/licenses/MIT
8
  Author: Storm Consultancy (Liam Gladdy)
14
  require('twitter-feed-for-developers-settings.php');
15
 
16
  /* implement getTweets */
17
+ function getTweets($username = false, $count = 20, $options = false) {
18
 
19
  $config['key'] = get_option('tdf_consumer_key');
20
  $config['secret'] = get_option('tdf_consumer_secret');