]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/dashboard.php
Wordpress 2.7.1
[autoinstalls/wordpress.git] / wp-admin / includes / dashboard.php
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' => apply_filters( 'dashboard_incoming_links_feed', 'http://blogsearch.google.com/blogsearch_feeds?hl=en&scoring=d&ie=utf-8&num=10&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="' . clean_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="' . clean_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='$meta_box[id]' /><input type='submit' value='" . __( 'Submit' ) . "' /></p>";
136
137         echo '</form>';
138 }
139
140 /**
141  * Displays the dashboard.
142  *
143  * @since unknown
144  */
145 function wp_dashboard() {
146         echo "<div id='dashboard-widgets' class='metabox-holder'>\n\n";
147
148         echo "<div id='side-info-column' class='inner-sidebar'>\n\n";
149         $class = do_meta_boxes( 'dashboard', 'side', '' ) ? ' class="has-sidebar"' : '';
150         echo "</div>\n\n";
151
152         echo "<div id='post-body'$class>\n\n";
153         echo "<div id='dashboard-widgets-main-content' class='has-sidebar-content'>\n\n";
154         do_meta_boxes( 'dashboard', 'normal', '' );
155         echo "</div>\n\n";
156         echo "</div>\n\n";
157
158         echo "<form style='display: none' method='get' action=''>\n<p>\n";
159         wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
160         wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
161         echo "</p>\n</form>\n";
162
163         echo "</div>";
164 }
165
166 /* Dashboard Widgets */
167
168 function wp_dashboard_right_now() {
169         $num_posts = wp_count_posts( 'post' );
170         $num_pages = wp_count_posts( 'page' );
171
172         $num_cats  = wp_count_terms('category');
173
174         $num_tags = wp_count_terms('post_tag');
175
176         $num_comm = wp_count_comments( );
177
178         echo "\n\t".'<p class="sub">' . __('At a Glance') . '</p>';
179         echo "\n\t".'<div class="table">'."\n\t".'<table>';
180         echo "\n\t".'<tr class="first">';
181
182         // Posts
183         $num = number_format_i18n( $num_posts->publish );
184         $text = __ngettext( 'Post', 'Posts', intval($num_posts->publish) );
185         if ( current_user_can( 'edit_posts' ) ) {
186                 $num = "<a href='edit.php'>$num</a>";
187                 $text = "<a href='edit.php'>$text</a>";
188         }
189         echo '<td class="first b b-posts">' . $num . '</td>';
190         echo '<td class="t posts">' . $text . '</td>';
191         /* TODO: Show status breakdown on hover
192         if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds.  Don't show if !current_user_can
193                 $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( __ngettext( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>';
194         }
195         if ( $can_edit_posts && !empty($num_posts->draft) ) {
196                 $post_type_texts[] = '<a href="edit.php?post_status=draft">'.sprintf( __ngettext( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'</a>';
197         }
198         if ( $can_edit_posts && !empty($num_posts->future) ) {
199                 $post_type_texts[] = '<a href="edit.php?post_status=future">'.sprintf( __ngettext( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'</a>';
200         }
201         if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
202                 $pending_text = sprintf( __ngettext( '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 ) );
203         } else {
204                 $pending_text = '';
205         }
206         */
207
208         // Total Comments
209         $num = number_format_i18n($num_comm->total_comments);
210         $text = __ngettext( 'Comment', 'Comments', $num_comm->total_comments );
211         if ( current_user_can( 'moderate_comments' ) ) {
212                 $num = "<a href='edit-comments.php'>$num</a>";
213                 $text = "<a href='edit-comments.php'>$text</a>";
214         }
215         echo '<td class="b b-comments">' . $num . '</td>';
216         echo '<td class="last t comments">' . $text . '</td>';
217
218         echo '</tr><tr>';
219
220         // Pages
221         $num = number_format_i18n( $num_pages->publish );
222         $text = __ngettext( 'Page', 'Pages', $num_pages->publish );
223         if ( current_user_can( 'edit_pages' ) ) {
224                 $num = "<a href='edit-pages.php'>$num</a>";
225                 $text = "<a href='edit-pages.php'>$text</a>";
226         }
227         echo '<td class="first b b_pages">' . $num . '</td>';
228         echo '<td class="t pages">' . $text . '</td>';
229
230         // Approved Comments
231         $num = number_format_i18n($num_comm->approved);
232         $text = __ngettext( 'Approved', 'Approved', $num_comm->approved );
233         if ( current_user_can( 'moderate_comments' ) ) {
234                 $num = "<a href='edit-comments.php?comment_status=approved'>$num</a>";
235                 $text = "<a class='approved' href='edit-comments.php?comment_status=approved'>$text</a>";
236         }
237         echo '<td class="b b_approved">' . $num . '</td>';
238         echo '<td class="last t">' . $text . '</td>';
239
240         echo "</tr>\n\t<tr>";
241
242         // Categories
243         $num = number_format_i18n( $num_cats );
244         $text = __ngettext( 'Category', 'Categories', $num_cats );
245         if ( current_user_can( 'manage_categories' ) ) {
246                 $num = "<a href='categories.php'>$num</a>";
247                 $text = "<a href='categories.php'>$text</a>";
248         }
249         echo '<td class="first b b-cats">' . $num . '</td>';
250         echo '<td class="t cats">' . $text . '</td>';
251
252         // Pending Comments
253         $num = number_format_i18n($num_comm->moderated);
254         $text = __ngettext( 'Pending', 'Pending', $num_comm->moderated );
255         if ( current_user_can( 'moderate_comments' ) ) {
256                 $num = "<a href='edit-comments.php?comment_status=moderated'><span class='pending-count'>$num</span></a>";
257                 $text = "<a class='waiting' href='edit-comments.php?comment_status=moderated'>$text</a>";
258         }
259         echo '<td class="b b-waiting">' . $num . '</td>';
260         echo '<td class="last t">' . $text . '</td>';
261
262         echo "</tr>\n\t<tr>";
263
264         // Tags
265         $num = number_format_i18n( $num_tags );
266         $text = __ngettext( 'Tag', 'Tags', $num_tags );
267         if ( current_user_can( 'manage_categories' ) ) {
268                 $num = "<a href='edit-tags.php'>$num</a>";
269                 $text = "<a href='edit-tags.php'>$text</a>";
270         }
271         echo '<td class="first b b-tags">' . $num . '</td>';
272         echo '<td class="t tags">' . $text . '</td>';
273
274         // Spam Comments
275         $num = number_format_i18n($num_comm->spam);
276         $text = __ngettext( 'Spam', 'Spam', $num_comm->spam );
277         if ( current_user_can( 'moderate_comments' ) ) {
278                 $num = "<a href='edit-comments.php?comment_status=spam'><span class='spam-count'>$num</span></a>";
279                 $text = "<a class='spam' href='edit-comments.php?comment_status=spam'>$text</a>";
280         }
281         echo '<td class="b b-spam">' . $num . '</td>';
282         echo '<td class="last t">' . $text . '</td>';
283
284         echo "</tr>";
285         do_action('right_now_table_end');
286         echo "\n\t</table>\n\t</div>";
287
288         echo "\n\t".'<div class="versions">';
289         $ct = current_theme_info();
290         $sidebars_widgets = wp_get_sidebars_widgets();
291         $num_widgets = array_reduce( $sidebars_widgets, create_function( '$prev, $curr', 'return $prev+count($curr);' ), 0 );
292         $num = number_format_i18n( $num_widgets );
293
294         echo "\n\t<p>";
295         if ( current_user_can( 'switch_themes' ) ) {
296                 echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
297                 printf(__ngettext('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);
298         } else {
299                 printf(__ngettext('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);
300         }
301
302         echo '</p>';
303
304         update_right_now_message();
305
306         echo "\n\t".'<br class="clear" /></div>';
307         do_action( 'rightnow_end' );
308         do_action( 'activity_box_end' );
309 }
310
311 function wp_dashboard_quick_press() {
312         $drafts = false;
313         if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
314                 $view = get_permalink( $_POST['post_ID'] );
315                 $edit = clean_url( get_edit_post_link( $_POST['post_ID'] ) );
316                 if ( 'post-quickpress-publish' == $_POST['action'] ) {
317                         if ( current_user_can('publish_posts') )
318                                 printf( '<div class="message"><p>' . __( 'Post Published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', clean_url( $view ), $edit );
319                         else
320                                 printf( '<div class="message"><p>' . __( 'Post submitted. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', clean_url( add_query_arg( 'preview', 1, $view ) ), $edit );
321                 } else {
322                         printf( '<div class="message"><p>' . __( 'Draft Saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', clean_url( add_query_arg( 'preview', 1, $view ) ), $edit );
323                         $drafts_query = new WP_Query( array(
324                                 'post_type' => 'post',
325                                 'what_to_show' => 'posts',
326                                 'post_status' => 'draft',
327                                 'author' => $GLOBALS['current_user']->ID,
328                                 'posts_per_page' => 1,
329                                 'orderby' => 'modified',
330                                 'order' => 'DESC'
331                         ) );
332
333                         if ( $drafts_query->posts )
334                                 $drafts =& $drafts_query->posts;
335                 }
336                 printf('<p class="textright">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="tools.php">' . __('Press This') . '</a>' );
337                 $_REQUEST = array(); // hack for get_default_post_to_edit()
338         }
339
340         $post = get_default_post_to_edit();
341 ?>
342
343         <form name="post" action="<?php echo clean_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
344                 <h4 id="quick-post-title"><label for="title"><?php _e('Title') ?></label></h4>
345                 <div class="input-text-wrap">
346                         <input type="text" name="post_title" id="title" tabindex="1" autocomplete="off" value="<?php echo attribute_escape( $post->post_title ); ?>" />
347                 </div>
348
349                 <?php if ( current_user_can( 'upload_files' ) ) : ?>
350                 <div id="media-buttons" class="hide-if-no-js">
351                         <?php do_action( 'media_buttons' ); ?>
352                 </div>
353                 <?php endif; ?>
354
355                 <h4 id="content-label"><label for="content"><?php _e('Content') ?></label></h4>
356                 <div class="textarea-wrap">
357                         <textarea name="content" id="content" class="mceEditor" rows="3" cols="15" tabindex="2"><?php echo $post->post_content; ?></textarea>
358                 </div>
359
360                 <script type="text/javascript">edCanvas = document.getElementById('content');edInsertContent = null;</script>
361
362                 <h4><label for="tags-input"><?php _e('Tags') ?></label></h4>
363                 <div class="input-text-wrap">
364                         <input type="text" name="tags_input" id="tags-input" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
365                 </div>
366
367                 <p class="submit">
368                         <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
369                         <input type="hidden" name="quickpress_post_ID" value="<?php echo (int) $post->ID; ?>" />
370                         <?php wp_nonce_field('add-post'); ?>
371                         <input type="submit" name="save" id="save-post" class="button" tabindex="4" value="<?php _e('Save Draft'); ?>" />
372                         <input type="reset" value="<?php _e( 'Cancel' ); ?>" class="cancel" />
373                         <?php if ( current_user_can('publish_posts') ) { ?>
374                         <input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="<?php _e('Publish'); ?>" />
375                         <?php } else { ?>
376                         <input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="<?php _e('Submit for Review'); ?>" />
377                         <?php } ?>
378                         <br class="clear" />
379                 </p>
380
381         </form>
382
383 <?php
384         if ( $drafts )
385                 wp_dashboard_recent_drafts( $drafts );
386 }
387
388 function wp_dashboard_recent_drafts( $drafts = false ) {
389         if ( !$drafts ) {
390                 $drafts_query = new WP_Query( array(
391                         'post_type' => 'post',
392                         'what_to_show' => 'posts',
393                         'post_status' => 'draft',
394                         'author' => $GLOBALS['current_user']->ID,
395                         'posts_per_page' => 5,
396                         'orderby' => 'modified',
397                         'order' => 'DESC'
398                 ) );
399                 $drafts =& $drafts_query->posts;
400         }
401
402         if ( $drafts && is_array( $drafts ) ) {
403                 $list = array();
404                 foreach ( $drafts as $draft ) {
405                         $url = get_edit_post_link( $draft->ID );
406                         $title = _draft_or_post_title( $draft->ID );
407                         $item = "<h4><a href='$url' title='" . sprintf( __( 'Edit "%s"' ), attribute_escape( $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>';
408                         if ( $the_content = preg_split( '#\s#', strip_tags( $draft->post_content ), 11, PREG_SPLIT_NO_EMPTY ) )
409                                 $item .= '<p>' . join( ' ', array_slice( $the_content, 0, 10 ) ) . ( 10 < count( $the_content ) ? '&hellip;' : '' ) . '</p>';
410                         $list[] = $item;
411                 }
412 ?>
413         <ul>
414                 <li><?php echo join( "</li>\n<li>", $list ); ?></li>
415         </ul>
416         <p class="textright"><a href="edit.php?post_status=draft" class="button"><?php _e('View all'); ?></a></p>
417 <?php
418         } else {
419                 _e('There are no drafts at the moment');
420         }
421 }
422
423 /**
424  * Display recent comments dashboard widget content.
425  *
426  * @since unknown
427  */
428 function wp_dashboard_recent_comments() {
429         global $wpdb;
430
431         if ( current_user_can('edit_posts') )
432                 $allowed_states = array('0', '1');
433         else
434                 $allowed_states = array('1');
435
436         // Select all comment types and filter out spam later for better query performance.
437         $comments = array();
438         $start = 0;
439
440         while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments ORDER BY comment_date_gmt DESC LIMIT $start, 50" ) ) {
441
442                 foreach ( $possible as $comment ) {
443                         if ( count( $comments ) >= 5 )
444                                 break;
445                         if ( in_array( $comment->comment_approved, $allowed_states ) )
446                                 $comments[] = $comment;
447                 }
448
449                 $start = $start + 50;
450         }
451
452         if ( $comments ) :
453 ?>
454
455                 <div id="the-comment-list" class="list:comment">
456 <?php
457                 foreach ( $comments as $comment )
458                         _wp_dashboard_recent_comments_row( $comment );
459 ?>
460
461                 </div>
462
463 <?php
464                 if ( current_user_can('edit_posts') ) { ?>
465                         <p class="textright"><a href="edit-comments.php" class="button"><?php _e('View all'); ?></a></p>
466 <?php   }
467
468                 wp_comment_reply( -1, false, 'dashboard', false );
469
470         else :
471 ?>
472
473         <p><?php _e( 'No comments yet.' ); ?></p>
474
475 <?php
476         endif; // $comments;
477 }
478
479 function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
480         $GLOBALS['comment'] =& $comment;
481
482         $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
483         $comment_post_title = get_the_title( $comment->comment_post_ID );
484         $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
485         $comment_link = '<a class="comment-link" href="' . get_comment_link() . '">#</a>';
486
487         $delete_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
488         $approve_url = clean_url( wp_nonce_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) );
489         $unapprove_url = clean_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) );
490         $spam_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
491
492         $actions = array();
493
494         $actions_string = '';
495         if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
496                 $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>';
497                 $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>';
498                 $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
499                 //$actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\',\'edit\');return false;" class="vim-q" title="'.__('Quick Edit').'" href="#">' . __('Quick&nbsp;Edit') . '</a>';
500                 $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>';
501                 $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' ) . "'>" . _c( 'Spam|verb' ) . '</a>';
502                 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';
503
504                 $actions = apply_filters( 'comment_row_actions', $actions, $comment );
505
506                 $i = 0;
507                 foreach ( $actions as $action => $link ) {
508                         ++$i;
509                         ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
510
511                         // Reply and quickedit need a hide-if-no-js span
512                         if ( 'reply' == $action || 'quickedit' == $action )
513                                 $action .= ' hide-if-no-js';
514
515                         $actions_string .= "<span class='$action'>$sep$link</span>";
516                 }
517         }
518
519 ?>
520
521                 <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
522                         <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
523
524                         <?php echo get_avatar( $comment, 50 ); ?>
525                         <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>
526
527                         <?php
528                         else :
529                                 switch ( $comment->comment_type ) :
530                                 case 'pingback' :
531                                         $type = __( 'Pingback' );
532                                         break;
533                                 case 'trackback' :
534                                         $type = __( 'Trackback' );
535                                         break;
536                                 default :
537                                         $type = ucwords( $comment->comment_type );
538                                 endswitch;
539                                 $type = wp_specialchars( $type );
540                         ?>
541
542                         <h4 class="comment-meta"><?php printf( __( '%1$s on %2$s' ), "<strong>$type</strong>", $comment_post_link ); ?></h4>
543                         <p class="comment-author"><?php comment_author_link(); ?></p>
544
545                         <?php endif; // comment_type ?>
546                         <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
547                         <p class="row-actions"><?php echo $actions_string; ?></p>
548
549                         <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
550                                 <textarea class="comment" rows="3" cols="10"><?php echo $comment->comment_content; ?></textarea>
551                                 <div class="author-email"><?php echo attribute_escape( $comment->comment_author_email ); ?></div>
552                                 <div class="author"><?php echo attribute_escape( $comment->comment_author ); ?></div>
553                                 <div class="author-url"><?php echo attribute_escape( $comment->comment_author_url ); ?></div>
554                                 <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
555                         </div>
556
557                 </div>
558 <?php
559 }
560
561 function wp_dashboard_incoming_links() {
562         wp_dashboard_cached_rss_widget( 'dashboard_incoming_links', 'wp_dashboard_incoming_links_output' );
563 }
564
565 /**
566  * Display incoming links dashboard widget content.
567  *
568  * @since unknown
569  */
570 function wp_dashboard_incoming_links_output() {
571         $widgets = get_option( 'dashboard_widget_options' );
572         @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
573         $rss = @fetch_rss( $url );
574         if ( isset($rss->items) && 0 < count($rss->items) )  {
575
576                 echo "<ul>\n";
577
578                 $rss->items = array_slice($rss->items, 0, $items);
579                 foreach ( $rss->items as $item ) {
580                         $publisher = '';
581                         $site_link = '';
582                         $link = '';
583                         $content = '';
584                         $date = '';
585                         $link = clean_url( strip_tags( $item['link'] ) );
586
587                         if ( isset( $item['author_uri'] ) )
588                                 $site_link = clean_url( strip_tags( $item['author_uri'] ) );
589
590                         if ( !$publisher = wp_specialchars( strip_tags( isset($item['dc']['publisher']) ? $item['dc']['publisher'] : $item['author_name'] ) ) )
591                                 $publisher = __( 'Somebody' );
592                         if ( $site_link )
593                                 $publisher = "<a href='$site_link'>$publisher</a>";
594                         else
595                                 $publisher = "<strong>$publisher</strong>";
596
597                         if ( isset($item['description']) )
598                                 $content = $item['description'];
599                         elseif ( isset($item['summary']) )
600                                 $content = $item['summary'];
601                         elseif ( isset($item['atom_content']) )
602                                 $content = $item['atom_content'];
603                         else
604                                 $content = __( 'something' );
605                         $content = wp_html_excerpt($content, 50) . ' ...';
606                         if ( $link )
607                                 $text = _c( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"|feed_display' );
608                         else
609                                 $text = _c( '%1$s linked here saying, "%3$s"|feed_display' );
610
611                         if ( $show_date ) {
612                                 if ( $show_author || $show_summary )
613                                         $text .= _c( ' on %4$s|feed_display' );
614                                 $date = wp_specialchars( strip_tags( isset($item['pubdate']) ? $item['pubdate'] : $item['published'] ) );
615                                 $date = strtotime( $date );
616                                 $date = gmdate( get_option( 'date_format' ), $date );
617                         }
618
619                         echo "\t<li>" . sprintf( _c( "$text|feed_display" ), $publisher, $link, $content, $date ) . "</li>\n";
620                 }
621
622                 echo "</ul>\n";
623
624         } else {
625                 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";
626         }
627 }
628
629 function wp_dashboard_incoming_links_control() {
630         wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) );
631 }
632
633 function wp_dashboard_primary() {
634         wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_rss_output' );
635 }
636
637 function wp_dashboard_primary_control() {
638         wp_dashboard_rss_control( 'dashboard_primary' );
639 }
640
641 /**
642  * {@internal Missing Short Description}}
643  *
644  * @since unknown
645  *
646  * @param int $widget_id
647  */
648 function wp_dashboard_rss_output( $widget_id ) {
649         $widgets = get_option( 'dashboard_widget_options' );
650         echo "<div class='rss-widget'>";
651         wp_widget_rss_output( $widgets[$widget_id] );
652         echo "</div>";
653 }
654
655 function wp_dashboard_secondary() {
656         wp_dashboard_cached_rss_widget( 'dashboard_secondary', 'wp_dashboard_secondary_output' );
657 }
658
659 function wp_dashboard_secondary_control() {
660         wp_dashboard_rss_control( 'dashboard_secondary' );
661 }
662
663 /**
664  * Display secondary dashboard RSS widget feed.
665  *
666  * @since unknown
667  *
668  * @return unknown
669  */
670 function wp_dashboard_secondary_output() {
671         $widgets = get_option( 'dashboard_widget_options' );
672         @extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
673         $rss = @fetch_rss( $url );
674
675         if ( !isset($rss->items) || 0 == count($rss->items) )
676                 return false;
677
678         $rss->items = array_slice($rss->items, 0, $items);
679
680         if ( 'http://planet.wordpress.org/' == $rss->channel['link'] ) {
681                 foreach ( array_keys($rss->items) as $i ) {
682                         list($site, $description) = explode( ':', wp_specialchars($rss->items[$i]['title']), 2 );
683                         $rss->items[$i]['dc']['creator'] = trim($site);
684                         $rss->items[$i]['title'] = trim($description);
685                 }
686         }
687
688         echo "<div class='rss-widget'>";
689         wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] );
690         echo "</div>";
691 }
692
693 function wp_dashboard_plugins() {
694         wp_dashboard_cached_rss_widget( 'dashboard_plugins', 'wp_dashboard_plugins_output', array(
695                 'http://wordpress.org/extend/plugins/rss/browse/popular/',
696                 'http://wordpress.org/extend/plugins/rss/browse/new/',
697                 'http://wordpress.org/extend/plugins/rss/browse/updated/'
698         ) );
699 }
700
701 /**
702  * Display plugins most popular, newest plugins, and recently updated widget text.
703  *
704  * @since unknown
705  */
706 function wp_dashboard_plugins_output() {
707         $popular = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/popular/' );
708         $new     = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
709         $updated = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
710
711         foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
712                 if ( !isset($$feed->items) || 0 == count($$feed->items) )
713                         continue;
714
715                 $$feed->items = array_slice($$feed->items, 0, 5);
716                 $item_key = array_rand($$feed->items);
717
718                 // Eliminate some common badly formed plugin descriptions
719                 while ( ( null !== $item_key = array_rand($$feed->items) ) && false !== strpos( $$feed->items[$item_key]['description'], 'Plugin Name:' ) )
720                         unset($$feed->items[$item_key]);
721
722                 if ( !isset($$feed->items[$item_key]) )
723                         continue;
724
725                 $item = $$feed->items[$item_key];
726
727                 // current bbPress feed item titles are: user on "topic title"
728                 if ( preg_match( '/"(.*)"/s', $item['title'], $matches ) )
729                         $title = $matches[1];
730                 else // but let's make it forward compatible if things change
731                         $title = $item['title'];
732                 $title = wp_specialchars( $title );
733
734                 $description = wp_specialchars( strip_tags(html_entity_decode($item['description'], ENT_QUOTES)) );
735
736                 list($link, $frag) = explode( '#', $item['link'] );
737
738                 $link = clean_url($link);
739                 if( preg_match('|/([^/]+?)/?$|', $link, $matches) )
740                         $slug = $matches[1];
741                 else
742                         $slug = '';
743
744                 $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
745                                                         '&amp;TB_iframe=true&amp;width=600&amp;height=800';
746
747                 echo "<h4>$label</h4>\n";
748                 echo "<h5><a href='$link'>$title</a></h5>&nbsp;<span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span>\n";
749                 echo "<p>$description</p>\n";
750         }
751 }
752
753 /**
754  * Checks to see if all of the feed url in $check_urls are cached.
755  *
756  * If $check_urls is empty, look for the rss feed url found in the dashboard
757  * widget optios of $widget_id. If cached, call $callback, a function that
758  * echoes out output for this widget. If not cache, echo a "Loading..." stub
759  * which is later replaced by AJAX call (see top of /wp-admin/index.php)
760  *
761  * @since unknown
762  *
763  * @param int $widget_id
764  * @param callback $callback
765  * @param array $check_urls RSS feeds
766  * @return bool False on failure. True on success.
767  */
768 function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
769         $loading = '<p class="widget-loading">' . __( 'Loading&#8230;' ) . '</p>';
770
771         if ( empty($check_urls) ) {
772                 $widgets = get_option( 'dashboard_widget_options' );
773                 if ( empty($widgets[$widget_id]['url']) ) {
774                         echo $loading;
775                         return false;
776                 }
777                 $check_urls = array( $widgets[$widget_id]['url'] );
778         }
779
780
781         require_once( ABSPATH . WPINC . '/rss.php' );
782         init(); // initialize rss constants
783
784         $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );
785
786         foreach ( $check_urls as $check_url ) {
787                 $status = $cache->check_cache( $check_url );
788                 if ( 'HIT' !== $status ) {
789                         echo $loading;
790                         return false;
791                 }
792         }
793
794         if ( $callback && is_callable( $callback ) ) {
795                 $args = array_slice( func_get_args(), 2 );
796                 array_unshift( $args, $widget_id );
797                 call_user_func_array( $callback, $args );
798         }
799
800         return true;
801 }
802
803 /* Dashboard Widgets Controls */
804
805 // Calls widget_control callback
806 /**
807  * Calls widget control callback.
808  *
809  * @since unknown
810  *
811  * @param int $widget_control_id Registered Widget ID.
812  */
813 function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
814         global $wp_dashboard_control_callbacks;
815
816         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]) ) {
817                 call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
818         }
819 }
820
821 /**
822  * The RSS dashboard widget control.
823  *
824  * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
825  * from RSS-type widgets.
826  *
827  * @since unknown
828  *
829  * @param string widget_id
830  * @param array form_inputs
831  */
832 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
833         if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
834                 $widget_options = array();
835
836         if ( !isset($widget_options[$widget_id]) )
837                 $widget_options[$widget_id] = array();
838
839         $number = 1; // Hack to use wp_widget_rss_form()
840         $widget_options[$widget_id]['number'] = $number;
841
842         if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
843                 $_POST['widget-rss'][$number] = stripslashes_deep( $_POST['widget-rss'][$number] );
844                 $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
845                 // title is optional.  If black, fill it if possible
846                 if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
847                         require_once(ABSPATH . WPINC . '/rss.php');
848                         $rss = fetch_rss($widget_options[$widget_id]['url']);
849                         $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->channel['title']));
850                 }
851                 update_option( 'dashboard_widget_options', $widget_options );
852         }
853
854         wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
855 }
856
857 /**
858  * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
859  */
860 function wp_dashboard_empty() {}
861
862 ?>