]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/template.php
010c057d16caaee5d2953ec8c159ee39a2a6ed8f
[autoinstalls/wordpress.git] / wp-admin / includes / template.php
1 <?php
2 /**
3  * Template WordPress Administration API.
4  *
5  * A Big Mess. Also some neat functions that are nicely written.
6  *
7  * @package WordPress
8  * @subpackage Administration
9  */
10
11
12 //
13 // Category Checklists
14 //
15
16 /**
17  * {@internal Missing Short Description}}
18  *
19  * @since 2.5.1
20  */
21 class Walker_Category_Checklist extends Walker {
22         var $tree_type = 'category';
23         var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
24
25         function start_lvl(&$output, $depth, $args) {
26                 $indent = str_repeat("\t", $depth);
27                 $output .= "$indent<ul class='children'>\n";
28         }
29
30         function end_lvl(&$output, $depth, $args) {
31                 $indent = str_repeat("\t", $depth);
32                 $output .= "$indent</ul>\n";
33         }
34
35         function start_el(&$output, $category, $depth, $args) {
36                 extract($args);
37                 if ( empty($taxonomy) )
38                         $taxonomy = 'category';
39
40                 if ( $taxonomy == 'category' )
41                         $name = 'post_category';
42                 else
43                         $name = 'tax_input['.$taxonomy.']';
44
45                 $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
46                 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
47         }
48
49         function end_el(&$output, $category, $depth, $args) {
50                 $output .= "</li>\n";
51         }
52 }
53
54 /**
55  * {@internal Missing Short Description}}
56  *
57  * @since 2.5.1
58  *
59  * @param unknown_type $post_id
60  * @param unknown_type $descendants_and_self
61  * @param unknown_type $selected_cats
62  * @param unknown_type $popular_cats
63  */
64 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
65         wp_terms_checklist($post_id,
66                 array(
67                         'taxonomy' => 'category',
68                         'descendants_and_self' => $descendants_and_self,
69                         'selected_cats' => $selected_cats,
70                         'popular_cats' => $popular_cats,
71                         'walker' => $walker,
72                         'checked_ontop' => $checked_ontop
73   ));
74 }
75
76 /**
77  * Taxonomy independent version of wp_category_checklist
78  *
79  * @since 3.0.0
80  *
81  * @param int $post_id
82  * @param array $args
83  */
84 function wp_terms_checklist($post_id = 0, $args = array()) {
85         $defaults = array(
86                 'descendants_and_self' => 0,
87                 'selected_cats' => false,
88                 'popular_cats' => false,
89                 'walker' => null,
90                 'taxonomy' => 'category',
91                 'checked_ontop' => true
92         );
93         extract( wp_parse_args($args, $defaults), EXTR_SKIP );
94
95         if ( empty($walker) || !is_a($walker, 'Walker') )
96                 $walker = new Walker_Category_Checklist;
97
98         $descendants_and_self = (int) $descendants_and_self;
99
100         $args = array('taxonomy' => $taxonomy);
101
102         $tax = get_taxonomy($taxonomy);
103         $args['disabled'] = !current_user_can($tax->cap->assign_terms);
104
105         if ( is_array( $selected_cats ) )
106                 $args['selected_cats'] = $selected_cats;
107         elseif ( $post_id )
108                 $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));
109         else
110                 $args['selected_cats'] = array();
111
112         if ( is_array( $popular_cats ) )
113                 $args['popular_cats'] = $popular_cats;
114         else
115                 $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
116
117         if ( $descendants_and_self ) {
118                 $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
119                 $self = get_term( $descendants_and_self, $taxonomy );
120                 array_unshift( $categories, $self );
121         } else {
122                 $categories = (array) get_terms($taxonomy, array('get' => 'all'));
123         }
124
125         if ( $checked_ontop ) {
126                 // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
127                 $checked_categories = array();
128                 $keys = array_keys( $categories );
129
130                 foreach( $keys as $k ) {
131                         if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
132                                 $checked_categories[] = $categories[$k];
133                                 unset( $categories[$k] );
134                         }
135                 }
136
137                 // Put checked cats on top
138                 echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
139         }
140         // Then the rest of them
141         echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
142 }
143
144 /**
145  * {@internal Missing Short Description}}
146  *
147  * @since 2.5.0
148  *
149  * @param unknown_type $taxonomy
150  * @param unknown_type $default
151  * @param unknown_type $number
152  * @param unknown_type $echo
153  * @return unknown
154  */
155 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
156         global $post_ID;
157
158         if ( $post_ID )
159                 $checked_terms = wp_get_object_terms($post_ID, $taxonomy, array('fields'=>'ids'));
160         else
161                 $checked_terms = array();
162
163         $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
164
165         $tax = get_taxonomy($taxonomy);
166         if ( ! current_user_can($tax->cap->assign_terms) )
167                 $disabled = 'disabled="disabled"';
168         else
169                 $disabled = '';
170
171         $popular_ids = array();
172         foreach ( (array) $terms as $term ) {
173                 $popular_ids[] = $term->term_id;
174                 if ( !$echo ) // hack for AJAX use
175                         continue;
176                 $id = "popular-$taxonomy-$term->term_id";
177                 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
178                 ?>
179
180                 <li id="<?php echo $id; ?>" class="popular-category">
181                         <label class="selectit">
182                         <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php echo $disabled ?>/>
183                                 <?php echo esc_html( apply_filters( 'the_category', $term->name ) ); ?>
184                         </label>
185                 </li>
186
187                 <?php
188         }
189         return $popular_ids;
190 }
191
192 /**
193  * {@internal Missing Short Description}}
194  *
195  * @since 2.5.1
196  *
197  * @param unknown_type $link_id
198  */
199 function wp_link_category_checklist( $link_id = 0 ) {
200         $default = 1;
201
202         if ( $link_id ) {
203                 $checked_categories = wp_get_link_cats( $link_id );
204                 // No selected categories, strange
205                 if ( ! count( $checked_categories ) )
206                         $checked_categories[] = $default;
207         } else {
208                 $checked_categories[] = $default;
209         }
210
211         $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
212
213         if ( empty( $categories ) )
214                 return;
215
216         foreach ( $categories as $category ) {
217                 $cat_id = $category->term_id;
218                 $name = esc_html( apply_filters( 'the_category', $category->name ) );
219                 $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
220                 echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>";
221         }
222 }
223
224 // adds hidden fields with the data for use in the inline editor for posts and pages
225 /**
226  * {@internal Missing Short Description}}
227  *
228  * @since 2.7.0
229  *
230  * @param unknown_type $post
231  */
232 function get_inline_data($post) {
233         $post_type_object = get_post_type_object($post->post_type);
234         if ( ! current_user_can($post_type_object->cap->edit_post, $post->ID) )
235                 return;
236
237         $title = esc_textarea( trim( $post->post_title ) );
238
239         echo '
240 <div class="hidden" id="inline_' . $post->ID . '">
241         <div class="post_title">' . $title . '</div>
242         <div class="post_name">' . apply_filters('editable_slug', $post->post_name) . '</div>
243         <div class="post_author">' . $post->post_author . '</div>
244         <div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
245         <div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
246         <div class="_status">' . esc_html( $post->post_status ) . '</div>
247         <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
248         <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
249         <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
250         <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
251         <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
252         <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
253         <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
254
255         if ( $post_type_object->hierarchical )
256                 echo '<div class="post_parent">' . $post->post_parent . '</div>';
257
258         if ( $post->post_type == 'page' )
259                 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
260
261         if ( $post_type_object->hierarchical )
262                 echo '<div class="menu_order">' . $post->menu_order . '</div>';
263
264         $taxonomy_names = get_object_taxonomies( $post->post_type );
265         foreach ( $taxonomy_names as $taxonomy_name) {
266                 $taxonomy = get_taxonomy( $taxonomy_name );
267
268                 if ( $taxonomy->hierarchical && $taxonomy->show_ui )
269                                 echo '<div class="post_category" id="'.$taxonomy_name.'_'.$post->ID.'">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array('fields'=>'ids')) ) . '</div>';
270                 elseif ( $taxonomy->show_ui )
271                         echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '</div>';
272         }
273
274         if ( !$post_type_object->hierarchical )
275                 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
276
277         if ( post_type_supports( $post->post_type, 'post-formats' ) )
278                 echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
279
280         echo '</div>';
281 }
282
283 /**
284  * {@internal Missing Short Description}}
285  *
286  * @since 2.7.0
287  *
288  * @param unknown_type $position
289  * @param unknown_type $checkbox
290  * @param unknown_type $mode
291  */
292 function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
293         // allow plugin to replace the popup content
294         $content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) );
295
296         if ( ! empty($content) ) {
297                 echo $content;
298                 return;
299         }
300
301         if ( $mode == 'single' ) {
302                 $wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
303         } else {
304                 $wp_list_table = _get_list_table('WP_Comments_List_Table');
305         }
306
307 ?>
308 <form method="get" action="">
309 <?php if ( $table_row ) : ?>
310 <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange">
311 <?php else : ?>
312 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
313 <?php endif; ?>
314         <div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div>
315
316         <div id="edithead" style="display:none;">
317                 <div class="inside">
318                 <label for="author"><?php _e('Name') ?></label>
319                 <input type="text" name="newcomment_author" size="50" value="" tabindex="101" id="author" />
320                 </div>
321
322                 <div class="inside">
323                 <label for="author-email"><?php _e('E-mail') ?></label>
324                 <input type="text" name="newcomment_author_email" size="50" value="" tabindex="102" id="author-email" />
325                 </div>
326
327                 <div class="inside">
328                 <label for="author-url"><?php _e('URL') ?></label>
329                 <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" tabindex="103" />
330                 </div>
331                 <div style="clear:both;"></div>
332         </div>
333
334         <div id="replycontainer">
335         <?php
336         $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close' );
337         wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );
338         ?>
339         </div>
340
341         <p id="replysubmit" class="submit">
342         <a href="#comments-form" class="cancel button-secondary alignleft" tabindex="106"><?php _e('Cancel'); ?></a>
343         <a href="#comments-form" class="save button-primary alignright" tabindex="104">
344         <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
345         <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
346         <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
347         <span class="error" style="display:none;"></span>
348         <br class="clear" />
349         </p>
350
351         <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" />
352         <input type="hidden" name="action" id="action" value="" />
353         <input type="hidden" name="comment_ID" id="comment_ID" value="" />
354         <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
355         <input type="hidden" name="status" id="status" value="" />
356         <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
357         <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
358         <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
359         <?php
360                 wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false );
361                 if ( current_user_can( 'unfiltered_html' ) )
362                         wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false );
363         ?>
364 <?php if ( $table_row ) : ?>
365 </td></tr></tbody></table>
366 <?php else : ?>
367 </div></div>
368 <?php endif; ?>
369 </form>
370 <?php
371 }
372
373 /**
374  * Output 'undo move to trash' text for comments
375  *
376  * @since 2.9.0
377  */
378 function wp_comment_trashnotice() {
379 ?>
380 <div class="hidden" id="trash-undo-holder">
381         <div class="trash-undo-inside"><?php printf(__('Comment by %s moved to the trash.'), '<strong></strong>'); ?> <span class="undo untrash"><a href="#"><?php _e('Undo'); ?></a></span></div>
382 </div>
383 <div class="hidden" id="spam-undo-holder">
384         <div class="spam-undo-inside"><?php printf(__('Comment by %s marked as spam.'), '<strong></strong>'); ?> <span class="undo unspam"><a href="#"><?php _e('Undo'); ?></a></span></div>
385 </div>
386 <?php
387 }
388
389 /**
390  * {@internal Missing Short Description}}
391  *
392  * @since 1.2.0
393  *
394  * @param unknown_type $meta
395  */
396 function list_meta( $meta ) {
397         // Exit if no meta
398         if ( ! $meta ) {
399                 echo '
400 <table id="list-table" style="display: none;">
401         <thead>
402         <tr>
403                 <th class="left">' . _x( 'Name', 'meta name' ) . '</th>
404                 <th>' . __( 'Value' ) . '</th>
405         </tr>
406         </thead>
407         <tbody id="the-list" class="list:meta">
408         <tr><td></td></tr>
409         </tbody>
410 </table>'; //TBODY needed for list-manipulation JS
411                 return;
412         }
413         $count = 0;
414 ?>
415 <table id="list-table">
416         <thead>
417         <tr>
418                 <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
419                 <th><?php _e( 'Value' ) ?></th>
420         </tr>
421         </thead>
422         <tbody id='the-list' class='list:meta'>
423 <?php
424         foreach ( $meta as $entry )
425                 echo _list_meta_row( $entry, $count );
426 ?>
427         </tbody>
428 </table>
429 <?php
430 }
431
432 /**
433  * {@internal Missing Short Description}}
434  *
435  * @since 2.5.0
436  *
437  * @param unknown_type $entry
438  * @param unknown_type $count
439  * @return unknown
440  */
441 function _list_meta_row( $entry, &$count ) {
442         static $update_nonce = false;
443
444         if ( is_protected_meta( $entry['meta_key'], 'post' ) )
445                 return;
446
447         if ( !$update_nonce )
448                 $update_nonce = wp_create_nonce( 'add-meta' );
449
450         $r = '';
451         ++ $count;
452         if ( $count % 2 )
453                 $style = 'alternate';
454         else
455                 $style = '';
456
457         if ( is_serialized( $entry['meta_value'] ) ) {
458                 if ( is_serialized_string( $entry['meta_value'] ) ) {
459                         // this is a serialized string, so we should display it
460                         $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
461                 } else {
462                         // this is a serialized array/object so we should NOT display it
463                         --$count;
464                         return;
465                 }
466         }
467
468         $entry['meta_key'] = esc_attr($entry['meta_key']);
469         $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
470         $entry['meta_id'] = (int) $entry['meta_id'];
471
472         $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
473
474         $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
475         $r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta[{$entry['meta_id']}][key]'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' />";
476
477         $r .= "\n\t\t<div class='submit'>";
478         $r .= get_submit_button( __( 'Delete' ), "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta", "deletemeta[{$entry['meta_id']}]", false, array( 'tabindex' => '6' ) );
479         $r .= "\n\t\t";
480         $r .= get_submit_button( __( 'Update' ), "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce updatemeta" , 'updatemeta', false, array( 'tabindex' => '6' ) );
481         $r .= "</div>";
482         $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
483         $r .= "</td>";
484
485         $r .= "\n\t\t<td><label class='screen-reader-text' for='meta[{$entry['meta_id']}][value]'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";
486         return $r;
487 }
488
489 /**
490  * {@internal Missing Short Description}}
491  *
492  * @since 1.2.0
493  */
494 function meta_form() {
495         global $wpdb;
496         $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
497         $keys = $wpdb->get_col( "
498                 SELECT meta_key
499                 FROM $wpdb->postmeta
500                 GROUP BY meta_key
501                 HAVING meta_key NOT LIKE '\_%'
502                 ORDER BY meta_key
503                 LIMIT $limit" );
504         if ( $keys )
505                 natcasesort($keys);
506 ?>
507 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
508 <table id="newmeta">
509 <thead>
510 <tr>
511 <th class="left"><label for="metakeyselect"><?php _ex( 'Name', 'meta name' ) ?></label></th>
512 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
513 </tr>
514 </thead>
515
516 <tbody>
517 <tr>
518 <td id="newmetaleft" class="left">
519 <?php if ( $keys ) { ?>
520 <select id="metakeyselect" name="metakeyselect" tabindex="7">
521 <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
522 <?php
523
524         foreach ( $keys as $key ) {
525                 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
526         }
527 ?>
528 </select>
529 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
530 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
531 <span id="enternew"><?php _e('Enter new'); ?></span>
532 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
533 <?php } else { ?>
534 <input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
535 <?php } ?>
536 </td>
537 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td>
538 </tr>
539
540 <tr><td colspan="2" class="submit">
541 <?php submit_button( __( 'Add Custom Field' ), 'add:the-list:newmeta', 'addmeta', false, array( 'id' => 'addmetasub', 'tabindex' => '9' ) ); ?>
542 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
543 </td></tr>
544 </tbody>
545 </table>
546 <?php
547
548 }
549
550 /**
551  * {@internal Missing Short Description}}
552  *
553  * @since 0.71
554  *
555  * @param unknown_type $edit
556  * @param unknown_type $for_post
557  * @param unknown_type $tab_index
558  * @param unknown_type $multi
559  */
560 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
561         global $wp_locale, $post, $comment;
562
563         if ( $for_post )
564                 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
565
566         $tab_index_attribute = '';
567         if ( (int) $tab_index > 0 )
568                 $tab_index_attribute = " tabindex=\"$tab_index\"";
569
570         // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
571
572         $time_adj = current_time('timestamp');
573         $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
574         $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
575         $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
576         $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
577         $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
578         $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
579         $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
580
581         $cur_jj = gmdate( 'd', $time_adj );
582         $cur_mm = gmdate( 'm', $time_adj );
583         $cur_aa = gmdate( 'Y', $time_adj );
584         $cur_hh = gmdate( 'H', $time_adj );
585         $cur_mn = gmdate( 'i', $time_adj );
586
587         $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
588         for ( $i = 1; $i < 13; $i = $i +1 ) {
589                 $monthnum = zeroise($i, 2);
590                 $month .= "\t\t\t" . '<option value="' . $monthnum . '"';
591                 if ( $i == $mm )
592                         $month .= ' selected="selected"';
593                 $month .= '>' . $monthnum . '-' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
594         }
595         $month .= '</select>';
596
597         $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
598         $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
599         $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
600         $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
601
602         echo '<div class="timestamp-wrap">';
603         /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
604         printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
605
606         echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
607
608         if ( $multi ) return;
609
610         echo "\n\n";
611         foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) {
612                 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
613                 $cur_timeunit = 'cur_' . $timeunit;
614                 echo '<input type="hidden" id="'. $cur_timeunit . '" name="'. $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
615         }
616 ?>
617
618 <p>
619 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
620 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
621 </p>
622 <?php
623 }
624
625 /**
626  * {@internal Missing Short Description}}
627  *
628  * @since 1.5.0
629  *
630  * @param unknown_type $default
631  */
632 function page_template_dropdown( $default = '' ) {
633         $templates = get_page_templates();
634         ksort( $templates );
635         foreach (array_keys( $templates ) as $template )
636                 : if ( $default == $templates[$template] )
637                         $selected = " selected='selected'";
638                 else
639                         $selected = '';
640         echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
641         endforeach;
642 }
643
644 /**
645  * {@internal Missing Short Description}}
646  *
647  * @since 1.5.0
648  *
649  * @param unknown_type $default
650  * @param unknown_type $parent
651  * @param unknown_type $level
652  * @return unknown
653  */
654 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
655         global $wpdb, $post_ID;
656         $items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );
657
658         if ( $items ) {
659                 foreach ( $items as $item ) {
660                         // A page cannot be its own parent.
661                         if (!empty ( $post_ID ) ) {
662                                 if ( $item->ID == $post_ID ) {
663                                         continue;
664                                 }
665                         }
666                         $pad = str_repeat( '&nbsp;', $level * 3 );
667                         if ( $item->ID == $default)
668                                 $current = ' selected="selected"';
669                         else
670                                 $current = '';
671
672                         echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";
673                         parent_dropdown( $default, $item->ID, $level +1 );
674                 }
675         } else {
676                 return false;
677         }
678 }
679
680 /**
681  * {@internal Missing Short Description}}
682  *
683  * @since 2.0.0
684  *
685  * @param unknown_type $id
686  * @return unknown
687  */
688 function the_attachment_links( $id = false ) {
689         $id = (int) $id;
690         $post = & get_post( $id );
691
692         if ( $post->post_type != 'attachment' )
693                 return false;
694
695         $icon = wp_get_attachment_image( $post->ID, 'thumbnail', true );
696         $attachment_data = wp_get_attachment_metadata( $id );
697         $thumb = isset( $attachment_data['thumb'] );
698 ?>
699 <form id="the-attachment-links">
700 <table>
701         <col />
702         <col class="widefat" />
703         <tr>
704                 <th scope="row"><?php _e( 'URL' ) ?></th>
705                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo esc_textarea( wp_get_attachment_url() ); ?></textarea></td>
706         </tr>
707 <?php if ( $icon ) : ?>
708         <tr>
709                 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
710                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td>
711         </tr>
712         <tr>
713                 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
714                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
715         </tr>
716 <?php else : ?>
717         <tr>
718                 <th scope="row"><?php _e( 'Link to file' ) ?></th>
719                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() ); ?></a></textarea></td>
720         </tr>
721         <tr>
722                 <th scope="row"><?php _e( 'Link to page' ) ?></th>
723                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
724         </tr>
725 <?php endif; ?>
726 </table>
727 </form>
728 <?php
729 }
730
731
732 /**
733  * Print out <option> html elements for role selectors
734  *
735  * @since 2.1.0
736  *
737  * @param string $selected slug for the role that should be already selected
738  */
739 function wp_dropdown_roles( $selected = false ) {
740         $p = '';
741         $r = '';
742
743         $editable_roles = get_editable_roles();
744
745         foreach ( $editable_roles as $role => $details ) {
746                 $name = translate_user_role($details['name'] );
747                 if ( $selected == $role ) // preselect specified role
748                         $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
749                 else
750                         $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
751         }
752         echo $p . $r;
753 }
754
755 /**
756  * {@internal Missing Short Description}}
757  *
758  * @since 2.3.0
759  *
760  * @param unknown_type $size
761  * @return unknown
762  */
763 function wp_convert_hr_to_bytes( $size ) {
764         $size = strtolower($size);
765         $bytes = (int) $size;
766         if ( strpos($size, 'k') !== false )
767                 $bytes = intval($size) * 1024;
768         elseif ( strpos($size, 'm') !== false )
769                 $bytes = intval($size) * 1024 * 1024;
770         elseif ( strpos($size, 'g') !== false )
771                 $bytes = intval($size) * 1024 * 1024 * 1024;
772         return $bytes;
773 }
774
775 /**
776  * {@internal Missing Short Description}}
777  *
778  * @since 2.3.0
779  *
780  * @param unknown_type $bytes
781  * @return unknown
782  */
783 function wp_convert_bytes_to_hr( $bytes ) {
784         $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
785         $log = log( $bytes, 1024 );
786         $power = (int) $log;
787         $size = pow(1024, $log - $power);
788         return $size . $units[$power];
789 }
790
791 /**
792  * {@internal Missing Short Description}}
793  *
794  * @since 2.5.0
795  *
796  * @return unknown
797  */
798 function wp_max_upload_size() {
799         $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
800         $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
801         $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
802         return $bytes;
803 }
804
805 /**
806  * Outputs the form used by the importers to accept the data to be imported
807  *
808  * @since 2.0.0
809  *
810  * @param string $action The action attribute for the form.
811  */
812 function wp_import_upload_form( $action ) {
813         $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
814         $size = wp_convert_bytes_to_hr( $bytes );
815         $upload_dir = wp_upload_dir();
816         if ( ! empty( $upload_dir['error'] ) ) :
817                 ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
818                 <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
819         else :
820 ?>
821 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
822 <p>
823 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
824 <input type="file" id="upload" name="import" size="25" />
825 <input type="hidden" name="action" value="save" />
826 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
827 </p>
828 <?php submit_button( __('Upload file and import'), 'button' ); ?>
829 </form>
830 <?php
831         endif;
832 }
833
834 /**
835  * Add a meta box to an edit form.
836  *
837  * @since 2.5.0
838  *
839  * @param string $id String for use in the 'id' attribute of tags.
840  * @param string $title Title of the meta box.
841  * @param string $callback Function that fills the box with the desired content. The function should echo its output.
842  * @param string|object $screen Optional. The screen on which to show the box (post, page, link). Defaults to current screen.
843  * @param string $context Optional. The context within the page where the boxes should show ('normal', 'advanced').
844  * @param string $priority Optional. The priority within the context where the boxes should show ('high', 'low').
845  */
846 function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
847         global $wp_meta_boxes;
848
849         if ( empty( $screen ) )
850                 $screen = get_current_screen();
851         elseif ( is_string( $screen ) )
852                 $screen = convert_to_screen( $screen );
853
854         $page = $screen->id;
855
856         if ( !isset($wp_meta_boxes) )
857                 $wp_meta_boxes = array();
858         if ( !isset($wp_meta_boxes[$page]) )
859                 $wp_meta_boxes[$page] = array();
860         if ( !isset($wp_meta_boxes[$page][$context]) )
861                 $wp_meta_boxes[$page][$context] = array();
862
863         foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
864                 foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
865                         if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
866                                 continue;
867
868                         // If a core box was previously added or removed by a plugin, don't add.
869                         if ( 'core' == $priority ) {
870                                 // If core box previously deleted, don't add
871                                 if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
872                                         return;
873                                 // If box was added with default priority, give it core priority to maintain sort order
874                                 if ( 'default' == $a_priority ) {
875                                         $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
876                                         unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
877                                 }
878                                 return;
879                         }
880                         // If no priority given and id already present, use existing priority
881                         if ( empty($priority) ) {
882                                 $priority = $a_priority;
883                         // else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority.
884                         } elseif ( 'sorted' == $priority ) {
885                                 $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
886                                 $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
887                                 $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
888                         }
889                         // An id can be in only one priority and one context
890                         if ( $priority != $a_priority || $context != $a_context )
891                                 unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
892                 }
893         }
894
895         if ( empty($priority) )
896                 $priority = 'low';
897
898         if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
899                 $wp_meta_boxes[$page][$context][$priority] = array();
900
901         $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
902 }
903
904 /**
905  * Meta-Box template function
906  *
907  * @since 2.5.0
908  *
909  * @param string|object $screen Screen identifier
910  * @param string $context box context
911  * @param mixed $object gets passed to the box callback function as first parameter
912  * @return int number of meta_boxes
913  */
914 function do_meta_boxes( $screen, $context, $object ) {
915         global $wp_meta_boxes;
916         static $already_sorted = false;
917
918         if ( empty( $screen ) )
919                 $screen = get_current_screen();
920         elseif ( is_string( $screen ) )
921                 $screen = convert_to_screen( $screen );
922
923         $page = $screen->id;
924
925         $hidden = get_hidden_meta_boxes( $screen );
926
927         printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
928
929         $i = 0;
930         do {
931                 // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
932                 if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
933                         foreach ( $sorted as $box_context => $ids ) {
934                                 foreach ( explode(',', $ids ) as $id ) {
935                                         if ( $id && 'dashboard_browser_nag' !== $id )
936                                                 add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
937                                 }
938                         }
939                 }
940                 $already_sorted = true;
941
942                 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
943                         break;
944
945                 foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
946                         if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
947                                 foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
948                                         if ( false == $box || ! $box['title'] )
949                                                 continue;
950                                         $i++;
951                                         $style = '';
952                                         $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
953                                         echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
954                                         if ( 'dashboard_browser_nag' != $box['id'] )
955                                                 echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>';
956                                         echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
957                                         echo '<div class="inside">' . "\n";
958                                         call_user_func($box['callback'], $object, $box);
959                                         echo "</div>\n";
960                                         echo "</div>\n";
961                                 }
962                         }
963                 }
964         } while(0);
965
966         echo "</div>";
967
968         return $i;
969
970 }
971
972 /**
973  * Remove a meta box from an edit form.
974  *
975  * @since 2.6.0
976  *
977  * @param string $id String for use in the 'id' attribute of tags.
978  * @param string|object $screen The screen on which to show the box (post, page, link).
979  * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
980  */
981 function remove_meta_box($id, $screen, $context) {
982         global $wp_meta_boxes;
983
984         if ( empty( $screen ) )
985                 $screen = get_current_screen();
986         elseif ( is_string( $screen ) )
987                 $screen = convert_to_screen( $screen );
988
989         $page = $screen->id;
990
991         if ( !isset($wp_meta_boxes) )
992                 $wp_meta_boxes = array();
993         if ( !isset($wp_meta_boxes[$page]) )
994                 $wp_meta_boxes[$page] = array();
995         if ( !isset($wp_meta_boxes[$page][$context]) )
996                 $wp_meta_boxes[$page][$context] = array();
997
998         foreach ( array('high', 'core', 'default', 'low') as $priority )
999                 $wp_meta_boxes[$page][$context][$priority][$id] = false;
1000 }
1001
1002 /**
1003  * Add a new section to a settings page.
1004  *
1005  * Part of the Settings API. Use this to define new settings sections for an admin page.
1006  * Show settings sections in your admin page callback function with do_settings_sections().
1007  * Add settings fields to your section with add_settings_field()
1008  *
1009  * The $callback argument should be the name of a function that echoes out any
1010  * content you want to show at the top of the settings section before the actual
1011  * fields. It can output nothing if you want.
1012  *
1013  * @since 2.7.0
1014  *
1015  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1016  *
1017  * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
1018  * @param string $title Formatted title of the section. Shown as the heading for the section.
1019  * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
1020  * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page();
1021  */
1022 function add_settings_section($id, $title, $callback, $page) {
1023         global $wp_settings_sections;
1024
1025         if ( 'misc' == $page ) {
1026                 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
1027                 $page = 'general';
1028         }
1029
1030         if ( !isset($wp_settings_sections) )
1031                 $wp_settings_sections = array();
1032         if ( !isset($wp_settings_sections[$page]) )
1033                 $wp_settings_sections[$page] = array();
1034         if ( !isset($wp_settings_sections[$page][$id]) )
1035                 $wp_settings_sections[$page][$id] = array();
1036
1037         $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
1038 }
1039
1040 /**
1041  * Add a new field to a section of a settings page
1042  *
1043  * Part of the Settings API. Use this to define a settings field that will show
1044  * as part of a settings section inside a settings page. The fields are shown using
1045  * do_settings_fields() in do_settings-sections()
1046  *
1047  * The $callback argument should be the name of a function that echoes out the
1048  * html input tags for this setting field. Use get_option() to retrieve existing
1049  * values to show.
1050  *
1051  * @since 2.7.0
1052  *
1053  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1054  *
1055  * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
1056  * @param string $title Formatted title of the field. Shown as the label for the field during output.
1057  * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
1058  * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
1059  * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...).
1060  * @param array $args Additional arguments
1061  */
1062 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
1063         global $wp_settings_fields;
1064
1065         if ( 'misc' == $page ) {
1066                 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
1067                 $page = 'general';
1068         }
1069
1070         if ( !isset($wp_settings_fields) )
1071                 $wp_settings_fields = array();
1072         if ( !isset($wp_settings_fields[$page]) )
1073                 $wp_settings_fields[$page] = array();
1074         if ( !isset($wp_settings_fields[$page][$section]) )
1075                 $wp_settings_fields[$page][$section] = array();
1076
1077         $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
1078 }
1079
1080 /**
1081  * Prints out all settings sections added to a particular settings page
1082  *
1083  * Part of the Settings API. Use this in a settings page callback function
1084  * to output all the sections and fields that were added to that $page with
1085  * add_settings_section() and add_settings_field()
1086  *
1087  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
1088  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
1089  * @since 2.7.0
1090  *
1091  * @param string $page The slug name of the page whos settings sections you want to output
1092  */
1093 function do_settings_sections($page) {
1094         global $wp_settings_sections, $wp_settings_fields;
1095
1096         if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
1097                 return;
1098
1099         foreach ( (array) $wp_settings_sections[$page] as $section ) {
1100                 if ( $section['title'] )
1101                         echo "<h3>{$section['title']}</h3>\n";
1102                 call_user_func($section['callback'], $section);
1103                 if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
1104                         continue;
1105                 echo '<table class="form-table">';
1106                 do_settings_fields($page, $section['id']);
1107                 echo '</table>';
1108         }
1109 }
1110
1111 /**
1112  * Print out the settings fields for a particular settings section
1113  *
1114  * Part of the Settings API. Use this in a settings page to output
1115  * a specific section. Should normally be called by do_settings_sections()
1116  * rather than directly.
1117  *
1118  * @global $wp_settings_fields Storage array of settings fields and their pages/sections
1119  *
1120  * @since 2.7.0
1121  *
1122  * @param string $page Slug title of the admin page who's settings fields you want to show.
1123  * @param section $section Slug title of the settings section who's fields you want to show.
1124  */
1125 function do_settings_fields($page, $section) {
1126         global $wp_settings_fields;
1127
1128         if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
1129                 return;
1130
1131         foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
1132                 echo '<tr valign="top">';
1133                 if ( !empty($field['args']['label_for']) )
1134                         echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
1135                 else
1136                         echo '<th scope="row">' . $field['title'] . '</th>';
1137                 echo '<td>';
1138                 call_user_func($field['callback'], $field['args']);
1139                 echo '</td>';
1140                 echo '</tr>';
1141         }
1142 }
1143
1144 /**
1145  * Register a settings error to be displayed to the user
1146  *
1147  * Part of the Settings API. Use this to show messages to users about settings validation
1148  * problems, missing settings or anything else.
1149  *
1150  * Settings errors should be added inside the $sanitize_callback function defined in
1151  * register_setting() for a given setting to give feedback about the submission.
1152  *
1153  * By default messages will show immediately after the submission that generated the error.
1154  * Additional calls to settings_errors() can be used to show errors even when the settings
1155  * page is first accessed.
1156  *
1157  * @since 3.0.0
1158  *
1159  * @global array $wp_settings_errors Storage array of errors registered during this pageload
1160  *
1161  * @param string $setting Slug title of the setting to which this error applies
1162  * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
1163  * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>)
1164  * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
1165  */
1166 function add_settings_error( $setting, $code, $message, $type = 'error' ) {
1167         global $wp_settings_errors;
1168
1169         if ( !isset($wp_settings_errors) )
1170                 $wp_settings_errors = array();
1171
1172         $new_error = array(
1173                 'setting' => $setting,
1174                 'code' => $code,
1175                 'message' => $message,
1176                 'type' => $type
1177         );
1178         $wp_settings_errors[] = $new_error;
1179 }
1180
1181 /**
1182  * Fetch settings errors registered by add_settings_error()
1183  *
1184  * Checks the $wp_settings_errors array for any errors declared during the current
1185  * pageload and returns them.
1186  *
1187  * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
1188  * to the 'settings_errors' transient then those errors will be returned instead. This
1189  * is used to pass errors back across pageloads.
1190  *
1191  * Use the $sanitize argument to manually re-sanitize the option before returning errors.
1192  * This is useful if you have errors or notices you want to show even when the user
1193  * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
1194  *
1195  * @since 3.0.0
1196  *
1197  * @global array $wp_settings_errors Storage array of errors registered during this pageload
1198  *
1199  * @param string $setting Optional slug title of a specific setting who's errors you want.
1200  * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1201  * @return array Array of settings errors
1202  */
1203 function get_settings_errors( $setting = '', $sanitize = FALSE ) {
1204         global $wp_settings_errors;
1205
1206         // If $sanitize is true, manually re-run the sanitizisation for this option
1207         // This allows the $sanitize_callback from register_setting() to run, adding
1208         // any settings errors you want to show by default.
1209         if ( $sanitize )
1210                 sanitize_option( $setting, get_option($setting));
1211
1212         // If settings were passed back from options.php then use them
1213         // Ignore transients if $sanitize is true, we don't want the old values anyway
1214         if ( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('settings_errors') ) {
1215                 $settings_errors = get_transient('settings_errors');
1216                 delete_transient('settings_errors');
1217         // Otherwise check global in case validation has been run on this pageload
1218         } elseif ( count( $wp_settings_errors ) ) {
1219                 $settings_errors = $wp_settings_errors;
1220         } else {
1221                 return;
1222         }
1223
1224         // Filter the results to those of a specific setting if one was set
1225         if ( $setting ) {
1226                 foreach ( (array) $settings_errors as $key => $details )
1227                         if ( $setting != $details['setting'] )
1228                                 unset( $settings_errors[$key] );
1229         }
1230         return $settings_errors;
1231 }
1232
1233 /**
1234  * Display settings errors registered by add_settings_error()
1235  *
1236  * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
1237  *
1238  * This is called automatically after a settings page based on the Settings API is submitted.
1239  * Errors should be added during the validation callback function for a setting defined in register_setting()
1240  *
1241  * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
1242  * on its current value.
1243  *
1244  * The $hide_on_update option will cause errors to only show when the settings page is first loaded.
1245  * if the user has already saved new values it will be hidden to avoid repeating messages already
1246  * shown in the default error reporting after submission. This is useful to show general errors like missing
1247  * settings when the user arrives at the settings page.
1248  *
1249  * @since 3.0.0
1250  *
1251  * @param string $setting Optional slug title of a specific setting who's errors you want.
1252  * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
1253  * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
1254  */
1255 function settings_errors( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
1256
1257         if ($hide_on_update AND $_GET['settings-updated']) return;
1258
1259         $settings_errors = get_settings_errors( $setting, $sanitize );
1260
1261         if ( !is_array($settings_errors) ) return;
1262
1263         $output = '';
1264         foreach ( $settings_errors as $key => $details ) {
1265                 $css_id = 'setting-error-' . $details['code'];
1266                 $css_class = $details['type'] . ' settings-error';
1267                 $output .= "<div id='$css_id' class='$css_class'> \n";
1268                 $output .= "<p><strong>{$details['message']}</strong></p>";
1269                 $output .= "</div> \n";
1270         }
1271         echo $output;
1272 }
1273
1274 /**
1275  * {@internal Missing Short Description}}
1276  *
1277  * @since 2.7.0
1278  *
1279  * @param unknown_type $found_action
1280  */
1281 function find_posts_div($found_action = '') {
1282 ?>
1283         <div id="find-posts" class="find-box" style="display:none;">
1284                 <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
1285                 <div class="find-box-inside">
1286                         <div class="find-box-search">
1287                                 <?php if ( $found_action ) { ?>
1288                                         <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
1289                                 <?php } ?>
1290
1291                                 <input type="hidden" name="affected" id="affected" value="" />
1292                                 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
1293                                 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
1294                                 <input type="text" id="find-posts-input" name="ps" value="" />
1295                                 <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
1296
1297                                 <?php
1298                                 $post_types = get_post_types( array('public' => true), 'objects' );
1299                                 foreach ( $post_types as $post ) {
1300                                         if ( 'attachment' == $post->name )
1301                                                 continue;
1302                                 ?>
1303                                 <input type="radio" name="find-posts-what" id="find-posts-<?php echo esc_attr($post->name); ?>" value="<?php echo esc_attr($post->name); ?>" <?php checked($post->name,  'post'); ?> />
1304                                 <label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label>
1305                                 <?php
1306                                 } ?>
1307                         </div>
1308                         <div id="find-posts-response"></div>
1309                 </div>
1310                 <div class="find-box-buttons">
1311                         <input id="find-posts-close" type="button" class="button alignleft" value="<?php esc_attr_e('Close'); ?>" />
1312                         <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?>
1313                 </div>
1314         </div>
1315 <?php
1316 }
1317
1318 /**
1319  * Display the post password.
1320  *
1321  * The password is passed through {@link esc_attr()} to ensure that it
1322  * is safe for placing in an html attribute.
1323  *
1324  * @uses attr
1325  * @since 2.7.0
1326  */
1327 function the_post_password() {
1328         global $post;
1329         if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
1330 }
1331
1332 /**
1333  * Get the post title.
1334  *
1335  * The post title is fetched and if it is blank then a default string is
1336  * returned.
1337  *
1338  * @since 2.7.0
1339  * @param int $post_id The post id. If not supplied the global $post is used.
1340  * @return string The post title if set
1341  */
1342 function _draft_or_post_title( $post_id = 0 ) {
1343         $title = get_the_title($post_id);
1344         if ( empty($title) )
1345                 $title = __('(no title)');
1346         return $title;
1347 }
1348
1349 /**
1350  * Display the search query.
1351  *
1352  * A simple wrapper to display the "s" parameter in a GET URI. This function
1353  * should only be used when {@link the_search_query()} cannot.
1354  *
1355  * @uses attr
1356  * @since 2.7.0
1357  *
1358  */
1359 function _admin_search_query() {
1360         echo isset($_REQUEST['s']) ? esc_attr( stripslashes( $_REQUEST['s'] ) ) : '';
1361 }
1362
1363 /**
1364  * Generic Iframe header for use with Thickbox
1365  *
1366  * @since 2.7.0
1367  * @param string $title Title of the Iframe page.
1368  * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
1369  *
1370  */
1371 function iframe_header( $title = '', $limit_styles = false ) {
1372         show_admin_bar( false );
1373         global $hook_suffix, $current_user, $admin_body_class, $wp_locale;
1374         $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
1375
1376         $current_screen = get_current_screen();
1377
1378         _wp_admin_html_begin();
1379 ?>
1380 <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
1381 <?php
1382 wp_enqueue_style( 'colors' );
1383 ?>
1384 <script type="text/javascript">
1385 //<![CDATA[
1386 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
1387 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
1388 var userSettings = {
1389                 'url': '<?php echo SITECOOKIEPATH; ?>',
1390                 'uid': '<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>',
1391                 'time':'<?php echo time() ?>'
1392         },
1393         ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>',
1394         pagenow = '<?php echo $current_screen->id; ?>',
1395         typenow = '<?php echo $current_screen->post_type; ?>',
1396         adminpage = '<?php echo $admin_body_class; ?>',
1397         thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
1398         decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
1399         isRtl = <?php echo (int) is_rtl(); ?>;
1400 //]]>
1401 </script>
1402 <?php
1403 do_action('admin_enqueue_scripts', $hook_suffix);
1404 do_action("admin_print_styles-$hook_suffix");
1405 do_action('admin_print_styles');
1406 do_action("admin_print_scripts-$hook_suffix");
1407 do_action('admin_print_scripts');
1408 do_action("admin_head-$hook_suffix");
1409 do_action('admin_head');
1410 ?>
1411 </head>
1412 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>  class="wp-admin no-js iframe <?php echo apply_filters( 'admin_body_class', '' ) . ' ' . $admin_body_class; ?>">
1413 <script type="text/javascript">
1414 //<![CDATA[
1415 (function(){
1416 var c = document.body.className;
1417 c = c.replace(/no-js/, 'js');
1418 document.body.className = c;
1419 })();
1420 //]]>
1421 </script>
1422 <?php
1423 }
1424
1425 /**
1426  * Generic Iframe footer for use with Thickbox
1427  *
1428  * @since 2.7.0
1429  *
1430  */
1431 function iframe_footer() {
1432         //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?>
1433         <div class="hidden">
1434 <?php
1435         do_action('admin_footer', '');
1436         do_action('admin_print_footer_scripts'); ?>
1437         </div>
1438 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
1439 </body>
1440 </html>
1441 <?php
1442 }
1443
1444 function _post_states($post) {
1445         $post_states = array();
1446         if ( isset( $_REQUEST['post_status'] ) )
1447                 $post_status = $_REQUEST['post_status'];
1448         else
1449                 $post_status = '';
1450
1451         if ( !empty($post->post_password) )
1452                 $post_states['protected'] = __('Password protected');
1453         if ( 'private' == $post->post_status && 'private' != $post_status )
1454                 $post_states['private'] = __('Private');
1455         if ( 'draft' == $post->post_status && 'draft' != $post_status )
1456                 $post_states['draft'] = __('Draft');
1457         if ( 'pending' == $post->post_status && 'pending' != $post_status )
1458                 /* translators: post state */
1459                 $post_states['pending'] = _x('Pending', 'post state');
1460         if ( is_sticky($post->ID) )
1461                 $post_states['sticky'] = __('Sticky');
1462
1463         $post_states = apply_filters( 'display_post_states', $post_states );
1464
1465         if ( ! empty($post_states) ) {
1466                 $state_count = count($post_states);
1467                 $i = 0;
1468                 echo ' - ';
1469                 foreach ( $post_states as $state ) {
1470                         ++$i;
1471                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1472                         echo "<span class='post-state'>$state$sep</span>";
1473                 }
1474         }
1475
1476         if ( get_post_format( $post->ID ) )
1477                 echo ' - <span class="post-state-format">' . get_post_format_string( get_post_format( $post->ID ) ) . '</span>';
1478 }
1479
1480 function _media_states( $post ) {
1481         $media_states = array();
1482         $stylesheet = get_option('stylesheet');
1483
1484         if ( current_theme_supports( 'custom-header') ) {
1485                 $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
1486                 if ( ! empty( $meta_header ) && $meta_header == $stylesheet )
1487                         $media_states[] = __( 'Header Image' );
1488         }
1489
1490         if ( current_theme_supports( 'custom-background') ) {
1491                 $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
1492                 if ( ! empty( $meta_background ) && $meta_background == $stylesheet )
1493                         $media_states[] = __( 'Background Image' );
1494         }
1495
1496         $media_states = apply_filters( 'display_media_states', $media_states );
1497
1498         if ( ! empty( $media_states ) ) {
1499                 $state_count = count( $media_states );
1500                 $i = 0;
1501                 echo ' - ';
1502                 foreach ( $media_states as $state ) {
1503                         ++$i;
1504                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
1505                         echo "<span class='post-state'>$state$sep</span>";
1506                 }
1507         }
1508 }
1509
1510 /**
1511  * Test support for compressing JavaScript from PHP
1512  *
1513  * Outputs JavaScript that tests if compression from PHP works as expected
1514  * and sets an option with the result. Has no effect when the current user
1515  * is not an administrator. To run the test again the option 'can_compress_scripts'
1516  * has to be deleted.
1517  *
1518  * @since 2.8.0
1519  */
1520 function compression_test() {
1521 ?>
1522         <script type="text/javascript">
1523         /* <![CDATA[ */
1524         var testCompression = {
1525                 get : function(test) {
1526                         var x;
1527                         if ( window.XMLHttpRequest ) {
1528                                 x = new XMLHttpRequest();
1529                         } else {
1530                                 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
1531                         }
1532
1533                         if (x) {
1534                                 x.onreadystatechange = function() {
1535                                         var r, h;
1536                                         if ( x.readyState == 4 ) {
1537                                                 r = x.responseText.substr(0, 18);
1538                                                 h = x.getResponseHeader('Content-Encoding');
1539                                                 testCompression.check(r, h, test);
1540                                         }
1541                                 }
1542
1543                                 x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
1544                                 x.send('');
1545                         }
1546                 },
1547
1548                 check : function(r, h, test) {
1549                         if ( ! r && ! test )
1550                                 this.get(1);
1551
1552                         if ( 1 == test ) {
1553                                 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
1554                                         this.get('no');
1555                                 else
1556                                         this.get(2);
1557
1558                                 return;
1559                         }
1560
1561                         if ( 2 == test ) {
1562                                 if ( '"wpCompressionTest' == r )
1563                                         this.get('yes');
1564                                 else
1565                                         this.get('no');
1566                         }
1567                 }
1568         };
1569         testCompression.check();
1570         /* ]]> */
1571         </script>
1572 <?php
1573 }
1574
1575 /**
1576  * Echos a submit button, with provided text and appropriate class
1577  *
1578  * @since 3.1.0
1579  *
1580  * @param string $text The text of the button (defaults to 'Save Changes')
1581  * @param string $type The type of button. One of: primary, secondary, delete
1582  * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
1583  *               is given in $other_attributes below, $name will be used as the button's id.
1584  * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1585  *                         false otherwise. Defaults to true
1586  * @param array|string $other_attributes Other attributes that should be output with the button,
1587  *                     mapping attributes to their values, such as array( 'tabindex' => '1' ).
1588  *                     These attributes will be output as attribute="value", such as tabindex="1".
1589  *                     Defaults to no other attributes. Other attributes can also be provided as a
1590  *                     string such as 'tabindex="1"', though the array format is typically cleaner.
1591  */
1592 function submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
1593         echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
1594 }
1595
1596 /**
1597  * Returns a submit button, with provided text and appropriate class
1598  *
1599  * @since 3.1.0
1600  *
1601  * @param string $text The text of the button (defaults to 'Save Changes')
1602  * @param string $type The type of button. One of: primary, secondary, delete
1603  * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute
1604  *               is given in $other_attributes below, $name will be used as the button's id.
1605  * @param bool $wrap True if the output button should be wrapped in a paragraph tag,
1606  *                         false otherwise. Defaults to true
1607  * @param array|string $other_attributes Other attributes that should be output with the button,
1608  *                     mapping attributes to their values, such as array( 'tabindex' => '1' ).
1609  *                     These attributes will be output as attribute="value", such as tabindex="1".
1610  *                     Defaults to no other attributes. Other attributes can also be provided as a
1611  *                     string such as 'tabindex="1"', though the array format is typically cleaner.
1612  */
1613 function get_submit_button( $text = NULL, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL ) {
1614         switch ( $type ) :
1615                 case 'primary' :
1616                 case 'secondary' :
1617                         $class = 'button-' . $type;
1618                         break;
1619                 case 'delete' :
1620                         $class = 'button-secondary delete';
1621                         break;
1622                 default :
1623                         $class = $type; // Custom cases can just pass in the classes they want to be used
1624         endswitch;
1625         $text = ( NULL == $text ) ? __( 'Save Changes' ) : $text;
1626
1627         // Default the id attribute to $name unless an id was specifically provided in $other_attributes
1628         $id = $name;
1629         if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
1630                 $id = $other_attributes['id'];
1631                 unset( $other_attributes['id'] );
1632         }
1633
1634         $attributes = '';
1635         if ( is_array( $other_attributes ) ) {
1636                 foreach ( $other_attributes as $attribute => $value ) {
1637                         $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
1638                 }
1639         } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
1640                 $attributes = $other_attributes;
1641         }
1642
1643         $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
1644         $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
1645
1646         if ( $wrap ) {
1647                 $button = '<p class="submit">' . $button . '</p>';
1648         }
1649
1650         return $button;
1651 }
1652
1653 function _wp_admin_html_begin() {
1654 ?>
1655 <!DOCTYPE html>
1656 <!--[if IE 8]>
1657 <html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
1658 <![endif]-->
1659 <!--[if !(IE 8) ]><!-->
1660 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
1661 <!--<![endif]-->
1662 <head>
1663 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
1664 <?php
1665 }
1666
1667 final class WP_Internal_Pointers {
1668         /**
1669          * Initializes the new feature pointers.
1670          *
1671          * @since 3.3.0
1672          *
1673          * All pointers can be disabled using the following:
1674          *     remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
1675          *
1676          * Individual pointers (e.g. wp330_toolbar) can be disabled using the following:
1677          *     remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp330_toolbar' ) );
1678          */
1679         public static function enqueue_scripts( $hook_suffix ) {
1680                 /*
1681                  * Register feature pointers
1682                  * Format: array( hook_suffix => pointer_id )
1683                  */
1684
1685                 $registered_pointers = array(
1686                         'index.php'    => 'wp330_toolbar',
1687                         'post-new.php' => 'wp330_media_uploader',
1688                         'post.php'     => 'wp330_media_uploader',
1689                         'themes.php'   => 'wp330_saving_widgets',
1690                 );
1691
1692                 // Check if screen related pointer is registered
1693                 if ( empty( $registered_pointers[ $hook_suffix ] ) )
1694                         return;
1695
1696                 $pointer = $registered_pointers[ $hook_suffix ];
1697
1698                 $caps_required = array(
1699                         'wp330_media_uploader' => array( 'upload_files' ),
1700                         'wp330_saving_widgets' => array( 'edit_theme_options', 'switch_themes' ),
1701                 );
1702
1703                 if ( isset( $caps_required[ $pointer ] ) ) {
1704                         foreach ( $caps_required[ $pointer ] as $cap ) {
1705                                 if ( ! current_user_can( $cap ) )
1706                                         return;
1707                         }
1708                 }
1709
1710                 // Get dismissed pointers
1711                 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
1712
1713                 // Pointer has been dismissed
1714                 if ( in_array( $pointer, $dismissed ) )
1715                         return;
1716
1717                 // Bind pointer print function
1718                 add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
1719
1720                 // Add pointers script and style to queue
1721                 wp_enqueue_style( 'wp-pointer' );
1722                 wp_enqueue_script( 'wp-pointer' );
1723         }
1724
1725         /**
1726          * Print the pointer javascript data.
1727          *
1728          * @since 3.3.0
1729          *
1730          * @param string $pointer_id The pointer ID.
1731          * @param string $selector The HTML elements, on which the pointer should be attached.
1732          * @param array  $args Arguments to be passed to the pointer JS (see wp-pointer.dev.js).
1733          */
1734         private static function print_js( $pointer_id, $selector, $args ) {
1735                 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
1736                         return;
1737
1738                 ?>
1739                 <script type="text/javascript">
1740                 //<![CDATA[
1741                 jQuery(document).ready( function($) {
1742                         var options = <?php echo json_encode( $args ); ?>;
1743
1744                         if ( ! options )
1745                                 return;
1746
1747                         options = $.extend( options, {
1748                                 close: function() {
1749                                         $.post( ajaxurl, {
1750                                                 pointer: '<?php echo $pointer_id; ?>',
1751                                                 action: 'dismiss-wp-pointer'
1752                                         });
1753                                 }
1754                         });
1755
1756                         $('<?php echo $selector; ?>').pointer( options ).pointer('open');
1757                 });
1758                 //]]>
1759                 </script>
1760                 <?php
1761         }
1762
1763         public static function pointer_wp330_toolbar() {
1764                 $content  = '<h3>' . esc_js( __( 'New Feature: Toolbar' ) ). '</h3>';
1765                 $content .= '<p>' . esc_js( __( 'We&#8217;ve combined the admin bar and the old Dashboard header into one persistent toolbar. Hover over the toolbar items to see what&#8217;s new.' ) ) . '</p>';
1766
1767                 if ( is_multisite() && is_super_admin() )
1768                         $content .= '<p>' .esc_js( __( 'Network Admin is now located in the My Sites menu.' ) ) . '</p>';
1769
1770                 WP_Internal_Pointers::print_js( 'wp330_toolbar', '#wpadminbar', array(
1771                         'content'  => $content,
1772                         'position' => array( 'edge' => 'top', 'align' => 'center' ),
1773                 ) );
1774         }
1775
1776         /**
1777          * Print 'Updated Media Uploader' for 3.3.0.
1778          *
1779          * @since 3.3.0
1780          */
1781         public static function pointer_wp330_media_uploader() {
1782                 $content  = '<h3>' . esc_js( __( 'Updated Media Uploader' ) ) . '</h3>';
1783                 $content .= '<p>' . esc_js( __( 'The single media icon now launches the uploader for all file types, and the new drag and drop interface makes uploading a breeze.' ) ) . '</p>';
1784
1785                 WP_Internal_Pointers::print_js( 'wp330_media_uploader', '#content-add_media', array(
1786                         'content'  => $content,
1787                         'position' => array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' ),
1788                 ) );
1789         }
1790
1791         /**
1792          * Print 'New Feature: Saving Widgets' for 3.3.0.
1793          *
1794          * @since 3.3.0
1795          */
1796         public static function pointer_wp330_saving_widgets() {
1797                 $content  = '<h3>' . esc_js( __( 'New Feature: Saving Widgets' ) ) . '</h3>';
1798                 $content .= '<p>' . esc_js( __( 'If you change your mind and revert to your previous theme, we&#8217;ll put the widgets back the way you had them.' ) ) . '</p>';
1799
1800                 WP_Internal_Pointers::print_js( 'wp330_saving_widgets', '#message2', array(
1801                         'content'  => $content,
1802                         'position' => array( 'edge' => 'top', 'align' => is_rtl() ? 'right' : 'left' ),
1803                 ) );
1804         }
1805
1806         /**
1807          * Prevents new users from seeing existing 'new feature' pointers.
1808          *
1809          * @since 3.3.0
1810          */
1811         public static function dismiss_pointers_for_new_users( $user_id ) {
1812                 add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp330_toolbar,wp330_media_uploader,wp330_saving_widgets' );
1813         }
1814 }
1815
1816 add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts'                ) );
1817 add_action( 'user_register',         array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) );
1818
1819 /**
1820  * Convert a screen string to a screen object
1821  *
1822  * @since 3.0.0
1823  *
1824  * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
1825  * @return WP_Screen Screen object.
1826  */
1827 function convert_to_screen( $hook_name ) {
1828         if ( ! class_exists( 'WP_Screen' ) ) {
1829                 _doing_it_wrong( 'convert_to_screen(), add_meta_box()', __( "Likely direct inclusion of wp-admin/includes/template.php in order to use add_meta_box(). This is very wrong. Hook the add_meta_box() call into the add_meta_boxes action instead." ), '3.3' );
1830                 return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' );
1831         }
1832
1833         return WP_Screen::get( $hook_name );
1834 }