X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/9c40b4d36daed9e28e48a5fe9205c32557195a4b..8ab4a4532479e8db471032b51042ec8c4716d091:/wp-includes/default-widgets.php diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php index d2bebc80..748fc9ae 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') ); - $this->WP_Widget('pages', __('Pages'), $widget_ops); + public function __construct() { + $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'A list of your site’s Pages.') ); + parent::__construct('pages', __('Pages'), $widget_ops); } - function widget( $args, $instance ) { - extract( $args ); + public function widget( $args, $instance ) { + + /** + * Filter the widget title. + * + * @since 2.6.0 + * + * @param string $title The widget title. Default 'Pages'. + * @param array $instance An array of the widget's settings. + * @param mixed $id_base The widget ID. + */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base ); - $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title']); $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; if ( $sortby == 'menu_order' ) $sortby = 'menu_order, post_title'; - $out = wp_list_pages( apply_filters('widget_pages_args', array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) ) ); - - if ( !empty( $out ) ) { - echo $before_widget; - if ( $title) - echo $before_title . $title . $after_title; + /** + * Filter the arguments for the Pages widget. + * + * @since 2.8.0 + * + * @see wp_list_pages() + * + * @param array $args An array of arguments to retrieve the pages list. + */ + $out = wp_list_pages( apply_filters( 'widget_pages_args', array( + 'title_li' => '', + 'echo' => 0, + 'sort_column' => $sortby, + 'exclude' => $exclude + ) ) ); + + if ( ! empty( $out ) ) { + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } ?>
- +
+ + + +
id="get_field_id('images'); ?>" name="get_field_name('images'); ?>" />
@@ -160,6 +207,10 @@ class WP_Widget_Links extends WP_Widget {
id="get_field_id('rating'); ?>" name="get_field_name('rating'); ?>" />
+ + +
'widget_search', 'description' => __( "A search form for your blog") ); - $this->WP_Widget('search', __('Search'), $widget_ops); + public function __construct() { + $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") ); + parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops ); } - function widget( $args, $instance ) { - extract($args); - $title = apply_filters('widget_title', $instance['title']); + public function widget( $args, $instance ) { - echo $before_widget; - if ( $title ) - echo $before_title . $title . $after_title; + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } // Use current theme search form if it exists get_search_form(); - echo $after_widget; + echo $args['after_widget']; } - function form( $instance ) { + public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); $title = $instance['title']; ?> @@ -198,7 +251,7 @@ class WP_Widget_Search extends WP_Widget { '')); $instance['title'] = strip_tags($new_instance['title']); @@ -214,37 +267,94 @@ 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') ); - $this->WP_Widget('archives', __('Archives'), $widget_ops); + public function __construct() { + $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s Posts.') ); + parent::__construct('archives', __('Archives'), $widget_ops); } - function widget( $args, $instance ) { - extract($args); - $c = $instance['count'] ? '1' : '0'; - $d = $instance['dropdown'] ? '1' : '0'; - $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title']); + public function widget( $args, $instance ) { + $c = ! empty( $instance['count'] ) ? '1' : '0'; + $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; - echo $before_widget; - if ( $title ) - echo $before_title . $title . $after_title; + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base ); + + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } if ( $d ) { + $dropdown_id = "{$this->id_base}-dropdown-{$this->number}"; ?> - + +
+ 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'); ?>" />
-
/>
+/>
'widget_categories', 'description' => __( "A list or dropdown of categories" ) ); - $this->WP_Widget('categories', __('Categories'), $widget_ops); + public function __construct() { + $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories." ) ); + parent::__construct('categories', __('Categories'), $widget_ops); } - function widget( $args, $instance ) { - extract( $args ); + public function widget( $args, $instance ) { - $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title']); - $c = $instance['count'] ? '1' : '0'; - $h = $instance['hierarchical'] ? '1' : '0'; - $d = $instance['dropdown'] ? '1' : '0'; + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base ); - echo $before_widget; - if ( $title ) - echo $before_title . $title . $after_title; + $c = ! empty( $instance['count'] ) ? '1' : '0'; + $h = ! empty( $instance['hierarchical'] ) ? '1' : '0'; + $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; + + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } - $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h); + $cat_args = array( + 'orderby' => 'name', + 'show_count' => $c, + 'hierarchical' => $h + ); if ( $d ) { - $cat_args['show_option_none'] = __('Select Category'); - wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args)); + static $first_dropdown = true; + + $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}"; + $first_dropdown = false; + + echo ''; + + $cat_args['show_option_none'] = __( 'Select Category' ); + $cat_args['id'] = $dropdown_id; + + /** + * Filter the arguments for the Categories widget drop-down. + * + * @since 2.8.0 + * + * @see wp_dropdown_categories() + * + * @param array $cat_args An array of Categories widget drop-down arguments. + */ + wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) ); ?> @@ -460,38 +627,46 @@ class WP_Widget_Categories extends WP_Widget {
/>
-
+
/>
@@ -510,59 +685,99 @@ 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") );
- $this->WP_Widget('recent-posts', __('Recent Posts'), $widget_ops);
+ public function __construct() {
+ $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "Your site’s most recent Posts.") );
+ parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
$this->alt_option_name = 'widget_recent_entries';
- add_action( 'save_post', array(&$this, 'flush_widget_cache') );
- add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
- add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
+ add_action( 'save_post', array($this, 'flush_widget_cache') );
+ add_action( 'deleted_post', array($this, 'flush_widget_cache') );
+ add_action( 'switch_theme', array($this, 'flush_widget_cache') );
}
- function widget($args, $instance) {
- $cache = wp_cache_get('widget_recent_posts', 'widget');
+ public function widget($args, $instance) {
+ $cache = array();
+ if ( ! $this->is_preview() ) {
+ $cache = wp_cache_get( 'widget_recent_posts', 'widget' );
+ }
- if ( !is_array($cache) )
+ if ( ! is_array( $cache ) ) {
$cache = array();
+ }
+
+ if ( ! isset( $args['widget_id'] ) ) {
+ $args['widget_id'] = $this->id;
+ }
- 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 = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
+
+ /** This filter is documented in wp-includes/default-widgets.php */
+ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
+
+ $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
+ if ( ! $number )
+ $number = 5;
+ $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
+
+ /**
+ * Filter the arguments for the Recent Posts widget.
+ *
+ * @since 3.4.0
+ *
+ * @see WP_Query::get_posts()
+ *
+ * @param array $args An array of arguments used to retrieve the recent posts.
+ */
+ $r = new WP_Query( apply_filters( 'widget_posts_args', array(
+ 'posts_per_page' => $number,
+ 'no_found_rows' => true,
+ 'post_status' => 'publish',
+ 'ignore_sticky_posts' => true
+ ) ) );
- $r = new WP_Query(array('showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
if ($r->have_posts()) :
?>
-
-
+
+
-
++
-
-
-
+
+ +id="get_field_id( 'show_date' ); ?>" name="get_field_name( 'show_date' ); ?>" /> +
'widget_recent_comments', 'description' => __( 'The most recent comments' ) ); - $this->WP_Widget('recent-comments', __('Recent Comments'), $widget_ops); + public function __construct() { + $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'Your site’s most recent comments.' ) ); + parent::__construct('recent-comments', __('Recent Comments'), $widget_ops); $this->alt_option_name = 'widget_recent_comments'; if ( is_active_widget(false, false, $this->id_base) ) - add_action( 'wp_head', array(&$this, 'recent_comments_style') ); + add_action( 'wp_head', array($this, 'recent_comments_style') ); - add_action( 'comment_post', array(&$this, 'flush_widget_cache') ); - add_action( 'wp_set_comment_status', array(&$this, 'flush_widget_cache') ); + add_action( 'comment_post', array($this, 'flush_widget_cache') ); + add_action( 'edit_comment', array($this, 'flush_widget_cache') ); + add_action( 'transition_comment_status', array($this, 'flush_widget_cache') ); } - function recent_comments_style() { ?> + public function recent_comments_style() { + + /** + * Filter the Recent Comments default widget styles. + * + * @since 3.1.0 + * + * @param bool $active Whether the widget is active. Default true. + * @param string $id_base The widget ID. + */ + if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876 + || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) ) + return; + ?> is_preview() ) { + $cache = wp_cache_get('widget_recent_comments', 'widget'); + } + if ( ! is_array( $cache ) ) { + $cache = array(); + } + + if ( ! isset( $args['widget_id'] ) ) + $args['widget_id'] = $this->id; + + if ( isset( $cache[ $args['widget_id'] ] ) ) { + echo $cache[ $args['widget_id'] ]; + return; + } + + $output = ''; - extract($args, EXTR_SKIP); - $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']); - if ( !$number = (int) $instance['number'] ) + $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Comments' ); + + /** This filter is documented in wp-includes/default-widgets.php */ + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); + + $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5; + if ( ! $number ) $number = 5; - else if ( $number < 1 ) - $number = 1; - else if ( $number > 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' ); + + /** + * Filter the arguments for the Recent Comments widget. + * + * @since 3.4.0 + * + * @see WP_Comment_Query::query() for information on accepted arguments. + * + * @param array $comment_args An array of arguments used to retrieve the recent comments. + */ + $comments = get_comments( apply_filters( 'widget_comments_args', array( + 'number' => $number, + 'status' => 'approve', + 'post_status' => 'publish' + ) ) ); + + $output .= $args['before_widget']; + if ( $title ) { + $output .= $args['before_title'] . $title . $args['after_title']; } - $comments = array_slice( (array) $comments, 0, $number ); -?> - - --
++
-
-
-
+
__('Entries from any RSS or Atom feed') ); + public function __construct() { + $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') ); $control_ops = array( 'width' => 400, 'height' => 200 ); - $this->WP_Widget( 'rss', __('RSS'), $widget_ops, $control_ops ); + parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops ); } - function widget($args, $instance) { + public function widget($args, $instance) { if ( isset($instance['error']) && $instance['error'] ) return; - extract($args, EXTR_SKIP); - - $url = $instance['url']; + $url = ! empty( $instance['url'] ) ? $instance['url'] : ''; while ( stristr($url, 'http') != $url ) $url = substr($url, 1); if ( empty($url) ) return; + // self-url destruction sequence + if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) ) + return; + $rss = fetch_feed($url); $title = $instance['title']; $desc = ''; @@ -710,7 +990,7 @@ class WP_Widget_RSS extends WP_Widget { if ( ! is_wp_error($rss) ) { $desc = esc_attr(strip_tags(@html_entity_decode($rss->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,25 +999,32 @@ class WP_Widget_RSS extends WP_Widget { if ( empty($title) ) $title = empty($desc) ? __('Unknown Feed') : $desc; - $title = apply_filters('widget_title', $title ); + /** This filter is documented in wp-includes/default-widgets.php */ + $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"; + $title = " $title"; - echo $before_widget; - if ( $title ) - echo $before_title . $title . $after_title; + echo $args['before_widget']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } wp_widget_rss_output( $rss, $instance ); - echo $after_widget; + echo $args['after_widget']; + + if ( ! is_wp_error($rss) ) + $rss->__destruct(); + unset($rss); } - function update($new_instance, $old_instance) { - $testurl = $new_instance['url'] != $old_instance['url']; + public function update($new_instance, $old_instance) { + $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) ); return wp_widget_rss_process( $new_instance, $testurl ); } - function form($instance) { + public function form($instance) { if ( empty($instance) ) $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 ); @@ -768,55 +1055,60 @@ 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; } - $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 ); + $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 ); $args = wp_parse_args( $args, $default_args ); - extract( $args, EXTR_SKIP ); - $items = (int) $items; + $items = (int) $args['items']; if ( $items < 1 || 20 < $items ) $items = 10; - $show_summary = (int) $show_summary; - $show_author = (int) $show_author; - $show_date = (int) $show_date; + $show_summary = (int) $args['show_summary']; + $show_author = (int) $args['show_author']; + $show_date = (int) $args['show_date']; if ( !$rss->get_item_quantity() ) { - echo '-
++
--
++
--