PageRenderTime 54ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/dashboard.php

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