Version Description
Download this release
Release Info
Developer | aaroncampbell |
Plugin | Twitter Widget Pro |
Version | 1.3.0 |
Comparing to | |
See all releases |
Code changes from version 1.2.2 to 1.3.0
- readme.txt +10 -3
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- screenshot-4.png +0 -0
- wp-twitter-widget.php +53 -77
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
Contributors: aaroncampbell
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%40xavisys%2ecom&item_name=Twitter%20Widget%20Pro&no_shipping=0&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8
|
4 |
Tags: twitter, widget, feed
|
5 |
-
Requires at least: 2.
|
6 |
-
Tested up to: 2.
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
A widget that properly handles twitter feeds, including parsing @username and URLs into links. Requires PHP5.
|
10 |
|
@@ -34,3 +34,10 @@ Absolutely, each instance of the widget can have different settings and track di
|
|
34 |
= Why can't I display a friends feed anymore? =
|
35 |
|
36 |
Aparently the database queries required to display the friends feed was causing twitter to crash, so they removed it. Unfortunately, this is outside my control.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
Contributors: aaroncampbell
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%40xavisys%2ecom&item_name=Twitter%20Widget%20Pro&no_shipping=0&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8
|
4 |
Tags: twitter, widget, feed
|
5 |
+
Requires at least: 2.7
|
6 |
+
Tested up to: 2.7.1
|
7 |
+
Stable tag: 1.3.0
|
8 |
|
9 |
A widget that properly handles twitter feeds, including parsing @username and URLs into links. Requires PHP5.
|
10 |
|
34 |
= Why can't I display a friends feed anymore? =
|
35 |
|
36 |
Aparently the database queries required to display the friends feed was causing twitter to crash, so they removed it. Unfortunately, this is outside my control.
|
37 |
+
|
38 |
+
== Screenshots ==
|
39 |
+
|
40 |
+
1. To user the widget, go to Appearance -> Widgets and choose to "Add" the "Twitter Feed" widget.
|
41 |
+
2. Each widget has settings that need to be set, so the next step is to click "edit" on the newly added widget and adjust all the settings. When you're done click "Save Changes"
|
42 |
+
3. This is what the widget looks like in the default theme with no added styles.
|
43 |
+
4. By using some (X)HTML in the title element and adding a few styles and a background image, you could make it look like this.
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|
screenshot-3.png
ADDED
Binary file
|
screenshot-4.png
ADDED
Binary file
|
wp-twitter-widget.php
CHANGED
@@ -3,15 +3,20 @@
|
|
3 |
* Plugin Name: Twitter Widget Pro
|
4 |
* Plugin URI: http://xavisys.com/wordpress-twitter-widget/
|
5 |
* Description: A widget that properly handles twitter feeds, including @username and link parsing, and can even display profile images for the users. Requires PHP5.
|
6 |
-
* Version: 1.
|
7 |
* Author: Aaron D. Campbell
|
8 |
* Author URI: http://xavisys.com/
|
9 |
*/
|
10 |
|
11 |
-
define('TWP_VERSION', '1.
|
12 |
|
13 |
/**
|
14 |
* Changelog:
|
|
|
|
|
|
|
|
|
|
|
15 |
* 06/09/2008: 1.2.2
|
16 |
* - Fixed minor issue with Zend JSON Decoder
|
17 |
* - Added an option for Twitter timeout. 2 seconds wasn't enough for some people
|
@@ -90,37 +95,14 @@ class wpTwitterWidgetException extends Exception {}
|
|
90 |
class wpTwitterWidget
|
91 |
{
|
92 |
/**
|
93 |
-
*
|
94 |
-
*
|
95 |
-
* @var string
|
96 |
*/
|
97 |
-
private $
|
98 |
|
99 |
-
|
100 |
-
* Read timeout to use when fetching the feeds. Defaults to 2 seconds.
|
101 |
-
*
|
102 |
-
* @todo make a set function for this
|
103 |
-
*
|
104 |
-
* @var int
|
105 |
-
*/
|
106 |
-
private $fetchTimeOut = 2;
|
107 |
-
|
108 |
-
/**
|
109 |
-
* Whether to use GZip when fetching feeds. Defaults to true
|
110 |
-
*
|
111 |
-
* @todo make a set function for this
|
112 |
-
*
|
113 |
-
* @var bool
|
114 |
-
*/
|
115 |
-
private $useGzip = true;
|
116 |
-
|
117 |
-
public function __construct() {
|
118 |
-
// Set the user agent to Wordpress/x.x.x
|
119 |
-
$this->userAgent = 'WordPress/' . $GLOBALS['wp_version'];
|
120 |
-
}
|
121 |
|
122 |
function admin_menu() {
|
123 |
-
add_options_page(__('Twitter Widget Pro'), __('Twitter Widget Pro'), 'manage_options',
|
124 |
}
|
125 |
/**
|
126 |
* This is used to display the options page for this plugin
|
@@ -167,13 +149,14 @@ class wpTwitterWidget
|
|
167 |
*/
|
168 |
private function _parseFeed($widgetOptions) {
|
169 |
$feedUrl = $this->_getFeedUrl($widgetOptions);
|
170 |
-
$resp =
|
171 |
-
|
|
|
172 |
if (function_exists('json_decode')) {
|
173 |
-
return json_decode($resp
|
174 |
} else {
|
175 |
require_once('json_decode.php');
|
176 |
-
return Zend_Json_Decoder::decode($resp
|
177 |
}
|
178 |
} else {
|
179 |
// Failed to fetch url;
|
@@ -196,11 +179,7 @@ class wpTwitterWidget
|
|
196 |
if (!in_array($type, array('rss', 'json'))) {
|
197 |
$type = 'json';
|
198 |
}
|
199 |
-
|
200 |
-
$count = sprintf('?count=%u', $widgetOptions['items']);
|
201 |
-
} else {
|
202 |
-
$count = '';
|
203 |
-
}
|
204 |
return sprintf('http://twitter.com/statuses/user_timeline/%1$s.%2$s%3$s', $widgetOptions['username'], $type, $count);
|
205 |
}
|
206 |
|
@@ -245,29 +224,6 @@ class wpTwitterWidget
|
|
245 |
return $text;
|
246 |
}
|
247 |
|
248 |
-
/**
|
249 |
-
* Uses snoopy class to pull file contents
|
250 |
-
*
|
251 |
-
* @param string $url - Url to get
|
252 |
-
* @param array $headers - Raw headers to pass
|
253 |
-
* @return Snoopy
|
254 |
-
*/
|
255 |
-
private function _fetch_remote_file ($url, $timeout = 2, $headers = "" ) {
|
256 |
-
$timeout = (!empty($timeout))? (int) $timeout : 2;
|
257 |
-
require_once( ABSPATH . 'wp-includes/class-snoopy.php' );
|
258 |
-
// Snoopy is an HTTP client in PHP
|
259 |
-
$client = new Snoopy();
|
260 |
-
$client->agent = $this->userAgent;
|
261 |
-
$client->read_timeout = $timeout;
|
262 |
-
$client->use_gzip = $this->useGzip;
|
263 |
-
if (is_array($headers) ) {
|
264 |
-
$client->rawheaders = $headers;
|
265 |
-
}
|
266 |
-
|
267 |
-
@$client->fetch($url);
|
268 |
-
return $client;
|
269 |
-
}
|
270 |
-
|
271 |
/**
|
272 |
* Gets tweets, from cache if possible
|
273 |
*
|
@@ -275,14 +231,15 @@ class wpTwitterWidget
|
|
275 |
* @return array - Array of objects
|
276 |
*/
|
277 |
private function _getTweets($widgetOptions) {
|
278 |
-
|
279 |
-
$tweets =
|
280 |
-
|
281 |
-
|
|
|
282 |
try {
|
283 |
$tweets = $this->_parseFeed($widgetOptions);
|
284 |
-
|
285 |
-
|
286 |
} catch (wpTwitterWidgetException $e) {
|
287 |
throw $e;
|
288 |
}
|
@@ -329,7 +286,7 @@ class wpTwitterWidget
|
|
329 |
$tweets = $e;
|
330 |
}
|
331 |
|
332 |
-
echo $before_widget;
|
333 |
|
334 |
// If "hide rss" hasn't been checked, show the linked icon
|
335 |
if (!$options[$number]['hiderss']) {
|
@@ -381,7 +338,7 @@ class wpTwitterWidget
|
|
381 |
} ?></ul>
|
382 |
<?php
|
383 |
}
|
384 |
-
echo $after_widget;
|
385 |
}
|
386 |
|
387 |
/**
|
@@ -464,8 +421,12 @@ profileImage;
|
|
464 |
foreach ( (array) $_POST['widget-twitter'] as $widget_number => $widget_twitter ) {
|
465 |
if ( !isset($widget_twitter['username']) && isset($options[$widget_number]) ) // user clicked cancel
|
466 |
continue;
|
467 |
-
$widget_twitter['title'] =
|
468 |
-
$widget_twitter['errmsg'] =
|
|
|
|
|
|
|
|
|
469 |
$options[$widget_number] = $widget_twitter;
|
470 |
}
|
471 |
|
@@ -690,6 +651,20 @@ profileImage;
|
|
690 |
|
691 |
return $s;
|
692 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
693 |
}
|
694 |
// Instantiate our class
|
695 |
$wpTwitterWidget = new wpTwitterWidget();
|
@@ -697,9 +672,10 @@ $wpTwitterWidget = new wpTwitterWidget();
|
|
697 |
/**
|
698 |
* Add filters and actions
|
699 |
*/
|
700 |
-
add_action('admin_menu', array($wpTwitterWidget,'admin_menu'));
|
701 |
-
add_action('widgets_init', array($wpTwitterWidget, 'register'));
|
702 |
-
add_filter('widget_twitter_content', array($wpTwitterWidget, 'linkTwitterUsers'));
|
703 |
-
add_filter('widget_twitter_content', array($wpTwitterWidget, 'linkUrls'));
|
704 |
-
add_action('activate_twitter-widget-pro/wp-twitter-widget.php', array($wpTwitterWidget, 'activatePlugin'));
|
705 |
-
add_action('admin_footer', array($wpTwitterWidget, 'outputSendInfoForm'));
|
|
3 |
* Plugin Name: Twitter Widget Pro
|
4 |
* Plugin URI: http://xavisys.com/wordpress-twitter-widget/
|
5 |
* Description: A widget that properly handles twitter feeds, including @username and link parsing, and can even display profile images for the users. Requires PHP5.
|
6 |
+
* Version: 1.3.0
|
7 |
* Author: Aaron D. Campbell
|
8 |
* Author URI: http://xavisys.com/
|
9 |
*/
|
10 |
|
11 |
+
define('TWP_VERSION', '1.3.0');
|
12 |
|
13 |
/**
|
14 |
* Changelog:
|
15 |
+
* 04/10/2009: 1.3.0
|
16 |
+
* - Updated to use HTTP class and phased out Snoopy
|
17 |
+
* - No longer relies on user having a caching solution in place. Caches for 5 minutes using blog options
|
18 |
+
* - Allow HTML in title and error message if user can
|
19 |
+
*
|
20 |
* 06/09/2008: 1.2.2
|
21 |
* - Fixed minor issue with Zend JSON Decoder
|
22 |
* - Added an option for Twitter timeout. 2 seconds wasn't enough for some people
|
95 |
class wpTwitterWidget
|
96 |
{
|
97 |
/**
|
98 |
+
* @var string Stores the plugin file to test against on plugins page
|
|
|
|
|
99 |
*/
|
100 |
+
private $_pluginBasename;
|
101 |
|
102 |
+
public function __construct() {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
function admin_menu() {
|
105 |
+
add_options_page(__('Twitter Widget Pro'), __('Twitter Widget Pro'), 'manage_options', 'TwitterWidgetPro', array($this, 'options'));
|
106 |
}
|
107 |
/**
|
108 |
* This is used to display the options page for this plugin
|
149 |
*/
|
150 |
private function _parseFeed($widgetOptions) {
|
151 |
$feedUrl = $this->_getFeedUrl($widgetOptions);
|
152 |
+
$resp = wp_remote_request($feedUrl, array('timeout' => $widgetOptions['fetchTimeOut']));
|
153 |
+
|
154 |
+
if ( $resp['response']['code'] >= 200 && $resp['response']['code'] < 300 ) {
|
155 |
if (function_exists('json_decode')) {
|
156 |
+
return json_decode($resp['body']);
|
157 |
} else {
|
158 |
require_once('json_decode.php');
|
159 |
+
return Zend_Json_Decoder::decode($resp['body']);
|
160 |
}
|
161 |
} else {
|
162 |
// Failed to fetch url;
|
179 |
if (!in_array($type, array('rss', 'json'))) {
|
180 |
$type = 'json';
|
181 |
}
|
182 |
+
$count = ($count)? sprintf('?count=%u', $widgetOptions['items']) : '';
|
|
|
|
|
|
|
|
|
183 |
return sprintf('http://twitter.com/statuses/user_timeline/%1$s.%2$s%3$s', $widgetOptions['username'], $type, $count);
|
184 |
}
|
185 |
|
224 |
return $text;
|
225 |
}
|
226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
/**
|
228 |
* Gets tweets, from cache if possible
|
229 |
*
|
231 |
* @return array - Array of objects
|
232 |
*/
|
233 |
private function _getTweets($widgetOptions) {
|
234 |
+
$feedHash = sha1($this->_getFeedUrl($widgetOptions));
|
235 |
+
$tweets = get_option("wptw-{$feedHash}");
|
236 |
+
$cacheAge = get_option("wptw-{$feedHash}-time");
|
237 |
+
//If we don't have cache or it's more than 5 minutes old
|
238 |
+
if ( empty($tweets) || (time() - $cacheAge) > 300 ) {
|
239 |
try {
|
240 |
$tweets = $this->_parseFeed($widgetOptions);
|
241 |
+
update_option("wptw-{$feedHash}", $tweets);
|
242 |
+
update_option("wptw-{$feedHash}-time", time());
|
243 |
} catch (wpTwitterWidgetException $e) {
|
244 |
throw $e;
|
245 |
}
|
286 |
$tweets = $e;
|
287 |
}
|
288 |
|
289 |
+
echo $before_widget . '<div>';
|
290 |
|
291 |
// If "hide rss" hasn't been checked, show the linked icon
|
292 |
if (!$options[$number]['hiderss']) {
|
338 |
} ?></ul>
|
339 |
<?php
|
340 |
}
|
341 |
+
echo '</div>' . $after_widget;
|
342 |
}
|
343 |
|
344 |
/**
|
421 |
foreach ( (array) $_POST['widget-twitter'] as $widget_number => $widget_twitter ) {
|
422 |
if ( !isset($widget_twitter['username']) && isset($options[$widget_number]) ) // user clicked cancel
|
423 |
continue;
|
424 |
+
$widget_twitter['title'] = stripslashes($widget_twitter['title']);
|
425 |
+
$widget_twitter['errmsg'] = stripslashes($widget_twitter['errmsg']);
|
426 |
+
if ( !current_user_can('unfiltered_html') ) {
|
427 |
+
$widget_twitter['title'] = strip_tags($widget_twitter['title']);
|
428 |
+
$widget_twitter['errmsg'] = strip_tags($widget_twitter['errmsg']);
|
429 |
+
}
|
430 |
$options[$widget_number] = $widget_twitter;
|
431 |
}
|
432 |
|
651 |
|
652 |
return $s;
|
653 |
}
|
654 |
+
|
655 |
+
public function addSettingLink( $links, $file ){
|
656 |
+
if ( empty($this->_pluginBasename) ) {
|
657 |
+
$this->_pluginBasename = plugin_basename(__FILE__);
|
658 |
+
}
|
659 |
+
|
660 |
+
if ( $file == $this->_pluginBasename ) {
|
661 |
+
// Add settings link to our plugin
|
662 |
+
$link = '<a href="options-general.php?page=TwitterWidgetPro">' . __('Settings') . '</a>';
|
663 |
+
array_unshift( $links, $link );
|
664 |
+
}
|
665 |
+
return $links;
|
666 |
+
}
|
667 |
+
|
668 |
}
|
669 |
// Instantiate our class
|
670 |
$wpTwitterWidget = new wpTwitterWidget();
|
672 |
/**
|
673 |
* Add filters and actions
|
674 |
*/
|
675 |
+
add_action( 'admin_menu', array($wpTwitterWidget,'admin_menu') );
|
676 |
+
add_action( 'widgets_init', array($wpTwitterWidget, 'register') );
|
677 |
+
add_filter( 'widget_twitter_content', array($wpTwitterWidget, 'linkTwitterUsers') );
|
678 |
+
add_filter( 'widget_twitter_content', array($wpTwitterWidget, 'linkUrls') );
|
679 |
+
add_action( 'activate_twitter-widget-pro/wp-twitter-widget.php', array($wpTwitterWidget, 'activatePlugin') );
|
680 |
+
add_action( 'admin_footer', array($wpTwitterWidget, 'outputSendInfoForm') );
|
681 |
+
add_filter( 'plugin_action_links', array($wpTwitterWidget, 'addSettingLink'), 10, 2 );
|