| 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 |
|
| 9 |
class Jetpack_RSS_Links_Widget extends WP_Widget { |
| 10 |
|
| 11 |
function Jetpack_RSS_Links_Widget() { |
| 12 |
$widget_ops = array('classname' => 'widget_rss_links', 'description' => __("Links to your blog's RSS feeds", 'jetpack') ); |
| 13 |
$this->WP_Widget('rss_links', __('RSS Links (Jetpack)', 'jetpack'), $widget_ops); |
| 14 |
} |
| 15 |
|
| 16 |
function widget($args, $instance) { |
| 17 |
extract( $args ); |
| 18 |
|
| 19 |
$title = apply_filters( 'widget_title', $instance['title'] ); |
| 20 |
echo $before_widget; |
| 21 |
|
| 22 |
if ( $title ) |
| 23 |
echo $before_title . stripslashes( $title ) . $after_title; |
| 24 |
|
| 25 |
if ( 'text' == $instance['format'] ) echo '<ul>'; |
| 26 |
|
| 27 |
if ( 'posts' == $instance['display'] ) { |
| 28 |
$this->_rss_link('posts', $instance); |
| 29 |
} elseif ( 'comments' == $instance['display'] ) { |
| 30 |
$this->_rss_link('comments', $instance); |
| 31 |
} elseif ( 'posts-comments' == $instance['display'] ) { |
| 32 |
$this->_rss_link('posts', $instance); |
| 33 |
$this->_rss_link('comments', $instance); |
| 34 |
} |
| 35 |
|
| 36 |
if ( 'text' == $instance['format'] ) echo '</ul>'; |
| 37 |
|
| 38 |
echo "\n" . $after_widget; |
| 39 |
} |
| 40 |
|
| 41 |
function update($new_instance, $old_instance) { |
| 42 |
$instance = $old_instance; |
| 43 |
|
| 44 |
$instance['title'] = wp_filter_nohtml_kses( $new_instance['title'] ); |
| 45 |
$instance['display'] = $new_instance['display']; |
| 46 |
$instance['format'] = $new_instance['format']; |
| 47 |
$instance['imagesize'] = $new_instance['imagesize']; |
| 48 |
$instance['imagecolor'] = $new_instance['imagecolor']; |
| 49 |
|
| 50 |
return $instance; |
| 51 |
} |
| 52 |
|
| 53 |
function form($instance) { |
| 54 |
$instance = wp_parse_args( (array) $instance, array('title' => '', 'display' => 'posts-comments', 'format' => 'text') ); |
| 55 |
|
| 56 |
$title = stripslashes( $instance['title'] ); |
| 57 |
$display = $instance['display']; |
| 58 |
$format = $instance['format']; |
| 59 |
$image_size = isset( $instance['imagesize'] ) ? $instance['imagesize'] : 0 ; |
| 60 |
$image_color = isset( $instance['imagecolor'] ) ? $instance['imagecolor'] : 'red'; |
| 61 |
|
| 62 |
echo '<p><label for="' . $this->get_field_id('title') . '">' . esc_html__('Title:', 'jetpack') . ' |
| 63 |
<input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . esc_attr($title) . '" /> |
| 64 |
</label></p>'; |
| 65 |
|
| 66 |
$displays = array( |
| 67 |
'posts' => __('Posts', 'jetpack'), |
| 68 |
'comments' => __('Comments', 'jetpack'), |
| 69 |
'posts-comments' => __('Posts & Comments', 'jetpack') |
| 70 |
); |
| 71 |
echo '<p><label for="' . $this->get_field_id('display') . '">' . esc_html__('Feed(s) to Display:', 'jetpack') . ' |
| 72 |
<select class="widefat" id="' . $this->get_field_id('display') . '" name="' . $this->get_field_name('display') . '">'; |
| 73 |
foreach ( $displays as $display_option => $label ) { |
| 74 |
echo '<option value="' . esc_attr($display_option) . '"'; |
| 75 |
if ( $display_option == $display ) echo ' selected="selected"'; |
| 76 |
echo '>' . esc_html($label) . '</option>' . "\n"; |
| 77 |
} |
| 78 |
echo '</select></label></p>'; |
| 79 |
|
| 80 |
$formats = array( |
| 81 |
'text' => __('Text Link', 'jetpack'), |
| 82 |
'image' => __('Image Link', 'jetpack'), |
| 83 |
'text-image' => __('Text & Image Links', 'jetpack') |
| 84 |
); |
| 85 |
echo '<p><label for="' . $this->get_field_id('format') . '">' . __('Format:', 'jetpack') . ' |
| 86 |
<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();">'; |
| 87 |
foreach ( $formats as $format_option => $label ) { |
| 88 |
echo '<option value="' . esc_attr($format_option) . '"'; |
| 89 |
if ( $format_option == $format ) echo ' selected="selected"'; |
| 90 |
echo '>' . esc_html($label) . '</option>' . "\n"; |
| 91 |
} |
| 92 |
echo '</select></label></p>'; |
| 93 |
|
| 94 |
echo '<div id="' . $this->get_field_id('image-settings') . '"'; |
| 95 |
if ( 'text' == $format ) echo ' style="display: none;"'; |
| 96 |
echo '><h3>' . esc_html__('Image Settings:', 'jetpack') . '</h3>'; |
| 97 |
|
| 98 |
$sizes = array( |
| 99 |
'small' => __('Small', 'jetpack'), |
| 100 |
'medium' => __('Medium', 'jetpack'), |
| 101 |
'large' => __('Large', 'jetpack') |
| 102 |
); |
| 103 |
echo '<p><label for="' . $this->get_field_id('imagesize') . '">' . esc_html__('Image Size:', 'jetpack') . ' |
| 104 |
<select class="widefat" id="' . $this->get_field_id('imagesize') . '" name="' . $this->get_field_name('imagesize') . '">'; |
| 105 |
foreach ( $sizes as $size => $label ) { |
| 106 |
echo '<option value="' . esc_attr($size) . '"'; |
| 107 |
if ( $size == $image_size ) echo ' selected="selected"'; |
| 108 |
echo '>' . esc_html($label) . '</option>' . "\n"; |
| 109 |
} |
| 110 |
echo '</select></label></p>'; |
| 111 |
|
| 112 |
$colors = array( |
| 113 |
'red' => __('Red', 'jetpack'), |
| 114 |
'orange' => __('Orange', 'jetpack'), |
| 115 |
'green' => __('Green', 'jetpack'), |
| 116 |
'blue' => __('Blue', 'jetpack'), |
| 117 |
'purple' => __('Purple', 'jetpack'), |
| 118 |
'pink' => __('Pink', 'jetpack'), |
| 119 |
'silver' => __('Silver', 'jetpack'), |
| 120 |
); |
| 121 |
echo '<p><label for="' . $this->get_field_id('imagecolor') . '">' . esc_html__('Image Color:', 'jetpack') . ' |
| 122 |
<select class="widefat" id="' . $this->get_field_id('imagecolor') . '" name="' . $this->get_field_name('imagecolor') . '">'; |
| 123 |
foreach ( $colors as $color => $label ) { |
| 124 |
echo '<option value="' . esc_attr($color) . '"'; |
| 125 |
if ( $color == $image_color ) echo ' selected="selected"'; |
| 126 |
echo '>' . esc_html($label) . '</option>' . "\n"; |
| 127 |
} |
| 128 |
echo '</select></label></p></div>'; |
| 129 |
} |
| 130 |
|
| 131 |
function _rss_link( $type = 'posts', $args ) { |
| 132 |
if ( 'posts' == $type ) { |
| 133 |
$type_text = __( 'Posts', 'jetpack' ); |
| 134 |
$rss_type = 'rss2_url'; |
| 135 |
} elseif ( 'comments' == $type ) { |
| 136 |
$type_text = __( 'Comments', 'jetpack' ); |
| 137 |
$rss_type = 'comments_rss2_url'; |
| 138 |
} |
| 139 |
|
| 140 |
$subscribe_to = sprintf( __( 'Subscribe to %s', 'jetpack'), $type_text ); |
| 141 |
|
| 142 |
$link_item = ''; |
| 143 |
$format = $args['format']; |
| 144 |
if ( 'image' == $format || 'text-image' == $format ) |
| 145 |
$link_item = '<a href="' . get_bloginfo($rss_type) . '" title="' . esc_attr( $subscribe_to ) . '"><img src="' . esc_url( plugins_url( '_inc/images/rss/' . $args['imagecolor'] . '-' . $args['imagesize'] . '.png', dirname( dirname( __FILE__ ) ) ) ) . '" alt="RSS Feed" /></a>'; |
| 146 |
if ( 'text-image' == $format ) |
| 147 |
$link_item .= ' <a href="' . get_bloginfo($rss_type) . '" title="' . esc_attr( $subscribe_to ) . '">' . esc_html__('RSS - ' . $type_text, 'jetpack'). '</a>'; |
| 148 |
if ( 'text' == $format ) |
| 149 |
$link_item = '<a href="' . get_bloginfo($rss_type) . '" title="' . esc_attr( $subscribe_to ) . '">' . esc_html__('RSS - ' . $type_text, 'jetpack'). '</a>'; |
| 150 |
|
| 151 |
if ( 'text' == $format ) |
| 152 |
echo '<li>'; |
| 153 |
else |
| 154 |
echo '<p>'; |
| 155 |
echo $link_item; |
| 156 |
if ( 'text' == $format ) |
| 157 |
echo '</li>'; |
| 158 |
else |
| 159 |
echo '</p>'; |
| 160 |
|
| 161 |
} |
| 162 |
} //Class Jetpack_RSS_Links_Widget |
| 163 |
|
| 164 |
function jetpack_rss_links_widget_init() { |
| 165 |
register_widget('Jetpack_RSS_Links_Widget'); |
| 166 |
} |
| 167 |
add_action( 'widgets_init', 'jetpack_rss_links_widget_init' ); |
| 168 |
?> |
| 169 |
|