/wp-content/plugins/jetpack/modules/widgets/rsslinks-widget.php

https://gitlab.com/thisishayat/itv-2016 · PHP · 221 lines · 176 code · 21 blank · 24 comment · 27 complexity · 89da1e4fb1999bc44ead60a9eae7d920 MD5 · raw file

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