20 * Sets up a new RSS widget instance. |
20 * Sets up a new RSS widget instance. |
21 * |
21 * |
22 * @since 2.8.0 |
22 * @since 2.8.0 |
23 */ |
23 */ |
24 public function __construct() { |
24 public function __construct() { |
25 $widget_ops = array( |
25 $widget_ops = array( |
26 'description' => __( 'Entries from any RSS or Atom feed.' ), |
26 'description' => __( 'Entries from any RSS or Atom feed.' ), |
27 'customize_selective_refresh' => true, |
27 'customize_selective_refresh' => true, |
28 ); |
28 ); |
29 $control_ops = array( 'width' => 400, 'height' => 200 ); |
29 $control_ops = array( |
|
30 'width' => 400, |
|
31 'height' => 200, |
|
32 ); |
30 parent::__construct( 'rss', __( 'RSS' ), $widget_ops, $control_ops ); |
33 parent::__construct( 'rss', __( 'RSS' ), $widget_ops, $control_ops ); |
31 } |
34 } |
32 |
35 |
33 /** |
36 /** |
34 * Outputs the content for the current RSS widget instance. |
37 * Outputs the content for the current RSS widget instance. |
38 * @param array $args Display arguments including 'before_title', 'after_title', |
41 * @param array $args Display arguments including 'before_title', 'after_title', |
39 * 'before_widget', and 'after_widget'. |
42 * 'before_widget', and 'after_widget'. |
40 * @param array $instance Settings for the current RSS widget instance. |
43 * @param array $instance Settings for the current RSS widget instance. |
41 */ |
44 */ |
42 public function widget( $args, $instance ) { |
45 public function widget( $args, $instance ) { |
43 if ( isset($instance['error']) && $instance['error'] ) |
46 if ( isset( $instance['error'] ) && $instance['error'] ) { |
44 return; |
47 return; |
|
48 } |
45 |
49 |
46 $url = ! empty( $instance['url'] ) ? $instance['url'] : ''; |
50 $url = ! empty( $instance['url'] ) ? $instance['url'] : ''; |
47 while ( stristr($url, 'http') != $url ) |
51 while ( stristr( $url, 'http' ) != $url ) { |
48 $url = substr($url, 1); |
52 $url = substr( $url, 1 ); |
|
53 } |
49 |
54 |
50 if ( empty($url) ) |
55 if ( empty( $url ) ) { |
51 return; |
56 return; |
|
57 } |
52 |
58 |
53 // self-url destruction sequence |
59 // self-url destruction sequence |
54 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) |
60 if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) { |
55 return; |
61 return; |
|
62 } |
56 |
63 |
57 $rss = fetch_feed($url); |
64 $rss = fetch_feed( $url ); |
58 $title = $instance['title']; |
65 $title = $instance['title']; |
59 $desc = ''; |
66 $desc = ''; |
60 $link = ''; |
67 $link = ''; |
61 |
68 |
62 if ( ! is_wp_error($rss) ) { |
69 if ( ! is_wp_error( $rss ) ) { |
63 $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset')))); |
70 $desc = esc_attr( strip_tags( @html_entity_decode( $rss->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) ); |
64 if ( empty($title) ) |
71 if ( empty( $title ) ) { |
65 $title = strip_tags( $rss->get_title() ); |
72 $title = strip_tags( $rss->get_title() ); |
|
73 } |
66 $link = strip_tags( $rss->get_permalink() ); |
74 $link = strip_tags( $rss->get_permalink() ); |
67 while ( stristr($link, 'http') != $link ) |
75 while ( stristr( $link, 'http' ) != $link ) { |
68 $link = substr($link, 1); |
76 $link = substr( $link, 1 ); |
|
77 } |
69 } |
78 } |
70 |
79 |
71 if ( empty( $title ) ) { |
80 if ( empty( $title ) ) { |
72 $title = ! empty( $desc ) ? $desc : __( 'Unknown Feed' ); |
81 $title = ! empty( $desc ) ? $desc : __( 'Unknown Feed' ); |
73 } |
82 } |
74 |
83 |
75 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
84 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
76 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
85 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
77 |
86 |
78 $url = strip_tags( $url ); |
87 $url = strip_tags( $url ); |
79 $icon = includes_url( 'images/rss.png' ); |
88 $icon = includes_url( 'images/rss.png' ); |
80 if ( $title ) |
89 if ( $title ) { |
81 $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>'; |
90 $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>'; |
|
91 } |
82 |
92 |
83 echo $args['before_widget']; |
93 echo $args['before_widget']; |
84 if ( $title ) { |
94 if ( $title ) { |
85 echo $args['before_title'] . $title . $args['after_title']; |
95 echo $args['before_title'] . $title . $args['after_title']; |
86 } |
96 } |
87 wp_widget_rss_output( $rss, $instance ); |
97 wp_widget_rss_output( $rss, $instance ); |
88 echo $args['after_widget']; |
98 echo $args['after_widget']; |
89 |
99 |
90 if ( ! is_wp_error($rss) ) |
100 if ( ! is_wp_error( $rss ) ) { |
91 $rss->__destruct(); |
101 $rss->__destruct(); |
92 unset($rss); |
102 } |
|
103 unset( $rss ); |
93 } |
104 } |
94 |
105 |
95 /** |
106 /** |
96 * Handles updating settings for the current RSS widget instance. |
107 * Handles updating settings for the current RSS widget instance. |
97 * |
108 * |