3 * Widget API: WP_Widget_RSS class
11 * Core class used to implement a RSS widget.
17 class WP_Widget_RSS extends WP_Widget {
20 * Sets up a new RSS widget instance.
25 public function __construct() {
26 $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') );
27 $control_ops = array( 'width' => 400, 'height' => 200 );
28 parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
32 * Outputs the content for the current RSS widget instance.
37 * @param array $args Display arguments including 'before_title', 'after_title',
38 * 'before_widget', and 'after_widget'.
39 * @param array $instance Settings for the current RSS widget instance.
41 public function widget( $args, $instance ) {
42 if ( isset($instance['error']) && $instance['error'] )
45 $url = ! empty( $instance['url'] ) ? $instance['url'] : '';
46 while ( stristr($url, 'http') != $url )
47 $url = substr($url, 1);
52 // self-url destruction sequence
53 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
56 $rss = fetch_feed($url);
57 $title = $instance['title'];
61 if ( ! is_wp_error($rss) ) {
62 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
64 $title = strip_tags( $rss->get_title() );
65 $link = strip_tags( $rss->get_permalink() );
66 while ( stristr($link, 'http') != $link )
67 $link = substr($link, 1);
71 $title = empty($desc) ? __('Unknown Feed') : $desc;
73 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
74 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
76 $url = strip_tags( $url );
77 $icon = includes_url( 'images/rss.png' );
79 $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">"'. esc_html( $title ) .'"</a>';
81 echo $args['before_widget'];
83 echo $args['before_title'] . $title . $args['after_title'];
85 wp_widget_rss_output( $rss, $instance );
86 echo $args['after_widget'];
88 if ( ! is_wp_error($rss) )
94 * Handles updating settings for the current RSS widget instance.
99 * @param array $new_instance New settings for this instance as input by the user via
101 * @param array $old_instance Old settings for this instance.
102 * @return array Updated settings to save.
104 public function update( $new_instance, $old_instance ) {
105 $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
106 return wp_widget_rss_process( $new_instance, $testurl );
110 * Outputs the settings form for the RSS widget.
115 * @param array $instance Current settings.
117 public function form( $instance ) {
118 if ( empty( $instance ) ) {
119 $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
121 $instance['number'] = $this->number;
123 wp_widget_rss_form( $instance );