Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/widgets
File: rsslinks-widget.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
/**
[1] Fix | Delete
* RSS Links Widget
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[7] Fix | Delete
exit( 0 );
[8] Fix | Delete
}
[9] Fix | Delete
[10] Fix | Delete
// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Register the widget.
[14] Fix | Delete
*/
[15] Fix | Delete
function jetpack_rss_links_widget_init() {
[16] Fix | Delete
register_widget( Jetpack_RSS_Links_Widget::class );
[17] Fix | Delete
}
[18] Fix | Delete
add_action( 'widgets_init', 'jetpack_rss_links_widget_init' );
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* RSS Links Widget class.
[22] Fix | Delete
*/
[23] Fix | Delete
class Jetpack_RSS_Links_Widget extends WP_Widget {
[24] Fix | Delete
/**
[25] Fix | Delete
* Constructor
[26] Fix | Delete
*/
[27] Fix | Delete
public function __construct() {
[28] Fix | Delete
$widget_ops = array(
[29] Fix | Delete
'classname' => 'widget_rss_links',
[30] Fix | Delete
'description' => __( "Links to your blog's RSS feeds", 'jetpack' ),
[31] Fix | Delete
'customize_selective_refresh' => true,
[32] Fix | Delete
);
[33] Fix | Delete
parent::__construct(
[34] Fix | Delete
'rss_links',
[35] Fix | Delete
/** This filter is documented in modules/widgets/facebook-likebox.php */
[36] Fix | Delete
apply_filters( 'jetpack_widget_name', __( 'RSS Links', 'jetpack' ) ),
[37] Fix | Delete
$widget_ops
[38] Fix | Delete
);
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Display the widget.
[43] Fix | Delete
*
[44] Fix | Delete
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
[45] Fix | Delete
* @param array $instance The settings for the particular instance of the widget.
[46] Fix | Delete
*/
[47] Fix | Delete
public function widget( $args, $instance ) {
[48] Fix | Delete
$instance = wp_parse_args( (array) $instance, $this->defaults() );
[49] Fix | Delete
[50] Fix | Delete
$before_widget = isset( $args['before_widget'] ) ? $args['before_widget'] : '';
[51] Fix | Delete
$before_title = isset( $args['before_title'] ) ? $args['before_title'] : '';
[52] Fix | Delete
$after_title = isset( $args['after_title'] ) ? $args['after_title'] : '';
[53] Fix | Delete
$after_widget = isset( $args['after_widget'] ) ? $args['after_widget'] : '';
[54] Fix | Delete
[55] Fix | Delete
/** This filter is documented in core/src/wp-includes/default-widgets.php */
[56] Fix | Delete
$title = apply_filters( 'widget_title', $instance['title'] );
[57] Fix | Delete
echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[58] Fix | Delete
[59] Fix | Delete
if ( $title ) {
[60] Fix | Delete
echo $before_title . $title . $after_title; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
if ( 'text' === $instance['format'] ) {
[64] Fix | Delete
echo '<ul>';
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
if ( 'posts' === $instance['display'] ) {
[68] Fix | Delete
$this->rss_link( 'posts', $instance );
[69] Fix | Delete
} elseif ( 'comments' === $instance['display'] ) {
[70] Fix | Delete
$this->rss_link( 'comments', $instance );
[71] Fix | Delete
} elseif ( 'posts-comments' === $instance['display'] ) {
[72] Fix | Delete
$this->rss_link( 'posts', $instance );
[73] Fix | Delete
$this->rss_link( 'comments', $instance );
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
if ( 'text' === $instance['format'] ) {
[77] Fix | Delete
echo '</ul>';
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
echo "\n" . $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[81] Fix | Delete
[82] Fix | Delete
/** This action is documented in modules/widgets/gravatar-profile.php */
[83] Fix | Delete
do_action( 'jetpack_stats_extra', 'widget_view', 'rss-links' );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Return an associative array of default values
[88] Fix | Delete
* These values are used in new widgets as well as when sanitizing input.
[89] Fix | Delete
*
[90] Fix | Delete
* @return array Array of default values for the Widget's options
[91] Fix | Delete
*/
[92] Fix | Delete
public function defaults() {
[93] Fix | Delete
return array(
[94] Fix | Delete
'title' => '',
[95] Fix | Delete
'display' => 'posts-comments',
[96] Fix | Delete
'format' => 'text',
[97] Fix | Delete
);
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Sanitize widget form values as they are saved.
[102] Fix | Delete
*
[103] Fix | Delete
* @see WP_Widget::update()
[104] Fix | Delete
*
[105] Fix | Delete
* @param array $new_instance Values just sent to be saved.
[106] Fix | Delete
* @param array $old_instance Previously saved values from database.
[107] Fix | Delete
*
[108] Fix | Delete
* @return array Updated safe values to be saved.
[109] Fix | Delete
*/
[110] Fix | Delete
public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
[111] Fix | Delete
$instance = $old_instance;
[112] Fix | Delete
[113] Fix | Delete
$instance['title'] = wp_filter_nohtml_kses( $new_instance['title'] );
[114] Fix | Delete
$instance['display'] = $new_instance['display'];
[115] Fix | Delete
$instance['format'] = $new_instance['format'];
[116] Fix | Delete
$instance['imagesize'] = $new_instance['imagesize'];
[117] Fix | Delete
$instance['imagecolor'] = $new_instance['imagecolor'];
[118] Fix | Delete
[119] Fix | Delete
return $instance;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Back end widget form.
[124] Fix | Delete
*
[125] Fix | Delete
* @see WP_Widget::form()
[126] Fix | Delete
*
[127] Fix | Delete
* @param array $instance Previously saved values from database.
[128] Fix | Delete
*
[129] Fix | Delete
* @return string|void
[130] Fix | Delete
*/
[131] Fix | Delete
public function form( $instance ) {
[132] Fix | Delete
$instance = wp_parse_args( (array) $instance, $this->defaults() );
[133] Fix | Delete
[134] Fix | Delete
$title = stripslashes( $instance['title'] );
[135] Fix | Delete
$display = $instance['display'];
[136] Fix | Delete
$format = $instance['format'];
[137] Fix | Delete
$image_size = isset( $instance['imagesize'] ) ? $instance['imagesize'] : 0;
[138] Fix | Delete
$image_color = isset( $instance['imagecolor'] ) ? $instance['imagecolor'] : 'red';
[139] Fix | Delete
[140] Fix | Delete
echo '<p><label for="' . esc_attr( $this->get_field_id( 'title' ) ) . '">' . esc_html__( 'Title:', 'jetpack' ) . '
[141] Fix | Delete
<input class="widefat" id="' . esc_attr( $this->get_field_id( 'title' ) ) . '" name="' . esc_attr( $this->get_field_name( 'title' ) ) . '" type="text" value="' . esc_attr( $title ) . '" />
[142] Fix | Delete
</label></p>';
[143] Fix | Delete
[144] Fix | Delete
$displays = array(
[145] Fix | Delete
'posts' => __( 'Posts', 'jetpack' ),
[146] Fix | Delete
'comments' => __( 'Comments', 'jetpack' ),
[147] Fix | Delete
'posts-comments' => __( 'Posts & Comments', 'jetpack' ),
[148] Fix | Delete
);
[149] Fix | Delete
echo '<p><label for="' . esc_attr( $this->get_field_id( 'display' ) ) . '">' . esc_html__( 'Feed(s) to Display:', 'jetpack' ) . '
[150] Fix | Delete
<select class="widefat" id="' . esc_attr( $this->get_field_id( 'display' ) ) . '" name="' . esc_attr( $this->get_field_name( 'display' ) ) . '">';
[151] Fix | Delete
foreach ( $displays as $display_option => $label ) {
[152] Fix | Delete
echo '<option value="' . esc_attr( $display_option ) . '"';
[153] Fix | Delete
if ( $display_option === $display ) {
[154] Fix | Delete
echo ' selected="selected"';
[155] Fix | Delete
}
[156] Fix | Delete
echo '>' . esc_html( $label ) . '</option>' . "\n";
[157] Fix | Delete
}
[158] Fix | Delete
echo '</select></label></p>';
[159] Fix | Delete
[160] Fix | Delete
$formats = array(
[161] Fix | Delete
'text' => __( 'Text Link', 'jetpack' ),
[162] Fix | Delete
'image' => __( 'Image Link', 'jetpack' ),
[163] Fix | Delete
'text-image' => __( 'Text & Image Links', 'jetpack' ),
[164] Fix | Delete
);
[165] Fix | Delete
echo '<p><label for="' . esc_attr( $this->get_field_id( 'format' ) ) . '">' . esc_html_x( 'Format:', 'Noun', 'jetpack' ) . '
[166] Fix | Delete
<select class="widefat" id="' . esc_attr( $this->get_field_id( 'format' ) ) . '" name="' . esc_attr( $this->get_field_name( 'format' ) ) . '" onchange="if ( this.value == \'text\' ) jQuery( \'#' . esc_js( $this->get_field_id( 'image-settings' ) ) . '\' ).fadeOut(); else jQuery( \'#' . esc_js( $this->get_field_id( 'image-settings' ) ) . '\' ).fadeIn();">';
[167] Fix | Delete
foreach ( $formats as $format_option => $label ) {
[168] Fix | Delete
echo '<option value="' . esc_attr( $format_option ) . '"';
[169] Fix | Delete
if ( $format_option === $format ) {
[170] Fix | Delete
echo ' selected="selected"';
[171] Fix | Delete
}
[172] Fix | Delete
echo '>' . esc_html( $label ) . '</option>' . "\n";
[173] Fix | Delete
}
[174] Fix | Delete
echo '</select></label></p>';
[175] Fix | Delete
[176] Fix | Delete
echo '<div id="' . esc_attr( $this->get_field_id( 'image-settings' ) ) . '"';
[177] Fix | Delete
if ( 'text' === $format ) {
[178] Fix | Delete
echo ' style="display: none;"';
[179] Fix | Delete
}
[180] Fix | Delete
echo '><h3>' . esc_html__( 'Image Settings:', 'jetpack' ) . '</h3>';
[181] Fix | Delete
[182] Fix | Delete
$sizes = array(
[183] Fix | Delete
'small' => __( 'Small', 'jetpack' ),
[184] Fix | Delete
'medium' => __( 'Medium', 'jetpack' ),
[185] Fix | Delete
'large' => __( 'Large', 'jetpack' ),
[186] Fix | Delete
);
[187] Fix | Delete
echo '<p><label for="' . esc_attr( $this->get_field_id( 'imagesize' ) ) . '">' . esc_html__( 'Image Size:', 'jetpack' ) . '
[188] Fix | Delete
<select class="widefat" id="' . esc_attr( $this->get_field_id( 'imagesize' ) ) . '" name="' . esc_attr( $this->get_field_name( 'imagesize' ) ) . '">';
[189] Fix | Delete
foreach ( $sizes as $size => $label ) {
[190] Fix | Delete
echo '<option value="' . esc_attr( $size ) . '"';
[191] Fix | Delete
if ( $size === $image_size ) {
[192] Fix | Delete
echo ' selected="selected"';
[193] Fix | Delete
}
[194] Fix | Delete
echo '>' . esc_html( $label ) . '</option>' . "\n";
[195] Fix | Delete
}
[196] Fix | Delete
echo '</select></label></p>';
[197] Fix | Delete
[198] Fix | Delete
$colors = array(
[199] Fix | Delete
'red' => __( 'Red', 'jetpack' ),
[200] Fix | Delete
'orange' => __( 'Orange', 'jetpack' ),
[201] Fix | Delete
'green' => __( 'Green', 'jetpack' ),
[202] Fix | Delete
'blue' => __( 'Blue', 'jetpack' ),
[203] Fix | Delete
'purple' => __( 'Purple', 'jetpack' ),
[204] Fix | Delete
'pink' => __( 'Pink', 'jetpack' ),
[205] Fix | Delete
'silver' => __( 'Silver', 'jetpack' ),
[206] Fix | Delete
);
[207] Fix | Delete
echo '<p><label for="' . esc_attr( $this->get_field_id( 'imagecolor' ) ) . '">' . esc_html__( 'Image Color:', 'jetpack' ) . '
[208] Fix | Delete
<select class="widefat" id="' . esc_attr( $this->get_field_id( 'imagecolor' ) ) . '" name="' . esc_attr( $this->get_field_name( 'imagecolor' ) ) . '">';
[209] Fix | Delete
foreach ( $colors as $color => $label ) {
[210] Fix | Delete
echo '<option value="' . esc_attr( $color ) . '"';
[211] Fix | Delete
if ( $color === $image_color ) {
[212] Fix | Delete
echo ' selected="selected"';
[213] Fix | Delete
}
[214] Fix | Delete
echo '>' . esc_html( $label ) . '</option>' . "\n";
[215] Fix | Delete
}
[216] Fix | Delete
echo '</select></label></p></div>';
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Output a link with a link to the feed.
[221] Fix | Delete
*
[222] Fix | Delete
* @param string $type Widget type (posts or comments).
[223] Fix | Delete
* @param array $args Widget arguments.
[224] Fix | Delete
*/
[225] Fix | Delete
private function rss_link( $type, $args ) {
[226] Fix | Delete
$link_text = null;
[227] Fix | Delete
$rss_type = null;
[228] Fix | Delete
$subscribe_to = null;
[229] Fix | Delete
[230] Fix | Delete
if ( 'posts' === $type ) {
[231] Fix | Delete
$subscribe_to = esc_html__( 'Subscribe to posts', 'jetpack' );
[232] Fix | Delete
$link_text = esc_html__( 'RSS - Posts', 'jetpack' );
[233] Fix | Delete
$rss_type = 'rss2_url';
[234] Fix | Delete
} elseif ( 'comments' === $type ) {
[235] Fix | Delete
$subscribe_to = esc_html__( 'Subscribe to comments', 'jetpack' );
[236] Fix | Delete
$link_text = esc_html__( 'RSS - Comments', 'jetpack' );
[237] Fix | Delete
$rss_type = 'comments_rss2_url';
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
/**
[241] Fix | Delete
* Filters the target link attribute for the RSS link in the RSS widget.
[242] Fix | Delete
*
[243] Fix | Delete
* @module widgets
[244] Fix | Delete
*
[245] Fix | Delete
* @since 3.4.0
[246] Fix | Delete
*
[247] Fix | Delete
* @param bool false Control whether the link should open in a new tab. Default to false.
[248] Fix | Delete
*/
[249] Fix | Delete
if ( apply_filters( 'jetpack_rsslinks_widget_target_blank', false ) ) {
[250] Fix | Delete
$link_target = '_blank';
[251] Fix | Delete
} else {
[252] Fix | Delete
$link_target = '_self';
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
$link_contents = null;
[256] Fix | Delete
$format = $args['format'];
[257] Fix | Delete
if ( 'image' === $format ) {
[258] Fix | Delete
$link_contents = $this->get_image_tag( $args );
[259] Fix | Delete
} elseif ( 'text-image' === $format ) {
[260] Fix | Delete
$link_contents = sprintf(
[261] Fix | Delete
'%1$s&nbsp;%2$s',
[262] Fix | Delete
$this->get_image_tag( $args ),
[263] Fix | Delete
$link_text
[264] Fix | Delete
);
[265] Fix | Delete
} elseif ( 'text' === $format ) {
[266] Fix | Delete
$link_contents = $link_text;
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
printf(
[270] Fix | Delete
'%1$s<a target="%3$s" href="%4$s" title="%5$s">%6$s</a>%2$s',
[271] Fix | Delete
'text' === $format ? '<li>' : '<p>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[272] Fix | Delete
'text' === $format ? '</li>' : '</p>', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[273] Fix | Delete
esc_attr( $link_target ),
[274] Fix | Delete
esc_url( get_bloginfo( $rss_type ) ),
[275] Fix | Delete
esc_attr( $subscribe_to ),
[276] Fix | Delete
$link_contents // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- we are escaping this above.
[277] Fix | Delete
);
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* Return an image tag for the RSS icon.
[282] Fix | Delete
*
[283] Fix | Delete
* @param array $args Widget arguments.
[284] Fix | Delete
*/
[285] Fix | Delete
private function get_image_tag( $args ) {
[286] Fix | Delete
$image_path = sprintf(
[287] Fix | Delete
'images/rss/%1$s-%2$s.png',
[288] Fix | Delete
$args['imagecolor'],
[289] Fix | Delete
$args['imagesize']
[290] Fix | Delete
);
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* Filters the image used as RSS icon in the RSS widget.
[294] Fix | Delete
*
[295] Fix | Delete
* @module widgets
[296] Fix | Delete
*
[297] Fix | Delete
* @since 3.6.0
[298] Fix | Delete
*
[299] Fix | Delete
* @param string $var URL of RSS Widget icon.
[300] Fix | Delete
*/
[301] Fix | Delete
$image = apply_filters(
[302] Fix | Delete
'jetpack_rss_widget_icon',
[303] Fix | Delete
plugins_url( $image_path, dirname( __DIR__ ) )
[304] Fix | Delete
);
[305] Fix | Delete
[306] Fix | Delete
return sprintf(
[307] Fix | Delete
'<img src="%1$s" alt="%2$s" />',
[308] Fix | Delete
esc_url( $image ),
[309] Fix | Delete
esc_attr__( 'RSS feed', 'jetpack' )
[310] Fix | Delete
);
[311] Fix | Delete
}
[312] Fix | Delete
} // Class Jetpack_RSS_Links_Widget
[313] Fix | Delete
[314] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function