From 97266a7552b291be47c6198976ec5bc7594537bb Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 21 Oct 2008 17:56:48 +0000 Subject: [PATCH] Right Now modules. Very rough, needs styling. git-svn-id: http://svn.automattic.com/wordpress/trunk@9265 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/dashboard.php | 116 ++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index 82c822245a..366a4fef92 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -24,6 +24,9 @@ function wp_dashboard_setup() { /* Register Widgets and Controls */ + // Right Now + wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' ); + // Recent Comments Widget wp_add_dashboard_widget( 'dashboard_recent_comments', __( 'Recent Comments' ), 'wp_dashboard_recent_comments' ); @@ -150,6 +153,119 @@ function wp_dashboard() { /* Dashboard Widgets */ +function wp_dashboard_right_now() { + $num_posts = wp_count_posts( 'post' ); + $num_pages = wp_count_posts( 'page' ); + + $num_cats = wp_count_terms('category'); + + $num_tags = wp_count_terms('post_tag'); + + $num_comm = get_comment_count( ); + + echo '

' . __('At a Glance') . '

'; + echo ''; + echo ''; + + // Posts + $num = number_format_i18n( $num_posts->publish ); + if ( current_user_can( 'edit_posts' ) ) + $num = "$num"; + echo ""; + echo ''; + /* TODO: Show status breakdown on hover + if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds. Don't show if !current_user_can + $post_type_texts[] = ''.sprintf( __ngettext( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).''; + } + if ( $can_edit_posts && !empty($num_posts->draft) ) { + $post_type_texts[] = ''.sprintf( __ngettext( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).''; + } + if ( $can_edit_posts && !empty($num_posts->future) ) { + $post_type_texts[] = ''.sprintf( __ngettext( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).''; + } + if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) { + $pending_text = sprintf( __ngettext( 'There is %2$s post pending your review.', 'There are %2$s posts pending your review.', $num_posts->pending ), 'edit.php?post_status=pending', number_format_i18n( $num_posts->pending ) ); + } else { + $pending_text = ''; + } + */ + + // Total Comments + $num = number_format_i18n($num_comm['total_comments']); + if ( current_user_can( 'moderate_comments' ) ) + $num = "$num"; + echo ""; + echo ''; + + echo ''; + + // Pages + $num = number_format_i18n( $num_pages->publish ); + if ( current_user_can( 'edit_pages' ) ) + $num = "$num"; + echo ""; + echo ''; + + // Approved Comments + $num = number_format_i18n($num_comm['approved']); + if ( current_user_can( 'moderate_comments' ) ) + $num = "$num"; + echo ""; + echo ''; + + echo ''; + + // Categories + $num = number_format_i18n( $num_cats ); + if ( current_user_can( 'manage_categories' ) ) + $num = "$num"; + echo ""; + echo ''; + + // Spam Comments + $num = number_format_i18n($num_comm['spam']); + if ( current_user_can( 'moderate_comments' ) ) + $num = "$num"; + echo ""; + echo ''; + + echo ''; + + // Tags + $num = number_format_i18n( $num_tags ); + if ( current_user_can( 'manage_categories' ) ) + $num = "$num"; + echo ""; + echo ''; + + // Pending Comments + $num = number_format_i18n($num_comm['awaiting_moderation']); + if ( current_user_can( 'moderate_comments' ) ) + $num = "$num"; + echo ""; + echo ''; + + echo '
$num' . __ngettext( 'Post', 'Posts', $num_posts->publish ) . '$num' . __ngettext( 'Comment', 'Comments', $num_comm['total_comments'] ) . '
$num' . __ngettext( 'Page', 'Pages', $num_pages->publish ) . '$num' . __ngettext( 'Approved', 'Approved', $num_comm['approved'] ) . '
$num' . __ngettext( 'Category', 'Categories', $num_cats ) . '$num' . __ngettext( 'Spam', 'Spam', $num_comm['spam'] ) . '
$num' . __ngettext( 'Tag', 'Tags', $num_tags ) . '$num' . __ngettext( 'Pending', 'Pending', $num_comm['awaiting_moderation'] ) . '
'; + + $ct = current_theme_info(); + $sidebars_widgets = wp_get_sidebars_widgets(); + $num_widgets = array_reduce( $sidebars_widgets, create_function( '$prev, $curr', 'return $prev+count($curr);' ), 0 ); + $num = number_format_i18n( $num_widgets ); + if ( $can_switch_themes = current_user_can( 'switch_themes' ) ) + $num = "$num"; + + echo '

'; + printf(__ngettext('Theme %1$s with %2$s Widgets', 'Theme %1$s with %2$s Widgets', $num_widgets), $ct->title, $num); + if ( $can_switch_themes ) + echo '' . __('Change Theme') . ''; + echo '

'; + + update_right_now_message(); + + do_action( 'rightnow_end' ); + do_action( 'activity_box_end' ); +} + function wp_dashboard_quick_press( $dashboard, $meta_box ) { $drafts = false; if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) ) {