Changes from branches/3.1/wp-admin/includes/dashboard.php at r17557 to trunk/wp-admin/includes/dashboard.php at r18314
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/dashboard.php
r17557 r18314 1 1 <?php 2 2 /** 3 * WordPress Dashboard Widget Administration PanelAPI3 * WordPress Dashboard Widget Administration Screen API 4 4 * 5 5 * @package WordPress … … 25 25 26 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 } 27 37 28 38 // Right Now … … 162 172 if ( in_array($widget_id, $side_widgets) ) 163 173 $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 ); 165 180 } 166 181 … … 385 400 386 401 $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') ) 389 403 $switch_themes = '<a href="themes.php">' . $switch_themes . '</a>'; 390 }391 404 if ( current_user_can( 'edit_theme_options' ) ) { 392 405 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); … … 395 408 } 396 409 } 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' ) ) 399 411 printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $ct->title ); 400 } else {412 else 401 413 printf( __('Theme <span class="b">%1$s</span>'), $ct->title ); 402 }403 414 } 404 415 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 } 405 424 406 425 update_right_now_message(); … … 458 477 } 459 478 460 function wp_dashboard_quick_press _output() {479 function wp_dashboard_quick_press() { 461 480 global $post_ID; 462 481 … … 539 558 <span id="publishing-action"> 540 559 <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="" /> 542 561 </span> 543 562 <br class="clear" /> … … 549 568 if ( $drafts ) 550 569 wp_dashboard_recent_drafts( $drafts ); 551 }552 553 function wp_dashboard_quick_press() {554 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';555 570 } 556 571 … … 582 597 <li><?php echo join( "</li>\n<li>", $list ); ?></li> 583 598 </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> 585 600 <?php 586 601 } else { … … 635 650 <?php 636 651 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(); ?> 638 653 <?php } 639 654 … … 768 783 769 784 function wp_dashboard_incoming_links() { 770 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</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' ); 771 786 } 772 787 … … 856 871 857 872 function wp_dashboard_primary() { 858 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';873 wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_rss_output' ); 859 874 } 860 875 … … 878 893 879 894 function wp_dashboard_secondary() { 880 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';895 wp_dashboard_cached_rss_widget( 'dashboard_secondary', 'wp_dashboard_secondary_output' ); 881 896 } 882 897 … … 917 932 918 933 function wp_dashboard_plugins() { 919 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</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 ) ); 920 939 } 921 940 … … 1017 1036 */ 1018 1037 function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) { 1019 $loading = '<p class="widget-loading">' . __( 'Loading…' ) . '</p>'; 1038 $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>'; 1039 $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX ); 1020 1040 1021 1041 if ( empty($check_urls) ) { 1022 1042 $widgets = get_option( 'dashboard_widget_options' ); 1023 if ( empty($widgets[$widget_id]['url']) ) {1043 if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) { 1024 1044 echo $loading; 1025 1045 return false; … … 1028 1048 } 1029 1049 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; 1037 1059 } 1038 1060 … … 1040 1062 $args = array_slice( func_get_args(), 2 ); 1041 1063 array_unshift( $args, $widget_id ); 1064 ob_start(); 1042 1065 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) 1043 1067 } 1044 1068 … … 1100 1124 } 1101 1125 update_option( 'dashboard_widget_options', $widget_options ); 1126 $cache_key = 'dash_' . md5( $widget_id ); 1127 delete_transient( $cache_key ); 1102 1128 } 1103 1129 … … 1107 1133 // Display File upload quota on dashboard 1108 1134 function 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' ) ) 1110 1136 return true; 1111 1137 … … 1117 1143 else 1118 1144 $percentused = ( $used / $quota ) * 100; 1119 $used_color = ( $percentused < 70 ) ? ( ( $percentused >= 40 ) ? 'waiting' : 'approved' ) : 'spam';1145 $used_color = ( $percentused >= 70 ) ? ' spam' : ''; 1120 1146 $used = round( $used, 2 ); 1121 1147 $percentused = number_format( $percentused ); … … 1135 1161 <tr class="first"> 1136 1162 <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 1163 <td class="last t comments<?php echo $used_color;?>"><?php _e( 'Space Used' );?></td> 1138 1164 </tr> 1139 1165 </table> … … 1144 1170 add_action( 'activity_box_end', 'wp_dashboard_quota' ); 1145 1171 1172 // Display Browser Nag Meta Box 1173 function 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 1200 function 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 */ 1216 function 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 1146 1257 /** 1147 1258 * 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.