Changeset 588909
- Timestamp:
- 08/22/2012 03:53:12 PM (14 years ago)
- Location:
- widget-embed-lastest-tweets/trunk
- Files:
-
- 4 added
- 3 edited
-
README.md (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
twitteroauth (added)
-
twitteroauth/OAuth.php (added)
-
twitteroauth/twitteroauth.php (added)
-
welt-option.php (added)
-
widget-embed-latest-tweets.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
widget-embed-lastest-tweets/trunk/README.md
r586780 r588909 2 2 3 3 A Widget to show your latest tweets. Use the oEmbed methode and some cache. It is simple, elegant and it works. 4 Just type your Twitter username. 4 5 You can authentified your widget and get rid of the Twitter's API limitation from anonymous request. See the option page of the plugin : plugins -> Widget Embed Latest Tweets 5 6 6 7 Options : 8 7 9 * number of tweet to display 8 10 * Maximum width -
widget-embed-lastest-tweets/trunk/readme.txt
r586839 r588909 14 14 15 15 A Widget to show your latest tweets. Use the oEmbed methode and some cache. It is simple, elegant and it works. 16 Just type your Twitter username. 16 17 You can authentified your widget and get rid of the Twitter's API limitation from anonymous request. See the option page of the plugin : plugins -> Widget Embed Latest Tweets 17 18 18 19 Options : 20 19 21 * number of tweet to display 20 22 * Maximum width 21 23 * Alignment (left, right, center, none) 24 * Choose your language 25 * Hide the original message in the case that the embedded Tweet is a reply 22 26 23 27 Note that with the oEmbed method you can not customise easily the display of your tweet. … … 45 49 == Changelog == 46 50 51 = 0.3 = 52 53 * You can authentified your widget and get read of the Twitter's API limitation from anonymous request 54 * Choose your language 55 * Hide the original message in the case that the embedded Tweet is a reply 56 47 57 = 0.2 = 48 Don't show Warning in case of error 58 59 * Don't show Warning in case of error 49 60 50 61 = 0.1 = 51 This is the first version. 52 Choose the number of tweet, the maximum width and alignment 62 63 * This is the first version. 64 * Choose the number of tweet, the maximum width and alignment 53 65 54 66 == Upgrade Notice == -
widget-embed-lastest-tweets/trunk/widget-embed-latest-tweets.php
r586839 r588909 1 1 <?php 2 2 /* 3 * Plugin Name: Widget embed la stest Tweets3 * Plugin Name: Widget embed latest Tweets 4 4 * Plugin URI: http://www.arnaudbanvillet.com/blog/portfolio/widget-embed-latest-tweets/ 5 5 * Description: A Widget to show your latest tweets. Use the oEmbed methode and some cache. It is simple, elegant and it works. Just type your user name and the numbers of tweets you want to show. 6 * Version: 0. 26 * Version: 0.3 7 7 * Author: Arnaud Banvillet 8 8 * Author URI: http://www.arnaudbanvillet.com … … 29 29 30 30 var $defaut = array( 31 'nb-tweets' => 3, 32 'align' => 'none' 31 'title' => 'Last Tweet', 32 'count' => 3, 33 'align' => 'none', 34 'hide_thread' => true, 35 'lang' => 'en', 36 'include_rts' => true 33 37 ); 34 var $align_possible_value = array('left', 'right', 'center', 'none'); 38 39 var $align_possible_value = array('none', 'left', 'right', 'center'); 35 40 36 41 /** … … 40 45 parent::__construct( 41 46 'last_tweets', // Base ID 42 'Widget embed la stet Tweets', // Name43 array('description' => __('Show your la st tweets', 'ab-welt-locales'))// Args47 'Widget embed latest Tweets', // Name 48 array('description' => __('Show your latest tweets', 'ab-welt-locales'))// Args 44 49 ); 45 50 } … … 67 72 echo $before_title . $title . $after_title; 68 73 69 if ($user_name){74 if( !empty( $screen_name ) ){ 70 75 71 76 $last_tweet = get_transient('last_tweet'); … … 73 78 if (false === $last_tweet) { 74 79 75 $options = array( 76 'nb_tweets' => $nb_tweets, 77 'maxwidth' => $maxwidth, 78 'align' => $align 79 ); 80 81 82 $this->welt_set_tweet_transient($user_name, $options); 80 81 $this->welt_set_tweet_transient( $instance ); 83 82 84 83 … … 120 119 $instance = wp_parse_args($instance, $this->defaut); 121 120 122 $nb_tweet = strip_tags($new_instance['nb_tweets']); 121 $instance['title'] = strip_tags($new_instance['title']); 122 123 $instance['screen_name'] = strip_tags($new_instance['screen_name']); 124 125 $count = strip_tags($new_instance['count']); 126 127 if( is_numeric($count)) 128 $instance['count'] = $count ; 129 123 130 $maxwidth = strip_tags($new_instance['maxwidth']); 124 125 $instance['title'] = strip_tags($new_instance['title']);126 $instance['user_name'] = strip_tags($new_instance['user_name']);127 128 if( is_numeric( $nb_tweet ) )129 $instance['nb_tweets'] = $nb_tweet;130 131 if( is_numeric( $maxwidth ) ) 131 132 $instance['maxwidth'] = $maxwidth; 132 133 134 133 135 if(in_array($new_instance['align'], $this->align_possible_value )) 134 136 $instance['align'] = $new_instance['align']; 135 137 136 $options = array( 137 'nb_tweets' => $instance['nb_tweets'], 138 'maxwidth' => $instance['maxwidth'], 139 'align' => $instance['align'] 140 ); 141 $this->welt_set_tweet_transient( $instance['user_name'], $options , true); 138 $instance['hide_thread'] = $new_instance['hide_thread'] == 'hide_thread'; 139 140 $instance['lang'] = strip_tags($new_instance['lang']); 141 142 $this->welt_set_tweet_transient( $instance , true); 142 143 143 144 return $instance; … … 152 153 */ 153 154 public function form($instance) { 154 if ($instance) { 155 $title = esc_attr($instance['title']); 156 $user_name = esc_attr($instance['user_name']); 157 $nb_tweets = esc_attr($instance['nb_tweets']); 158 $maxwidth = esc_attr($instance['maxwidth']); 159 $align = $instance['align']; 160 } else { 161 $title = 'Last Tweet'; 162 } 155 156 $instance = wp_parse_args($instance, $this->defaut); 157 extract($instance); 158 163 159 ?> 164 160 <p> … … 168 164 169 165 <p> 170 <label for="<?php echo $this->get_field_id(' user_name'); ?>"><?php _e('Twitter Usernam :', 'ab-welt-locales') ?></label>171 <input class="widefat" id="<?php echo $this->get_field_id(' user_name'); ?>" name="<?php echo $this->get_field_name('user_name'); ?>" type="text" value="<?php echo $user_name; ?>" />172 </p> 173 174 <p> 175 <label for="<?php echo $this->get_field_id(' nb_tweets'); ?>"><?php _e('Number of tweet to dislay :', 'ab-welt-locales') ?></label>176 <input id="<?php echo $this->get_field_id(' nb_tweets'); ?>" name="<?php echo $this->get_field_name('nb_tweets'); ?>" type="number" step="1" min="1" max="20" value="<?php echo $nb_tweets; ?>" />166 <label for="<?php echo $this->get_field_id('screen_name'); ?>"><?php _e('Twitter Usernam :', 'ab-welt-locales') ?></label> 167 <input class="widefat" id="<?php echo $this->get_field_id('screen_name'); ?>" name="<?php echo $this->get_field_name('screen_name'); ?>" type="text" value="<?php echo $screen_name; ?>" /> 168 </p> 169 170 <p> 171 <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Number of tweet to dislay :', 'ab-welt-locales') ?></label> 172 <input id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="number" step="1" min="1" max="20" value="<?php echo $count; ?>" /> 177 173 </p> 178 174 … … 190 186 </select> 191 187 </p> 188 189 <p> 190 <label for="<?php echo $this->get_field_id('hide_thread'); ?>"><?php _e('Hide Thread :', 'ab-welt-locales') ?></label> 191 <input id="<?php echo $this->get_field_id('hide_thread'); ?>" name="<?php echo $this->get_field_name('hide_thread'); ?>" type="checkbox" <?php checked( $hide_thread ) ?> value="hide_thread"/> 192 <br /> 193 <span class="description"><?php _e('Hide the original message in the case that the embedded Tweet is a reply') ?></span> 194 </p> 195 196 <p> 197 <label for="<?php echo $this->get_field_id('lang'); ?>"><?php _e('Language :', 'ab-welt-locales') ?></label> 198 <input id="<?php echo $this->get_field_id('lang'); ?>" name="<?php echo $this->get_field_name('lang'); ?>" type="text" value="<?php echo $lang; ?>" size="2"/> 199 <br /> 200 <span class="description"><?php _e('Two firsts caractere only. Example : "fr" for french') ?></span> 201 </p> 202 <?php if( get_option('welt_twitter_authentification') ) { ?> 203 <p class="description"> 204 <?php _e('You are authentified', 'ab-welt-locales'); ?> 205 </p> 192 206 <?php 207 } 208 209 //var_dump( get_option('welt_twitter_http_hreader') ); 193 210 } 194 211 … … 197 214 * And the page load faster with this cache. 198 215 * 199 * @param string $user_name200 216 * @param array $options 201 217 * @param boolean $update 202 218 */ 203 private function welt_set_tweet_transient( $user_name, $options, $update = false){ 204 205 extract( $options ); 206 207 $embed_options = ''; 208 209 if( !empty( $maxwidth ) ) 210 $embed_options .= '&maxwidth=' . $maxwidth; 211 if( !empty( $align ) ) 212 $embed_options .= '&align=' . $align; 213 214 // We use the GET statuses/user_timeline to get the latest tweet 215 // https://dev.twitter.com/docs/api/1/get/statuses/oembed 216 $last_tweet = @file_get_contents('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $user_name . '&count=' . $nb_tweets . '&include_rts=1'); 217 218 219 if( $last_tweet == false ){ 219 private function welt_set_tweet_transient( $options, $update = false){ 220 221 extract($options); 222 223 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 224 225 226 //Check if wee use the authentification methode. We need to have all the key and secret. 227 $oauth_methode = ! in_array("", $twitter_oauth_var); 228 229 230 //The authentification methode 231 if( $oauth_methode ){ 232 $connection = new TwitterOAuth($twitter_oauth_var[consumer_key], $twitter_oauth_var[consumer_secret], $twitter_oauth_var[token_key],$twitter_oauth_var[token_secret]); 233 234 $last_tweet = $connection->get('http://api.twitter.com/1/statuses/user_timeline.json', $options ); 235 236 } else { 237 // We use the GET statuses/user_timeline to get the latest tweet 238 // https://dev.twitter.com/docs/api/1/get/statuses/oembed 239 $last_tweet = @file_get_contents('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $screen_name . '&count=' . $count . '&include_rts=1'); 240 $last_tweet = json_decode($last_tweet); 241 } 242 243 if( $last_tweet == false || empty( $last_tweet )){ 220 244 delete_transient( 'last_tweet' ); 221 245 return; 222 246 } 223 247 224 $last_tweet = json_decode($last_tweet);225 226 227 248 set_transient('last_tweet', $last_tweet, 60 * 5); 228 249 229 250 foreach ($last_tweet as $tweet) { 230 251 252 $id = $tweet->id_str; 253 231 254 232 255 if( $update || get_transient('last_tweet_html_' . $id)){ 233 256 234 $id = $tweet->id_str; 235 236 // We use the GET statuses/oembed API to get the html to display 237 // https://dev.twitter.com/docs/api/1/get/statuses/oembed 238 $last_tweet_html = @file_get_contents('https://api.twitter.com/1/statuses/oembed.json?id=' . $id . $embed_options); 239 $last_tweet_html = json_decode($last_tweet_html); 257 258 if( $oauth_methode ){ 259 260 $options['id'] = $id; 261 $last_tweet_html = $connection->get('https://api.twitter.com/1/statuses/oembed.json', $options); 262 263 $welt_twitter_http_hreader = $connection->http_info; 264 265 update_option('welt_twitter_authentification', true); 266 267 } else { 268 269 // We use the GET statuses/oembed API to get the html to display 270 // https://dev.twitter.com/docs/api/1/get/statuses/oembed 271 $last_tweet_html = @file_get_contents('https://api.twitter.com/1/statuses/oembed.json?id=' . $id . $embed_options); 272 $last_tweet_html = json_decode($last_tweet_html); 273 274 $welt_twitter_http_hreader = $http_response_header; 275 276 update_option('welt_twitter_authentification', false); 277 } 278 240 279 set_transient('last_tweet_html_' . $id, $last_tweet_html, 60 * 60 * 24); 241 280 … … 243 282 244 283 } 245 } 246 284 285 update_option('welt_twitter_http_hreader', $welt_twitter_http_hreader); 286 287 } 247 288 } 248 289 249 290 add_action('widgets_init', create_function('', 'register_widget( "Widget_Embed_Latest_Tweets" );')); 291 292 //Files needed for the Twitter authentification 293 require_once 'twitteroauth/OAuth.php'; 294 require_once 'twitteroauth/twitteroauth.php'; 295 require_once 'welt-option.php';
Note: See TracChangeset
for help on using the changeset viewer.