Twitter Widget Pro - Version 2.1.0

Version Description

  • Added a shortcode to allow you to embed a widget in any post or page
Download this release

Release Info

Developer aaroncampbell
Plugin Icon wp plugin Twitter Widget Pro
Version 2.1.0
Comparing to
See all releases

Code changes from version 2.0.5 to 2.1.0

Files changed (4) hide show
  1. languages/twitter-widget-pro.pot +20 -20
  2. readme.txt +36 -5
  3. upgrade.html +1 -4
  4. wp-twitter-widget.php +254 -173
languages/twitter-widget-pro.pot CHANGED
@@ -7,7 +7,7 @@ msgid ""
7
  msgstr ""
8
  "Project-Id-Version: PACKAGE VERSION\n"
9
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/twitter-widget-pro\n"
10
- "POT-Creation-Date: 2009-10-28 17:58+0000\n"
11
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -108,92 +108,92 @@ msgstr ""
108
  msgid "Show Link to Twitter Widget Pro"
109
  msgstr ""
110
 
111
- #: wp-twitter-widget.php:176
 
 
 
 
112
  msgid "Syndicate this content"
113
  msgstr ""
114
 
115
- #: wp-twitter-widget.php:194
116
  msgid "No Tweets Available"
117
  msgstr ""
118
 
119
- #: wp-twitter-widget.php:211
120
  #, php-format
121
  msgid "from %s"
122
  msgstr ""
123
 
124
- #: wp-twitter-widget.php:215
125
  #, php-format
126
  msgid "in reply to %s"
127
  msgstr ""
128
 
129
- #: wp-twitter-widget.php:239
130
  #, php-format
131
  msgid ""
132
  "Powered by <a href=\"%s\" title=\"Get Twitter Widget for your WordPress site"
133
  "\">WordPress Twitter Widget Pro</a>"
134
  msgstr ""
135
 
136
- #: wp-twitter-widget.php:295
137
  msgid "Invalid Twitter Response."
138
  msgstr ""
139
 
140
- #: wp-twitter-widget.php:309
141
  msgid "Could not connect to Twitter"
142
  msgstr ""
143
 
144
- #: wp-twitter-widget.php:361
145
  msgid "h:i:s A F d, Y"
146
  msgstr ""
147
 
148
- #: wp-twitter-widget.php:372
149
  #, php-format
150
  msgid "about %s year ago"
151
  msgid_plural "about %s years ago"
152
  msgstr[0] ""
153
  msgstr[1] ""
154
 
155
- #: wp-twitter-widget.php:373
156
  #, php-format
157
  msgid "about %s month ago"
158
  msgid_plural "about %s months ago"
159
  msgstr[0] ""
160
  msgstr[1] ""
161
 
162
- #: wp-twitter-widget.php:374
163
  #, php-format
164
  msgid "about %s week ago"
165
  msgid_plural "about %s weeks ago"
166
  msgstr[0] ""
167
  msgstr[1] ""
168
 
169
- #: wp-twitter-widget.php:375
170
  #, php-format
171
  msgid "about %s day ago"
172
  msgid_plural "about %s days ago"
173
  msgstr[0] ""
174
  msgstr[1] ""
175
 
176
- #: wp-twitter-widget.php:376
177
  #, php-format
178
  msgid "about %s hour ago"
179
  msgid_plural "about %s hours ago"
180
  msgstr[0] ""
181
  msgstr[1] ""
182
 
183
- #: wp-twitter-widget.php:377
184
  #, php-format
185
  msgid "about %s minute ago"
186
  msgid_plural "about %s minutes ago"
187
  msgstr[0] ""
188
  msgstr[1] ""
189
 
190
- #: wp-twitter-widget.php:378
191
  #, php-format
192
  msgid "about %s second ago"
193
  msgid_plural "about %s seconds ago"
194
  msgstr[0] ""
195
  msgstr[1] ""
196
-
197
- #: wp-twitter-widget.php:465
198
- msgid "Manage Widgets"
199
- msgstr ""
7
  msgstr ""
8
  "Project-Id-Version: PACKAGE VERSION\n"
9
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/twitter-widget-pro\n"
10
+ "POT-Creation-Date: 2009-11-11 22:34+0000\n"
11
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
108
  msgid "Show Link to Twitter Widget Pro"
109
  msgstr ""
110
 
111
+ #: wp-twitter-widget.php:241
112
+ msgid "Manage Widgets"
113
+ msgstr ""
114
+
115
+ #: wp-twitter-widget.php:343
116
  msgid "Syndicate this content"
117
  msgstr ""
118
 
119
+ #: wp-twitter-widget.php:361
120
  msgid "No Tweets Available"
121
  msgstr ""
122
 
123
+ #: wp-twitter-widget.php:369
124
  #, php-format
125
  msgid "from %s"
126
  msgstr ""
127
 
128
+ #: wp-twitter-widget.php:384
129
  #, php-format
130
  msgid "in reply to %s"
131
  msgstr ""
132
 
133
+ #: wp-twitter-widget.php:406
134
  #, php-format
135
  msgid ""
136
  "Powered by <a href=\"%s\" title=\"Get Twitter Widget for your WordPress site"
137
  "\">WordPress Twitter Widget Pro</a>"
138
  msgstr ""
139
 
140
+ #: wp-twitter-widget.php:467
141
  msgid "Invalid Twitter Response."
142
  msgstr ""
143
 
144
+ #: wp-twitter-widget.php:481
145
  msgid "Could not connect to Twitter"
146
  msgstr ""
147
 
148
+ #: wp-twitter-widget.php:533
149
  msgid "h:i:s A F d, Y"
150
  msgstr ""
151
 
152
+ #: wp-twitter-widget.php:544
153
  #, php-format
154
  msgid "about %s year ago"
155
  msgid_plural "about %s years ago"
156
  msgstr[0] ""
157
  msgstr[1] ""
158
 
159
+ #: wp-twitter-widget.php:545
160
  #, php-format
161
  msgid "about %s month ago"
162
  msgid_plural "about %s months ago"
163
  msgstr[0] ""
164
  msgstr[1] ""
165
 
166
+ #: wp-twitter-widget.php:546
167
  #, php-format
168
  msgid "about %s week ago"
169
  msgid_plural "about %s weeks ago"
170
  msgstr[0] ""
171
  msgstr[1] ""
172
 
173
+ #: wp-twitter-widget.php:547
174
  #, php-format
175
  msgid "about %s day ago"
176
  msgid_plural "about %s days ago"
177
  msgstr[0] ""
178
  msgstr[1] ""
179
 
180
+ #: wp-twitter-widget.php:548
181
  #, php-format
182
  msgid "about %s hour ago"
183
  msgid_plural "about %s hours ago"
184
  msgstr[0] ""
185
  msgstr[1] ""
186
 
187
+ #: wp-twitter-widget.php:549
188
  #, php-format
189
  msgid "about %s minute ago"
190
  msgid_plural "about %s minutes ago"
191
  msgstr[0] ""
192
  msgstr[1] ""
193
 
194
+ #: wp-twitter-widget.php:550
195
  #, php-format
196
  msgid "about %s second ago"
197
  msgid_plural "about %s seconds ago"
198
  msgstr[0] ""
199
  msgstr[1] ""
 
 
 
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%4
4
  Tags: twitter, widget, feed
5
  Requires at least: 2.8
6
  Tested up to: 2.9
7
- Stable tag: 2.0.5
8
 
9
  A widget that properly handles twitter feeds, including parsing @username, #hashtags, and URLs into links. Requires PHP5.
10
 
@@ -33,14 +33,42 @@ Yes, Twitter Widget Pro employs the multi-widget pattern, which allows you to no
33
 
34
  Absolutely, each instance of the widget can have different settings and track different feeds.
35
 
36
- = Why can't I display a friends feed anymore? =
37
-
38
- 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.
39
-
40
  = I get an error similar to "Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /.../wp-twitter-widget.php on line ##" when I try to activate the plugin. Is your plugin broke? =
41
 
42
  No. This error occurs because the plugin requires PHP 5 and you're running PHP 4. Most hosts offer PHP5 but sometimes you have to enable it in your control panel, through .htaccess, or by asking them. There may be instructions for your specific host in the <a href="http://codex.wordpress.org/Switching_to_PHP5">Switching to PHP5</a> article in the codex.
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  == Screenshots ==
45
 
46
  1. To use the widget, go to Appearance -> Widgets and Add "Twitter Widget Pro" widget.
@@ -50,6 +78,9 @@ No. This error occurs because the plugin requires PHP 5 and you're running PHP
50
 
51
  == Changelog ==
52
 
 
 
 
53
  = 2.0.5 =
54
  * Remove the settings link from the plugin line on the plugins page
55
  * Add a link to manage widgets to the plugin line on the plugins page
4
  Tags: twitter, widget, feed
5
  Requires at least: 2.8
6
  Tested up to: 2.9
7
+ Stable tag: 2.1.0
8
 
9
  A widget that properly handles twitter feeds, including parsing @username, #hashtags, and URLs into links. Requires PHP5.
10
 
33
 
34
  Absolutely, each instance of the widget can have different settings and track different feeds.
35
 
 
 
 
 
36
  = I get an error similar to "Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /.../wp-twitter-widget.php on line ##" when I try to activate the plugin. Is your plugin broke? =
37
 
38
  No. This error occurs because the plugin requires PHP 5 and you're running PHP 4. Most hosts offer PHP5 but sometimes you have to enable it in your control panel, through .htaccess, or by asking them. There may be instructions for your specific host in the <a href="http://codex.wordpress.org/Switching_to_PHP5">Switching to PHP5</a> article in the codex.
39
 
40
+ = How can I add this widget to a post or page? =
41
+
42
+ You can now use the twitter-widget shortcode to embed this widget into a post or
43
+ page. The simplest form of this would be `[twitter-widget username="yourTwitterUsername"]`
44
+
45
+ = How exactly do you use the twitter-widget shortcode? =
46
+ The simplest form of this would be `[twitter-widget username="yourTwitterUsername"]`
47
+ However, there are more things you can control.
48
+
49
+ * before_widget - This is inserted before the widget.
50
+ * after_widget - This is inserted after the widget, and is often used to close tags opened in before_widget
51
+ * before_title - This is inserted before the title and defults to <h2>
52
+ * after_title - This is inserted after the title and defults to </h2>
53
+ * errmsg - This is the error message that displays if there's a problem connecting to Twitter
54
+ * hiderss - set to true to hide the RSS icon (defaults to false)
55
+ * hidereplies - set to true to hide @replies that are sent from the account (defaults to false)
56
+ * avatar - set to true to display the avatar from the Twitter account (defaults to false)
57
+ * showXavisysLink - set to true to display a link to the Twitter Widget Pro page. We greatly appreciate your support in linking to this page so others can find this useful plugin too! (defaults to false)
58
+ * items - The number of items to display (defaults to 10)
59
+ * showts - Number of seconds old a tweet has to be to show ___ ago rather than a date/time (defaults to 86400 seconds which is 24 hours)
60
+ * title - The title of the widget (defaults 'Twitter: Username')
61
+
62
+ You can see these put into action by trying something like:
63
+
64
+ * `[twitter-widget username="wpinformer" before_widget="<div class='half-box'>" after_widget="</div>" before_title="<h1>" after_title="</h1>" errmsg="Uh oh!" hiderss="true" hidereplies="true" avatar="1" showXavisysLink="1" items="3" showts="60"]Your Title[/twitter-widget]`
65
+ * `[twitter-widget username="wpinformer" before_widget="<div class='half-box'>" after_widget="</div>" before_title="<h1>" after_title="</h1>" errmsg="Uh oh!" hiderss="true" hidereplies="true" avatar="1" showXavisysLink="1" items="3" showts="60" title="Your Title"]`
66
+ * `[twitter-widget username="wpinformer"]`
67
+
68
+ = Why can't I display a friends feed anymore? =
69
+
70
+ 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.
71
+
72
  == Screenshots ==
73
 
74
  1. To use the widget, go to Appearance -> Widgets and Add "Twitter Widget Pro" widget.
78
 
79
  == Changelog ==
80
 
81
+ = 2.1.0 =
82
+ * Added a shortcode to allow you to embed a widget in any post or page
83
+
84
  = 2.0.5 =
85
  * Remove the settings link from the plugin line on the plugins page
86
  * Add a link to manage widgets to the plugin line on the plugins page
upgrade.html CHANGED
@@ -1,8 +1,5 @@
1
  <p><a href="http://wordpress.org/extend/plugins/twitter-widget-pro/changelog/">Change Log</a></p>
2
  <ul style="list-style: disc inside; padding: 5px 0 0 15px; font-weight: normal;">
3
- <li>2.0.5: Make date string translatable</li>
4
- <li>2.0.5: Changed the settings link (make non-functional in 2.0.4) to a "Manage Widgets" link</li>
5
- <li>2.0.4: Removed the optional anonymous statistics collection. Nothing is ever collected anymore.</li>
6
- <li>2.0.4: Added twitterwidget-title and twitterwidget-rss classes to the title and rss links for separate styling</li>
7
  <li style="color:red; font-weight:bold;">2.0+: Now requires WordPress 2.8 and still requires PHP 5+</li>
8
  </ul>
1
  <p><a href="http://wordpress.org/extend/plugins/twitter-widget-pro/changelog/">Change Log</a></p>
2
  <ul style="list-style: disc inside; padding: 5px 0 0 15px; font-weight: normal;">
3
+ <li>2.1.0: Added a shortcode to allow you to embed a widget in any post or page</li>
 
 
 
4
  <li style="color:red; font-weight:bold;">2.0+: Now requires WordPress 2.8 and still requires PHP 5+</li>
5
  </ul>
wp-twitter-widget.php CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
  /**
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, #hashtag, and link parsing. It can even display profile images for the users. Requires PHP5.
6
- * Version: 2.0.5
7
  * Author: Aaron D. Campbell
8
  * Author URI: http://xavisys.com/
9
  * Text Domain: twitter-widget-pro
@@ -147,101 +147,276 @@ class WP_Widget_Twitter_Pro extends WP_Widget {
147
 
148
  public function widget( $args, $instance ) {
149
  $instance = $this->_getInstanceSettings( $instance );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  // Validate our options
152
- $instance['items'] = (int) $instance['items'];
153
- if ( $instance['items'] < 1 || 20 < $instance['items'] ) {
154
- $instance['items'] = 10;
155
  }
156
- if (!isset($instance['showts'])) {
157
- $instance['showts'] = 86400;
158
  }
159
 
160
  try {
161
- $tweets = $this->_getTweets($instance);
162
  } catch (wpTwitterWidgetException $e) {
163
  $tweets = $e;
164
  }
165
 
166
- echo $args['before_widget'] . '<div>';
167
 
168
  // If "hide rss" hasn't been checked, show the linked icon
169
- if ( $instance['hiderss'] != 'true' ) {
170
  if ( file_exists(dirname(__FILE__) . '/rss.png') ) {
171
  $icon = str_replace(ABSPATH, get_option('siteurl').'/', dirname(__FILE__)) . '/rss.png';
172
  } else {
173
  $icon = get_option('siteurl').'/wp-includes/images/rss.png';
174
  }
175
- $feedUrl = $this->_getFeedUrl($instance, 'rss', false);
176
  $args['before_title'] .= "<a class='twitterwidget twitterwidget-rss' href='{$feedUrl}' title='" . attribute_escape(__('Syndicate this content', 'twitter-widget-pro')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='{$icon}' alt='RSS' /></a> ";
177
  }
178
- $twitterLink = 'http://twitter.com/' . $instance['username'];
179
- $args['before_title'] .= "<a class='twitterwidget twitterwidget-title' href='{$twitterLink}' title='" . attribute_escape("Twitter: {$instance['username']}") . "'>";
180
  $args['after_title'] = '</a>' . $args['after_title'];
181
- if (empty($instance['title'])) {
182
- $instance['title'] = "Twitter: {$instance['username']}";
183
  }
184
- echo $args['before_title'] . $instance['title'] . $args['after_title'];
185
- if (!is_a($tweets, 'wpTwitterWidgetException') && !empty($tweets[0]) && $instance['avatar'] == 'true') {
186
- echo '<div class="twitter-avatar">';
187
- echo $this->_getProfileImage($tweets[0]->user);
188
- echo '</div>';
189
  }
190
- echo '<ul>';
191
  if (is_a($tweets, 'wpTwitterWidgetException')) {
192
- echo '<li class="wpTwitterWidgetError">' . $tweets->getMessage() . '</li>';
193
  } else if (count($tweets) == 0) {
194
- echo '<li class="wpTwitterWidgetEmpty">' . __('No Tweets Available', 'twitter-widget-pro') . '</li>';
195
  } else {
196
  $count = 0;
197
  foreach ($tweets as $tweet) {
198
- if ( $instance['hidereplies'] != 'true' || empty($tweet->in_reply_to_user_id)) {
199
  // Set our "ago" string which converts the date to "# ___(s) ago"
200
- $tweet->ago = $this->_timeSince(strtotime($tweet->created_at), $instance['showts']);
201
- ?>
 
 
202
  <li>
203
- <span class="entry-content"><?php echo apply_filters( 'widget_twitter_content', $tweet->text ); ?></span>
204
  <span class="entry-meta">
205
  <span class="time-meta">
206
- <a href="http://twitter.com/<?php echo $tweet->user->screen_name; ?>/statuses/<?php echo $tweet->id; ?>">
207
- <?php echo $tweet->ago; ?>
208
  </a>
209
  </span>
210
  <span class="from-meta">
211
- <?php echo sprintf(__('from %s', 'twitter-widget-pro'), str_replace('&', '&amp;', $tweet->source)); ?>
212
  </span>
213
- <?php
214
  if (!empty($tweet->in_reply_to_screen_name)) {
215
  $rtLinkText = sprintf( __('in reply to %s', 'twitter-widget-pro'), $tweet->in_reply_to_screen_name );
216
- echo <<<replyTo
217
  <span class="in-reply-to-meta">
218
  <a href="http://twitter.com/{$tweet->in_reply_to_screen_name}/statuses/{$tweet->in_reply_to_status_id}" class="reply-to">
219
  {$rtLinkText}
220
  </a>
221
  </span>
222
  replyTo;
223
- } ?>
224
-
225
  </span>
226
  </li>
227
- <?php
228
- if (++$count >= $instance['items']) {
 
229
  break;
230
  }
231
  }
232
  }
233
  }
234
 
235
- if ( $instance['showXavisysLink'] == 'true' ) {
236
- ?>
 
237
  <li class="xavisys-link">
238
  <span class="xavisys-link-text">
239
- <?php echo sprintf(__('Powered by <a href="%s" title="Get Twitter Widget for your WordPress site">WordPress Twitter Widget Pro</a>', 'twitter-widget-pro'), 'http://xavisys.com/2008/04/wordpress-twitter-widget/' );?>
240
  </span>
241
  </li>
242
- <?php
243
  }
244
- echo '</ul></div>' . $args['after_widget'];
 
245
  }
246
 
247
  /**
@@ -394,147 +569,53 @@ replyTo;
394
  </a>
395
  profileImage;
396
  }
397
- }
398
 
399
-
400
- /**
401
- * wpTwitterWidget is the class that handles everything outside the widget. This
402
- * includes filters that modify tweet content for things like linked usernames.
403
- * It also helps us avoid name collisions.
404
- */
405
- class wpTwitterWidget
406
- {
407
- /**
408
- * @var array Plugin settings
409
- */
410
- private $_settings;
411
-
412
- /**
413
- * Repository base url
414
  *
415
- * @since 1.4.4
416
- * @var string
 
417
  */
418
- private $_reposUrl = 'http://plugins.svn.wordpress.org/';
419
-
420
- public function __construct() {
421
- /**
422
- * Add filters and actions
423
- */
424
- add_filter( 'init', array( $this, 'init_locale') );
425
- add_action( 'widgets_init', array($this, 'register') );
426
- add_filter( 'widget_twitter_content', array($this, 'linkTwitterUsers') );
427
- add_filter( 'widget_twitter_content', array($this, 'linkUrls') );
428
- add_filter( 'widget_twitter_content', array($this, 'linkHashtags') );
429
- add_filter( 'widget_twitter_content', 'convert_chars' );
430
- add_filter( 'plugin_action_links', array($this, 'addWidgetLink'), 10, 2 );
431
- add_action ( 'in_plugin_update_message-'.plugin_basename ( __FILE__ ) , array ( $this , '_changelog' ), null, 2 );
432
- }
433
-
434
- public function init_locale() {
435
- $lang_dir = basename(dirname(__FILE__)) . '/languages';
436
- load_plugin_textdomain('twitter-widget-pro', 'wp-content/plugins/' . $lang_dir, $lang_dir);
437
- }
438
-
439
- public function _changelog ($pluginData, $newPluginData) {
440
- $url = "{$this->_reposUrl}/{$newPluginData->slug}/tags/{$newPluginData->new_version}/upgrade.html";
441
- $response = wp_remote_get ( $url );
442
- $code = (int) wp_remote_retrieve_response_code ( $response );
443
- if ( $code == 200 ) {
444
- echo wp_remote_retrieve_body ( $response );
445
  }
446
- }
447
 
448
- /**
449
- * Returns the user's screen name as a link inside strong tags.
450
- *
451
- * @param object $user - Twitter user
452
- * @return string - Username as link (XHTML)
453
- */
454
- private function _getUserName($user) {
455
- return <<<profileImage
456
- <strong>
457
- <a title="{$user->name}" href="http://twitter.com/{$user->screen_name}">{$user->screen_name}</a>
458
- </strong>
459
- profileImage;
460
- }
461
 
462
- public function addWidgetLink( $links, $file ){
463
- if ( $file == plugin_basename(__FILE__) ) {
464
- // Add settings link to our plugin
465
- $link = '<a href="widgets.php">' . __('Manage Widgets', 'twitter-widget-pro') . '</a>';
466
- array_unshift( $links, $link );
 
 
 
 
 
 
467
  }
468
- return $links;
469
- }
470
-
471
- /**
472
- * Replace @username with a link to that twitter user
473
- *
474
- * @param string $text - Tweet text
475
- * @return string - Tweet text with @replies linked
476
- */
477
- public function linkTwitterUsers($text) {
478
- $text = preg_replace('/(^|\s)@(\w*)/i', '$1<a href="http://twitter.com/$2" class="twitter-user">@$2</a>', $text);
479
- return $text;
480
- }
481
-
482
- /**
483
- * Replace #hashtag with a link to search.twitter.com for that hashtag
484
- *
485
- * @param string $text - Tweet text
486
- * @return string - Tweet text with #hashtags linked
487
- */
488
- public function linkHashtags($text) {
489
- $text = preg_replace_callback('/(^|\s)(#\w*)/i', array($this, '_hashtagLink'), $text);
490
- return $text;
491
- }
492
-
493
- /**
494
- * Replace #hashtag with a link to search.twitter.com for that hashtag
495
- *
496
- * @param array $matches - Tweet text
497
- * @return string - Tweet text with #hashtags linked
498
- */
499
- private function _hashtagLink($matches) {
500
- return "{$matches[1]}<a href='http://search.twitter.com/search?q="
501
- . urlencode($matches[2])
502
- . "' class='twitter-hashtag'>{$matches[2]}</a>";
503
- }
504
-
505
- /**
506
- * Turn URLs into links
507
- *
508
- * @param string $text - Tweet text
509
- * @return string - Tweet text with URLs repalced with links
510
- */
511
- public function linkUrls($text) {
512
- /**
513
- * match protocol://address/path/file.extension?some=variable&another=asf%
514
- * $1 is a possible space, this keeps us from linking href="[link]" etc
515
- * $2 is the whole URL
516
- * $3 is protocol://
517
- * $4 is the URL without the protocol://
518
- * $5 is the URL parameters
519
- */
520
- $text = preg_replace("/(^|\s)(([a-zA-Z]+:\/\/)([a-z][a-z0-9_\..-]*[a-z]{2,6})([a-zA-Z0-9~\/*-?&%]*))/i", "$1<a href=\"$2\">$2</a>", $text);
521
-
522
- /**
523
- * match www.something.domain/path/file.extension?some=variable&another=asf%
524
- * $1 is a possible space, this keeps us from linking href="[link]" etc
525
- * $2 is the whole URL that was matched. The protocol is missing, so we assume http://
526
- * $3 is www.
527
- * $4 is the URL matched without the www.
528
- * $5 is the URL parameters
529
- */
530
- $text = preg_replace("/(^|\s)(www\.([a-z][a-z0-9_\..-]*[a-z]{2,6})([a-zA-Z0-9~\/*-?&%]*))/i", "$1<a href=\"http://$2\">$2</a>", $text);
531
 
532
- return $text;
533
  }
534
 
535
- function register() {
536
- register_widget('WP_Widget_Twitter_Pro');
537
- }
538
  }
539
  // Instantiate our class
540
- $wpTwitterWidget = new wpTwitterWidget();
1
  <?php
2
  /**
3
  * Plugin Name: Twitter Widget Pro
4
+ * Plugin URI: http://xavisys.com/wordpress-plugins/wordpress-twitter-widget/
5
  * Description: A widget that properly handles twitter feeds, including @username, #hashtag, and link parsing. It can even display profile images for the users. Requires PHP5.
6
+ * Version: 2.1.0
7
  * Author: Aaron D. Campbell
8
  * Author URI: http://xavisys.com/
9
  * Text Domain: twitter-widget-pro
147
 
148
  public function widget( $args, $instance ) {
149
  $instance = $this->_getInstanceSettings( $instance );
150
+ $wpTwitterWidget = wpTwitterWidget::getInstance();
151
+ echo $wpTwitterWidget->display( wp_parse_args( $instance, $args ) );
152
+ }
153
+ }
154
+
155
+
156
+ /**
157
+ * wpTwitterWidget is the class that handles everything outside the widget. This
158
+ * includes filters that modify tweet content for things like linked usernames.
159
+ * It also helps us avoid name collisions.
160
+ */
161
+ class wpTwitterWidget
162
+ {
163
+ /**
164
+ * Static property to hold our singleton instance
165
+ */
166
+ static $instance = false;
167
+
168
+ /**
169
+ * @var array Plugin settings
170
+ */
171
+ private $_settings;
172
+
173
+ /**
174
+ * This is our constructor, which is private to force the use of getInstance()
175
+ * @return void
176
+ */
177
+ private function __construct() {
178
+ /**
179
+ * Add filters and actions
180
+ */
181
+ add_filter( 'init', array( $this, 'init_locale') );
182
+ add_action( 'widgets_init', array($this, 'register') );
183
+ add_filter( 'widget_twitter_content', array($this, 'linkTwitterUsers') );
184
+ add_filter( 'widget_twitter_content', array($this, 'linkUrls') );
185
+ add_filter( 'widget_twitter_content', array($this, 'linkHashtags') );
186
+ add_filter( 'widget_twitter_content', 'convert_chars' );
187
+ add_filter( 'plugin_action_links', array($this, 'addWidgetLink'), 10, 2 );
188
+ add_action ( 'in_plugin_update_message-'.plugin_basename ( __FILE__ ) , array ( $this , '_changelog' ), null, 2 );
189
+ add_shortcode( 'twitter-widget', array( $this, 'handleShortcodes' ) );
190
+ }
191
+
192
+ /**
193
+ * Function to instantiate our class and make it a singleton
194
+ */
195
+ public static function getInstance() {
196
+ if ( !self::$instance ) {
197
+ self::$instance = new self;
198
+ }
199
+ return self::$instance;
200
+ }
201
+
202
+ public function init_locale() {
203
+ $lang_dir = basename(dirname(__FILE__)) . '/languages';
204
+ load_plugin_textdomain('twitter-widget-pro', 'wp-content/plugins/' . $lang_dir, $lang_dir);
205
+ }
206
+
207
+ public function _changelog ($pluginData, $newPluginData) {
208
+ require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
209
+
210
+ $plugin = plugins_api( 'plugin_information', array( 'slug' => $newPluginData->slug ) );
211
+
212
+ if ( !$plugin || is_wp_error( $plugin ) || empty( $plugin->sections['changelog'] ) ) {
213
+ return;
214
+ }
215
+
216
+ $changes = $plugin->sections['changelog'];
217
+
218
+ $pos = strpos( $changes, '<h4>' . $pluginData['Version'] );
219
+ $changes = trim( substr( $changes, 0, $pos ) );
220
+ $replace = array(
221
+ '<ul>' => '<ul style="list-style: disc inside; padding-left: 15px; font-weight: normal;">',
222
+ '<h4>' => '<h4 style="margin-bottom:0;">',
223
+ );
224
+ echo str_replace( array_keys($replace), $replace, $changes );
225
+ }
226
+
227
+ /**
228
+ * Returns the user's screen name as a link inside strong tags.
229
+ *
230
+ * @param object $user - Twitter user
231
+ * @return string - Username as link (XHTML)
232
+ */
233
+ private function _getUserName($user) {
234
+ return <<<profileImage
235
+ <strong>
236
+ <a title="{$user->name}" href="http://twitter.com/{$user->screen_name}">{$user->screen_name}</a>
237
+ </strong>
238
+ profileImage;
239
+ }
240
+
241
+ public function addWidgetLink( $links, $file ){
242
+ if ( $file == plugin_basename(__FILE__) ) {
243
+ // Add settings link to our plugin
244
+ $link = '<a href="widgets.php">' . __('Manage Widgets', 'twitter-widget-pro') . '</a>';
245
+ array_unshift( $links, $link );
246
+ }
247
+ return $links;
248
+ }
249
+
250
+ /**
251
+ * Replace @username with a link to that twitter user
252
+ *
253
+ * @param string $text - Tweet text
254
+ * @return string - Tweet text with @replies linked
255
+ */
256
+ public function linkTwitterUsers($text) {
257
+ $text = preg_replace('/(^|\s)@(\w*)/i', '$1<a href="http://twitter.com/$2" class="twitter-user">@$2</a>', $text);
258
+ return $text;
259
+ }
260
+
261
+ /**
262
+ * Replace #hashtag with a link to search.twitter.com for that hashtag
263
+ *
264
+ * @param string $text - Tweet text
265
+ * @return string - Tweet text with #hashtags linked
266
+ */
267
+ public function linkHashtags($text) {
268
+ $text = preg_replace_callback('/(^|\s)(#\w*)/i', array($this, '_hashtagLink'), $text);
269
+ return $text;
270
+ }
271
+
272
+ /**
273
+ * Replace #hashtag with a link to search.twitter.com for that hashtag
274
+ *
275
+ * @param array $matches - Tweet text
276
+ * @return string - Tweet text with #hashtags linked
277
+ */
278
+ private function _hashtagLink($matches) {
279
+ return "{$matches[1]}<a href='http://search.twitter.com/search?q="
280
+ . urlencode($matches[2])
281
+ . "' class='twitter-hashtag'>{$matches[2]}</a>";
282
+ }
283
+
284
+ /**
285
+ * Turn URLs into links
286
+ *
287
+ * @param string $text - Tweet text
288
+ * @return string - Tweet text with URLs repalced with links
289
+ */
290
+ public function linkUrls($text) {
291
+ /**
292
+ * match protocol://address/path/file.extension?some=variable&another=asf%
293
+ * $1 is a possible space, this keeps us from linking href="[link]" etc
294
+ * $2 is the whole URL
295
+ * $3 is protocol://
296
+ * $4 is the URL without the protocol://
297
+ * $5 is the URL parameters
298
+ */
299
+ $text = preg_replace("/(^|\s)(([a-zA-Z]+:\/\/)([a-z][a-z0-9_\..-]*[a-z]{2,6})([a-zA-Z0-9~\/*-?&%]*))/i", "$1<a href=\"$2\">$2</a>", $text);
300
+
301
+ /**
302
+ * match www.something.domain/path/file.extension?some=variable&another=asf%
303
+ * $1 is a possible space, this keeps us from linking href="[link]" etc
304
+ * $2 is the whole URL that was matched. The protocol is missing, so we assume http://
305
+ * $3 is www.
306
+ * $4 is the URL matched without the www.
307
+ * $5 is the URL parameters
308
+ */
309
+ $text = preg_replace("/(^|\s)(www\.([a-z][a-z0-9_\..-]*[a-z]{2,6})([a-zA-Z0-9~\/*-?&%]*))/i", "$1<a href=\"http://$2\">$2</a>", $text);
310
+
311
+ return $text;
312
+ }
313
+
314
+ function register() {
315
+ register_widget('WP_Widget_Twitter_Pro');
316
+ }
317
+
318
+ public function display( $args ) {
319
+ $args = wp_parse_args( $args );
320
 
321
  // Validate our options
322
+ $args['items'] = (int) $args['items'];
323
+ if ( $args['items'] < 1 || 20 < $args['items'] ) {
324
+ $args['items'] = 10;
325
  }
326
+ if (!isset($args['showts'])) {
327
+ $args['showts'] = 86400;
328
  }
329
 
330
  try {
331
+ $tweets = $this->_getTweets($args);
332
  } catch (wpTwitterWidgetException $e) {
333
  $tweets = $e;
334
  }
335
 
336
+ $widgetContent = $args['before_widget'] . '<div>';
337
 
338
  // If "hide rss" hasn't been checked, show the linked icon
339
+ if ( $args['hiderss'] != 'true' ) {
340
  if ( file_exists(dirname(__FILE__) . '/rss.png') ) {
341
  $icon = str_replace(ABSPATH, get_option('siteurl').'/', dirname(__FILE__)) . '/rss.png';
342
  } else {
343
  $icon = get_option('siteurl').'/wp-includes/images/rss.png';
344
  }
345
+ $feedUrl = $this->_getFeedUrl($args, 'rss', false);
346
  $args['before_title'] .= "<a class='twitterwidget twitterwidget-rss' href='{$feedUrl}' title='" . attribute_escape(__('Syndicate this content', 'twitter-widget-pro')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='{$icon}' alt='RSS' /></a> ";
347
  }
348
+ $twitterLink = 'http://twitter.com/' . $args['username'];
349
+ $args['before_title'] .= "<a class='twitterwidget twitterwidget-title' href='{$twitterLink}' title='" . attribute_escape("Twitter: {$args['username']}") . "'>";
350
  $args['after_title'] = '</a>' . $args['after_title'];
351
+ if (empty($args['title'])) {
352
+ $args['title'] = "Twitter: {$args['username']}";
353
  }
354
+ $widgetContent .= $args['before_title'] . $args['title'] . $args['after_title'];
355
+ if (!is_a($tweets, 'wpTwitterWidgetException') && !empty($tweets[0]) && $args['avatar'] == 'true') {
356
+ $widgetContent .= '<div class="twitter-avatar">';
357
+ $widgetContent .= $this->_getProfileImage($tweets[0]->user);
358
+ $widgetContent .= '</div>';
359
  }
360
+ $widgetContent .= '<ul>';
361
  if (is_a($tweets, 'wpTwitterWidgetException')) {
362
+ $widgetContent .= '<li class="wpTwitterWidgetError">' . $tweets->getMessage() . '</li>';
363
  } else if (count($tweets) == 0) {
364
+ $widgetContent .= '<li class="wpTwitterWidgetEmpty">' . __('No Tweets Available', 'twitter-widget-pro') . '</li>';
365
  } else {
366
  $count = 0;
367
  foreach ($tweets as $tweet) {
368
+ if ( $args['hidereplies'] != 'true' || empty($tweet->in_reply_to_user_id)) {
369
  // Set our "ago" string which converts the date to "# ___(s) ago"
370
+ $tweet->ago = $this->_timeSince(strtotime($tweet->created_at), $args['showts']);
371
+ $entryContent = apply_filters( 'widget_twitter_content', $tweet->text );
372
+ $from = sprintf(__('from %s', 'twitter-widget-pro'), str_replace('&', '&amp;', $tweet->source));
373
+ $widgetContent .= <<<WIDGET_START
374
  <li>
375
+ <span class="entry-content">{$entryContent}</span>
376
  <span class="entry-meta">
377
  <span class="time-meta">
378
+ <a href="http://twitter.com/{$tweet->user->screen_name}/statuses/{$tweet->id}">
379
+ {$tweet->ago}
380
  </a>
381
  </span>
382
  <span class="from-meta">
383
+ {$from}
384
  </span>
385
+ WIDGET_START;
386
  if (!empty($tweet->in_reply_to_screen_name)) {
387
  $rtLinkText = sprintf( __('in reply to %s', 'twitter-widget-pro'), $tweet->in_reply_to_screen_name );
388
+ $widgetContent .= <<<replyTo
389
  <span class="in-reply-to-meta">
390
  <a href="http://twitter.com/{$tweet->in_reply_to_screen_name}/statuses/{$tweet->in_reply_to_status_id}" class="reply-to">
391
  {$rtLinkText}
392
  </a>
393
  </span>
394
  replyTo;
395
+ }
396
+ $widgetContent .= <<<WIDGET_ENTRY_END
397
  </span>
398
  </li>
399
+ WIDGET_ENTRY_END;
400
+
401
+ if (++$count >= $args['items']) {
402
  break;
403
  }
404
  }
405
  }
406
  }
407
 
408
+ if ( $args['showXavisysLink'] == 'true' ) {
409
+ $xavisysLink = sprintf(__('Powered by <a href="%s" title="Get Twitter Widget for your WordPress site">WordPress Twitter Widget Pro</a>', 'twitter-widget-pro'), 'http://xavisys.com/wordpress-plugins/wordpress-twitter-widget/' );
410
+ $widgetContent .= <<<XAVISYS_LINK
411
  <li class="xavisys-link">
412
  <span class="xavisys-link-text">
413
+ {$xavisysLink}
414
  </span>
415
  </li>
416
+ XAVISYS_LINK;
417
  }
418
+ $widgetContent .= '</ul></div>' . $args['after_widget'];
419
+ return $widgetContent;
420
  }
421
 
422
  /**
569
  </a>
570
  profileImage;
571
  }
 
572
 
573
+ /**
574
+ * Replace our shortCode with the "widget"
 
 
 
 
 
 
 
 
 
 
 
 
 
575
  *
576
+ * @param array $attr - array of attributes from the shortCode
577
+ * @param string $content - Content of the shortCode
578
+ * @return string - formatted XHTML replacement for the shortCode
579
  */
580
+ public function handleShortcodes($attr, $content = '') {
581
+ $defaults = array(
582
+ 'before_widget' => '',
583
+ 'after_widget' => '',
584
+ 'before_title' => '<h2>',
585
+ 'after_title' => '</h2>',
586
+ 'title' => '',
587
+ 'errmsg' => '',
588
+ 'fetchTimeOut' => '2',
589
+ 'username' => '',
590
+ 'hiderss' => false,
591
+ 'hidereplies' => false,
592
+ 'avatar' => false,
593
+ 'showXavisysLink' => false,
594
+ 'items' => 10,
595
+ 'showts' => 60 * 60 * 24,
596
+ );
597
+ if ( !empty($content) && empty($attr['title']) ) {
598
+ $attr['title'] = $content;
 
 
 
 
 
 
 
 
599
  }
 
600
 
601
+ $attr = shortcode_atts($defaults, $attr);
 
 
 
 
 
 
 
 
 
 
 
 
602
 
603
+ if ( $attr['hiderss'] && $attr['hiderss'] != 'false' && $attr['hiderss'] != '0' ) {
604
+ $attr['hiderss'] == true;
605
+ }
606
+ if ( $attr['hidereplies'] && $attr['hidereplies'] != 'false' && $attr['hidereplies'] != '0' ) {
607
+ $attr['hidereplies'] == true;
608
+ }
609
+ if ( $attr['avatar'] && $attr['avatar'] != 'false' && $attr['avatar'] != '0' ) {
610
+ $attr['avatar'] == true;
611
+ }
612
+ if ( $attr['showXavisysLink'] && $attr['showXavisysLink'] != 'false' && $attr['showXavisysLink'] != '0' ) {
613
+ $attr['showXavisysLink'] == true;
614
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
615
 
616
+ return $this->display($attr);
617
  }
618
 
 
 
 
619
  }
620
  // Instantiate our class
621
+ $wpTwitterWidget = wpTwitterWidget::getInstance();