]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/dashboard.php
Wordpress 3.0-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / dashboard.php
1 <?php
2 /**
3  * WordPress Dashboard Widget Administration Panel API
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /**
10  * Registers dashboard widgets.
11  *
12  * handles POST data, sets up filters.
13  *
14  * @since unknown
15  */
16 function wp_dashboard_setup() {
17         global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
18         $wp_dashboard_control_callbacks = array();
19
20         $update = false;
21         $widget_options = get_option( 'dashboard_widget_options' );
22         if ( !$widget_options || !is_array($widget_options) )
23                 $widget_options = array();
24
25         /* Register Widgets and Controls */
26
27         // Right Now
28         wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' );
29
30         // Recent Comments Widget
31         if ( !isset( $widget_options['dashboard_recent_comments'] ) || !isset( $widget_options['dashboard_recent_comments']['items'] ) ) {
32                 $update = true;
33                 $widget_options['dashboard_recent_comments'] = array(
34                         'items' => 5,
35                 );
36         }
37         $recent_comments_title = __( 'Recent Comments' );
38         wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments', 'wp_dashboard_recent_comments_control' );
39
40         // Incoming Links Widget
41         if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) {
42                 $update = true;
43                 $num_items = isset($widget_options['dashboard_incoming_links']['items']) ? $widget_options['dashboard_incoming_links']['items'] : 10;
44                 $widget_options['dashboard_incoming_links'] = array(
45                         'home' => get_option('home'),
46                         'link' => apply_filters( 'dashboard_incoming_links_link', 'http://blogsearch.google.com/blogsearch?scoring=d&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
47                         'url' => isset($widget_options['dashboard_incoming_links']['url']) ? apply_filters( 'dashboard_incoming_links_feed', $widget_options['dashboard_incoming_links']['url'] ) : apply_filters( 'dashboard_incoming_links_feed', 'http://blogsearch.google.com/blogsearch_feeds?scoring=d&ie=utf-8&num=' . $num_items . '&output=rss&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
48                         'items' => $num_items,
49                         'show_date' => isset($widget_options['dashboard_incoming_links']['show_date']) ? $widget_options['dashboard_incoming_links']['show_date'] : false
50                 );
51         }
52         wp_add_dashboard_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_incoming_links', 'wp_dashboard_incoming_links_control' );
53
54         // WP Plugins Widget
55         if ( current_user_can( 'install_plugins' ) )
56                 wp_add_dashboard_widget( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_plugins' );
57
58         // QuickPress Widget
59         if ( current_user_can('edit_posts') )
60                 wp_add_dashboard_widget( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_quick_press' );
61
62         // Recent Drafts
63         if ( current_user_can('edit_posts') )
64                 wp_add_dashboard_widget( 'dashboard_recent_drafts', __('Recent Drafts'), 'wp_dashboard_recent_drafts' );
65
66         // Primary feed (Dev Blog) Widget
67         if ( !isset( $widget_options['dashboard_primary'] ) ) {
68                 $update = true;
69                 $widget_options['dashboard_primary'] = array(
70                         'link' => apply_filters( 'dashboard_primary_link',  __( 'http://wordpress.org/development/' ) ),
71                         'url' => apply_filters( 'dashboard_primary_feed',  __( 'http://wordpress.org/development/feed/' ) ),
72                         'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
73                         'items' => 2,
74                         'show_summary' => 1,
75                         'show_author' => 0,
76                         'show_date' => 1,
77                 );
78         }
79         wp_add_dashboard_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_primary', 'wp_dashboard_primary_control' );
80
81         // Secondary Feed (Planet) Widget
82         if ( !isset( $widget_options['dashboard_secondary'] ) ) {
83                 $update = true;
84                 $widget_options['dashboard_secondary'] = array(
85                         'link' => apply_filters( 'dashboard_secondary_link',  __( 'http://planet.wordpress.org/' ) ),
86                         'url' => apply_filters( 'dashboard_secondary_feed',  __( 'http://planet.wordpress.org/feed/' ) ),
87                         'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
88                         'items' => 5,
89                         'show_summary' => 0,
90                         'show_author' => 0,
91                         'show_date' => 0,
92                 );
93         }
94         wp_add_dashboard_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_secondary', 'wp_dashboard_secondary_control' );
95
96         // Hook to register new widgets
97         do_action( 'wp_dashboard_setup' );
98
99         // Filter widget order
100         $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
101
102         foreach ( $dashboard_widgets as $widget_id ) {
103                 $name = empty( $wp_registered_widgets[$widget_id]['all_link'] ) ? $wp_registered_widgets[$widget_id]['name'] : $wp_registered_widgets[$widget_id]['name'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __('View all') . '</a>';
104                 wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
105         }
106
107         if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
108                 ob_start(); // hack - but the same hack wp-admin/widgets.php uses
109                 wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
110                 ob_end_clean();
111                 wp_redirect( remove_query_arg( 'edit' ) );
112                 exit;
113         }
114
115         if ( $update )
116                 update_option( 'dashboard_widget_options', $widget_options );
117
118         do_action('do_meta_boxes', 'dashboard', 'normal', '');
119         do_action('do_meta_boxes', 'dashboard', 'side', '');
120 }
121
122 function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null ) {
123         global $wp_dashboard_control_callbacks;
124         if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
125                 $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
126                 if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
127                         list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
128                         $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
129                         add_meta_box( $widget_id, $widget_name, '_wp_dashboard_control_callback', 'dashboard', 'normal', 'core' );
130                         return;
131                 }
132                 list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
133                 $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
134         }
135         $side_widgets = array('dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_primary', 'dashboard_secondary');
136         $location = 'normal';
137         if ( in_array($widget_id, $side_widgets) )
138                 $location = 'side';
139         add_meta_box( $widget_id, $widget_name , $callback, 'dashboard', $location, 'core' );
140 }
141
142 function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
143         echo '<form action="" method="post" class="dashboard-widget-control-form">';
144         wp_dashboard_trigger_widget_control( $meta_box['id'] );
145         echo '<p class="submit"><input type="hidden" name="widget_id" value="' . esc_attr($meta_box['id']) . '" /><input type="submit" value="' . esc_attr__( 'Submit' ) . '" /></p>';
146
147         echo '</form>';
148 }
149
150 /**
151  * Displays the dashboard.
152  *
153  * @since unknown
154  */
155 function wp_dashboard() {
156         global $screen_layout_columns;
157
158         $hide2 = $hide3 = $hide4 = '';
159         switch ( $screen_layout_columns ) {
160                 case 4:
161                         $width = 'width:24.5%;';
162                         break;
163                 case 3:
164                         $width = 'width:32.67%;';
165                         $hide4 = 'display:none;';
166                         break;
167                 case 2:
168                         $width = 'width:49%;';
169                         $hide3 = $hide4 = 'display:none;';
170                         break;
171                 default:
172                         $width = 'width:98%;';
173                         $hide2 = $hide3 = $hide4 = 'display:none;';
174         }
175 ?>
176 <div id="dashboard-widgets" class="metabox-holder">
177 <?php
178         echo "\t<div class='postbox-container' style='$width'>\n";
179         do_meta_boxes( 'dashboard', 'normal', '' );
180
181         echo "\t</div><div class='postbox-container' style='{$hide2}$width'>\n";
182         do_meta_boxes( 'dashboard', 'side', '' );
183
184         echo "\t</div><div class='postbox-container' style='{$hide3}$width'>\n";
185         do_meta_boxes( 'dashboard', 'column3', '' );
186
187         echo "\t</div><div class='postbox-container' style='{$hide4}$width'>\n";
188         do_meta_boxes( 'dashboard', 'column4', '' );
189 ?>
190 </div></div>
191
192 <form style="display:none" method="get" action="">
193         <p>
194 <?php
195         wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
196         wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
197 ?>
198         </p>
199 </form>
200
201 <?php
202 }
203
204 /* Dashboard Widgets */
205
206 function wp_dashboard_right_now() {
207         global $wp_registered_sidebars;
208
209         $num_posts = wp_count_posts( 'post' );
210         $num_pages = wp_count_posts( 'page' );
211
212         $num_cats  = wp_count_terms('category');
213
214         $num_tags = wp_count_terms('post_tag');
215
216         $num_comm = wp_count_comments( );
217
218         echo "\n\t".'<div class="table table_content">';
219         echo "\n\t".'<p class="sub">' . __('Content') . '</p>'."\n\t".'<table>';
220         echo "\n\t".'<tr class="first">';
221
222         // Posts
223         $num = number_format_i18n( $num_posts->publish );
224         $text = _n( 'Post', 'Posts', intval($num_posts->publish) );
225         if ( current_user_can( 'edit_posts' ) ) {
226                 $num = "<a href='edit.php'>$num</a>";
227                 $text = "<a href='edit.php'>$text</a>";
228         }
229         echo '<td class="first b b-posts">' . $num . '</td>';
230         echo '<td class="t posts">' . $text . '</td>';
231
232         echo '</tr><tr>';
233         /* TODO: Show status breakdown on hover
234         if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds.  Don't show if !current_user_can
235                 $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( _n( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>';
236         }
237         if ( $can_edit_posts && !empty($num_posts->draft) ) {
238                 $post_type_texts[] = '<a href="edit.php?post_status=draft">'.sprintf( _n( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'</a>';
239         }
240         if ( $can_edit_posts && !empty($num_posts->future) ) {
241                 $post_type_texts[] = '<a href="edit.php?post_status=future">'.sprintf( _n( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'</a>';
242         }
243         if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
244                 $pending_text = sprintf( _n( 'There is <a href="%1$s">%2$s post</a> pending your review.', 'There are <a href="%1$s">%2$s posts</a> pending your review.', $num_posts->pending ), 'edit.php?post_status=pending', number_format_i18n( $num_posts->pending ) );
245         } else {
246                 $pending_text = '';
247         }
248         */
249
250         // Pages
251         $num = number_format_i18n( $num_pages->publish );
252         $text = _n( 'Page', 'Pages', $num_pages->publish );
253         if ( current_user_can( 'edit_pages' ) ) {
254                 $num = "<a href='edit.php?post_type=page'>$num</a>";
255                 $text = "<a href='edit.php?post_type=page'>$text</a>";
256         }
257         echo '<td class="first b b_pages">' . $num . '</td>';
258         echo '<td class="t pages">' . $text . '</td>';
259
260         echo '</tr><tr>';
261
262         // Categories
263         $num = number_format_i18n( $num_cats );
264         $text = _n( 'Category', 'Categories', $num_cats );
265         if ( current_user_can( 'manage_categories' ) ) {
266                 $num = "<a href='edit-tags.php?taxonomy=category'>$num</a>";
267                 $text = "<a href='edit-tags.php?taxonomy=category'>$text</a>";
268         }
269         echo '<td class="first b b-cats">' . $num . '</td>';
270         echo '<td class="t cats">' . $text . '</td>';
271
272         echo '</tr><tr>';
273
274         // Tags
275         $num = number_format_i18n( $num_tags );
276         $text = _n( 'Tag', 'Tags', $num_tags );
277         if ( current_user_can( 'manage_categories' ) ) {
278                 $num = "<a href='edit-tags.php'>$num</a>";
279                 $text = "<a href='edit-tags.php'>$text</a>";
280         }
281         echo '<td class="first b b-tags">' . $num . '</td>';
282         echo '<td class="t tags">' . $text . '</td>';
283
284         echo "</tr>";
285         do_action('right_now_content_table_end');
286         echo "\n\t</table>\n\t</div>";
287
288
289         echo "\n\t".'<div class="table table_discussion">';
290         echo "\n\t".'<p class="sub">' . __('Discussion') . '</p>'."\n\t".'<table>';
291         echo "\n\t".'<tr class="first">';
292
293         // Total Comments
294         $num = '<span class="total-count">' . number_format_i18n($num_comm->total_comments) . '</span>';
295         $text = _n( 'Comment', 'Comments', $num_comm->total_comments );
296         if ( current_user_can( 'moderate_comments' ) ) {
297                 $num = '<a href="edit-comments.php">' . $num . '</a>';
298                 $text = '<a href="edit-comments.php">' . $text . '</a>';
299         }
300         echo '<td class="b b-comments">' . $num . '</td>';
301         echo '<td class="last t comments">' . $text . '</td>';
302
303         echo '</tr><tr>';
304
305         // Approved Comments
306         $num = '<span class="approved-count">' . number_format_i18n($num_comm->approved) . '</span>';
307         $text = _nx( 'Approved', 'Approved', $num_comm->approved, 'Right Now' );
308         if ( current_user_can( 'moderate_comments' ) ) {
309                 $num = "<a href='edit-comments.php?comment_status=approved'>$num</a>";
310                 $text = "<a class='approved' href='edit-comments.php?comment_status=approved'>$text</a>";
311         }
312         echo '<td class="b b_approved">' . $num . '</td>';
313         echo '<td class="last t">' . $text . '</td>';
314
315         echo "</tr>\n\t<tr>";
316
317         // Pending Comments
318         $num = '<span class="pending-count">' . number_format_i18n($num_comm->moderated) . '</span>';
319         $text = _n( 'Pending', 'Pending', $num_comm->moderated );
320         if ( current_user_can( 'moderate_comments' ) ) {
321                 $num = "<a href='edit-comments.php?comment_status=moderated'>$num</a>";
322                 $text = "<a class='waiting' href='edit-comments.php?comment_status=moderated'>$text</a>";
323         }
324         echo '<td class="b b-waiting">' . $num . '</td>';
325         echo '<td class="last t">' . $text . '</td>';
326
327         echo "</tr>\n\t<tr>";
328
329         // Spam Comments
330         $num = number_format_i18n($num_comm->spam);
331         $text = _nx( 'Spam', 'Spam', $num_comm->spam, 'comment' );
332         if ( current_user_can( 'moderate_comments' ) ) {
333                 $num = "<a href='edit-comments.php?comment_status=spam'><span class='spam-count'>$num</span></a>";
334                 $text = "<a class='spam' href='edit-comments.php?comment_status=spam'>$text</a>";
335         }
336         echo '<td class="b b-spam">' . $num . '</td>';
337         echo '<td class="last t">' . $text . '</td>';
338
339         echo "</tr>";
340         do_action('right_now_table_end');
341         do_action('right_now_discussion_table_end');
342         echo "\n\t</table>\n\t</div>";
343
344         echo "\n\t".'<div class="versions">';
345         $ct = current_theme_info();
346
347         echo "\n\t<p>";
348         if ( !empty($wp_registered_sidebars) ) {
349                 $sidebars_widgets = wp_get_sidebars_widgets();
350                 $num_widgets = 0;
351                 foreach ( (array) $sidebars_widgets as $k => $v ) {
352                         if ( 'wp_inactive_widgets' == $k )
353                                 continue;
354                         if ( is_array($v) )
355                                 $num_widgets = $num_widgets + count($v);
356                 }
357                 $num = number_format_i18n( $num_widgets );
358
359                 $switch_themes = $ct->title;
360                 if ( current_user_can( 'switch_themes') ) {
361                         echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
362                         $switch_themes = '<a href="themes.php">' . $switch_themes . '</a>';
363                 }
364                 if ( current_user_can( 'edit_theme_options' ) ) {
365                         printf(_n('Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widget</a></span>', 'Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widgets</a></span>', $num_widgets), $switch_themes, $num);
366                 } else {
367                         printf(_n('Theme <span class="b">%1$s</span> with <span class="b">%2$s Widget</span>', 'Theme <span class="b">%1$s</span> with <span class="b">%2$s Widgets</span>', $num_widgets), $switch_themes, $num);
368                 }
369         } else {
370                 if ( current_user_can( 'switch_themes' ) ) {
371                         echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
372                         printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $ct->title );
373                 } else {
374                         printf( __('Theme <span class="b">%1$s</span>'), $ct->title );
375                 }
376         }
377         echo '</p>';
378
379         update_right_now_message();
380
381         echo "\n\t".'<br class="clear" /></div>';
382         do_action( 'rightnow_end' );
383         do_action( 'activity_box_end' );
384 }
385
386 function wp_dashboard_quick_press_output() {
387         global $post_ID;
388
389         $drafts = false;
390         if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
391                 $view = get_permalink( $_POST['post_ID'] );
392                 $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
393                 if ( 'post-quickpress-publish' == $_POST['action'] ) {
394                         if ( current_user_can('publish_posts') )
395                                 printf( '<div class="updated"><p>' . __( 'Post published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( $view ), $edit );
396                         else
397                                 printf( '<div class="updated"><p>' . __( 'Post submitted. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
398                 } else {
399                         printf( '<div class="updated"><p>' . __( 'Draft saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
400                         $drafts_query = new WP_Query( array(
401                                 'post_type' => 'post',
402                                 'post_status' => 'draft',
403                                 'author' => $GLOBALS['current_user']->ID,
404                                 'posts_per_page' => 1,
405                                 'orderby' => 'modified',
406                                 'order' => 'DESC'
407                         ) );
408
409                         if ( $drafts_query->posts )
410                                 $drafts =& $drafts_query->posts;
411                 }
412                 printf('<p class="textright">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="' . esc_url( admin_url( 'tools.php' ) ) . '">' . __('Press This') . '</a>' );
413                 $_REQUEST = array(); // hack for get_default_post_to_edit()
414         }
415
416         /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
417         $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
418         if ( $last_post_id ) {
419                 $post = get_post( $last_post_id );
420                 if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
421                         $post = get_default_post_to_edit('post', true);
422                         update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
423                 } else {
424                         $post->post_title = ''; // Remove the auto draft title
425                 }
426         } else {
427                 $post = get_default_post_to_edit('post', true);
428                 update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
429         }
430
431         $post_ID = (int) $post->ID;
432 ?>
433
434         <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
435                 <h4 id="quick-post-title"><label for="title"><?php _e('Title') ?></label></h4>
436                 <div class="input-text-wrap">
437                         <input type="text" name="post_title" id="title" tabindex="1" autocomplete="off" value="<?php echo esc_attr( $post->post_title ); ?>" />
438                 </div>
439
440                 <?php if ( current_user_can( 'upload_files' ) ) : ?>
441                 <div id="media-buttons" class="hide-if-no-js">
442                         <?php do_action( 'media_buttons' ); ?>
443                 </div>
444                 <?php endif; ?>
445
446                 <h4 id="content-label"><label for="content"><?php _e('Content') ?></label></h4>
447                 <div class="textarea-wrap">
448                         <textarea name="content" id="content" class="mceEditor" rows="3" cols="15" tabindex="2"><?php echo $post->post_content; ?></textarea>
449                 </div>
450
451                 <script type="text/javascript">edCanvas = document.getElementById('content');edInsertContent = null;</script>
452
453                 <h4><label for="tags-input"><?php _e('Tags') ?></label></h4>
454                 <div class="input-text-wrap">
455                         <input type="text" name="tags_input" id="tags-input" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
456                 </div>
457
458                 <p class="submit">
459                         <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
460                         <input type="hidden" name="quickpress_post_ID" value="<?php echo $post_ID; ?>" />
461                         <input type="hidden" name="post_type" value="post" />
462                         <?php wp_nonce_field('add-post'); ?>
463                         <input type="submit" name="save" id="save-post" class="button" tabindex="4" value="<?php esc_attr_e('Save Draft'); ?>" />
464                         <input type="reset" value="<?php esc_attr_e( 'Reset' ); ?>" class="button" />
465                         <span id="publishing-action">
466                                 <input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="<?php current_user_can('publish_posts') ? esc_attr_e('Publish') : esc_attr_e('Submit for Review'); ?>" />
467                                 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
468                         </span>
469                         <br class="clear" />
470                 </p>
471
472         </form>
473
474 <?php
475         if ( $drafts )
476                 wp_dashboard_recent_drafts( $drafts );
477 }
478
479 function wp_dashboard_quick_press() {
480         echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
481 }
482
483 function wp_dashboard_recent_drafts( $drafts = false ) {
484         if ( !$drafts ) {
485                 $drafts_query = new WP_Query( array(
486                         'post_type' => 'post',
487                         'post_status' => 'draft',
488                         'author' => $GLOBALS['current_user']->ID,
489                         'posts_per_page' => 5,
490                         'orderby' => 'modified',
491                         'order' => 'DESC'
492                 ) );
493                 $drafts =& $drafts_query->posts;
494         }
495
496         if ( $drafts && is_array( $drafts ) ) {
497                 $list = array();
498                 foreach ( $drafts as $draft ) {
499                         $url = get_edit_post_link( $draft->ID );
500                         $title = _draft_or_post_title( $draft->ID );
501                         $item = "<h4><a href='$url' title='" . sprintf( __( 'Edit &#8220;%s&#8221;' ), esc_attr( $title ) ) . "'>" . esc_html($title) . "</a> <abbr title='" . get_the_time(__('Y/m/d g:i:s A'), $draft) . "'>" . get_the_time( get_option( 'date_format' ), $draft ) . '</abbr></h4>';
502                         if ( $the_content = preg_split( '#\s#', strip_tags( $draft->post_content ), 11, PREG_SPLIT_NO_EMPTY ) )
503                                 $item .= '<p>' . join( ' ', array_slice( $the_content, 0, 10 ) ) . ( 10 < count( $the_content ) ? '&hellip;' : '' ) . '</p>';
504                         $list[] = $item;
505                 }
506 ?>
507         <ul>
508                 <li><?php echo join( "</li>\n<li>", $list ); ?></li>
509         </ul>
510         <p class="textright"><a href="edit.php?post_status=draft" class="button"><?php _e('View all'); ?></a></p>
511 <?php
512         } else {
513                 _e('There are no drafts at the moment');
514         }
515 }
516
517 /**
518  * Display recent comments dashboard widget content.
519  *
520  * @since unknown
521  */
522 function wp_dashboard_recent_comments() {
523         global $wpdb;
524
525         if ( current_user_can('edit_posts') )
526                 $allowed_states = array('0', '1');
527         else
528                 $allowed_states = array('1');
529
530         // Select all comment types and filter out spam later for better query performance.
531         $comments = array();
532         $start = 0;
533
534         $widgets = get_option( 'dashboard_widget_options' );
535         if ( isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] ) )
536                 $total_items = (int) $widgets['dashboard_recent_comments']['items'];
537         else
538                 $total_items = 5;
539
540         while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) {
541
542                 foreach ( $possible as $comment ) {
543                         if ( count( $comments ) >= $total_items )
544                                 break;
545                         if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) )
546                                 $comments[] = $comment;
547                 }
548
549                 $start = $start + 50;
550         }
551
552         if ( $comments ) :
553 ?>
554
555                 <div id="the-comment-list" class="list:comment">
556 <?php
557                 foreach ( $comments as $comment )
558                         _wp_dashboard_recent_comments_row( $comment );
559 ?>
560
561                 </div>
562
563 <?php
564                 if ( current_user_can('edit_posts') ) { ?>
565                         <p class="textright"><a href="edit-comments.php" class="button"><?php _e('View all'); ?></a></p>
566 <?php   }
567
568                 wp_comment_reply( -1, false, 'dashboard', false );
569                 wp_comment_trashnotice();
570
571         else :
572 ?>
573
574         <p><?php _e( 'No comments yet.' ); ?></p>
575
576 <?php
577         endif; // $comments;
578 }
579
580 function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
581         $GLOBALS['comment'] =& $comment;
582
583         $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
584         $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
585         $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
586         $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
587
588         $actions_string = '';
589         if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
590                 // preorder it: Approve | Reply | Edit | Spam | Trash
591                 $actions = array(
592                         'approve' => '', 'unapprove' => '',
593                         'reply' => '',
594                         'edit' => '',
595                         'spam' => '',
596                         'trash' => '', 'delete' => ''
597                 );
598
599                 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
600                 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
601
602                 $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
603                 $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
604                 $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
605                 $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
606                 $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
607
608                 $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>';
609                 $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>';
610                 $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
611                 $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
612                 $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' ) . "'>" . /* translators: mark as spam link */  _x( 'Spam', 'verb' ) . '</a>';
613                 if ( !EMPTY_TRASH_DAYS )
614                         $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
615                 else
616                         $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . __( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>';
617
618                 $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
619
620                 $i = 0;
621                 foreach ( $actions as $action => $link ) {
622                         ++$i;
623                         ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
624
625                         // Reply and quickedit need a hide-if-no-js span
626                         if ( 'reply' == $action || 'quickedit' == $action )
627                                 $action .= ' hide-if-no-js';
628
629                         $actions_string .= "<span class='$action'>$sep$link</span>";
630                 }
631         }
632
633 ?>
634
635                 <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
636                         <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
637
638                         <?php echo get_avatar( $comment, 50 ); ?>
639
640                         <div class="dashboard-comment-wrap">
641                         <h4 class="comment-meta">
642                                 <?php printf( /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */__( 'From %1$s on %2$s%3$s' ),
643                                         '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link.' '.$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?>
644                         </h4>
645
646                         <?php
647                         else :
648                                 switch ( $comment->comment_type ) :
649                                 case 'pingback' :
650                                         $type = __( 'Pingback' );
651                                         break;
652                                 case 'trackback' :
653                                         $type = __( 'Trackback' );
654                                         break;
655                                 default :
656                                         $type = ucwords( $comment->comment_type );
657                                 endswitch;
658                                 $type = esc_html( $type );
659                         ?>
660                         <div class="dashboard-comment-wrap">
661                         <?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?>
662                         <h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link." ".$comment_link ); ?></h4>
663                         <p class="comment-author"><?php comment_author_link(); ?></p>
664
665                         <?php endif; // comment_type ?>
666                         <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
667                         <p class="row-actions"><?php echo $actions_string; ?></p>
668                         </div>
669                 </div>
670 <?php
671 }
672
673 /**
674  * The recent comments dashboard widget control.
675  *
676  * @since 3.0.0
677  */
678 function wp_dashboard_recent_comments_control() {
679         if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
680                 $widget_options = array();
681
682         if ( !isset($widget_options['dashboard_recent_comments']) )
683                 $widget_options['dashboard_recent_comments'] = array();
684
685         if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-recent-comments']) ) {
686                 $number = (int) stripslashes($_POST['widget-recent-comments']['items']);
687                 if ( $number < 1 || $number > 30 )
688                         $number = 5;
689                 $widget_options['dashboard_recent_comments']['items'] = $number;
690                 update_option( 'dashboard_widget_options', $widget_options );
691         }
692
693         $number = isset( $widget_options['dashboard_recent_comments']['items'] ) ? (int) $widget_options['dashboard_recent_comments']['items'] : '';
694
695         echo '<p><label for="comments-number">' . __('Number of comments to show:') . '</label>';
696         echo '<input id="comments-number" name="widget-recent-comments[items]" type="text" value="' . $number . '" size="3" /> <small>' . __( '(at most 30)' ) . '</small></p>';
697 }
698
699 function wp_dashboard_incoming_links() {
700         echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
701 }
702
703 /**
704  * Display incoming links dashboard widget content.
705  *
706  * @since unknown
707  */
708 function wp_dashboard_incoming_links_output() {
709         $widgets = get_option( 'dashboard_widget_options' );
710         @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
711         $rss = fetch_feed( $url );
712
713         if ( is_wp_error($rss) ) {
714                 if ( is_admin() || current_user_can('manage_options') ) {
715                         echo '<p>';
716                         printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
717                         echo '</p>';
718                 }
719                 return;
720         }
721
722         if ( !$rss->get_item_quantity() ) {
723                 echo '<p>' . __('This dashboard widget queries <a href="http://blogsearch.google.com/">Google Blog Search</a> so that when another blog links to your site it will show up here. It has found no incoming links&hellip; yet. It&#8217;s okay &#8212; there is no rush.') . "</p>\n";
724                 $rss->__destruct();
725                 unset($rss);
726                 return;
727         }
728
729         echo "<ul>\n";
730
731         if ( !isset($items) )
732                 $items = 10;
733
734         foreach ( $rss->get_items(0, $items) as $item ) {
735                 $publisher = '';
736                 $site_link = '';
737                 $link = '';
738                 $content = '';
739                 $date = '';
740                 $link = esc_url( strip_tags( $item->get_link() ) );
741
742                 $author = $item->get_author();
743                 if ( $author ) {
744                         $site_link = esc_url( strip_tags( $author->get_link() ) );
745
746                         if ( !$publisher = esc_html( strip_tags( $author->get_name() ) ) )
747                                 $publisher = __( 'Somebody' );
748                 } else {
749                   $publisher = __( 'Somebody' );
750                 }
751                 if ( $site_link )
752                         $publisher = "<a href='$site_link'>$publisher</a>";
753                 else
754                         $publisher = "<strong>$publisher</strong>";
755
756                 $content = $item->get_content();
757                 $content = wp_html_excerpt($content, 50) . ' ...';
758
759                 if ( $link )
760                         /* translators: incoming links feed, %1$s is other person, %3$s is content */
761                         $text = __( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"' );
762                 else
763                         /* translators: incoming links feed, %1$s is other person, %3$s is content */
764                         $text = __( '%1$s linked here saying, "%3$s"' );
765
766                 if ( $show_date ) {
767                         if ( $show_author || $show_summary )
768                                 /* translators: incoming links feed, %4$s is the date */
769                                 $text .= ' ' . __( 'on %4$s' );
770                         $date = esc_html( strip_tags( $item->get_date() ) );
771                         $date = strtotime( $date );
772                         $date = gmdate( get_option( 'date_format' ), $date );
773                 }
774
775                 echo "\t<li>" . sprintf( $text, $publisher, $link, $content, $date ) . "</li>\n";
776         }
777
778         echo "</ul>\n";
779         $rss->__destruct();
780         unset($rss);
781 }
782
783 function wp_dashboard_incoming_links_control() {
784         wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) );
785 }
786
787 function wp_dashboard_primary() {
788         echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
789 }
790
791 function wp_dashboard_primary_control() {
792         wp_dashboard_rss_control( 'dashboard_primary' );
793 }
794
795 /**
796  * {@internal Missing Short Description}}
797  *
798  * @since unknown
799  *
800  * @param int $widget_id
801  */
802 function wp_dashboard_rss_output( $widget_id ) {
803         $widgets = get_option( 'dashboard_widget_options' );
804         echo '<div class="rss-widget">';
805         wp_widget_rss_output( $widgets[$widget_id] );
806         echo "</div>";
807 }
808
809 function wp_dashboard_secondary() {
810         echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
811 }
812
813 function wp_dashboard_secondary_control() {
814         wp_dashboard_rss_control( 'dashboard_secondary' );
815 }
816
817 /**
818  * Display secondary dashboard RSS widget feed.
819  *
820  * @since unknown
821  *
822  * @return unknown
823  */
824 function wp_dashboard_secondary_output() {
825         $widgets = get_option( 'dashboard_widget_options' );
826         @extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
827         $rss = @fetch_feed( $url );
828
829         if ( is_wp_error($rss) ) {
830                 if ( is_admin() || current_user_can('manage_options') ) {
831                         echo '<div class="rss-widget"><p>';
832                         printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
833                         echo '</p></div>';
834                 }
835         } elseif ( !$rss->get_item_quantity() ) {
836                 $rss->__destruct();
837                 unset($rss);
838                 return false;
839         } else {
840                 echo '<div class="rss-widget">';
841                 wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] );
842                 echo '</div>';
843                 $rss->__destruct();
844                 unset($rss);
845         }
846 }
847
848 function wp_dashboard_plugins() {
849         echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
850 }
851
852 /**
853  * Display plugins most popular, newest plugins, and recently updated widget text.
854  *
855  * @since unknown
856  */
857 function wp_dashboard_plugins_output() {
858         $popular = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/popular/' );
859         $new     = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
860         $updated = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
861
862         if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
863                 $plugin_slugs = array_keys( get_plugins() );
864                 set_transient( 'plugin_slugs', $plugin_slugs, 86400 );
865         }
866
867         foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
868                 if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
869                         continue;
870
871                 $items = $$feed->get_items(0, 5);
872
873                 // Pick a random, non-installed plugin
874                 while ( true ) {
875                         // Abort this foreach loop iteration if there's no plugins left of this type
876                         if ( 0 == count($items) )
877                                 continue 2;
878
879                         $item_key = array_rand($items);
880                         $item = $items[$item_key];
881
882                         list($link, $frag) = explode( '#', $item->get_link() );
883
884                         $link = esc_url($link);
885                         if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
886                                 $slug = $matches[1];
887                         else {
888                                 unset( $items[$item_key] );
889                                 continue;
890                         }
891
892                         // Is this random plugin's slug already installed? If so, try again.
893                         reset( $plugin_slugs );
894                         foreach ( $plugin_slugs as $plugin_slug ) {
895                                 if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
896                                         unset( $items[$item_key] );
897                                         continue 2;
898                                 }
899                         }
900
901                         // If we get to this point, then the random plugin isn't installed and we can stop the while().
902                         break;
903                 }
904
905                 // Eliminate some common badly formed plugin descriptions
906                 while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
907                         unset($items[$item_key]);
908
909                 if ( !isset($items[$item_key]) )
910                         continue;
911
912                 // current bbPress feed item titles are: user on "topic title"
913                 if ( preg_match( '/&quot;(.*)&quot;/s', $item->get_title(), $matches ) )
914                         $title = $matches[1];
915                 else // but let's make it forward compatible if things change
916                         $title = $item->get_title();
917                 $title = esc_html( $title );
918
919                 $description = esc_html( strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))) );
920
921                 $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
922                                                         '&amp;TB_iframe=true&amp;width=600&amp;height=800';
923
924                 echo "<h4>$label</h4>\n";
925                 echo "<h5><a href='$link'>$title</a></h5>&nbsp;<span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span>\n";
926                 echo "<p>$description</p>\n";
927
928                 $$feed->__destruct();
929                 unset($$feed);
930         }
931 }
932
933 /**
934  * Checks to see if all of the feed url in $check_urls are cached.
935  *
936  * If $check_urls is empty, look for the rss feed url found in the dashboard
937  * widget optios of $widget_id. If cached, call $callback, a function that
938  * echoes out output for this widget. If not cache, echo a "Loading..." stub
939  * which is later replaced by AJAX call (see top of /wp-admin/index.php)
940  *
941  * @since unknown
942  *
943  * @param int $widget_id
944  * @param callback $callback
945  * @param array $check_urls RSS feeds
946  * @return bool False on failure. True on success.
947  */
948 function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
949         $loading = '<p class="widget-loading">' . __( 'Loading&#8230;' ) . '</p>';
950
951         if ( empty($check_urls) ) {
952                 $widgets = get_option( 'dashboard_widget_options' );
953                 if ( empty($widgets[$widget_id]['url']) ) {
954                         echo $loading;
955                         return false;
956                 }
957                 $check_urls = array( $widgets[$widget_id]['url'] );
958         }
959
960         include_once ABSPATH . WPINC . '/class-feed.php';
961         foreach ( $check_urls as $check_url ) {
962                 $cache = new WP_Feed_Cache_Transient('', md5($check_url), '');
963                 if ( ! $cache->load() ) {
964                         echo $loading;
965                         return false;
966                 }
967         }
968
969         if ( $callback && is_callable( $callback ) ) {
970                 $args = array_slice( func_get_args(), 2 );
971                 array_unshift( $args, $widget_id );
972                 call_user_func_array( $callback, $args );
973         }
974
975         return true;
976 }
977
978 /* Dashboard Widgets Controls */
979
980 // Calls widget_control callback
981 /**
982  * Calls widget control callback.
983  *
984  * @since unknown
985  *
986  * @param int $widget_control_id Registered Widget ID.
987  */
988 function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
989         global $wp_dashboard_control_callbacks;
990
991         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]) ) {
992                 call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
993         }
994 }
995
996 /**
997  * The RSS dashboard widget control.
998  *
999  * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
1000  * from RSS-type widgets.
1001  *
1002  * @since unknown
1003  *
1004  * @param string widget_id
1005  * @param array form_inputs
1006  */
1007 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
1008         if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
1009                 $widget_options = array();
1010
1011         if ( !isset($widget_options[$widget_id]) )
1012                 $widget_options[$widget_id] = array();
1013
1014         $number = 1; // Hack to use wp_widget_rss_form()
1015         $widget_options[$widget_id]['number'] = $number;
1016
1017         if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
1018                 $_POST['widget-rss'][$number] = stripslashes_deep( $_POST['widget-rss'][$number] );
1019                 $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
1020                 // title is optional.  If black, fill it if possible
1021                 if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
1022                         $rss = fetch_feed($widget_options[$widget_id]['url']);
1023                         if ( is_wp_error($rss) ) {
1024                                 $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
1025                         } else {
1026                                 $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
1027                                 $rss->__destruct();
1028                                 unset($rss);
1029                         }
1030                 }
1031                 update_option( 'dashboard_widget_options', $widget_options );
1032         }
1033
1034         wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
1035 }
1036
1037 /**
1038  * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
1039  */
1040 function wp_dashboard_empty() {}
1041
1042 ?>