Changeset 668718
- Timestamp:
- 02/15/2013 10:11:55 PM (13 years ago)
- Location:
- widget-embed-lastest-tweets
- Files:
-
- 4 added
- 6 edited
- 1 copied
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-2.png (modified) (previous)
-
tags/0.4 (copied) (copied from widget-embed-lastest-tweets/trunk)
-
tags/0.4/js (added)
-
tags/0.4/js/welt-scripts.js (added)
-
tags/0.4/readme.txt (modified) (5 diffs)
-
tags/0.4/widget-embed-latest-tweets.php (modified) (8 diffs)
-
trunk/js (added)
-
trunk/js/welt-scripts.js (added)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/widget-embed-latest-tweets.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
widget-embed-lastest-tweets/tags/0.4/readme.txt
r624528 r668718 3 3 Tags: twitter, widget, embed 4 4 Requires at least: 3 5 Tested up to: 3. 4.25 Tested up to: 3.5.1 6 6 Stable tag: trunk 7 7 License: GPLv2 … … 9 9 10 10 A Widget to show your latest Tweets. 11 Just type your Twitter username. 11 Visit the option page "Plugins->Widget Embed Last Plugin" to authentify yourself 12 12 13 13 14 == Description == … … 15 16 A Widget to show your latest tweets. Use the oEmbed methode and some cache. It is simple, elegant and it works. 16 17 17 You can authentify 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 18 This plugin uses the Twitter API version 1.1. You have to authentify yourself ! 19 Visit the option page "Plugins->Widget Embed Last Plugin" to do so. 18 20 19 21 Options : … … 24 26 * Choose your language 25 27 * Hide the original message in the case that the embedded Tweet is a reply 28 * Hide images in the Tweet 26 29 27 30 Note that with the oEmbed method you can not customise easily the display of your Tweet. … … 56 59 57 60 == Changelog == 61 62 = 0.4 = 63 64 **Importante update** 65 Be careful, the plugin uses the new API version 1.1 66 This mean that you have to authentify yourself 67 68 * update to API version 1.1 69 * use AJAX to load the page faster 58 70 59 71 = 0.3.7 = -
widget-embed-lastest-tweets/tags/0.4/widget-embed-latest-tweets.php
r624528 r668718 3 3 * Plugin Name: Widget embed latest Tweets 4 4 * Plugin URI: http://www.arnaudbanvillet.com/blog/portfolio/widget-embed-latest-tweets/ 5 * Description: A Widget to show your latest Tweets. Use the oEmbed methode and some cache. 6 * Version: 0. 3.75 * Description: A Widget to show your latest Tweets. Use the oEmbed methode and some cache. Visit the option page "Plugins->Widget Embed Last Plugin" to authentify yourself 6 * Version: 0.4 7 7 * Author: Arnaud Banvillet 8 8 * Author URI: http://www.arnaudbanvillet.com … … 29 29 30 30 var $defaut = array( 31 'title' => 'Last Tweet', 32 'count' => 3, 33 'align' => 'none', 34 'hide_thread' => true, 35 'lang' => 'en', 36 'include_rts' => true 31 'title' => 'Last Tweet', 32 'count' => 3, 33 'align' => 'none', 34 'hide_thread' => true, 35 'lang' => 'en', 36 'include_rts' => true, 37 'hide_media' => true 37 38 ); 38 39 … … 44 45 public function __construct() { 45 46 parent::__construct( 46 ' last_tweets', // Base ID47 'welt_last_tweets', // Base ID 47 48 'Widget embed latest Tweets', // Name 48 49 array('description' => __('Show your latest Tweets', 'ab-welt-locales'))// Args … … 69 70 echo $before_widget; 70 71 71 if ( !empty($title))72 if ( !empty( $title ) ) 72 73 echo $before_title . $title . $after_title; 73 74 74 if( !empty( $screen_name ) ){ 75 76 $last_tweet = get_transient('last_tweet_' . $this->id); 77 78 if (false === $last_tweet) { 79 80 81 $this->welt_set_tweet_transient( $instance, false ); 82 83 84 $last_tweet = get_transient('last_tweet_' .$this->id); 85 86 } 87 88 if( $last_tweet != false ){ 89 90 foreach ($last_tweet as $tweet) { 91 92 $tweet_id = $tweet->id_str; 93 94 $last_tweet_html = get_transient('last_tweet_html_' . $tweet_id); 95 96 echo $last_tweet_html->html; 97 } 98 } else { 99 _e('Error: Twitter did not respond. Please wait a few minutes and refresh this page.', 'ab-welt-locales'); 100 } 101 } 75 if( !empty( $screen_name ) ) 76 echo '<div id="welt-' . $this->id . '" class="welt-tweet-wrapper"></div>'; 102 77 103 78 echo $after_widget; … … 137 112 138 113 $instance['hide_thread'] = $new_instance['hide_thread'] == 'hide_thread'; 114 $instance['hide_media'] = $new_instance['hide_media'] == 'hide_media'; 139 115 140 116 $instance['lang'] = strip_tags($new_instance['lang']); 141 117 142 $this->welt_set_tweet_transient( $instance , true ); 118 //When everythings is check, set the transient 119 welt_set_tweet_transient( $this->id, $instance , true ); 143 120 144 121 return $instance; … … 194 171 <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"/> 195 172 <br /> 196 <span class="description"><?php _e('Hide the original message in the case that the embedded Tweet is a reply') ?></span> 173 <span class="description"><?php _e('Hide the original message in the case that the embedded Tweet is a reply', 'ab-welt-locales') ?></span> 174 </p> 175 <p> 176 <label for="<?php echo $this->get_field_id('hide_media'); ?>"><?php _e('Hide Media', 'ab-welt-locales') ?> :</label> 177 <input id="<?php echo $this->get_field_id('hide_media'); ?>" name="<?php echo $this->get_field_name('hide_media'); ?>" type="checkbox" <?php checked( $hide_media ) ?> value="hide_media"/> 178 <br /> 179 <span class="description"><?php _e('Hide the images in the Tweet' , 'ab-welt-locales') ?></span> 197 180 </p> 198 181 … … 203 186 <span class="description"><?php _e('Two firsts caractere only. Example : "fr" for french') ?></span> 204 187 </p> 205 <?php if( get_option('welt_twitter_authentification') ) { ?>206 <p class="description">207 <?php _e('You are authentified', 'ab-welt-locales'); ?>208 </p>209 188 <?php 210 } 211 } 212 213 /** 214 * Cache the twitter json file. Twitter say "Store API responses in your application or on your site" 215 * And the page load faster with this cache. 216 * 217 * @param array $options 218 * @param boolean $update 219 */ 220 private function welt_set_tweet_transient( $options, $update = false){ 221 222 extract($options); 223 224 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 225 226 227 //Check if wee use the authentification methode. We need to have all the key and secret. 228 $oauth_methode = ($twitter_oauth_var == false) ? false : ! in_array("", $twitter_oauth_var); 229 230 231 //The authentification methode 232 if( $oauth_methode ){ 233 $connection = new TwitterOAuth($twitter_oauth_var['consumer_key'], $twitter_oauth_var['consumer_secret'], $twitter_oauth_var['token_key'],$twitter_oauth_var['token_secret']); 234 $last_tweet = $connection->get('http://api.twitter.com/1/statuses/user_timeline.json', $options ); 235 189 } 190 191 } 192 193 add_action('widgets_init', create_function('', 'register_widget( "Widget_Embed_Latest_Tweets" );')); 194 195 196 /** 197 * Cache the twitter json file. Twitter say "Store API responses in your application or on your site" 198 * And the page load faster with this cache. 199 * 200 * @param array $options 201 * @param boolean $update 202 */ 203 function welt_set_tweet_transient( $widget_id, $options, $update = false){ 204 205 $return_value = false; 206 207 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 208 209 //Check if wee use the authentification methode. We need to have all the key and secret. 210 if( is_array( $twitter_oauth_var ) && count($twitter_oauth_var) == 4 ){ 211 212 $connection = new TwitterOAuth($twitter_oauth_var['consumer_key'], $twitter_oauth_var['consumer_secret'], $twitter_oauth_var['token_key'],$twitter_oauth_var['token_secret']); 213 $last_tweet = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json', $options ); 214 215 // if there is an error 216 if( isset( $last_tweet->errors ) ){ 217 218 delete_transient( 'last_tweet_' . $widget_id ); 219 $return_value = $last_tweet->errors[0]->message; 220 221 // If there is nothing 222 } elseif( $last_tweet == false || empty( $last_tweet )){ 223 224 delete_transient( 'last_tweet_' . $widget_id ); 225 $return_value = false; 226 227 // It should be ok 236 228 } 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 )){ 244 delete_transient( 'last_tweet' ); 245 return; 246 } 247 248 set_transient('last_tweet_' . $this->id , $last_tweet, 60 * 5); 249 250 foreach ($last_tweet as $tweet) { 251 252 $id = $tweet->id_str; 253 254 255 if( $update || ! get_transient('last_tweet_html_' . $id)){ 256 257 258 if( $oauth_methode ){ 229 230 $return_value = $last_tweet; 231 232 set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5); 233 234 foreach ($last_tweet as $tweet) { 235 236 $id = $tweet->id_str; 237 238 239 if( $update || ! get_transient('last_tweet_html_' . $id)){ 240 259 241 260 242 $options['id'] = $id; … … 264 246 } 265 247 266 $last_tweet_html = $connection->get('https://api.twitter.com/1/statuses/oembed.json', $options); 267 268 269 update_option('welt_twitter_authentification', true); 270 271 } else { 272 273 // We use the GET statuses/oembed API to get the html to display 274 // https://dev.twitter.com/docs/api/1/get/statuses/oembed 275 $option_string = 'id=' . $id . '&align=' . $align . '&hide_thread='. $hide_thread .'&lang=' . $lang; 276 277 if( is_numeric( $maxwidth) ){ 278 $option_string .= '&maxwidth=' . $maxwidth; 279 } 280 281 $last_tweet_html = @file_get_contents('https://api.twitter.com/1/statuses/oembed.json?' . $option_string); 282 $last_tweet_html = json_decode($last_tweet_html); 283 284 update_option('welt_twitter_authentification', false); 248 $last_tweet_html = $connection->get('https://api.twitter.com/1.1/statuses/oembed.json', $options); 249 250 251 set_transient('last_tweet_html_' . $id, $last_tweet_html ); 252 285 253 } 286 287 set_transient('last_tweet_html_' . $id, $last_tweet_html, 60 * 60 * 24);288 289 254 } 290 291 255 } 292 293 } 294 } 295 296 add_action('widgets_init', create_function('', 'register_widget( "Widget_Embed_Latest_Tweets" );')); 256 } 257 258 return $return_value; 259 } 260 261 262 /** 263 * The function callback in ajax to display Tweet 264 */ 265 function welt_display_tweets( ){ 266 267 $widget_id = $_POST['widget_id']; 268 269 $tweet_html = ''; 270 271 $last_tweet = get_transient('last_tweet_' . $widget_id); 272 273 274 if( false === $last_tweet ) { 275 276 // Get the widget instance 277 $all_instance_widget = get_option('widget_welt_last_tweets'); 278 279 $widget_real_id = str_replace('welt_last_tweets-', '', $widget_id); 280 281 $instance = $all_instance_widget[$widget_real_id]; 282 283 // Set the transient for this widget 284 $last_tweet = welt_set_tweet_transient( $widget_id, $instance, false ); 285 286 } 287 288 if( is_string( $last_tweet ) ){ // It is a error 289 290 echo $last_tweet; 291 292 } elseif ( $last_tweet != false ){ 293 294 foreach ($last_tweet as $tweet) { 295 296 $tweet_id = $tweet->id_str; 297 298 $last_tweet_html = get_transient('last_tweet_html_' . $tweet_id); 299 300 $tweet_html .= $last_tweet_html->html; 301 302 } 303 } else { 304 $tweet_html = __('Error: Twitter did not respond. Please wait a few minutes and refresh this page.', 'ab-welt-locales'); 305 } 306 307 308 echo $tweet_html; 309 die; 310 } 311 312 add_action('wp_ajax_welt_display_tweets', 'welt_display_tweets'); 313 add_action('wp_ajax_nopriv_welt_display_tweets', 'welt_display_tweets'); 314 315 316 /** 317 * Enqueue welt script and Twitter Script 318 */ 319 function welt_enqueue_scripts(){ 320 // welt 321 wp_enqueue_script('welt_script', plugins_url('/js/welt-scripts.js', __FILE__) , array( 'jquery' ), '20130129', true ); 322 wp_localize_script( 'welt_script', 'ajaxurl', admin_url('admin-ajax.php') ); 323 324 } 325 add_action('wp_enqueue_scripts', 'welt_enqueue_scripts'); 297 326 298 327 //Files needed for the Twitter authentification -
widget-embed-lastest-tweets/trunk/readme.txt
r624528 r668718 3 3 Tags: twitter, widget, embed 4 4 Requires at least: 3 5 Tested up to: 3. 4.25 Tested up to: 3.5.1 6 6 Stable tag: trunk 7 7 License: GPLv2 … … 9 9 10 10 A Widget to show your latest Tweets. 11 Just type your Twitter username. 11 Visit the option page "Plugins->Widget Embed Last Plugin" to authentify yourself 12 12 13 13 14 == Description == … … 15 16 A Widget to show your latest tweets. Use the oEmbed methode and some cache. It is simple, elegant and it works. 16 17 17 You can authentify 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 18 This plugin uses the Twitter API version 1.1. You have to authentify yourself ! 19 Visit the option page "Plugins->Widget Embed Last Plugin" to do so. 18 20 19 21 Options : … … 24 26 * Choose your language 25 27 * Hide the original message in the case that the embedded Tweet is a reply 28 * Hide images in the Tweet 26 29 27 30 Note that with the oEmbed method you can not customise easily the display of your Tweet. … … 56 59 57 60 == Changelog == 61 62 = 0.4 = 63 64 **Importante update** 65 Be careful, the plugin uses the new API version 1.1 66 This mean that you have to authentify yourself 67 68 * update to API version 1.1 69 * use AJAX to load the page faster 58 70 59 71 = 0.3.7 = -
widget-embed-lastest-tweets/trunk/widget-embed-latest-tweets.php
r624528 r668718 3 3 * Plugin Name: Widget embed latest Tweets 4 4 * Plugin URI: http://www.arnaudbanvillet.com/blog/portfolio/widget-embed-latest-tweets/ 5 * Description: A Widget to show your latest Tweets. Use the oEmbed methode and some cache. 6 * Version: 0. 3.75 * Description: A Widget to show your latest Tweets. Use the oEmbed methode and some cache. Visit the option page "Plugins->Widget Embed Last Plugin" to authentify yourself 6 * Version: 0.4 7 7 * Author: Arnaud Banvillet 8 8 * Author URI: http://www.arnaudbanvillet.com … … 29 29 30 30 var $defaut = array( 31 'title' => 'Last Tweet', 32 'count' => 3, 33 'align' => 'none', 34 'hide_thread' => true, 35 'lang' => 'en', 36 'include_rts' => true 31 'title' => 'Last Tweet', 32 'count' => 3, 33 'align' => 'none', 34 'hide_thread' => true, 35 'lang' => 'en', 36 'include_rts' => true, 37 'hide_media' => true 37 38 ); 38 39 … … 44 45 public function __construct() { 45 46 parent::__construct( 46 ' last_tweets', // Base ID47 'welt_last_tweets', // Base ID 47 48 'Widget embed latest Tweets', // Name 48 49 array('description' => __('Show your latest Tweets', 'ab-welt-locales'))// Args … … 69 70 echo $before_widget; 70 71 71 if ( !empty($title))72 if ( !empty( $title ) ) 72 73 echo $before_title . $title . $after_title; 73 74 74 if( !empty( $screen_name ) ){ 75 76 $last_tweet = get_transient('last_tweet_' . $this->id); 77 78 if (false === $last_tweet) { 79 80 81 $this->welt_set_tweet_transient( $instance, false ); 82 83 84 $last_tweet = get_transient('last_tweet_' .$this->id); 85 86 } 87 88 if( $last_tweet != false ){ 89 90 foreach ($last_tweet as $tweet) { 91 92 $tweet_id = $tweet->id_str; 93 94 $last_tweet_html = get_transient('last_tweet_html_' . $tweet_id); 95 96 echo $last_tweet_html->html; 97 } 98 } else { 99 _e('Error: Twitter did not respond. Please wait a few minutes and refresh this page.', 'ab-welt-locales'); 100 } 101 } 75 if( !empty( $screen_name ) ) 76 echo '<div id="welt-' . $this->id . '" class="welt-tweet-wrapper"></div>'; 102 77 103 78 echo $after_widget; … … 137 112 138 113 $instance['hide_thread'] = $new_instance['hide_thread'] == 'hide_thread'; 114 $instance['hide_media'] = $new_instance['hide_media'] == 'hide_media'; 139 115 140 116 $instance['lang'] = strip_tags($new_instance['lang']); 141 117 142 $this->welt_set_tweet_transient( $instance , true ); 118 //When everythings is check, set the transient 119 welt_set_tweet_transient( $this->id, $instance , true ); 143 120 144 121 return $instance; … … 194 171 <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"/> 195 172 <br /> 196 <span class="description"><?php _e('Hide the original message in the case that the embedded Tweet is a reply') ?></span> 173 <span class="description"><?php _e('Hide the original message in the case that the embedded Tweet is a reply', 'ab-welt-locales') ?></span> 174 </p> 175 <p> 176 <label for="<?php echo $this->get_field_id('hide_media'); ?>"><?php _e('Hide Media', 'ab-welt-locales') ?> :</label> 177 <input id="<?php echo $this->get_field_id('hide_media'); ?>" name="<?php echo $this->get_field_name('hide_media'); ?>" type="checkbox" <?php checked( $hide_media ) ?> value="hide_media"/> 178 <br /> 179 <span class="description"><?php _e('Hide the images in the Tweet' , 'ab-welt-locales') ?></span> 197 180 </p> 198 181 … … 203 186 <span class="description"><?php _e('Two firsts caractere only. Example : "fr" for french') ?></span> 204 187 </p> 205 <?php if( get_option('welt_twitter_authentification') ) { ?>206 <p class="description">207 <?php _e('You are authentified', 'ab-welt-locales'); ?>208 </p>209 188 <?php 210 } 211 } 212 213 /** 214 * Cache the twitter json file. Twitter say "Store API responses in your application or on your site" 215 * And the page load faster with this cache. 216 * 217 * @param array $options 218 * @param boolean $update 219 */ 220 private function welt_set_tweet_transient( $options, $update = false){ 221 222 extract($options); 223 224 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 225 226 227 //Check if wee use the authentification methode. We need to have all the key and secret. 228 $oauth_methode = ($twitter_oauth_var == false) ? false : ! in_array("", $twitter_oauth_var); 229 230 231 //The authentification methode 232 if( $oauth_methode ){ 233 $connection = new TwitterOAuth($twitter_oauth_var['consumer_key'], $twitter_oauth_var['consumer_secret'], $twitter_oauth_var['token_key'],$twitter_oauth_var['token_secret']); 234 $last_tweet = $connection->get('http://api.twitter.com/1/statuses/user_timeline.json', $options ); 235 189 } 190 191 } 192 193 add_action('widgets_init', create_function('', 'register_widget( "Widget_Embed_Latest_Tweets" );')); 194 195 196 /** 197 * Cache the twitter json file. Twitter say "Store API responses in your application or on your site" 198 * And the page load faster with this cache. 199 * 200 * @param array $options 201 * @param boolean $update 202 */ 203 function welt_set_tweet_transient( $widget_id, $options, $update = false){ 204 205 $return_value = false; 206 207 $twitter_oauth_var = get_option('welt_twitter_oauth_var'); 208 209 //Check if wee use the authentification methode. We need to have all the key and secret. 210 if( is_array( $twitter_oauth_var ) && count($twitter_oauth_var) == 4 ){ 211 212 $connection = new TwitterOAuth($twitter_oauth_var['consumer_key'], $twitter_oauth_var['consumer_secret'], $twitter_oauth_var['token_key'],$twitter_oauth_var['token_secret']); 213 $last_tweet = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json', $options ); 214 215 // if there is an error 216 if( isset( $last_tweet->errors ) ){ 217 218 delete_transient( 'last_tweet_' . $widget_id ); 219 $return_value = $last_tweet->errors[0]->message; 220 221 // If there is nothing 222 } elseif( $last_tweet == false || empty( $last_tweet )){ 223 224 delete_transient( 'last_tweet_' . $widget_id ); 225 $return_value = false; 226 227 // It should be ok 236 228 } 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 )){ 244 delete_transient( 'last_tweet' ); 245 return; 246 } 247 248 set_transient('last_tweet_' . $this->id , $last_tweet, 60 * 5); 249 250 foreach ($last_tweet as $tweet) { 251 252 $id = $tweet->id_str; 253 254 255 if( $update || ! get_transient('last_tweet_html_' . $id)){ 256 257 258 if( $oauth_methode ){ 229 230 $return_value = $last_tweet; 231 232 set_transient('last_tweet_' . $widget_id , $last_tweet, 60 * 5); 233 234 foreach ($last_tweet as $tweet) { 235 236 $id = $tweet->id_str; 237 238 239 if( $update || ! get_transient('last_tweet_html_' . $id)){ 240 259 241 260 242 $options['id'] = $id; … … 264 246 } 265 247 266 $last_tweet_html = $connection->get('https://api.twitter.com/1/statuses/oembed.json', $options); 267 268 269 update_option('welt_twitter_authentification', true); 270 271 } else { 272 273 // We use the GET statuses/oembed API to get the html to display 274 // https://dev.twitter.com/docs/api/1/get/statuses/oembed 275 $option_string = 'id=' . $id . '&align=' . $align . '&hide_thread='. $hide_thread .'&lang=' . $lang; 276 277 if( is_numeric( $maxwidth) ){ 278 $option_string .= '&maxwidth=' . $maxwidth; 279 } 280 281 $last_tweet_html = @file_get_contents('https://api.twitter.com/1/statuses/oembed.json?' . $option_string); 282 $last_tweet_html = json_decode($last_tweet_html); 283 284 update_option('welt_twitter_authentification', false); 248 $last_tweet_html = $connection->get('https://api.twitter.com/1.1/statuses/oembed.json', $options); 249 250 251 set_transient('last_tweet_html_' . $id, $last_tweet_html ); 252 285 253 } 286 287 set_transient('last_tweet_html_' . $id, $last_tweet_html, 60 * 60 * 24);288 289 254 } 290 291 255 } 292 293 } 294 } 295 296 add_action('widgets_init', create_function('', 'register_widget( "Widget_Embed_Latest_Tweets" );')); 256 } 257 258 return $return_value; 259 } 260 261 262 /** 263 * The function callback in ajax to display Tweet 264 */ 265 function welt_display_tweets( ){ 266 267 $widget_id = $_POST['widget_id']; 268 269 $tweet_html = ''; 270 271 $last_tweet = get_transient('last_tweet_' . $widget_id); 272 273 274 if( false === $last_tweet ) { 275 276 // Get the widget instance 277 $all_instance_widget = get_option('widget_welt_last_tweets'); 278 279 $widget_real_id = str_replace('welt_last_tweets-', '', $widget_id); 280 281 $instance = $all_instance_widget[$widget_real_id]; 282 283 // Set the transient for this widget 284 $last_tweet = welt_set_tweet_transient( $widget_id, $instance, false ); 285 286 } 287 288 if( is_string( $last_tweet ) ){ // It is a error 289 290 echo $last_tweet; 291 292 } elseif ( $last_tweet != false ){ 293 294 foreach ($last_tweet as $tweet) { 295 296 $tweet_id = $tweet->id_str; 297 298 $last_tweet_html = get_transient('last_tweet_html_' . $tweet_id); 299 300 $tweet_html .= $last_tweet_html->html; 301 302 } 303 } else { 304 $tweet_html = __('Error: Twitter did not respond. Please wait a few minutes and refresh this page.', 'ab-welt-locales'); 305 } 306 307 308 echo $tweet_html; 309 die; 310 } 311 312 add_action('wp_ajax_welt_display_tweets', 'welt_display_tweets'); 313 add_action('wp_ajax_nopriv_welt_display_tweets', 'welt_display_tweets'); 314 315 316 /** 317 * Enqueue welt script and Twitter Script 318 */ 319 function welt_enqueue_scripts(){ 320 // welt 321 wp_enqueue_script('welt_script', plugins_url('/js/welt-scripts.js', __FILE__) , array( 'jquery' ), '20130129', true ); 322 wp_localize_script( 'welt_script', 'ajaxurl', admin_url('admin-ajax.php') ); 323 324 } 325 add_action('wp_enqueue_scripts', 'welt_enqueue_scripts'); 297 326 298 327 //Files needed for the Twitter authentification
Note: See TracChangeset
for help on using the changeset viewer.