oAuth Twitter Feed for Developers - Version 2.2.0

Version Description

  • Check if any of our libraries are loaded by other plugins. If so, don't load them and produce a warning in our settings. This will prevent fatal errors when any other plugin uses OAuth or TwitterOAuth.
Download this release

Release Info

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

Code changes from version 2.1.4 to 2.2.0

README.md CHANGED
@@ -3,9 +3,9 @@ Storm Twitter Feed for WordPress
3
 
4
  A Twitter API 1.1 compliant wordpress plugin that provides an array of a users timeline from Twitter for use by theme developers.
5
 
6
- The new Twitter API requires you be oAuth'd before you can request a list of tweets, this means that all of the existing Twitter plugins that simply make an AJAX request for to the JSON API endpoint will break as of March 2013.
7
 
8
- This is a major problem for the vast majority of websites that are currently using twitter, so we built a PHP class that implements all the new requirements for authentication and gives you an array of tweets out of the other end, for you to use in your PHP applications, or WordPress theme. You can find the stand-alone [StormTwitter](https://github.com/stormuk/storm-twitter) class on GitHub
9
 
10
  This plugin wraps our Twitter class and provides a settings screen for easy integration into WordPress. However, it's definitely for developers - you only get a PHP array out of it that contains Twitter tweet objects. You'll still need to style the output and make it comply with the new display requirements.
11
 
@@ -60,7 +60,7 @@ Uses Abraham Williams's Twitter OAuth class.
60
  About
61
  =====
62
 
63
- Version: 2.1.3
64
 
65
  Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
66
 
@@ -71,7 +71,7 @@ If you are looking for a [Bath WordPress Developer](http://www.stormconsultancy.
71
  License
72
  =======
73
 
74
- Copyright (c) 2013 Storm Consultancy (EU) Ltd,
75
  <http://www.stormconsultancy.co.uk/>
76
 
77
  Permission is hereby granted, free of charge, to any person obtaining
3
 
4
  A Twitter API 1.1 compliant wordpress plugin that provides an array of a users timeline from Twitter for use by theme developers.
5
 
6
+ The new Twitter API requires you be oAuth'd before you can request a list of tweets, this means that all of the existing Twitter plugins that simply make an AJAX request for to the JSON API endpoint broke in March 2013.
7
 
8
+ This was a major problem for the vast majority of websites that are currently using twitter, so we built a PHP class that implements all the new requirements for authentication and gives you an array of tweets out of the other end, for you to use in your PHP applications, or WordPress theme. You can find the stand-alone [StormTwitter](https://github.com/stormuk/storm-twitter) class on GitHub
9
 
10
  This plugin wraps our Twitter class and provides a settings screen for easy integration into WordPress. However, it's definitely for developers - you only get a PHP array out of it that contains Twitter tweet objects. You'll still need to style the output and make it comply with the new display requirements.
11
 
60
  About
61
  =====
62
 
63
+ Version: 2.2.0
64
 
65
  Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
66
 
71
  License
72
  =======
73
 
74
+ Copyright (c) 2014 Storm Consultancy (EU) Ltd and Liam Gladdy,
75
  <http://www.stormconsultancy.co.uk/>
76
 
77
  Permission is hereby granted, free of charge, to any person obtaining
StormTwitter.class.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
2
  /*
3
- * Version 2.1.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?
7
  */
8
 
9
- require_once('oauth/twitteroauth.php');
 
 
 
 
 
10
 
11
  class StormTwitter {
12
 
1
  <?php
2
  /*
3
+ * Version 2.2.0
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?
7
  */
8
 
9
+
10
+ if (!class_exists('TwitterOAuth')) {
11
+ require_once('oauth/twitteroauth.php');
12
+ } else {
13
+ define('TFD_USING_EXISTING_LIBRARY_TWITTEROAUTH',true);
14
+ }
15
 
16
  class StormTwitter {
17
 
oauth/OAuth.php CHANGED
@@ -3,8 +3,10 @@
3
 
4
  /* Generic exception class
5
  */
6
- class OAuthException extends Exception {
7
- // pass
 
 
8
  }
9
 
10
  class OAuthConsumer {
@@ -380,10 +382,10 @@ class OAuthRequest {
380
  public function get_normalized_http_url() {
381
  $parts = parse_url($this->http_url);
382
 
383
- if (isset($parts['port'])) $port = $parts['port']; else $port = null;
384
  $scheme = $parts['scheme'];
385
  $host = $parts['host'];
386
- if (isset($parts['path'])) $path = $parts['path']; else $path = null;
387
 
388
  $port or $port = ($scheme == 'https') ? '443' : '80';
389
 
@@ -870,5 +872,3 @@ class OAuthUtil {
870
  return implode('&', $pairs);
871
  }
872
  }
873
-
874
- ?>
3
 
4
  /* Generic exception class
5
  */
6
+ if (!class_exists('OAuthException')) {
7
+ class OAuthException extends Exception {
8
+ // pass
9
+ }
10
  }
11
 
12
  class OAuthConsumer {
382
  public function get_normalized_http_url() {
383
  $parts = parse_url($this->http_url);
384
 
385
+ $port = @$parts['port'];
386
  $scheme = $parts['scheme'];
387
  $host = $parts['host'];
388
+ $path = @$parts['path'];
389
 
390
  $port or $port = ($scheme == 'https') ? '443' : '80';
391
 
872
  return implode('&', $pairs);
873
  }
874
  }
 
 
oauth/twitteroauth.php CHANGED
@@ -4,11 +4,15 @@
4
  * Abraham Williams (abraham@abrah.am) http://abrah.am
5
  *
6
  * The first PHP Library to support OAuth for Twitter's REST API.
 
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
@@ -33,7 +37,7 @@ class TwitterOAuth {
33
  /* Contains the last HTTP headers returned. */
34
  public $http_info;
35
  /* Set the useragnet. */
36
- public $useragent = 'Twitter Feed for Wordpress Developers 1.0';
37
  /* Immediately retry the API call if the response was not successful. */
38
  //public $retry = TRUE;
39
 
@@ -44,8 +48,8 @@ class TwitterOAuth {
44
  * Set API URLS
45
  */
46
  function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
47
- function authenticateURL() { return 'https://twitter.com/oauth/authenticate'; }
48
- function authorizeURL() { return 'https://twitter.com/oauth/authorize'; }
49
  function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
50
 
51
  /**
@@ -73,11 +77,9 @@ class TwitterOAuth {
73
  *
74
  * @returns a key/value array containing oauth_token and oauth_token_secret
75
  */
76
- function getRequestToken($oauth_callback = NULL) {
77
  $parameters = array();
78
- if (!empty($oauth_callback)) {
79
- $parameters['oauth_callback'] = $oauth_callback;
80
- }
81
  $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
82
  $token = OAuthUtil::parse_parameters($request);
83
  $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
@@ -109,11 +111,9 @@ class TwitterOAuth {
109
  * "user_id" => "9436992",
110
  * "screen_name" => "abraham")
111
  */
112
- function getAccessToken($oauth_verifier = FALSE) {
113
  $parameters = array();
114
- if (!empty($oauth_verifier)) {
115
- $parameters['oauth_verifier'] = $oauth_verifier;
116
- }
117
  $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
118
  $token = OAuthUtil::parse_parameters($request);
119
  $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
@@ -146,7 +146,7 @@ class TwitterOAuth {
146
  function get($url, $parameters = array()) {
147
  $response = $this->oAuthRequest($url, 'GET', $parameters);
148
  if ($this->format === 'json' && $this->decode_json) {
149
- return json_decode($response,true);
150
  }
151
  return $response;
152
  }
@@ -157,7 +157,7 @@ class TwitterOAuth {
157
  function post($url, $parameters = array()) {
158
  $response = $this->oAuthRequest($url, 'POST', $parameters);
159
  if ($this->format === 'json' && $this->decode_json) {
160
- return json_decode($response,true);
161
  }
162
  return $response;
163
  }
@@ -168,7 +168,7 @@ class TwitterOAuth {
168
  function delete($url, $parameters = array()) {
169
  $response = $this->oAuthRequest($url, 'DELETE', $parameters);
170
  if ($this->format === 'json' && $this->decode_json) {
171
- return json_decode($response,true);
172
  }
173
  return $response;
174
  }
@@ -207,12 +207,6 @@ class TwitterOAuth {
207
  curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
208
  curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
209
  curl_setopt($ci, CURLOPT_HEADER, FALSE);
210
- if (defined('WP_PROXY_HOST')){
211
- curl_setopt($ci, CURLOPT_PROXY, WP_PROXY_HOST);
212
- }
213
- if (defined('WP_PROXY_PORT')){
214
- curl_setopt($ci, CURLOPT_PROXYPORT, WP_PROXY_PORT);
215
- }
216
 
217
  switch ($method) {
218
  case 'POST':
4
  * Abraham Williams (abraham@abrah.am) http://abrah.am
5
  *
6
  * The first PHP Library to support OAuth for Twitter's REST API.
7
+ * Modified for compatibility with other plugins which could provide OAuthConsumer by Liam Gladdy, 2014.
8
  */
9
 
10
  /* Load OAuth lib. You can find it at http://oauth.net */
11
+ if (!class_exists('OAuthConsumer')) {
12
+ require_once('OAuth.php');
13
+ } else {
14
+ define('THR_USING_EXISTING_LIBRARY_OAUTH',true);
15
+ }
16
 
17
  /**
18
  * Twitter OAuth class
37
  /* Contains the last HTTP headers returned. */
38
  public $http_info;
39
  /* Set the useragnet. */
40
+ public $useragent = 'Twitter Feed for Wordpress Developers 2.2.0';
41
  /* Immediately retry the API call if the response was not successful. */
42
  //public $retry = TRUE;
43
 
48
  * Set API URLS
49
  */
50
  function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
51
+ function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
52
+ function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; }
53
  function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
54
 
55
  /**
77
  *
78
  * @returns a key/value array containing oauth_token and oauth_token_secret
79
  */
80
+ function getRequestToken($oauth_callback) {
81
  $parameters = array();
82
+ $parameters['oauth_callback'] = $oauth_callback;
 
 
83
  $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
84
  $token = OAuthUtil::parse_parameters($request);
85
  $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
111
  * "user_id" => "9436992",
112
  * "screen_name" => "abraham")
113
  */
114
+ function getAccessToken($oauth_verifier) {
115
  $parameters = array();
116
+ $parameters['oauth_verifier'] = $oauth_verifier;
 
 
117
  $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
118
  $token = OAuthUtil::parse_parameters($request);
119
  $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
146
  function get($url, $parameters = array()) {
147
  $response = $this->oAuthRequest($url, 'GET', $parameters);
148
  if ($this->format === 'json' && $this->decode_json) {
149
+ return json_decode($response);
150
  }
151
  return $response;
152
  }
157
  function post($url, $parameters = array()) {
158
  $response = $this->oAuthRequest($url, 'POST', $parameters);
159
  if ($this->format === 'json' && $this->decode_json) {
160
+ return json_decode($response);
161
  }
162
  return $response;
163
  }
168
  function delete($url, $parameters = array()) {
169
  $response = $this->oAuthRequest($url, 'DELETE', $parameters);
170
  if ($this->format === 'json' && $this->decode_json) {
171
+ return json_decode($response);
172
  }
173
  return $response;
174
  }
207
  curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
208
  curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
209
  curl_setopt($ci, CURLOPT_HEADER, FALSE);
 
 
 
 
 
 
210
 
211
  switch ($method) {
212
  case 'POST':
readme.txt CHANGED
@@ -4,8 +4,8 @@ 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.4
8
- Version: 2.1.4
9
  License: MIT
10
  License URI: http://opensource.org/licenses/MIT
11
 
@@ -15,9 +15,9 @@ Twitter API 1.1 compliant plugin that provides a function to get an array of twe
15
 
16
  A Twitter API 1.1 compliant wordpress plugin that provides an array of a users timeline from Twitter for use by theme developers.
17
 
18
- The new Twitter API requires you be oAuth'd before you can request a list of tweets, this means that all of the existing Twitter plugins that simply make an AJAX request for to the JSON API endpoint will break as of March 2013.
19
 
20
- This is a major problem for the vast majority of websites that are currently using twitter, so we built a PHP class that implements all the new requirements for authentication and gives you an array of tweets out of the other end, for you to use in your PHP applications, or WordPress theme. You can find the stand-alone [StormTwitter](https://github.com/stormuk/storm-twitter) class on GitHub
21
 
22
  This plugin wraps our Twitter class and provides a settings screen for easy integration into WordPress. However, it's definitely for developers - you only get a PHP array out of it that contains Twitter tweet objects. You'll still need to style the output and make it comply with the new display requirements.
23
 
@@ -66,7 +66,7 @@ Uses Abraham Williams's Twitter OAuth class.
66
 
67
  == About ==
68
 
69
- Version: 2.1.3
70
 
71
  Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
72
 
@@ -76,7 +76,7 @@ If you are looking for a [Bath WordPress Developer](http://www.stormconsultancy.
76
 
77
  == License ==
78
 
79
- Copyright (c) 2013 Storm Consultancy (EU) Ltd,
80
  <http://www.stormconsultancy.co.uk/>
81
 
82
  Permission is hereby granted, free of charge, to any person obtaining
@@ -100,6 +100,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
100
 
101
  == Changelog ==
102
 
 
 
 
103
  = 2.1.3 =
104
  * Fixes 2.1 for people using the very old getTweets($int) syntax. You should still change to the new version, but this will at least not be broken!
105
 
4
  Tags: twitter, oauth, feed, tweets
5
  Requires at least: 3.4
6
  Tested up to: 3.8
7
+ Stable tag: 2.2.0
8
+ Version: 2.2.0
9
  License: MIT
10
  License URI: http://opensource.org/licenses/MIT
11
 
15
 
16
  A Twitter API 1.1 compliant wordpress plugin that provides an array of a users timeline from Twitter for use by theme developers.
17
 
18
+ The new Twitter API requires you be oAuth'd before you can request a list of tweets, this means that all of the existing Twitter plugins that simply make an AJAX request for to the JSON API endpoint broke in March 2013.
19
 
20
+ This wass a major problem for the vast majority of websites that are currently using twitter, so we built a PHP class that implements all the new requirements for authentication and gives you an array of tweets out of the other end, for you to use in your PHP applications, or WordPress theme. You can find the stand-alone [StormTwitter](https://github.com/stormuk/storm-twitter) class on GitHub
21
 
22
  This plugin wraps our Twitter class and provides a settings screen for easy integration into WordPress. However, it's definitely for developers - you only get a PHP array out of it that contains Twitter tweet objects. You'll still need to style the output and make it comply with the new display requirements.
23
 
66
 
67
  == About ==
68
 
69
+ Version: 2.2.0
70
 
71
  Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
72
 
76
 
77
  == License ==
78
 
79
+ Copyright (c) 2014 Storm Consultancy (EU) Ltd and Liam Gladdy,
80
  <http://www.stormconsultancy.co.uk/>
81
 
82
  Permission is hereby granted, free of charge, to any person obtaining
100
 
101
  == Changelog ==
102
 
103
+ = 2.2.0 =
104
+ * Check if any of our libraries are loaded by other plugins. If so, don't load them and produce a warning in our settings. This will prevent fatal errors when any other plugin uses OAuth or TwitterOAuth.
105
+
106
  = 2.1.3 =
107
  * Fixes 2.1 for people using the very old getTweets($int) syntax. You should still change to the new version, but this will at least not be broken!
108
 
twitter-feed-for-developers-settings.php CHANGED
@@ -12,8 +12,8 @@ function tdf_menu() {
12
 
13
  function tdf_settings() {
14
  $tdf = array();
15
- $tdf[] = array('name'=>'tdf_consumer_key','label'=>'Twitter Application Consumer Key');
16
- $tdf[] = array('name'=>'tdf_consumer_secret','label'=>'Twitter Application Consumer Secret');
17
  $tdf[] = array('name'=>'tdf_access_token','label'=>'Account Access Token');
18
  $tdf[] = array('name'=>'tdf_access_token_secret','label'=>'Account Access Token Secret');
19
  $tdf[] = array('name'=>'tdf_cache_expire','label'=>'Cache Duration (Default 3600)');
@@ -36,6 +36,20 @@ function tdf_settings_output() {
36
 
37
  echo '<h2>oAuth Twitter Feed for Developers</h2>';
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>';
12
 
13
  function tdf_settings() {
14
  $tdf = array();
15
+ $tdf[] = array('name'=>'tdf_consumer_key','label'=>'Twitter Application API Key');
16
+ $tdf[] = array('name'=>'tdf_consumer_secret','label'=>'Twitter Application API Secret');
17
  $tdf[] = array('name'=>'tdf_access_token','label'=>'Account Access Token');
18
  $tdf[] = array('name'=>'tdf_access_token_secret','label'=>'Account Access Token Secret');
19
  $tdf[] = array('name'=>'tdf_cache_expire','label'=>'Cache Duration (Default 3600)');
36
 
37
  echo '<h2>oAuth Twitter Feed for Developers</h2>';
38
 
39
+ if (defined('TFD_USING_EXISTING_LIBRARY_TWITTEROAUTH') && TFD_USING_EXISTING_LIBRARY_TWITTEROAUTH) {
40
+ $reflector = new ReflectionClass('TwitterOAuth');
41
+ $file = $reflector->getFileName();
42
+
43
+ echo '<div id="message" class="error"><p><strong>oAuth Twitter Feed for Developers</strong> is using an existing version of the TwitterOAuth class library to provide compatibility with existing plugins.<br />This could lead to conflicts if the plugin is using an different version of the class.</p><p>The class is being loaded at <strong>'.$file.'</strong></p></div>';
44
+ }
45
+
46
+ if (defined('TFD_USING_EXISTING_LIBRARY_OAUTH') && TFD_USING_EXISTING_LIBRARY_OAUTH) {
47
+ $reflector = new ReflectionClass('OAuthConsumer');
48
+ $file = $reflector->getFileName();
49
+
50
+ echo '<div id="message" class="error"><p><strong>oAuth Twitter Feed for Developers</strong> is using an existing version of the PHP OAuth library to provide compatibility with existing plugins or your PHP installation.<br />This could lead to conflicts if the plugin, or your PHP installed class is using an different version of the class.</p><p>The class is being loaded at <strong>'.$file.'</strong></p></div>';
51
+ }
52
+
53
  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>';
54
  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>';
55
  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>';
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.1.4
6
  License: MIT
7
  License URI: http://opensource.org/licenses/MIT
8
  Author: Storm Consultancy (Liam Gladdy)
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.2.0
6
  License: MIT
7
  License URI: http://opensource.org/licenses/MIT
8
  Author: Storm Consultancy (Liam Gladdy)