[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/widgets/ -> class-wp-widget-rss.php (source)

   1  <?php
   2  /**
   3   * Widget API: WP_Widget_RSS class
   4   *
   5   * @package WordPress
   6   * @subpackage Widgets
   7   * @since 4.4.0
   8   */
   9  
  10  /**
  11   * Core class used to implement a RSS widget.
  12   *
  13   * @since 2.8.0
  14   *
  15   * @see WP_Widget
  16   */
  17  class WP_Widget_RSS extends WP_Widget {
  18  
  19      /**
  20       * Sets up a new RSS widget instance.
  21       *
  22       * @since 2.8.0
  23       */
  24  	public function __construct() {
  25          $widget_ops  = array(
  26              'description'                 => __( 'Entries from any RSS or Atom feed.' ),
  27              'customize_selective_refresh' => true,
  28          );
  29          $control_ops = array(
  30              'width'  => 400,
  31              'height' => 200,
  32          );
  33          parent::__construct( 'rss', __( 'RSS' ), $widget_ops, $control_ops );
  34      }
  35  
  36      /**
  37       * Outputs the content for the current RSS widget instance.
  38       *
  39       * @since 2.8.0
  40       *
  41       * @param array $args     Display arguments including 'before_title', 'after_title',
  42       *                        'before_widget', and 'after_widget'.
  43       * @param array $instance Settings for the current RSS widget instance.
  44       */
  45  	public function widget( $args, $instance ) {
  46          if ( isset( $instance['error'] ) && $instance['error'] ) {
  47              return;
  48          }
  49  
  50          $url = ! empty( $instance['url'] ) ? $instance['url'] : '';
  51          while ( stristr( $url, 'http' ) != $url ) {
  52              $url = substr( $url, 1 );
  53          }
  54  
  55          if ( empty( $url ) ) {
  56              return;
  57          }
  58  
  59          // self-url destruction sequence
  60          if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) {
  61              return;
  62          }
  63  
  64          $rss   = fetch_feed( $url );
  65          $title = $instance['title'];
  66          $desc  = '';
  67          $link  = '';
  68  
  69          if ( ! is_wp_error( $rss ) ) {
  70              $desc = esc_attr( strip_tags( html_entity_decode( $rss->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
  71              if ( empty( $title ) ) {
  72                  $title = strip_tags( $rss->get_title() );
  73              }
  74              $link = strip_tags( $rss->get_permalink() );
  75              while ( stristr( $link, 'http' ) != $link ) {
  76                  $link = substr( $link, 1 );
  77              }
  78          }
  79  
  80          if ( empty( $title ) ) {
  81              $title = ! empty( $desc ) ? $desc : __( 'Unknown Feed' );
  82          }
  83  
  84          /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
  85          $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  86  
  87          $url  = strip_tags( $url );
  88          $icon = includes_url( 'images/rss.png' );
  89          if ( $title ) {
  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          }
  92  
  93          echo $args['before_widget'];
  94          if ( $title ) {
  95              echo $args['before_title'] . $title . $args['after_title'];
  96          }
  97          wp_widget_rss_output( $rss, $instance );
  98          echo $args['after_widget'];
  99  
 100          if ( ! is_wp_error( $rss ) ) {
 101              $rss->__destruct();
 102          }
 103          unset( $rss );
 104      }
 105  
 106      /**
 107       * Handles updating settings for the current RSS widget instance.
 108       *
 109       * @since 2.8.0
 110       *
 111       * @param array $new_instance New settings for this instance as input by the user via
 112       *                            WP_Widget::form().
 113       * @param array $old_instance Old settings for this instance.
 114       * @return array Updated settings to save.
 115       */
 116  	public function update( $new_instance, $old_instance ) {
 117          $testurl = ( isset( $new_instance['url'] ) && ( ! isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
 118          return wp_widget_rss_process( $new_instance, $testurl );
 119      }
 120  
 121      /**
 122       * Outputs the settings form for the RSS widget.
 123       *
 124       * @since 2.8.0
 125       *
 126       * @param array $instance Current settings.
 127       */
 128  	public function form( $instance ) {
 129          if ( empty( $instance ) ) {
 130              $instance = array(
 131                  'title'        => '',
 132                  'url'          => '',
 133                  'items'        => 10,
 134                  'error'        => false,
 135                  'show_summary' => 0,
 136                  'show_author'  => 0,
 137                  'show_date'    => 0,
 138              );
 139          }
 140          $instance['number'] = $this->number;
 141  
 142          wp_widget_rss_form( $instance );
 143      }
 144  }


Generated: Sat Sep 21 01:00:03 2019 Cross-referenced by PHPXref 0.7.1