X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/d3b1ea255664edd2deef17f900a655613d20820d..fef8173b8c3bad08f495551e43cfdeac1cae6021:/wp-includes/default-widgets.php
diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php
index d2bebc80..a3699051 100644
--- a/wp-includes/default-widgets.php
+++ b/wp-includes/default-widgets.php
@@ -1,5 +1,4 @@
'widget_pages', 'description' => __( 'Your blog’s WordPress Pages') );
+ $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'Your site’s WordPress Pages') );
$this->WP_Widget('pages', __('Pages'), $widget_ops);
}
function widget( $args, $instance ) {
extract( $args );
- $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title']);
+ $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base);
$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
@@ -172,13 +171,13 @@ class WP_Widget_Links extends WP_Widget {
class WP_Widget_Search extends WP_Widget {
function WP_Widget_Search() {
- $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your blog") );
+ $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") );
$this->WP_Widget('search', __('Search'), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
- $title = apply_filters('widget_title', $instance['title']);
+ $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
echo $before_widget;
if ( $title )
@@ -215,7 +214,7 @@ class WP_Widget_Search extends WP_Widget {
class WP_Widget_Archives extends WP_Widget {
function WP_Widget_Archives() {
- $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your blog’s posts') );
+ $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s posts') );
$this->WP_Widget('archives', __('Archives'), $widget_ops);
}
@@ -223,7 +222,7 @@ class WP_Widget_Archives extends WP_Widget {
extract($args);
$c = $instance['count'] ? '1' : '0';
$d = $instance['dropdown'] ? '1' : '0';
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title']);
+ $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base);
echo $before_widget;
if ( $title )
@@ -262,9 +261,9 @@ class WP_Widget_Archives extends WP_Widget {
?>
+ id="get_field_id('dropdown'); ?>" name="get_field_name('dropdown'); ?>" />
+
id="get_field_id('count'); ?>" name="get_field_name('count'); ?>" />
-
- id="get_field_id('dropdown'); ?>" name="get_field_name('dropdown'); ?>" />
id_base);
echo $before_widget;
if ( $title )
@@ -328,13 +327,13 @@ class WP_Widget_Meta extends WP_Widget {
class WP_Widget_Calendar extends WP_Widget {
function WP_Widget_Calendar() {
- $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your blog’s posts') );
+ $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s posts') );
$this->WP_Widget('calendar', __('Calendar'), $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
- $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']);
+ $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base);
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
@@ -376,8 +375,8 @@ class WP_Widget_Text extends WP_Widget {
function widget( $args, $instance ) {
extract($args);
- $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
- $text = apply_filters( 'widget_text', $instance['text'] );
+ $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
+ $text = apply_filters( 'widget_text', $instance['text'], $instance );
echo $before_widget;
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
@@ -391,7 +390,7 @@ class WP_Widget_Text extends WP_Widget {
if ( current_user_can('unfiltered_html') )
$instance['text'] = $new_instance['text'];
else
- $instance['text'] = wp_filter_post_kses( $new_instance['text'] );
+ $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
$instance['filter'] = isset($new_instance['filter']);
return $instance;
}
@@ -399,14 +398,14 @@ class WP_Widget_Text extends WP_Widget {
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
$title = strip_tags($instance['title']);
- $text = format_to_edit($instance['text']);
+ $text = esc_textarea($instance['text']);
?>
- />
+ />
id_base);
$c = $instance['count'] ? '1' : '0';
$h = $instance['hierarchical'] ? '1' : '0';
$d = $instance['dropdown'] ? '1' : '0';
@@ -447,7 +446,7 @@ class WP_Widget_Categories extends WP_Widget {
var dropdown = document.getElementById("cat");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
- location.href = "/?cat="+dropdown.options[dropdown.selectedIndex].value;
+ location.href = "/?cat="+dropdown.options[dropdown.selectedIndex].value;
}
}
dropdown.onchange = onCatChange;
@@ -472,9 +471,9 @@ class WP_Widget_Categories extends WP_Widget {
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
- $instance['count'] = $new_instance['count'] ? 1 : 0;
- $instance['hierarchical'] = $new_instance['hierarchical'] ? 1 : 0;
- $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
+ $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
+ $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
+ $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
return $instance;
}
@@ -483,15 +482,15 @@ class WP_Widget_Categories extends WP_Widget {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
$title = esc_attr( $instance['title'] );
- $count = (bool) $instance['count'];
- $hierarchical = (bool) $instance['hierarchical'];
- $dropdown = (bool) $instance['dropdown'];
+ $count = isset($instance['count']) ? (bool) $instance['count'] :false;
+ $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
+ $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
?>
/>
-
+
/>
@@ -511,7 +510,7 @@ class WP_Widget_Categories extends WP_Widget {
class WP_Widget_Recent_Posts extends WP_Widget {
function WP_Widget_Recent_Posts() {
- $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your blog") );
+ $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
$this->WP_Widget('recent-posts', __('Recent Posts'), $widget_ops);
$this->alt_option_name = 'widget_recent_entries';
@@ -526,37 +525,37 @@ class WP_Widget_Recent_Posts extends WP_Widget {
if ( !is_array($cache) )
$cache = array();
- if ( isset($cache[$args['widget_id']]) )
- return $cache[$args['widget_id']];
+ if ( isset($cache[$args['widget_id']]) ) {
+ echo $cache[$args['widget_id']];
+ return;
+ }
ob_start();
extract($args);
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title']);
- if ( !$number = (int) $instance['number'] )
- $number = 10;
- else if ( $number < 1 )
- $number = 1;
- else if ( $number > 15 )
- $number = 15;
+ $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
+ if ( ! $number = absint( $instance['number'] ) )
+ $number = 10;
- $r = new WP_Query(array('showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
+ $r = new WP_Query(array('posts_per_page' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
if ($r->have_posts()) :
?>
have_posts()) : $r->the_post(); ?>
- -
+
-
-
+
+ function recent_comments_style() {
+ if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
+ || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
+ return;
+ ?>
15 )
- $number = 15;
-
- if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
- $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 15");
- wp_cache_add( 'recent_comments', $comments, 'widget' );
+ $cache = wp_cache_get('widget_recent_comments', 'widget');
+
+ if ( ! is_array( $cache ) )
+ $cache = array();
+
+ if ( isset( $cache[$args['widget_id']] ) ) {
+ echo $cache[$args['widget_id']];
+ return;
}
- $comments = array_slice( (array) $comments, 0, $number );
-?>
-
-
-
-
- $number, 'status' => 'approve' ) );
+ $output .= $before_widget;
+ if ( $title )
+ $output .= $before_title . $title . $after_title;
+
+ $output .= '';
+ $output .= $after_widget;
+
+ echo $output;
+ $cache[$args['widget_id']] = $output;
+ wp_cache_set('widget_recent_comments', $cache, 'widget');
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
- $instance['number'] = (int) $new_instance['number'];
+ $instance['number'] = absint( $new_instance['number'] );
$this->flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );
@@ -669,8 +680,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
-
-
+
get_description(), ENT_QUOTES, get_option('blog_charset'))));
if ( empty($title) )
- $title = htmlentities(strip_tags($rss->get_title()));
+ $title = esc_html(strip_tags($rss->get_title()));
$link = esc_url(strip_tags($rss->get_permalink()));
while ( stristr($link, 'http') != $link )
$link = substr($link, 1);
@@ -719,21 +733,25 @@ class WP_Widget_RSS extends WP_Widget {
if ( empty($title) )
$title = empty($desc) ? __('Unknown Feed') : $desc;
- $title = apply_filters('widget_title', $title );
+ $title = apply_filters('widget_title', $title, $instance, $this->id_base);
$url = esc_url(strip_tags($url));
$icon = includes_url('images/rss.png');
if ( $title )
- $title = " ";
+ $title = " ";
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
wp_widget_rss_output( $rss, $instance );
echo $after_widget;
+
+ if ( ! is_wp_error($rss) )
+ $rss->__destruct();
+ unset($rss);
}
function update($new_instance, $old_instance) {
- $testurl = $new_instance['url'] != $old_instance['url'];
+ $testurl = ( isset($new_instance['url']) && ($new_instance['url'] != $old_instance['url']) );
return wp_widget_rss_process( $new_instance, $testurl );
}
@@ -768,7 +786,6 @@ function wp_widget_rss_output( $rss, $args = array() ) {
if ( is_wp_error($rss) ) {
if ( is_admin() || current_user_can('manage_options') )
echo '' . sprintf( __('RSS Error: %s'), $rss->get_error_message() ) . '
';
-
return;
}
@@ -785,6 +802,8 @@ function wp_widget_rss_output( $rss, $args = array() ) {
if ( !$rss->get_item_quantity() ) {
echo '- ' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '
';
+ $rss->__destruct();
+ unset($rss);
return;
}
@@ -798,8 +817,15 @@ function wp_widget_rss_output( $rss, $args = array() ) {
if ( empty($title) )
$title = __('Untitled');
- $desc = str_replace(array("\n", "\r"), ' ', esc_attr(strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset')))));
- $desc = wp_html_excerpt( $desc, 360 ) . ' […]';
+ $desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
+ $desc = wp_html_excerpt( $desc, 360 );
+
+ // Append ellipsis. Change existing [...] to […].
+ if ( '[...]' == substr( $desc, -5 ) )
+ $desc = substr( $desc, 0, -5 ) . '[…]';
+ elseif ( '[…]' != substr( $desc, -10 ) )
+ $desc .= ' […]';
+
$desc = esc_html( $desc );
if ( $show_summary ) {
@@ -810,13 +836,10 @@ function wp_widget_rss_output( $rss, $args = array() ) {
$date = '';
if ( $show_date ) {
- $date = $item->get_date();
+ $date = $item->get_date( 'U' );
if ( $date ) {
- if ( $date_stamp = strtotime( $date ) )
- $date = ' ';
- else
- $date = '';
+ $date = ' ';
}
}
@@ -836,6 +859,8 @@ function wp_widget_rss_output( $rss, $args = array() ) {
}
}
echo '';
+ $rss->__destruct();
+ unset($rss);
}
@@ -930,9 +955,9 @@ function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
$items = 10;
$url = esc_url_raw(strip_tags( $widget_rss['url'] ));
$title = trim(strip_tags( $widget_rss['title'] ));
- $show_summary = (int) $widget_rss['show_summary'];
- $show_author = (int) $widget_rss['show_author'];
- $show_date = (int) $widget_rss['show_date'];
+ $show_summary = isset($widget_rss['show_summary']) ? (int) $widget_rss['show_summary'] : 0;
+ $show_author = isset($widget_rss['show_author']) ? (int) $widget_rss['show_author'] :0;
+ $show_date = isset($widget_rss['show_date']) ? (int) $widget_rss['show_date'] : 0;
if ( $check_feed ) {
$rss = fetch_feed($url);
@@ -944,6 +969,9 @@ function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
$link = esc_url(strip_tags($rss->get_permalink()));
while ( stristr($link, 'http') != $link )
$link = substr($link, 1);
+
+ $rss->__destruct();
+ unset($rss);
}
}
@@ -964,27 +992,125 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
function widget( $args, $instance ) {
extract($args);
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Tags') : $instance['title']);
+ $current_taxonomy = $this->_get_current_taxonomy($instance);
+ if ( !empty($instance['title']) ) {
+ $title = $instance['title'];
+ } else {
+ if ( 'post_tag' == $current_taxonomy ) {
+ $title = __('Tags');
+ } else {
+ $tax = get_taxonomy($current_taxonomy);
+ $title = $tax->labels->name;
+ }
+ }
+ $title = apply_filters('widget_title', $title, $instance, $this->id_base);
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
- echo '';
- wp_tag_cloud(apply_filters('widget_tag_cloud_args', array()));
+ echo '
';
+ wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
echo "
\n";
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
+ $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
return $instance;
}
function form( $instance ) {
+ $current_taxonomy = $this->_get_current_taxonomy($instance);
?>
-
-get_field_id('title'); ?>" name="get_field_name('title'); ?>" value="" />
+
+
__('Use this widget to add one of your custom menus as a widget.') );
+ parent::WP_Widget( 'nav_menu', __('Custom Menu'), $widget_ops );
+ }
+
+ function widget($args, $instance) {
+ // Get menu
+ $nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );
+
+ if ( !$nav_menu )
+ return;
+
+ $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
+
+ echo $args['before_widget'];
+
+ if ( !empty($instance['title']) )
+ echo $args['before_title'] . $instance['title'] . $args['after_title'];
+
+ wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
+
+ echo $args['after_widget'];
+ }
+
+ function update( $new_instance, $old_instance ) {
+ $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
+ $instance['nav_menu'] = (int) $new_instance['nav_menu'];
+ return $instance;
+ }
+
+ function form( $instance ) {
+ $title = isset( $instance['title'] ) ? $instance['title'] : '';
+ $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
+
+ // Get menus
+ $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
+
+ // If no menus exists, direct the user to go and create some.
+ if ( !$menus ) {
+ echo '
'. sprintf( __('No menus have been created yet. Create some.'), admin_url('nav-menus.php') ) .'
';
+ return;
+ }
+ ?>
+
+
+
+
+
+
+
+
+