PageRenderTime 52ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/dashboard.php

https://bitbucket.org/masidev/eapinfo
PHP | 1326 lines | 956 code | 203 blank | 167 comment | 215 complexity | a3562c3e876753f8442fdcfe5610d1bd MD5 | raw file

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file