From 7f4d8b2f2722026d1f63bdd7325e3f6439cadf8e Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 2 Feb 2008 07:57:51 +0000 Subject: [PATCH] New dashboard from mdawaffe. see #5750 git-svn-id: http://svn.automattic.com/wordpress/trunk@6705 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/dashboard.php | 510 ++++++++++++++++++++++++++++++++ wp-admin/includes/schema.php | 9 + wp-admin/includes/upgrade.php | 11 + wp-admin/index-extra.php | 78 +++-- wp-admin/index.php | 102 +------ wp-admin/wp-admin.css | 2 +- wp-includes/version.php | 2 +- wp-includes/widgets.php | 251 ++++++++++++---- 8 files changed, 788 insertions(+), 177 deletions(-) create mode 100644 wp-admin/includes/dashboard.php diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php new file mode 100644 index 000000000..c1899e6a4 --- /dev/null +++ b/wp-admin/includes/dashboard.php @@ -0,0 +1,510 @@ + 'WordPress Dashboard', + 'id' => 'wp_dashboard', + 'before_widget' => "\t
\n\n\t\t
\n\n", + 'after_widget' => "\t\t
\n\n\t
\n\n", + 'before_title' => "\t\t\t

", + 'after_title' => "

\n\n" + ) ); + + + /* Register Widgets and Controls */ + + // Recent Comments Widget + if ( $mod_comments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'") ) { + $notice = sprintf( __ngettext( '%d comment awaiting moderation', '%d comments awaiting moderation', $mod_comments ), $mod_comments ); + $notice = "$notice"; + } else { + $notice = ''; + } + wp_register_sidebar_widget( 'dashboard_recent_comments', __( 'Recent Comments' ), 'wp_dashboard_recent_comments', + array( 'all_link' => 'edit-comments.php', 'notice' => $notice, 'width' => 'half' ) + ); + + + // Incoming Links Widget + if ( !isset( $widget_options['dashboard_incoming_links'] ) ) { + $update = true; + $widget_options['dashboard_incoming_links'] = array( + 'link' => apply_filters( 'dashboard_incoming_links_link', 'http://blogsearch.google.com/blogsearch?hl=en&scoring=d&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ), + 'url' => apply_filters( 'dashboard_incoming_links_feed', 'http://blogsearch.google.com/blogsearch_feeds?hl=en&scoring=d&ie=utf-8&num=10&output=rss&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ), + 'items' => 5, + 'show_date' => 0 + ); + } + wp_register_sidebar_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_empty', + array( 'all_link' => $widget_options['dashboard_incoming_links']['link'], 'feed_link' => $widget_options['dashboard_incoming_links']['url'], 'width' => 'half' ) + ); + wp_register_widget_control( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_rss_control', array(), + array( 'widget_id' => 'dashboard_incoming_links', 'form_inputs' => array( 'title' => false, 'show_summary' => false, 'show_author' => false ) ) + ); + + + // WP Plugins Widget + wp_register_sidebar_widget( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_empty', + array( 'all_link' => 'http://wordpress.org/extend/plugins/', 'feed_link' => 'http://wordpress.org/extend/plugins/rss/', 'width' => 'half' ) + ); + wp_register_widget_control( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_empty', array(), + array( 'widget_id' => 'dashboard_plugins' ) + ); + + + // Primary feed (Dev Blog) Widget + if ( !isset( $widget_options['dashboard_primary'] ) ) { + $update = true; + $widget_options['dashboard_primary'] = array( + 'link' => apply_filters( 'dashboard_primary_link', 'http://wordpress.org/development/' ), + 'url' => apply_filters( 'dashboard_primary_feed', 'http://wordpress.org/development/feed/' ), + 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Development Blog' ) ), + 'items' => 2, + 'show_summary' => 1, + 'show_author' => 0, + 'show_date' => 1 + ); + } + wp_register_sidebar_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_empty', + array( 'all_link' => $widget_options['dashboard_primary']['link'], 'feed_link' => $widget_options['dashboard_primary']['url'], 'width' => 'half', 'class' => 'widget_rss' ) + ); + wp_register_widget_control( 'dashboard_primary', __( 'Primary Feed' ), 'wp_dashboard_rss_control', array(), + array( 'widget_id' => 'dashboard_primary' ) + ); + + + // Secondary Feed (Planet) Widget + if ( !isset( $widget_options['dashboard_secondary'] ) ) { + $update = true; + $widget_options['dashboard_secondary'] = array( + 'link' => apply_filters( 'dashboard_secondary_link', 'http://planet.wordpress.org/' ), + 'url' => apply_filters( 'dashboard_secondary_feed', 'http://planet.wordpress.org/feed/' ), + 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ), + 'items' => 15 + ); + } + wp_register_sidebar_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_empty', + array( 'all_link' => $widget_options['dashboard_secondary']['link'], 'feed_link' => $widget_options['dashboard_secondary']['url'], 'width' => 'full' ) + ); + wp_register_widget_control( 'dashboard_secondary', __( 'Secondary Feed' ), 'wp_dashboard_rss_control', array(), + array( 'widget_id' => 'dashboard_secondary', 'form_inputs' => array( 'show_summary' => false, 'show_author' => false, 'show_date' => false ) ) + ); + + + // Hook to register new widgets + do_action( 'wp_dashboard_setup' ); + + // Hard code the sidebar's widgets and order + $dashboard_widgets = array( 'dashboard_recent_comments', 'dashboard_incoming_links', 'dashboard_primary', 'dashboard_plugins', 'dashboard_secondary' ); + + // Filter widget order + $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', $dashboard_widgets ); + + $wp_dashboard_sidebars = array( 'wp_dashboard' => $dashboard_widgets ); + + add_filter( 'dynamic_sidebar_params', 'wp_dashboard_dynamic_sidebar_params' ); + + if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) { + ob_start(); // hack - but the same hack wp-admin/widgets.php uses + wp_dashbaord_trigger_widget_control( $_POST['widget_id'] ); + ob_end_clean(); + wp_redirect( remove_query_arg( 'edit' ) ); + exit; + } + + if ( $update ) + update_option( 'dashboard_widget_options', $widget_options ); +} + +// Echoes out the dashboard +function wp_dashboard() { + echo "
\n\n"; + + // We're already filtering dynamic_sidebar_params obove + add_filter( 'option_sidebars_widgets', 'wp_dashboard_sidebars_widgets' ); // here there be hackery + dynamic_sidebar( 'wp_dashboard' ); + remove_filter( 'option_sidebars_widgets', 'wp_dashboard_sidebars_widgets' ); + + echo "
\n
\n\n\n"; +} + +// Makes sidebar_widgets option reflect the dashboard settings +function wp_dashboard_sidebars_widgets() { // hackery + return $GLOBALS['wp_dashboard_sidebars']; +} + +// Modifies sidbar params on the fly to set up ids, class names, titles for each widget (called once per widget) +// Switches widget to edit mode if $_GET['edit'] +function wp_dashboard_dynamic_sidebar_params( $params ) { + global $wp_registered_widgets, $wp_registered_widget_controls; + + extract( $params[0], EXTR_PREFIX_ALL, 'sidebar' ); + extract( $wp_registered_widgets[$sidebar_widget_id], EXTR_PREFIX_ALL, 'widget' ); + + $the_classes = array(); + if ( in_array($widget_width, array( 'third', 'fourth', 'full' ) ) ) + $the_classes[] = $widget_width; + + if ( 'double' == $widget_height ) + $the_classes[] = 'double'; + + if ( $widget_class ) + $the_classes[] = $widget_class; + + // Add classes to the widget holder + if ( $the_classes ) + $sidebar_before_widget = str_replace( "
' . __( 'See All' ) . ''; + + $content_class = 'dashboard-widget-content'; + if ( current_user_can( 'edit_dashboard' ) && isset($wp_registered_widget_controls[$widget_id]) && is_callable($wp_registered_widget_controls[$widget_id]['callback']) ) { + // Switch this widget to edit mode + if ( isset($_GET['edit']) && $_GET['edit'] == $widget_id ) { + $content_class .= ' dashboard-widget-control'; + $wp_registered_widgets[$widget_id]['callback'] = 'wp_dashboard_empty'; + $sidebar_widget_name = $wp_registered_widget_controls[$widget_id]['name']; + $params[1] = $widget_id; + $sidebar_before_widget .= '
'; + $sidebar_after_widget = "
$sidebar_after_widget"; + $links[] = '' . __( 'Cancel' ) . ''; + } else { + $links[] = '' . __( 'Edit' ) . ''; + } + } + + if ( $widget_feed_link ) + $links[] = '' . __( 'rss icon' ) . ' ' . __( 'RSS' ) . ''; + + $links = apply_filters( "wp_dashboard_widget_links_$widget_id", $links ); + + // Add links to widget's title bar + if ( $links ) { + $sidebar_before_title .= ''; + $sidebar_after_title = '' . join( ' | ', $links ) . "
$sidebar_after_title"; + } + + // Could have put this in widget-content. Doesn't really matter + if ( $widget_notice ) + $sidebar_after_title .= "\t\t\t
$widget_notice
\n\n"; + + if ( $widget_error ) + $sidebar_after_title .= "\t\t\t
$widget_error
\n\n"; + + $sidebar_after_title .= "\t\t\t
\n\n"; + + $sidebar_after_widget .= "\t\t\t
\n\n"; + + foreach( array_keys( $params[0] ) as $key ) + $$key = ${'sidebar_' . $key}; + + $params[0] = compact( array_keys( $params[0] ) ); + + return $params; +} + + +/* Dashboard Widgets */ + +function wp_dashboard_recent_comments( $sidebar_args ) { + global $comment; + + extract( $sidebar_args, EXTR_SKIP ); + + echo $before_widget; + + echo $before_title; + echo $widget_name; + echo $after_title; + + $lambda = create_function( '', 'return 5;' ); + add_filter( 'option_posts_per_rss', $lambda ); // hack - comments query doesn't accept per_page parameter + $comments_query = new WP_Query('feed=rss2&withcomments=1'); + remove_filter( 'option_posts_per_rss', $lambda ); + + $is_first = true; + + if ( $comments_query->have_comments() ) { + while ( $comments_query->have_comments() ) { $comments_query->the_comment(); + + $comment_post_url = get_permalink( $comment->comment_post_ID ); + $comment_post_title = get_the_title( $comment->comment_post_ID ); + $comment_post_link = "$comment_post_title"; + $comment_link = '#'; + $comment_meta = sprintf( __( 'From %s on %s %s' ), get_comment_author(), $comment_post_link, $comment_link ); + + if ( $is_first ) : $is_first = false; +?> +
+

+ + + +channel['title'])); + } + update_option( 'dashboard_widget_options', $widget_options ); + } + + wp_widget_rss_form( $widget_options[$widget_id], $form_inputs ); +} + + +// Move this into wp-admin.css +function temp_dashboard_css() { +?> + + diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index 04f1973d0..b3557d067 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -251,6 +251,7 @@ function populate_roles() { populate_roles_160(); populate_roles_210(); populate_roles_230(); + populate_roles_250(); } function populate_roles_160() { @@ -390,4 +391,12 @@ function populate_roles_230() { } } +function populate_roles_250() { + $role = get_role( 'administrator' ); + + if ( !empty( $role ) ) { + $role->add_cap( 'edit_dashboard' ); + } +} + ?> diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index 334b6115b..5bbf85a28 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -198,6 +198,9 @@ function upgrade_all() { if ( $wp_current_db_version < 6124 ) upgrade_230_old_tables(); + if ( $wp_current_db_version < 6689 ) + upgrade_250(); + maybe_disable_automattic_widgets(); $wp_rewrite->flush_rules(); @@ -716,6 +719,14 @@ function upgrade_old_slugs() { } +function upgrade_250() { + global $wp_current_db_version; + + if ( $wp_current_db_version < 6689 ) { + populate_roles_250(); + } +} + // The functions we use to actually do stuff // General diff --git a/wp-admin/index-extra.php b/wp-admin/index-extra.php index b7b900654..a1f407152 100644 --- a/wp-admin/index-extra.php +++ b/wp-admin/index-extra.php @@ -4,23 +4,65 @@ require_once (ABSPATH . WPINC . '/rss.php'); @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); +$widgets = get_option( 'dashboard_widget_options' ); + + switch ( $_GET['jax'] ) { case 'incominglinks' : - -$rss_feed = apply_filters( 'dashboard_incoming_links_feed', 'http://blogsearch.google.com/blogsearch_feeds?hl=en&scoring=d&ie=utf-8&num=10&output=rss&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ); - - -$rss = @fetch_rss( $rss_feed ); +@extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP ); +$rss = @fetch_rss( $url ); if ( isset($rss->items) && 1 < count($rss->items) ) { // Technorati returns a 1-item feed when it has no results ?> items as $item ) { break; case 'devnews' : -$rss = @fetch_rss(apply_filters( 'dashboard_primary_feed', 'http://wordpress.org/development/feed/' )); -if ( isset($rss->items) && 0 != count($rss->items) ) { - -$rss->items = array_slice($rss->items, 0, 2); -foreach ($rss->items as $item ) { -?> -

'>

-

- - -items) && 0 != count($rss->items) ) { ?> -

-

title, "$widgets_text" ); ?> You're using BetaPress TODO.

-

-

+ -
+ -
-
|
-

Recent Comments

+
-get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5"); -$numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'"); - -if ( $comments || $numcomments ) : -?> - - -

- - - - -
- - -
- -
|
-

- - -
- -
-get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5"); -?> -
|
-

Recent Posts

- - -
- -
-
| |
-

- -
-
- - - -

.

- - - - -
- -
  -
-
- - - + diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css index 7b63a3bb3..f16c438b3 100644 --- a/wp-admin/wp-admin.css +++ b/wp-admin/wp-admin.css @@ -1017,7 +1017,7 @@ html, body { background: #464646 url('images/logo-ghost.png') no-repeat 20px 10px; color: #999; position: relative; - margin-top: -75px; +// margin-top: -75px; } #footer a { diff --git a/wp-includes/version.php b/wp-includes/version.php index 980dae2d1..23e2d8102 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,6 +16,6 @@ $wp_version = '2.4-bleeding'; * * @global int $wp_db_version */ -$wp_db_version = 6124; +$wp_db_version = 6689; ?> \ No newline at end of file diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index 0a1df5592..7ed97a1c0 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -221,9 +221,10 @@ function dynamic_sidebar($index = 1) { $did_one = false; foreach ( $sidebars_widgets[$index] as $id ) { - $callback = $wp_registered_widgets[$id]['callback']; - - $params = array_merge(array($sidebar), (array) $wp_registered_widgets[$id]['params']); + $params = array_merge( + array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ), + (array) $wp_registered_widgets[$id]['params'] + ); // Substitute HTML id and class attributes into before_widget $classname_ = ''; @@ -236,6 +237,10 @@ function dynamic_sidebar($index = 1) { $classname_ = ltrim($classname_, '_'); $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); + $params = apply_filters( 'dynamic_sidebar_params', $params ); + + $callback = $wp_registered_widgets[$id]['callback']; + if ( is_callable($callback) ) { call_user_func_array($callback, $params); $did_one = true; @@ -1003,9 +1008,6 @@ function wp_widget_rss($args, $widget_args = 1) { if ( isset($options[$number]['error']) && $options[$number]['error'] ) return; - $num_items = (int) $options[$number]['items']; - $show_summary = $options[$number]['show_summary']; - if ( empty($num_items) || $num_items < 1 || $num_items > 10 ) $num_items = 10; $url = $options[$number]['url']; while ( strstr($url, 'http') != $url ) $url = substr($url, 1); @@ -1032,12 +1034,40 @@ function wp_widget_rss($args, $widget_args = 1) { else $icon = get_option('siteurl').'/wp-includes/images/rss.png'; $title = "RSS $title"; -?> - - -items ) && !empty( $rss->items ) ) { - $rss->items = array_slice($rss->items, 0, $num_items); + $rss->items = array_slice($rss->items, 0, $items); echo ''; } else { echo ''; } - - echo $after_widget; } function wp_widget_rss_control($widget_args) { @@ -1082,7 +1147,7 @@ function wp_widget_rss_control($widget_args) { if ( isset($option['url']) ) $urls[$option['url']] = true; - if ( !$updated && !empty($_POST['sidebar']) ) { + if ( !$updated && 'POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['sidebar']) ) { $sidebar = (string) $_POST['sidebar']; $sidebars_widgets = wp_get_sidebars_widgets(); @@ -1099,22 +1164,9 @@ function wp_widget_rss_control($widget_args) { } foreach( (array) $_POST['widget-rss'] as $widget_number => $widget_rss ) { - $items = (int) $widget_rss['items']; - if ( $items < 1 ) - $items = 10; - $url = sanitize_url(strip_tags(stripslashes($widget_rss['url']))); - $title = trim(strip_tags(stripslashes($widget_rss['title']))); - - if ( !isset($urls[$url]) ) { - require_once(ABSPATH . WPINC . '/rss.php'); - $rss = fetch_rss($url); - $error = false; - if ( !is_object($rss) ) { - $url = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1); - $error = sprintf(__('Error in RSS %1$d'), $widget_number ); - } - } - $options[$widget_number] = compact( 'title', 'url', 'items', 'error' ); + $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); @@ -1127,38 +1179,115 @@ function wp_widget_rss_control($widget_args) { $items = 10; $error = false; $number = '%i%'; + $show_summary = 0; + $show_author = 0; + $show_date = 0; } else { - $title = attribute_escape($options[$number]['title']); - $url = attribute_escape($options[$number]['url']); - $items = (int) $options[$number]['items']; - if ( $items < 1 ) - $items = 10; - $error = $options[$number]['error']; + extract( $options[$number] ); } + wp_widget_rss_form( compact( 'number', 'title', 'url', 'items', 'error', 'show_summary', 'show_author', 'show_date' ) ); +} + +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 ); + $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'] ) : ?> -

- -

-

- -

-

- -

- +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ +

+ + +channel['link'])); + while ( strstr($link, 'http') != $link ) + $link = substr($link, 1); + } + } + + return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); } function wp_widget_rss_register() {