Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. class WP_Widget_RSS_UNLINK extends WP_Widget {
  2.  
  3. function __construct() {
  4. $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') );
  5. $control_ops = array( 'width' => 400, 'height' => 200 );
  6. parent::__construct( 'rss', __('RSS UNLINK'), $widget_ops, $control_ops );
  7. }
  8.  
  9. function widget($args, $instance) {
  10. if ( isset($instance['error']) && $instance['error'] ) return;
  11. extract($args, EXTR_SKIP);
  12.  
  13. $url = ! empty( $instance['url'] ) ? $instance['url'] : '';
  14. while ( stristr($url, 'http') != $url )
  15. $url = substr($url, 1);
  16.  
  17. if ( empty($url) ) return;
  18.  
  19. if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) return;
  20.  
  21. $rss = fetch_feed($url);
  22. $title = $instance['title'];
  23. $desc = '';
  24. $link = '';
  25.  
  26. if ( ! is_wp_error($rss) ) {
  27. $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
  28. if ( empty($title) ) $title = esc_html(strip_tags($rss->get_title()));
  29. $link = esc_url(strip_tags($rss->get_permalink()));
  30. while ( stristr($link, 'http') != $link )
  31. $link = substr($link, 1);
  32. }
  33.  
  34. if ( empty($title) ) $title = empty($desc) ? __('Unknown Feed') : $desc;
  35.  
  36. $title = apply_filters('widget_title', $title, $instance, $this->id_base);
  37. $url = esc_url(strip_tags($url));
  38.  
  39. echo $before_widget;
  40. if ( $title ) echo $before_title . $title . $after_title;
  41. wp_widget_rss_output( $rss, $instance );
  42. echo $after_widget;
  43.  
  44. if ( ! is_wp_error($rss) ) $rss->__destruct();
  45. unset($rss);
  46. }
  47.  
  48. function update($new_instance, $old_instance) {
  49. $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
  50. return wp_widget_rss_process( $new_instance, $testurl );
  51. }
  52.  
  53. function form($instance) {
  54.  
  55. if ( empty($instance) )
  56. $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
  57. $instance['number'] = $this->number;
  58.  
  59. wp_widget_rss_form( $instance );
  60. }
  61. }
  62. add_action( 'widgets_init', create_function( '', "register_widget('WP_Widget_RSS_UNLINK');" ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement