Version Description
- Some styling issues were fixed
- Now the script checks if a function already exists
- Special function naming are applied so function dupes are also prevented
- Exclude replies option has been added
Download this release
Release Info
Developer | ThemePrince |
Plugin | Recent Tweets Widget |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.1
- assets/banner-772x250.png +0 -0
- readme.txt +8 -2
- recent-tweets.php +1 -1
- tp_twitter_plugin.css +6 -4
- widget.php +81 -67
assets/banner-772x250.png
CHANGED
Binary file
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: themeprince
|
|
3 |
Donate link: http://themeprince.com/
|
4 |
Tags: recent tweets, twitter widget, twitter api v1.1, cache
|
5 |
Requires at least: 3.4.1
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -39,6 +39,12 @@ You will need to visit [this link](https://dev.twitter.com/apps/ "Twitter"), sig
|
|
39 |
|
40 |
== Changelog ==
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
= 1.0 =
|
43 |
* The first version of this plugin! Enjoy! :)
|
44 |
|
3 |
Donate link: http://themeprince.com/
|
4 |
Tags: recent tweets, twitter widget, twitter api v1.1, cache
|
5 |
Requires at least: 3.4.1
|
6 |
+
Tested up to: 3.6
|
7 |
+
Stable tag: 1.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
39 |
|
40 |
== Changelog ==
|
41 |
|
42 |
+
= 1.1 =
|
43 |
+
* Some styling issues were fixed
|
44 |
+
* Now the script checks if a function already exists
|
45 |
+
* Special function naming are applied so function dupes are also prevented
|
46 |
+
* Exclude replies option has been added
|
47 |
+
|
48 |
= 1.0 =
|
49 |
* The first version of this plugin! Enjoy! :)
|
50 |
|
recent-tweets.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
Plugin Name: Recent Tweets Widget
|
5 |
Plugin URI: http://wordpress.org/extend/plugins/recent-tweets-widget/
|
6 |
Description: Recent Tweets Widget plugin for Twitter API v1.1 with Cache. It uses the new Twitter API v1.1 and stores tweets in the cache. It means that it will read status messages from your database and it doesn't query Twitter.com for every page load so you won't be rate limited. You can set how often you want to update the cache.
|
7 |
-
Version: 1.
|
8 |
Author: Theme Prince
|
9 |
Author URI: http://themeprince.com
|
10 |
*/
|
4 |
Plugin Name: Recent Tweets Widget
|
5 |
Plugin URI: http://wordpress.org/extend/plugins/recent-tweets-widget/
|
6 |
Description: Recent Tweets Widget plugin for Twitter API v1.1 with Cache. It uses the new Twitter API v1.1 and stores tweets in the cache. It means that it will read status messages from your database and it doesn't query Twitter.com for every page load so you won't be rate limited. You can set how often you want to update the cache.
|
7 |
+
Version: 1.1
|
8 |
Author: Theme Prince
|
9 |
Author URI: http://themeprince.com
|
10 |
*/
|
tp_twitter_plugin.css
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
|
2 |
-
.tp_recent_tweets {
|
3 |
float: left;
|
4 |
clear: left;
|
|
|
5 |
}
|
6 |
|
7 |
-
.tp_recent_tweets li {
|
8 |
background-image: url('assets/tweet.png');
|
9 |
background-repeat: no-repeat;
|
10 |
background-position: 0px 4px;
|
@@ -13,13 +14,14 @@
|
|
13 |
float: left;
|
14 |
clear: left;
|
15 |
line-height: 20px;
|
|
|
16 |
}
|
17 |
|
18 |
-
.tp_recent_tweets li a {
|
19 |
font-weight: bold;
|
20 |
}
|
21 |
|
22 |
-
.tp_recent_tweets .twitter_time {
|
23 |
color: #999;
|
24 |
font-size: 12px;
|
25 |
font-style: italic;
|
1 |
|
2 |
+
.widget .tp_recent_tweets {
|
3 |
float: left;
|
4 |
clear: left;
|
5 |
+
|
6 |
}
|
7 |
|
8 |
+
.widget .tp_recent_tweets li {
|
9 |
background-image: url('assets/tweet.png');
|
10 |
background-repeat: no-repeat;
|
11 |
background-position: 0px 4px;
|
14 |
float: left;
|
15 |
clear: left;
|
16 |
line-height: 20px;
|
17 |
+
list-style-type: none;
|
18 |
}
|
19 |
|
20 |
+
.widget .tp_recent_tweets li a {
|
21 |
font-weight: bold;
|
22 |
}
|
23 |
|
24 |
+
.widget .tp_recent_tweets .twitter_time {
|
25 |
color: #999;
|
26 |
font-size: 12px;
|
27 |
font-style: italic;
|
widget.php
CHANGED
@@ -49,7 +49,7 @@
|
|
49 |
|
50 |
|
51 |
$connection = getConnectionWithAccessToken($instance['consumerkey'], $instance['consumersecret'], $instance['accesstoken'], $instance['accesstokensecret']);
|
52 |
-
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$instance['username']."&count=10") or die('Couldn\'t retrieve tweets! Wrong username?');
|
53 |
|
54 |
|
55 |
if(!empty($tweets->errors)){
|
@@ -77,69 +77,7 @@
|
|
77 |
}
|
78 |
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
//convert links to clickable format
|
87 |
-
function convert_links($status,$targetBlank=true,$linkMaxLen=250){
|
88 |
-
|
89 |
-
// the target
|
90 |
-
$target=$targetBlank ? " target=\"_blank\" " : "";
|
91 |
-
|
92 |
-
// convert link to url
|
93 |
-
$status = preg_replace("/((http:\/\/|https:\/\/)[^ )
|
94 |
-
]+)/e", "'<a href=\"$1\" title=\"$1\" $target >'. ((strlen('$1')>=$linkMaxLen ? substr('$1',0,$linkMaxLen).'...':'$1')).'</a>'", $status);
|
95 |
-
|
96 |
-
// convert @ to follow
|
97 |
-
$status = preg_replace("/(@([_a-z0-9\-]+))/i","<a href=\"http://twitter.com/$2\" title=\"Follow $2\" $target >$1</a>",$status);
|
98 |
-
|
99 |
-
// convert # to search
|
100 |
-
$status = preg_replace("/(#([_a-z0-9\-]+))/i","<a href=\"https://twitter.com/search?q=$2\" title=\"Search $1\" $target >$1</a>",$status);
|
101 |
-
|
102 |
-
// return the status
|
103 |
-
return $status;
|
104 |
-
}
|
105 |
-
|
106 |
-
|
107 |
-
//convert dates to readable format
|
108 |
-
function relative_time($a) {
|
109 |
-
//get current timestampt
|
110 |
-
$b = strtotime("now");
|
111 |
-
//get timestamp when tweet created
|
112 |
-
$c = strtotime($a);
|
113 |
-
//get difference
|
114 |
-
$d = $b - $c;
|
115 |
-
//calculate different time values
|
116 |
-
$minute = 60;
|
117 |
-
$hour = $minute * 60;
|
118 |
-
$day = $hour * 24;
|
119 |
-
$week = $day * 7;
|
120 |
-
|
121 |
-
if(is_numeric($d) && $d > 0) {
|
122 |
-
//if less then 3 seconds
|
123 |
-
if($d < 3) return "right now";
|
124 |
-
//if less then minute
|
125 |
-
if($d < $minute) return floor($d) . " seconds ago";
|
126 |
-
//if less then 2 minutes
|
127 |
-
if($d < $minute * 2) return "about 1 minute ago";
|
128 |
-
//if less then hour
|
129 |
-
if($d < $hour) return floor($d / $minute) . " minutes ago";
|
130 |
-
//if less then 2 hours
|
131 |
-
if($d < $hour * 2) return "about 1 hour ago";
|
132 |
-
//if less then day
|
133 |
-
if($d < $day) return floor($d / $hour) . " hours ago";
|
134 |
-
//if more then day, but less then 2 days
|
135 |
-
if($d > $day && $d < $day * 2) return "yesterday";
|
136 |
-
//if less then year
|
137 |
-
if($d < $day * 365) return floor($d / $day) . " days ago";
|
138 |
-
//else return more than a year
|
139 |
-
return "over a year ago";
|
140 |
-
}
|
141 |
-
}
|
142 |
-
|
143 |
|
144 |
$tp_twitter_plugin_tweets = maybe_unserialize(get_option('tp_twitter_plugin_tweets'));
|
145 |
if(!empty($tp_twitter_plugin_tweets)){
|
@@ -148,7 +86,7 @@
|
|
148 |
<ul>';
|
149 |
$fctr = '1';
|
150 |
foreach($tp_twitter_plugin_tweets as $tweet){
|
151 |
-
print '<li><span>'.
|
152 |
if($fctr == $instance['tweetstoshow']){ break; }
|
153 |
$fctr++;
|
154 |
}
|
@@ -175,6 +113,7 @@
|
|
175 |
$instance['cachetime'] = strip_tags( $new_instance['cachetime'] );
|
176 |
$instance['username'] = strip_tags( $new_instance['username'] );
|
177 |
$instance['tweetstoshow'] = strip_tags( $new_instance['tweetstoshow'] );
|
|
|
178 |
|
179 |
if($old_instance['username'] != $new_instance['username']){
|
180 |
delete_option('tp_twitter_plugin_last_cache_time');
|
@@ -211,15 +150,90 @@
|
|
211 |
echo '<option value="'.$i.'"'; if($instance['tweetstoshow'] == $i){ echo ' selected="selected"'; } echo '>'.$i.'</option>';
|
212 |
}
|
213 |
echo '
|
214 |
-
</select></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
}
|
216 |
}
|
217 |
|
218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
// register widget
|
220 |
function register_tp_twitter_widget(){
|
221 |
register_widget('tp_widget_recent_tweets');
|
222 |
}
|
223 |
add_action('init', 'register_tp_twitter_widget', 1)
|
|
|
|
|
224 |
|
225 |
-
?>
|
|
49 |
|
50 |
|
51 |
$connection = getConnectionWithAccessToken($instance['consumerkey'], $instance['consumersecret'], $instance['accesstoken'], $instance['accesstokensecret']);
|
52 |
+
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$instance['username']."&count=10&exclude_replies=".$instance['excludereplies']) or die('Couldn\'t retrieve tweets! Wrong username?');
|
53 |
|
54 |
|
55 |
if(!empty($tweets->errors)){
|
77 |
}
|
78 |
|
79 |
|
80 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
$tp_twitter_plugin_tweets = maybe_unserialize(get_option('tp_twitter_plugin_tweets'));
|
83 |
if(!empty($tp_twitter_plugin_tweets)){
|
86 |
<ul>';
|
87 |
$fctr = '1';
|
88 |
foreach($tp_twitter_plugin_tweets as $tweet){
|
89 |
+
print '<li><span>'.tp_convert_links($tweet['text']).'</span><br /><a class="twitter_time" target="_blank" href="http://twitter.com/'.$instance['username'].'/statuses/'.$tweet['status_id'].'">'.tp_relative_time($tweet['created_at']).'</a></li>';
|
90 |
if($fctr == $instance['tweetstoshow']){ break; }
|
91 |
$fctr++;
|
92 |
}
|
113 |
$instance['cachetime'] = strip_tags( $new_instance['cachetime'] );
|
114 |
$instance['username'] = strip_tags( $new_instance['username'] );
|
115 |
$instance['tweetstoshow'] = strip_tags( $new_instance['tweetstoshow'] );
|
116 |
+
$instance['excludereplies'] = strip_tags( $new_instance['excludereplies'] );
|
117 |
|
118 |
if($old_instance['username'] != $new_instance['username']){
|
119 |
delete_option('tp_twitter_plugin_last_cache_time');
|
150 |
echo '<option value="'.$i.'"'; if($instance['tweetstoshow'] == $i){ echo ' selected="selected"'; } echo '>'.$i.'</option>';
|
151 |
}
|
152 |
echo '
|
153 |
+
</select></p>
|
154 |
+
<p><label>Exclude replies:</label>
|
155 |
+
<input type="checkbox" name="'.$this->get_field_name( 'excludereplies' ).'" id="'.$this->get_field_id( 'excludereplies' ).'" value="true"';
|
156 |
+
if(esc_attr($instance['excludereplies']) == 'true'){
|
157 |
+
print ' checked="checked"';
|
158 |
+
}
|
159 |
+
print ' /></p>';
|
160 |
}
|
161 |
}
|
162 |
|
163 |
|
164 |
+
|
165 |
+
|
166 |
+
|
167 |
+
//convert links to clickable format
|
168 |
+
if (!function_exists('tp_convert_links')) {
|
169 |
+
function tp_convert_links($status,$targetBlank=true,$linkMaxLen=250){
|
170 |
+
|
171 |
+
// the target
|
172 |
+
$target=$targetBlank ? " target=\"_blank\" " : "";
|
173 |
+
|
174 |
+
// convert link to url
|
175 |
+
$status = preg_replace("/((http:\/\/|https:\/\/)[^ )
|
176 |
+
]+)/e", "'<a href=\"$1\" title=\"$1\" $target >'. ((strlen('$1')>=$linkMaxLen ? substr('$1',0,$linkMaxLen).'...':'$1')).'</a>'", $status);
|
177 |
+
|
178 |
+
// convert @ to follow
|
179 |
+
$status = preg_replace("/(@([_a-z0-9\-]+))/i","<a href=\"http://twitter.com/$2\" title=\"Follow $2\" $target >$1</a>",$status);
|
180 |
+
|
181 |
+
// convert # to search
|
182 |
+
$status = preg_replace("/(#([_a-z0-9\-]+))/i","<a href=\"https://twitter.com/search?q=$2\" title=\"Search $1\" $target >$1</a>",$status);
|
183 |
+
|
184 |
+
// return the status
|
185 |
+
return $status;
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
|
190 |
+
//convert dates to readable format
|
191 |
+
if (!function_exists('tp_relative_time')) {
|
192 |
+
function tp_relative_time($a) {
|
193 |
+
//get current timestampt
|
194 |
+
$b = strtotime("now");
|
195 |
+
//get timestamp when tweet created
|
196 |
+
$c = strtotime($a);
|
197 |
+
//get difference
|
198 |
+
$d = $b - $c;
|
199 |
+
//calculate different time values
|
200 |
+
$minute = 60;
|
201 |
+
$hour = $minute * 60;
|
202 |
+
$day = $hour * 24;
|
203 |
+
$week = $day * 7;
|
204 |
+
|
205 |
+
if(is_numeric($d) && $d > 0) {
|
206 |
+
//if less then 3 seconds
|
207 |
+
if($d < 3) return "right now";
|
208 |
+
//if less then minute
|
209 |
+
if($d < $minute) return floor($d) . " seconds ago";
|
210 |
+
//if less then 2 minutes
|
211 |
+
if($d < $minute * 2) return "about 1 minute ago";
|
212 |
+
//if less then hour
|
213 |
+
if($d < $hour) return floor($d / $minute) . " minutes ago";
|
214 |
+
//if less then 2 hours
|
215 |
+
if($d < $hour * 2) return "about 1 hour ago";
|
216 |
+
//if less then day
|
217 |
+
if($d < $day) return floor($d / $hour) . " hours ago";
|
218 |
+
//if more then day, but less then 2 days
|
219 |
+
if($d > $day && $d < $day * 2) return "yesterday";
|
220 |
+
//if less then year
|
221 |
+
if($d < $day * 365) return floor($d / $day) . " days ago";
|
222 |
+
//else return more than a year
|
223 |
+
return "over a year ago";
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
|
229 |
+
|
230 |
// register widget
|
231 |
function register_tp_twitter_widget(){
|
232 |
register_widget('tp_widget_recent_tweets');
|
233 |
}
|
234 |
add_action('init', 'register_tp_twitter_widget', 1)
|
235 |
+
|
236 |
+
|
237 |
|
238 |
+
?>
|
239 |
+
|