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