tweet_wid

The Recent Tweet Widget AFO tweet wid class.

Defined (1)

The class is defined in the following location(s).

/tweet_afo_widget.php  
  1. class tweet_wid extends WP_Widget { 
  2.  
  3. public function __construct() { 
  4. parent::__construct( 
  5. 'tweet_wid',  
  6. 'Tweet Widget AFO',  
  7. array( 'description' => __( 'Recent tweet widget by afo.', 'text_domain' ), ) 
  8. ); 
  9.  
  10. public function widget( $args, $instance ) { 
  11. extract( $args ); 
  12.  
  13. $wid_title = apply_filters( 'widget_title', $instance['wid_title'] ); 
  14.  
  15. echo $args['before_widget']; 
  16. if ( ! empty( $wid_title ) ) 
  17. echo $args['before_title'] . $wid_title . $args['after_title']; 
  18. echo $this->getTweets(); 
  19. echo $args['after_widget']; 
  20.  
  21. public function update( $new_instance, $old_instance ) { 
  22. $instance = array(); 
  23. $instance['wid_title'] = strip_tags( $new_instance['wid_title'] ); 
  24. return $instance; 
  25.  
  26.  
  27. public function form( $instance ) { 
  28. $wid_title = $instance[ 'wid_title' ]; 
  29. ?> 
  30. <p><label for="<?php echo $this->get_field_id('wid_title'); ?>"><?php _e('Title:'); ?> </label> 
  31. <input class="widefat" id="<?php echo $this->get_field_id('wid_title'); ?>" name="<?php echo $this->get_field_name('wid_title'); ?>" type="text" value="<?php echo $wid_title; ?>" /> 
  32. </p> 
  33. <?php  
  34.  
  35. public function getTweets() { 
  36.  
  37. require_once(plugin_dir_path(__FILE__) . "twitteroauth/twitteroauth.php"); //Path to twitteroauth library 
  38. $afo_twitteruser = get_option('afo_twitteruser'); 
  39. $afo_notweets = get_option('afo_notweets'); 
  40. $afo_consumerkey = get_option('afo_consumerkey'); 
  41. $afo_consumersecret = get_option('afo_consumersecret'); 
  42. $afo_accesstoken = get_option('afo_accesstoken'); 
  43. $afo_accesstokensecret = get_option('afo_accesstokensecret'); 
  44.  
  45. if($afo_notweets == "") { 
  46. $afo_notweets = 5; 
  47.  
  48. function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) { 
  49. $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret); 
  50. return $connection; 
  51.  
  52. $connection = getConnectionWithAccessToken($afo_consumerkey, $afo_consumersecret, $afo_accesstoken, $afo_accesstokensecret); 
  53.  
  54. $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$afo_twitteruser."&count=".$afo_notweets); 
  55.  
  56. if(is_array($tweets)) { 
  57. $tweets = array_filter($tweets); 
  58.  
  59. if(is_array($tweets) and count($tweets) > 0) { 
  60. $ret = '<ul>'; 
  61. foreach($tweets as $key => $value) { 
  62. $ret .= '<li>'; 
  63. $ret .= '<a href="https://twitter.com/'.$afo_twitteruser.'/status/'.$value->id_str.'" target="_blank">'.substr($value->text, 0, 50).'..</a>'; 
  64. $datetoshow = date("M j, Y", strtotime($value->created_at)); 
  65. $ret .= '<br>'. $datetoshow; 
  66. $ret .= '</li>'; 
  67. $ret .= '<li><a href="https://twitter.com/'.$afo_twitteruser.'" target="_blank">Follow @'.$afo_twitteruser.'</a></li>'; 
  68. $ret .= '</ul>'; 
  69. } else { 
  70. $ret = 'Sorry. No tweets found!'; 
  71. return $ret; 
  72. }