'recent_comments', 'widget' );
}
add_action( 'comment_post', 'wp_delete_recent_comments_cache' );
add_action( 'wp_set_comment_status', 'wp_delete_recent_comments_cache' );
/**
* Display and process recent comments widget options form.
*
* @since 2.2.0
*/
function wp_widget_recent_comments_control() {
$options = $newoptions = get_option('widget_recent_comments');
if ( isset($_POST["recent-comments-submit"]) ) {
$newoptions['title'] = strip_tags(stripslashes($_POST["recent-comments-title"]));
$newoptions['number'] = (int) $_POST["recent-comments-number"];
}
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('widget_recent_comments', $options);
wp_delete_recent_comments_cache();
}
$title = attribute_escape($options['title']);
if ( !$number = (int) $options['number'] )
$number = 5;
?>
'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
wp_register_sidebar_widget('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments', $widget_ops);
wp_register_widget_control('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments_control');
if ( is_active_widget('wp_widget_recent_comments') )
add_action('wp_head', 'wp_widget_recent_comments_style');
}
/**
* Display RSS widget.
*
* Allows for multiple widgets to be displayed.
*
* @since 2.2.0
*
* @param array $args Widget arguments.
* @param int $number Widget number.
*/
function wp_widget_rss($args, $widget_args = 1) {
extract($args, EXTR_SKIP);
if ( is_numeric($widget_args) )
$widget_args = array( 'number' => $widget_args );
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
extract($widget_args, EXTR_SKIP);
$options = get_option('widget_rss');
if ( !isset($options[$number]) )
return;
if ( isset($options[$number]['error']) && $options[$number]['error'] )
return;
$url = $options[$number]['url'];
while ( strstr($url, 'http') != $url )
$url = substr($url, 1);
if ( empty($url) )
return;
require_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss($url);
$link = clean_url(strip_tags($rss->channel['link']));
while ( strstr($link, 'http') != $link )
$link = substr($link, 1);
$desc = attribute_escape(strip_tags(html_entity_decode($rss->channel['description'], ENT_QUOTES)));
$title = $options[$number]['title'];
if ( empty($title) )
$title = htmlentities(strip_tags($rss->channel['title']));
if ( empty($title) )
$title = $desc;
if ( empty($title) )
$title = __('Unknown Feed');
$title = apply_filters('widget_title', $title );
$url = clean_url(strip_tags($url));
if ( file_exists(dirname(__FILE__) . '/rss.png') )
$icon = str_replace(ABSPATH, site_url() . '/', dirname(__FILE__)) . '/rss.png';
else
$icon = includes_url('images/rss.png');
$title = " ";
echo $before_widget;
echo $before_title . $title . $after_title;
wp_widget_rss_output( $rss, $options[$number] );
echo $after_widget;
}
/**
* Display the RSS entries in a list.
*
* @since 2.5.0
*
* @param string|array|object $rss RSS url.
* @param array $args Widget arguments.
*/
function wp_widget_rss_output( $rss, $args = array() ) {
if ( is_string( $rss ) ) {
require_once(ABSPATH . WPINC . '/rss.php');
if ( !$rss = fetch_rss($rss) )
return;
} elseif ( is_array($rss) && isset($rss['url']) ) {
require_once(ABSPATH . WPINC . '/rss.php');
$args = $rss;
if ( !$rss = fetch_rss($rss['url']) )
return;
} elseif ( !is_object($rss) ) {
return;
}
$default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
$args = wp_parse_args( $args, $default_args );
extract( $args, EXTR_SKIP );
$items = (int) $items;
if ( $items < 1 || 20 < $items )
$items = 10;
$show_summary = (int) $show_summary;
$show_author = (int) $show_author;
$show_date = (int) $show_date;
if ( is_array( $rss->items ) && !empty( $rss->items ) ) {
$rss->items = array_slice($rss->items, 0, $items);
echo '';
foreach ( (array) $rss->items as $item ) {
while ( strstr($item['link'], 'http') != $item['link'] )
$item['link'] = substr($item['link'], 1);
$link = clean_url(strip_tags($item['link']));
$title = attribute_escape(strip_tags($item['title']));
if ( empty($title) )
$title = __('Untitled');
$desc = '';
if ( isset( $item['description'] ) && is_string( $item['description'] ) )
$desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['description'], ENT_QUOTES))));
elseif ( isset( $item['summary'] ) && is_string( $item['summary'] ) )
$desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['summary'], ENT_QUOTES))));
if ( 360 < strlen( $desc ) )
$desc = wp_html_excerpt( $desc, 360 ) . ' […]';
$summary = $desc;
if ( $show_summary ) {
$desc = '';
$summary = wp_specialchars( $summary );
$summary = "";
} else {
$summary = '';
}
$date = '';
if ( $show_date ) {
if ( isset($item['pubdate']) )
$date = $item['pubdate'];
elseif ( isset($item['published']) )
$date = $item['published'];
if ( $date ) {
if ( $date_stamp = strtotime( $date ) )
$date = ' ';
else
$date = '';
}
}
$author = '';
if ( $show_author ) {
if ( isset($item['dc']['creator']) )
$author = ' ' . wp_specialchars( strip_tags( $item['dc']['creator'] ) ) . '';
elseif ( isset($item['author_name']) )
$author = ' ' . wp_specialchars( strip_tags( $item['author_name'] ) ) . '';
}
if ( $link == '' ) {
echo "- $title{$date}{$summary}{$author}
";
} else {
echo "- {$date}{$summary}{$author}
";
}
}
echo '
';
} else {
echo '- ' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '
';
}
}
/**
* Display and process RSS widget control form.
*
* @since 2.2.0
*
* @param int $widget_args Widget number.
*/
function wp_widget_rss_control($widget_args) {
global $wp_registered_widgets;
static $updated = false;
if ( is_numeric($widget_args) )
$widget_args = array( 'number' => $widget_args );
$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
extract($widget_args, EXTR_SKIP);
$options = get_option('widget_rss');
if ( !is_array($options) )
$options = array();
$urls = array();
foreach ( (array) $options as $option )
if ( isset($option['url']) )
$urls[$option['url']] = true;
if ( !$updated && 'POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['sidebar']) ) {
$sidebar = (string) $_POST['sidebar'];
$sidebars_widgets = wp_get_sidebars_widgets();
if ( isset($sidebars_widgets[$sidebar]) )
$this_sidebar =& $sidebars_widgets[$sidebar];
else
$this_sidebar = array();
foreach ( (array) $this_sidebar as $_widget_id ) {
if ( 'wp_widget_rss' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
if ( !in_array( "rss-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
unset($options[$widget_number]);
}
}
foreach( (array) $_POST['widget-rss'] as $widget_number => $widget_rss ) {
if ( !isset($widget_rss['url']) && isset($options[$widget_number]) ) // user clicked cancel
continue;
$widget_rss = stripslashes_deep( $widget_rss );
$url = sanitize_url(strip_tags($widget_rss['url']));
$options[$widget_number] = wp_widget_rss_process( $widget_rss, !isset($urls[$url]) );
}
update_option('widget_rss', $options);
$updated = true;
}
if ( -1 == $number ) {
$title = '';
$url = '';
$items = 10;
$error = false;
$number = '%i%';
$show_summary = 0;
$show_author = 0;
$show_date = 0;
} else {
extract( (array) $options[$number] );
}
wp_widget_rss_form( compact( 'number', 'title', 'url', 'items', 'error', 'show_summary', 'show_author', 'show_date' ) );
}
/**
* Display RSS widget options form.
*
* The options for what fields are displayed for the RSS form are all booleans
* and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
* 'show_date'.
*
* @since 2.5.0
*
* @param array|string $args Values for input fields.
* @param array $inputs Override default display options.
*/
function wp_widget_rss_form( $args, $inputs = null ) {
$default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
$inputs = wp_parse_args( $inputs, $default_inputs );
extract( $args );
extract( $inputs, EXTR_SKIP);
$number = attribute_escape( $number );
$title = attribute_escape( $title );
$url = attribute_escape( $url );
$items = (int) $items;
if ( $items < 1 || 20 < $items )
$items = 10;
$show_summary = (int) $show_summary;
$show_author = (int) $show_author;
$show_date = (int) $show_date;
if ( $inputs['url'] ) :
?>