Version Description
- New support for reading from multiple accounts. Addition of settings options for timeout and caching.
=
Download this release
Release Info
Developer | mpntod |
Plugin | Rotating Tweets (Twitter widget and shortcode) |
Version | 1.6.1 |
Comparing to | |
See all releases |
Code changes from version 1.6.0 to 1.6.1
- lib/wp_twitteroauth.php +242 -241
- readme.txt +5 -2
- rotatingtweets.php +2 -2
lib/wp_twitteroauth.php
CHANGED
@@ -13,265 +13,266 @@
|
|
13 |
|
14 |
/* Load WP_OAuth lib. You can find it at http://oauth.net */
|
15 |
if(!class_exists('WP_OAuthException')) require_once('WP_OAuth.php');
|
16 |
-
|
17 |
-
/**
|
18 |
-
|
19 |
-
|
20 |
-
class
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
endif;
|
211 |
-
$args['timeout'] = $this->timeout;
|
212 |
-
$args['sslverify'] = $this->ssl_verifypeer;
|
213 |
-
if(WP_DEBUG):
|
214 |
-
echo "\n\$args = ";
|
215 |
-
if(isset($args)):
|
216 |
-
print_r($args);
|
217 |
-
else:
|
218 |
-
echo "NULL";
|
219 |
endif;
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
-
/*
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
*/
|
263 |
-
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
}
|
|
13 |
|
14 |
/* Load WP_OAuth lib. You can find it at http://oauth.net */
|
15 |
if(!class_exists('WP_OAuthException')) require_once('WP_OAuth.php');
|
16 |
+
if(!class_exists('rotatingtweets_TwitterOauth')):
|
17 |
+
/**
|
18 |
+
* Twitter WP_OAuth class
|
19 |
+
*/
|
20 |
+
class rotatingtweets_TwitterOAuth {
|
21 |
+
/* Contains the last HTTP status code returned. */
|
22 |
+
public $http_code;
|
23 |
+
/* Contains the last API call. */
|
24 |
+
public $url;
|
25 |
+
/* Set up the API root URL. */
|
26 |
+
public $host = "https://api.twitter.com/1.1/";
|
27 |
+
/* Set timeout default. */
|
28 |
+
public $timeout = 3;
|
29 |
+
/* Set connect timeout. */
|
30 |
+
public $connecttimeout = 2;
|
31 |
+
/* Verify SSL Cert. */
|
32 |
+
public $ssl_verifypeer = TRUE;
|
33 |
+
/* Respons format. */
|
34 |
+
public $format = 'json';
|
35 |
+
/* Decode returned json data. */
|
36 |
+
public $decode_json = FALSE;
|
37 |
+
/* Contains the last HTTP headers returned. */
|
38 |
+
public $http_info;
|
39 |
+
/* Set the useragnet. */
|
40 |
+
public $useragent = 'Twitter Feed for Wordpress Developers 1.1';
|
41 |
+
/* Immediately retry the API call if the response was not successful. */
|
42 |
+
//public $retry = TRUE;
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
+
/**
|
48 |
+
* Set API URLS
|
49 |
+
*/
|
50 |
+
function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
|
51 |
+
function authenticateURL() { return 'https://twitter.com/oauth/authenticate'; }
|
52 |
+
function authorizeURL() { return 'https://twitter.com/oauth/authorize'; }
|
53 |
+
function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
|
54 |
|
55 |
+
/**
|
56 |
+
* Debug helpers
|
57 |
+
*/
|
58 |
+
function lastStatusCode() { return $this->http_status; }
|
59 |
+
function lastAPICall() { return $this->last_api_call; }
|
60 |
|
61 |
+
/**
|
62 |
+
* construct TwitterOAuth object
|
63 |
+
*/
|
64 |
+
function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
|
65 |
+
$this->sha1_method = new WP_OAuthSignatureMethod_HMAC_SHA1();
|
66 |
+
$this->consumer = new WP_OAuthConsumer($consumer_key, $consumer_secret);
|
67 |
+
if (!empty($oauth_token) && !empty($oauth_token_secret)) {
|
68 |
+
$this->token = new WP_OAuthConsumer($oauth_token, $oauth_token_secret);
|
69 |
+
} else {
|
70 |
+
$this->token = NULL;
|
71 |
+
}
|
72 |
+
}
|
73 |
|
74 |
|
75 |
+
/**
|
76 |
+
* Get a request_token from Twitter
|
77 |
+
*
|
78 |
+
* @returns a key/value array containing oauth_token and oauth_token_secret
|
79 |
+
*/
|
80 |
+
function getRequestToken($oauth_callback = NULL) {
|
81 |
+
$parameters = array();
|
82 |
+
if (!empty($oauth_callback)) {
|
83 |
+
$parameters['oauth_callback'] = $oauth_callback;
|
84 |
+
}
|
85 |
+
$request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
|
86 |
+
$token = WP_OAuthUtil::parse_parameters($request);
|
87 |
+
$this->token = new WP_OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
|
88 |
+
return $token;
|
89 |
+
}
|
90 |
|
91 |
+
/**
|
92 |
+
* Get the authorize URL
|
93 |
+
*
|
94 |
+
* @returns a string
|
95 |
+
*/
|
96 |
+
function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
|
97 |
+
if (is_array($token)) {
|
98 |
+
$token = $token['oauth_token'];
|
99 |
+
}
|
100 |
+
if (empty($sign_in_with_twitter)) {
|
101 |
+
return $this->authorizeURL() . "?oauth_token={$token}";
|
102 |
+
} else {
|
103 |
+
return $this->authenticateURL() . "?oauth_token={$token}";
|
104 |
+
}
|
105 |
+
}
|
106 |
|
107 |
+
/**
|
108 |
+
* Exchange request token and secret for an access token and
|
109 |
+
* secret, to sign API calls.
|
110 |
+
*
|
111 |
+
* @returns array("oauth_token" => "the-access-token",
|
112 |
+
* "oauth_token_secret" => "the-access-secret",
|
113 |
+
* "user_id" => "9436992",
|
114 |
+
* "screen_name" => "abraham")
|
115 |
+
*/
|
116 |
+
function getAccessToken($oauth_verifier = FALSE) {
|
117 |
+
$parameters = array();
|
118 |
+
if (!empty($oauth_verifier)) {
|
119 |
+
$parameters['oauth_verifier'] = $oauth_verifier;
|
120 |
+
}
|
121 |
+
$request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
|
122 |
+
$token = WP_OAuthUtil::parse_parameters($request);
|
123 |
+
$this->token = new WP_OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
|
124 |
+
return $token;
|
125 |
+
}
|
126 |
|
127 |
+
/**
|
128 |
+
* One time exchange of username and password for access token and secret.
|
129 |
+
*
|
130 |
+
* @returns array("oauth_token" => "the-access-token",
|
131 |
+
* "oauth_token_secret" => "the-access-secret",
|
132 |
+
* "user_id" => "9436992",
|
133 |
+
* "screen_name" => "abraham",
|
134 |
+
* "x_auth_expires" => "0")
|
135 |
+
*/
|
136 |
+
function getXAuthToken($username, $password) {
|
137 |
+
$parameters = array();
|
138 |
+
$parameters['x_auth_username'] = $username;
|
139 |
+
$parameters['x_auth_password'] = $password;
|
140 |
+
$parameters['x_auth_mode'] = 'client_auth';
|
141 |
+
$request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
|
142 |
+
$token = WP_OAuthUtil::parse_parameters($request);
|
143 |
+
$this->token = new WP_OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
|
144 |
+
return $token;
|
145 |
+
}
|
146 |
|
147 |
+
/**
|
148 |
+
* GET wrapper for oAuthRequest.
|
149 |
+
*/
|
150 |
+
function get($url, $parameters = array()) {
|
151 |
+
$response = $this->oAuthRequest($url, 'GET', $parameters);
|
152 |
+
if ($this->format === 'json' && $this->decode_json) {
|
153 |
+
return json_decode($response,true);
|
154 |
+
}
|
155 |
+
return $response;
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* POST wrapper for oAuthRequest.
|
160 |
+
*/
|
161 |
+
function post($url, $parameters = array()) {
|
162 |
+
$response = $this->oAuthRequest($url, 'POST', $parameters);
|
163 |
+
if ($this->format === 'json' && $this->decode_json) {
|
164 |
+
return json_decode($response,true);
|
165 |
+
}
|
166 |
+
return $response;
|
167 |
+
}
|
168 |
|
169 |
+
/**
|
170 |
+
* DELETE wrapper for oAuthReqeust.
|
171 |
+
*/
|
172 |
+
function delete($url, $parameters = array()) {
|
173 |
+
$response = $this->oAuthRequest($url, 'DELETE', $parameters);
|
174 |
+
if ($this->format === 'json' && $this->decode_json) {
|
175 |
+
return json_decode($response,true);
|
176 |
+
}
|
177 |
+
return $response;
|
178 |
+
}
|
179 |
|
180 |
+
/**
|
181 |
+
* Format and sign an WP_OAuth / API request
|
182 |
+
*/
|
183 |
+
function oAuthRequest($url, $method, $parameters) {
|
184 |
+
if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
|
185 |
+
$url = "{$this->host}{$url}.{$this->format}";
|
186 |
+
}
|
187 |
+
$request = WP_OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
|
188 |
+
$request->sign_request($this->sha1_method, $this->consumer, $this->token);
|
189 |
+
switch ($method) {
|
190 |
+
case 'GET':
|
191 |
+
return $this->http($request->to_url(), 'GET');
|
192 |
+
default:
|
193 |
+
return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
|
194 |
+
}
|
195 |
+
}
|
196 |
|
197 |
+
/**
|
198 |
+
* Make an HTTP request
|
199 |
+
*
|
200 |
+
* @return API results
|
201 |
+
*/
|
202 |
+
function http($url, $method, $postfields = NULL) {
|
203 |
|
204 |
+
if(WP_DEBUG) echo "<!-- wp_remote_request() variables in lib/wp_twitteroauth.php: \n\n\$url = ".esc_url($url)."\n";
|
205 |
+
if(!empty($method)):
|
206 |
+
$args['method']=$method;
|
207 |
+
endif;
|
208 |
+
if(is_array($postfields)):
|
209 |
+
$args['body'] = $postfields;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
endif;
|
211 |
+
$args['timeout'] = $this->timeout;
|
212 |
+
$args['sslverify'] = $this->ssl_verifypeer;
|
213 |
+
if(WP_DEBUG):
|
214 |
+
echo "\n\$args = ";
|
215 |
+
if(isset($args)):
|
216 |
+
print_r($args);
|
217 |
+
else:
|
218 |
+
echo "NULL";
|
219 |
+
endif;
|
220 |
+
echo "\n-->\n";
|
221 |
+
endif;
|
222 |
+
$response = wp_remote_request($url,$args);
|
223 |
+
if(WP_DEBUG) echo "<!-- wp_remote_request() in lib/wp_twitteroauth.php successfully completed -->\n";
|
224 |
+
return($response);
|
225 |
|
226 |
+
/*
|
227 |
+
if(WP_DEBUG) echo "<!-- Using curl API to access data directly -->";
|
228 |
+
$this->http_info = array();
|
229 |
+
$ci = curl_init();
|
230 |
+
# Curl settings
|
231 |
+
curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
|
232 |
+
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
|
233 |
+
curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
|
234 |
+
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
|
235 |
+
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
|
236 |
+
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
|
237 |
+
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
|
238 |
+
curl_setopt($ci, CURLOPT_HEADER, FALSE);
|
239 |
|
240 |
+
switch ($method) {
|
241 |
+
case 'POST':
|
242 |
+
curl_setopt($ci, CURLOPT_POST, TRUE);
|
243 |
+
if (!empty($postfields)) {
|
244 |
+
curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
|
245 |
+
}
|
246 |
+
break;
|
247 |
+
case 'DELETE':
|
248 |
+
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
249 |
+
if (!empty($postfields)) {
|
250 |
+
$url = "{$url}?{$postfields}";
|
251 |
+
}
|
252 |
+
}
|
253 |
|
254 |
+
curl_setopt($ci, CURLOPT_URL, $url);
|
255 |
+
$response = curl_exec($ci);
|
256 |
+
$this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
|
257 |
+
$this->http_info = array_merge($this->http_info, curl_getinfo($ci));
|
258 |
+
$this->url = $url;
|
259 |
+
curl_close ($ci);
|
260 |
+
$return = array('body' => $response);
|
261 |
+
return $return;
|
262 |
+
*/
|
263 |
+
}
|
264 |
|
265 |
+
/**
|
266 |
+
* Get the header info to store.
|
267 |
+
*/
|
268 |
+
function getHeader($ch, $header) {
|
269 |
+
$i = strpos($header, ':');
|
270 |
+
if (!empty($i)) {
|
271 |
+
$key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
|
272 |
+
$value = trim(substr($header, $i + 2));
|
273 |
+
$this->http_header[$key] = $value;
|
274 |
+
}
|
275 |
+
return strlen($header);
|
276 |
+
}
|
277 |
+
}
|
278 |
+
endif;
|
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,responsive
|
5 |
Requires at least: 2.6
|
6 |
Tested up to: 3.6
|
7 |
-
Stable tag: 1.6.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -162,10 +162,13 @@ into your CSS - changing `123px;` to the width you're aiming at - either via put
|
|
162 |
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.
|
163 |
|
164 |
== Upgrade notice ==
|
165 |
-
= 1.6.
|
166 |
* New support for reading from multiple accounts. Addition of settings options for timeout and caching.
|
167 |
|
168 |
== Changelog ==
|
|
|
|
|
|
|
169 |
= 1.6.0 =
|
170 |
* New support for reading from multiple accounts
|
171 |
* Improved clean-up on uninstallation or deactivation
|
4 |
Tags: shortcode,widget,twitter,rotating,rotate,rotator,tweet,tweets,animation,jquery,jquery cycle,cycle,multilingual,responsive
|
5 |
Requires at least: 2.6
|
6 |
Tested up to: 3.6
|
7 |
+
Stable tag: 1.6.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
162 |
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.
|
163 |
|
164 |
== Upgrade notice ==
|
165 |
+
= 1.6.1 =
|
166 |
* New support for reading from multiple accounts. Addition of settings options for timeout and caching.
|
167 |
|
168 |
== Changelog ==
|
169 |
+
= 1.6.1 =
|
170 |
+
* Move to a more unique class name to avoid clashes with another template.
|
171 |
+
|
172 |
= 1.6.0 =
|
173 |
* New support for reading from multiple accounts
|
174 |
* Improved clean-up on uninstallation or deactivation
|
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.6.
|
6 |
Text Domain: rotatingtweets
|
7 |
Author: Martin Tod
|
8 |
Author URI: http://www.martintod.org.uk
|
@@ -786,7 +786,7 @@ And now the Twitter API itself!
|
|
786 |
function rotatingtweets_call_twitter_API($command,$options = NULL,$api = NULL ) {
|
787 |
if(empty($api)) $api = get_option('rotatingtweets-api-settings');
|
788 |
if(!empty($api)):
|
789 |
-
$connection = new
|
790 |
// $result = $connection->get('statuses/user_timeline', $options);
|
791 |
if(WP_DEBUG && ! is_admin()):
|
792 |
echo "\n<!-- Using OAuth - version 1.1 of API - ".esc_attr($command)." -->\n";
|
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.6.1
|
6 |
Text Domain: rotatingtweets
|
7 |
Author: Martin Tod
|
8 |
Author URI: http://www.martintod.org.uk
|
786 |
function rotatingtweets_call_twitter_API($command,$options = NULL,$api = NULL ) {
|
787 |
if(empty($api)) $api = get_option('rotatingtweets-api-settings');
|
788 |
if(!empty($api)):
|
789 |
+
$connection = new rotatingtweets_TwitterOAuth($api['key'], $api['secret'], $api['token'], $api['token_secret'] );
|
790 |
// $result = $connection->get('statuses/user_timeline', $options);
|
791 |
if(WP_DEBUG && ! is_admin()):
|
792 |
echo "\n<!-- Using OAuth - version 1.1 of API - ".esc_attr($command)." -->\n";
|