Jetpack_RSS_Links_Widget

Module Name: RSS Links Widget Module Description: Easily add RSS links to your theme's sidebar.

Defined (1)

The class is defined in the following location(s).

/modules/widgets/rsslinks-widget.php  
  1. class Jetpack_RSS_Links_Widget extends WP_Widget { 
  2.  
  3. function __construct() { 
  4. $widget_ops = array( 
  5. 'classname' => 'widget_rss_links',  
  6. 'description' => __( "Links to your blog's RSS feeds", 'jetpack' ) 
  7. ); 
  8. parent::__construct( 
  9. 'rss_links',  
  10. /** This filter is documented in modules/widgets/facebook-likebox.php */ 
  11. apply_filters( 'jetpack_widget_name', __( 'RSS Links', 'jetpack' ) ),  
  12. $widget_ops 
  13. ); 
  14.  
  15. function widget( $args, $instance ) { 
  16. $instance = wp_parse_args( (array) $instance, $this->defaults() ); 
  17.  
  18. extract( $args ); 
  19.  
  20. /** This filter is documented in core/src/wp-includes/default-widgets.php */ 
  21. $title = apply_filters( 'widget_title', $instance['title'] ); 
  22. echo $before_widget; 
  23.  
  24. if ( $title ) 
  25. echo $before_title . stripslashes( $title ) . $after_title; 
  26.  
  27. if ( 'text' == $instance['format'] ) echo '<ul>'; 
  28.  
  29. if ( 'posts' == $instance['display'] ) { 
  30. $this->_rss_link( 'posts', $instance); 
  31. } elseif ( 'comments' == $instance['display'] ) { 
  32. $this->_rss_link( 'comments', $instance); 
  33. } elseif ( 'posts-comments' == $instance['display'] ) { 
  34. $this->_rss_link( 'posts', $instance ); 
  35. $this->_rss_link( 'comments', $instance ); 
  36.  
  37. if ( 'text' == $instance['format'] ) echo '</ul>'; 
  38.  
  39. echo "\n" . $after_widget; 
  40.  
  41. /** 
  42. * Return an associative array of default values 
  43. * These values are used in new widgets as well as when sanitizing input. 
  44. * @return array Array of default values for the Widget's options 
  45. */ 
  46. function defaults() { 
  47. return array( 
  48. 'title' => '',  
  49. 'display' => 'posts-comments',  
  50. 'format' => 'text' 
  51. ); 
  52.  
  53. function update( $new_instance, $old_instance ) { 
  54. $instance = $old_instance; 
  55.  
  56. $instance['title'] = wp_filter_nohtml_kses( $new_instance['title'] ); 
  57. $instance['display'] = $new_instance['display']; 
  58. $instance['format'] = $new_instance['format']; 
  59. $instance['imagesize'] = $new_instance['imagesize']; 
  60. $instance['imagecolor'] = $new_instance['imagecolor']; 
  61.  
  62. return $instance; 
  63.  
  64. function form( $instance ) { 
  65. $instance = wp_parse_args( (array) $instance, $this->defaults() ); 
  66.  
  67. $title = stripslashes( $instance['title'] ); 
  68. $display = $instance['display']; 
  69. $format = $instance['format']; 
  70. $image_size = isset( $instance['imagesize'] ) ? $instance['imagesize'] : 0 ; 
  71. $image_color = isset( $instance['imagecolor'] ) ? $instance['imagecolor'] : 'red'; 
  72.  
  73. echo '<p><label for="' . $this->get_field_id( 'title' ) . '">' . esc_html__( 'Title:', 'jetpack' ) . ' 
  74. <input class="widefat" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( $title ) . '" /> 
  75. </label></p>'; 
  76.  
  77. $displays = array( 
  78. 'posts' => __( 'Posts', 'jetpack' ),  
  79. 'comments' => __( 'Comments', 'jetpack' ),  
  80. 'posts-comments' => __( 'Posts & Comments', 'jetpack' ) 
  81. ); 
  82. echo '<p><label for="' . $this->get_field_id( 'display' ) . '">' . esc_html__( 'Feed(s) to Display:', 'jetpack' ) . ' 
  83. <select class="widefat" id="' . $this->get_field_id( 'display' ) . '" name="' . $this->get_field_name( 'display' ) . '">'; 
  84. foreach ( $displays as $display_option => $label ) { 
  85. echo '<option value="' . esc_attr( $display_option ) . '"'; 
  86. if ( $display_option == $display ) echo ' selected="selected"'; 
  87. echo '>' . esc_html( $label ) . '</option>' . "\n"; 
  88. echo '</select></label></p>'; 
  89.  
  90. $formats = array( 
  91. 'text' => __( 'Text Link', 'jetpack' ),  
  92. 'image' => __( 'Image Link', 'jetpack' ),  
  93. 'text-image' => __( 'Text & Image Links', 'jetpack' ) 
  94. ); 
  95. echo '<p><label for="' . $this->get_field_id( 'format' ) . '">' . __( 'Format:', 'jetpack' ) . ' 
  96. <select class="widefat" id="' . $this->get_field_id( 'format' ) . '" name="' . $this->get_field_name( 'format' ) . '" onchange="if ( this.value == \'text\' ) jQuery( \'#' . $this->get_field_id( 'image-settings' ) . '\' ).fadeOut(); else jQuery( \'#' . $this->get_field_id( 'image-settings' ) . '\' ).fadeIn();">'; 
  97. foreach ( $formats as $format_option => $label ) { 
  98. echo '<option value="' . esc_attr( $format_option ) . '"'; 
  99. if ( $format_option == $format ) echo ' selected="selected"'; 
  100. echo '>' . esc_html( $label ) . '</option>' . "\n"; 
  101. echo '</select></label></p>'; 
  102.  
  103. echo '<div id="' . $this->get_field_id( 'image-settings' ) . '"'; 
  104. if ( 'text' == $format ) echo ' style="display: none;"'; 
  105. echo '><h3>' . esc_html__( 'Image Settings:', 'jetpack' ) . '</h3>'; 
  106.  
  107. $sizes = array( 
  108. 'small' => __( 'Small', 'jetpack' ),  
  109. 'medium' => __( 'Medium', 'jetpack' ),  
  110. 'large' => __( 'Large', 'jetpack' ) 
  111. ); 
  112. echo '<p><label for="' . $this->get_field_id( 'imagesize' ) . '">' . esc_html__( 'Image Size:', 'jetpack' ) . ' 
  113. <select class="widefat" id="' . $this->get_field_id( 'imagesize' ) . '" name="' . $this->get_field_name( 'imagesize' ) . '">'; 
  114. foreach ( $sizes as $size => $label ) { 
  115. echo '<option value="' . esc_attr( $size) . '"'; 
  116. if ( $size == $image_size ) echo ' selected="selected"'; 
  117. echo '>' . esc_html( $label ) . '</option>' . "\n"; 
  118. echo '</select></label></p>'; 
  119.  
  120. $colors = array( 
  121. 'red' => __( 'Red', 'jetpack' ),  
  122. 'orange' => __( 'Orange', 'jetpack' ),  
  123. 'green' => __( 'Green', 'jetpack' ),  
  124. 'blue' => __( 'Blue', 'jetpack' ),  
  125. 'purple' => __( 'Purple', 'jetpack' ),  
  126. 'pink' => __( 'Pink', 'jetpack' ),  
  127. 'silver' => __( 'Silver', 'jetpack' ),  
  128. ); 
  129. echo '<p><label for="' . $this->get_field_id( 'imagecolor' ) . '">' . esc_html__( 'Image Color:', 'jetpack' ) . ' 
  130. <select class="widefat" id="' . $this->get_field_id( 'imagecolor' ) . '" name="' . $this->get_field_name( 'imagecolor' ) . '">'; 
  131. foreach ( $colors as $color => $label ) { 
  132. echo '<option value="' . esc_attr( $color) . '"'; 
  133. if ( $color == $image_color ) echo ' selected="selected"'; 
  134. echo '>' . esc_html( $label ) . '</option>' . "\n"; 
  135. echo '</select></label></p></div>'; 
  136.  
  137. function _rss_link( $type = 'posts', $args ) { 
  138. if ( 'posts' == $type ) { 
  139. $type_text = __( 'Posts', 'jetpack' ); 
  140. $rss_type = 'rss2_url'; 
  141. } elseif ( 'comments' == $type ) { 
  142. $type_text = __( 'Comments', 'jetpack' ); 
  143. $rss_type = 'comments_rss2_url'; 
  144.  
  145. $subscribe_to = sprintf( __( 'Subscribe to %s', 'jetpack' ), $type_text ); 
  146.  
  147. $link_item = ''; 
  148. $format = $args['format']; 
  149.  
  150. /** 
  151. * Filters the target link attribute for the RSS link in the RSS widget. 
  152. * @module widgets 
  153. * @since 3.4.0 
  154. * @param bool false Control whether the link should open in a new tab. Default to false. 
  155. */ 
  156. if ( apply_filters( 'jetpack_rsslinks_widget_target_blank', false ) ) { 
  157. $link_target = '_blank'; 
  158. } else { 
  159. $link_target = '_self'; 
  160.  
  161. if ( 'image' == $format || 'text-image' == $format ) { 
  162. /** 
  163. * Filters the image used as RSS icon in the RSS widget. 
  164. * @module widgets 
  165. * @since 3.6.0 
  166. * @param string $var URL of RSS Widget icon. 
  167. */ 
  168. $link_image = apply_filters( 'jetpack_rss_widget_icon', plugins_url( 'images/rss/' . $args['imagecolor'] . '-' . $args['imagesize'] . '.png', dirname( dirname( __FILE__ ) ) ) ); 
  169. $link_item = '<a target="' . $link_target . '" href="' . get_bloginfo( $rss_type ) . '" title="' . esc_attr( $subscribe_to ) . '"><img src="' . esc_url( $link_image ) . '" alt="RSS Feed" /></a>'; 
  170. if ( 'text-image' == $format ) { 
  171. $link_item .= ' <a target="' . $link_target . '" href="' . get_bloginfo( $rss_type ) . '" title="' . esc_attr( $subscribe_to ) . '">' . esc_html__( 'RSS - ' . $type_text, 'jetpack' ). '</a>'; 
  172. if ( 'text' == $format ) { 
  173. $link_item = '<a target="' . $link_target . '" href="' . get_bloginfo( $rss_type ) . '" title="' . esc_attr( $subscribe_to ) . '">' . esc_html__( 'RSS - ' . $type_text, 'jetpack' ). '</a>'; 
  174.  
  175. if ( 'text' == $format ) 
  176. echo '<li>'; 
  177. else 
  178. echo '<p>'; 
  179. echo $link_item; 
  180. if ( 'text' == $format ) 
  181. echo '</li>'; 
  182. else 
  183. echo '</p>'; 
  184.  
  185. } // Class Jetpack_RSS_Links_Widget