X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/98a4d31e52bd56c908617df281730bd4ba58d110..5964d2279dc52bdfe105f9bfa17e04337d47a3fa:/wp-includes/default-widgets.php diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php index 54d1d401..bcbae03d 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); + function __construct() { + $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'Your site’s WordPress Pages') ); + parent::__construct('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']; @@ -90,9 +89,9 @@ class WP_Widget_Pages extends WP_Widget { */ class WP_Widget_Links extends WP_Widget { - function WP_Widget_Links() { + function __construct() { $widget_ops = array('description' => __( "Your blogroll" ) ); - $this->WP_Widget('links', __('Links'), $widget_ops); + parent::__construct('links', __('Links'), $widget_ops); } function widget( $args, $instance ) { @@ -103,12 +102,9 @@ class WP_Widget_Links extends WP_Widget { $show_rating = isset($instance['rating']) ? $instance['rating'] : false; $show_images = isset($instance['images']) ? $instance['images'] : true; $category = isset($instance['category']) ? $instance['category'] : false; - - if ( is_admin() && !$category ) { - // Display All Links widget as such in the widgets screen - echo $before_widget . $before_title. __('All Links') . $after_title . $after_widget; - return; - } + $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name'; + $order = $orderby == 'rating' ? 'DESC' : 'ASC'; + $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1; $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget); wp_list_bookmarks(apply_filters('widget_links_args', array( @@ -116,18 +112,26 @@ class WP_Widget_Links extends WP_Widget { 'category_before' => $before_widget, 'category_after' => $after_widget, 'show_images' => $show_images, 'show_description' => $show_description, 'show_name' => $show_name, 'show_rating' => $show_rating, - 'category' => $category, 'class' => 'linkcat widget' + 'category' => $category, 'class' => 'linkcat widget', + 'orderby' => $orderby, 'order' => $order, + 'limit' => $limit, ))); } function update( $new_instance, $old_instance ) { $new_instance = (array) $new_instance; - $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0); + $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 ); foreach ( $instance as $field => $val ) { if ( isset($new_instance[$field]) ) $instance[$field] = 1; } - $instance['category'] = intval($new_instance['category']); + + $instance['orderby'] = 'name'; + if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) + $instance['orderby'] = $new_instance['orderby']; + + $instance['category'] = intval( $new_instance['category'] ); + $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1; return $instance; } @@ -135,21 +139,31 @@ class WP_Widget_Links extends WP_Widget { function form( $instance ) { //Defaults - $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) ); - $link_cats = get_terms( 'link_category'); + $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) ); + $link_cats = get_terms( 'link_category' ); + if ( ! $limit = intval( $instance['limit'] ) ) + $limit = -1; ?>
- +
+ + + +
id="get_field_id('images'); ?>" name="get_field_name('images'); ?>" />
@@ -160,6 +174,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); + function __construct() { + $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") ); + parent::__construct('search', __('Search'), $widget_ops); } function widget( $args, $instance ) { extract($args); - $title = apply_filters('widget_title', $instance['title']); + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); echo $before_widget; if ( $title ) @@ -214,16 +232,16 @@ 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); + 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']); + $c = ! empty( $instance['count'] ) ? '1' : '0'; + $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; + $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base); echo $before_widget; if ( $title ) @@ -262,9 +280,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'); ?>" />
-
/>
+/>
'widget_categories', 'description' => __( "A list or dropdown of categories" ) ); - $this->WP_Widget('categories', __('Categories'), $widget_ops); + parent::__construct('categories', __('Categories'), $widget_ops); } function widget( $args, $instance ) { extract( $args ); - $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'; + $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base); + $c = ! empty( $instance['count'] ) ? '1' : '0'; + $h = ! empty( $instance['hierarchical'] ) ? '1' : '0'; + $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; echo $before_widget; if ( $title ) @@ -447,7 +468,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 +493,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 +504,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; ?>
/>
-
+
/>
@@ -510,14 +531,14 @@ 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);
+ function __construct() {
+ $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
+ 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) {
@@ -526,45 +547,53 @@ class WP_Widget_Recent_Posts extends WP_Widget {
if ( !is_array($cache) )
$cache = array();
- if ( isset($cache[$args['widget_id']]) ) {
- echo $cache[$args['widget_id']];
+ if ( ! isset( $args['widget_id'] ) )
+ $args['widget_id'] = $this->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 ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
+ $number = 10;
+ $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
- $r = new WP_Query(array('showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
+ $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 ) ) );
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); + 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( 'transition_comment_status', array($this, 'flush_widget_cache') ); } - function recent_comments_style() { ?> + 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( $args['widget_id'] ) ) + $args['widget_id'] = $this->id; + + if ( isset( $cache[ $args['widget_id'] ] ) ) { + echo $cache[ $args['widget_id'] ]; + return; } - $comments = array_slice( (array) $comments, 0, $number ); -?> - - -
-
-
' . sprintf( __('RSS Error: %s'), $rss->get_error_message() ) . '
'; - return; } @@ -786,7 +844,9 @@ function wp_widget_rss_output( $rss, $args = array() ) { $show_date = (int) $show_date; if ( !$rss->get_item_quantity() ) { - echo '-
-get_field_id('title'); ?>" name="get_field_name('title'); ?>" value="" /> ++
__('Use this widget to add one of your custom menus as a widget.') ); + parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops ); + } + + function widget($args, $instance) { + // Get menu + $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; + + if ( !$nav_menu ) + return; + + $instance['title'] = apply_filters( 'widget_title', empty( $instance['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; + } + ?> ++ + +
++ + +
+