Version Description
- [Fixed] URLs no longer truncated in retweets!
- [Added] cURL error notification: this is a required PHP extension for connection to the Twitter API
Download this release
Release Info
Developer | Planet Interactive |
Plugin | Simple Twitter Tweets |
Version | 1.3.3 |
Comparing to | |
See all releases |
Code changes from version 1.3.2 to 1.3.3
- README.txt +7 -3
- simple-twitter-tweets.php +135 -45
README.txt
CHANGED
@@ -4,7 +4,7 @@ Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A94
|
|
4 |
Tags: Twitter, Stream, Tweets, Twitter OAuth, social
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.5.2
|
7 |
-
Stable tag: 1.3.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -115,6 +115,10 @@ As far as we know it just works! Phew, but if you have an issue or you want to p
|
|
115 |
|
116 |
== Changelog ==
|
117 |
|
|
|
|
|
|
|
|
|
118 |
= 1.3.2 =
|
119 |
* Fixed Exclude Replies variable notice and tweet calculation
|
120 |
|
@@ -146,5 +150,5 @@ As far as we know it just works! Phew, but if you have an issue or you want to p
|
|
146 |
|
147 |
== Upgrade Notice ==
|
148 |
|
149 |
-
= 1.3.
|
150 |
-
|
4 |
Tags: Twitter, Stream, Tweets, Twitter OAuth, social
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.5.2
|
7 |
+
Stable tag: 1.3.3
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
115 |
|
116 |
== Changelog ==
|
117 |
|
118 |
+
= 1.3.3 =
|
119 |
+
* [Fixed] URLs no longer truncated in retweets!
|
120 |
+
* [Added] cURL error notification: this is a required PHP extension for connection to the Twitter API
|
121 |
+
|
122 |
= 1.3.2 =
|
123 |
* Fixed Exclude Replies variable notice and tweet calculation
|
124 |
|
150 |
|
151 |
== Upgrade Notice ==
|
152 |
|
153 |
+
= 1.3.3 =
|
154 |
+
Fixed retweets truncated links and more.
|
simple-twitter-tweets.php
CHANGED
@@ -4,14 +4,14 @@ Plugin Name: Simple Twitter Tweets
|
|
4 |
Plugin URI: http://www.planet-interactive.co.uk/simple-twitter-tweets
|
5 |
Description: Display last x number tweets from Twitter API stream, store locally in dataabse to present past tweets when failure to access Twitters restrictive API occurs
|
6 |
Author: Ashley Sheinwald
|
7 |
-
Version: 1.3.
|
8 |
Author URI: http://www.planet-interactive.co.uk/
|
9 |
*/
|
10 |
|
11 |
/* Copyright 2013 Ashley Sheinwald (email : ashley@planet-interactive.co.uk)
|
12 |
|
13 |
This program is free software; you can redistribute it and/or modify
|
14 |
-
it under the terms of the GNU General Public License, version 2, as
|
15 |
published by the Free Software Foundation.
|
16 |
|
17 |
This program is distributed in the hope that it will be useful,
|
@@ -27,11 +27,24 @@ Author URI: http://www.planet-interactive.co.uk/
|
|
27 |
// USED FOR DEBUG
|
28 |
// include 'console.php';
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
class PI_SimpleTwitterTweets extends WP_Widget{
|
31 |
|
32 |
function PI_SimpleTwitterTweets() {
|
33 |
$widget_ops = array('classname' => 'PI_SimpleTwitterTweets', 'description' => 'Displays the most recent tweets from your Twitter Stream' );
|
34 |
-
//$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'Not-required-this-time' );
|
35 |
$this->WP_Widget('PI_SimpleTwitterTweets', 'Simple Twitter Tweets', $widget_ops);
|
36 |
|
37 |
// Load (enqueue) some JS in Admin ONLY on widgets page
|
@@ -40,16 +53,85 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
40 |
|
41 |
// Lets load some JS to aid widget display in Appearance->Widgets
|
42 |
function PI_load_admin_scripts($hook) {
|
43 |
-
if( $hook != 'widgets.php' )
|
44 |
return;
|
45 |
|
46 |
wp_enqueue_script('PI_stt_js', plugins_url( '/simple-twitter-tweets/js/sttAdmin.min.js' , dirname(__FILE__) ), array('jquery'));
|
47 |
}
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
function form($instance){
|
50 |
-
|
51 |
//Set up some default widget settings.
|
52 |
-
$defaults = array(
|
53 |
'title' => __('Recent Tweets', 'pi-tweet')
|
54 |
, 'name' => __('iPlanetUK', 'pi-tweet')
|
55 |
, 'numTweets' => __(4, 'pi-tweet') // How many to display
|
@@ -79,6 +161,14 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
79 |
$dataShowScreenName = $instance['dataShowScreenName'];
|
80 |
$dataLang = $instance['dataLang'];
|
81 |
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
<p>
|
83 |
<label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label>
|
84 |
</p>
|
@@ -103,29 +193,31 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
103 |
<p>
|
104 |
<label for="<?php echo $this->get_field_id('accessTokenSecret'); ?>">Access Token Secret: <input class="widefat" id="<?php echo $this->get_field_id('accessTokenSecret'); ?>" name="<?php echo $this->get_field_name('accessTokenSecret'); ?>" type="text" value="<?php echo esc_attr($accessTokenSecret); ?>" /></label>
|
105 |
</p>
|
106 |
-
<p>
|
107 |
-
<input class="checkbox" type="checkbox" <?php checked( isset( $instance['exclude_replies']), true ); ?> id="<?php echo $this->get_field_id( 'exclude_replies' ); ?>" name="<?php echo $this->get_field_name( 'exclude_replies' ); ?>" />
|
108 |
-
<label for="<?php echo $this->get_field_id( 'exclude_replies' ); ?>"><?php _e('Exclude_@replies', 'pi-tweet'); ?></label>
|
109 |
</p>
|
110 |
-
|
|
|
|
|
111 |
<div class="twitterFollow" style="background:#d6eef9;">
|
112 |
<h4 class="button-secondary" style="width:100%; text-align:center;">Twitter Follow Button <span style="font-size:75%;">▼</span></h4>
|
113 |
<div style="padding:10px;">
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
</div>
|
130 |
</div>
|
131 |
<?php
|
@@ -133,10 +225,10 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
133 |
|
134 |
function update($new_instance, $old_instance){
|
135 |
$instance = $old_instance;
|
136 |
-
|
137 |
-
//Strip tags from title and name to remove HTML
|
138 |
-
$instance['title'] = strip_tags( $new_instance['title'] );
|
139 |
-
$instance['name'] = strip_tags( $new_instance['name'] );
|
140 |
$instance['numTweets'] = $new_instance['numTweets'];
|
141 |
$instance['cacheTime'] = $new_instance['cacheTime'];
|
142 |
$instance['consumerKey'] = $new_instance['consumerKey'];
|
@@ -148,10 +240,10 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
148 |
$instance['dataShowCount'] = $new_instance['dataShowCount'];
|
149 |
$instance['dataShowScreenName'] = $new_instance['dataShowScreenName'];
|
150 |
$instance['dataLang'] = $new_instance['dataLang'];
|
151 |
-
|
152 |
return $instance;
|
153 |
}
|
154 |
-
|
155 |
function widget($args, $instance){
|
156 |
extract($args, EXTR_SKIP);
|
157 |
|
@@ -218,11 +310,11 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
218 |
$backupName = $transName . '-backup'; // Name of backup value in database.
|
219 |
|
220 |
// Do we already have saved tweet data? If not, lets get it.
|
221 |
-
if(false === ($tweets = get_transient($transName) ) ) :
|
222 |
|
223 |
// Get the tweets from Twitter.
|
224 |
include 'twitteroauth/twitteroauth.php';
|
225 |
-
|
226 |
$connection = new TwitterOAuth(
|
227 |
$consumerKey, // Consumer key
|
228 |
$consumerSecret, // Consumer secret
|
@@ -233,7 +325,7 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
233 |
// If excluding replies, we need to fetch more than requested as the
|
234 |
// total is fetched first, and then replies removed.
|
235 |
$totalToFetch = ($exclude_replies) ? max(50, $numTweets * 3) : $numTweets;
|
236 |
-
|
237 |
$fetchedTweets = $connection->get(
|
238 |
'statuses/user_timeline',
|
239 |
array(
|
@@ -242,20 +334,22 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
242 |
'exclude_replies' => $exclude_replies
|
243 |
)
|
244 |
);
|
245 |
-
|
246 |
// Did the fetch fail?
|
247 |
if($connection->http_code != 200) :
|
248 |
$tweets = get_option($backupName); // False if there has never been data saved.
|
249 |
-
|
250 |
else :
|
251 |
// Fetch succeeded.
|
252 |
// Now update the array to store just what we need.
|
253 |
// (Done here instead of PHP doing this for every page load)
|
254 |
$limitToDisplay = min($numTweets, count($fetchedTweets));
|
255 |
-
|
256 |
for($i = 0; $i < $limitToDisplay; $i++) :
|
257 |
$tweet = $fetchedTweets[$i];
|
258 |
-
|
|
|
|
|
259 |
// Core info.
|
260 |
$name = $tweet->user->name;
|
261 |
|
@@ -267,13 +361,9 @@ class PI_SimpleTwitterTweets extends WP_Widget{
|
|
267 |
/* Alternative image sizes method: http://dev.twitter.com/doc/get/users/profile_image/:screen_name */
|
268 |
$image = $tweet->user->profile_image_url;
|
269 |
|
270 |
-
//
|
271 |
-
$
|
272 |
-
|
273 |
-
$personCheck = preg_replace('/[@]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/$1" target="_blank" rel="nofollow">@$1</a>', $linkCheck );
|
274 |
-
// Clickable Twitter hash tags
|
275 |
-
$text = preg_replace('/[#]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/search?q=%23$1" target="_blank" rel="nofollow">$0</a>', $personCheck );
|
276 |
-
// END TWEET CONTENT REGEX
|
277 |
|
278 |
// Need to get time in Unix format.
|
279 |
$time = $tweet->created_at;
|
4 |
Plugin URI: http://www.planet-interactive.co.uk/simple-twitter-tweets
|
5 |
Description: Display last x number tweets from Twitter API stream, store locally in dataabse to present past tweets when failure to access Twitters restrictive API occurs
|
6 |
Author: Ashley Sheinwald
|
7 |
+
Version: 1.3.3
|
8 |
Author URI: http://www.planet-interactive.co.uk/
|
9 |
*/
|
10 |
|
11 |
/* Copyright 2013 Ashley Sheinwald (email : ashley@planet-interactive.co.uk)
|
12 |
|
13 |
This program is free software; you can redistribute it and/or modify
|
14 |
+
it under the terms of the GNU General Public License, version 2, as
|
15 |
published by the Free Software Foundation.
|
16 |
|
17 |
This program is distributed in the hope that it will be useful,
|
27 |
// USED FOR DEBUG
|
28 |
// include 'console.php';
|
29 |
|
30 |
+
// if(!class_exists('helpers')) {
|
31 |
+
// require 'libs/helpers.php';
|
32 |
+
// }
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
// TODO
|
37 |
+
// HELPER FUNCTIONS - Where and how
|
38 |
+
// Precess Links function for regex
|
39 |
+
// Assess truncated links use
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
class PI_SimpleTwitterTweets extends WP_Widget{
|
44 |
|
45 |
function PI_SimpleTwitterTweets() {
|
46 |
$widget_ops = array('classname' => 'PI_SimpleTwitterTweets', 'description' => 'Displays the most recent tweets from your Twitter Stream' );
|
47 |
+
//$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'Not-required-this-time' );
|
48 |
$this->WP_Widget('PI_SimpleTwitterTweets', 'Simple Twitter Tweets', $widget_ops);
|
49 |
|
50 |
// Load (enqueue) some JS in Admin ONLY on widgets page
|
53 |
|
54 |
// Lets load some JS to aid widget display in Appearance->Widgets
|
55 |
function PI_load_admin_scripts($hook) {
|
56 |
+
if( $hook != 'widgets.php' )
|
57 |
return;
|
58 |
|
59 |
wp_enqueue_script('PI_stt_js', plugins_url( '/simple-twitter-tweets/js/sttAdmin.min.js' , dirname(__FILE__) ), array('jquery'));
|
60 |
}
|
61 |
|
62 |
+
function process_links($tweet) {
|
63 |
+
|
64 |
+
// Is the Tweet a ReTweet - then grab the full text of the original Tweet
|
65 |
+
if(isset($tweet->retweeted_status)) {
|
66 |
+
// Split it so indices count correctly for @mentions etc.
|
67 |
+
$rt_section = current(explode(":", $tweet->text));
|
68 |
+
$text = $rt_section.": ";
|
69 |
+
// Get Text
|
70 |
+
$text .= $tweet->retweeted_status->text;
|
71 |
+
} else {
|
72 |
+
// Not a retweet - get Tweet
|
73 |
+
$text = $tweet->text;
|
74 |
+
}
|
75 |
+
|
76 |
+
/*
|
77 |
+
// GRRRRR Retweet links entity reference for making links
|
78 |
+
// Look into further when get a chance
|
79 |
+
|
80 |
+
// Grab the Tweet entities for URLs etc.
|
81 |
+
$entities = $tweet->entities;
|
82 |
+
|
83 |
+
// STart replacing pertinent content to create required linkages
|
84 |
+
$replacements = array();
|
85 |
+
foreach ($entities->hashtags as $hashtag) {
|
86 |
+
list ($start, $end) = $hashtag->indices;
|
87 |
+
$replacements[$start] = array($start, $end-$start,
|
88 |
+
"<a href=\"https://twitter.com/search?q={$hashtag->text}\" target=\"_blank\">#{$hashtag->text}</a>");
|
89 |
+
}
|
90 |
+
foreach ($entities->urls as $url) {
|
91 |
+
list ($start, $end) = $url->indices;
|
92 |
+
// Was using $url->display_url but is verbose
|
93 |
+
$replacements[$start] = array($start, $end-$start,
|
94 |
+
"<a href=\"{$url->url}\" target=\"_blank\">{$url->url}</a>");
|
95 |
+
}
|
96 |
+
foreach ($entities->user_mentions as $mention) {
|
97 |
+
list ($start, $end) = $mention->indices;
|
98 |
+
$replacements[$start] = array($start, $end-$start,
|
99 |
+
"<a href=\"https://twitter.com/{$mention->screen_name}\" target=\"_blank\">@{$mention->screen_name}</a>");
|
100 |
+
}
|
101 |
+
foreach ($entities->media as $media) {
|
102 |
+
list ($start, $end) = $media->indices;
|
103 |
+
// Was using $media->display_url but is verbose - trying to overcome limits
|
104 |
+
$replacements[$start] = array($start, $end-$start,
|
105 |
+
"<a href=\"{$media->url}\" target=\"_blank\">{$media->url}</a>");
|
106 |
+
}
|
107 |
+
|
108 |
+
// sort in reverse order by start location
|
109 |
+
krsort($replacements);
|
110 |
+
|
111 |
+
foreach ($replacements as $replace_data) {
|
112 |
+
list ($start, $length, $replace_text) = $replace_data;
|
113 |
+
$text = substr_replace($text, $replace_text, $start, $length);
|
114 |
+
}
|
115 |
+
return $text;
|
116 |
+
*/
|
117 |
+
|
118 |
+
// NEW Link Creation from clickable items in the text
|
119 |
+
$text = preg_replace('/((http)+(s)?:\/\/[^<>\s]+)/i', '<a href="$0" target="_blank" rel="nofollow">$0</a>', $text );
|
120 |
+
// Clickable Twitter names
|
121 |
+
$text = preg_replace('/[@]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/$1" target="_blank" rel="nofollow">@$1</a>', $text );
|
122 |
+
// Clickable Twitter hash tags
|
123 |
+
$text = preg_replace('/[#]+([A-Za-z0-9-_]+)/', '<a href="http://twitter.com/search?q=%23$1" target="_blank" rel="nofollow">$0</a>', $text );
|
124 |
+
// END TWEET CONTENT REGEX
|
125 |
+
return $text;
|
126 |
+
|
127 |
+
}
|
128 |
+
// END PROCESS LINKS - Using Entities
|
129 |
+
|
130 |
+
|
131 |
function form($instance){
|
132 |
+
|
133 |
//Set up some default widget settings.
|
134 |
+
$defaults = array(
|
135 |
'title' => __('Recent Tweets', 'pi-tweet')
|
136 |
, 'name' => __('iPlanetUK', 'pi-tweet')
|
137 |
, 'numTweets' => __(4, 'pi-tweet') // How many to display
|
161 |
$dataShowScreenName = $instance['dataShowScreenName'];
|
162 |
$dataLang = $instance['dataLang'];
|
163 |
?>
|
164 |
+
|
165 |
+
<?php
|
166 |
+
// Show error if cURL not installed - extension required for Twitter API calls
|
167 |
+
if (!in_array('curl', get_loaded_extensions())) {
|
168 |
+
echo '<p style="background-color:pink;padding:10px;border:1px solid red;"><strong>You do not have cURL installed! This is a required PHP extension to use the Twitter API: <a href="http://curl.haxx.se/docs/install.html" taget="_blank">cURL install</a></strong></p>';
|
169 |
+
}
|
170 |
+
?>
|
171 |
+
|
172 |
<p>
|
173 |
<label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label>
|
174 |
</p>
|
193 |
<p>
|
194 |
<label for="<?php echo $this->get_field_id('accessTokenSecret'); ?>">Access Token Secret: <input class="widefat" id="<?php echo $this->get_field_id('accessTokenSecret'); ?>" name="<?php echo $this->get_field_name('accessTokenSecret'); ?>" type="text" value="<?php echo esc_attr($accessTokenSecret); ?>" /></label>
|
195 |
</p>
|
196 |
+
<p>
|
197 |
+
<input class="checkbox" type="checkbox" <?php checked( isset( $instance['exclude_replies']), true ); ?> id="<?php echo $this->get_field_id( 'exclude_replies' ); ?>" name="<?php echo $this->get_field_name( 'exclude_replies' ); ?>" />
|
198 |
+
<label for="<?php echo $this->get_field_id( 'exclude_replies' ); ?>"><?php _e('Exclude_@replies', 'pi-tweet'); ?></label>
|
199 |
</p>
|
200 |
+
|
201 |
+
<!-- <p style="text-align:right;"><button class="button-secondary" style="background:red; color:#ffffff; text-shadow:none;" title="Only click if you have changed a setting esp. the number of Tweets to display - this deletes your cache which will be restored the next time your site successfully connects to Twitter!">Delete Cache</button></p> -->
|
202 |
+
|
203 |
<div class="twitterFollow" style="background:#d6eef9;">
|
204 |
<h4 class="button-secondary" style="width:100%; text-align:center;">Twitter Follow Button <span style="font-size:75%;">▼</span></h4>
|
205 |
<div style="padding:10px;">
|
206 |
+
<p>
|
207 |
+
<input class="checkbox" type="checkbox" <?php checked( (isset( $instance['twitterFollow']) && ($instance['twitterFollow'] == "on") ), true ); ?> id="<?php echo $this->get_field_id( 'twitterFollow' ); ?>" name="<?php echo $this->get_field_name( 'twitterFollow' ); ?>" />
|
208 |
+
<label for="<?php echo $this->get_field_id( 'twitterFollow' ); ?>"><?php _e('Show Twitter Follow Button', 'pi-tweet'); ?></label>
|
209 |
+
</p>
|
210 |
+
<p>
|
211 |
+
<input class="checkbox" type="checkbox" <?php checked( (isset( $instance['dataShowScreenName']) && ($instance['dataShowScreenName'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'dataShowScreenName' ); ?>" name="<?php echo $this->get_field_name( 'dataShowScreenName' ); ?>" value="true" />
|
212 |
+
<label for="<?php echo $this->get_field_id( 'dataShowScreenName' ); ?>"><?php _e('Show Twitter Screen Name', 'pi-tweet'); ?></label>
|
213 |
+
</p>
|
214 |
+
<p>
|
215 |
+
<input class="checkbox" type="checkbox" <?php checked( (isset( $instance['dataShowCount']) && ($instance['dataShowCount'] == "true") ), true ); ?> id="<?php echo $this->get_field_id( 'dataShowCount' ); ?>" name="<?php echo $this->get_field_name( 'dataShowCount' ); ?>" value="true" />
|
216 |
+
<label for="<?php echo $this->get_field_id( 'dataShowCount' ); ?>"><?php _e('Show Twitter Followers Count', 'pi-tweet'); ?></label>
|
217 |
+
</p>
|
218 |
+
<p>
|
219 |
+
<label for="<?php echo $this->get_field_id('dataLang'); ?>">Language: <input class="widefat" id="<?php echo $this->get_field_id('dataLang'); ?>" name="<?php echo $this->get_field_name('dataLang'); ?>" type="text" value="<?php echo esc_attr($dataLang); ?>" /></label>
|
220 |
+
</p>
|
221 |
</div>
|
222 |
</div>
|
223 |
<?php
|
225 |
|
226 |
function update($new_instance, $old_instance){
|
227 |
$instance = $old_instance;
|
228 |
+
|
229 |
+
//Strip tags from title and name to remove HTML
|
230 |
+
$instance['title'] = strip_tags( $new_instance['title'] );
|
231 |
+
$instance['name'] = strip_tags( $new_instance['name'] );
|
232 |
$instance['numTweets'] = $new_instance['numTweets'];
|
233 |
$instance['cacheTime'] = $new_instance['cacheTime'];
|
234 |
$instance['consumerKey'] = $new_instance['consumerKey'];
|
240 |
$instance['dataShowCount'] = $new_instance['dataShowCount'];
|
241 |
$instance['dataShowScreenName'] = $new_instance['dataShowScreenName'];
|
242 |
$instance['dataLang'] = $new_instance['dataLang'];
|
243 |
+
|
244 |
return $instance;
|
245 |
}
|
246 |
+
|
247 |
function widget($args, $instance){
|
248 |
extract($args, EXTR_SKIP);
|
249 |
|
310 |
$backupName = $transName . '-backup'; // Name of backup value in database.
|
311 |
|
312 |
// Do we already have saved tweet data? If not, lets get it.
|
313 |
+
if(false === ($tweets = get_transient($transName) ) ) :
|
314 |
|
315 |
// Get the tweets from Twitter.
|
316 |
include 'twitteroauth/twitteroauth.php';
|
317 |
+
|
318 |
$connection = new TwitterOAuth(
|
319 |
$consumerKey, // Consumer key
|
320 |
$consumerSecret, // Consumer secret
|
325 |
// If excluding replies, we need to fetch more than requested as the
|
326 |
// total is fetched first, and then replies removed.
|
327 |
$totalToFetch = ($exclude_replies) ? max(50, $numTweets * 3) : $numTweets;
|
328 |
+
|
329 |
$fetchedTweets = $connection->get(
|
330 |
'statuses/user_timeline',
|
331 |
array(
|
334 |
'exclude_replies' => $exclude_replies
|
335 |
)
|
336 |
);
|
337 |
+
|
338 |
// Did the fetch fail?
|
339 |
if($connection->http_code != 200) :
|
340 |
$tweets = get_option($backupName); // False if there has never been data saved.
|
341 |
+
|
342 |
else :
|
343 |
// Fetch succeeded.
|
344 |
// Now update the array to store just what we need.
|
345 |
// (Done here instead of PHP doing this for every page load)
|
346 |
$limitToDisplay = min($numTweets, count($fetchedTweets));
|
347 |
+
|
348 |
for($i = 0; $i < $limitToDisplay; $i++) :
|
349 |
$tweet = $fetchedTweets[$i];
|
350 |
+
|
351 |
+
|
352 |
+
|
353 |
// Core info.
|
354 |
$name = $tweet->user->name;
|
355 |
|
361 |
/* Alternative image sizes method: http://dev.twitter.com/doc/get/users/profile_image/:screen_name */
|
362 |
$image = $tweet->user->profile_image_url;
|
363 |
|
364 |
+
// Process Tweets - Use Twitter entities for correct URL, hash and mentions
|
365 |
+
$text = $this->process_links($tweet);
|
366 |
+
|
|
|
|
|
|
|
|
|
367 |
|
368 |
// Need to get time in Unix format.
|
369 |
$time = $tweet->created_at;
|