Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17557 r18314  
    11<?php
    22/**
    3  * WordPress Dashboard Widget Administration Panel API
     3 * WordPress Dashboard Widget Administration Screen API
    44 *
    55 * @package WordPress
     
    2525
    2626    /* 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    }
    2737
    2838    // Right Now
     
    162172    if ( in_array($widget_id, $side_widgets) )
    163173        $location = 'side';
    164     add_meta_box( $widget_id, $widget_name , $callback, $screen->id, $location, 'core' );
     174
     175    $priority = 'core';
     176    if ( 'dashboard_browser_nag' === $widget_id )
     177        $priority = 'high';
     178
     179    add_meta_box( $widget_id, $widget_name, $callback, $screen->id, $location, $priority );
    165180}
    166181
     
    385400
    386401        $switch_themes = $ct->title;
    387         if ( current_user_can( 'switch_themes') ) {
    388             echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
     402        if ( current_user_can( 'switch_themes') )
    389403            $switch_themes = '<a href="themes.php">' . $switch_themes . '</a>';
    390         }
    391404        if ( current_user_can( 'edit_theme_options' ) ) {
    392405            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);
     
    395408        }
    396409    } else {
    397         if ( current_user_can( 'switch_themes' ) ) {
    398             echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
     410        if ( current_user_can( 'switch_themes' ) )
    399411            printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $ct->title );
    400         } else {
     412        else
    401413            printf( __('Theme <span class="b">%1$s</span>'), $ct->title );
    402         }
    403414    }
    404415    echo '</p>';
     416
     417    // Check if search engines are blocked.
     418    if ( !is_network_admin() && !is_user_admin() && current_user_can('manage_options') && '1' != get_option('blog_public') ) {
     419        $title = apply_filters('privacy_on_link_title', __('Your site is asking search engines not to index its content') );
     420        $content = apply_filters('privacy_on_link_text', __('Search Engines Blocked') );
     421
     422        echo "<p><a href='options-privacy.php' title='$title'>$content</a></p>";
     423    }
    405424
    406425    update_right_now_message();
     
    458477}
    459478
    460 function wp_dashboard_quick_press_output() {
     479function wp_dashboard_quick_press() {
    461480    global $post_ID;
    462481
     
    539558            <span id="publishing-action">
    540559                <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'); ?>" />
    541                 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
     560                <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
    542561            </span>
    543562            <br class="clear" />
     
    549568    if ( $drafts )
    550569        wp_dashboard_recent_drafts( $drafts );
    551 }
    552 
    553 function wp_dashboard_quick_press() {
    554     echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
    555570}
    556571
     
    582597        <li><?php echo join( "</li>\n<li>", $list ); ?></li>
    583598    </ul>
    584     <p class="textright"><a href="edit.php?post_status=draft" class="button"><?php _e('View all'); ?></a></p>
     599    <p class="textright"><a href="edit.php?post_status=draft" ><?php _e('View all'); ?></a></p>
    585600<?php
    586601    } else {
     
    635650<?php
    636651        if ( current_user_can('edit_posts') ) { ?>
    637             <p class="textright"><a href="edit-comments.php" class="button"><?php _e('View all'); ?></a></p>
     652            <?php _get_list_table('WP_Comments_List_Table')->views(); ?>
    638653<?php   }
    639654
     
    768783
    769784function wp_dashboard_incoming_links() {
    770     echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
     785    wp_dashboard_cached_rss_widget( 'dashboard_incoming_links', 'wp_dashboard_incoming_links_output' );
    771786}
    772787
     
    856871
    857872function wp_dashboard_primary() {
    858     echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
     873    wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_rss_output' );
    859874}
    860875
     
    878893
    879894function wp_dashboard_secondary() {
    880     echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
     895    wp_dashboard_cached_rss_widget( 'dashboard_secondary', 'wp_dashboard_secondary_output' );
    881896}
    882897
     
    917932
    918933function wp_dashboard_plugins() {
    919     echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
     934    wp_dashboard_cached_rss_widget( 'dashboard_plugins', 'wp_dashboard_plugins_output', array(
     935        'http://wordpress.org/extend/plugins/rss/browse/popular/',
     936        'http://wordpress.org/extend/plugins/rss/browse/new/',
     937        'http://wordpress.org/extend/plugins/rss/browse/updated/'
     938    ) );
    920939}
    921940
     
    10171036 */
    10181037function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
    1019     $loading = '<p class="widget-loading">' . __( 'Loading&#8230;' ) . '</p>';
     1038    $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
     1039    $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
    10201040
    10211041    if ( empty($check_urls) ) {
    10221042        $widgets = get_option( 'dashboard_widget_options' );
    1023         if ( empty($widgets[$widget_id]['url']) ) {
     1043        if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
    10241044            echo $loading;
    10251045            return false;
     
    10281048    }
    10291049
    1030     include_once ABSPATH . WPINC . '/class-feed.php';
    1031     foreach ( $check_urls as $check_url ) {
    1032         $cache = new WP_Feed_Cache_Transient('', md5($check_url), '');
    1033         if ( ! $cache->load() ) {
    1034             echo $loading;
    1035             return false;
    1036         }
     1050    $cache_key = 'dash_' . md5( $widget_id );
     1051    if ( false !== ( $output = get_transient( $cache_key ) ) ) {
     1052        echo $output;
     1053        return true;
     1054    }
     1055
     1056    if ( ! $doing_ajax ) {
     1057        echo $loading;
     1058        return false;
    10371059    }
    10381060
     
    10401062        $args = array_slice( func_get_args(), 2 );
    10411063        array_unshift( $args, $widget_id );
     1064        ob_start();
    10421065        call_user_func_array( $callback, $args );
     1066        set_transient( $cache_key, ob_get_flush(), 43200); // Default lifetime in cache of 12 hours (same as the feeds)
    10431067    }
    10441068
     
    11001124        }
    11011125        update_option( 'dashboard_widget_options', $widget_options );
     1126        $cache_key = 'dash_' . md5( $widget_id );
     1127        delete_transient( $cache_key );
    11021128    }
    11031129
     
    11071133// Display File upload quota on dashboard
    11081134function wp_dashboard_quota() {
    1109     if ( !is_multisite() || !current_user_can('edit_posts') || get_site_option( 'upload_space_check_disabled' ) )
     1135    if ( !is_multisite() || !current_user_can('upload_files') || get_site_option( 'upload_space_check_disabled' ) )
    11101136        return true;
    11111137
     
    11171143    else
    11181144        $percentused = ( $used / $quota ) * 100;
    1119     $used_color = ( $percentused < 70 ) ? ( ( $percentused >= 40 ) ? 'waiting' : 'approved' ) : 'spam';
     1145    $used_color = ( $percentused >= 70 ) ? ' spam' : '';
    11201146    $used = round( $used, 2 );
    11211147    $percentused = number_format( $percentused );
     
    11351161        <tr class="first">
    11361162            <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' ) ), $used, $percentused ); ?></td>
    1137             <td class="last t comments <?php echo $used_color;?>"><?php _e( 'Space Used' );?></td>
     1163            <td class="last t comments<?php echo $used_color;?>"><?php _e( 'Space Used' );?></td>
    11381164        </tr>
    11391165    </table>
     
    11441170add_action( 'activity_box_end', 'wp_dashboard_quota' );
    11451171
     1172// Display Browser Nag Meta Box
     1173function wp_dashboard_browser_nag() {
     1174    $notice = '';
     1175    $response = wp_check_browser_version();
     1176
     1177    if ( $response ) {
     1178        if ( $response['insecure'] ) {
     1179            $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'] ) );
     1180        } else {
     1181            $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'] ) );
     1182        }
     1183
     1184        $browser_nag_class = '';
     1185        if ( !empty( $response['img_src'] ) ) {
     1186            $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
     1187
     1188            $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
     1189            $browser_nag_class = ' has-browser-icon';
     1190        }
     1191        $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
     1192        $notice .= sprintf( __( '<p><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></p>' ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ), 'http://browsehappy.com/' );
     1193        $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
     1194        $notice .= '<div class="clear"></div>';
     1195    }
     1196
     1197    echo apply_filters( 'browse-happy-notice', $notice, $response );
     1198}
     1199
     1200function dashboard_browser_nag_class( $classes ) {
     1201    $response = wp_check_browser_version();
     1202
     1203    if ( $response && $response['insecure'] )
     1204        $classes[] = 'browser-insecure';
     1205
     1206    return $classes;
     1207}
     1208
     1209/**
     1210 * Check if the user needs a browser update
     1211 *
     1212 * @since 3.2.0
     1213 *
     1214 * @return array|bool False on failure, array of browser data on success.
     1215 */
     1216function wp_check_browser_version() {
     1217    if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
     1218        return false;
     1219
     1220    $key = md5( $_SERVER['HTTP_USER_AGENT'] );
     1221
     1222    if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
     1223        global $wp_version;
     1224
     1225        $options = array(
     1226            'body'          => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
     1227            'user-agent'    => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
     1228        );
     1229
     1230        $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
     1231
     1232        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
     1233            return false;
     1234
     1235        /**
     1236         * Response should be an array with:
     1237         *  'name' - string - A user friendly browser name
     1238         *  'version' - string - The most recent version of the browser
     1239         *  'current_version' - string - The version of the browser the user is using
     1240         *  'upgrade' - boolean - Whether the browser needs an upgrade
     1241         *  'insecure' - boolean - Whether the browser is deemed insecure
     1242         *  'upgrade_url' - string - The url to visit to upgrade
     1243         *  'img_src' - string - An image representing the browser
     1244         *  'img_src_ssl' - string - An image (over SSL) representing the browser
     1245         */
     1246        $response = unserialize( wp_remote_retrieve_body( $response ) );
     1247
     1248        if ( ! $response )
     1249            return false;
     1250
     1251        set_site_transient( 'browser_' . $key, $response, 604800 ); // cache for 1 week
     1252    }
     1253
     1254    return $response;
     1255}
     1256
    11461257/**
    11471258 * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
Note: See TracChangeset for help on using the changeset viewer.