RtThemesSupport

rt15-twitterfeed

Nov 3rd, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. <?php
  2. #
  3. # RT-Theme Twitter Widget
  4. #
  5.  
  6. class Twitter_Widget extends WP_Widget {
  7.  
  8. function Twitter_Widget() {
  9. $opts =array(
  10. 'classname' => 'widget_twitter',
  11. 'description' => __( 'Displays your Twitter feeds', 'rt_theme_admin' )
  12. );
  13.  
  14. $this-> WP_Widget('rt-twitter', '['. THEMENAME.'] '.__('Twitter', 'rt_theme_admin'), $opts);
  15. }
  16.  
  17.  
  18. function widget( $args, $instance ) {
  19. extract( $args );
  20.  
  21. $title = apply_filters('widget_title', $instance['title']) ;
  22. $twitter_username = $instance['twitter_username'];
  23. $show_tweets = empty($instance['show_tweets']) ? 3 : $instance['show_tweets'];
  24. $randomID = 'tweets-'.rand(10000, 1000000);
  25.  
  26.  
  27. echo $before_widget;
  28. if ($title) echo $before_title . $title . $after_title;
  29.  
  30. echo '<div id="'.$randomID.'">';
  31. echo '<script type="text/javascript">jQuery("#'.$randomID.'").tweet({ count: '.$show_tweets.',count: '.$show_tweets.', username: "'.$twitter_username.'", loading_text: "..." });</script> ';
  32. echo '</div>';
  33. echo $after_widget;
  34. }
  35.  
  36. function update( $new_instance, $old_instance ) {
  37. $instance = $old_instance;
  38. $instance['title'] = strip_tags($new_instance['title']);
  39. $instance['twitter_username'] = strip_tags($new_instance['twitter_username']);
  40. $instance['show_tweets'] = strip_tags($new_instance['show_tweets']);
  41. return $instance;
  42. }
  43.  
  44. function form( $instance ) {
  45. $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
  46. $twitter_username = isset($instance['twitter_username']) ? esc_attr($instance['twitter_username']) : '';
  47. $show_tweets = Is_Numeric(@$instance['show_tweets']) ? absint(@$instance['show_tweets']) : 3;
  48.  
  49. ?>
  50. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'rt_theme_admin'); ?></label>
  51. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo empty($title) ? __('Twitter Feeds','rt_theme') : $title; ?>" /></p>
  52.  
  53. <p><label for="<?php echo $this->get_field_id('twitter_username'); ?>"><?php _e('Twitter Username:', 'rt_theme_admin'); ?></label>
  54. <input class="widefat" id="<?php echo $this->get_field_id('twitter_username'); ?>" name="<?php echo $this->get_field_name('twitter_username'); ?>" type="text" value="<?php echo $twitter_username; ?>" /></p>
  55.  
  56. <p><label for="<?php echo $this->get_field_id('show_tweets'); ?>"><?php _e('Tweet Number:', 'rt_theme_admin'); ?></label>
  57. <input class="widefat" id="<?php echo $this->get_field_id('show_tweets'); ?>" name="<?php echo $this->get_field_name('show_tweets'); ?>" type="text" value="<?php echo empty($show_tweets) ? 3 : $show_tweets; ?>" /></p>
  58.  
  59. <?php } } ?>
Advertisement
Add Comment
Please, Sign In to add comment