[44] | 1 | <?php
|
---|
| 2 | /**
|
---|
| 3 | * WordPress Dashboard Widget Administration Panel API
|
---|
| 4 | *
|
---|
| 5 | * @package WordPress
|
---|
| 6 | * @subpackage Administration
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | /**
|
---|
| 10 | * Registers dashboard widgets.
|
---|
| 11 | *
|
---|
| 12 | * handles POST data, sets up filters.
|
---|
| 13 | *
|
---|
| 14 | * @since unknown
|
---|
| 15 | */
|
---|
| 16 | function wp_dashboard_setup() {
|
---|
| 17 | global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
|
---|
| 18 | $wp_dashboard_control_callbacks = array();
|
---|
| 19 |
|
---|
| 20 | $update = false;
|
---|
| 21 | $widget_options = get_option( 'dashboard_widget_options' );
|
---|
| 22 | if ( !$widget_options || !is_array($widget_options) )
|
---|
| 23 | $widget_options = array();
|
---|
| 24 |
|
---|
| 25 | /* Register Widgets and Controls */
|
---|
| 26 |
|
---|
| 27 | // Right Now
|
---|
| 28 | wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' );
|
---|
| 29 |
|
---|
| 30 | // Recent Comments Widget
|
---|
| 31 | $recent_comments_title = __( 'Recent Comments' );
|
---|
| 32 | wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments' );
|
---|
| 33 |
|
---|
| 34 | // Incoming Links Widget
|
---|
| 35 | if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) {
|
---|
| 36 | $update = true;
|
---|
| 37 | $widget_options['dashboard_incoming_links'] = array(
|
---|
| 38 | 'home' => get_option('home'),
|
---|
| 39 | 'link' => apply_filters( 'dashboard_incoming_links_link', 'http://blogsearch.google.com/blogsearch?hl=en&scoring=d&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
|
---|
| 40 | '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?hl=en&scoring=d&ie=utf-8&num=20&output=rss&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
|
---|
| 41 | 'items' => isset($widget_options['dashboard_incoming_links']['items']) ? $widget_options['dashboard_incoming_links']['items'] : 10,
|
---|
| 42 | 'show_date' => isset($widget_options['dashboard_incoming_links']['show_date']) ? $widget_options['dashboard_incoming_links']['show_date'] : false
|
---|
| 43 | );
|
---|
| 44 | }
|
---|
| 45 | wp_add_dashboard_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_incoming_links', 'wp_dashboard_incoming_links_control' );
|
---|
| 46 |
|
---|
| 47 | // WP Plugins Widget
|
---|
| 48 | if ( current_user_can( 'activate_plugins' ) )
|
---|
| 49 | wp_add_dashboard_widget( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_plugins' );
|
---|
| 50 |
|
---|
| 51 | // QuickPress Widget
|
---|
| 52 | if ( current_user_can('edit_posts') )
|
---|
| 53 | wp_add_dashboard_widget( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_quick_press' );
|
---|
| 54 |
|
---|
| 55 | // Recent Drafts
|
---|
| 56 | if ( current_user_can('edit_posts') )
|
---|
| 57 | wp_add_dashboard_widget( 'dashboard_recent_drafts', __('Recent Drafts'), 'wp_dashboard_recent_drafts' );
|
---|
| 58 |
|
---|
| 59 | // Primary feed (Dev Blog) Widget
|
---|
| 60 | if ( !isset( $widget_options['dashboard_primary'] ) ) {
|
---|
| 61 | $update = true;
|
---|
| 62 | $widget_options['dashboard_primary'] = array(
|
---|
| 63 | 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/development/' ) ),
|
---|
| 64 | 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/development/feed/' ) ),
|
---|
| 65 | 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Development Blog' ) ),
|
---|
| 66 | 'items' => 2,
|
---|
| 67 | 'show_summary' => 1,
|
---|
| 68 | 'show_author' => 0,
|
---|
| 69 | 'show_date' => 1
|
---|
| 70 | );
|
---|
| 71 | }
|
---|
| 72 | wp_add_dashboard_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_primary', 'wp_dashboard_primary_control' );
|
---|
| 73 |
|
---|
| 74 | // Secondary Feed (Planet) Widget
|
---|
| 75 | if ( !isset( $widget_options['dashboard_secondary'] ) ) {
|
---|
| 76 | $update = true;
|
---|
| 77 | $widget_options['dashboard_secondary'] = array(
|
---|
| 78 | 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
|
---|
| 79 | 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
|
---|
| 80 | 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
|
---|
| 81 | 'items' => 5
|
---|
| 82 | );
|
---|
| 83 | }
|
---|
| 84 | wp_add_dashboard_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_secondary', 'wp_dashboard_secondary_control' );
|
---|
| 85 |
|
---|
| 86 | // Hook to register new widgets
|
---|
| 87 | do_action( 'wp_dashboard_setup' );
|
---|
| 88 |
|
---|
| 89 | // Filter widget order
|
---|
| 90 | $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
|
---|
| 91 |
|
---|
| 92 | foreach ( $dashboard_widgets as $widget_id ) {
|
---|
| 93 | $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>';
|
---|
| 94 | wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
|
---|
| 98 | ob_start(); // hack - but the same hack wp-admin/widgets.php uses
|
---|
| 99 | wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
|
---|
| 100 | ob_end_clean();
|
---|
| 101 | wp_redirect( remove_query_arg( 'edit' ) );
|
---|
| 102 | exit;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | if ( $update )
|
---|
| 106 | update_option( 'dashboard_widget_options', $widget_options );
|
---|
| 107 |
|
---|
| 108 | do_action('do_meta_boxes', 'dashboard', 'normal', '');
|
---|
| 109 | do_action('do_meta_boxes', 'dashboard', 'side', '');
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null ) {
|
---|
| 113 | global $wp_dashboard_control_callbacks;
|
---|
| 114 | if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
|
---|
| 115 | $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
|
---|
| 116 | if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
|
---|
| 117 | list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
|
---|
| 118 | $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
|
---|
| 119 | add_meta_box( $widget_id, $widget_name, '_wp_dashboard_control_callback', 'dashboard', 'normal', 'core' );
|
---|
| 120 | return;
|
---|
| 121 | }
|
---|
| 122 | list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
|
---|
| 123 | $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
|
---|
| 124 | }
|
---|
| 125 | $side_widgets = array('dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_primary', 'dashboard_secondary');
|
---|
| 126 | $location = 'normal';
|
---|
| 127 | if ( in_array($widget_id, $side_widgets) )
|
---|
| 128 | $location = 'side';
|
---|
| 129 | add_meta_box( $widget_id, $widget_name , $callback, 'dashboard', $location, 'core' );
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
|
---|
| 133 | echo '<form action="" method="post" class="dashboard-widget-control-form">';
|
---|
| 134 | wp_dashboard_trigger_widget_control( $meta_box['id'] );
|
---|
| 135 | echo "<p class='submit'><input type='hidden' name='widget_id' value='" . esc_attr($meta_box['id']) . "' /><input type='submit' value='" . esc_attr__( 'Submit' ) . "' /></p>";
|
---|
| 136 |
|
---|
| 137 | echo '</form>';
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /**
|
---|
| 141 | * Displays the dashboard.
|
---|
| 142 | *
|
---|
| 143 | * @since unknown
|
---|
| 144 | */
|
---|
| 145 | function wp_dashboard() {
|
---|
| 146 | global $screen_layout_columns;
|
---|
| 147 |
|
---|
| 148 | $hide2 = $hide3 = $hide4 = '';
|
---|
| 149 | switch ( $screen_layout_columns ) {
|
---|
| 150 | case 4:
|
---|
| 151 | $width = 'width:24.5%;';
|
---|
| 152 | break;
|
---|
| 153 | case 3:
|
---|
| 154 | $width = 'width:32.67%;';
|
---|
| 155 | $hide4 = 'display:none;';
|
---|
| 156 | break;
|
---|
| 157 | case 2:
|
---|
| 158 | $width = 'width:49%;';
|
---|
| 159 | $hide3 = $hide4 = 'display:none;';
|
---|
| 160 | break;
|
---|
| 161 | default:
|
---|
| 162 | $width = 'width:98%;';
|
---|
| 163 | $hide2 = $hide3 = $hide4 = 'display:none;';
|
---|
| 164 | }
|
---|
| 165 | ?>
|
---|
| 166 | <div id='dashboard-widgets' class='metabox-holder'>
|
---|
| 167 | <?php
|
---|
| 168 | echo "\t<div class='postbox-container' style='$width'>\n";
|
---|
| 169 | do_meta_boxes( 'dashboard', 'normal', '' );
|
---|
| 170 |
|
---|
| 171 | echo "\t</div><div class='postbox-container' style='{$hide2}$width'>\n";
|
---|
| 172 | do_meta_boxes( 'dashboard', 'side', '' );
|
---|
| 173 |
|
---|
| 174 | echo "\t</div><div class='postbox-container' style='{$hide3}$width'>\n";
|
---|
| 175 | do_meta_boxes( 'dashboard', 'column3', '' );
|
---|
| 176 |
|
---|
| 177 | echo "\t</div><div class='postbox-container' style='{$hide4}$width'>\n";
|
---|
| 178 | do_meta_boxes( 'dashboard', 'column4', '' );
|
---|
| 179 | ?>
|
---|
| 180 | </div></div>
|
---|
| 181 |
|
---|
| 182 | <form style='display: none' method='get' action=''>
|
---|
| 183 | <p>
|
---|
| 184 | <?php
|
---|
| 185 | wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
|
---|
| 186 | wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
|
---|
| 187 | ?>
|
---|
| 188 | </p>
|
---|
| 189 | </form>
|
---|
| 190 |
|
---|
| 191 | <?php
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | /* Dashboard Widgets */
|
---|
| 195 |
|
---|
| 196 | function wp_dashboard_right_now() {
|
---|
| 197 | global $wp_registered_sidebars;
|
---|
| 198 |
|
---|
| 199 | $num_posts = wp_count_posts( 'post' );
|
---|
| 200 | $num_pages = wp_count_posts( 'page' );
|
---|
| 201 |
|
---|
| 202 | $num_cats = wp_count_terms('category');
|
---|
| 203 |
|
---|
| 204 | $num_tags = wp_count_terms('post_tag');
|
---|
| 205 |
|
---|
| 206 | $num_comm = wp_count_comments( );
|
---|
| 207 |
|
---|
| 208 | echo "\n\t".'<p class="sub">' . __('At a Glance') . '</p>';
|
---|
| 209 | echo "\n\t".'<div class="table">'."\n\t".'<table>';
|
---|
| 210 | echo "\n\t".'<tr class="first">';
|
---|
| 211 |
|
---|
| 212 | // Posts
|
---|
| 213 | $num = number_format_i18n( $num_posts->publish );
|
---|
| 214 | $text = _n( 'Post', 'Posts', intval($num_posts->publish) );
|
---|
| 215 | if ( current_user_can( 'edit_posts' ) ) {
|
---|
| 216 | $num = "<a href='edit.php'>$num</a>";
|
---|
| 217 | $text = "<a href='edit.php'>$text</a>";
|
---|
| 218 | }
|
---|
| 219 | echo '<td class="first b b-posts">' . $num . '</td>';
|
---|
| 220 | echo '<td class="t posts">' . $text . '</td>';
|
---|
| 221 | /* TODO: Show status breakdown on hover
|
---|
| 222 | if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds. Don't show if !current_user_can
|
---|
| 223 | $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( _n( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>';
|
---|
| 224 | }
|
---|
| 225 | if ( $can_edit_posts && !empty($num_posts->draft) ) {
|
---|
| 226 | $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>';
|
---|
| 227 | }
|
---|
| 228 | if ( $can_edit_posts && !empty($num_posts->future) ) {
|
---|
| 229 | $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>';
|
---|
| 230 | }
|
---|
| 231 | if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
|
---|
| 232 | $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 ) );
|
---|
| 233 | } else {
|
---|
| 234 | $pending_text = '';
|
---|
| 235 | }
|
---|
| 236 | */
|
---|
| 237 |
|
---|
| 238 | // Total Comments
|
---|
| 239 | $num = number_format_i18n($num_comm->total_comments);
|
---|
| 240 | $text = _n( 'Comment', 'Comments', $num_comm->total_comments );
|
---|
| 241 | if ( current_user_can( 'moderate_comments' ) ) {
|
---|
| 242 | $num = "<a href='edit-comments.php'>$num</a>";
|
---|
| 243 | $text = "<a href='edit-comments.php'>$text</a>";
|
---|
| 244 | }
|
---|
| 245 | echo '<td class="b b-comments">' . $num . '</td>';
|
---|
| 246 | echo '<td class="last t comments">' . $text . '</td>';
|
---|
| 247 |
|
---|
| 248 | echo '</tr><tr>';
|
---|
| 249 |
|
---|
| 250 | // Pages
|
---|
| 251 | $num = number_format_i18n( $num_pages->publish );
|
---|
| 252 | $text = _n( 'Page', 'Pages', $num_pages->publish );
|
---|
| 253 | if ( current_user_can( 'edit_pages' ) ) {
|
---|
| 254 | $num = "<a href='edit-pages.php'>$num</a>";
|
---|
| 255 | $text = "<a href='edit-pages.php'>$text</a>";
|
---|
| 256 | }
|
---|
| 257 | echo '<td class="first b b_pages">' . $num . '</td>';
|
---|
| 258 | echo '<td class="t pages">' . $text . '</td>';
|
---|
| 259 |
|
---|
| 260 | // Approved Comments
|
---|
| 261 | $num = number_format_i18n($num_comm->approved);
|
---|
| 262 | $text = _nc( 'Approved|Right Now', 'Approved', $num_comm->approved );
|
---|
| 263 | if ( current_user_can( 'moderate_comments' ) ) {
|
---|
| 264 | $num = "<a href='edit-comments.php?comment_status=approved'>$num</a>";
|
---|
| 265 | $text = "<a class='approved' href='edit-comments.php?comment_status=approved'>$text</a>";
|
---|
| 266 | }
|
---|
| 267 | echo '<td class="b b_approved">' . $num . '</td>';
|
---|
| 268 | echo '<td class="last t">' . $text . '</td>';
|
---|
| 269 |
|
---|
| 270 | echo "</tr>\n\t<tr>";
|
---|
| 271 |
|
---|
| 272 | // Categories
|
---|
| 273 | $num = number_format_i18n( $num_cats );
|
---|
| 274 | $text = _n( 'Category', 'Categories', $num_cats );
|
---|
| 275 | if ( current_user_can( 'manage_categories' ) ) {
|
---|
| 276 | $num = "<a href='categories.php'>$num</a>";
|
---|
| 277 | $text = "<a href='categories.php'>$text</a>";
|
---|
| 278 | }
|
---|
| 279 | echo '<td class="first b b-cats">' . $num . '</td>';
|
---|
| 280 | echo '<td class="t cats">' . $text . '</td>';
|
---|
| 281 |
|
---|
| 282 | // Pending Comments
|
---|
| 283 | $num = number_format_i18n($num_comm->moderated);
|
---|
| 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'><span class='pending-count'>$num</span></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 |
|
---|
| 292 | echo "</tr>\n\t<tr>";
|
---|
| 293 |
|
---|
| 294 | // Tags
|
---|
| 295 | $num = number_format_i18n( $num_tags );
|
---|
| 296 | $text = _n( 'Tag', 'Tags', $num_tags );
|
---|
| 297 | if ( current_user_can( 'manage_categories' ) ) {
|
---|
| 298 | $num = "<a href='edit-tags.php'>$num</a>";
|
---|
| 299 | $text = "<a href='edit-tags.php'>$text</a>";
|
---|
| 300 | }
|
---|
| 301 | echo '<td class="first b b-tags">' . $num . '</td>';
|
---|
| 302 | echo '<td class="t tags">' . $text . '</td>';
|
---|
| 303 |
|
---|
| 304 | // Spam Comments
|
---|
| 305 | $num = number_format_i18n($num_comm->spam);
|
---|
| 306 | $text = _n( 'Spam', 'Spam', $num_comm->spam );
|
---|
| 307 | if ( current_user_can( 'moderate_comments' ) ) {
|
---|
| 308 | $num = "<a href='edit-comments.php?comment_status=spam'><span class='spam-count'>$num</span></a>";
|
---|
| 309 | $text = "<a class='spam' href='edit-comments.php?comment_status=spam'>$text</a>";
|
---|
| 310 | }
|
---|
| 311 | echo '<td class="b b-spam">' . $num . '</td>';
|
---|
| 312 | echo '<td class="last t">' . $text . '</td>';
|
---|
| 313 |
|
---|
| 314 | echo "</tr>";
|
---|
| 315 | do_action('right_now_table_end');
|
---|
| 316 | echo "\n\t</table>\n\t</div>";
|
---|
| 317 |
|
---|
| 318 | echo "\n\t".'<div class="versions">';
|
---|
| 319 | $ct = current_theme_info();
|
---|
| 320 |
|
---|
| 321 | echo "\n\t<p>";
|
---|
| 322 | if ( !empty($wp_registered_sidebars) ) {
|
---|
| 323 | $sidebars_widgets = wp_get_sidebars_widgets();
|
---|
| 324 | $num_widgets = 0;
|
---|
| 325 | foreach ( (array) $sidebars_widgets as $k => $v ) {
|
---|
| 326 | if ( 'wp_inactive_widgets' == $k )
|
---|
| 327 | continue;
|
---|
| 328 | if ( is_array($v) )
|
---|
| 329 | $num_widgets = $num_widgets + count($v);
|
---|
| 330 | }
|
---|
| 331 | $num = number_format_i18n( $num_widgets );
|
---|
| 332 |
|
---|
| 333 | if ( current_user_can( 'switch_themes' ) ) {
|
---|
| 334 | echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
|
---|
| 335 | printf(_n('Theme <span class="b"><a href="themes.php">%1$s</a></span> with <span class="b"><a href="widgets.php">%2$s Widget</a></span>', 'Theme <span class="b"><a href="themes.php">%1$s</a></span> with <span class="b"><a href="widgets.php">%2$s Widgets</a></span>', $num_widgets), $ct->title, $num);
|
---|
| 336 | } else {
|
---|
| 337 | 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), $ct->title, $num);
|
---|
| 338 | }
|
---|
| 339 | } else {
|
---|
| 340 | if ( current_user_can( 'switch_themes' ) ) {
|
---|
| 341 | echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
|
---|
| 342 | printf('Theme <span class="b"><a href="themes.php">%1$s</a></span>', $ct->title);
|
---|
| 343 | } else {
|
---|
| 344 | printf('Theme <span class="b">%1$s</span>', $ct->title);
|
---|
| 345 | }
|
---|
| 346 | }
|
---|
| 347 | echo '</p>';
|
---|
| 348 |
|
---|
| 349 | update_right_now_message();
|
---|
| 350 |
|
---|
| 351 | echo "\n\t".'<br class="clear" /></div>';
|
---|
| 352 | do_action( 'rightnow_end' );
|
---|
| 353 | do_action( 'activity_box_end' );
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | function wp_dashboard_quick_press() {
|
---|
| 357 | $drafts = false;
|
---|
| 358 | if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
|
---|
| 359 | $view = get_permalink( $_POST['post_ID'] );
|
---|
| 360 | $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
|
---|
| 361 | if ( 'post-quickpress-publish' == $_POST['action'] ) {
|
---|
| 362 | if ( current_user_can('publish_posts') )
|
---|
| 363 | printf( '<div class="message"><p>' . __( 'Post Published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( $view ), $edit );
|
---|
| 364 | else
|
---|
| 365 | printf( '<div class="message"><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 );
|
---|
| 366 | } else {
|
---|
| 367 | printf( '<div class="message"><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 );
|
---|
| 368 | $drafts_query = new WP_Query( array(
|
---|
| 369 | 'post_type' => 'post',
|
---|
| 370 | 'post_status' => 'draft',
|
---|
| 371 | 'author' => $GLOBALS['current_user']->ID,
|
---|
| 372 | 'posts_per_page' => 1,
|
---|
| 373 | 'orderby' => 'modified',
|
---|
| 374 | 'order' => 'DESC'
|
---|
| 375 | ) );
|
---|
| 376 |
|
---|
| 377 | if ( $drafts_query->posts )
|
---|
| 378 | $drafts =& $drafts_query->posts;
|
---|
| 379 | }
|
---|
| 380 | printf('<p class="textright">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="tools.php">' . __('Press This') . '</a>' );
|
---|
| 381 | $_REQUEST = array(); // hack for get_default_post_to_edit()
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | $post = get_default_post_to_edit();
|
---|
| 385 | ?>
|
---|
| 386 |
|
---|
| 387 | <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
|
---|
| 388 | <h4 id="quick-post-title"><label for="title"><?php _e('Title') ?></label></h4>
|
---|
| 389 | <div class="input-text-wrap">
|
---|
| 390 | <input type="text" name="post_title" id="title" tabindex="1" autocomplete="off" value="<?php echo esc_attr( $post->post_title ); ?>" />
|
---|
| 391 | </div>
|
---|
| 392 |
|
---|
| 393 | <?php if ( current_user_can( 'upload_files' ) ) : ?>
|
---|
| 394 | <div id="media-buttons" class="hide-if-no-js">
|
---|
| 395 | <?php do_action( 'media_buttons' ); ?>
|
---|
| 396 | </div>
|
---|
| 397 | <?php endif; ?>
|
---|
| 398 |
|
---|
| 399 | <h4 id="content-label"><label for="content"><?php _e('Content') ?></label></h4>
|
---|
| 400 | <div class="textarea-wrap">
|
---|
| 401 | <textarea name="content" id="content" class="mceEditor" rows="3" cols="15" tabindex="2"><?php echo $post->post_content; ?></textarea>
|
---|
| 402 | </div>
|
---|
| 403 |
|
---|
| 404 | <script type="text/javascript">edCanvas = document.getElementById('content');edInsertContent = null;</script>
|
---|
| 405 |
|
---|
| 406 | <h4><label for="tags-input"><?php _e('Tags') ?></label></h4>
|
---|
| 407 | <div class="input-text-wrap">
|
---|
| 408 | <input type="text" name="tags_input" id="tags-input" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
|
---|
| 409 | </div>
|
---|
| 410 |
|
---|
| 411 | <p class="submit">
|
---|
| 412 | <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
|
---|
| 413 | <input type="hidden" name="quickpress_post_ID" value="<?php echo (int) $post->ID; ?>" />
|
---|
| 414 | <?php wp_nonce_field('add-post'); ?>
|
---|
| 415 | <input type="submit" name="save" id="save-post" class="button" tabindex="4" value="<?php esc_attr_e('Save Draft'); ?>" />
|
---|
| 416 | <input type="reset" value="<?php esc_attr_e( 'Reset' ); ?>" class="button" />
|
---|
| 417 | <?php if ( current_user_can('publish_posts') ) { ?>
|
---|
| 418 | <input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="<?php esc_attr_e('Publish'); ?>" />
|
---|
| 419 | <?php } else { ?>
|
---|
| 420 | <input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="<?php esc_attr_e('Submit for Review'); ?>" />
|
---|
| 421 | <?php } ?>
|
---|
| 422 | <br class="clear" />
|
---|
| 423 | </p>
|
---|
| 424 |
|
---|
| 425 | </form>
|
---|
| 426 |
|
---|
| 427 | <?php
|
---|
| 428 | if ( $drafts )
|
---|
| 429 | wp_dashboard_recent_drafts( $drafts );
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | function wp_dashboard_recent_drafts( $drafts = false ) {
|
---|
| 433 | if ( !$drafts ) {
|
---|
| 434 | $drafts_query = new WP_Query( array(
|
---|
| 435 | 'post_type' => 'post',
|
---|
| 436 | 'post_status' => 'draft',
|
---|
| 437 | 'author' => $GLOBALS['current_user']->ID,
|
---|
| 438 | 'posts_per_page' => 5,
|
---|
| 439 | 'orderby' => 'modified',
|
---|
| 440 | 'order' => 'DESC'
|
---|
| 441 | ) );
|
---|
| 442 | $drafts =& $drafts_query->posts;
|
---|
| 443 | }
|
---|
| 444 |
|
---|
| 445 | if ( $drafts && is_array( $drafts ) ) {
|
---|
| 446 | $list = array();
|
---|
| 447 | foreach ( $drafts as $draft ) {
|
---|
| 448 | $url = get_edit_post_link( $draft->ID );
|
---|
| 449 | $title = _draft_or_post_title( $draft->ID );
|
---|
| 450 | $item = "<h4><a href='$url' title='" . sprintf( __( 'Edit “%s”' ), esc_attr( $title ) ) . "'>$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>';
|
---|
| 451 | if ( $the_content = preg_split( '#\s#', strip_tags( $draft->post_content ), 11, PREG_SPLIT_NO_EMPTY ) )
|
---|
| 452 | $item .= '<p>' . join( ' ', array_slice( $the_content, 0, 10 ) ) . ( 10 < count( $the_content ) ? '…' : '' ) . '</p>';
|
---|
| 453 | $list[] = $item;
|
---|
| 454 | }
|
---|
| 455 | ?>
|
---|
| 456 | <ul>
|
---|
| 457 | <li><?php echo join( "</li>\n<li>", $list ); ?></li>
|
---|
| 458 | </ul>
|
---|
| 459 | <p class="textright"><a href="edit.php?post_status=draft" class="button"><?php _e('View all'); ?></a></p>
|
---|
| 460 | <?php
|
---|
| 461 | } else {
|
---|
| 462 | _e('There are no drafts at the moment');
|
---|
| 463 | }
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | /**
|
---|
| 467 | * Display recent comments dashboard widget content.
|
---|
| 468 | *
|
---|
| 469 | * @since unknown
|
---|
| 470 | */
|
---|
| 471 | function wp_dashboard_recent_comments() {
|
---|
| 472 | global $wpdb;
|
---|
| 473 |
|
---|
| 474 | if ( current_user_can('edit_posts') )
|
---|
| 475 | $allowed_states = array('0', '1');
|
---|
| 476 | else
|
---|
| 477 | $allowed_states = array('1');
|
---|
| 478 |
|
---|
| 479 | // Select all comment types and filter out spam later for better query performance.
|
---|
| 480 | $comments = array();
|
---|
| 481 | $start = 0;
|
---|
| 482 |
|
---|
| 483 | while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments ORDER BY comment_date_gmt DESC LIMIT $start, 50" ) ) {
|
---|
| 484 |
|
---|
| 485 | foreach ( $possible as $comment ) {
|
---|
| 486 | if ( count( $comments ) >= 5 )
|
---|
| 487 | break;
|
---|
| 488 | if ( in_array( $comment->comment_approved, $allowed_states ) )
|
---|
| 489 | $comments[] = $comment;
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | $start = $start + 50;
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | if ( $comments ) :
|
---|
| 496 | ?>
|
---|
| 497 |
|
---|
| 498 | <div id="the-comment-list" class="list:comment">
|
---|
| 499 | <?php
|
---|
| 500 | foreach ( $comments as $comment )
|
---|
| 501 | _wp_dashboard_recent_comments_row( $comment );
|
---|
| 502 | ?>
|
---|
| 503 |
|
---|
| 504 | </div>
|
---|
| 505 |
|
---|
| 506 | <?php
|
---|
| 507 | if ( current_user_can('edit_posts') ) { ?>
|
---|
| 508 | <p class="textright"><a href="edit-comments.php" class="button"><?php _e('View all'); ?></a></p>
|
---|
| 509 | <?php }
|
---|
| 510 |
|
---|
| 511 | wp_comment_reply( -1, false, 'dashboard', false );
|
---|
| 512 |
|
---|
| 513 | else :
|
---|
| 514 | ?>
|
---|
| 515 |
|
---|
| 516 | <p><?php _e( 'No comments yet.' ); ?></p>
|
---|
| 517 |
|
---|
| 518 | <?php
|
---|
| 519 | endif; // $comments;
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 | function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
|
---|
| 523 | $GLOBALS['comment'] =& $comment;
|
---|
| 524 |
|
---|
| 525 | $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
|
---|
| 526 | $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
|
---|
| 527 | $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
|
---|
| 528 | $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
|
---|
| 529 |
|
---|
| 530 | $delete_url = esc_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
|
---|
| 531 | $approve_url = esc_url( wp_nonce_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) );
|
---|
| 532 | $unapprove_url = esc_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) );
|
---|
| 533 | $spam_url = esc_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
|
---|
| 534 |
|
---|
| 535 | $actions = array();
|
---|
| 536 |
|
---|
| 537 | $actions_string = '';
|
---|
| 538 | if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
|
---|
| 539 | $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
|
---|
| 540 | $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
|
---|
| 541 | $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
|
---|
| 542 | //$actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\',\'edit\');return false;" class="vim-q" title="'.__('Quick Edit').'" href="#">' . __('Quick Edit') . '</a>';
|
---|
| 543 | $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
|
---|
| 544 | $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
|
---|
| 545 | $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';
|
---|
| 546 |
|
---|
| 547 | $actions = apply_filters( 'comment_row_actions', $actions, $comment );
|
---|
| 548 |
|
---|
| 549 | $i = 0;
|
---|
| 550 | foreach ( $actions as $action => $link ) {
|
---|
| 551 | ++$i;
|
---|
| 552 | ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
|
---|
| 553 |
|
---|
| 554 | // Reply and quickedit need a hide-if-no-js span
|
---|
| 555 | if ( 'reply' == $action || 'quickedit' == $action )
|
---|
| 556 | $action .= ' hide-if-no-js';
|
---|
| 557 |
|
---|
| 558 | $actions_string .= "<span class='$action'>$sep$link</span>";
|
---|
| 559 | }
|
---|
| 560 | }
|
---|
| 561 |
|
---|
| 562 | ?>
|
---|
| 563 |
|
---|
| 564 | <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
|
---|
| 565 | <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
|
---|
| 566 |
|
---|
| 567 | <?php echo get_avatar( $comment, 50 ); ?>
|
---|
| 568 |
|
---|
| 569 | <div class="dashboard-comment-wrap">
|
---|
| 570 | <h4 class="comment-meta"><?php printf( __( 'From %1$s on %2$s%3$s' ), '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link." ".$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?></h4>
|
---|
| 571 |
|
---|
| 572 | <?php
|
---|
| 573 | else :
|
---|
| 574 | switch ( $comment->comment_type ) :
|
---|
| 575 | case 'pingback' :
|
---|
| 576 | $type = __( 'Pingback' );
|
---|
| 577 | break;
|
---|
| 578 | case 'trackback' :
|
---|
| 579 | $type = __( 'Trackback' );
|
---|
| 580 | break;
|
---|
| 581 | default :
|
---|
| 582 | $type = ucwords( $comment->comment_type );
|
---|
| 583 | endswitch;
|
---|
| 584 | $type = esc_html( $type );
|
---|
| 585 | ?>
|
---|
| 586 | <div class="dashboard-comment-wrap">
|
---|
| 587 | <?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?>
|
---|
| 588 | <h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link ); ?></h4>
|
---|
| 589 | <p class="comment-author"><?php comment_author_link(); ?></p>
|
---|
| 590 |
|
---|
| 591 | <?php endif; // comment_type ?>
|
---|
| 592 | <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
|
---|
| 593 | <p class="row-actions"><?php echo $actions_string; ?></p>
|
---|
| 594 |
|
---|
| 595 | <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
|
---|
| 596 | <textarea class="comment" rows="3" cols="10"><?php echo $comment->comment_content; ?></textarea>
|
---|
| 597 | <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
|
---|
| 598 | <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
|
---|
| 599 | <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
|
---|
| 600 | <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
|
---|
| 601 | </div>
|
---|
| 602 | </div>
|
---|
| 603 | </div>
|
---|
| 604 | <?php
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | function wp_dashboard_incoming_links() {
|
---|
| 608 | echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
|
---|
| 609 | }
|
---|
| 610 |
|
---|
| 611 | /**
|
---|
| 612 | * Display incoming links dashboard widget content.
|
---|
| 613 | *
|
---|
| 614 | * @since unknown
|
---|
| 615 | */
|
---|
| 616 | function wp_dashboard_incoming_links_output() {
|
---|
| 617 | $widgets = get_option( 'dashboard_widget_options' );
|
---|
| 618 | @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
|
---|
| 619 | $rss = fetch_feed( $url );
|
---|
| 620 |
|
---|
| 621 | if ( is_wp_error($rss) ) {
|
---|
| 622 | if ( is_admin() || current_user_can('manage_options') ) {
|
---|
| 623 | echo '<p>';
|
---|
| 624 | printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
|
---|
| 625 | echo '</p>';
|
---|
| 626 | }
|
---|
| 627 | return;
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | if ( !$rss->get_item_quantity() ) {
|
---|
| 631 | 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… yet. It’s okay — there is no rush.') . "</p>\n";
|
---|
| 632 | return;
|
---|
| 633 | }
|
---|
| 634 |
|
---|
| 635 | echo "<ul>\n";
|
---|
| 636 |
|
---|
| 637 | if ( !isset($items) )
|
---|
| 638 | $items = 10;
|
---|
| 639 |
|
---|
| 640 | foreach ( $rss->get_items(0, $items) as $item ) {
|
---|
| 641 | $publisher = '';
|
---|
| 642 | $site_link = '';
|
---|
| 643 | $link = '';
|
---|
| 644 | $content = '';
|
---|
| 645 | $date = '';
|
---|
| 646 | $link = esc_url( strip_tags( $item->get_link() ) );
|
---|
| 647 |
|
---|
| 648 | $author = $item->get_author();
|
---|
| 649 | if ( $author ) {
|
---|
| 650 | $site_link = esc_url( strip_tags( $author->get_link() ) );
|
---|
| 651 |
|
---|
| 652 | if ( !$publisher = esc_html( strip_tags( $author->get_name() ) ) )
|
---|
| 653 | $publisher = __( 'Somebody' );
|
---|
| 654 | } else {
|
---|
| 655 | $publisher = __( 'Somebody' );
|
---|
| 656 | }
|
---|
| 657 | if ( $site_link )
|
---|
| 658 | $publisher = "<a href='$site_link'>$publisher</a>";
|
---|
| 659 | else
|
---|
| 660 | $publisher = "<strong>$publisher</strong>";
|
---|
| 661 |
|
---|
| 662 | $content = $item->get_content();
|
---|
| 663 | $content = wp_html_excerpt($content, 50) . ' ...';
|
---|
| 664 |
|
---|
| 665 | if ( $link )
|
---|
| 666 | /* translators: incoming links feed, %1$s is other person, %3$s is content */
|
---|
| 667 | $text = __( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"' );
|
---|
| 668 | else
|
---|
| 669 | /* translators: incoming links feed, %1$s is other person, %3$s is content */
|
---|
| 670 | $text = __( '%1$s linked here saying, "%3$s"' );
|
---|
| 671 |
|
---|
| 672 | if ( $show_date ) {
|
---|
| 673 | if ( $show_author || $show_summary )
|
---|
| 674 | /* translators: incoming links feed, %4$s is the date */
|
---|
| 675 | $text .= ' ' . __( 'on %4$s' );
|
---|
| 676 | $date = esc_html( strip_tags( $item->get_date() ) );
|
---|
| 677 | $date = strtotime( $date );
|
---|
| 678 | $date = gmdate( get_option( 'date_format' ), $date );
|
---|
| 679 | }
|
---|
| 680 |
|
---|
| 681 | echo "\t<li>" . sprintf( $text, $publisher, $link, $content, $date ) . "</li>\n";
|
---|
| 682 | }
|
---|
| 683 |
|
---|
| 684 | echo "</ul>\n";
|
---|
| 685 |
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | function wp_dashboard_incoming_links_control() {
|
---|
| 689 | wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) );
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | function wp_dashboard_primary() {
|
---|
| 693 | echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
|
---|
| 694 | }
|
---|
| 695 |
|
---|
| 696 | function wp_dashboard_primary_control() {
|
---|
| 697 | wp_dashboard_rss_control( 'dashboard_primary' );
|
---|
| 698 | }
|
---|
| 699 |
|
---|
| 700 | /**
|
---|
| 701 | * {@internal Missing Short Description}}
|
---|
| 702 | *
|
---|
| 703 | * @since unknown
|
---|
| 704 | *
|
---|
| 705 | * @param int $widget_id
|
---|
| 706 | */
|
---|
| 707 | function wp_dashboard_rss_output( $widget_id ) {
|
---|
| 708 | $widgets = get_option( 'dashboard_widget_options' );
|
---|
| 709 | echo "<div class='rss-widget'>";
|
---|
| 710 | wp_widget_rss_output( $widgets[$widget_id] );
|
---|
| 711 | echo "</div>";
|
---|
| 712 | }
|
---|
| 713 |
|
---|
| 714 | function wp_dashboard_secondary() {
|
---|
| 715 | echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
|
---|
| 716 | }
|
---|
| 717 |
|
---|
| 718 | function wp_dashboard_secondary_control() {
|
---|
| 719 | wp_dashboard_rss_control( 'dashboard_secondary' );
|
---|
| 720 | }
|
---|
| 721 |
|
---|
| 722 | /**
|
---|
| 723 | * Display secondary dashboard RSS widget feed.
|
---|
| 724 | *
|
---|
| 725 | * @since unknown
|
---|
| 726 | *
|
---|
| 727 | * @return unknown
|
---|
| 728 | */
|
---|
| 729 | function wp_dashboard_secondary_output() {
|
---|
| 730 | $widgets = get_option( 'dashboard_widget_options' );
|
---|
| 731 | @extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
|
---|
| 732 | $rss = @fetch_feed( $url );
|
---|
| 733 |
|
---|
| 734 | if ( is_wp_error($rss) ) {
|
---|
| 735 | if ( is_admin() || current_user_can('manage_options') ) {
|
---|
| 736 | echo '<div class="rss-widget"><p>';
|
---|
| 737 | printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
|
---|
| 738 | echo '</p></div>';
|
---|
| 739 | }
|
---|
| 740 | } elseif ( !$rss->get_item_quantity() ) {
|
---|
| 741 | return false;
|
---|
| 742 | } else {
|
---|
| 743 | echo '<div class="rss-widget">';
|
---|
| 744 | wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] );
|
---|
| 745 | echo '</div>';
|
---|
| 746 | }
|
---|
| 747 | }
|
---|
| 748 |
|
---|
| 749 | function wp_dashboard_plugins() {
|
---|
| 750 | echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
|
---|
| 751 | }
|
---|
| 752 |
|
---|
| 753 | /**
|
---|
| 754 | * Display plugins most popular, newest plugins, and recently updated widget text.
|
---|
| 755 | *
|
---|
| 756 | * @since unknown
|
---|
| 757 | */
|
---|
| 758 | function wp_dashboard_plugins_output() {
|
---|
| 759 | $popular = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/popular/' );
|
---|
| 760 | $new = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
|
---|
| 761 | $updated = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
|
---|
| 762 |
|
---|
| 763 | if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
|
---|
| 764 | $plugin_slugs = array_keys( get_plugins() );
|
---|
| 765 | set_transient( 'plugin_slugs', $plugin_slugs, 86400 );
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 | foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
|
---|
| 769 | if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
|
---|
| 770 | continue;
|
---|
| 771 |
|
---|
| 772 | $items = $$feed->get_items(0, 5);
|
---|
| 773 |
|
---|
| 774 | // Pick a random, non-installed plugin
|
---|
| 775 | while ( true ) {
|
---|
| 776 | // Abort this foreach loop iteration if there's no plugins left of this type
|
---|
| 777 | if ( 0 == count($items) )
|
---|
| 778 | continue 2;
|
---|
| 779 |
|
---|
| 780 | $item_key = array_rand($items);
|
---|
| 781 | $item = $items[$item_key];
|
---|
| 782 |
|
---|
| 783 | list($link, $frag) = explode( '#', $item->get_link() );
|
---|
| 784 |
|
---|
| 785 | $link = esc_url($link);
|
---|
| 786 | if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
|
---|
| 787 | $slug = $matches[1];
|
---|
| 788 | else {
|
---|
| 789 | unset( $items[$item_key] );
|
---|
| 790 | continue;
|
---|
| 791 | }
|
---|
| 792 |
|
---|
| 793 | // Is this random plugin's slug already installed? If so, try again.
|
---|
| 794 | reset( $plugin_slugs );
|
---|
| 795 | foreach ( $plugin_slugs as $plugin_slug ) {
|
---|
| 796 | if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
|
---|
| 797 | unset( $items[$item_key] );
|
---|
| 798 | continue 2;
|
---|
| 799 | }
|
---|
| 800 | }
|
---|
| 801 |
|
---|
| 802 | // If we get to this point, then the random plugin isn't installed and we can stop the while().
|
---|
| 803 | break;
|
---|
| 804 | }
|
---|
| 805 |
|
---|
| 806 | // Eliminate some common badly formed plugin descriptions
|
---|
| 807 | while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
|
---|
| 808 | unset($items[$item_key]);
|
---|
| 809 |
|
---|
| 810 | if ( !isset($items[$item_key]) )
|
---|
| 811 | continue;
|
---|
| 812 |
|
---|
| 813 | // current bbPress feed item titles are: user on "topic title"
|
---|
| 814 | if ( preg_match( '/"(.*)"/s', $item->get_title(), $matches ) )
|
---|
| 815 | $title = $matches[1];
|
---|
| 816 | else // but let's make it forward compatible if things change
|
---|
| 817 | $title = $item->get_title();
|
---|
| 818 | $title = esc_html( $title );
|
---|
| 819 |
|
---|
| 820 | $description = esc_html( strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))) );
|
---|
| 821 |
|
---|
| 822 | $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
|
---|
| 823 | '&TB_iframe=true&width=600&height=800';
|
---|
| 824 |
|
---|
| 825 | echo "<h4>$label</h4>\n";
|
---|
| 826 | echo "<h5><a href='$link'>$title</a></h5> <span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span>\n";
|
---|
| 827 | echo "<p>$description</p>\n";
|
---|
| 828 | }
|
---|
| 829 | }
|
---|
| 830 |
|
---|
| 831 | /**
|
---|
| 832 | * Checks to see if all of the feed url in $check_urls are cached.
|
---|
| 833 | *
|
---|
| 834 | * If $check_urls is empty, look for the rss feed url found in the dashboard
|
---|
| 835 | * widget optios of $widget_id. If cached, call $callback, a function that
|
---|
| 836 | * echoes out output for this widget. If not cache, echo a "Loading..." stub
|
---|
| 837 | * which is later replaced by AJAX call (see top of /wp-admin/index.php)
|
---|
| 838 | *
|
---|
| 839 | * @since unknown
|
---|
| 840 | *
|
---|
| 841 | * @param int $widget_id
|
---|
| 842 | * @param callback $callback
|
---|
| 843 | * @param array $check_urls RSS feeds
|
---|
| 844 | * @return bool False on failure. True on success.
|
---|
| 845 | */
|
---|
| 846 | function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
|
---|
| 847 | $loading = '<p class="widget-loading">' . __( 'Loading…' ) . '</p>';
|
---|
| 848 |
|
---|
| 849 | if ( empty($check_urls) ) {
|
---|
| 850 | $widgets = get_option( 'dashboard_widget_options' );
|
---|
| 851 | if ( empty($widgets[$widget_id]['url']) ) {
|
---|
| 852 | echo $loading;
|
---|
| 853 | return false;
|
---|
| 854 | }
|
---|
| 855 | $check_urls = array( $widgets[$widget_id]['url'] );
|
---|
| 856 | }
|
---|
| 857 |
|
---|
| 858 | include_once ABSPATH . WPINC . '/class-feed.php';
|
---|
| 859 | foreach ( $check_urls as $check_url ) {
|
---|
| 860 | $cache = new WP_Feed_Cache_Transient('', md5($check_url), '');
|
---|
| 861 | if ( ! $cache->load() ) {
|
---|
| 862 | echo $loading;
|
---|
| 863 | return false;
|
---|
| 864 | }
|
---|
| 865 | }
|
---|
| 866 |
|
---|
| 867 | if ( $callback && is_callable( $callback ) ) {
|
---|
| 868 | $args = array_slice( func_get_args(), 2 );
|
---|
| 869 | array_unshift( $args, $widget_id );
|
---|
| 870 | call_user_func_array( $callback, $args );
|
---|
| 871 | }
|
---|
| 872 |
|
---|
| 873 | return true;
|
---|
| 874 | }
|
---|
| 875 |
|
---|
| 876 | /* Dashboard Widgets Controls */
|
---|
| 877 |
|
---|
| 878 | // Calls widget_control callback
|
---|
| 879 | /**
|
---|
| 880 | * Calls widget control callback.
|
---|
| 881 | *
|
---|
| 882 | * @since unknown
|
---|
| 883 | *
|
---|
| 884 | * @param int $widget_control_id Registered Widget ID.
|
---|
| 885 | */
|
---|
| 886 | function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
|
---|
| 887 | global $wp_dashboard_control_callbacks;
|
---|
| 888 |
|
---|
| 889 | 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]) ) {
|
---|
| 890 | call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
|
---|
| 891 | }
|
---|
| 892 | }
|
---|
| 893 |
|
---|
| 894 | /**
|
---|
| 895 | * The RSS dashboard widget control.
|
---|
| 896 | *
|
---|
| 897 | * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
|
---|
| 898 | * from RSS-type widgets.
|
---|
| 899 | *
|
---|
| 900 | * @since unknown
|
---|
| 901 | *
|
---|
| 902 | * @param string widget_id
|
---|
| 903 | * @param array form_inputs
|
---|
| 904 | */
|
---|
| 905 | function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
|
---|
| 906 | if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
|
---|
| 907 | $widget_options = array();
|
---|
| 908 |
|
---|
| 909 | if ( !isset($widget_options[$widget_id]) )
|
---|
| 910 | $widget_options[$widget_id] = array();
|
---|
| 911 |
|
---|
| 912 | $number = 1; // Hack to use wp_widget_rss_form()
|
---|
| 913 | $widget_options[$widget_id]['number'] = $number;
|
---|
| 914 |
|
---|
| 915 | if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
|
---|
| 916 | $_POST['widget-rss'][$number] = stripslashes_deep( $_POST['widget-rss'][$number] );
|
---|
| 917 | $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
|
---|
| 918 | // title is optional. If black, fill it if possible
|
---|
| 919 | if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
|
---|
| 920 | $rss = fetch_feed($widget_options[$widget_id]['url']);
|
---|
| 921 | if ( ! is_wp_error($rss) )
|
---|
| 922 | $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
|
---|
| 923 | else
|
---|
| 924 | $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
|
---|
| 925 | }
|
---|
| 926 | update_option( 'dashboard_widget_options', $widget_options );
|
---|
| 927 | }
|
---|
| 928 |
|
---|
| 929 | wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
|
---|
| 930 | }
|
---|
| 931 |
|
---|
| 932 | /**
|
---|
| 933 | * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
|
---|
| 934 | */
|
---|
| 935 | function wp_dashboard_empty() {}
|
---|
| 936 |
|
---|
| 937 | ?>
|
---|