+/**
+ * Display file upload quota on dashboard.
+ *
+ * Runs on the activity_box_end hook in wp_dashboard_right_now().
+ *
+ * @since 3.0.0
+ *
+ * @return bool True if not multisite, user can't upload files, or the space check option is disabled.
+*/
+function wp_dashboard_quota() {
+ if ( !is_multisite() || !current_user_can('upload_files') || get_site_option( 'upload_space_check_disabled' ) )
+ return true;
+
+ $quota = get_space_allowed();
+ $used = get_space_used();
+
+ if ( $used > $quota )
+ $percentused = '100';
+ else
+ $percentused = ( $used / $quota ) * 100;
+ $used_color = ( $percentused >= 70 ) ? ' spam' : '';
+ $used = round( $used, 2 );
+ $percentused = number_format( $percentused );
+
+ ?>
+ <p class="sub musub"><?php _e( 'Storage Space' ); ?></p>
+ <div class="table table_content musubtable">
+ <table>
+ <tr class="first">
+ <td class="first b b-posts"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>' ), esc_url( admin_url( 'upload.php' ) ), number_format_i18n( $quota ) ); ?></td>
+ <td class="t posts"><?php _e( 'Space Allowed' ); ?></td>
+ </tr>
+ </table>
+ </div>
+ <div class="table table_discussion musubtable">
+ <table>
+ <tr class="first">
+ <td class="b b-comments"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>' ), esc_url( admin_url( 'upload.php' ) ), number_format_i18n( $used, 2 ), $percentused ); ?></td>
+ <td class="last t comments<?php echo $used_color;?>"><?php _e( 'Space Used' );?></td>
+ </tr>
+ </table>
+ </div>
+ <br class="clear" />
+ <?php
+}
+add_action( 'activity_box_end', 'wp_dashboard_quota' );
+
+// Display Browser Nag Meta Box
+function wp_dashboard_browser_nag() {
+ $notice = '';
+ $response = wp_check_browser_version();
+
+ if ( $response ) {
+ if ( $response['insecure'] ) {
+ $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'] ) );
+ } else {
+ $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'] ) );
+ }
+
+ $browser_nag_class = '';
+ if ( !empty( $response['img_src'] ) ) {
+ $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
+
+ $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
+ $browser_nag_class = ' has-browser-icon';
+ }
+ $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
+
+ $browsehappy = 'http://browsehappy.com/';
+ $locale = get_locale();
+ if ( 'en_US' !== $locale )
+ $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
+
+ $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>';
+ $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
+ $notice .= '<div class="clear"></div>';
+ }
+
+ echo apply_filters( 'browse-happy-notice', $notice, $response );
+}
+
+function dashboard_browser_nag_class( $classes ) {
+ $response = wp_check_browser_version();
+
+ if ( $response && $response['insecure'] )
+ $classes[] = 'browser-insecure';
+
+ return $classes;
+}
+
+/**
+ * Check if the user needs a browser update
+ *
+ * @since 3.2.0
+ *
+ * @return array|bool False on failure, array of browser data on success.
+ */
+function wp_check_browser_version() {
+ if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
+ return false;
+
+ $key = md5( $_SERVER['HTTP_USER_AGENT'] );
+
+ if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
+ global $wp_version;
+
+ $options = array(
+ 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url()
+ );
+
+ $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $options );
+
+ if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
+ return false;
+
+ /**
+ * Response should be an array with:
+ * 'name' - string - A user friendly browser name
+ * 'version' - string - The most recent version of the browser
+ * 'current_version' - string - The version of the browser the user is using
+ * 'upgrade' - boolean - Whether the browser needs an upgrade
+ * 'insecure' - boolean - Whether the browser is deemed insecure
+ * 'upgrade_url' - string - The url to visit to upgrade
+ * 'img_src' - string - An image representing the browser
+ * 'img_src_ssl' - string - An image (over SSL) representing the browser
+ */
+ $response = json_decode( wp_remote_retrieve_body( $response ), true );
+
+ if ( ! is_array( $response ) )
+ return false;
+
+ set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
+ }
+
+ return $response;
+}
+