Make WordPress Core


Ignore:
Timestamp:
10/08/2008 11:32:34 PM (18 years ago)
Author:
ryan
Message:

Draggable dash, first cut. Props mdawaffe. see #7552

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/dashboard.php

    r9078 r9103  
    1515 */
    1616function wp_dashboard_setup() {
    17         global $wpdb, $wp_dashboard_sidebars;
     17        global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
     18        $wp_dashboard_control_callbacks = array();
     19
    1820        $update = false;
    1921        $widget_options = get_option( 'dashboard_widget_options' );
    … …  
    2123                $widget_options = array();
    2224
    23 
    24         /* Register WP Dashboard Dynamic Sidebar */
    25         register_sidebar( array(
    26                 'name' => 'WordPress Dashboard',
    27                 'id' => 'wp_dashboard',
    28                 'before_widget' => "\t<div class='dashboard-widget-holder %2\$s' id='%1\$s'>\n\n\t\t<div class='dashboard-widget'>\n\n",
    29                 'after_widget' => "\t\t</div>\n\n\t</div>\n\n",
    30                 'before_title' => "\t\t\t<h3 class='dashboard-widget-title'>",
    31                 'after_title' => "</h3>\n\n"
    32         ) );
    33 
    34 
    3525        /* Register Widgets and Controls */
    3626
    3727        // Recent Comments Widget
    38         $mod_comments = wp_count_comments();
    39         $mod_comments = $mod_comments->moderated;
    40         if ( current_user_can( 'moderate_comments' ) && $mod_comments ) {
    41                 $notice = sprintf( __ngettext( '%d comment awaiting moderation', '%d comments awaiting moderation', $mod_comments ), $mod_comments );
    42                 $notice = "<a href='edit-comments.php?comment_status=moderated'>$notice</a>";
    43         } else {
    44                 $notice = '';
    45         }
    46         wp_register_sidebar_widget( 'dashboard_recent_comments', __( 'Recent Comments' ), 'wp_dashboard_recent_comments',
    47                 array( 'all_link' => 'edit-comments.php', 'notice' => $notice, 'width' => 'half' )
    48         );
    49 
     28        wp_add_dashboard_widget( 'dashboard_recent_comments', __( 'Recent Comments' ), 'wp_dashboard_recent_comments' );
    5029
    5130        // QuickPress Widget
    52         if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) ) {
    53                 $view = get_permalink( $_POST['post_ID'] );
    54                 $edit = clean_url( get_edit_post_link( $_POST['post_ID'] ) );
    55                 if ( 'post-quickpress-publish' == $_POST['action'] )
    56                         $notice = sprintf( __( 'Post Published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ), clean_url( $view ), $edit );
    57                 else
    58                         $notice = sprintf( __( 'Draft Saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ), clean_url( add_query_arg( 'preview', 1, $view ) ), $edit );
    59         } else {
    60                 $notice = '';
    61         }
    62         wp_register_sidebar_widget( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_quick_press',
    63                 array( 'all_link' => array( 'edit.php?post_status=draft', __('View All Drafts') ), 'width' => 'half', 'height' => 'double', 'notice' => $notice )
    64         );
    65         wp_register_widget_control( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_empty_control',
    66                 array( 'widget_id' => 'dashboard_quick_press' )
    67         );
     31        wp_add_dashboard_widget( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_quick_press', 'wp_dashboard_empty_control' );
     32
     33        // Recent Drafts
     34        wp_add_dashboard_widget( 'dashboard_recent_drafts', __( 'Recent Drafts' ), 'wp_dashboard_recent_drafts' );
    6835
    6936        // Incoming Links Widget
    … …  
    7845                );
    7946        }
    80         wp_register_sidebar_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_empty',
    81                 array( 'all_link' => $widget_options['dashboard_incoming_links']['link'], 'feed_link' => $widget_options['dashboard_incoming_links']['url'], 'width' => 'half' ),
    82                 'wp_dashboard_cached_rss_widget', 'wp_dashboard_incoming_links_output'
    83         );
    84         wp_register_widget_control( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_rss_control', array(),
    85                 array( 'widget_id' => 'dashboard_incoming_links', 'form_inputs' => array( 'title' => false, 'show_summary' => false, 'show_author' => false ) )
    86         );
    87 
     47        wp_add_dashboard_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_incoming_links', 'wp_dashboard_incoming_links_control' );
    8848
    8949        // WP Plugins Widget
    90         wp_register_sidebar_widget( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_empty',
    91                 array( 'all_link' => 'http://wordpress.org/extend/plugins/', 'feed_link' => 'http://wordpress.org/extend/plugins/rss/topics/', 'width' => 'half' ),
    92                 'wp_dashboard_cached_rss_widget', 'wp_dashboard_plugins_output',
    93                 array( 'http://wordpress.org/extend/plugins/rss/browse/popular/', 'http://wordpress.org/extend/plugins/rss/browse/new/', 'http://wordpress.org/extend/plugins/rss/browse/updated/' )
    94         );
     50        if ( current_user_can( 'activate_plugins' ) )
     51                wp_add_dashboard_widget( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_plugins' );
    9552
    9653        // Primary feed (Dev Blog) Widget
    … …  
    10764                );
    10865        }
    109         wp_register_sidebar_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_empty',
    110                 array( 'all_link' => $widget_options['dashboard_primary']['link'], 'feed_link' => $widget_options['dashboard_primary']['url'], 'width' => 'half', 'class' => 'widget_rss' ),
    111                 'wp_dashboard_cached_rss_widget', 'wp_dashboard_rss_output'
    112         );
    113         wp_register_widget_control( 'dashboard_primary', __( 'Primary Feed' ), 'wp_dashboard_rss_control', array(),
    114                 array( 'widget_id' => 'dashboard_primary' )
    115         );
    116 
     66        wp_add_dashboard_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_primary', 'wp_dashboard_primary_control' );
    11767
    11868        // Secondary Feed (Planet) Widget
    … …  
    12676                );
    12777        }
    128         wp_register_sidebar_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_empty',
    129                 array( 'all_link' => $widget_options['dashboard_secondary']['link'], 'feed_link' => $widget_options['dashboard_secondary']['url'], 'width' => 'full' ),
    130                 'wp_dashboard_cached_rss_widget', 'wp_dashboard_secondary_output'
    131         );
    132         wp_register_widget_control( 'dashboard_secondary', __( 'Secondary Feed' ), 'wp_dashboard_rss_control', array(),
    133                 array( 'widget_id' => 'dashboard_secondary', 'form_inputs' => array( 'show_summary' => false, 'show_author' => false, 'show_date' => false ) )
    134         );
    135 
    136 
    137                 /* Dashboard Widget Template
    138                 wp_register_sidebar_widget( $widget_id (unique slug) , $widget_title, $output_callback,
    139                         array(
    140                                 'all_link'  => full url for "View All" link,
    141                                 'feed_link' => full url for "RSS" link,
    142                                 'width'     => 'fourth', 'third', 'half', 'full' (defaults to 'half'),
    143                                 'height'    => 'single', 'double' (defaults to 'single'),
    144                         ),
    145                         $wp_dashboard_empty_callback (only needed if using 'wp_dashboard_empty' as your $output_callback),
    146                         $arg, $arg, $arg... (further args passed to callbacks)
    147                 );
    148 
    149                 // optional: if you want users to be able to edit the settings of your widget, you need to register a widget_control
    150                 wp_register_widget_control( $widget_id, $widget_control_title, $control_output_callback,
    151                         array(), // leave an empty array here: oddity in widget code
    152                         array(
    153                                 'widget_id' => $widget_id, // Yes - again.  This is required: oddity in widget code
    154                                 'arg'       => an arg to pass to the $control_output_callback,
    155                                 'another'   => another arg to pass to the $control_output_callback,
    156                                 ...
    157                         )
    158                 );
    159                 */
     78        wp_add_dashboard_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_secondary', 'wp_dashboard_secondary_control' );
    16079
    16180        // Hook to register new widgets
    16281        do_action( 'wp_dashboard_setup' );
    16382
    164         // Hard code the sidebar's widgets and order
    165         $dashboard_widgets = array();
    166         $dashboard_widgets[] = 'dashboard_quick_press';
    167         $dashboard_widgets[] = 'dashboard_recent_comments';
    168 /*
    169         $dashboard_widgets[] = 'dashboard_incoming_links';
    170         $dashboard_widgets[] = 'dashboard_primary';
    171         if ( current_user_can( 'activate_plugins' ) )
    172                 $dashboard_widgets[] = 'dashboard_plugins';
    173 */
    174         $dashboard_widgets[] = 'dashboard_secondary';
    175 
    17683        // Filter widget order
    177         $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', $dashboard_widgets );
    178         if ( in_array( 'dashboard_quick_press', $dashboard_widgets ) ) {
    179 //              add_action( 'admin_head', 'wp_teeny_mce' );
    180                 add_action( 'admin_head', 'wp_dashboard_quick_press_js' );
    181         }
    182 
    183         $wp_dashboard_sidebars = array( 'wp_dashboard' => $dashboard_widgets, 'array_version' => 3.5 );
    184 
    185         add_filter( 'dynamic_sidebar_params', 'wp_dashboard_dynamic_sidebar_params' );
     84        $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
    18685
    18786        if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
    … …  
    19594        if ( $update )
    19695                update_option( 'dashboard_widget_options', $widget_options );
     96
     97        foreach ( $dashboard_widgets as $widget_id )
     98                wp_add_dashboard_widget( $widget_id, $wp_registered_widgets[$widget_id]['name'], $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
     99}
     100
     101function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null ) {
     102        global $wp_dashboard_control_callbacks;
     103        if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
     104                $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
     105                if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
     106                        list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
     107                        $widget_name .= ' <a href="' . clean_url( $url ) . '">' . __( 'Cancel' ) . '</a>';
     108                        add_meta_box( $widget_id, $widget_name, '_wp_dashboard_control_callback', 'dashboard', 'normal', 'core' );
     109                        return;
     110                }
     111                list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
     112                $widget_name .= ' <a href="' . clean_url( "$url#$widget_id" ) . '" class="open-box">' . __( 'Edit' ) . '</a>';
     113        }
     114        add_meta_box( $widget_id, $widget_name , $callback, 'dashboard', 'normal', 'core' );
     115}
     116
     117function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
     118        echo '<form action="" method="post">';
     119        wp_dashboard_trigger_widget_control( $meta_box['id'] );
     120        echo "<p class='submit'><input type='hidden' name='widget_id' value='$meta_box[id]' /><input type='submit' value='" . __( 'Sumbit' ) . "' /></p>";
     121
     122        echo '</form>';
    197123}
    198124
    … …  
    203129 */
    204130function wp_dashboard() {
    205         echo "<div id='dashboard-widgets'>\n\n";
    206 
    207         // We're already filtering dynamic_sidebar_params obove
    208         add_filter( 'option_sidebars_widgets', 'wp_dashboard_sidebars_widgets' ); // here there be hackery
    209         dynamic_sidebar( 'wp_dashboard' );
    210         remove_filter( 'option_sidebars_widgets', 'wp_dashboard_sidebars_widgets' );
    211 
    212         echo "<br class='clear' />\n</div>\n\n\n";
    213 }
    214 
    215 /**
    216  * Makes sidebar_widgets option reflect the dashboard settings.
    217  *
    218  * @since unknown
    219  *
    220  * @return array WordPress Dashboard Widgets list.
    221  */
    222 function wp_dashboard_sidebars_widgets() { // hackery
    223         return $GLOBALS['wp_dashboard_sidebars'];
    224 }
    225 
    226 // Modifies sidbar params on the fly to set up ids, class names, titles for each widget (called once per widget)
    227 // Switches widget to edit mode if $_GET['edit']
    228 /**
    229  * {@internal Missing Short Description}}
    230  *
    231  * @since unknown
    232  *
    233  * @param unknown_type $params
    234  * @return unknown
    235  */
    236 function wp_dashboard_dynamic_sidebar_params( $params ) {
    237         global $wp_registered_widgets, $wp_registered_widget_controls;
    238 
    239         $sidebar_defaults = array('widget_id' => 0, 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '');
    240         extract( $sidebar_defaults, EXTR_PREFIX_ALL, 'sidebar' );
    241         extract( $params[0], EXTR_PREFIX_ALL, 'sidebar' );
    242 
    243         if ( !isset($wp_registered_widgets[$sidebar_widget_id]) || !is_array($wp_registered_widgets[$sidebar_widget_id]) ) {
    244                 return $params;
    245         }
    246         $widget_defaults = array('id' => '', 'width' => '', 'height' => '', 'class' => '', 'feed_link' => '', 'all_link' => '', 'notice' => false, 'error' => false);
    247         extract( $widget_defaults, EXTR_PREFIX_ALL, 'widget' );
    248         extract( $wp_registered_widgets[$sidebar_widget_id], EXTR_PREFIX_ALL, 'widget' );
    249 
    250         $the_classes = array();
    251         if ( in_array($widget_width, array( 'third', 'fourth', 'full' ) ) )
    252                 $the_classes[] = $widget_width;
    253 
    254         if ( 'double' == $widget_height )
    255                 $the_classes[] = 'double';
    256 
    257         if ( $widget_class )
    258                 $the_classes[] = $widget_class;
    259 
    260         // Add classes to the widget holder
    261         if ( $the_classes )
    262                 $sidebar_before_widget = str_replace( "<div class='dashboard-widget-holder ", "<div class='dashboard-widget-holder " . join( ' ', $the_classes ) . ' ', $sidebar_before_widget );
    263 
    264         $top_links = $bottom_links = array();
    265         if ( $widget_all_link ) {
    266                 $widget_all_link = (array) $widget_all_link;
    267                 $bottom_links[] = '<a href="' . clean_url( $widget_all_link[0] ) . '">' . ( isset($widget_all_link[1]) ? $widget_all_link[1] : __( 'View All' ) ) . '</a>';
    268         }
    269 
    270         $content_class = 'dashboard-widget-content';
    271         if ( current_user_can( 'edit_dashboard' ) && isset($wp_registered_widget_controls[$widget_id]) && is_callable($wp_registered_widget_controls[$widget_id]['callback']) ) {
    272                 // Switch this widget to edit mode
    273                 if ( isset($_GET['edit']) && $_GET['edit'] == $widget_id ) {
    274                         $content_class .= ' dashboard-widget-control';
    275                         $wp_registered_widgets[$widget_id]['callback'] = 'wp_dashboard_empty';
    276                         $sidebar_widget_name = $wp_registered_widget_controls[$widget_id]['name'];
    277                         $params[1] = 'wp_dashboard_trigger_widget_control';
    278                         $sidebar_before_widget .= '<form action="' . clean_url(remove_query_arg( 'edit' ))  . '" method="post">';
    279                         $sidebar_after_widget   = "<div class='dashboard-widget-submit'><input type='hidden' name='sidebar' value='wp_dashboard' /><input type='hidden' name='widget_id' value='$widget_id' /><input type='submit' value='" . __( 'Save' ) . "' /></div></form>$sidebar_after_widget";
    280                         $top_links[] = '<a href="' . clean_url(remove_query_arg( 'edit' )) . '">' . __( 'Cancel' ) . '</a>';
     131        echo "<div id='dashboard-widgets' class='metabox-holder'>\n\n";
     132
     133        echo "<div id='side-info-column' class='inner-sidebar'>\n\n";
     134        $class = do_meta_boxes( 'dashboard', 'side', '' ) ? ' class="has-sidebar"' : '';
     135        echo "</div>\n\n";
     136
     137        echo "<div id='post-body'$class>\n\n";
     138        echo "<div id='dashboard-widgets-main-content' class='has-sidebar-content'>\n\n";
     139        do_meta_boxes( 'dashboard', 'normal', '' );
     140        echo "</div>\n\n";
     141        echo "</div>\n\n";
     142
     143        echo "<form style='display: none' method='get' action=''>\n<p>\n";
     144        wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
     145        wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
     146        echo "</p>\n</form>\n";
     147}
     148
     149/* Dashboard Widgets */
     150
     151function wp_dashboard_quick_press( $dashboard, $meta_box ) {
     152        $drafts = false;
     153        if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) ) {
     154                $view = get_permalink( $_POST['post_ID'] );
     155                $edit = clean_url( get_edit_post_link( $_POST['post_ID'] ) );
     156                if ( 'post-quickpress-publish' == $_POST['action'] ) {
     157                        printf( __( 'Post Published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ), clean_url( $view ), $edit );
    281158                } else {
    282                         $top_links[] = '<a href="' . clean_url(add_query_arg( 'edit', $widget_id )) . "#$widget_id" . '">' . __( 'Edit' ) . '</a>';
    283                 }
    284         }
    285 
    286         if ( $widget_feed_link )
    287                 $bottom_links[] = '<img class="rss-icon" src="' . includes_url('images/rss.png') . '" alt="' . __( 'rss icon' ) . '" /> <a href="' . clean_url( $widget_feed_link ) . '">' . __( 'RSS' ) . '</a>';
    288 
    289         $bottom_links = apply_filters( "wp_dashboard_widget_links_$widget_id", $bottom_links );
    290 
    291         // Could have put this in widget-content.  Doesn't really matter
    292         if ( $widget_notice )
    293                 $sidebar_after_title .= "\t\t\t<div class='dashboard-widget-notice'>$widget_notice</div>\n\n";
    294 
    295         if ( $widget_error )
    296                 $sidebar_after_title .= "\t\t\t<div class='dashboard-widget-error'>$widget_error</div>\n\n";
    297 
    298         $sidebar_after_title .= "\t\t\t<div class='$content_class'>\n\n";
    299 
    300         // Add links to widget's title bar
    301         if ( $top_links ) {
    302                 $sidebar_before_title .= '<span>';
    303                 $sidebar_after_title   = '</span><small>' . join( '&nbsp;|&nbsp;', $top_links ) . "</small><br class='clear' />$sidebar_after_title";
    304         }
    305 
    306         // Add links to bottom of widget
    307         if ( $bottom_links )
    308                 $sidebar_after_widget .= "<p class='dashboard-widget-links'>" . join( ' | ', $bottom_links ) . "</p>";
    309 
    310         $sidebar_after_widget .= "\t\t\t</div>\n\n";
    311 
    312         foreach( array_keys( $params[0] ) as $key )
    313                 $$key = ${'sidebar_' . $key};
    314 
    315         $params[0] = compact( array_keys( $params[0] ) );
    316 
    317         return $params;
    318 }
    319 
    320 
    321 /* Dashboard Widgets */
    322 
    323 function wp_dashboard_quick_press( $sidebar_args ) {
    324         extract( $sidebar_args, EXTR_SKIP );
    325 
    326         echo $before_widget;
    327 
    328         echo $before_title;
    329         echo $widget_name;
    330         echo $after_title;
    331 
    332         if ( ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) ) && 'post-quickpress-save-cont' === $_POST['action'] ) {
    333                 $post = get_post_to_edit( $_POST['post_ID'] );
    334         } else {
    335                 $_REQUEST = array(); // hack
    336                 $post = get_default_post_to_edit();
    337         }
     159                        printf( __( 'Draft Saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ), clean_url( add_query_arg( 'preview', 1, $view ) ), $edit );
     160                        $drafts_query = new WP_Query( array(
     161                                'post_type' => 'post',
     162                                'what_to_show' => 'posts',
     163                                'post_status' => 'draft',
     164                                'author' => $GLOBALS['current_user']->ID,
     165                                'posts_per_page' => 1,
     166                                'orderby' => 'modified',
     167                                'order' => 'DESC'
     168                        ) );
     169               
     170                        if ( $drafts_query->posts )
     171                                $drafts =& $drafts_query->posts;
     172                }
     173                $_REQUEST = array(); // hack for get_default_post_to_edit()
     174        }
     175
     176        $post = get_default_post_to_edit();
    338177?>
    339178
    340179        <form name="post" action="<?php echo clean_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
    341                 <h3 id="quick-post-title"><label for="title"><?php _e('Title') ?></label></h3>
     180                <h4 id="quick-post-title"><label for="title"><?php _e('Title') ?></label></h4>
    342181                <div class="input-text-wrap">
    343182                        <input type="text" name="post_title" id="title" autocomplete="off" value="<?php echo attribute_escape( $post->post_title ); ?>" />
    344183                </div>
    345184
    346                 <h3><label for="content"><?php _e('Post') ?></label></h3>
     185                <h4><label for="content"><?php _e('Post') ?></label></h4>
    347186                <div class="textarea-wrap">
    348187                        <textarea name="content" id="quickpress-content" class="mceEditor" rows="3" cols="15"><?php echo $post->post_content; ?></textarea>
    349188                </div>
    350189
    351                 <h3><label for="tags-input"><?php _e('Tags') ?></label></h3>
     190                <h4><label for="tags-input"><?php _e('Tags') ?></label></h4>
    352191                <div class="input-text-wrap">
    353192                        <input type="text" name="tags_input" id="tags-input" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
    … …  
    359198                        <input type="hidden" name="quickpress_post_ID" value="<?php echo (int) $post->ID; ?>" />
    360199                        <?php wp_nonce_field('add-post'); ?>
    361                         <input type="submit" name="save" id="save-post" class="button" value="<?php _e('Save'); ?>" />
    362                         <input type="submit" name="save-cont" id="save-cont" class="button" value="<?php _e('Save and Continue'); ?>" />
    363                         <input type="submit" name="publish" id="publish" accesskey="p" class="button button-highlighted" value="<?php _e('Publish'); ?>" />
     200                        <input type="submit" name="save" id="save-post" class="button alignleft" value="<?php _e('Save Draft'); ?>" />
     201                        <input type="submit" name="publish" id="publish" accesskey="p" class="button button-highlighted alignright" value="<?php _e('Publish'); ?>" />
     202                        <br class="clear" />
    364203                </p>
    365204
     205        </form>
     206
    366207<?php
    367         $drafts_query = new WP_Query( array(
    368                 'post_type' => 'post',
    369                 'what_to_show' => 'posts',
    370                 'post_status' => 'draft',
    371                 'author' => $GLOBALS['current_user']->ID,
    372                 'posts_per_page' => 5,
    373                 'orderby' => 'modified',
    374                 'order' => 'DESC'
    375         ) );
    376 
    377         if ( $drafts_query->posts ) :
     208        if ( $drafts )
     209                wp_dashboard_recent_drafts( $drafts );
     210}
     211
     212function wp_dashboard_recent_drafts( $drafts = false ) {
     213        if ( !$drafts ) {
     214                $drafts_query = new WP_Query( array(
     215                        'post_type' => 'post',
     216                        'what_to_show' => 'posts',
     217                        'post_status' => 'draft',
     218                        'author' => $GLOBALS['current_user']->ID,
     219                        'posts_per_page' => 5,
     220                        'orderby' => 'modified',
     221                        'order' => 'DESC'
     222                ) );
     223                $drafts =& $drafts_query->posts;
     224        }
     225
     226        if ( $drafts && is_array( $drafts ) ) :
    378227                $list = array();
    379                 foreach ( $drafts_query->posts as $draft ) {
     228                foreach ( $drafts as $draft ) {
    380229                        $url = get_edit_post_link( $draft->ID );
    381230                        $title = _draft_or_post_title( $draft->ID );
    … …  
    383232                }
    384233?>
    385 
    386                 <h3><?php _e('Recent Drafts'); ?></h3>
    387                 <p id='recent-drafts'>
    388                         <?php echo join( ', ', $list ); ?>
    389                 </p>
     234        <ul>
     235                <li><?php echo join( "</li>\n<li>", $list ); ?></li>
     236        </ul>
    390237
    391238<?php
    392239
    393240        endif; // drafts
    394 
     241}
     242
     243/**
     244 * Display recent comments dashboard widget content.
     245 *
     246 * @since unknown
     247 */
     248function wp_dashboard_recent_comments() {
     249        list($comments, $total) = _wp_get_comment_list( '', false, 0, 5 );
     250
     251        if ( $comments ) :
    395252?>
    396253
    397         </form>
     254                <p class="view-all"><a href="edit-comments.php"><?php _e( 'View All Comments' ); ?></a></p>
     255                <div id="the-comment-list" class="list:comment">
    398256
    399257<?php
    400 
    401         echo $after_widget;
    402 }
    403 
    404 function wp_dashboard_quick_press_js() {
     258                foreach ( $comments as $comment )
     259                        _wp_dashboard_recent_comments_row( $comment );
    405260?>
    406261
    407 <script type="text/javascript">
    408 /* <![CDATA[ */
    409 var quickPressLoad = function($) {
    410         var act = $('#quickpost-action');
    411         var t = $('#quick-press').submit( function() {
    412                 if ( 'post-quickpress-save-cont' == act.val() ) {
    413                         return true;
    414                 }
    415 
    416                 var head = $('#dashboard_quick_press div.dashboard-widget').children( 'div').hide().end().find('h3 small');
    417                 head.prepend( '<img src="images/loading.gif" style="margin: 0 6px 0 0; vertical-align: middle" />' );
    418 
    419                 if ( 'post' == act.val() ) { act.val( 'post-quickpress-publish' ); }
    420 
    421                 if ( 'undefined' != typeof tinyMCE ) {
    422                         tinyMCE.get('quickpress-content').save();
    423                         tinyMCE.get('quickpress-content').remove();
    424                 }
    425 
    426                 $('#dashboard_quick_press').load( t.attr( 'action' ) + ' #dashboard_quick_press > *', t.serializeArray(), function() {
    427                         if ( 'undefined' != typeof wpTeenyMCEInit && $.isFunction( wpTeenyMCEInit ) ) { wpTeenyMCEInit(); }
    428                         quickPressLoad($);
    429                 } );
    430                 return false;
    431         } );
    432 
    433         $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } );
    434         $('#save-cont').click( function() { act.val( 'post-quickpress-save-cont' ); t.attr( 'action', 'post.php' ); } );
    435 };
    436 jQuery( quickPressLoad );
    437 /* ]]> */
    438 </script>
     262                </div>
     263
    439264<?php
    440 }
    441 
    442 /**
    443  * Display recent comments dashboard widget content.
    444  *
    445  * @since unknown
    446  *
    447  * @param unknown_type $sidebar_args
    448  */
    449 function wp_dashboard_recent_comments( $sidebar_args ) {
    450         global $comment;
    451         extract( $sidebar_args, EXTR_SKIP );
    452 
    453         echo $before_widget;
    454 
    455         echo $before_title;
    456         echo $widget_name;
    457         echo $after_title;
    458 
    459         $lambda = create_function( '', 'return 5;' );
    460         add_filter( 'option_posts_per_rss', $lambda ); // hack - comments query doesn't accept per_page parameter
    461         $comments_query = new WP_Query(array('feed' => 'rss2', 'withcomments' => 1));
    462         remove_filter( 'option_posts_per_rss', $lambda );
    463 
    464         $is_first = true;
    465 
    466         if ( $comments_query->have_comments() ) {
    467                 while ( $comments_query->have_comments() ) { $comments_query->the_comment();
    468 
    469                         $comment_post_url = get_permalink( $comment->comment_post_ID );
    470                         $comment_post_title = get_the_title( $comment->comment_post_ID );
    471                         $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
    472                         $comment_link = '<a class="comment-link" href="' . get_comment_link() . '">#</a>';
    473                         $comment_meta = sprintf( __( 'From <strong>%1$s</strong> on %2$s %3$s' ), get_comment_author(), $comment_post_link, $comment_link );
    474 
    475                         if ( $is_first ) : $is_first = false;
     265                wp_comment_reply( -1, false, 'dashboard', false );
     266
     267        else :
    476268?>
    477                                 <blockquote><p>&#8220;<?php comment_excerpt(); ?>&#8221;</p></blockquote>
    478                                 <p class='comment-meta'><?php echo $comment_meta; ?></p>
     269
     270        <p><?php _e( 'No comments yet.' ); ?></p>
     271
    479272<?php
    480                                 if ( $comments_query->comment_count > 1 ) : ?>
    481                                 <ul id="dashboard-comments-list">
     273        endif; // $comments;
     274}
     275
     276function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
     277        static $date = false;
     278        static $today = false;
     279        static $yesterday = false;
     280
     281        $GLOBALS['comment'] =& $comment;
     282
     283        if ( $show_date ) {
     284                if ( !$today )
     285                        $today = gmdate( get_option( 'date_format' ), time() + get_option( 'gmt_offset' ) );
     286                if ( !$yesterday )
     287                        $yesterday = gmdate( get_option( 'date_format' ), strtotime( 'yesterday' ) + get_option( 'gmt_offset' ) );
     288                $wordy_dates = array( $today => __( 'Today' ), $yesterday => __( 'Yesterday' ) );
     289       
     290                $comment_date = gmdate( get_option( 'date_format' ), strtotime( $comment->comment_date ) + get_option( 'gmt_offset' ) );
     291                if ( $comment_date != $date ) {
     292                        $date = $comment_date;
     293                        echo '<h4>' . ( isset( $wordy_dates[$date] ) ? $wordy_dates[$date] : $date ) . ":</h4>\n";
     294                }
     295        }
     296
     297        $comment_post_url = get_permalink( $comment->comment_post_ID );
     298        $comment_post_title = get_the_title( $comment->comment_post_ID );
     299        $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
     300        $comment_link = '<a class="comment-link" href="' . get_comment_link() . '">#</a>';
     301
     302        $delete_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
     303        $approve_url = clean_url( wp_nonce_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) );
     304        $unapprove_url = clean_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) );
     305        $spam_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
     306
     307        $actions = array();
     308
     309        if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
     310                $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
     311                $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
     312                $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
     313                $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . __( 'Spam' ) . '</a>';
     314                $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';
     315                $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
     316
     317                $actions = apply_filters( 'comment_row_actions', $actions, $comment );
     318
     319                $i = 0;
     320                $actions_string = '';
     321                foreach ( $actions as $action => $link ) {
     322                        ++$i;
     323                        ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
     324
     325                        // Reply and quickedit need a hide-if-no-js span
     326                        if ( 'reply' == $action || 'quickedit' == $action )
     327                                $action .= ' hide-if-no-js';
     328
     329                        $actions_string .= "<span class='$action'>$sep$link</span>";
     330                }
     331        }
     332
     333?>
     334
     335                <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status() ) ); ?>>
     336                        <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
     337
     338                        <?php echo get_avatar( $comment, 32 ); ?>
     339                        <span class="comment-meta"><?php printf( __( '%1$s in response to %2$s:' ), '<cite>' . get_comment_author() . '</cite>', $comment_post_link ); ?></span>
     340
     341                        <?php
     342                        else :
     343                                switch ( $comment->comment_type ) :
     344                                case 'pingback' :
     345                                        $type = __( 'Pingback' );
     346                                        break;
     347                                case 'trackback' :
     348                                        $type = __( 'Trackback' );
     349                                        break;
     350                                default :
     351                                        $type = ucwords( $comment->comment_type );
     352                                endswitch;
     353                                $type = wp_specialchars( $type );
     354                        ?>
     355
     356                        <span class="comment-meta"><?php printf( __( '%3$s on %2$s: %1$s' ), '<cite>' . get_comment_author() . '</cite>', $comment_post_link, "<strong>$type</strong>" ); ?></span>
     357
     358                        <?php endif; // comment_type ?>
     359                        <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
     360                        <p class="comment-actions"><?php echo $actions_string; ?></p>
     361                </div>
    482362<?php
    483                                 endif; // comment_count
    484                         else : // is_first
    485 ?>
    486 
    487                                         <li class='comment-meta'><?php echo $comment_meta; ?></li>
    488 <?php
    489                         endif; // is_first
    490                 }
    491 
    492                 if ( $comments_query->comment_count > 1 ) : ?>
    493                                 </ul>
    494 <?php
    495                 endif; // comment_count;
    496 
    497         }
    498 
    499         echo $after_widget;
     363}
     364
     365function wp_dashboard_incoming_links() {
     366        wp_dashboard_cached_rss_widget( 'dashboard_incoming_links', 'wp_dashboard_incoming_links_output' );
    500367}
    501368
    502369/**
    503370 * Display incoming links dashboard widget content.
    504  *
    505  * $sidebar_args are handled by wp_dashboard_empty().
    506371 *
    507372 * @since unknown
    … …  
    566431}
    567432
     433function wp_dashboard_incoming_links_control() {
     434        wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) );
     435}
     436
     437function wp_dashboard_primary() {
     438        wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_rss_output' );
     439}
     440
     441function wp_dashboard_primary_control() {
     442        wp_dashboard_rss_control( 'dashboard_primary' );
     443}
     444
    568445/**
    569446 * {@internal Missing Short Description}}
    570  *
    571  * $sidebar_args are handled by wp_dashboard_empty().
    572447 *
    573448 * @since unknown
    … …  
    580455}
    581456
     457function wp_dashboard_secondary() {
     458        wp_dashboard_cached_rss_widget( 'dashboard_secondary', 'wp_dashboard_secondary_output' );
     459}
     460
     461function wp_dashboard_secondary_control() {
     462        wp_dashboard_rss_control( 'dashboard_secondary', array( 'show_summary' => false, 'show_author' => false, 'show_date' => false ) );
     463}
     464
    582465/**
    583466 * Display secondary dashboard RSS widget feed.
    584  *
    585  * $sidebar_args are handled by wp_dashboard_empty().
    586467 *
    587468 * @since unknown
    … …  
    610491}
    611492
     493function wp_dashboard_plugins() {
     494        wp_dashboard_cached_rss_widget( 'dashboard_plugins', 'wp_dashboard_plugins_output', array(
     495                'http://wordpress.org/extend/plugins/rss/browse/popular/',
     496                'http://wordpress.org/extend/plugins/rss/browse/new/',
     497                'http://wordpress.org/extend/plugins/rss/browse/updated/'
     498        ) );
     499}
     500
    612501/**
    613502 * Display plugins most popular, newest plugins, and recently updated widget text.
    614  *
    615  * $sidebar_args are handled by wp_dashboard_empty().
    616503 *
    617504 * @since unknown
    … …  
    714601}
    715602
    716 /**
    717  * Empty widget used for JS/AJAX created output.
    718  *
    719  * Callback inserts content between before_widget and after_widget. Used when
    720  * widget is in edit mode. Can also be used for custom widgets.
    721  *
    722  * @since unknown
    723  *
    724  * @param array $sidebar_args
    725  * @param callback $callback Optional. Only used in edit mode.
    726  */
    727 function wp_dashboard_empty( $sidebar_args, $callback = false ) {
    728         extract( $sidebar_args, EXTR_SKIP );
    729 
    730         echo $before_widget;
    731 
    732         echo $before_title;
    733         echo $widget_name;
    734         echo $after_title;
    735 
    736         // When in edit mode, the callback passed to this function is the widget_control callback
    737         if ( $callback && is_callable( $callback ) ) {
    738                 $args = array_slice( func_get_args(), 2 );
    739                 array_unshift( $args, $widget_id );
    740                 call_user_func_array( $callback, $args );
    741         }
    742 
    743         echo $after_widget;
    744 }
    745 
    746 /* Dashboard Widgets Controls. See also wp_dashboard_empty() */
     603/* Dashboard Widgets Controls */
    747604
    748605// Temp
    … …  
    760617 */
    761618function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
    762         global $wp_registered_widget_controls;
    763         if ( is_scalar($widget_control_id) && $widget_control_id && isset($wp_registered_widget_controls[$widget_control_id]) && is_callable($wp_registered_widget_controls[$widget_control_id]['callback']) )
    764                 call_user_func_array( $wp_registered_widget_controls[$widget_control_id]['callback'], $wp_registered_widget_controls[$widget_control_id]['params'] );
     619        global $wp_dashboard_control_callbacks;
     620       
     621        if ( is_scalar($widget_control_id) && $widget_control_id && isset($wp_dashboard_control_callbacks[$widget_control_id]) && is_callable($wp_dashboard_control_callbacks[$widget_control_id]) ) {
     622                call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
     623        }
    765624}
    766625
    … …  
    773632 * @since unknown
    774633 *
    775  * @param array $args Expects 'widget_id' and 'form_inputs'.
    776  * @return bool|null False if no widget_id is given. Null on success.
    777  */
    778 function wp_dashboard_rss_control( $args ) {
    779         extract( $args );
    780         if ( !$widget_id )
    781                 return false;
    782 
     634 * @param string widget_id
     635 * @param array form_inputs
     636 */
     637function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
    783638        if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
    784639                $widget_options = array();
Note: See TracChangeset for help on using the changeset viewer.