]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/dashboard.php
WordPress 3.9-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / dashboard.php
1 <?php
2 /**
3  * WordPress Dashboard Widget Administration Screen 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 2.5.0
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         $screen = get_current_screen();
20
21         $update = false;
22         $widget_options = get_option( 'dashboard_widget_options' );
23         if ( !$widget_options || !is_array($widget_options) )
24                 $widget_options = array();
25
26         /* Register Widgets and Controls */
27
28         $response = wp_check_browser_version();
29
30         if ( $response && $response['upgrade'] ) {
31                 add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
32                 if ( $response['insecure'] )
33                         wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
34                 else
35                         wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' );
36         }
37
38         // Right Now
39         if ( is_blog_admin() && current_user_can('edit_posts') )
40                 wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
41
42         if ( is_network_admin() )
43                 wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
44
45         // Activity Widget
46         if ( is_blog_admin() ) {
47                 wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
48         }
49
50         // QuickPress Widget
51         if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
52                 $quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Drafts' ) );
53                 wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
54         }
55
56         // WordPress News
57         wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress News' ), 'wp_dashboard_primary' );
58
59         if ( is_network_admin() ) {
60
61                 /**
62                  * Fires after core widgets for the Network Admin dashboard have been registered.
63                  *
64                  * @since 3.1.0
65                  */
66                 do_action( 'wp_network_dashboard_setup' );
67
68                 /**
69                  * Filter the list of widgets to load for the Network Admin dashboard.
70                  *
71                  * @since 3.1.0
72                  *
73                  * @param array $dashboard_widgets An array of dashboard widgets.
74                  */
75                 $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
76         } elseif ( is_user_admin() ) {
77
78                 /**
79                  * Fires after core widgets for the User Admin dashboard have been registered.
80                  *
81                  * @since 3.1.0
82                  */
83                 do_action( 'wp_user_dashboard_setup' );
84
85                 /**
86                  * Filter the list of widgets to load for the User Admin dashboard.
87                  *
88                  * @since 3.1.0
89                  *
90                  * @param array $dashboard_widgets An array of dashboard widgets.
91                  */
92                 $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
93         } else {
94
95                 /**
96                  * Fires after core widgets for the admin dashboard have been registered.
97                  *
98                  * @since 2.5.0
99                  */
100                 do_action( 'wp_dashboard_setup' );
101
102                 /**
103                  * Filter the list of widgets to load for the admin dashboard.
104                  *
105                  * @since 2.5.0
106                  *
107                  * @param array $dashboard_widgets An array of dashboard widgets.
108                  */
109                 $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
110         }
111
112         foreach ( $dashboard_widgets as $widget_id ) {
113                 $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>';
114                 wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
115         }
116
117         if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
118                 check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
119                 ob_start(); // hack - but the same hack wp-admin/widgets.php uses
120                 wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
121                 ob_end_clean();
122                 wp_redirect( remove_query_arg( 'edit' ) );
123                 exit;
124         }
125
126         if ( $update )
127                 update_option( 'dashboard_widget_options', $widget_options );
128
129         /** This action is documented in wp-admin/edit-form-advanced.php */
130         do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
131
132         /** This action is documented in wp-admin/edit-form-advanced.php */
133         do_action( 'do_meta_boxes', $screen->id, 'side', '' );
134 }
135
136 function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) {
137         $screen = get_current_screen();
138         global $wp_dashboard_control_callbacks;
139
140         if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
141                 $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
142                 if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
143                         list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
144                         $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
145                         $callback = '_wp_dashboard_control_callback';
146                 } else {
147                         list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
148                         $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
149                 }
150         }
151
152         $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
153
154         $location = 'normal';
155         if ( in_array($widget_id, $side_widgets) )
156                 $location = 'side';
157
158         $priority = 'core';
159         if ( 'dashboard_browser_nag' === $widget_id )
160                 $priority = 'high';
161
162         add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
163 }
164
165 function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
166         echo '<form action="" method="post" class="dashboard-widget-control-form">';
167         wp_dashboard_trigger_widget_control( $meta_box['id'] );
168         wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
169         echo '<input type="hidden" name="widget_id" value="' . esc_attr($meta_box['id']) . '" />';
170         submit_button( __('Submit') );
171         echo '</form>';
172 }
173
174 /**
175  * Displays the dashboard.
176  *
177  * @since 2.5.0
178  */
179 function wp_dashboard() {
180         $screen = get_current_screen();
181         $columns = absint( $screen->get_columns() );
182         $columns_css = '';
183         if ( $columns ) {
184                 $columns_css = " columns-$columns";
185         }
186
187 ?>
188 <div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>">
189         <div id='postbox-container-1' class='postbox-container'>
190         <?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
191         </div>
192         <div id='postbox-container-2' class='postbox-container'>
193         <?php do_meta_boxes( $screen->id, 'side', '' ); ?>
194         </div>
195         <div id='postbox-container-3' class='postbox-container'>
196         <?php do_meta_boxes( $screen->id, 'column3', '' ); ?>
197         </div>
198         <div id='postbox-container-4' class='postbox-container'>
199         <?php do_meta_boxes( $screen->id, 'column4', '' ); ?>
200         </div>
201 </div>
202
203 <?php
204         wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
205         wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
206
207 }
208
209 //
210 // Dashboard Widgets
211 //
212
213 /**
214  * Dashboard widget that displays some basic stats about the site.
215  *
216  * Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8.
217  *
218  * @since 2.7.0
219  */
220 function wp_dashboard_right_now() {
221         $theme = wp_get_theme();
222         if ( current_user_can( 'switch_themes' ) )
223                 $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme->display('Name') );
224         else
225                 $theme_name = $theme->display('Name');
226 ?>
227         <div class="main">
228         <ul>
229         <?php
230         // Posts and Pages
231         foreach ( array( 'post', 'page' ) as $post_type ) {
232                 $num_posts = wp_count_posts( $post_type );
233                 if ( $num_posts && $num_posts->publish ) {
234                         if ( 'post' == $post_type ) {
235                                 $text = _n( '%s Post', '%s Posts', $num_posts->publish );
236                         } else {
237                                 $text = _n( '%s Page', '%s Pages', $num_posts->publish );
238                         }
239                         $text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
240                         $post_type_object = get_post_type_object( $post_type );
241                         if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
242                                 printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
243                         } else {
244                                 printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
245                         }
246
247                 }
248         }
249         // Comments
250         $num_comm = wp_count_comments();
251         if ( $num_comm && $num_comm->total_comments ) {
252                 $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->total_comments ), number_format_i18n( $num_comm->total_comments ) );
253                 ?>
254                 <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
255                 <?php
256                 if ( $num_comm->moderated ) {
257                         /* translators: Number of comments in moderation */
258                         $text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), number_format_i18n( $num_comm->moderated ) );
259                         ?>
260                         <li class="comment-mod-count"><a href="edit-comments.php?comment_status=moderated"><?php echo $text; ?></a></li>
261                         <?php
262                 }
263         }
264
265         /**
266          * Filter the array of extra elements to list in the 'At a Glance'
267          * dashboard widget.
268          *
269          * Prior to 3.8.0, the widget was named 'Right Now'. Each element
270          * is wrapped in list-item tags on output.
271          *
272          * @since 3.8.0
273          *
274          * @param array $items Array of extra 'At a Glance' widget items.
275          */
276         $elements = apply_filters( 'dashboard_glance_items', array() );
277
278         if ( $elements ) {
279                 echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";
280         }
281
282         ?>
283         </ul>
284         <?php
285         update_right_now_message();
286
287         // Check if search engines are asked not to index this site.
288         if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '1' != get_option( 'blog_public' ) ) {
289
290                 /**
291                  * Filter the link title attribute for the 'Search Engines Discouraged'
292                  * message displayed in the 'At a Glance' dashboard widget.
293                  *
294                  * Prior to 3.8.0, the widget was named 'Right Now'.
295                  *
296                  * @since 3.0.0
297                  *
298                  * @param string $title Default attribute text.
299                  */
300                 $title = apply_filters( 'privacy_on_link_title', __( 'Your site is asking search engines not to index its content' ) );
301
302                 /**
303                  * Filter the link label for the 'Search Engines Discouraged' message
304                  * displayed in the 'At a Glance' dashboard widget.
305                  *
306                  * Prior to 3.8.0, the widget was named 'Right Now'.
307                  *
308                  * @since 3.0.0
309                  *
310                  * @param string $content Default text.
311                  */
312                 $content = apply_filters( 'privacy_on_link_text' , __( 'Search Engines Discouraged' ) );
313
314                 echo "<p><a href='options-reading.php' title='$title'>$content</a></p>";
315         }
316         ?>
317         </div>
318         <?php
319         /*
320          * activity_box_end has a core action, but only prints content when multisite.
321          * Using an output buffer is the only way to really check if anything's displayed here.
322          */
323         ob_start();
324
325         /**
326          * Fires at the end of the 'At a Glance' dashboard widget.
327          *
328          * Prior to 3.8.0, the widget was named 'Right Now'.
329          *
330          * @since 2.5.0
331          */
332         do_action( 'rightnow_end' );
333
334         /**
335          * Fires at the end of the 'At a Glance' dashboard widget.
336          *
337          * Prior to 3.8.0, the widget was named 'Right Now'.
338          *
339          * @since 2.0.0
340          */
341         do_action( 'activity_box_end' );
342
343         $actions = ob_get_clean();
344
345         if ( !empty( $actions ) ) : ?>
346         <div class="sub">
347                 <?php echo $actions; ?>
348         </div>
349         <?php endif;
350 }
351
352 function wp_network_dashboard_right_now() {
353         $actions = array();
354         if ( current_user_can('create_sites') )
355                 $actions['create-site'] = '<a href="' . network_admin_url('site-new.php') . '">' . __( 'Create a New Site' ) . '</a>';
356         if ( current_user_can('create_users') )
357                 $actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>';
358
359         $c_users = get_user_count();
360         $c_blogs = get_blog_count();
361
362         $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
363         $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
364
365         $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
366
367         if ( $actions ) {
368                 echo '<ul class="subsubsub">';
369                 foreach ( $actions as $class => $action ) {
370                          $actions[ $class ] = "\t<li class='$class'>$action";
371                 }
372                 echo implode( " |</li>\n", $actions ) . "</li>\n";
373                 echo '</ul>';
374         }
375 ?>
376         <br class="clear" />
377
378         <p class="youhave"><?php echo $sentence; ?></p>
379
380
381         <?php
382                 /**
383                  * Fires in the Network Admin 'Right Now' dashboard widget
384                  * just before the user and site search form fields.
385                  *
386                  * @since MU
387                  *
388                  * @param null $unused
389                  */
390                 do_action( 'wpmuadminresult', '' );
391         ?>
392
393         <form action="<?php echo network_admin_url('users.php'); ?>" method="get">
394                 <p>
395                         <input type="search" name="s" value="" size="30" autocomplete="off" />
396                         <?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?>
397                 </p>
398         </form>
399
400         <form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
401                 <p>
402                         <input type="search" name="s" value="" size="30" autocomplete="off" />
403                         <?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?>
404                 </p>
405         </form>
406 <?php
407         /**
408          * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
409          *
410          * @since MU
411          */
412         do_action( 'mu_rightnow_end' );
413
414         /**
415          * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
416          *
417          * @since MU
418          */
419         do_action( 'mu_activity_box_end' );
420 }
421
422 /**
423  * The Quick Draft widget display and creation of drafts.
424  *
425  * @since 3.8.0
426  *
427  * @param string $error_msg Optional. Error message. Default false.
428  */
429 function wp_dashboard_quick_press( $error_msg = false ) {
430         global $post_ID;
431
432         /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
433         $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
434         if ( $last_post_id ) {
435                 $post = get_post( $last_post_id );
436                 if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
437                         $post = get_default_post_to_edit( 'post', true );
438                         update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
439                 } else {
440                         $post->post_title = ''; // Remove the auto draft title
441                 }
442         } else {
443                 $post = get_default_post_to_edit( 'post' , true);
444                 $user_id = get_current_user_id();
445                 // Don't create an option if this is a super admin who does not belong to this site.
446                 if ( ! ( is_super_admin( $user_id ) && ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) )
447                         update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
448         }
449
450         $post_ID = (int) $post->ID;
451 ?>
452
453         <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">
454
455                 <?php if ( $error_msg ) : ?>
456                 <div class="error"><?php echo $error_msg; ?></div>
457                 <?php endif; ?>
458
459                 <div class="input-text-wrap" id="title-wrap">
460                         <label class="screen-reader-text prompt" for="title" id="title-prompt-text">
461
462                                 <?php
463                                 /** This filter is documented in wp-admin/edit-form-advanced.php */
464                                 echo apply_filters( 'enter_title_here', __( 'Title' ), $post );
465                                 ?>
466                         </label>
467                         <input type="text" name="post_title" id="title" autocomplete="off" />
468                 </div>
469
470                 <div class="textarea-wrap" id="description-wrap">
471                         <label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( 'What&#8217;s on your mind?' ); ?></label>
472                         <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"></textarea>
473                 </div>
474
475                 <p class="submit">
476                         <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
477                         <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
478                         <input type="hidden" name="post_type" value="post" />
479                         <?php wp_nonce_field( 'add-post' ); ?>
480                         <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
481                         <br class="clear" />
482                 </p>
483
484         </form>
485         <?php
486         wp_dashboard_recent_drafts();
487 }
488
489 /**
490  * Show recent drafts of the user on the dashboard.
491  *
492  * @since 2.7.0
493  */
494 function wp_dashboard_recent_drafts( $drafts = false ) {
495         if ( ! $drafts ) {
496                 $query_args = array(
497                         'post_type'      => 'post',
498                         'post_status'    => 'draft',
499                         'author'         => get_current_user_id(),
500                         'posts_per_page' => 4,
501                         'orderby'        => 'modified',
502                         'order'          => 'DESC'
503                 );
504                 $drafts = get_posts( $query_args );
505                 if ( ! $drafts ) {
506                         return;
507                 }
508         }
509
510         echo '<div class="drafts">';
511         if ( count( $drafts ) > 3 ) {
512                 echo '<p class="view-all"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '">' . _x( 'View all', 'drafts' ) . "</a></p>\n";
513         }
514         echo '<h4 class="hide-if-no-js">' . __( 'Drafts' ) . "</h4>\n<ul>";
515
516         $drafts = array_slice( $drafts, 0, 3 );
517         foreach ( $drafts as $draft ) {
518                 $url = get_edit_post_link( $draft->ID );
519                 $title = _draft_or_post_title( $draft->ID );
520                 echo "<li>\n";
521                 echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ) . '">' . esc_html( $title ) . '</a>';
522                 echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( get_option( 'date_format' ), $draft ) . '</time></div>';
523                 if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) {
524                         echo '<p>' . $the_content . '</p>';
525                 }
526                 echo "</li>\n";
527         }
528         echo "</ul>\n</div>";
529 }
530
531 function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
532         $GLOBALS['comment'] =& $comment;
533
534         $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
535
536         if ( current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
537                 $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
538                 $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
539         } else {
540                 $comment_post_link = $comment_post_title;
541         }
542
543         $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
544
545         $actions_string = '';
546         if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
547                 // preorder it: Approve | Reply | Edit | Spam | Trash
548                 $actions = array(
549                         'approve' => '', 'unapprove' => '',
550                         'reply' => '',
551                         'edit' => '',
552                         'spam' => '',
553                         'trash' => '', 'delete' => ''
554                 );
555
556                 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
557                 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
558
559                 $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
560                 $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
561                 $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
562                 $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
563                 $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
564
565                 $actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
566                 $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
567                 $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
568                 $actions['reply'] = '<a onclick="window.commentReply && commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" title="'.esc_attr__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
569                 $actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
570                 if ( !EMPTY_TRASH_DAYS )
571                         $actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
572                 else
573                         $actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>';
574
575                 /**
576                  * Filter the action links displayed for each comment in the 'Recent Comments'
577                  * dashboard widget.
578                  *
579                  * @since 2.6.0
580                  *
581                  * @param array  $actions An array of comment actions. Default actions include:
582                  *                        'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
583                  *                        'Delete', and 'Trash'.
584                  * @param object $comment The comment object.
585                  */
586                 $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
587
588                 $i = 0;
589                 foreach ( $actions as $action => $link ) {
590                         ++$i;
591                         ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
592
593                         // Reply and quickedit need a hide-if-no-js span
594                         if ( 'reply' == $action || 'quickedit' == $action )
595                                 $action .= ' hide-if-no-js';
596
597                         $actions_string .= "<span class='$action'>$sep$link</span>";
598                 }
599         }
600
601 ?>
602
603                 <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
604
605                         <?php echo get_avatar( $comment, 50, 'mystery' ); ?>
606
607                         <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
608
609                         <div class="dashboard-comment-wrap">
610                         <h4 class="comment-meta">
611                                 <?php printf( /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */__( 'From %1$s on %2$s%3$s' ),
612                                         '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link.' '.$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?>
613                         </h4>
614
615                         <?php
616                         else :
617                                 switch ( $comment->comment_type ) :
618                                 case 'pingback' :
619                                         $type = __( 'Pingback' );
620                                         break;
621                                 case 'trackback' :
622                                         $type = __( 'Trackback' );
623                                         break;
624                                 default :
625                                         $type = ucwords( $comment->comment_type );
626                                 endswitch;
627                                 $type = esc_html( $type );
628                         ?>
629                         <div class="dashboard-comment-wrap">
630                         <?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?>
631                         <h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link." ".$comment_link ); ?></h4>
632                         <p class="comment-author"><?php comment_author_link(); ?></p>
633
634                         <?php endif; // comment_type ?>
635                         <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
636                         <p class="row-actions"><?php echo $actions_string; ?></p>
637                         </div>
638                 </div>
639 <?php
640 }
641
642 /**
643  * Callback function for Activity widget.
644  *
645  * @since 3.8.0
646  */
647 function wp_dashboard_site_activity() {
648
649         echo '<div id="activity-widget">';
650
651         $future_posts = wp_dashboard_recent_posts( array(
652                 'max'     => 5,
653                 'status'  => 'future',
654                 'order'   => 'ASC',
655                 'title'   => __( 'Publishing Soon' ),
656                 'id'      => 'future-posts',
657         ) );
658         $recent_posts = wp_dashboard_recent_posts( array(
659                 'max'     => 5,
660                 'status'  => 'publish',
661                 'order'   => 'DESC',
662                 'title'   => __( 'Recently Published' ),
663                 'id'      => 'published-posts',
664         ) );
665
666         $recent_comments = wp_dashboard_recent_comments();
667
668         if ( !$future_posts && !$recent_posts && !$recent_comments ) {
669                 echo '<div class="no-activity">';
670                 echo '<p class="smiley"></p>';
671                 echo '<p>' . __( 'No activity yet!' ) . '</p>';
672                 echo '</div>';
673         }
674
675         echo '</div>';
676 }
677
678 /**
679  * Generates Publishing Soon and Recently Published sections.
680  *
681  * @since 3.8.0
682  *
683  * @param array $args {
684  *     An array of query and display arguments.
685  *
686  *     @type int    $max     Number of posts to display.
687  *     @type string $status  Post status.
688  *     @type string $order   Designates ascending ('ASC') or descending ('DESC') order.
689  *     @type string $title   Section title.
690  *     @type string $id      The container id.
691  * }
692  * @return bool False if no posts were found. True otherwise.
693  */
694 function wp_dashboard_recent_posts( $args ) {
695         $query_args = array(
696                 'post_type'      => 'post',
697                 'post_status'    => $args['status'],
698                 'orderby'        => 'date',
699                 'order'          => $args['order'],
700                 'posts_per_page' => intval( $args['max'] ),
701                 'no_found_rows'  => true,
702                 'cache_results'  => false,
703                 'perm'           => ( 'future' === $args['status'] ) ? 'editable' : 'readable',
704         );
705         $posts = new WP_Query( $query_args );
706
707         if ( $posts->have_posts() ) {
708
709                 echo '<div id="' . $args['id'] . '" class="activity-block">';
710
711                 echo '<h4>' . $args['title'] . '</h4>';
712
713                 echo '<ul>';
714
715                 $i = 0;
716                 $today    = date( 'Y-m-d', current_time( 'timestamp' ) );
717                 $tomorrow = date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
718
719                 while ( $posts->have_posts() ) {
720                         $posts->the_post();
721
722                         $time = get_the_time( 'U' );
723                         if ( date( 'Y-m-d', $time ) == $today ) {
724                                 $relative = __( 'Today' );
725                         } elseif ( date( 'Y-m-d', $time ) == $tomorrow ) {
726                                 $relative = __( 'Tomorrow' );
727                         } else {
728                                 /* translators: date and time format for recent posts on the dashboard, see http://php.net/date */
729                                 $relative = date_i18n( __( 'M jS' ), $time );
730                         }
731
732                         if ( current_user_can( 'edit_post', get_the_ID() ) ) {
733                                 /* translators: 1: relative date, 2: time, 3: post edit link, 4: post title */
734                                 $format = __( '<span>%1$s, %2$s</span> <a href="%3$s">%4$s</a>' );
735                                 printf( "<li>$format</li>", $relative, get_the_time(), get_edit_post_link(), _draft_or_post_title() );
736                         } else {
737                                 /* translators: 1: relative date, 2: time, 3: post title */
738                                 $format = __( '<span>%1$s, %2$s</span> %3$s' );
739                                 printf( "<li>$format</li>", $relative, get_the_time(), _draft_or_post_title() );
740                         }
741                 }
742
743                 echo '</ul>';
744                 echo '</div>';
745
746         } else {
747                 return false;
748         }
749
750         wp_reset_postdata();
751
752         return true;
753 }
754
755 /**
756  * Show Comments section.
757  *
758  * @since 3.8.0
759  *
760  * @param int $total_items Optional. Number of comments to query. Default 5.
761  * @return bool False if no comments were found. True otherwise.
762  */
763 function wp_dashboard_recent_comments( $total_items = 5 ) {
764         global $wpdb;
765
766         // Select all comment types and filter out spam later for better query performance.
767         $comments = array();
768         $start = 0;
769
770         $comments_query = array(
771                 'number' => $total_items * 5,
772                 'offset' => 0
773         );
774         if ( ! current_user_can( 'edit_posts' ) )
775                 $comments_query['status'] = 'approve';
776
777         while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
778                 foreach ( $possible as $comment ) {
779                         if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
780                                 continue;
781                         $comments[] = $comment;
782                         if ( count( $comments ) == $total_items )
783                                 break 2;
784                 }
785                 $comments_query['offset'] += $comments_query['number'];
786                 $comments_query['number'] = $total_items * 10;
787         }
788
789
790
791         if ( $comments ) {
792                 echo '<div id="latest-comments" class="activity-block">';
793                 echo '<h4>' . __( 'Comments' ) . '</h4>';
794
795                 echo '<div id="the-comment-list" data-wp-lists="list:comment">';
796                 foreach ( $comments as $comment )
797                         _wp_dashboard_recent_comments_row( $comment );
798                 echo '</div>';
799
800                 if ( current_user_can('edit_posts') )
801                         _get_list_table('WP_Comments_List_Table')->views();
802
803                 wp_comment_reply( -1, false, 'dashboard', false );
804                 wp_comment_trashnotice();
805
806                 echo '</div>';
807         } else {
808                 return false;
809         }
810         return true;
811 }
812
813 /**
814  * Display generic dashboard RSS widget feed.
815  *
816  * @since 2.5.0
817  *
818  * @param string $widget_id
819  */
820 function wp_dashboard_rss_output( $widget_id ) {
821         $widgets = get_option( 'dashboard_widget_options' );
822         echo '<div class="rss-widget">';
823         wp_widget_rss_output( $widgets[ $widget_id ] );
824         echo "</div>";
825 }
826
827 /**
828  * Checks to see if all of the feed url in $check_urls are cached.
829  *
830  * If $check_urls is empty, look for the rss feed url found in the dashboard
831  * widget options of $widget_id. If cached, call $callback, a function that
832  * echoes out output for this widget. If not cache, echo a "Loading..." stub
833  * which is later replaced by AJAX call (see top of /wp-admin/index.php)
834  *
835  * @since 2.5.0
836  *
837  * @param string $widget_id
838  * @param callback $callback
839  * @param array $check_urls RSS feeds
840  * @return bool False on failure. True on success.
841  */
842 function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
843         $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
844         $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
845
846         if ( empty($check_urls) ) {
847                 $widgets = get_option( 'dashboard_widget_options' );
848                 if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
849                         echo $loading;
850                         return false;
851                 }
852                 $check_urls = array( $widgets[$widget_id]['url'] );
853         }
854
855         $cache_key = 'dash_' . md5( $widget_id );
856         if ( false !== ( $output = get_transient( $cache_key ) ) ) {
857                 echo $output;
858                 return true;
859         }
860
861         if ( ! $doing_ajax ) {
862                 echo $loading;
863                 return false;
864         }
865
866         if ( $callback && is_callable( $callback ) ) {
867                 $args = array_slice( func_get_args(), 2 );
868                 array_unshift( $args, $widget_id );
869                 ob_start();
870                 call_user_func_array( $callback, $args );
871                 set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
872         }
873
874         return true;
875 }
876
877 /* Dashboard Widgets Controls */
878
879 // Calls widget_control callback
880 /**
881  * Calls widget control callback.
882  *
883  * @since 2.5.0
884  *
885  * @param int $widget_control_id Registered Widget ID.
886  */
887 function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
888         global $wp_dashboard_control_callbacks;
889
890         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]) ) {
891                 call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
892         }
893 }
894
895 /**
896  * The RSS dashboard widget control.
897  *
898  * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
899  * from RSS-type widgets.
900  *
901  * @since 2.5.0
902  *
903  * @param string $widget_id
904  * @param array $form_inputs
905  */
906 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
907         if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
908                 $widget_options = array();
909
910         if ( !isset($widget_options[$widget_id]) )
911                 $widget_options[$widget_id] = array();
912
913         $number = 1; // Hack to use wp_widget_rss_form()
914         $widget_options[$widget_id]['number'] = $number;
915
916         if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
917                 $_POST['widget-rss'][$number] = wp_unslash( $_POST['widget-rss'][$number] );
918                 $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
919                 $widget_options[$widget_id]['number'] = $number;
920                 // title is optional. If black, fill it if possible
921                 if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
922                         $rss = fetch_feed($widget_options[$widget_id]['url']);
923                         if ( is_wp_error($rss) ) {
924                                 $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
925                         } else {
926                                 $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
927                                 $rss->__destruct();
928                                 unset($rss);
929                         }
930                 }
931                 update_option( 'dashboard_widget_options', $widget_options );
932                 $cache_key = 'dash_' . md5( $widget_id );
933                 delete_transient( $cache_key );
934         }
935
936         wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
937 }
938
939 /**
940  * WordPress News dashboard widget.
941  *
942  * @since 2.7.0
943  */
944 function wp_dashboard_primary() {
945         $feeds = array(
946                 'news' => array(
947
948                         /**
949                          * Filter the primary link URL for the 'WordPress News' dashboard widget.
950                          *
951                          * @since 2.5.0
952                          *
953                          * @param string $link The widget's primary link URL.
954                          */
955                         'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
956
957                         /**
958                          * Filter the primary feed URL for the 'WordPress News' dashboard widget.
959                          *
960                          * @since 2.3.0
961                          *
962                          * @param string $url The widget's primary feed URL.
963                          */
964                         'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
965
966                         /**
967                          * Filter the primary link title for the 'WordPress News' dashboard widget.
968                          *
969                          * @since 2.3.0
970                          *
971                          * @param string $title Title attribute for the widget's primary link.
972                          */
973                         'title'        => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
974                         'items'        => 1,
975                         'show_summary' => 1,
976                         'show_author'  => 0,
977                         'show_date'    => 1,
978                 ),
979                 'planet' => array(
980
981                         /**
982                          * Filter the secondary link URL for the 'WordPress News' dashboard widget.
983                          *
984                          * @since 2.3.0
985                          *
986                          * @param string $link The widget's secondary link URL.
987                          */
988                         'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
989
990                         /**
991                          * Filter the secondary feed URL for the 'WordPress News' dashboard widget.
992                          *
993                          * @since 2.3.0
994                          *
995                          * @param string $url The widget's secondary feed URL.
996                          */
997                         'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
998
999                         /**
1000                          * Filter the secondary link title for the 'WordPress News' dashboard widget.
1001                          *
1002                          * @since 2.3.0
1003                          *
1004                          * @param string $title Title attribute for the widget's secondary link.
1005                          */
1006                         'title'        => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
1007                         'items'        => 3,
1008                         'show_summary' => 0,
1009                         'show_author'  => 0,
1010                         'show_date'    => 0,
1011                 )
1012         );
1013
1014         if ( ( ! is_multisite() && is_blog_admin() && current_user_can( 'install_plugins' ) ) || ( is_network_admin() && current_user_can( 'manage_network_plugins' ) && current_user_can( 'install_plugins' ) ) ) {
1015                 $feeds['plugins'] = array(
1016                         'link'         => '',
1017                         'url'          => array(
1018                                 'popular' => 'http://wordpress.org/plugins/rss/browse/popular/',
1019                         ),
1020                         'title'        => '',
1021                         'items'        => 1,
1022                         'show_summary' => 0,
1023                         'show_author'  => 0,
1024                         'show_date'    => 0,
1025                 );
1026         }
1027
1028         wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
1029 }
1030
1031 /**
1032  * Display the WordPress news feeds.
1033  *
1034  * @since 3.8.0
1035  *
1036  * @param string $widget_id Widget ID.
1037  * @param array  $feeds     Array of RSS feeds.
1038  */
1039 function wp_dashboard_primary_output( $widget_id, $feeds ) {
1040         foreach( $feeds as $type => $args ) {
1041                 $args['type'] = $type;
1042                 echo '<div class="rss-widget">';
1043                 if ( $type === 'plugins' ) {
1044                         wp_dashboard_plugins_output( $args['url'], $args );
1045                 } else {
1046                         wp_widget_rss_output( $args['url'], $args );
1047                 }
1048                 echo "</div>";
1049         }
1050 }
1051
1052 /**
1053  * Display plugins text for the WordPress news widget.
1054  *
1055  * @since 2.5.0
1056  */
1057 function wp_dashboard_plugins_output( $rss, $args = array() ) {
1058         // Plugin feeds plus link to install them
1059         $popular = fetch_feed( $args['url']['popular'] );
1060
1061         if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
1062                 $plugin_slugs = array_keys( get_plugins() );
1063                 set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
1064         }
1065
1066         echo '<ul>';
1067
1068         foreach ( array(
1069                 'popular' => __( 'Popular Plugin' )
1070         ) as $feed => $label ) {
1071                 if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
1072                         continue;
1073
1074                 $items = $$feed->get_items(0, 5);
1075
1076                 // Pick a random, non-installed plugin
1077                 while ( true ) {
1078                         // Abort this foreach loop iteration if there's no plugins left of this type
1079                         if ( 0 == count($items) )
1080                                 continue 2;
1081
1082                         $item_key = array_rand($items);
1083                         $item = $items[$item_key];
1084
1085                         list($link, $frag) = explode( '#', $item->get_link() );
1086
1087                         $link = esc_url($link);
1088                         if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
1089                                 $slug = $matches[1];
1090                         else {
1091                                 unset( $items[$item_key] );
1092                                 continue;
1093                         }
1094
1095                         // Is this random plugin's slug already installed? If so, try again.
1096                         reset( $plugin_slugs );
1097                         foreach ( $plugin_slugs as $plugin_slug ) {
1098                                 if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
1099                                         unset( $items[$item_key] );
1100                                         continue 2;
1101                                 }
1102                         }
1103
1104                         // If we get to this point, then the random plugin isn't installed and we can stop the while().
1105                         break;
1106                 }
1107
1108                 // Eliminate some common badly formed plugin descriptions
1109                 while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
1110                         unset($items[$item_key]);
1111
1112                 if ( !isset($items[$item_key]) )
1113                         continue;
1114
1115                 $title = esc_html( $item->get_title() );
1116
1117                 $description = esc_html( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
1118
1119                 $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&amp;TB_iframe=true&amp;width=600&amp;height=800';
1120
1121                 echo "<li class='dashboard-news-plugin'><span>$label:</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a>&nbsp;<span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span></li>";
1122
1123                 $$feed->__destruct();
1124                 unset( $$feed );
1125         }
1126
1127         echo '</ul>';
1128 }
1129
1130 /**
1131  * Display file upload quota on dashboard.
1132  *
1133  * Runs on the activity_box_end hook in wp_dashboard_right_now().
1134  *
1135  * @since 3.0.0
1136  *
1137  * @return bool True if not multisite, user can't upload files, or the space check option is disabled.
1138 */
1139 function wp_dashboard_quota() {
1140         if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) )
1141                 return true;
1142
1143         $quota = get_space_allowed();
1144         $used = get_space_used();
1145
1146         if ( $used > $quota )
1147                 $percentused = '100';
1148         else
1149                 $percentused = ( $used / $quota ) * 100;
1150         $used_class = ( $percentused >= 70 ) ? ' warning' : '';
1151         $used = round( $used, 2 );
1152         $percentused = number_format( $percentused );
1153
1154         ?>
1155         <h4 class="mu-storage"><?php _e( 'Storage Space' ); ?></h4>
1156         <div class="mu-storage">
1157         <ul>
1158                 <li class="storage-count">
1159                         <?php $text = sprintf(
1160                                 /* translators: number of megabytes */
1161                                 __( '%s MB Space Allowed' ),
1162                                 number_format_i18n( $quota )
1163                         );
1164                         printf(
1165                                 '<a href="%1$s" title="%2$s">%3$s</a>',
1166                                 esc_url( admin_url( 'upload.php' ) ),
1167                                 __( 'Manage Uploads' ),
1168                                 $text
1169                         ); ?>
1170                 </li><li class="storage-count <?php echo $used_class; ?>">
1171                         <?php $text = sprintf(
1172                                 /* translators: 1: number of megabytes, 2: percentage */
1173                                 __( '%1$s MB (%2$s%%) Space Used' ),
1174                                 number_format_i18n( $used, 2 ),
1175                                 $percentused
1176                         );
1177                         printf(
1178                                 '<a href="%1$s" title="%2$s" class="musublink">%3$s</a>',
1179                                 esc_url( admin_url( 'upload.php' ) ),
1180                                 __( 'Manage Uploads' ),
1181                                 $text
1182                         ); ?>
1183                 </li>
1184         </ul>
1185         </div>
1186         <?php
1187 }
1188 add_action( 'activity_box_end', 'wp_dashboard_quota' );
1189
1190 // Display Browser Nag Meta Box
1191 function wp_dashboard_browser_nag() {
1192         $notice = '';
1193         $response = wp_check_browser_version();
1194
1195         if ( $response ) {
1196                 if ( $response['insecure'] ) {
1197                         $msg = sprintf( __( "It looks like you're using an insecure version of <a href='%s'>%s</a>. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) );
1198                 } else {
1199                         $msg = sprintf( __( "It looks like you're using an old version of <a href='%s'>%s</a>. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) );
1200                 }
1201
1202                 $browser_nag_class = '';
1203                 if ( !empty( $response['img_src'] ) ) {
1204                         $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
1205
1206                         $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
1207                         $browser_nag_class = ' has-browser-icon';
1208                 }
1209                 $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
1210
1211                 $browsehappy = 'http://browsehappy.com/';
1212                 $locale = get_locale();
1213                 if ( 'en_US' !== $locale )
1214                         $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
1215
1216                 $notice .= '<p>' . sprintf( __( '<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>' ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ), esc_url( $browsehappy ) ) . '</p>';
1217                 $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
1218                 $notice .= '<div class="clear"></div>';
1219         }
1220
1221         /**
1222         * Filter the notice output for the 'Browse Happy' nag meta box.
1223         *
1224         * @since 3.2.0
1225         *
1226         * @param string $notice   The notice content.
1227         * @param array  $response An array containing web browser information.
1228         */
1229         echo apply_filters( 'browse-happy-notice', $notice, $response );
1230 }
1231
1232 function dashboard_browser_nag_class( $classes ) {
1233         $response = wp_check_browser_version();
1234
1235         if ( $response && $response['insecure'] )
1236                 $classes[] = 'browser-insecure';
1237
1238         return $classes;
1239 }
1240
1241 /**
1242  * Check if the user needs a browser update
1243  *
1244  * @since 3.2.0
1245  *
1246  * @return array|bool False on failure, array of browser data on success.
1247  */
1248 function wp_check_browser_version() {
1249         if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1250                 return false;
1251
1252         $key = md5( $_SERVER['HTTP_USER_AGENT'] );
1253
1254         if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
1255                 global $wp_version;
1256
1257                 $options = array(
1258                         'body'                  => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
1259                         'user-agent'    => 'WordPress/' . $wp_version . '; ' . home_url()
1260                 );
1261
1262                 $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $options );
1263
1264                 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
1265                         return false;
1266
1267                 /**
1268                  * Response should be an array with:
1269                  *  'name' - string - A user friendly browser name
1270                  *  'version' - string - The most recent version of the browser
1271                  *  'current_version' - string - The version of the browser the user is using
1272                  *  'upgrade' - boolean - Whether the browser needs an upgrade
1273                  *  'insecure' - boolean - Whether the browser is deemed insecure
1274                  *  'upgrade_url' - string - The url to visit to upgrade
1275                  *  'img_src' - string - An image representing the browser
1276                  *  'img_src_ssl' - string - An image (over SSL) representing the browser
1277                  */
1278                 $response = json_decode( wp_remote_retrieve_body( $response ), true );
1279
1280                 if ( ! is_array( $response ) )
1281                         return false;
1282
1283                 set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
1284         }
1285
1286         return $response;
1287 }
1288
1289 /**
1290  * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
1291  */
1292 function wp_dashboard_empty() {}
1293
1294 /**
1295  * Displays a welcome panel to introduce users to WordPress.
1296  *
1297  * @since 3.3.0
1298  */
1299 function wp_welcome_panel() {
1300         ?>
1301         <div class="welcome-panel-content">
1302         <h3><?php _e( 'Welcome to WordPress!' ); ?></h3>
1303         <p class="about-description"><?php _e( 'We&#8217;ve assembled some links to get you started:' ); ?></p>
1304         <div class="welcome-panel-column-container">
1305         <div class="welcome-panel-column">
1306                 <h4><?php _e( 'Get Started' ); ?></h4>
1307                 <a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"><?php _e( 'Customize Your Site' ); ?></a>
1308                 <a class="button button-primary button-hero hide-if-customize" href="<?php echo admin_url( 'themes.php' ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
1309                 <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
1310                         <p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">change your theme completely</a>' ), admin_url( 'themes.php' ) ); ?></p>
1311                 <?php endif; ?>
1312         </div>
1313         <div class="welcome-panel-column">
1314                 <h4><?php _e( 'Next Steps' ); ?></h4>
1315                 <ul>
1316                 <?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
1317                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
1318                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
1319                 <?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
1320                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
1321                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
1322                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
1323                 <?php else : ?>
1324                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
1325                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add an About page' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
1326                 <?php endif; ?>
1327                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li>
1328                 </ul>
1329         </div>
1330         <div class="welcome-panel-column welcome-panel-last">
1331                 <h4><?php _e( 'More Actions' ); ?></h4>
1332                 <ul>
1333                 <?php if ( current_theme_supports( 'widgets' ) || current_theme_supports( 'menus' ) ) : ?>
1334                         <li><div class="welcome-icon welcome-widgets-menus"><?php
1335                                 if ( current_theme_supports( 'widgets' ) && current_theme_supports( 'menus' ) ) {
1336                                         printf( __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ),
1337                                                 admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' ) );
1338                                 } elseif ( current_theme_supports( 'widgets' ) ) {
1339                                         echo '<a href="' . admin_url( 'widgets.php' ) . '">' . __( 'Manage widgets' ) . '</a>';
1340                                 } else {
1341                                         echo '<a href="' . admin_url( 'nav-menus.php' ) . '">' . __( 'Manage menus' ) . '</a>';
1342                                 }
1343                         ?></div></li>
1344                 <?php endif; ?>
1345                 <?php if ( current_user_can( 'manage_options' ) ) : ?>
1346                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
1347                 <?php endif; ?>
1348                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'http://codex.wordpress.org/First_Steps_With_WordPress' ) ); ?></li>
1349                 </ul>
1350         </div>
1351         </div>
1352         </div>
1353         <?php
1354 }