Rotating Tweets (Twitter widget and shortcode) - Version 0.500

Version Description

Adds options for how tweet information is displayed and how the tweet rotates.

=

Download this release

Release Info

Developer mpntod
Plugin Icon wp plugin Rotating Tweets (Twitter widget and shortcode)
Version 0.500
Comparing to
See all releases

Code changes from version 0.491 to 0.500

Files changed (4) hide show
  1. js/rotating_tweet.js +16 -3
  2. readme.txt +22 -9
  3. rotatingtweets.php +141 -45
  4. screenshot-2.png +0 -0
js/rotating_tweet.js CHANGED
@@ -3,12 +3,25 @@
3
  */
4
  jQuery(document).ready(function() {
5
  jQuery('.rotatingtweets').each(function() {
 
6
  var rotate_id = "#"+this.id
7
- var timeoutdelay = rotate_id.split('_');
 
 
 
 
 
 
 
 
 
 
 
8
  jQuery(rotate_id).cycle({
9
  pause: 1,
10
- timeout: timeoutdelay[1],
11
- fx: 'scrollUp'
 
12
  });
13
  });
14
  });
3
  */
4
  jQuery(document).ready(function() {
5
  jQuery('.rotatingtweets').each(function() {
6
+ /* Get the ID of the rotating tweets div - and parse it to get rotation speed and rotation fx */
7
  var rotate_id = "#"+this.id
8
+ var rotate_id_split = rotate_id.split('_');
9
+ var rotate_timeout = rotate_id_split[1];
10
+ var rotate_fx = rotate_id_split[2];
11
+ /* If we have the zeebizcard template - set a minimum height - used to do this via a separate script, but this is easier to maintain */
12
+ if (jQuery('#zee_stylesheet-css').is('link')) {
13
+ var rotate_height = '7em';
14
+ } else {
15
+ var rotate_height = 'auto';
16
+ }
17
+ /* If the rotation type has not been set - then set it to scrollUp */
18
+ if(rotate_fx == null){rotate_fx = 'scrollUp'};
19
+ /* Call the rotation */
20
  jQuery(rotate_id).cycle({
21
  pause: 1,
22
+ height: rotate_height,
23
+ timeout: rotate_timeout,
24
+ fx: rotate_fx
25
  });
26
  });
27
  });
readme.txt CHANGED
@@ -4,17 +4,17 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: shortcode,widget,twitter,rotating,rotate,rotator,tweet,tweets,animation,jquery,jquery cycle,cycle
5
  Requires at least: 2.6
6
  Tested up to: 3.4
7
- Stable tag: 0.490
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Widget and/or shortcode to show your latest tweets one at a time an animated rotation
12
 
13
  == Description ==
14
- * Replaces a [shortcode](http://codex.wordpress.org/Shortcode) such as `[rotatingtweets screen_name='your_twitter_name']`, or a [widget](http://codex.wordpress.org/WordPress_Widgets), with a rotating display of your most recent tweets
15
- * Space efficient - instead of showing all your tweets at once, shows one at a time and then smoothly replaces it with the next one. After showing all your tweets, loops back to the beginning again.
16
- * Reliable - keeps showing your latest Tweets even if the Twitter website is down.
17
- * Customisable - you decide whose tweets to show, how many to show, whether to include retweets and replies, and whether to show a follow button. You can also decide how quickly the tweets rotate.
18
  * Gives you the option to show a fully customisable Twitter 'follow' button
19
  * Replaces [t.co](http://t.co) links with the original link
20
  * Caches the most recent data from Twitter to avoid problems with rate limiting
@@ -45,18 +45,31 @@ Possible variables for the shortcode include:
45
  * `timeout` = time that each tweet is shown in milliseconds - optional - default is `'4000'` (i.e. 4 seconds)
46
  * `no_show_count` = `'0'` or `'1'` - remove the follower count from the Twitter follow button - optional - default is `'0'`
47
  * `no_show_screen_name` = `'0'` or `'1'` - remove the screen name from the Twitter follow button - optional - default is `'0'`
 
 
 
 
 
 
 
48
 
49
  == Frequently Asked Questions ==
50
  = How often does the plug-in call Twitter =
51
  In most cases, each use (or "instance") of this plug-in gets data from Twitter every 2 minutes. The exception is when two or more instances share the same settings (screen name etc.), in which case they share the same data rather than each calling it separately.
52
 
53
  == Upgrade notice ==
54
- = 0.49 =
55
- Lets you customise the Twitter 'follow' button. Fixes problem with media links. Sorts problem of overlong links reshaping widgets.
56
 
57
  == Changelog ==
58
- = 0.49 =
59
- Lets you customise the Twitter 'follow' button
 
 
 
 
 
 
60
 
61
  = 0.48 =
62
  More detailed error messages for Wordpress installations unable to access Twitter.
4
  Tags: shortcode,widget,twitter,rotating,rotate,rotator,tweet,tweets,animation,jquery,jquery cycle,cycle
5
  Requires at least: 2.6
6
  Tested up to: 3.4
7
+ Stable tag: 0.500
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Widget and/or shortcode to show your latest tweets one at a time an animated rotation
12
 
13
  == Description ==
14
+ * **Replaces a [shortcode](http://codex.wordpress.org/Shortcode) such as `[rotatingtweets screen_name='your_twitter']`, or a [widget](http://codex.wordpress.org/WordPress_Widgets), with a rotating display of your most recent tweets**
15
+ * **Space efficient** - instead of showing all your tweets at once, shows one at a time and then smoothly replaces it with the next one. After showing all your tweets, loops back to the beginning again.
16
+ * **Reliable** - keeps showing your latest Tweets even if the Twitter website is down.
17
+ * **Customisable** - you decide whose tweets to show, how many to show, whether to include retweets and replies, and whether to show a follow button. You can also decide how quickly the tweets rotate and what type of animation to use.
18
  * Gives you the option to show a fully customisable Twitter 'follow' button
19
  * Replaces [t.co](http://t.co) links with the original link
20
  * Caches the most recent data from Twitter to avoid problems with rate limiting
45
  * `timeout` = time that each tweet is shown in milliseconds - optional - default is `'4000'` (i.e. 4 seconds)
46
  * `no_show_count` = `'0'` or `'1'` - remove the follower count from the Twitter follow button - optional - default is `'0'`
47
  * `no_show_screen_name` = `'0'` or `'1'` - remove the screen name from the Twitter follow button - optional - default is `'0'`
48
+ * `show_meta_timestamp` = `'0'` or `'1'` - show the time and date of each tweet - optional - default is `'1'`
49
+ * `show_meta_screen` = `'0'` or `'1'` - show who posted each tweet - optional - default is `'1'`
50
+ * `show_meta_via` = `'0'` or `'1'` - show how each tweet was posted - optional - default is `'1'`
51
+ * `show_meta_reply_retweet_favorite` = `'0'` or `'1'` - show 'reply', 'retweet' and 'favorite' buttons - optional - default is `'0'`
52
+ * `rotation_type` = any of the options listed on the [jQuery.cycle website](http://jquery.malsup.com/cycle/browser.html) - default is `'scrollUp'`
53
+
54
+ although the only one you *have* to have is `screen_name`.
55
 
56
  == Frequently Asked Questions ==
57
  = How often does the plug-in call Twitter =
58
  In most cases, each use (or "instance") of this plug-in gets data from Twitter every 2 minutes. The exception is when two or more instances share the same settings (screen name etc.), in which case they share the same data rather than each calling it separately.
59
 
60
  == Upgrade notice ==
61
+ = 0.500 =
62
+ Adds options for how tweet information is displayed and how the tweet rotates.
63
 
64
  == Changelog ==
65
+ = 0.500 =
66
+ Adds options for how tweet information is displayed and how the tweet rotates.
67
+
68
+ = 0.492 =
69
+ Solves `Cannot use string offset as an array` error on line 232
70
+
71
+ = 0.491 =
72
+ Lets you customise the Twitter 'follow' button. Fixes problem with media links. Sorts problem of overlong links reshaping widgets.
73
 
74
  = 0.48 =
75
  More detailed error messages for Wordpress installations unable to access Twitter.
rotatingtweets.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Rotating Tweets widget & shortcode
4
  Description: Replaces a shortcode such as [rotatingtweets userid='your_twitter_name'], or a widget, with a rotating tweets display
5
- Version: 0.491
6
  Author: Martin Tod
7
  Author URI: http://www.martintod.org.uk
8
  License: GPL2
@@ -44,7 +44,7 @@ class rotatingtweets_Widget extends WP_Widget {
44
  $style = get_stylesheet();
45
  switch ($style):
46
  case 'zeebizzcard':
47
- wp_enqueue_script( 'rotating_tweet', plugins_url('js/rotating_tweet_zee.js', __FILE__),array('jquery','zee_jquery-cycle'),FALSE,FALSE );
48
  break;
49
  default:
50
  wp_enqueue_script( 'jquery-cycle', plugins_url('js/jquery.cycle.all.js', __FILE__),array('jquery'),FALSE,FALSE );
@@ -58,39 +58,45 @@ class rotatingtweets_Widget extends WP_Widget {
58
  function widget($args, $instance) {
59
  extract( $args );
60
  $title = apply_filters('widget_title', $instance['title']);
61
- $tw_screen_name = $instance['tw_screen_name'];
62
- $tw_include_rts = $instance['tw_include_rts'];
63
- $tw_exclude_replies = $instance['tw_exclude_replies'];
64
- $tw_tweet_count = $instance['tw_tweet_count'];
65
- $tw_show_follow = $instance['tw_show_follow'];
66
- $tw_timeout = $instance['tw_timeout'];
67
- switch($tw_show_follow) {
 
 
 
 
 
68
  case 2:
69
- $tw_no_show_count = TRUE;
70
- $tw_no_show_screen_name = FALSE;
71
  break;
72
  case 3:
73
- $tw_no_show_count = FALSE;
74
- $tw_no_show_screen_name = TRUE;
75
  break;
76
  case 4:
77
- $tw_no_show_count = TRUE;
78
- $tw_no_show_screen_name = TRUE;
79
  break;
80
  default:
81
- $tw_no_show_count = FALSE;
82
- $tw_no_show_screen_name = FALSE;
83
  break;
84
  }
85
-
86
- if(empty($tw_timeout)) $tw_timeout = 4000;
87
- $tweets = rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_replies,$tw_tweet_count);
88
  ?>
89
  <?php echo $before_widget;
90
  if ( $title )
91
  echo $before_title . $title . $after_title;
92
- rotating_tweets_display($tweets,$tw_tweet_count,$tw_show_follow,$tw_timeout,TRUE,$tw_no_show_count,$tw_no_show_screen_name);
93
- echo $after_widget; ?>
 
 
94
  <?php
95
  }
96
 
@@ -99,22 +105,34 @@ class rotatingtweets_Widget extends WP_Widget {
99
  $instance = $old_instance;
100
  $instance['title'] = strip_tags($new_instance['title']);
101
  $instance['tw_screen_name'] = strip_tags(trim($new_instance['tw_screen_name']));
 
102
  $instance['tw_include_rts'] = absint($new_instance['tw_include_rts']);
103
  $instance['tw_exclude_replies'] = absint($new_instance['tw_exclude_replies']);
104
  $instance['tw_tweet_count'] = max(1,intval($new_instance['tw_tweet_count']));
105
  $instance['tw_show_follow'] = absint($new_instance['tw_show_follow']);
 
 
 
 
 
106
  $instance['tw_timeout'] = max(min(intval($new_instance['tw_timeout']/1000)*1000,6000),3000);
107
  return $instance;
108
  }
109
-
110
  /** @see WP_Widget::form */
111
  function form($instance) {
112
  $title = esc_attr($instance['title']);
113
  $tw_screen_name = esc_attr(trim($instance['tw_screen_name']));
 
 
114
  $tw_include_rts = absint($instance['tw_include_rts']);
115
  $tw_exclude_replies = absint($instance['tw_exclude_replies']);
116
  $tw_tweet_count = intval($instance['tw_tweet_count']);
117
  $tw_show_follow = absint($instance['tw_show_follow']);
 
 
 
 
118
  $tw_timeout = intval($instance['tw_timeout']);
119
  # If values not set, set default values
120
  if(empty($tw_timeout)) $tw_timeout = 4000;
@@ -122,8 +140,8 @@ class rotatingtweets_Widget extends WP_Widget {
122
  ?>
123
  <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('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 $title; ?>" /></label></p>
124
  <p><label for="<?php echo $this->get_field_id('tw_screen_name'); ?>"><?php _e('Twitter name:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('tw_screen_name'); ?>" name="<?php echo $this->get_field_name('tw_screen_name'); ?>" value="<?php echo $tw_screen_name; ?>" /></label></p>
125
- <p><label for="<?php echo $this->get_field_id('tw_include_rts'); ?>"><?php _e('Include retweets?'); ?> <input id="<?php echo $this->get_field_id('tw_include_rts'); ?>" name="<?php echo $this->get_field_name('tw_include_rts'); ?>" type="checkbox" value="1" <?php if($tw_include_rts==1): ?>checked="checked" <?php endif; ?>/></label></p>
126
- <p><label for="<?php echo $this->get_field_id('tw_exclude_replies'); ?>"><?php _e('Exclude replies?'); ?> <input id="<?php echo $this->get_field_id('tw_exclude_replies'); ?>" name="<?php echo $this->get_field_name('tw_exclude_replies'); ?>" type="checkbox" value="1" <?php if($tw_exclude_replies==1): ?>checked="checked" <?php endif; ?>/></label></p>
127
  <p><label for="<?php echo $this->get_field_id('tw_tweet_count'); ?>"><?php _e('How many tweets?'); ?> <select id="<?php echo $this->get_field_id('tw_tweet_count'); ?>" name="<?php echo $this->get_field_name('tw_tweet_count');?>">
128
  <?php
129
  for ($i=1; $i<20; $i++) {
@@ -146,6 +164,43 @@ class rotatingtweets_Widget extends WP_Widget {
146
  echo ">$words</option>";
147
  }
148
  ?></select></label></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  <p><?php _e('Show follow button?'); ?></p>
150
  <?php
151
  $showfollowoptions = array (
@@ -202,7 +257,7 @@ function rotatingtweets_display( $atts, $content=null, $code="" ) {
202
  $no_show_count :: [boolean] remove count from follow button
203
  $no_show_screen_name :: [boolean] remove screen name from follow button
204
  */
205
- extract( shortcode_atts( array(
206
  'screen_name' => 'twitter',
207
  'include_rts' => FALSE,
208
  'exclude_replies' => FALSE,
@@ -210,27 +265,41 @@ function rotatingtweets_display( $atts, $content=null, $code="" ) {
210
  'show_follow' => FALSE,
211
  'timeout' => 4000,
212
  'no_show_count' => FALSE,
213
- 'no_show_screen_name' => FALSE
214
- ), $atts ) );
215
- $tweets = rotatingtweets_get_tweets($screen_name,$include_rts,$exclude_replies,$tweet_count);
216
- $returnstring = rotating_tweets_display($tweets,$tweet_count,$show_follow,$timeout,FALSE,$no_show_count,$no_show_screen_name);
 
 
 
 
 
 
217
  return $returnstring;
218
  }
219
  add_shortcode( 'rotatingtweets', 'rotatingtweets_display' );
220
 
221
  # Get the latest data from Twitter (or from a cache if it's been less than 2 minutes since the last load)
222
- function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_replies,$tw_tweet_count) {
223
  # Clear up variables
224
  $cache_delay = 120;
225
  if($tw_include_rts != 1) $tw_include_rts = 0;
226
  if($tw_exclude_replies != 1) $tw_exclude_replies = 0;
227
- $tw_tweet_count = max(1,intval($tw_tweet_count));
228
  # Get the option strong
229
  $stringname = $tw_screen_name.$tw_include_rts.$tw_exclude_replies;
230
  $optionname = "rotatingtweets-cache";
231
  $option = get_option($optionname);
232
- $latest_json = $option[$stringname]['json'];
233
- $latest_json_date = $option[$stringname]['datetime'];
 
 
 
 
 
 
 
 
234
  $timegap = time()-$latest_json_date;
235
  if($timegap > $cache_delay):
236
  $callstring = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=".urlencode($tw_screen_name)."&include_entities=1&count=70&include_rts=".$tw_include_rts."&exclude_replies=".$tw_exclude_replies;
@@ -238,7 +307,6 @@ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_r
238
  if(!is_wp_error($twitterdata)):
239
  $twitterjson = json_decode($twitterdata['body']);
240
  else:
241
- # echo "<!-- ";print_r($twitterdata);echo " -->";
242
  set_transient('rotatingtweets_wp_error',$twitterdata->get_error_messages(), 120);
243
  endif;
244
  endif;
@@ -290,11 +358,20 @@ function rotatingtweets_trigger_rate_limiting() {
290
  }
291
 
292
  # Displays the tweets
293
- function rotating_tweets_display($json,$tweet_count=5,$show_follow=FALSE,$timeout=4000,$print=TRUE,$no_show_count=FALSE,$no_show_screen_name=FALSE) {
294
  unset($result);
295
- $tweet_count = max(1,intval($tweet_count));
296
- $timeout = max(intval($timeout),0);
297
- $result = "\n<div class='rotatingtweets' id='".uniqid('rotatingtweets_'.$timeout.'_')."'>";
 
 
 
 
 
 
 
 
 
298
  if(empty($json)):
299
  $result .= "\n\t<div class = 'rotatingtweet'><p class='rtw_main'>Problem retrieving data from Twitter.</p></div>";
300
  $rate = rotatingtweets_get_rate_data();
@@ -376,9 +453,28 @@ function rotating_tweets_display($json,$tweet_count=5,$show_follow=FALSE,$timeou
376
  $after[]='<a href="http://search.twitter.com/search?q=%23$1" title="#$1">#$1</a>';
377
  $main_text = preg_replace($before,$after,$main_text);
378
  $result .= "\n\t\t<p class='rtw_main'>$main_text</p>";
379
- $result .= "\n\t\t<p class='rtw_meta'><a href='http://twitter.com/".$user->screen_name."/status/".$twitter_object->id_str."'>".ucfirst(rotatingtweets_contextualtime(strtotime($twitter_object->created_at)))."</a> from <a target='_BLANK' href='http://twitter.com/".$user->screen_name."' title=\"".$user->name."\">".$user->name."'s Twitter</a> via ".$twitter_object->source;
380
- # $result .= ' <a href="http://twitter.com/intent/tweet?in_reply_to='.$twitter_object->id_str.'" title="Reply"><img src="'.plugins_url('images/reply.png', __FILE__).'" width="16" height="16" alt="Reply" /></a> <a href="http://twitter.com/intent/retweet?tweet_id='.$twitter_object->id_str.'" title="Retweet" ><img src="'.plugins_url('images/retweet.png', __FILE__).'" width="16" height="16" alt="Retweet" /></a> <a href="http://twitter.com/intent/favorite?tweet_id='.$twitter_object->id_str.'" title="Favourite"><img src="'.plugins_url('images/favorite.png', __FILE__).'" alt="Favorite" width="16" height="16" /></a></p>';
381
- # $result .= ' &middot; <a href="http://twitter.com/intent/tweet?in_reply_to='.$twitter_object->id_str.'">reply</a> &middot; <a href="http://twitter.com/intent/retweet?tweet_id='.$twitter_object->id_str.'">retweet</a> &middot; <a href="http://twitter.com/intent/favorite?tweet_id='.$twitter_object->id_str.'">favorite</a></p>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  else:
383
  $result .= "\n\t\t<p class='rtw_main'>Problem retrieving data from Twitter.</p></div>";
384
  $result .= "<!-- rotatingtweets plugin was unable to parse this data: ".print_r($json,TRUE)." -->";
@@ -389,10 +485,10 @@ function rotating_tweets_display($json,$tweet_count=5,$show_follow=FALSE,$timeou
389
  endforeach;
390
  endif;
391
  $result .= "\n</div>";
392
- if($show_follow && !empty($user->screen_name)):
393
  unset($shortenvariables);
394
- if($no_show_count) $shortenvariables = ' data-show-count="false"';
395
- if($no_show_screen_name) $shortenvariables .= ' data-show-screen-name="false"';
396
  $result .= "\n<div class='follow-button'><a href='http://twitter.com/".$user->screen_name."' class='twitter-follow-button'{$shortenvariables} title='Follow @".$user->screen_name."'>Follow @".$user->screen_name."</a></div>";
397
  endif;
398
  wp_enqueue_script( 'jquery' );
2
  /*
3
  Plugin Name: Rotating Tweets widget & shortcode
4
  Description: Replaces a shortcode such as [rotatingtweets userid='your_twitter_name'], or a widget, with a rotating tweets display
5
+ Version: 0.500
6
  Author: Martin Tod
7
  Author URI: http://www.martintod.org.uk
8
  License: GPL2
44
  $style = get_stylesheet();
45
  switch ($style):
46
  case 'zeebizzcard':
47
+ wp_enqueue_script( 'rotating_tweet', plugins_url('js/rotating_tweet.js', __FILE__),array('jquery','zee_jquery-cycle'),FALSE,FALSE );
48
  break;
49
  default:
50
  wp_enqueue_script( 'jquery-cycle', plugins_url('js/jquery.cycle.all.js', __FILE__),array('jquery'),FALSE,FALSE );
58
  function widget($args, $instance) {
59
  extract( $args );
60
  $title = apply_filters('widget_title', $instance['title']);
61
+ $newargs['screen_name'] = $instance['tw_screen_name'];
62
+ $newargs['include_rts'] = $instance['tw_include_rts'];
63
+ $newargs['exclude_replies'] = $instance['tw_exclude_replies'];
64
+ $newargs['tweet_count'] = $instance['tw_tweet_count'];
65
+ $newargs['show_follow'] = $instance['tw_show_follow'];
66
+ $newargs['timeout'] = $instance['tw_timeout'];
67
+ $newargs['show_meta_timestamp'] = !$instance['tw_hide_meta_timestamp'];
68
+ $newargs['show_meta_screen_name'] = !$instance['tw_hide_meta_screen_name'];
69
+ $newargs['show_meta_via'] = !$instance['tw_hide_meta_via'];
70
+ $newargs['rotation_type'] = $instance['tw_rotation_type'];
71
+ $newargs['show_meta_reply_retweet_favorite'] = $instance['tw_show_meta_reply_retweet_favorite'];
72
+ switch($newargs['show_follow']) {
73
  case 2:
74
+ $newargs['no_show_count'] = TRUE;
75
+ $newargs['no_show_screen_name'] = FALSE;
76
  break;
77
  case 3:
78
+ $newargs['no_show_count'] = FALSE;
79
+ $newargs['no_show_screen_name'] = TRUE;
80
  break;
81
  case 4:
82
+ $newargs['no_show_count'] = TRUE;
83
+ $newargs['no_show_screen_name'] = TRUE;
84
  break;
85
  default:
86
+ $newargs['no_show_count'] = FALSE;
87
+ $newargs['no_show_screen_name'] = FALSE;
88
  break;
89
  }
90
+ if(empty($newargs['timeout'])) $newargs['timeout'] = 4000;
91
+ $tweets = rotatingtweets_get_tweets($newargs['screen_name'],$newargs['include_rts'],$newargs['exclude_replies']);
 
92
  ?>
93
  <?php echo $before_widget;
94
  if ( $title )
95
  echo $before_title . $title . $after_title;
96
+ rotating_tweets_display($tweets,$newargs,TRUE);
97
+ echo $after_widget;
98
+ # echo "<!-- ";print_r($newargs);echo " -->";
99
+ ?>
100
  <?php
101
  }
102
 
105
  $instance = $old_instance;
106
  $instance['title'] = strip_tags($new_instance['title']);
107
  $instance['tw_screen_name'] = strip_tags(trim($new_instance['tw_screen_name']));
108
+ $instance['tw_rotation_type'] = strip_tags(trim($new_instance['tw_rotation_type']));
109
  $instance['tw_include_rts'] = absint($new_instance['tw_include_rts']);
110
  $instance['tw_exclude_replies'] = absint($new_instance['tw_exclude_replies']);
111
  $instance['tw_tweet_count'] = max(1,intval($new_instance['tw_tweet_count']));
112
  $instance['tw_show_follow'] = absint($new_instance['tw_show_follow']);
113
+ # Complicated way to ensure the defaults remain as they were before the 0.500 upgrade - i.e. showing meta timestamp, screen name and via, but not reply, retweet, favorite
114
+ $instance['tw_hide_meta_timestamp'] = !$new_instance['tw_show_meta_timestamp'];
115
+ $instance['tw_hide_meta_screen_name'] = !$new_instance['tw_show_meta_screen_name'];
116
+ $instance['tw_hide_meta_via'] = !$new_instance['tw_show_meta_via'];
117
+ $instance['tw_show_meta_reply_retweet_favorite'] = absint($new_instance['tw_show_meta_reply_retweet_favorite']);
118
  $instance['tw_timeout'] = max(min(intval($new_instance['tw_timeout']/1000)*1000,6000),3000);
119
  return $instance;
120
  }
121
+
122
  /** @see WP_Widget::form */
123
  function form($instance) {
124
  $title = esc_attr($instance['title']);
125
  $tw_screen_name = esc_attr(trim($instance['tw_screen_name']));
126
+ $tw_rotation_type = $instance['tw_rotation_type'];
127
+ if(empty($tw_rotation_type)) $tw_rotation_type = 'scrollUp';
128
  $tw_include_rts = absint($instance['tw_include_rts']);
129
  $tw_exclude_replies = absint($instance['tw_exclude_replies']);
130
  $tw_tweet_count = intval($instance['tw_tweet_count']);
131
  $tw_show_follow = absint($instance['tw_show_follow']);
132
+ $metaoption['tw_show_meta_timestamp'] = !$instance['tw_hide_meta_timestamp'];
133
+ $metaoption['tw_show_meta_screen_name'] = !$instance['tw_hide_meta_screen_name'];
134
+ $metaoption['tw_show_meta_via'] = !$instance['tw_hide_meta_via'];
135
+ $metaoption['tw_show_meta_reply_retweet_favorite'] = absint($instance['tw_show_meta_reply_retweet_favorite']);
136
  $tw_timeout = intval($instance['tw_timeout']);
137
  # If values not set, set default values
138
  if(empty($tw_timeout)) $tw_timeout = 4000;
140
  ?>
141
  <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('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 $title; ?>" /></label></p>
142
  <p><label for="<?php echo $this->get_field_id('tw_screen_name'); ?>"><?php _e('Twitter name:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('tw_screen_name'); ?>" name="<?php echo $this->get_field_name('tw_screen_name'); ?>" value="<?php echo $tw_screen_name; ?>" /></label></p>
143
+ <p><input id="<?php echo $this->get_field_id('tw_include_rts'); ?>" name="<?php echo $this->get_field_name('tw_include_rts'); ?>" type="checkbox" value="1" <?php if($tw_include_rts==1): ?>checked="checked" <?php endif; ?>/><label for="<?php echo $this->get_field_id('tw_include_rts'); ?>"> <?php _e('Include retweets?'); ?></label></p>
144
+ <p><input id="<?php echo $this->get_field_id('tw_exclude_replies'); ?>" name="<?php echo $this->get_field_name('tw_exclude_replies'); ?>" type="checkbox" value="1" <?php if($tw_exclude_replies==1): ?>checked="checked" <?php endif; ?>/><label for="<?php echo $this->get_field_id('tw_exclude_replies'); ?>"> <?php _e('Exclude replies?'); ?></label></p>
145
  <p><label for="<?php echo $this->get_field_id('tw_tweet_count'); ?>"><?php _e('How many tweets?'); ?> <select id="<?php echo $this->get_field_id('tw_tweet_count'); ?>" name="<?php echo $this->get_field_name('tw_tweet_count');?>">
146
  <?php
147
  for ($i=1; $i<20; $i++) {
164
  echo ">$words</option>";
165
  }
166
  ?></select></label></p>
167
+ <?php
168
+ # For reference, all the rotations that look good.
169
+ # $goodRotations = array('blindX','blindY','blindZ','cover','curtainY','fade','growY','none','scrollUp','scrollDown','scrollLeft','scrollRight','scrollHorz','scrollVert','shuffle','toss','turnUp','turnDown','uncover');
170
+ $rotationoptions = array (
171
+ 'scrollUp' => 'Scroll Up',
172
+ 'scrollDown' => 'Scroll Down',
173
+ 'scrollLeft' => 'Scroll Left',
174
+ 'scrollRight' => 'Scroll Right',
175
+ 'fade' => 'Fade'
176
+ );
177
+ asort($rotationoptions);
178
+ ?>
179
+ <p><label for="<?php echo $this->get_field_id('tw_rotation_type'); ?>"><?php _e('Type of rotation'); ?> <select id="<?php echo $this->get_field_id('tw_rotation_type'); ?>" name="<?php echo $this->get_field_name('tw_rotation_type');?>">
180
+ <?php
181
+ foreach ($rotationoptions as $val => $words) {
182
+ echo "\n\t<option value='$val' ";
183
+ if($tw_rotation_type==$val): ?>selected="selected" <?php endif;
184
+ echo ">$words</option>";
185
+ }
186
+ ?></select></label></p>
187
+ <?php /* Ask about which Tweet details to show */ ?>
188
+ <p><?php _e('Show tweet details?'); ?></p><p>
189
+ <?php
190
+ $tweet_detail_options = array(
191
+ 'tw_show_meta_timestamp' => 'Time/date of tweet',
192
+ 'tw_show_meta_screen_name' => 'Name of person tweeting',
193
+ 'tw_show_meta_via' => 'Source of tweet',
194
+ 'tw_show_meta_reply_retweet_favorite' => "'reply &middot; retweet &middot; favourite' links"
195
+ );
196
+ $tw_br='';
197
+ foreach ($tweet_detail_options as $field => $text):
198
+ echo $tw_br;
199
+ ?>
200
+ <input id="<?php echo $this->get_field_id($field); ?>" name="<?php echo $this->get_field_name($field); ?>" type="checkbox" value="1" <?php if($metaoption[$field]==1): ?>checked="checked" <?php endif; ?>/><label for="<?php echo $this->get_field_id($field); ?>"> <?php _e($text); ?></label>
201
+ <?php
202
+ $tw_br = "<br />";
203
+ endforeach; ?></p>
204
  <p><?php _e('Show follow button?'); ?></p>
205
  <?php
206
  $showfollowoptions = array (
257
  $no_show_count :: [boolean] remove count from follow button
258
  $no_show_screen_name :: [boolean] remove screen name from follow button
259
  */
260
+ $args = shortcode_atts( array(
261
  'screen_name' => 'twitter',
262
  'include_rts' => FALSE,
263
  'exclude_replies' => FALSE,
265
  'show_follow' => FALSE,
266
  'timeout' => 4000,
267
  'no_show_count' => FALSE,
268
+ 'no_show_screen_name' => FALSE,
269
+ 'show_meta_timestamp' => TRUE,
270
+ 'show_meta_screen_name' => TRUE,
271
+ 'show_meta_via' => TRUE,
272
+ 'show_meta_reply_retweet_favorite' => FALSE,
273
+ 'rotation_type' => 'scrollUp'
274
+ ), $atts ) ;
275
+ extract($args);
276
+ $tweets = rotatingtweets_get_tweets($screen_name,$include_rts,$exclude_replies);
277
+ $returnstring = rotating_tweets_display($tweets,$args,FALSE);
278
  return $returnstring;
279
  }
280
  add_shortcode( 'rotatingtweets', 'rotatingtweets_display' );
281
 
282
  # Get the latest data from Twitter (or from a cache if it's been less than 2 minutes since the last load)
283
+ function rotatingtweets_get_tweets($tw_screen_name,$tw_include_rts,$tw_exclude_replies) {
284
  # Clear up variables
285
  $cache_delay = 120;
286
  if($tw_include_rts != 1) $tw_include_rts = 0;
287
  if($tw_exclude_replies != 1) $tw_exclude_replies = 0;
288
+ # $tw_tweet_count = max(1,intval($tw_tweet_count));
289
  # Get the option strong
290
  $stringname = $tw_screen_name.$tw_include_rts.$tw_exclude_replies;
291
  $optionname = "rotatingtweets-cache";
292
  $option = get_option($optionname);
293
+ # Attempt to deal with 'Cannot use string offset as an array' error
294
+ if(is_array($option)):
295
+ $latest_json = $option[$stringname]['json'];
296
+ $latest_json_date = $option[$stringname]['datetime'];
297
+ $timegap = time()-$latest_json_date;
298
+ else:
299
+ # Clears the cache and forces a reload
300
+ $timegap = $cache_delay + 1;
301
+ unset($option);
302
+ endif;
303
  $timegap = time()-$latest_json_date;
304
  if($timegap > $cache_delay):
305
  $callstring = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=".urlencode($tw_screen_name)."&include_entities=1&count=70&include_rts=".$tw_include_rts."&exclude_replies=".$tw_exclude_replies;
307
  if(!is_wp_error($twitterdata)):
308
  $twitterjson = json_decode($twitterdata['body']);
309
  else:
 
310
  set_transient('rotatingtweets_wp_error',$twitterdata->get_error_messages(), 120);
311
  endif;
312
  endif;
358
  }
359
 
360
  # Displays the tweets
361
+ function rotating_tweets_display($json,$args,$print=TRUE) {
362
  unset($result);
363
+ $tweet_count = max(1,intval($args['tweet_count']));
364
+ $timeout = max(intval($args['timeout']),0);
365
+ # Check that the rotation type is valid. If not, leave it as 'scrollUp'
366
+ $rotation_type = 'scrollUp';
367
+ # All the valid rotations - if people to use one that looks weird, that's their business!
368
+ $possibleRotations = array('blindX','blindY','blindZ','cover','curtainX','curtainY','fade','fadeZoom','growX','growY','none','scrollUp','scrollDown','scrollLeft','scrollRight','scrollHorz','scrollVert','shuffle','slideX','slideY','toss','turnUp','turnDown','turnLeft','turnRight','uncover','wipe','zoom');
369
+ foreach($possibleRotations as $possibleRotation):
370
+ if(strtolower($args['rotation_type']) == strtolower($possibleRotation)) $rotation_type = $possibleRotation;
371
+ endforeach;
372
+ # Create an ID that has all the relevant info in - rotation type and speed of rotation
373
+ $id = uniqid('rotatingtweets_'.$timeout.'_'.$rotation_type.'_');
374
+ $result = "\n<div class='rotatingtweets' id='$id'>";
375
  if(empty($json)):
376
  $result .= "\n\t<div class = 'rotatingtweet'><p class='rtw_main'>Problem retrieving data from Twitter.</p></div>";
377
  $rate = rotatingtweets_get_rate_data();
453
  $after[]='<a href="http://search.twitter.com/search?q=%23$1" title="#$1">#$1</a>';
454
  $main_text = preg_replace($before,$after,$main_text);
455
  $result .= "\n\t\t<p class='rtw_main'>$main_text</p>";
456
+ unset($meta);
457
+ if($args['show_meta_timestamp']):
458
+ $meta .= "<a href='http://twitter.com/".$user->screen_name."/status/".$twitter_object->id_str."'>".ucfirst(rotatingtweets_contextualtime(strtotime($twitter_object->created_at)))."</a>";
459
+ endif;
460
+ if($args['show_meta_screen_name']):
461
+ if(!empty($meta)) $meta .= ' ';
462
+ $meta .="from <a target='_BLANK' href='http://twitter.com/".$user->screen_name."' title=\"".$user->name."\">".$user->name."'s Twitter</a>";
463
+ endif;
464
+ if($args['show_meta_via']):
465
+ if(!empty($meta)) $meta .= ' ';
466
+ $meta .="via ".$twitter_object->source;
467
+ endif;
468
+ if($args['show_meta_reply_retweet_favorite']):
469
+ /* Code for $meta showing graphics
470
+ $meta .= ' <a href="http://twitter.com/intent/tweet?in_reply_to='.$twitter_object->id_str.'" title="Reply"><img src="'.plugins_url('images/reply.png', __FILE__).'" width="16" height="16" alt="Reply" /></a> <a href="http://twitter.com/intent/retweet?tweet_id='.$twitter_object->id_str.'" title="Retweet" ><img src="'.plugins_url('images/retweet.png', __FILE__).'" width="16" height="16" alt="Retweet" /></a> <a href="http://twitter.com/intent/favorite?tweet_id='.$twitter_object->id_str.'" title="Favourite"><img src="'.plugins_url('images/favorite.png', __FILE__).'" alt="Favorite" width="16" height="16" /></a></p>';
471
+ */
472
+ if(!empty($meta)) $meta .= ' &middot; ';
473
+ $meta .= '<a href="http://twitter.com/intent/tweet?in_reply_to='.$twitter_object->id_str.'">reply</a> &middot; <a href="http://twitter.com/intent/retweet?tweet_id='.$twitter_object->id_str.'">retweet</a> &middot; <a href="http://twitter.com/intent/favorite?tweet_id='.$twitter_object->id_str.'">favorite</a>';
474
+ endif;
475
+ if(!empty($meta)):
476
+ $result .= "\n\t\t<p class='rtw_meta'>".ucfirst($meta)."</p>";
477
+ endif;
478
  else:
479
  $result .= "\n\t\t<p class='rtw_main'>Problem retrieving data from Twitter.</p></div>";
480
  $result .= "<!-- rotatingtweets plugin was unable to parse this data: ".print_r($json,TRUE)." -->";
485
  endforeach;
486
  endif;
487
  $result .= "\n</div>";
488
+ if($args['show_follow'] && !empty($user->screen_name)):
489
  unset($shortenvariables);
490
+ if($args['no_show_count']) $shortenvariables = ' data-show-count="false"';
491
+ if($args['no_show_screen_name']) $shortenvariables .= ' data-show-screen-name="false"';
492
  $result .= "\n<div class='follow-button'><a href='http://twitter.com/".$user->screen_name."' class='twitter-follow-button'{$shortenvariables} title='Follow @".$user->screen_name."'>Follow @".$user->screen_name."</a></div>";
493
  endif;
494
  wp_enqueue_script( 'jquery' );
screenshot-2.png CHANGED
Binary file