Version Description
Download this release
Release Info
Developer | stormuk |
Plugin | oAuth Twitter Feed for Developers |
Version | 2.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.6 to 2.0
- README.md +11 -11
- StormTwitter.class.php +59 -19
- readme.txt +16 -10
- twitter-feed-for-developers-settings.php +10 -8
- twitter-feed-for-developers.php +6 -6
README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
Storm Twitter Feed for WordPress
|
2 |
================================
|
3 |
|
4 |
-
|
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 |
|
@@ -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();
|
31 |
var_dump($tweets);
|
32 |
|
33 |
foreach($tweets as $tweet){
|
@@ -37,7 +37,13 @@ You can then loop over the array and do whatever you want with it.
|
|
37 |
|
38 |
You can specify a number of tweets to return (up to 20) by passing a parameter to the function. For example, to display just the latest tweet you'd request `getTweets(1)`
|
39 |
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
Output
|
43 |
======
|
@@ -46,12 +52,6 @@ As we said, this plugin does not provide sidebar widgets, shortcodes or any othe
|
|
46 |
|
47 |
https://github.com/stormuk/storm-twitter-for-wordpress/wiki/Example-code-to-layout-tweets
|
48 |
|
49 |
-
TODO
|
50 |
-
====
|
51 |
-
|
52 |
-
* Move the screen name from the settings page to a function parameter so you can use the plugin to request different timelines
|
53 |
-
* Make the cache duration configurable
|
54 |
-
|
55 |
Credits
|
56 |
=======
|
57 |
|
@@ -60,7 +60,7 @@ Uses Abraham Williams's Twitter OAuth class.
|
|
60 |
About
|
61 |
=====
|
62 |
|
63 |
-
Version:
|
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)
|
75 |
<http://www.stormconsultancy.co.uk/>
|
76 |
|
77 |
Permission is hereby granted, free of charge, to any person obtaining
|
1 |
Storm Twitter Feed for WordPress
|
2 |
================================
|
3 |
|
4 |
+
Twitter API 1.1 compliant plugin that provides a single function for getting an array of a twitter timeline 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 |
|
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){
|
37 |
|
38 |
You can specify a number of tweets to return (up to 20) by passing a parameter to the function. For example, to display just the latest tweet you'd request `getTweets(1)`
|
39 |
|
40 |
+
The following default options are used unless you override them in the optional array of additional parameters.
|
41 |
+
|
42 |
+
* Trim the user object ("trim_user" => true)
|
43 |
+
* Exclude replies ("exclude_replies" => true)
|
44 |
+
* Exclude retweets ("include_rts" => false)
|
45 |
+
|
46 |
+
Results are cached for 1 hour (by default) to help you avoid hitting the API limits.
|
47 |
|
48 |
Output
|
49 |
======
|
52 |
|
53 |
https://github.com/stormuk/storm-twitter-for-wordpress/wiki/Example-code-to-layout-tweets
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
Credits
|
56 |
=======
|
57 |
|
60 |
About
|
61 |
=====
|
62 |
|
63 |
+
Version: 2.0
|
64 |
|
65 |
Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
|
66 |
|
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
|
StormTwitter.class.php
CHANGED
@@ -1,10 +1,13 @@
|
|
1 |
<?php
|
2 |
/*
|
|
|
3 |
* The base class for the storm twitter feed for developers.
|
4 |
* This class provides all the things needed for the wordpress plugin, but in theory means you don't need to use it with wordpress.
|
5 |
* What could go wrong?
|
6 |
*/
|
7 |
|
|
|
|
|
8 |
class StormTwitter {
|
9 |
|
10 |
private $defaults = array(
|
@@ -13,10 +16,10 @@ class StormTwitter {
|
|
13 |
'secret' => '',
|
14 |
'token' => '',
|
15 |
'token_secret' => '',
|
16 |
-
'screenname' => ''
|
|
|
17 |
);
|
18 |
|
19 |
-
public $st_last_cached = false;
|
20 |
public $st_last_error = false;
|
21 |
|
22 |
function __construct($args = array()) {
|
@@ -27,18 +30,29 @@ class StormTwitter {
|
|
27 |
return print_r($this->defaults, true);
|
28 |
}
|
29 |
|
30 |
-
|
|
|
31 |
if ($count > 20) $count = 20;
|
32 |
if ($count < 1) $count = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
$result = $this->checkValidCache();
|
35 |
|
36 |
if ($result !== false) {
|
37 |
return $this->cropTweets($result,$count);
|
38 |
}
|
39 |
|
40 |
//If we're here, we need to load.
|
41 |
-
$result = $this->oauthGetTweets();
|
42 |
|
43 |
if (isset($result['errors'])) {
|
44 |
return array('error'=>'Twitter said: '.$result['errors'][0]['message']);
|
@@ -48,45 +62,68 @@ class StormTwitter {
|
|
48 |
|
49 |
}
|
50 |
|
51 |
-
function cropTweets($result,$count) {
|
52 |
return array_slice($result, 0, $count);
|
53 |
}
|
54 |
|
55 |
-
function getCacheLocation() {
|
56 |
return $this->defaults['directory'].'.tweetcache';
|
57 |
}
|
58 |
|
59 |
-
function
|
|
|
|
|
|
|
|
|
|
|
60 |
$file = $this->getCacheLocation();
|
61 |
if (is_file($file)) {
|
62 |
$cache = file_get_contents($file);
|
63 |
$cache = @json_decode($cache,true);
|
64 |
-
|
|
|
65 |
unlink($file);
|
66 |
return false;
|
67 |
}
|
68 |
-
|
|
|
|
|
69 |
unlink($file);
|
70 |
return false;
|
71 |
}
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
if (!isset($result['errors'])) {
|
75 |
return $result;
|
76 |
}
|
77 |
}
|
78 |
-
return $cache['tweets'];
|
79 |
} else {
|
80 |
return false;
|
81 |
}
|
82 |
}
|
83 |
|
84 |
-
function oauthGetTweets() {
|
85 |
$key = $this->defaults['key'];
|
86 |
$secret = $this->defaults['secret'];
|
87 |
$token = $this->defaults['token'];
|
88 |
$token_secret = $this->defaults['token_secret'];
|
89 |
-
|
|
|
|
|
|
|
90 |
|
91 |
if (empty($key)) return array('error'=>'Missing Consumer Key - Check Settings');
|
92 |
if (empty($secret)) return array('error'=>'Missing Consumer Secret - Check Settings');
|
@@ -95,14 +132,17 @@ class StormTwitter {
|
|
95 |
if (empty($screenname)) return array('error'=>'Missing Twitter Feed Screen Name - Check Settings');
|
96 |
|
97 |
$connection = new TwitterOAuth($key, $secret, $token, $token_secret);
|
98 |
-
$result = $connection->get('statuses/user_timeline',
|
|
|
|
|
|
|
|
|
99 |
|
100 |
if (!isset($result['errors'])) {
|
101 |
-
$cache['time'] = time();
|
102 |
-
$cache['tweets'] = $result;
|
103 |
$file = $this->getCacheLocation();
|
104 |
file_put_contents($file,json_encode($cache));
|
105 |
-
$this->st_last_cached = $cache['time'];
|
106 |
} else {
|
107 |
$last_error = '['.date('r').'] Twitter error: '.$result['errors'][0]['message'];
|
108 |
$this->st_last_error = $last_error;
|
1 |
<?php
|
2 |
/*
|
3 |
+
* Version 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 |
+
require_once('oauth/twitteroauth.php');
|
10 |
+
|
11 |
class StormTwitter {
|
12 |
|
13 |
private $defaults = array(
|
16 |
'secret' => '',
|
17 |
'token' => '',
|
18 |
'token_secret' => '',
|
19 |
+
'screenname' => '',
|
20 |
+
'cache_expire' => 3600
|
21 |
);
|
22 |
|
|
|
23 |
public $st_last_error = false;
|
24 |
|
25 |
function __construct($args = array()) {
|
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 |
+
|
38 |
+
$default_options = array('trim_user'=>true, 'exclude_replies'=>true, 'include_rts'=>false);
|
39 |
+
|
40 |
+
if ($options === false || !is_array($options)) {
|
41 |
+
$options = $default_options;
|
42 |
+
} else {
|
43 |
+
$options = array_merge($default_options, $options);
|
44 |
+
}
|
45 |
+
|
46 |
+
if ($screenname === false) $screenname = $this->defaults['screenname'];
|
47 |
|
48 |
+
$result = $this->checkValidCache($screenname,$options);
|
49 |
|
50 |
if ($result !== false) {
|
51 |
return $this->cropTweets($result,$count);
|
52 |
}
|
53 |
|
54 |
//If we're here, we need to load.
|
55 |
+
$result = $this->oauthGetTweets($screenname,$options);
|
56 |
|
57 |
if (isset($result['errors'])) {
|
58 |
return array('error'=>'Twitter said: '.$result['errors'][0]['message']);
|
62 |
|
63 |
}
|
64 |
|
65 |
+
private function cropTweets($result,$count) {
|
66 |
return array_slice($result, 0, $count);
|
67 |
}
|
68 |
|
69 |
+
private function getCacheLocation() {
|
70 |
return $this->defaults['directory'].'.tweetcache';
|
71 |
}
|
72 |
|
73 |
+
private function getOptionsHash($options) {
|
74 |
+
$hash = md5(serialize($options));
|
75 |
+
return $hash;
|
76 |
+
}
|
77 |
+
|
78 |
+
private function checkValidCache($screenname,$options) {
|
79 |
$file = $this->getCacheLocation();
|
80 |
if (is_file($file)) {
|
81 |
$cache = file_get_contents($file);
|
82 |
$cache = @json_decode($cache,true);
|
83 |
+
|
84 |
+
if (!isset($cache)) {
|
85 |
unlink($file);
|
86 |
return false;
|
87 |
}
|
88 |
+
|
89 |
+
// Delete the old cache from the first version, before we added support for multiple usernames
|
90 |
+
if (isset($cache['time'])) {
|
91 |
unlink($file);
|
92 |
return false;
|
93 |
}
|
94 |
+
|
95 |
+
$cachename = $screenname."-".$this->getOptionsHash($options);
|
96 |
+
|
97 |
+
//Check if we have a cache for the user.
|
98 |
+
if (!isset($cache[$cachename])) return false;
|
99 |
+
|
100 |
+
if (!isset($cache[$cachename]['time']) || !isset($cache[$cachename]['tweets'])) {
|
101 |
+
unset($cache[$cachename]);
|
102 |
+
file_put_contents($file,json_encode($cache));
|
103 |
+
return false;
|
104 |
+
}
|
105 |
+
|
106 |
+
if ($cache[$cachename]['time'] < (time() - $this->defaults['cache_expire'])) {
|
107 |
+
$result = $this->oauthGetTweets($screenname,$options);
|
108 |
if (!isset($result['errors'])) {
|
109 |
return $result;
|
110 |
}
|
111 |
}
|
112 |
+
return $cache[$cachename]['tweets'];
|
113 |
} else {
|
114 |
return false;
|
115 |
}
|
116 |
}
|
117 |
|
118 |
+
private function oauthGetTweets($screenname,$options) {
|
119 |
$key = $this->defaults['key'];
|
120 |
$secret = $this->defaults['secret'];
|
121 |
$token = $this->defaults['token'];
|
122 |
$token_secret = $this->defaults['token_secret'];
|
123 |
+
|
124 |
+
$cachename = $screenname."-".$this->getOptionsHash($options);
|
125 |
+
|
126 |
+
$options = array_merge($options, array('screen_name' => $screenname, 'count' => 20));
|
127 |
|
128 |
if (empty($key)) return array('error'=>'Missing Consumer Key - Check Settings');
|
129 |
if (empty($secret)) return array('error'=>'Missing Consumer Secret - Check Settings');
|
132 |
if (empty($screenname)) return array('error'=>'Missing Twitter Feed Screen Name - Check Settings');
|
133 |
|
134 |
$connection = new TwitterOAuth($key, $secret, $token, $token_secret);
|
135 |
+
$result = $connection->get('statuses/user_timeline', $options);
|
136 |
+
|
137 |
+
if (is_file($this->getCacheLocation())) {
|
138 |
+
$cache = json_decode(file_get_contents($this->getCacheLocation()),true);
|
139 |
+
}
|
140 |
|
141 |
if (!isset($result['errors'])) {
|
142 |
+
$cache[$cachename]['time'] = time();
|
143 |
+
$cache[$cachename]['tweets'] = $result;
|
144 |
$file = $this->getCacheLocation();
|
145 |
file_put_contents($file,json_encode($cache));
|
|
|
146 |
} else {
|
147 |
$last_error = '['.date('r').'] Twitter error: '.$result['errors'][0]['message'];
|
148 |
$this->st_last_error = $last_error;
|
readme.txt
CHANGED
@@ -4,12 +4,12 @@ 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:
|
8 |
-
Version:
|
9 |
License: MIT
|
10 |
License URI: http://opensource.org/licenses/MIT
|
11 |
|
12 |
-
Twitter API 1.1 compliant plugin that provides a function
|
13 |
|
14 |
== Description ==
|
15 |
|
@@ -42,7 +42,7 @@ Now, anywhere in your theme files you can call the `getTweets()` function to ret
|
|
42 |
You can then loop over the array and do whatever you want with it.
|
43 |
|
44 |
`<?php
|
45 |
-
$tweets = getTweets();
|
46 |
var_dump($tweets);
|
47 |
|
48 |
foreach($tweets as $tweet){
|
@@ -52,12 +52,13 @@ You can then loop over the array and do whatever you want with it.
|
|
52 |
|
53 |
You can specify a number of tweets to return (up to 20) by passing a parameter to the function. For example, to display just the latest tweet you'd request `getTweets(1)`
|
54 |
|
55 |
-
|
56 |
|
57 |
-
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
* Make the cache duration configurable
|
61 |
|
62 |
== Credits ==
|
63 |
|
@@ -65,7 +66,7 @@ Uses Abraham Williams's Twitter OAuth class.
|
|
65 |
|
66 |
== About ==
|
67 |
|
68 |
-
Version:
|
69 |
|
70 |
Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
|
71 |
|
@@ -75,7 +76,7 @@ If you are looking for a [Bath WordPress Developer](http://www.stormconsultancy.
|
|
75 |
|
76 |
== License ==
|
77 |
|
78 |
-
Copyright (c)
|
79 |
<http://www.stormconsultancy.co.uk/>
|
80 |
|
81 |
Permission is hereby granted, free of charge, to any person obtaining
|
@@ -99,6 +100,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
99 |
|
100 |
== Changelog ==
|
101 |
|
|
|
|
|
|
|
|
|
|
|
102 |
= 1.0.4 =
|
103 |
* Make the plugin actually work properly!
|
104 |
* Correct documentation files for inclusion by wordpress
|
4 |
Tags: twitter, oauth, feed, tweets
|
5 |
Requires at least: 3.4
|
6 |
Tested up to: 3.5
|
7 |
+
Stable tag: 2.0
|
8 |
+
Version: 2.0
|
9 |
License: MIT
|
10 |
License URI: http://opensource.org/licenses/MIT
|
11 |
|
12 |
+
Twitter API 1.1 compliant plugin that provides a single function for getting an array of a twitter timeline for use by theme developers.
|
13 |
|
14 |
== Description ==
|
15 |
|
42 |
You can then loop over the array and do whatever you want with it.
|
43 |
|
44 |
`<?php
|
45 |
+
$tweets = getTweets($number_of_tweets, $twitter_screenname_to_load, $optional_array_of_any_additional_twitter_api_parameters);
|
46 |
var_dump($tweets);
|
47 |
|
48 |
foreach($tweets as $tweet){
|
52 |
|
53 |
You can specify a number of tweets to return (up to 20) by passing a parameter to the function. For example, to display just the latest tweet you'd request `getTweets(1)`
|
54 |
|
55 |
+
The following default options are used unless you override them in the optional array of additional parameters.
|
56 |
|
57 |
+
* Trim the user object ("trim_user" => true)
|
58 |
+
* Exclude replies ("exclude_replies" => true)
|
59 |
+
* Exclude retweets ("include_rts" => false)
|
60 |
|
61 |
+
Results are cached for 1 hour (by default) to help you avoid hitting the API limits.
|
|
|
62 |
|
63 |
== Credits ==
|
64 |
|
66 |
|
67 |
== About ==
|
68 |
|
69 |
+
Version: 2.0
|
70 |
|
71 |
Written by Liam Gladdy of Storm Consultancy - <http://www.stormconsultancy.co.uk>
|
72 |
|
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 |
|
101 |
== Changelog ==
|
102 |
|
103 |
+
= 2.0.0 =
|
104 |
+
* Support multiple screennames
|
105 |
+
* Support additional parameters to pass on to twitter (for excluding RTs, etc)
|
106 |
+
* Support custom cache expiry
|
107 |
+
|
108 |
= 1.0.4 =
|
109 |
* Make the plugin actually work properly!
|
110 |
* Correct documentation files for inclusion by wordpress
|
twitter-feed-for-developers-settings.php
CHANGED
@@ -16,7 +16,8 @@ function tdf_settings() {
|
|
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'=>'
|
|
|
20 |
return $tdf;
|
21 |
}
|
22 |
|
@@ -33,13 +34,12 @@ function tdf_settings_output() {
|
|
33 |
|
34 |
echo '<div class="wrap">';
|
35 |
|
36 |
-
echo '<h2>Twitter Feed for Developers</h2>';
|
37 |
|
38 |
-
echo '<p>
|
39 |
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>';
|
40 |
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>';
|
41 |
-
echo '<p>
|
42 |
-
echo '<p>getTweets($limit = 20) takes an optional limit on the number of tweets, up to a maximum of 20, and has default of 20.</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 />';
|
@@ -54,6 +54,11 @@ function tdf_settings_output() {
|
|
54 |
echo '<td>'.$setting['label'].'</td>';
|
55 |
echo '<td><input type="text" style="width: 400px" name="'.$setting['name'].'" value="'.get_option($setting['name']).'" /></td>';
|
56 |
echo '</tr>';
|
|
|
|
|
|
|
|
|
|
|
57 |
}
|
58 |
echo '</table>';
|
59 |
|
@@ -64,9 +69,6 @@ function tdf_settings_output() {
|
|
64 |
echo '<hr />';
|
65 |
|
66 |
echo '<h3>Debug Information</h3>';
|
67 |
-
$last_cached = get_option('tdf_last_cached');
|
68 |
-
if (empty($last_cached)) $last_cached = "Never"; else $last_cached = date('r',$last_cached);
|
69 |
-
echo '<p>Last Cached: '.$last_cached.'<br />';
|
70 |
$last_error = get_option('tdf_last_error');
|
71 |
if (empty($last_error)) $last_error = "None";
|
72 |
echo 'Last Error: '.$last_error.'</p>';
|
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)');
|
20 |
+
$tdf[] = array('name'=>'tdf_user_timeline','label'=>'Twitter Feed Screen Name*');
|
21 |
return $tdf;
|
22 |
}
|
23 |
|
34 |
|
35 |
echo '<div class="wrap">';
|
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>';
|
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 />';
|
54 |
echo '<td>'.$setting['label'].'</td>';
|
55 |
echo '<td><input type="text" style="width: 400px" name="'.$setting['name'].'" value="'.get_option($setting['name']).'" /></td>';
|
56 |
echo '</tr>';
|
57 |
+
if ($setting['name'] == 'tdf_user_timeline') {
|
58 |
+
echo '<tr>';
|
59 |
+
echo '<td colspan="2" style="font-size:10px; font-style: italic">This option is no longer required. You may define the screen name to load as part of the getTweets() call as detailed above.</td>';
|
60 |
+
echo '</tr>';
|
61 |
+
}
|
62 |
}
|
63 |
echo '</table>';
|
64 |
|
69 |
echo '<hr />';
|
70 |
|
71 |
echo '<h3>Debug Information</h3>';
|
|
|
|
|
|
|
72 |
$last_error = get_option('tdf_last_error');
|
73 |
if (empty($last_error)) $last_error = "None";
|
74 |
echo 'Last Error: '.$last_error.'</p>';
|
twitter-feed-for-developers.php
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: oAuth Twitter Feed for Developers
|
4 |
-
Description: Twitter API 1.1 compliant plugin that provides a function
|
5 |
-
Version:
|
6 |
License: MIT
|
7 |
License URI: http://opensource.org/licenses/MIT
|
8 |
Author: Storm Consultancy (Liam Gladdy)
|
@@ -12,21 +12,21 @@ Author URI: http://www.stormconsultancy.co.uk
|
|
12 |
|
13 |
require('StormTwitter.class.php');
|
14 |
require('twitter-feed-for-developers-settings.php');
|
15 |
-
require('oauth/twitteroauth.php');
|
16 |
|
17 |
/* implement getTweets */
|
18 |
-
function getTweets($count = 20) {
|
19 |
|
20 |
$config['key'] = get_option('tdf_consumer_key');
|
21 |
$config['secret'] = get_option('tdf_consumer_secret');
|
22 |
$config['token'] = get_option('tdf_access_token');
|
23 |
$config['token_secret'] = get_option('tdf_access_token_secret');
|
24 |
$config['screenname'] = get_option('tdf_user_timeline');
|
|
|
|
|
25 |
$config['directory'] = plugin_dir_path(__FILE__);
|
26 |
|
27 |
$obj = new StormTwitter($config);
|
28 |
-
$res = $obj->getTweets($count);
|
29 |
-
update_option('tdf_last_cached',$obj->st_last_cached);
|
30 |
update_option('tdf_last_error',$obj->st_last_error);
|
31 |
return $res;
|
32 |
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: oAuth Twitter Feed for Developers
|
4 |
+
Description: Twitter API 1.1 compliant plugin that provides a single function for getting an array of a twitter timeline for use by theme developers.
|
5 |
+
Version: 2.0
|
6 |
License: MIT
|
7 |
License URI: http://opensource.org/licenses/MIT
|
8 |
Author: Storm Consultancy (Liam Gladdy)
|
12 |
|
13 |
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');
|
21 |
$config['token'] = get_option('tdf_access_token');
|
22 |
$config['token_secret'] = get_option('tdf_access_token_secret');
|
23 |
$config['screenname'] = get_option('tdf_user_timeline');
|
24 |
+
$config['cache_expire'] = intval(get_option('tdf_cache_expire'));
|
25 |
+
if ($config['cache_expire'] < 1) $config['cache_expire'] = 3600;
|
26 |
$config['directory'] = plugin_dir_path(__FILE__);
|
27 |
|
28 |
$obj = new StormTwitter($config);
|
29 |
+
$res = $obj->getTweets($count, $username, $options);
|
|
|
30 |
update_option('tdf_last_error',$obj->st_last_error);
|
31 |
return $res;
|
32 |
|