]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/template.php
e3981f221c3d3411de9df2a06ede35e9bf6e3c0d
[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  * {@internal Missing Short Description}}
13  *
14  * @since 2.7
15  *
16  * Outputs the HTML for the hidden table rows used in Categories, Link Categories and Tags quick edit.
17  *
18  * @param string $type "edit-tags", "categoried" or "edit-link-categories"
19  * @param string $taxonomy The taxonomy of the row.
20  * @return
21  */
22 function inline_edit_term_row($type, $taxonomy) {
23
24         $tax = get_taxonomy($taxonomy);
25         if ( ! current_user_can( $tax->cap->edit_terms ) )
26                 return;
27
28         $columns = get_column_headers($type);
29         $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($type) ) );
30         $col_count = count($columns) - count($hidden);
31         ?>
32
33 <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
34         <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $col_count; ?>">
35
36                 <fieldset><div class="inline-edit-col">
37                         <h4><?php _e( 'Quick Edit' ); ?></h4>
38
39                         <label>
40                                 <span class="title"><?php _e( 'Name' ); ?></span>
41                                 <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
42                         </label>
43 <?php if ( !is_multisite() ) { ?>
44                         <label>
45                                 <span class="title"><?php _e( 'Slug' ); ?></span>
46                                 <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
47                         </label>
48 <?php } ?>
49
50                 </div></fieldset>
51
52 <?php
53
54         $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
55
56         foreach ( $columns as $column_name => $column_display_name ) {
57                 if ( isset( $core_columns[$column_name] ) )
58                         continue;
59                 do_action( 'quick_edit_custom_box', $column_name, $type, $taxonomy );
60         }
61
62 ?>
63
64         <p class="inline-edit-save submit">
65                 <a accesskey="c" href="#inline-edit" title="<?php _e('Cancel'); ?>" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
66                 <?php $update_text = $tax->labels->update_item; ?>
67                 <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a>
68                 <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
69                 <span class="error" style="display:none;"></span>
70                 <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
71                 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" />
72                 <br class="clear" />
73         </p>
74         </td></tr>
75         </tbody></table></form>
76 <?php
77 }
78
79 /**
80  * {@internal Missing Short Description}}
81  *
82  * @since unknown
83  *
84  * @param unknown_type $category
85  * @param unknown_type $name_override
86  * @return unknown
87  */
88 function link_cat_row( $category, $name_override = false ) {
89         static $row_class = '';
90
91         if ( !$category = get_term( $category, 'link_category', OBJECT, 'display' ) )
92                 return false;
93         if ( is_wp_error( $category ) )
94                 return $category;
95
96         $default_cat_id = (int) get_option( 'default_link_category' );
97         $name = ( $name_override ? $name_override : $category->name );
98         $edit_link = "link-category.php?action=edit&amp;cat_ID=$category->term_id";
99         if ( current_user_can( 'manage_categories' ) ) {
100                 $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $category->name)) . "'>$name</a><br />";
101                 $actions = array();
102                 $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
103                 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
104                 if ( $default_cat_id != $category->term_id )
105                         $actions['delete'] = "<a class='delete:the-list:link-cat-$category->term_id submitdelete' href='" . wp_nonce_url("link-category.php?action=delete&amp;cat_ID=$category->term_id", 'delete-link-category_' . $category->term_id) . "'>" . __('Delete') . "</a>";
106                 $actions = apply_filters('link_cat_row_actions', $actions, $category);
107                 $action_count = count($actions);
108                 $i = 0;
109                 $edit .= '<div class="row-actions">';
110                 foreach ( $actions as $action => $link ) {
111                         ++$i;
112                         ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
113                         $edit .= "<span class='$action'>$link$sep</span>";
114                 }
115                 $edit .= '</div>';
116         } else {
117                 $edit = $name;
118         }
119
120         $row_class = 'alternate' == $row_class ? '' : 'alternate';
121         $qe_data = get_term_to_edit($category->term_id, 'link_category');
122
123         $category->count = number_format_i18n( $category->count );
124         $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
125         $output = "<tr id='link-cat-$category->term_id' class='iedit $row_class'>";
126         $columns = get_column_headers('edit-link-categories');
127         $hidden = get_hidden_columns('edit-link-categories');
128         foreach ( $columns as $column_name => $column_display_name ) {
129                 $class = "class=\"$column_name column-$column_name\"";
130
131                 $style = '';
132                 if ( in_array($column_name, $hidden) )
133                         $style = ' style="display:none;"';
134
135                 $attributes = "$class$style";
136
137                 switch ($column_name) {
138                         case 'cb':
139                                 $output .= "<th scope='row' class='check-column'>";
140                                 if ( absint( get_option( 'default_link_category' ) ) != $category->term_id ) {
141                                         $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' />";
142                                 } else {
143                                         $output .= "&nbsp;";
144                                 }
145                                 $output .= "</th>";
146                                 break;
147                         case 'name':
148                                 $output .= "<td $attributes>$edit";
149                                 $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
150                                 $output .= '<div class="name">' . $qe_data->name . '</div>';
151                                 $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>';
152                                 $output .= '<div class="cat_parent">' . $qe_data->parent . '</div></div></td>';
153                                 break;
154                         case 'description':
155                                 $output .= "<td $attributes>$category->description</td>";
156                                 break;
157                         case 'slug':
158                                 $output .= "<td $attributes>" . apply_filters('editable_slug', $category->slug) . "</td>";
159                                 break;
160                         case 'links':
161                                 $attributes = 'class="links column-links num"' . $style;
162                                 $output .= "<td $attributes>$count</td>";
163                                 break;
164                         default:
165                                 $output .= "<td $attributes>";
166                                 $output .= apply_filters('manage_link_categories_custom_column', '', $column_name, $category->term_id);
167                                 $output .= "</td>";
168                 }
169         }
170         $output .= '</tr>';
171
172         return $output;
173 }
174
175 //
176 // Category Checklists
177 //
178
179 /**
180  * {@internal Missing Short Description}}
181  *
182  * @since unknown
183  */
184 class Walker_Category_Checklist extends Walker {
185         var $tree_type = 'category';
186         var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
187
188         function start_lvl(&$output, $depth, $args) {
189                 $indent = str_repeat("\t", $depth);
190                 $output .= "$indent<ul class='children'>\n";
191         }
192
193         function end_lvl(&$output, $depth, $args) {
194                 $indent = str_repeat("\t", $depth);
195                 $output .= "$indent</ul>\n";
196         }
197
198         function start_el(&$output, $category, $depth, $args) {
199                 extract($args);
200                 if ( empty($taxonomy) )
201                         $taxonomy = 'category';
202
203                 if ( $taxonomy == 'category' )
204                         $name = 'post_category';
205                 else
206                         $name = 'tax_input['.$taxonomy.']';
207
208                 $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
209                 $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>';
210         }
211
212         function end_el(&$output, $category, $depth, $args) {
213                 $output .= "</li>\n";
214         }
215 }
216
217 /**
218  * {@internal Missing Short Description}}
219  *
220  * @since unknown
221  *
222  * @param unknown_type $post_id
223  * @param unknown_type $descendants_and_self
224  * @param unknown_type $selected_cats
225  * @param unknown_type $popular_cats
226  */
227 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
228         wp_terms_checklist($post_id,
229                 array(
230                         'taxonomy' => 'category',
231                         'descendants_and_self' => $descendants_and_self,
232                         'selected_cats' => $selected_cats,
233                         'popular_cats' => $popular_cats,
234                         'walker' => $walker,
235                         'checked_ontop' => $checked_ontop
236   ));
237 }
238
239 /**
240  * Taxonomy independent version of wp_category_checklist
241  *
242  * @param int $post_id
243  * @param array $args
244  */
245 function wp_terms_checklist($post_id = 0, $args = array()) {
246         $defaults = array(
247                 'descendants_and_self' => 0,
248                 'selected_cats' => false,
249                 'popular_cats' => false,
250                 'walker' => null,
251                 'taxonomy' => 'category',
252                 'checked_ontop' => true
253         );
254         extract( wp_parse_args($args, $defaults), EXTR_SKIP );
255
256         if ( empty($walker) || !is_a($walker, 'Walker') )
257                 $walker = new Walker_Category_Checklist;
258
259         $descendants_and_self = (int) $descendants_and_self;
260
261         $args = array('taxonomy' => $taxonomy);
262
263         $tax = get_taxonomy($taxonomy);
264         $args['disabled'] = !current_user_can($tax->cap->assign_terms);
265
266         if ( is_array( $selected_cats ) )
267                 $args['selected_cats'] = $selected_cats;
268         elseif ( $post_id )
269                 $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));
270         else
271                 $args['selected_cats'] = array();
272
273         if ( is_array( $popular_cats ) )
274                 $args['popular_cats'] = $popular_cats;
275         else
276                 $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
277
278         if ( $descendants_and_self ) {
279                 $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
280                 $self = get_term( $descendants_and_self, $taxonomy );
281                 array_unshift( $categories, $self );
282         } else {
283                 $categories = (array) get_terms($taxonomy, array('get' => 'all'));
284         }
285
286         if ( $checked_ontop ) {
287                 // 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)
288                 $checked_categories = array();
289                 $keys = array_keys( $categories );
290
291                 foreach( $keys as $k ) {
292                         if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
293                                 $checked_categories[] = $categories[$k];
294                                 unset( $categories[$k] );
295                         }
296                 }
297
298                 // Put checked cats on top
299                 echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
300         }
301         // Then the rest of them
302         echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
303 }
304
305 /**
306  * {@internal Missing Short Description}}
307  *
308  * @since unknown
309  *
310  * @param unknown_type $taxonomy
311  * @param unknown_type $default
312  * @param unknown_type $number
313  * @param unknown_type $echo
314  * @return unknown
315  */
316 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
317         global $post_ID;
318
319         if ( $post_ID )
320                 $checked_terms = wp_get_object_terms($post_ID, $taxonomy, array('fields'=>'ids'));
321         else
322                 $checked_terms = array();
323
324         $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
325
326         $tax = get_taxonomy($taxonomy);
327         if ( ! current_user_can($tax->cap->assign_terms) )
328                 $disabled = 'disabled="disabled"';
329         else
330                 $disabled = '';
331
332         $popular_ids = array();
333         foreach ( (array) $terms as $term ) {
334                 $popular_ids[] = $term->term_id;
335                 if ( !$echo ) // hack for AJAX use
336                         continue;
337                 $id = "popular-$taxonomy-$term->term_id";
338                 $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
339                 ?>
340
341                 <li id="<?php echo $id; ?>" class="popular-category">
342                         <label class="selectit">
343                         <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php echo $disabled ?>/>
344                                 <?php echo esc_html( apply_filters( 'the_category', $term->name ) ); ?>
345                         </label>
346                 </li>
347
348                 <?php
349         }
350         return $popular_ids;
351 }
352
353 /**
354  * {@internal Missing Short Description}}
355  *
356  * @since unknown
357  *
358  * @param unknown_type $link_id
359  */
360 function wp_link_category_checklist( $link_id = 0 ) {
361         $default = 1;
362
363         if ( $link_id ) {
364                 $checked_categories = wp_get_link_cats( $link_id );
365                 // No selected categories, strange
366                 if ( ! count( $checked_categories ) )
367                         $checked_categories[] = $default;
368         } else {
369                 $checked_categories[] = $default;
370         }
371
372         $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
373
374         if ( empty( $categories ) )
375                 return;
376
377         foreach ( $categories as $category ) {
378                 $cat_id = $category->term_id;
379                 $name = esc_html( apply_filters( 'the_category', $category->name ) );
380                 $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
381                 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>";
382         }
383 }
384
385 // Tag stuff
386
387 // Returns a single tag row (see tag_rows below)
388 // Note: this is also used in admin-ajax.php!
389 /**
390  * {@internal Missing Short Description}}
391  *
392  * @since unknown
393  *
394  * @param unknown_type $tag
395  * @param unknown_type $class
396  * @return unknown
397  */
398 function _tag_row( $tag, $level, $taxonomy = 'post_tag' ) {
399                 global $post_type, $current_screen;
400                 static $row_class = '';
401                 $row_class = ($row_class == '' ? ' class="alternate"' : '');
402
403                 $count = number_format_i18n( $tag->count );
404                 $tax = get_taxonomy($taxonomy);
405
406                 if ( 'post_tag' == $taxonomy ) {
407                         $tagsel = 'tag';
408                 } elseif ( 'category' == $taxonomy ) {
409                         $tagsel = 'category_name';
410                 } elseif ( ! empty($tax->query_var) ) {
411                         $tagsel = $tax->query_var;
412                 } else {
413                         $tagsel = $taxonomy;
414                 }
415
416                 $pad = str_repeat( '&#8212; ', max(0, $level) );
417                 $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag );
418                 $qe_data = get_term($tag->term_id, $taxonomy, object, 'edit');
419                 $edit_link = "edit-tags.php?action=edit&amp;taxonomy=$taxonomy&amp;post_type=$post_type&amp;tag_ID=$tag->term_id";
420
421                 $out = '';
422                 $out .= '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>';
423
424
425                 $columns = get_column_headers($current_screen);
426                 $hidden = get_hidden_columns($current_screen);
427                 $default_term = get_option('default_' . $taxonomy);
428                 foreach ( $columns as $column_name => $column_display_name ) {
429                         $class = "class=\"$column_name column-$column_name\"";
430
431                         $style = '';
432                         if ( in_array($column_name, $hidden) )
433                                 $style = ' style="display:none;"';
434
435                         $attributes = "$class$style";
436
437                         switch ($column_name) {
438                                 case 'cb':
439                                         if ( current_user_can($tax->cap->delete_terms) && $tag->term_id != $default_term )
440                                                 $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
441                                         else
442                                                 $out .= '<th scope="row" class="check-column">&nbsp;</th>';
443                                         break;
444                                 case 'name':
445                                         $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $name)) . '">' . $name . '</a></strong><br />';
446                                         $actions = array();
447                                         if ( current_user_can($tax->cap->edit_terms) ) {
448                                                 $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
449                                                 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
450                                         }
451                                         if ( current_user_can($tax->cap->delete_terms) && $tag->term_id != $default_term )
452                                                 $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url("edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id) . "'>" . __('Delete') . "</a>";
453
454                                         $actions = apply_filters('tag_row_actions', $actions, $tag);
455                                         $actions = apply_filters("${taxonomy}_row_actions", $actions, $tag);
456
457                                         $action_count = count($actions);
458                                         $i = 0;
459                                         $out .= '<div class="row-actions">';
460                                         foreach ( $actions as $action => $link ) {
461                                                 ++$i;
462                                                 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
463                                                 $out .= "<span class='$action'>$link$sep</span>";
464                                         }
465                                         $out .= '</div>';
466                                         $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
467                                         $out .= '<div class="name">' . $qe_data->name . '</div>';
468                                         $out .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>';
469                                         $out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>';
470                                         break;
471                                 case 'description':
472                                         $out .= "<td $attributes>$tag->description</td>";
473                                         break;
474                                 case 'slug':
475                                         $out .= "<td $attributes>" . apply_filters('editable_slug', $tag->slug) . "</td>";
476                                         break;
477                                 case 'posts':
478                                         $attributes = 'class="posts column-posts num"' . $style;
479                                         $out .= "<td $attributes><a href='edit.php?$tagsel=$tag->slug&amp;post_type=$post_type'>$count</a></td>";
480                                         break;
481                                 default:
482                                         $out .= "<td $attributes>";
483                                         $out .= apply_filters("manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id);
484                                         $out .= "</td>";
485                         }
486                 }
487
488                 $out .= "</tr>\n";
489
490                 return $out;
491 }
492
493 // Outputs appropriate rows for the Nth page of the Tag Management screen,
494 // assuming M tags displayed at a time on the page
495 // Returns the number of tags displayed
496 /**
497  * {@internal Missing Short Description}}
498  *
499  * @since unknown
500  *
501  * @param unknown_type $page
502  * @param unknown_type $pagesize
503  * @param unknown_type $searchterms
504  * @return unknown
505  */
506 function tag_rows( $page = 1, $pagesize = 20, $searchterms = '', $taxonomy = 'post_tag' ) {
507
508         // Get a page worth of tags
509         $start = ($page - 1) * $pagesize;
510
511         $args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0);
512
513         if ( !empty( $searchterms ) )
514                 $args['search'] = $searchterms;
515
516         // convert it to table rows
517         $out = '';
518         $count = 0;
519         if ( is_taxonomy_hierarchical($taxonomy) ) {
520                 // We'll need the full set of terms then.
521                 $args['number'] = $args['offset'] = 0;
522
523                 $terms = get_terms( $taxonomy, $args );
524                 if ( !empty( $searchterms ) ) // Ignore children on searches.
525                         $children = array();
526                 else
527                         $children = _get_term_hierarchy($taxonomy);
528
529                 // Some funky recursion to get the job done(Paging & parents mainly) is contained within, Skip it for non-hierarchical taxonomies for performance sake
530                 $out .= _term_rows($taxonomy, $terms, $children, $page, $pagesize, $count);
531         } else {
532                 $terms = get_terms( $taxonomy, $args );
533                 foreach( $terms as $term )
534                         $out .= _tag_row( $term, 0, $taxonomy );
535                 $count = $pagesize; // Only displaying a single page.
536         }
537
538         echo $out;
539         return $count;
540 }
541
542 function _term_rows( $taxonomy, $terms, &$children, $page = 1, $per_page = 20, &$count, $parent = 0, $level = 0 ) {
543
544         $start = ($page - 1) * $per_page;
545         $end = $start + $per_page;
546
547         $output = '';
548         foreach ( $terms as $key => $term ) {
549
550                 if ( $count >= $end )
551                         break;
552
553                 if ( $term->parent != $parent && empty($_GET['s']) )
554                         continue;
555
556                 // If the page starts in a subtree, print the parents.
557                 if ( $count == $start && $term->parent > 0 && empty($_GET['s']) ) {
558                         $my_parents = $parent_ids = array();
559                         $p = $term->parent;
560                         while ( $p ) {
561                                 $my_parent = get_term( $p, $taxonomy );
562                                 $my_parents[] = $my_parent;
563                                 $p = $my_parent->parent;
564                                 if ( in_array($p, $parent_ids) ) // Prevent parent loops.
565                                         break;
566                                 $parent_ids[] = $p;
567                         }
568                         unset($parent_ids);
569
570                         $num_parents = count($my_parents);
571                         while ( $my_parent = array_pop($my_parents) ) {
572                                 $output .=  "\t" . _tag_row( $my_parent, $level - $num_parents, $taxonomy );
573                                 $num_parents--;
574                         }
575                 }
576
577                 if ( $count >= $start )
578                         $output .= "\t" . _tag_row( $term, $level, $taxonomy );
579
580                 ++$count;
581
582                 unset($terms[$key]);
583
584                 if ( isset($children[$term->term_id]) && empty($_GET['s']) )
585                         $output .= _term_rows( $taxonomy, $terms, $children, $page, $per_page, $count, $term->term_id, $level + 1 );
586         }
587
588         return $output;
589 }
590
591 // define the columns to display, the syntax is 'internal name' => 'display name'
592 /**
593  * {@internal Missing Short Description}}
594  *
595  * @since unknown
596  *
597  * @return unknown
598  */
599 function wp_manage_posts_columns( $screen = '') {
600         if ( empty($screen) )
601                 $post_type = 'post';
602         else
603                 $post_type = $screen->post_type;
604
605         $posts_columns = array();
606         $posts_columns['cb'] = '<input type="checkbox" />';
607         /* translators: manage posts column name */
608         $posts_columns['title'] = _x('Title', 'column name');
609         $posts_columns['author'] = __('Author');
610         if ( empty($post_type) || is_object_in_taxonomy($post_type, 'category') )
611                 $posts_columns['categories'] = __('Categories');
612         if ( empty($post_type) || is_object_in_taxonomy($post_type, 'post_tag') )
613                 $posts_columns['tags'] = __('Tags');
614         $post_status = !empty($_REQUEST['post_status']) ? $_REQUEST['post_status'] : 'all';
615         if ( !in_array( $post_status, array('pending', 'draft', 'future') ) && ( empty($post_type) || post_type_supports($post_type, 'comments') ) )
616                 $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>';
617         $posts_columns['date'] = __('Date');
618
619         if ( 'page' == $post_type )
620                 $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
621         else
622                 $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
623         $posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
624
625         return $posts_columns;
626 }
627
628 // define the columns to display, the syntax is 'internal name' => 'display name'
629 /**
630  * {@internal Missing Short Description}}
631  *
632  * @since unknown
633  *
634  * @return unknown
635  */
636 function wp_manage_media_columns() {
637         $posts_columns = array();
638         $posts_columns['cb'] = '<input type="checkbox" />';
639         $posts_columns['icon'] = '';
640         /* translators: column name */
641         $posts_columns['media'] = _x('File', 'column name');
642         $posts_columns['author'] = __('Author');
643         //$posts_columns['tags'] = _x('Tags', 'column name');
644         /* translators: column name */
645         $posts_columns['parent'] = _x('Attached to', 'column name');
646         $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>';
647         //$posts_columns['comments'] = __('Comments');
648         /* translators: column name */
649         $posts_columns['date'] = _x('Date', 'column name');
650         $posts_columns = apply_filters('manage_media_columns', $posts_columns);
651
652         return $posts_columns;
653 }
654
655 /**
656  * {@internal Missing Short Description}}
657  *
658  * @since unknown
659  *
660  * @return unknown
661  */
662 function wp_manage_pages_columns() {
663         return wp_manage_posts_columns();
664 }
665
666 /**
667  * Get the column headers for a screen
668  *
669  * @since unknown
670  *
671  * @param string|object $screen The screen you want the headers for
672  * @return array Containing the headers in the format id => UI String
673  */
674 function get_column_headers($screen) {
675         global $_wp_column_headers;
676
677         if ( !isset($_wp_column_headers) )
678                 $_wp_column_headers = array();
679
680         if ( is_string($screen) )
681                 $screen = convert_to_screen($screen);
682
683         // Store in static to avoid running filters on each call
684         if ( isset($_wp_column_headers[$screen->id]) )
685                 return $_wp_column_headers[$screen->id];
686
687         switch ($screen->base) {
688                 case 'edit':
689                          $_wp_column_headers[$screen->id] = wp_manage_posts_columns( $screen );
690                          break;
691                 case 'edit-comments':
692                         $_wp_column_headers[$screen->id] = array(
693                                 'cb' => '<input type="checkbox" />',
694                                 'author' => __('Author'),
695                                 /* translators: column name */
696                                 'comment' => _x('Comment', 'column name'),
697                                 //'date' => __('Submitted'),
698                                 'response' => __('In Response To')
699                         );
700
701                         break;
702                 case 'link-manager':
703                         $_wp_column_headers[$screen->id] = array(
704                                 'cb' => '<input type="checkbox" />',
705                                 'name' => __('Name'),
706                                 'url' => __('URL'),
707                                 'categories' => __('Categories'),
708                                 'rel' => __('Relationship'),
709                                 'visible' => __('Visible'),
710                                 'rating' => __('Rating')
711                         );
712
713                         break;
714                 case 'upload':
715                         $_wp_column_headers[$screen->id] = wp_manage_media_columns();
716                         break;
717                 case 'categories':
718                         $_wp_column_headers[$screen->id] = array(
719                                 'cb' => '<input type="checkbox" />',
720                                 'name' => __('Name'),
721                                 'description' => __('Description'),
722                                 'slug' => __('Slug'),
723                                 'posts' => __('Posts')
724                         );
725
726                         break;
727                 case 'edit-link-categories':
728                         $_wp_column_headers[$screen->id] = array(
729                                 'cb' => '<input type="checkbox" />',
730                                 'name' => __('Name'),
731                                 'description' => __('Description'),
732                                 'slug' => __('Slug'),
733                                 'links' => __('Links')
734                         );
735
736                         break;
737                 case 'edit-tags':
738                         $_wp_column_headers[$screen->id] = array(
739                                 'cb' => '<input type="checkbox" />',
740                                 'name' => __('Name'),
741                                 'description' => __('Description'),
742                                 'slug' => __('Slug'),
743                                 'posts' => __('Posts')
744                         );
745
746                         break;
747                 case 'users':
748                         $_wp_column_headers[$screen->id] = array(
749                                 'cb' => '<input type="checkbox" />',
750                                 'username' => __('Username'),
751                                 'name' => __('Name'),
752                                 'email' => __('E-mail'),
753                                 'role' => __('Role'),
754                                 'posts' => __('Posts')
755                         );
756                         break;
757                 default :
758                         $_wp_column_headers[$screen->id] = array();
759         }
760
761         $_wp_column_headers[$screen->id] = apply_filters('manage_' . $screen->id . '_columns', $_wp_column_headers[$screen->id]);
762         return $_wp_column_headers[$screen->id];
763 }
764
765 /**
766  * {@internal Missing Short Description}}
767  *
768  * @since unknown
769  *
770  * @param unknown_type $screen
771  * @param unknown_type $id
772  */
773 function print_column_headers( $screen, $id = true ) {
774         if ( is_string($screen) )
775                 $screen = convert_to_screen($screen);
776
777         $columns = get_column_headers( $screen );
778         $hidden = get_hidden_columns($screen);
779         $styles = array();
780
781         foreach ( $columns as $column_key => $column_display_name ) {
782                 $class = ' class="manage-column';
783
784                 $class .= " column-$column_key";
785
786                 if ( 'cb' == $column_key )
787                         $class .= ' check-column';
788                 elseif ( in_array($column_key, array('posts', 'comments', 'links')) )
789                         $class .= ' num';
790
791                 $class .= '"';
792
793                 $style = '';
794                 if ( in_array($column_key, $hidden) )
795                         $style = 'display:none;';
796
797                 if ( isset($styles[$screen->id]) && isset($styles[$screen->id][$column_key]) )
798                         $style .= ' ' . $styles[$screen>id][$column_key];
799                 $style = ' style="' . $style . '"';
800 ?>
801         <th scope="col" <?php echo $id ? "id=\"$column_key\"" : ""; echo $class; echo $style; ?>><?php echo $column_display_name; ?></th>
802 <?php }
803 }
804
805 /**
806  * Register column headers for a particular screen.  The header names will be listed in the Screen Options.
807  *
808  * @since 2.7.0
809  *
810  * @param string $screen The handle for the screen to add help to.  This is usually the hook name returned by the add_*_page() functions.
811  * @param array $columns An array of columns with column IDs as the keys and translated column names as the values
812  * @see get_column_headers(), print_column_headers(), get_hidden_columns()
813  */
814 function register_column_headers($screen, $columns) {
815         global $_wp_column_headers;
816
817         if ( is_string($screen) )
818                 $screen = convert_to_screen($screen);
819
820         if ( !isset($_wp_column_headers) )
821                 $_wp_column_headers = array();
822
823         $_wp_column_headers[$screen->id] = $columns;
824 }
825
826 /**
827  * {@internal Missing Short Description}}
828  *
829  * @since unknown
830  *
831  * @param unknown_type $screen
832  */
833 function get_hidden_columns($screen) {
834         if ( is_string($screen) )
835                 $screen = convert_to_screen($screen);
836
837         return (array) get_user_option( 'manage' . $screen->id. 'columnshidden' );
838 }
839
840 /**
841  * {@internal Missing Short Description}}
842  *
843  * Outputs the quick edit and bulk edit table rows for posts and pages
844  *
845  * @since 2.7
846  *
847  * @param string $screen
848  */
849 function inline_edit_row( $screen ) {
850         global $current_user, $mode;
851
852         if ( is_string($screen) ) {
853                 $screen = array('id' => 'edit-' . $screen, 'base' => 'edit', 'post_type' => $screen );
854                 $screen = (object) $screen;
855         }
856
857         $post = get_default_post_to_edit( $screen->post_type );
858         $post_type_object = get_post_type_object( $screen->post_type );
859
860         $taxonomy_names = get_object_taxonomies( $screen->post_type );
861         $hierarchical_taxonomies = array();
862         $flat_taxonomies = array();
863         foreach ( $taxonomy_names as $taxonomy_name ) {
864                 $taxonomy = get_taxonomy( $taxonomy_name);
865
866                 if ( !$taxonomy->show_ui )
867                         continue;
868
869                 if ( $taxonomy->hierarchical )
870                         $hierarchical_taxonomies[] = $taxonomy;
871                 else
872                         $flat_taxonomies[] = $taxonomy;
873         }
874
875         $columns = wp_manage_posts_columns($screen);
876         $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($screen) ) );
877         $col_count = count($columns) - count($hidden);
878         $m = ( isset($mode) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
879         $can_publish = current_user_can($post_type_object->cap->publish_posts);
880         $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
881
882 ?>
883
884 <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
885         <?php
886         $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
887         $bulk = 0;
888         while ( $bulk < 2 ) { ?>
889
890         <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-$screen->post_type ";
891                 echo $bulk ? "bulk-edit-row bulk-edit-row-$hclass bulk-edit-$screen->post_type" : "quick-edit-row quick-edit-row-$hclass inline-edit-$screen->post_type";
892         ?>" style="display: none"><td colspan="<?php echo $col_count; ?>">
893
894         <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
895                 <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
896
897
898 <?php
899
900 if ( post_type_supports( $screen->post_type, 'title' ) ) :
901         if ( $bulk ) : ?>
902                 <div id="bulk-title-div">
903                         <div id="bulk-titles"></div>
904                 </div>
905
906 <?php else : // $bulk ?>
907
908                 <label>
909                         <span class="title"><?php _e( 'Title' ); ?></span>
910                         <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
911                 </label>
912
913                 <label>
914                         <span class="title"><?php _e( 'Slug' ); ?></span>
915                         <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
916                 </label>
917
918 <?php endif; // $bulk
919 endif; // post_type_supports title ?>
920
921 <?php if ( !$bulk ) : ?>
922                 <label><span class="title"><?php _e( 'Date' ); ?></span></label>
923                 <div class="inline-edit-date">
924                         <?php touch_time(1, 1, 4, 1); ?>
925                 </div>
926                 <br class="clear" />
927
928 <?php endif; // $bulk
929
930         if ( post_type_supports( $screen->post_type, 'author' ) ) :
931                 $authors = get_editable_user_ids( $current_user->id, true, $screen->post_type ); // TODO: ROLE SYSTEM
932                 $authors_dropdown = '';
933                 if ( $authors && count( $authors ) > 1 ) :
934                         $users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1, 'echo' => 0);
935                         if ( $bulk )
936                                 $users_opt['show_option_none'] = __('&mdash; No Change &mdash;');
937                         $authors_dropdown  = '<label>';
938                         $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
939                         $authors_dropdown .= wp_dropdown_users( $users_opt );
940                         $authors_dropdown .= '</label>';
941
942                 endif; // authors
943 ?>
944
945 <?php if ( !$bulk ) echo $authors_dropdown;
946 endif; // post_type_supports author
947
948 if ( !$bulk ) :
949 ?>
950
951                 <div class="inline-edit-group">
952                         <label class="alignleft">
953                                 <span class="title"><?php _e( 'Password' ); ?></span>
954                                 <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
955                         </label>
956
957                         <em style="margin:5px 10px 0 0" class="alignleft">
958                                 <?php
959                                 /* translators: Between password field and private checkbox on post quick edit interface */
960                                 echo __( '&ndash;OR&ndash;' );
961                                 ?>
962                         </em>
963                         <label class="alignleft inline-edit-private">
964                                 <input type="checkbox" name="keep_private" value="private" />
965                                 <span class="checkbox-title"><?php echo __('Private'); ?></span>
966                         </label>
967                 </div>
968
969 <?php endif; ?>
970
971         </div></fieldset>
972
973 <?php if ( count($hierarchical_taxonomies) && !$bulk ) : ?>
974
975         <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
976
977 <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
978
979                 <span class="title inline-edit-categories-label"><?php echo esc_html($taxonomy->labels->name) ?>
980                         <span class="catshow"><?php _e('[more]'); ?></span>
981                         <span class="cathide" style="display:none;"><?php _e('[less]'); ?></span>
982                 </span>
983                 <input type="hidden" name="<?php echo ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr($taxonomy->name) . '][]'; ?>" value="0" />
984                 <ul class="cat-checklist <?php echo esc_attr($taxonomy->name)?>-checklist">
985                         <?php wp_terms_checklist(null, array('taxonomy' => $taxonomy->name)) ?>
986                 </ul>
987
988 <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
989
990         </div></fieldset>
991
992 <?php endif; // count($hierarchical_taxonomies) && !$bulk ?>
993
994         <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
995
996 <?php
997         if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
998                 echo $authors_dropdown;
999 ?>
1000
1001 <?php if ( $post_type_object->hierarchical ) : ?>
1002
1003                 <label>
1004                         <span class="title"><?php _e( 'Parent' ); ?></span>
1005 <?php
1006         $dropdown_args = array('post_type' => $post_type_object->name, 'selected' => $post->post_parent, 'name' => 'post_parent', 'show_option_none' => __('Main Page (no parent)'), 'option_none_value' => 0, 'sort_column'=> 'menu_order, post_title');
1007         if ( $bulk )
1008                 $dropdown_args['show_option_no_change'] =  __('&mdash; No Change &mdash;');
1009         $dropdown_args = apply_filters('quick_edit_dropdown_pages_args', $dropdown_args);
1010         wp_dropdown_pages($dropdown_args);
1011 ?>
1012                 </label>
1013
1014 <?php if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
1015                 if ( !$bulk ) : ?>
1016
1017                 <label>
1018                         <span class="title"><?php _e( 'Order' ); ?></span>
1019                         <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
1020                 </label>
1021
1022 <?php   endif; // !$bulk ?>
1023
1024                 <label>
1025                         <span class="title"><?php _e( 'Template' ); ?></span>
1026                         <select name="page_template">
1027 <?php   if ( $bulk ) : ?>
1028                                 <option value="-1"><?php _e('&mdash; No Change &mdash;'); ?></option>
1029 <?php   endif; // $bulk ?>
1030                                 <option value="default"><?php _e( 'Default Template' ); ?></option>
1031                                 <?php page_template_dropdown() ?>
1032                         </select>
1033                 </label>
1034
1035 <?php
1036         endif; // post_type_supports page-attributes
1037 endif; // $post_type_object->hierarchical ?>
1038
1039 <?php if ( count($flat_taxonomies) && !$bulk ) : ?>
1040
1041 <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
1042
1043                 <label class="inline-edit-tags">
1044                         <span class="title"><?php echo esc_html($taxonomy->labels->name) ?></span>
1045                         <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr($taxonomy->name)?>]" class="tax_input_<?php echo esc_attr($taxonomy->name)?>"></textarea>
1046                 </label>
1047
1048 <?php endforeach; //$flat_taxonomies as $taxonomy ?>
1049
1050 <?php endif; // count($flat_taxonomies) && !$bulk  ?>
1051
1052 <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
1053         if ( $bulk ) : ?>
1054
1055                 <div class="inline-edit-group">
1056         <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1057                 <label class="alignleft">
1058                         <span class="title"><?php _e( 'Comments' ); ?></span>
1059                         <select name="comment_status">
1060                                 <option value=""><?php _e('&mdash; No Change &mdash;'); ?></option>
1061                                 <option value="open"><?php _e('Allow'); ?></option>
1062                                 <option value="closed"><?php _e('Do not allow'); ?></option>
1063                         </select>
1064                 </label>
1065         <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1066                 <label class="alignright">
1067                         <span class="title"><?php _e( 'Pings' ); ?></span>
1068                         <select name="ping_status">
1069                                 <option value=""><?php _e('&mdash; No Change &mdash;'); ?></option>
1070                                 <option value="open"><?php _e('Allow'); ?></option>
1071                                 <option value="closed"><?php _e('Do not allow'); ?></option>
1072                         </select>
1073                 </label>
1074         <?php endif; ?>
1075                 </div>
1076
1077 <?php else : // $bulk ?>
1078
1079                 <div class="inline-edit-group">
1080                 <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1081                         <label class="alignleft">
1082                                 <input type="checkbox" name="comment_status" value="open" />
1083                                 <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
1084                         </label>
1085                 <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1086                         <label class="alignleft">
1087                                 <input type="checkbox" name="ping_status" value="open" />
1088                                 <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
1089                         </label>
1090                 <?php endif; ?>
1091                 </div>
1092
1093 <?php endif; // $bulk
1094 endif; // post_type_supports comments or pings ?>
1095
1096                 <div class="inline-edit-group">
1097                         <label class="inline-edit-status alignleft">
1098                                 <span class="title"><?php _e( 'Status' ); ?></span>
1099                                 <select name="_status">
1100 <?php if ( $bulk ) : ?>
1101                                         <option value="-1"><?php _e('&mdash; No Change &mdash;'); ?></option>
1102 <?php endif; // $bulk ?>
1103                                 <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
1104                                         <option value="publish"><?php _e( 'Published' ); ?></option>
1105                                         <option value="future"><?php _e( 'Scheduled' ); ?></option>
1106 <?php if ( $bulk ) : ?>
1107                                         <option value="private"><?php _e('Private') ?></option>
1108 <?php endif; // $bulk ?>
1109                                 <?php endif; ?>
1110                                         <option value="pending"><?php _e( 'Pending Review' ); ?></option>
1111                                         <option value="draft"><?php _e( 'Draft' ); ?></option>
1112                                 </select>
1113                         </label>
1114
1115 <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
1116
1117 <?php   if ( $bulk ) : ?>
1118
1119                         <label class="alignright">
1120                                 <span class="title"><?php _e( 'Sticky' ); ?></span>
1121                                 <select name="sticky">
1122                                         <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1123                                         <option value="sticky"><?php _e( 'Sticky' ); ?></option>
1124                                         <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
1125                                 </select>
1126                         </label>
1127
1128 <?php   else : // $bulk ?>
1129
1130                         <label class="alignleft">
1131                                 <input type="checkbox" name="sticky" value="sticky" />
1132                                 <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
1133                         </label>
1134
1135 <?php   endif; // $bulk ?>
1136
1137 <?php endif; // !$is_page && $can_publish && current_user_can( 'edit_others_cap' ) ?>
1138
1139                 </div>
1140
1141         </div></fieldset>
1142
1143 <?php
1144         foreach ( $columns as $column_name => $column_display_name ) {
1145                 if ( isset( $core_columns[$column_name] ) )
1146                         continue;
1147                 do_action( $bulk ? 'bulk_edit_custom_box' : 'quick_edit_custom_box', $column_name, $screen->post_type );
1148         }
1149 ?>
1150         <p class="submit inline-edit-save">
1151                 <a accesskey="c" href="#inline-edit" title="<?php _e('Cancel'); ?>" class="button-secondary cancel alignleft"><?php _e('Cancel'); ?></a>
1152                 <?php if ( ! $bulk ) {
1153                         wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
1154                         $update_text = __( 'Update' );
1155                         ?>
1156                         <a accesskey="s" href="#inline-edit" title="<?php _e('Update'); ?>" class="button-primary save alignright"><?php echo esc_attr( $update_text ); ?></a>
1157                         <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
1158                 <?php } else {
1159                         $update_text = __( 'Update' );
1160                 ?>
1161                         <input accesskey="s" class="button-primary alignright" type="submit" name="bulk_edit" value="<?php echo esc_attr( $update_text ); ?>" />
1162                 <?php } ?>
1163                 <input type="hidden" name="post_view" value="<?php echo esc_attr($m); ?>" />
1164                 <input type="hidden" name="screen" value="<?php echo esc_attr($screen->id); ?>" />
1165                 <br class="clear" />
1166         </p>
1167         </td></tr>
1168 <?php
1169         $bulk++;
1170         } ?>
1171         </tbody></table></form>
1172 <?php
1173 }
1174
1175 // adds hidden fields with the data for use in the inline editor for posts and pages
1176 /**
1177  * {@internal Missing Short Description}}
1178  *
1179  * @since unknown
1180  *
1181  * @param unknown_type $post
1182  */
1183 function get_inline_data($post) {
1184         $post_type_object = get_post_type_object($post->post_type);
1185         if ( ! current_user_can($post_type_object->cap->edit_post, $post->ID) )
1186                 return;
1187
1188         $title = esc_attr( get_the_title( $post->ID ) );
1189
1190         echo '
1191 <div class="hidden" id="inline_' . $post->ID . '">
1192         <div class="post_title">' . $title . '</div>
1193         <div class="post_name">' . apply_filters('editable_slug', $post->post_name) . '</div>
1194         <div class="post_author">' . $post->post_author . '</div>
1195         <div class="comment_status">' . $post->comment_status . '</div>
1196         <div class="ping_status">' . $post->ping_status . '</div>
1197         <div class="_status">' . $post->post_status . '</div>
1198         <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
1199         <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
1200         <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
1201         <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
1202         <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
1203         <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
1204         <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
1205
1206         if ( $post_type_object->hierarchical )
1207                 echo '<div class="post_parent">' . $post->post_parent . '</div>';
1208
1209         if ( $post->post_type == 'page' )
1210                 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
1211
1212         if ( $post_type_object->hierarchical )
1213                 echo '<div class="menu_order">' . $post->menu_order . '</div>';
1214
1215         $taxonomy_names = get_object_taxonomies( $post->post_type );
1216         foreach ( $taxonomy_names as $taxonomy_name) {
1217                 $taxonomy = get_taxonomy( $taxonomy_name );
1218
1219                 if ( $taxonomy->hierarchical && $taxonomy->show_ui )
1220                                 echo '<div class="post_category" id="'.$taxonomy_name.'_'.$post->ID.'">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array('fields'=>'ids')) ) . '</div>';
1221                 elseif ( $taxonomy->show_ui )
1222                         echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '</div>';
1223         }
1224
1225         if ( !$post_type_object->hierarchical )
1226                 echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
1227
1228         echo '</div>';
1229 }
1230
1231 /**
1232  * {@internal Missing Short Description}}
1233  *
1234  * @since unknown
1235  *
1236  * @param unknown_type $posts
1237  */
1238 function post_rows( $posts = array() ) {
1239         global $wp_query, $post, $mode;
1240
1241         add_filter('the_title','esc_html');
1242
1243         // Create array of post IDs.
1244         $post_ids = array();
1245
1246         if ( empty($posts) )
1247                 $posts = &$wp_query->posts;
1248
1249         foreach ( $posts as $a_post )
1250                 $post_ids[] = $a_post->ID;
1251
1252         $comment_pending_count = get_pending_comments_num($post_ids);
1253
1254         foreach ( $posts as $post ) {
1255                 if ( empty($comment_pending_count[$post->ID]) )
1256                         $comment_pending_count[$post->ID] = 0;
1257
1258                 _post_row($post, $comment_pending_count[$post->ID], $mode);
1259         }
1260 }
1261
1262 /**
1263  * {@internal Missing Short Description}}
1264  *
1265  * @since unknown
1266  *
1267  * @param unknown_type $a_post
1268  * @param unknown_type $pending_comments
1269  * @param unknown_type $mode
1270  */
1271 function _post_row($a_post, $pending_comments, $mode) {
1272         global $post, $current_user, $current_screen;
1273         static $rowclass;
1274
1275         $global_post = $post;
1276         $post = $a_post;
1277         setup_postdata($post);
1278
1279         $rowclass = 'alternate' == $rowclass ? '' : 'alternate';
1280         $post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' );
1281         $edit_link = get_edit_post_link( $post->ID );
1282         $title = _draft_or_post_title();
1283         $post_type_object = get_post_type_object($post->post_type);
1284 ?>
1285         <tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim( $rowclass . ' author-' . $post_owner . ' status-' . $post->post_status ); ?> iedit' valign="top">
1286 <?php
1287         $posts_columns = get_column_headers( $current_screen );
1288         $hidden = get_hidden_columns( $current_screen );
1289         foreach ( $posts_columns as $column_name=>$column_display_name ) {
1290                 $class = "class=\"$column_name column-$column_name\"";
1291
1292                 $style = '';
1293                 if ( in_array($column_name, $hidden) )
1294                         $style = ' style="display:none;"';
1295
1296                 $attributes = "$class$style";
1297
1298                 switch ($column_name) {
1299
1300                 case 'cb':
1301                 ?>
1302                 <th scope="row" class="check-column"><?php if ( current_user_can( $post_type_object->cap->edit_post, $post->ID ) ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
1303                 <?php
1304                 break;
1305
1306                 case 'date':
1307                         if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
1308                                 $t_time = $h_time = __('Unpublished');
1309                                 $time_diff = 0;
1310                         } else {
1311                                 $t_time = get_the_time(__('Y/m/d g:i:s A'));
1312                                 $m_time = $post->post_date;
1313                                 $time = get_post_time('G', true, $post);
1314
1315                                 $time_diff = time() - $time;
1316
1317                                 if ( $time_diff > 0 && $time_diff < 24*60*60 )
1318                                         $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
1319                                 else
1320                                         $h_time = mysql2date(__('Y/m/d'), $m_time);
1321                         }
1322
1323                         echo '<td ' . $attributes . '>';
1324                         if ( 'excerpt' == $mode )
1325                                 echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode);
1326                         else
1327                                 echo '<abbr title="' . $t_time . '">' . apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) . '</abbr>';
1328                         echo '<br />';
1329                         if ( 'publish' == $post->post_status ) {
1330                                 _e('Published');
1331                         } elseif ( 'future' == $post->post_status ) {
1332                                 if ( $time_diff > 0 )
1333                                         echo '<strong class="attention">' . __('Missed schedule') . '</strong>';
1334                                 else
1335                                         _e('Scheduled');
1336                         } else {
1337                                 _e('Last Modified');
1338                         }
1339                         echo '</td>';
1340                 break;
1341
1342                 case 'title':
1343                         $attributes = 'class="post-title column-title"' . $style;
1344                 ?>
1345                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->cap->edit_post, $post->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states($post); ?></strong>
1346                 <?php
1347                         if ( 'excerpt' == $mode )
1348                                 the_excerpt();
1349
1350                         $actions = array();
1351                         if ( current_user_can($post_type_object->cap->edit_post, $post->ID) && 'trash' != $post->post_status ) {
1352                                 $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this item')) . '">' . __('Edit') . '</a>';
1353                                 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this item inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
1354                         }
1355                         if ( current_user_can($post_type_object->cap->delete_post, $post->ID) ) {
1356                                 if ( 'trash' == $post->post_status )
1357                                         $actions['untrash'] = "<a title='" . esc_attr(__('Restore this item from the Trash')) . "' href='" . wp_nonce_url( admin_url( sprintf($post_type_object->_edit_link . '&amp;action=untrash', $post->ID) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __('Restore') . "</a>";
1358                                 elseif ( EMPTY_TRASH_DAYS )
1359                                         $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this item to the Trash')) . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash') . "</a>";
1360                                 if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
1361                                         $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this item permanently')) . "' href='" . get_delete_post_link($post->ID, '', true) . "'>" . __('Delete Permanently') . "</a>";
1362                         }
1363                         if ( in_array($post->post_status, array('pending', 'draft')) ) {
1364                                 if ( current_user_can($post_type_object->cap->edit_post, $post->ID) )
1365                                         $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink($post->ID) ) ) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
1366                         } elseif ( 'trash' != $post->post_status ) {
1367                                 $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
1368                         }
1369                         $actions = apply_filters('post_row_actions', $actions, $post);
1370                         $action_count = count($actions);
1371                         $i = 0;
1372                         echo '<div class="row-actions">';
1373                         foreach ( $actions as $action => $link ) {
1374                                 ++$i;
1375                                 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
1376                                 echo "<span class='$action'>$link$sep</span>";
1377                         }
1378                         echo '</div>';
1379
1380                         get_inline_data($post);
1381                 ?>
1382                 </td>
1383                 <?php
1384                 break;
1385
1386                 case 'categories':
1387                 ?>
1388                 <td <?php echo $attributes ?>><?php
1389                         $categories = get_the_category();
1390                         if ( !empty( $categories ) ) {
1391                                 $out = array();
1392                                 foreach ( $categories as $c )
1393                                         $out[] = "<a href='edit.php?category_name=$c->slug'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>";
1394                                         echo join( ', ', $out );
1395                         } else {
1396                                 _e('Uncategorized');
1397                         }
1398                 ?></td>
1399                 <?php
1400                 break;
1401
1402                 case 'tags':
1403                 ?>
1404                 <td <?php echo $attributes ?>><?php
1405                         $tags = get_the_tags($post->ID);
1406                         if ( !empty( $tags ) ) {
1407                                 $out = array();
1408                                 foreach ( $tags as $c )
1409                                         $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'post_tag', 'display')) . "</a>";
1410                                 echo join( ', ', $out );
1411                         } else {
1412                                 _e('No Tags');
1413                         }
1414                 ?></td>
1415                 <?php
1416                 break;
1417
1418                 case 'comments':
1419                 ?>
1420                 <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
1421                 <?php
1422                         $pending_phrase = sprintf( __('%s pending'), number_format( $pending_comments ) );
1423                         if ( $pending_comments )
1424                                 echo '<strong>';
1425                                 comments_number("<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('0', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('1', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link: % will be substituted by comment count */ _x('%', 'comment count') . '</span></a>');
1426                                 if ( $pending_comments )
1427                                 echo '</strong>';
1428                 ?>
1429                 </div></td>
1430                 <?php
1431                 break;
1432
1433                 case 'author':
1434                 ?>
1435                 <td <?php echo $attributes ?>><a href="edit.php?post_type=<?php echo $post->post_type; ?>&amp;author=<?php the_author_meta('ID'); ?>"><?php the_author() ?></a></td>
1436                 <?php
1437                 break;
1438
1439                 case 'control_view':
1440                 ?>
1441                 <td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e('View'); ?></a></td>
1442                 <?php
1443                 break;
1444
1445                 case 'control_edit':
1446                 ?>
1447                 <td><?php if ( current_user_can($post_type_object->cap->edit_post, $post->ID) ) { echo "<a href='$edit_link' class='edit'>" . __('Edit') . "</a>"; } ?></td>
1448                 <?php
1449                 break;
1450
1451                 case 'control_delete':
1452                 ?>
1453                 <td><?php if ( current_user_can($post_type_object->cap->delete_post, $post->ID) ) { echo "<a href='" . wp_nonce_url("post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "' class='delete'>" . __('Delete') . "</a>"; } ?></td>
1454                 <?php
1455                 break;
1456
1457                 default:
1458                 ?>
1459                 <td <?php echo $attributes ?>><?php do_action('manage_posts_custom_column', $column_name, $post->ID); ?></td>
1460                 <?php
1461                 break;
1462         }
1463 }
1464 ?>
1465         </tr>
1466 <?php
1467         $post = $global_post;
1468 }
1469
1470 /*
1471  * display one row if the page doesn't have any children
1472  * otherwise, display the row and its children in subsequent rows
1473  */
1474 /**
1475  * {@internal Missing Short Description}}
1476  *
1477  * @since unknown
1478  *
1479  * @param unknown_type $page
1480  * @param unknown_type $level
1481  */
1482 function display_page_row( $page, $level = 0 ) {
1483         global $post, $current_screen;
1484         static $rowclass;
1485
1486         $post = $page;
1487         setup_postdata($page);
1488
1489         if ( 0 == $level && (int)$page->post_parent > 0 ) {
1490                 //sent level 0 by accident, by default, or because we don't know the actual level
1491                 $find_main_page = (int)$page->post_parent;
1492                 while ( $find_main_page > 0 ) {
1493                         $parent = get_page($find_main_page);
1494
1495                         if ( is_null($parent) )
1496                                 break;
1497
1498                         $level++;
1499                         $find_main_page = (int)$parent->post_parent;
1500
1501                         if ( !isset($parent_name) )
1502                                 $parent_name = $parent->post_title;
1503                 }
1504         }
1505
1506         $page->post_title = esc_html( $page->post_title );
1507         $pad = str_repeat( '&#8212; ', $level );
1508         $id = (int) $page->ID;
1509         $rowclass = 'alternate' == $rowclass ? '' : 'alternate';
1510         $posts_columns = get_column_headers( $current_screen );
1511         $hidden = get_hidden_columns(  $current_screen );
1512         $title = _draft_or_post_title();
1513         $post_type = $page->post_type;
1514         $post_type_object = get_post_type_object($post_type);
1515 ?>
1516 <tr id="page-<?php echo $id; ?>" class="<?php echo $rowclass; ?> iedit">
1517 <?php
1518
1519 foreach ( $posts_columns as $column_name => $column_display_name ) {
1520         $class = "class=\"$column_name column-$column_name\"";
1521
1522         $style = '';
1523         if ( in_array($column_name, $hidden) )
1524                 $style = ' style="display:none;"';
1525
1526         $attributes = "$class$style";
1527
1528         switch ($column_name) {
1529
1530         case 'cb':
1531                 ?>
1532                 <th scope="row" class="check-column"><?php if ( current_user_can( $post_type_object->cap->edit_post, $page->ID ) ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
1533                 <?php
1534                 break;
1535         case 'date':
1536                 if ( '0000-00-00 00:00:00' == $page->post_date && 'date' == $column_name ) {
1537                         $t_time = $h_time = __('Unpublished');
1538                         $time_diff = 0;
1539                 } else {
1540                         $t_time = get_the_time(__('Y/m/d g:i:s A'));
1541                         $m_time = $page->post_date;
1542                         $time = get_post_time('G', true);
1543
1544                         $time_diff = time() - $time;
1545
1546                         if ( $time_diff > 0 && $time_diff < 24*60*60 )
1547                                 $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
1548                         else
1549                                 $h_time = mysql2date(__('Y/m/d'), $m_time);
1550                 }
1551                 echo '<td ' . $attributes . '>';
1552                 echo '<abbr title="' . $t_time . '">' . apply_filters('post_date_column_time', $h_time, $page, $column_name, '') . '</abbr>';
1553                 echo '<br />';
1554                 if ( 'publish' == $page->post_status ) {
1555                         _e('Published');
1556                 } elseif ( 'future' == $page->post_status ) {
1557                         if ( $time_diff > 0 )
1558                                 echo '<strong class="attention">' . __('Missed schedule') . '</strong>';
1559                         else
1560                                 _e('Scheduled');
1561                 } else {
1562                         _e('Last Modified');
1563                 }
1564                 echo '</td>';
1565                 break;
1566         case 'title':
1567                 $attributes = 'class="post-title page-title column-title"' . $style;
1568                 $edit_link = get_edit_post_link( $page->ID );
1569                 ?>
1570                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->cap->edit_post, $page->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html($parent_name) : ''; ?></strong>
1571                 <?php
1572                 $actions = array();
1573                 if ( current_user_can($post_type_object->cap->edit_post, $page->ID) && $post->post_status != 'trash' ) {
1574                         $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr(__('Edit this page')) . '">' . __('Edit') . '</a>';
1575                         $actions['inline'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
1576                 }
1577                 if ( current_user_can($post_type_object->cap->delete_post, $page->ID) ) {
1578                         if ( $post->post_status == 'trash' )
1579                                 $actions['untrash'] = "<a title='" . esc_attr(__('Remove this page from the Trash')) . "' href='" . wp_nonce_url("post.php?post_type=$post_type&amp;action=untrash&amp;post=$page->ID", 'untrash-' . $post->post_type . '_' . $page->ID) . "'>" . __('Restore') . "</a>";
1580                         elseif ( EMPTY_TRASH_DAYS )
1581                                 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this page to the Trash')) . "' href='" . get_delete_post_link($page->ID) . "'>" . __('Trash') . "</a>";
1582                         if ( $post->post_status == 'trash' || !EMPTY_TRASH_DAYS )
1583                                 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this page permanently')) . "' href='" . wp_nonce_url("post.php?post_type=$post_type&amp;action=delete&amp;post=$page->ID", 'delete-' . $post->post_type . '_' . $page->ID) . "'>" . __('Delete Permanently') . "</a>";
1584                 }
1585                 if ( in_array($post->post_status, array('pending', 'draft')) ) {
1586                         if ( current_user_can($post_type_object->cap->edit_post, $page->ID) )
1587                                 $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink($page->ID) ) ) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
1588                 } elseif ( $post->post_status != 'trash' ) {
1589                         $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
1590                 }
1591                 $actions = apply_filters('page_row_actions', $actions, $page);
1592                 $action_count = count($actions);
1593
1594                 $i = 0;
1595                 echo '<div class="row-actions">';
1596                 foreach ( $actions as $action => $link ) {
1597                         ++$i;
1598                         ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
1599                         echo "<span class='$action'>$link$sep</span>";
1600                 }
1601                 echo '</div>';
1602
1603                 get_inline_data($post);
1604                 echo '</td>';
1605                 break;
1606
1607         case 'comments':
1608                 ?>
1609                 <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
1610                 <?php
1611                 $left = get_pending_comments_num( $page->ID );
1612                 $pending_phrase = sprintf( __('%s pending'), number_format( $left ) );
1613                 if ( $left )
1614                         echo '<strong>';
1615                 comments_number("<a href='edit-comments.php?p=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('0', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('1', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link: % will be substituted by comment count */ _x('%', 'comment count') . '</span></a>');
1616                 if ( $left )
1617                         echo '</strong>';
1618                 ?>
1619                 </div></td>
1620                 <?php
1621                 break;
1622
1623         case 'author':
1624                 ?>
1625                 <td <?php echo $attributes ?>><a href="edit.php?post_type=<?php echo $post_type; ?>&amp;author=<?php the_author_meta('ID'); ?>"><?php the_author() ?></a></td>
1626                 <?php
1627                 break;
1628
1629         default:
1630                 ?>
1631                 <td <?php echo $attributes ?>><?php do_action('manage_pages_custom_column', $column_name, $id); ?></td>
1632                 <?php
1633                 break;
1634         }
1635 }
1636 ?>
1637
1638 </tr>
1639
1640 <?php
1641 }
1642
1643 /*
1644  * displays pages in hierarchical order with paging support
1645  */
1646 /**
1647  * {@internal Missing Short Description}}
1648  *
1649  * @since unknown
1650  *
1651  * @param unknown_type $pages
1652  * @param unknown_type $pagenum
1653  * @param unknown_type $per_page
1654  * @return unknown
1655  */
1656 function page_rows($pages, $pagenum = 1, $per_page = 20) {
1657         global $wpdb;
1658
1659         $level = 0;
1660
1661         if ( ! $pages ) {
1662                 $pages = get_pages( array('sort_column' => 'menu_order') );
1663
1664                 if ( ! $pages )
1665                         return false;
1666         }
1667
1668         /*
1669          * arrange pages into two parts: top level pages and children_pages
1670          * children_pages is two dimensional array, eg.
1671          * children_pages[10][] contains all sub-pages whose parent is 10.
1672          * It only takes O(N) to arrange this and it takes O(1) for subsequent lookup operations
1673          * If searching, ignore hierarchy and treat everything as top level
1674          */
1675         if ( empty($_GET['s']) ) {
1676
1677                 $top_level_pages = array();
1678                 $children_pages = array();
1679
1680                 foreach ( $pages as $page ) {
1681
1682                         // catch and repair bad pages
1683                         if ( $page->post_parent == $page->ID ) {
1684                                 $page->post_parent = 0;
1685                                 $wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $page->ID));
1686                                 clean_page_cache( $page->ID );
1687                         }
1688
1689                         if ( 0 == $page->post_parent )
1690                                 $top_level_pages[] = $page;
1691                         else
1692                                 $children_pages[ $page->post_parent ][] = $page;
1693                 }
1694
1695                 $pages = &$top_level_pages;
1696         }
1697
1698         $count = 0;
1699         $start = ($pagenum - 1) * $per_page;
1700         $end = $start + $per_page;
1701
1702         foreach ( $pages as $page ) {
1703                 if ( $count >= $end )
1704                         break;
1705
1706                 if ( $count >= $start )
1707                         echo "\t" . display_page_row( $page, $level );
1708
1709                 $count++;
1710
1711                 if ( isset($children_pages) )
1712                         _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
1713         }
1714
1715         // if it is the last pagenum and there are orphaned pages, display them with paging as well
1716         if ( isset($children_pages) && $count < $end ){
1717                 foreach( $children_pages as $orphans ){
1718                         foreach ( $orphans as $op ) {
1719                                 if ( $count >= $end )
1720                                         break;
1721                                 if ( $count >= $start )
1722                                         echo "\t" . display_page_row( $op, 0 );
1723                                 $count++;
1724                         }
1725                 }
1726         }
1727 }
1728
1729 /**
1730  * Given a top level page ID, display the nested hierarchy of sub-pages
1731  * together with paging support
1732  *
1733  * @since unknown
1734  *
1735  * @param unknown_type $children_pages
1736  * @param unknown_type $count
1737  * @param unknown_type $parent
1738  * @param unknown_type $level
1739  * @param unknown_type $pagenum
1740  * @param unknown_type $per_page
1741  */
1742 function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) {
1743
1744         if ( ! isset( $children_pages[$parent] ) )
1745                 return;
1746
1747         $start = ($pagenum - 1) * $per_page;
1748         $end = $start + $per_page;
1749
1750         foreach ( $children_pages[$parent] as $page ) {
1751
1752                 if ( $count >= $end )
1753                         break;
1754
1755                 // If the page starts in a subtree, print the parents.
1756                 if ( $count == $start && $page->post_parent > 0 ) {
1757                         $my_parents = array();
1758                         $my_parent = $page->post_parent;
1759                         while ( $my_parent) {
1760                                 $my_parent = get_post($my_parent);
1761                                 $my_parents[] = $my_parent;
1762                                 if ( !$my_parent->post_parent )
1763                                         break;
1764                                 $my_parent = $my_parent->post_parent;
1765                         }
1766                         $num_parents = count($my_parents);
1767                         while( $my_parent = array_pop($my_parents) ) {
1768                                 echo "\t" . display_page_row( $my_parent, $level - $num_parents );
1769                                 $num_parents--;
1770                         }
1771                 }
1772
1773                 if ( $count >= $start )
1774                         echo "\t" . display_page_row( $page, $level );
1775
1776                 $count++;
1777
1778                 _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
1779         }
1780
1781         unset( $children_pages[$parent] ); //required in order to keep track of orphans
1782 }
1783
1784 /**
1785  * Generate HTML for a single row on the users.php admin panel.
1786  *
1787  * @since 2.1.0
1788  *
1789  * @param object $user_object
1790  * @param string $style Optional. Attributes added to the TR element.  Must be sanitized.
1791  * @param string $role Key for the $wp_roles array.
1792  * @param int $numposts Optional. Post count to display for this user.  Defaults to zero, as in, a new user has made zero posts.
1793  * @return string
1794  */
1795 function user_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
1796         global $wp_roles;
1797
1798         $current_user = wp_get_current_user();
1799
1800         if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
1801                 $user_object = new WP_User( (int) $user_object );
1802         $user_object = sanitize_user_object($user_object, 'display');
1803         $email = $user_object->user_email;
1804         $url = $user_object->user_url;
1805         $short_url = str_replace( 'http://', '', $url );
1806         $short_url = str_replace( 'www.', '', $short_url );
1807         if ('/' == substr( $short_url, -1 ))
1808                 $short_url = substr( $short_url, 0, -1 );
1809         if ( strlen( $short_url ) > 35 )
1810                 $short_url = substr( $short_url, 0, 32 ).'...';
1811         $checkbox = '';
1812         // Check if the user for this row is editable
1813         if ( current_user_can( 'list_users' ) ) {
1814                 // Set up the user editing link
1815                 // TODO: make profile/user-edit determination a separate function
1816                 if ($current_user->ID == $user_object->ID) {
1817                         $edit_link = 'profile.php';
1818                 } else {
1819                         $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( esc_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) );
1820                 }
1821                 $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
1822
1823                 // Set up the hover actions for this user
1824                 $actions = array();
1825
1826                 if ( current_user_can('edit_user',  $user_object->ID) ) {
1827                         $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
1828                         $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1829                 } else {
1830                         $edit = "<strong>$user_object->user_login</strong><br />";
1831                 }
1832
1833                 if ( !is_multisite() && $current_user->ID != $user_object->ID && current_user_can('delete_user', $user_object->ID) )
1834                         $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=delete&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Delete') . "</a>";
1835                 if ( is_multisite() && $current_user->ID != $user_object->ID && current_user_can('remove_user', $user_object->ID) )
1836                         $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=remove&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Remove') . "</a>";
1837                 $actions = apply_filters('user_row_actions', $actions, $user_object);
1838                 $action_count = count($actions);
1839                 $i = 0;
1840                 $edit .= '<div class="row-actions">';
1841                 foreach ( $actions as $action => $link ) {
1842                         ++$i;
1843                         ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
1844                         $edit .= "<span class='$action'>$link$sep</span>";
1845                 }
1846                 $edit .= '</div>';
1847
1848                 // Set up the checkbox (because the user is editable, otherwise its empty)
1849                 $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
1850
1851         } else {
1852                 $edit = '<strong>' . $user_object->user_login . '</strong>';
1853         }
1854         $role_name = isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : __('None');
1855         $r = "<tr id='user-$user_object->ID'$style>";
1856         $columns = get_column_headers('users');
1857         $hidden = get_hidden_columns('users');
1858         $avatar = get_avatar( $user_object->ID, 32 );
1859         foreach ( $columns as $column_name => $column_display_name ) {
1860                 $class = "class=\"$column_name column-$column_name\"";
1861
1862                 $style = '';
1863                 if ( in_array($column_name, $hidden) )
1864                         $style = ' style="display:none;"';
1865
1866                 $attributes = "$class$style";
1867
1868                 switch ($column_name) {
1869                         case 'cb':
1870                                 $r .= "<th scope='row' class='check-column'>$checkbox</th>";
1871                                 break;
1872                         case 'username':
1873                                 $r .= "<td $attributes>$avatar $edit</td>";
1874                                 break;
1875                         case 'name':
1876                                 $r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>";
1877                                 break;
1878                         case 'email':
1879                                 $r .= "<td $attributes><a href='mailto:$email' title='" . sprintf( __('E-mail: %s' ), $email ) . "'>$email</a></td>";
1880                                 break;
1881                         case 'role':
1882                                 $r .= "<td $attributes>$role_name</td>";
1883                                 break;
1884                         case 'posts':
1885                                 $attributes = 'class="posts column-posts num"' . $style;
1886                                 $r .= "<td $attributes>";
1887                                 if ( $numposts > 0 ) {
1888                                         $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
1889                                         $r .= $numposts;
1890                                         $r .= '</a>';
1891                                 } else {
1892                                         $r .= 0;
1893                                 }
1894                                 $r .= "</td>";
1895                                 break;
1896                         default:
1897                                 $r .= "<td $attributes>";
1898                                 $r .= apply_filters('manage_users_custom_column', '', $column_name, $user_object->ID);
1899                                 $r .= "</td>";
1900                 }
1901         }
1902         $r .= '</tr>';
1903
1904         return $r;
1905 }
1906
1907 /**
1908  * {@internal Missing Short Description}}
1909  *
1910  * @since unknown
1911  *
1912  * @param string $status Comment status (approved, spam, trash, etc)
1913  * @param string $s Term to search for
1914  * @param int $start Offset to start at for pagination
1915  * @param int $num Maximum number of comments to return
1916  * @param int $post Post ID or 0 to return all comments
1917  * @param string $type Comment type (comment, trackback, pingback, etc)
1918  * @return array [0] contains the comments and [1] contains the total number of comments that match (ignoring $start and $num)
1919  */
1920 function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0, $type = '' ) {
1921         global $wpdb;
1922
1923         $start = abs( (int) $start );
1924         $num = (int) $num;
1925         $post = (int) $post;
1926         $count = wp_count_comments();
1927         $index = '';
1928
1929         if ( 'moderated' == $status ) {
1930                 $approved = "c.comment_approved = '0'";
1931                 $total = $count->moderated;
1932         } elseif ( 'approved' == $status ) {
1933                 $approved = "c.comment_approved = '1'";
1934                 $total = $count->approved;
1935         } elseif ( 'spam' == $status ) {
1936                 $approved = "c.comment_approved = 'spam'";
1937                 $total = $count->spam;
1938         } elseif ( 'trash' == $status ) {
1939                 $approved = "c.comment_approved = 'trash'";
1940                 $total = $count->trash;
1941         } else {
1942                 $approved = "( c.comment_approved = '0' OR c.comment_approved = '1' )";
1943                 $total = $count->moderated + $count->approved;
1944                 $index = 'USE INDEX (c.comment_date_gmt)';
1945         }
1946
1947         if ( $post ) {
1948                 $total = '';
1949                 $post = " AND c.comment_post_ID = '$post'";
1950         } else {
1951                 $post = '';
1952         }
1953
1954         $orderby = "ORDER BY c.comment_date_gmt DESC LIMIT $start, $num";
1955
1956         if ( 'comment' == $type )
1957                 $typesql = "AND c.comment_type = ''";
1958         elseif ( 'pings' == $type )
1959                 $typesql = "AND ( c.comment_type = 'pingback' OR c.comment_type = 'trackback' )";
1960         elseif ( 'all' == $type )
1961                 $typesql = '';
1962         elseif ( !empty($type) )
1963                 $typesql = $wpdb->prepare("AND c.comment_type = %s", $type);
1964         else
1965                 $typesql = '';
1966
1967         if ( !empty($type) )
1968                 $total = '';
1969
1970         $query = "FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ";
1971         if ( $s ) {
1972                 $total = '';
1973                 $s = $wpdb->escape($s);
1974                 $query .= "AND
1975                         (c.comment_author LIKE '%$s%' OR
1976                         c.comment_author_email LIKE '%$s%' OR
1977                         c.comment_author_url LIKE ('%$s%') OR
1978                         c.comment_author_IP LIKE ('%$s%') OR
1979                         c.comment_content LIKE ('%$s%') ) AND
1980                         $approved
1981                         $typesql";
1982         } else {
1983                 $query .= "AND $approved $post $typesql";
1984         }
1985
1986         $comments = $wpdb->get_results("SELECT * $query $orderby");
1987         if ( '' === $total )
1988                 $total = $wpdb->get_var("SELECT COUNT(c.comment_ID) $query");
1989
1990         update_comment_cache($comments);
1991
1992         return array($comments, $total);
1993 }
1994
1995 /**
1996  * {@internal Missing Short Description}}
1997  *
1998  * @since unknown
1999  *
2000  * @param unknown_type $comment_id
2001  * @param unknown_type $mode
2002  * @param unknown_type $comment_status
2003  * @param unknown_type $checkbox
2004  */
2005 function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true, $from_ajax = false ) {
2006         global $comment, $post, $_comment_pending_count;
2007         $comment = get_comment( $comment_id );
2008         $post = get_post($comment->comment_post_ID);
2009         $the_comment_status = wp_get_comment_status($comment->comment_ID);
2010         $post_type_object = get_post_type_object($post->post_type);
2011         $user_can = current_user_can($post_type_object->cap->edit_post, $post->ID);
2012
2013         $comment_url = esc_url(get_comment_link($comment->comment_ID));
2014         $author_url = get_comment_author_url();
2015         if ( 'http://' == $author_url )
2016                 $author_url = '';
2017         $author_url_display = preg_replace('|http://(www\.)?|i', '', $author_url);
2018         if ( strlen($author_url_display) > 50 )
2019                 $author_url_display = substr($author_url_display, 0, 49) . '...';
2020
2021         $ptime = date('G', strtotime( $comment->comment_date ) );
2022         if ( ( abs(time() - $ptime) ) < 86400 )
2023                 $ptime = sprintf( __('%s ago'), human_time_diff( $ptime ) );
2024         else
2025                 $ptime = mysql2date(__('Y/m/d \a\t g:i A'), $comment->comment_date );
2026
2027         if ( $user_can ) {
2028                 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
2029                 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
2030
2031                 $approve_url = esc_url( "comment.php?action=approvecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
2032                 $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
2033                 $spam_url = esc_url( "comment.php?action=spamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2034                 $unspam_url = esc_url( "comment.php?action=unspamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2035                 $trash_url = esc_url( "comment.php?action=trashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2036                 $untrash_url = esc_url( "comment.php?action=untrashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2037                 $delete_url = esc_url( "comment.php?action=deletecomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2038         }
2039
2040         echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>";
2041         $columns = get_column_headers('edit-comments');
2042         $hidden = get_hidden_columns('edit-comments');
2043         foreach ( $columns as $column_name => $column_display_name ) {
2044                 $class = "class=\"$column_name column-$column_name\"";
2045
2046                 $style = '';
2047                 if ( in_array($column_name, $hidden) )
2048                         $style = ' style="display:none;"';
2049
2050                 $attributes = "$class$style";
2051
2052                 switch ($column_name) {
2053                         case 'cb':
2054                                 if ( !$checkbox ) break;
2055                                 echo '<th scope="row" class="check-column">';
2056                                 if ( $user_can ) echo "<input type='checkbox' name='delete_comments[]' value='$comment->comment_ID' />";
2057                                 echo '</th>';
2058                                 break;
2059                         case 'comment':
2060                                 echo "<td $attributes>";
2061                                 echo '<div id="submitted-on">';
2062                                 /* translators: 2: comment date, 3: comment time */
2063                                 printf( __( '<a href="%1$s">%2$s at %3$s</a>' ), $comment_url,
2064                                         /* translators: comment date format. See http://php.net/date */ get_comment_date( __('Y/m/d') ),
2065                                         /* translators: comment time format. See http://php.net/date */ get_comment_date( get_option( 'time_format' ) ) );
2066
2067                                 if ( $comment->comment_parent ) {
2068                                         $parent = get_comment( $comment->comment_parent );
2069                                         $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
2070                                         $name = apply_filters( 'get_comment_author', $parent->comment_author ); // there's no API function for this
2071                                         printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
2072                                 }
2073
2074                                 echo '</div>';
2075                                 comment_text();
2076                                 if ( $user_can ) { ?>
2077                                 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
2078                                 <textarea class="comment" rows="1" cols="1"><?php echo htmlspecialchars( apply_filters('comment_edit_pre', $comment->comment_content), ENT_QUOTES ); ?></textarea>
2079                                 <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
2080                                 <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
2081                                 <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
2082                                 <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
2083                                 </div>
2084                                 <?php
2085                                 }
2086
2087                                 if ( $user_can ) {
2088                                         // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
2089                                         $actions = array(
2090                                                 'approve' => '', 'unapprove' => '',
2091                                                 'reply' => '',
2092                                                 'quickedit' => '',
2093                                                 'edit' => '',
2094                                                 'spam' => '', 'unspam' => '',
2095                                                 'trash' => '', 'untrash' => '', 'delete' => ''
2096                                         );
2097
2098                                         if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
2099                                                 if ( 'approved' == $the_comment_status )
2100                                                         $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
2101                                                 else if ( 'unapproved' == $the_comment_status )
2102                                                         $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
2103                                         } else {
2104                                                 $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
2105                                                 $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
2106                                         }
2107
2108                                         if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
2109                                                 $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
2110                                         } elseif ( 'spam' == $the_comment_status ) {
2111                                                 $actions['unspam'] = "<a href='$unspam_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1 vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>';
2112                                         } elseif ( 'trash' == $the_comment_status ) {
2113                                                 $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
2114                                         }
2115
2116                                         if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
2117                                                 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
2118                                         } else {
2119                                                 $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>';
2120                                         }
2121
2122                                         if ( 'trash' != $the_comment_status ) {
2123                                                 $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
2124                                                 $actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\');return false;" class="vim-q" title="'.esc_attr__('Quick Edit').'" href="#">' . __('Quick&nbsp;Edit') . '</a>';
2125                                                 if ( 'spam' != $the_comment_status )
2126                                                         $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\');return false;" class="vim-r" title="'.esc_attr__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
2127                                         }
2128
2129                                         $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
2130
2131                                         $i = 0;
2132                                         echo '<div class="row-actions">';
2133                                         foreach ( $actions as $action => $link ) {
2134                                                 ++$i;
2135                                                 ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
2136
2137                                                 // Reply and quickedit need a hide-if-no-js span when not added with ajax
2138                                                 if ( ('reply' == $action || 'quickedit' == $action) && ! $from_ajax )
2139                                                         $action .= ' hide-if-no-js';
2140                                                 elseif ( ($action == 'untrash' && $the_comment_status == 'trash') || ($action == 'unspam' && $the_comment_status == 'spam') ) {
2141                                                         if ('1' == get_comment_meta($comment_id, '_wp_trash_meta_status', true))
2142                                                                 $action .= ' approve';
2143                                                         else
2144                                                                 $action .= ' unapprove';
2145                                                 }
2146
2147                                                 echo "<span class='$action'>$sep$link</span>";
2148                                         }
2149                                         echo '</div>';
2150                                 }
2151
2152                                 echo '</td>';
2153                                 break;
2154                         case 'author':
2155                                 echo "<td $attributes><strong>"; comment_author(); echo '</strong><br />';
2156                                 if ( !empty($author_url) )
2157                                         echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />";
2158                                 if ( $user_can ) {
2159                                         if ( !empty($comment->comment_author_email) ) {
2160                                                 comment_author_email_link();
2161                                                 echo '<br />';
2162                                         }
2163                                         echo '<a href="edit-comments.php?s=';
2164                                         comment_author_IP();
2165                                         echo '&amp;mode=detail';
2166                                         if ( 'spam' == $comment_status )
2167                                                 echo '&amp;comment_status=spam';
2168                                         echo '">';
2169                                         comment_author_IP();
2170                                         echo '</a>';
2171                                 } //current_user_can
2172                                 echo '</td>';
2173                                 break;
2174                         case 'date':
2175                                 echo "<td $attributes>" . get_comment_date(__('Y/m/d \a\t g:ia')) . '</td>';
2176                                 break;
2177                         case 'response':
2178                                 if ( 'single' !== $mode ) {
2179                                         if ( isset( $_comment_pending_count[$post->ID] ) ) {
2180                                                 $pending_comments = $_comment_pending_count[$post->ID];
2181                                         } else {
2182                                                 $_comment_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
2183                                                 $pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp[$post->ID];
2184                                         }
2185                                         if ( $user_can ) {
2186                                                 $post_link = "<a href='" . get_edit_post_link($post->ID) . "'>";
2187                                                 $post_link .= get_the_title($post->ID) . '</a>';
2188                                         } else {
2189                                                 $post_link = get_the_title($post->ID);
2190                                         }
2191                                         echo "<td $attributes>\n";
2192                                         echo '<div class="response-links"><span class="post-com-count-wrapper">';
2193                                         echo $post_link . '<br />';
2194                                         $pending_phrase = esc_attr(sprintf( __('%s pending'), number_format( $pending_comments ) ));
2195                                         if ( $pending_comments )
2196                                                 echo '<strong>';
2197                                         comments_number("<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('0', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('1', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link: % will be substituted by comment count */ _x('%', 'comment count') . '</span></a>');
2198                                         if ( $pending_comments )
2199                                                 echo '</strong>';
2200                                         echo '</span> ';
2201                                         echo "<a href='" . get_permalink( $post->ID ) . "'>#</a>";
2202                                         echo '</div>';
2203                                         if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) )
2204                                                 echo $thumb;
2205                                         echo '</td>';
2206                                 }
2207                                 break;
2208                         default:
2209                                 echo "<td $attributes>\n";
2210                                 do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
2211                                 echo "</td>\n";
2212                                 break;
2213                 }
2214         }
2215         echo "</tr>\n";
2216 }
2217
2218 /**
2219  * {@internal Missing Short Description}}
2220  *
2221  * @since unknown
2222  *
2223  * @param unknown_type $position
2224  * @param unknown_type $checkbox
2225  * @param unknown_type $mode
2226  */
2227 function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
2228         global $current_user;
2229
2230         // allow plugin to replace the popup content
2231         $content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) );
2232
2233         if ( ! empty($content) ) {
2234                 echo $content;
2235                 return;
2236         }
2237
2238         $columns = get_column_headers('edit-comments');
2239         $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns('edit-comments') ) );
2240         $col_count = count($columns) - count($hidden);
2241
2242 ?>
2243 <form method="get" action="">
2244 <?php if ( $table_row ) : ?>
2245 <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $col_count; ?>">
2246 <?php else : ?>
2247 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
2248 <?php endif; ?>
2249         <div id="replyhead" style="display:none;"><?php _e('Reply to Comment'); ?></div>
2250
2251         <div id="edithead" style="display:none;">
2252                 <div class="inside">
2253                 <label for="author"><?php _e('Name') ?></label>
2254                 <input type="text" name="newcomment_author" size="50" value="" tabindex="101" id="author" />
2255                 </div>
2256
2257                 <div class="inside">
2258                 <label for="author-email"><?php _e('E-mail') ?></label>
2259                 <input type="text" name="newcomment_author_email" size="50" value="" tabindex="102" id="author-email" />
2260                 </div>
2261
2262                 <div class="inside">
2263                 <label for="author-url"><?php _e('URL') ?></label>
2264                 <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" tabindex="103" />
2265                 </div>
2266                 <div style="clear:both;"></div>
2267         </div>
2268
2269         <div id="replycontainer"><textarea rows="8" cols="40" name="replycontent" tabindex="104" id="replycontent"></textarea></div>
2270
2271         <p id="replysubmit" class="submit">
2272         <a href="#comments-form" class="cancel button-secondary alignleft" tabindex="106"><?php _e('Cancel'); ?></a>
2273         <a href="#comments-form" class="save button-primary alignright" tabindex="104">
2274         <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
2275         <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
2276         <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
2277         <span class="error" style="display:none;"></span>
2278         <br class="clear" />
2279         </p>
2280
2281         <input type="hidden" name="user_ID" id="user_ID" value="<?php echo $current_user->ID; ?>" />
2282         <input type="hidden" name="action" id="action" value="" />
2283         <input type="hidden" name="comment_ID" id="comment_ID" value="" />
2284         <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
2285         <input type="hidden" name="status" id="status" value="" />
2286         <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
2287         <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
2288         <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
2289         <?php wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false ); ?>
2290         <?php wp_comment_form_unfiltered_html_nonce(); ?>
2291 <?php if ( $table_row ) : ?>
2292 </td></tr></tbody></table>
2293 <?php else : ?>
2294 </div></div>
2295 <?php endif; ?>
2296 </form>
2297 <?php
2298 }
2299
2300 /**
2301  * Output 'undo move to trash' text for comments
2302  *
2303  * @since 2.9.0
2304  */
2305 function wp_comment_trashnotice() {
2306 ?>
2307 <div class="hidden" id="trash-undo-holder">
2308         <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>
2309 </div>
2310 <div class="hidden" id="spam-undo-holder">
2311         <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>
2312 </div>
2313 <?php
2314 }
2315
2316 /**
2317  * {@internal Missing Short Description}}
2318  *
2319  * @since unknown
2320  *
2321  * @param unknown_type $meta
2322  */
2323 function list_meta( $meta ) {
2324         // Exit if no meta
2325         if ( ! $meta ) {
2326                 echo '
2327 <table id="list-table" style="display: none;">
2328         <thead>
2329         <tr>
2330                 <th class="left">' . __( 'Name' ) . '</th>
2331                 <th>' . __( 'Value' ) . '</th>
2332         </tr>
2333         </thead>
2334         <tbody id="the-list" class="list:meta">
2335         <tr><td></td></tr>
2336         </tbody>
2337 </table>'; //TBODY needed for list-manipulation JS
2338                 return;
2339         }
2340         $count = 0;
2341 ?>
2342 <table id="list-table">
2343         <thead>
2344         <tr>
2345                 <th class="left"><?php _e( 'Name' ) ?></th>
2346                 <th><?php _e( 'Value' ) ?></th>
2347         </tr>
2348         </thead>
2349         <tbody id='the-list' class='list:meta'>
2350 <?php
2351         foreach ( $meta as $entry )
2352                 echo _list_meta_row( $entry, $count );
2353 ?>
2354         </tbody>
2355 </table>
2356 <?php
2357 }
2358
2359 /**
2360  * {@internal Missing Short Description}}
2361  *
2362  * @since unknown
2363  *
2364  * @param unknown_type $entry
2365  * @param unknown_type $count
2366  * @return unknown
2367  */
2368 function _list_meta_row( $entry, &$count ) {
2369         static $update_nonce = false;
2370         if ( !$update_nonce )
2371                 $update_nonce = wp_create_nonce( 'add-meta' );
2372
2373         $r = '';
2374         ++ $count;
2375         if ( $count % 2 )
2376                 $style = 'alternate';
2377         else
2378                 $style = '';
2379         if ('_' == $entry['meta_key'] { 0 } )
2380                 $style .= ' hidden';
2381
2382         if ( is_serialized( $entry['meta_value'] ) ) {
2383                 if ( is_serialized_string( $entry['meta_value'] ) ) {
2384                         // this is a serialized string, so we should display it
2385                         $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
2386                 } else {
2387                         // this is a serialized array/object so we should NOT display it
2388                         --$count;
2389                         return;
2390                 }
2391         }
2392
2393         $entry['meta_key'] = esc_attr($entry['meta_key']);
2394         $entry['meta_value'] = htmlspecialchars($entry['meta_value']); // using a <textarea />
2395         $entry['meta_id'] = (int) $entry['meta_id'];
2396
2397         $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
2398
2399         $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
2400         $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']}' />";
2401
2402         $r .= "\n\t\t<div class='submit'><input name='deletemeta[{$entry['meta_id']}]' type='submit' ";
2403         $r .= "class='delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta' tabindex='6' value='". esc_attr__( 'Delete' ) ."' />";
2404         $r .= "\n\t\t<input name='updatemeta' type='submit' tabindex='6' value='". esc_attr__( 'Update' ) ."' class='add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce updatemeta' /></div>";
2405         $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
2406         $r .= "</td>";
2407
2408         $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>";
2409         return $r;
2410 }
2411
2412 /**
2413  * {@internal Missing Short Description}}
2414  *
2415  * @since unknown
2416  */
2417 function meta_form() {
2418         global $wpdb;
2419         $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
2420         $keys = $wpdb->get_col( "
2421                 SELECT meta_key
2422                 FROM $wpdb->postmeta
2423                 GROUP BY meta_key
2424                 HAVING meta_key NOT LIKE '\_%'
2425                 ORDER BY meta_key
2426                 LIMIT $limit" );
2427         if ( $keys )
2428                 natcasesort($keys);
2429 ?>
2430 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
2431 <table id="newmeta">
2432 <thead>
2433 <tr>
2434 <th class="left"><label for="metakeyselect"><?php _e( 'Name' ) ?></label></th>
2435 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
2436 </tr>
2437 </thead>
2438
2439 <tbody>
2440 <tr>
2441 <td id="newmetaleft" class="left">
2442 <?php if ( $keys ) { ?>
2443 <select id="metakeyselect" name="metakeyselect" tabindex="7">
2444 <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
2445 <?php
2446
2447         foreach ( $keys as $key ) {
2448                 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
2449         }
2450 ?>
2451 </select>
2452 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
2453 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
2454 <span id="enternew"><?php _e('Enter new'); ?></span>
2455 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
2456 <?php } else { ?>
2457 <input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
2458 <?php } ?>
2459 </td>
2460 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td>
2461 </tr>
2462
2463 <tr><td colspan="2" class="submit">
2464 <input type="submit" id="addmetasub" name="addmeta" class="add:the-list:newmeta" tabindex="9" value="<?php esc_attr_e( 'Add Custom Field' ) ?>" />
2465 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
2466 </td></tr>
2467 </tbody>
2468 </table>
2469 <?php
2470
2471 }
2472
2473 /**
2474  * {@internal Missing Short Description}}
2475  *
2476  * @since unknown
2477  *
2478  * @param unknown_type $edit
2479  * @param unknown_type $for_post
2480  * @param unknown_type $tab_index
2481  * @param unknown_type $multi
2482  */
2483 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
2484         global $wp_locale, $post, $comment;
2485
2486         if ( $for_post )
2487                 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
2488
2489         $tab_index_attribute = '';
2490         if ( (int) $tab_index > 0 )
2491                 $tab_index_attribute = " tabindex=\"$tab_index\"";
2492
2493         // 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 />';
2494
2495         $time_adj = current_time('timestamp');
2496         $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
2497         $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
2498         $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
2499         $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
2500         $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
2501         $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
2502         $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
2503
2504         $cur_jj = gmdate( 'd', $time_adj );
2505         $cur_mm = gmdate( 'm', $time_adj );
2506         $cur_aa = gmdate( 'Y', $time_adj );
2507         $cur_hh = gmdate( 'H', $time_adj );
2508         $cur_mn = gmdate( 'i', $time_adj );
2509
2510         $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
2511         for ( $i = 1; $i < 13; $i = $i +1 ) {
2512                 $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
2513                 if ( $i == $mm )
2514                         $month .= ' selected="selected"';
2515                 $month .= '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
2516         }
2517         $month .= '</select>';
2518
2519         $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
2520         $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
2521         $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
2522         $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
2523
2524         echo '<div class="timestamp-wrap">';
2525         /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
2526         printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
2527
2528         echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
2529
2530         if ( $multi ) return;
2531
2532         echo "\n\n";
2533         foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) {
2534                 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
2535                 $cur_timeunit = 'cur_' . $timeunit;
2536                 echo '<input type="hidden" id="'. $cur_timeunit . '" name="'. $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
2537         }
2538 ?>
2539
2540 <p>
2541 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
2542 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
2543 </p>
2544 <?php
2545 }
2546
2547 /**
2548  * {@internal Missing Short Description}}
2549  *
2550  * @since unknown
2551  *
2552  * @param unknown_type $default
2553  */
2554 function page_template_dropdown( $default = '' ) {
2555         $templates = get_page_templates();
2556         ksort( $templates );
2557         foreach (array_keys( $templates ) as $template )
2558                 : if ( $default == $templates[$template] )
2559                         $selected = " selected='selected'";
2560                 else
2561                         $selected = '';
2562         echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
2563         endforeach;
2564 }
2565
2566 /**
2567  * {@internal Missing Short Description}}
2568  *
2569  * @since unknown
2570  *
2571  * @param unknown_type $default
2572  * @param unknown_type $parent
2573  * @param unknown_type $level
2574  * @return unknown
2575  */
2576 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
2577         global $wpdb, $post_ID;
2578         $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) );
2579
2580         if ( $items ) {
2581                 foreach ( $items as $item ) {
2582                         // A page cannot be its own parent.
2583                         if (!empty ( $post_ID ) ) {
2584                                 if ( $item->ID == $post_ID ) {
2585                                         continue;
2586                                 }
2587                         }
2588                         $pad = str_repeat( '&nbsp;', $level * 3 );
2589                         if ( $item->ID == $default)
2590                                 $current = ' selected="selected"';
2591                         else
2592                                 $current = '';
2593
2594                         echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";
2595                         parent_dropdown( $default, $item->ID, $level +1 );
2596                 }
2597         } else {
2598                 return false;
2599         }
2600 }
2601
2602 /**
2603  * {@internal Missing Short Description}}
2604  *
2605  * @since unknown
2606  *
2607  * @param unknown_type $id
2608  * @return unknown
2609  */
2610 function the_attachment_links( $id = false ) {
2611         $id = (int) $id;
2612         $post = & get_post( $id );
2613
2614         if ( $post->post_type != 'attachment' )
2615                 return false;
2616
2617         $icon = wp_get_attachment_image( $post->ID, 'thumbnail', true );
2618         $attachment_data = wp_get_attachment_metadata( $id );
2619         $thumb = isset( $attachment_data['thumb'] );
2620 ?>
2621 <form id="the-attachment-links">
2622 <table>
2623         <col />
2624         <col class="widefat" />
2625         <tr>
2626                 <th scope="row"><?php _e( 'URL' ) ?></th>
2627                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
2628         </tr>
2629 <?php if ( $icon ) : ?>
2630         <tr>
2631                 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
2632                 <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>
2633         </tr>
2634         <tr>
2635                 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
2636                 <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>
2637         </tr>
2638 <?php else : ?>
2639         <tr>
2640                 <th scope="row"><?php _e( 'Link to file' ) ?></th>
2641                 <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>
2642         </tr>
2643         <tr>
2644                 <th scope="row"><?php _e( 'Link to page' ) ?></th>
2645                 <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>
2646         </tr>
2647 <?php endif; ?>
2648 </table>
2649 </form>
2650 <?php
2651 }
2652
2653
2654 /**
2655  * Print out <option> html elements for role selectors based on $wp_roles
2656  *
2657  * @package WordPress
2658  * @subpackage Administration
2659  * @since 2.1
2660  *
2661  * @uses $wp_roles
2662  * @param string $default slug for the role that should be already selected
2663  */
2664 function wp_dropdown_roles( $selected = false ) {
2665         $p = '';
2666         $r = '';
2667
2668         $editable_roles = get_editable_roles();
2669
2670         foreach ( $editable_roles as $role => $details ) {
2671                 $name = translate_user_role($details['name'] );
2672                 if ( $selected == $role ) // Make default first in list
2673                         $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
2674                 else
2675                         $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
2676         }
2677         echo $p . $r;
2678 }
2679
2680 /**
2681  * {@internal Missing Short Description}}
2682  *
2683  * @since unknown
2684  *
2685  * @param unknown_type $size
2686  * @return unknown
2687  */
2688 function wp_convert_hr_to_bytes( $size ) {
2689         $size = strtolower($size);
2690         $bytes = (int) $size;
2691         if ( strpos($size, 'k') !== false )
2692                 $bytes = intval($size) * 1024;
2693         elseif ( strpos($size, 'm') !== false )
2694                 $bytes = intval($size) * 1024 * 1024;
2695         elseif ( strpos($size, 'g') !== false )
2696                 $bytes = intval($size) * 1024 * 1024 * 1024;
2697         return $bytes;
2698 }
2699
2700 /**
2701  * {@internal Missing Short Description}}
2702  *
2703  * @since unknown
2704  *
2705  * @param unknown_type $bytes
2706  * @return unknown
2707  */
2708 function wp_convert_bytes_to_hr( $bytes ) {
2709         $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
2710         $log = log( $bytes, 1024 );
2711         $power = (int) $log;
2712         $size = pow(1024, $log - $power);
2713         return $size . $units[$power];
2714 }
2715
2716 /**
2717  * {@internal Missing Short Description}}
2718  *
2719  * @since unknown
2720  *
2721  * @return unknown
2722  */
2723 function wp_max_upload_size() {
2724         $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
2725         $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
2726         $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
2727         return $bytes;
2728 }
2729
2730 /**
2731  * Outputs the form used by the importers to accept the data to be imported
2732  *
2733  * @since 2.0
2734  *
2735  * @param string $action The action attribute for the form.
2736  */
2737 function wp_import_upload_form( $action ) {
2738         $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
2739         $size = wp_convert_bytes_to_hr( $bytes );
2740         $upload_dir = wp_upload_dir();
2741         if ( ! empty( $upload_dir['error'] ) ) :
2742                 ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
2743                 <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
2744         else :
2745 ?>
2746 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
2747 <p>
2748 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
2749 <input type="file" id="upload" name="import" size="25" />
2750 <input type="hidden" name="action" value="save" />
2751 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
2752 </p>
2753 <p class="submit">
2754 <input type="submit" class="button" value="<?php esc_attr_e( 'Upload file and import' ); ?>" />
2755 </p>
2756 </form>
2757 <?php
2758         endif;
2759 }
2760
2761 /**
2762  * Add a meta box to an edit form.
2763  *
2764  * @since 2.5.0
2765  *
2766  * @param string $id String for use in the 'id' attribute of tags.
2767  * @param string $title Title of the meta box.
2768  * @param string $callback Function that fills the box with the desired content. The function should echo its output.
2769  * @param string $page The type of edit page on which to show the box (post, page, link).
2770  * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
2771  * @param string $priority The priority within the context where the boxes should show ('high', 'low').
2772  */
2773 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
2774         global $wp_meta_boxes;
2775
2776         if ( !isset($wp_meta_boxes) )
2777                 $wp_meta_boxes = array();
2778         if ( !isset($wp_meta_boxes[$page]) )
2779                 $wp_meta_boxes[$page] = array();
2780         if ( !isset($wp_meta_boxes[$page][$context]) )
2781                 $wp_meta_boxes[$page][$context] = array();
2782
2783         foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
2784         foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
2785                 if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
2786                         continue;
2787
2788                 // If a core box was previously added or removed by a plugin, don't add.
2789                 if ( 'core' == $priority ) {
2790                         // If core box previously deleted, don't add
2791                         if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
2792                                 return;
2793                         // If box was added with default priority, give it core priority to maintain sort order
2794                         if ( 'default' == $a_priority ) {
2795                                 $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
2796                                 unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
2797                         }
2798                         return;
2799                 }
2800                 // If no priority given and id already present, use existing priority
2801                 if ( empty($priority) ) {
2802                         $priority = $a_priority;
2803                 // else if we're adding to the sorted priortiy, we don't know the title or callback. Glab them from the previously added context/priority.
2804                 } elseif ( 'sorted' == $priority ) {
2805                         $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
2806                         $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
2807                         $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
2808                 }
2809                 // An id can be in only one priority and one context
2810                 if ( $priority != $a_priority || $context != $a_context )
2811                         unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
2812         }
2813         }
2814
2815         if ( empty($priority) )
2816                 $priority = 'low';
2817
2818         if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
2819                 $wp_meta_boxes[$page][$context][$priority] = array();
2820
2821         $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
2822 }
2823
2824 /**
2825  * Meta-Box template function
2826  *
2827  * @since 2.5.0
2828  *
2829  * @param string $page page identifier, also known as screen identifier
2830  * @param string $context box context
2831  * @param mixed $object gets passed to the box callback function as first parameter
2832  * @return int number of meta_boxes
2833  */
2834 function do_meta_boxes($page, $context, $object) {
2835         global $wp_meta_boxes;
2836         static $already_sorted = false;
2837
2838         $hidden = get_hidden_meta_boxes($page);
2839
2840         printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
2841
2842         $i = 0;
2843         do {
2844                 // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
2845                 if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
2846                         foreach ( $sorted as $box_context => $ids )
2847                                 foreach ( explode(',', $ids) as $id )
2848                                         if ( $id )
2849                                                 add_meta_box( $id, null, null, $page, $box_context, 'sorted' );
2850                 }
2851                 $already_sorted = true;
2852
2853                 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
2854                         break;
2855
2856                 foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
2857                         if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
2858                                 foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
2859                                         if ( false == $box || ! $box['title'] )
2860                                                 continue;
2861                                         $i++;
2862                                         $style = '';
2863                                         $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
2864                                         echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
2865                                         echo '<div class="handlediv" title="' . __('Click to toggle') . '"><br /></div>';
2866                                         echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
2867                                         echo '<div class="inside">' . "\n";
2868                                         call_user_func($box['callback'], $object, $box);
2869                                         echo "</div>\n";
2870                                         echo "</div>\n";
2871                                 }
2872                         }
2873                 }
2874         } while(0);
2875
2876         echo "</div>";
2877
2878         return $i;
2879
2880 }
2881
2882 /**
2883  * Remove a meta box from an edit form.
2884  *
2885  * @since 2.6.0
2886  *
2887  * @param string $id String for use in the 'id' attribute of tags.
2888  * @param string $page The type of edit page on which to show the box (post, page, link).
2889  * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
2890  */
2891 function remove_meta_box($id, $page, $context) {
2892         global $wp_meta_boxes;
2893
2894         if ( !isset($wp_meta_boxes) )
2895                 $wp_meta_boxes = array();
2896         if ( !isset($wp_meta_boxes[$page]) )
2897                 $wp_meta_boxes[$page] = array();
2898         if ( !isset($wp_meta_boxes[$page][$context]) )
2899                 $wp_meta_boxes[$page][$context] = array();
2900
2901         foreach ( array('high', 'core', 'default', 'low') as $priority )
2902                 $wp_meta_boxes[$page][$context][$priority][$id] = false;
2903 }
2904
2905 /**
2906  * {@internal Missing Short Description}}
2907  *
2908  * @since unknown
2909  *
2910  * @param unknown_type $screen
2911  */
2912 function meta_box_prefs($screen) {
2913         global $wp_meta_boxes;
2914
2915         if ( is_string($screen) )
2916                 $screen = convert_to_screen($screen);
2917
2918         if ( empty($wp_meta_boxes[$screen->id]) )
2919                 return;
2920
2921         $hidden = get_hidden_meta_boxes($screen);
2922
2923         foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
2924                 foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
2925                         foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
2926                                 if ( false == $box || ! $box['title'] )
2927                                         continue;
2928                                 // Submit box cannot be hidden
2929                                 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
2930                                         continue;
2931                                 $box_id = $box['id'];
2932                                 echo '<label for="' . $box_id . '-hide">';
2933                                 echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />';
2934                                 echo "{$box['title']}</label>\n";
2935                         }
2936                 }
2937         }
2938 }
2939
2940 /**
2941  * Get Hidden Meta Boxes
2942  *
2943  * @since 2.7
2944  *
2945  * @param string|object $screen Screen identifier
2946  * @return array Hidden Meta Boxes
2947  */
2948 function get_hidden_meta_boxes( $screen ) {
2949         if ( is_string( $screen ) )
2950                 $screen = convert_to_screen( $screen );
2951
2952         $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
2953
2954         // Hide slug boxes by default
2955         if ( !is_array( $hidden ) )
2956                 $hidden = array('slugdiv');
2957
2958         return $hidden;
2959 }
2960
2961 /**
2962  * Add a new section to a settings page.
2963  *
2964  * Part of the Settings API. Use this to define new settings sections for an admin page.
2965  * Show settings sections in your admin page callback function with do_settings_sections().
2966  * Add settings fields to your section with add_settings_field()
2967  *
2968  * The $callback argument should be the name of a function that echoes out any
2969  * content you want to show at the top of the settings section before the actual
2970  * fields. It can output nothing if you want.
2971  *
2972  * @since 2.7.0
2973  *
2974  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
2975  *
2976  * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
2977  * @param string $title Formatted title of the section. Shown as the heading for the section.
2978  * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
2979  * @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();
2980  */
2981 function add_settings_section($id, $title, $callback, $page) {
2982         global $wp_settings_sections;
2983
2984         if ( 'misc' == $page ) {
2985                 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
2986                 $page = 'general';
2987         }
2988
2989         if ( !isset($wp_settings_sections) )
2990                 $wp_settings_sections = array();
2991         if ( !isset($wp_settings_sections[$page]) )
2992                 $wp_settings_sections[$page] = array();
2993         if ( !isset($wp_settings_sections[$page][$id]) )
2994                 $wp_settings_sections[$page][$id] = array();
2995
2996         $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
2997 }
2998
2999 /**
3000  * Add a new field to a section of a settings page
3001  *
3002  * Part of the Settings API. Use this to define a settings field that will show
3003  * as part of a settings section inside a settings page. The fields are shown using
3004  * do_settings_fields() in do_settings-sections()
3005  *
3006  * The $callback argument should be the name of a function that echoes out the
3007  * html input tags for this setting field. Use get_option() to retrive existing
3008  * values to show.
3009  *
3010  * @since 2.7.0
3011  *
3012  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
3013  *
3014  * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
3015  * @param string $title Formatted title of the field. Shown as the label for the field during output.
3016  * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
3017  * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
3018  * @param string $section The slug-name of the section of the settingss page in which to show the box (default, ...).
3019  * @param array $args Additional arguments
3020  */
3021 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
3022         global $wp_settings_fields;
3023
3024         if ( 'misc' == $page ) {
3025                 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
3026                 $page = 'general';
3027         }
3028
3029         if ( !isset($wp_settings_fields) )
3030                 $wp_settings_fields = array();
3031         if ( !isset($wp_settings_fields[$page]) )
3032                 $wp_settings_fields[$page] = array();
3033         if ( !isset($wp_settings_fields[$page][$section]) )
3034                 $wp_settings_fields[$page][$section] = array();
3035
3036         $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
3037 }
3038
3039 /**
3040  * Prints out all settings sections added to a particular settings page
3041  *
3042  * Part of the Settings API. Use this in a settings page callback function
3043  * to output all the sections and fields that were added to that $page with
3044  * add_settings_section() and add_settings_field()
3045  *
3046  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
3047  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
3048  * @since unknown
3049  *
3050  * @param string $page The slug name of the page whos settings sections you want to output
3051  */
3052 function do_settings_sections($page) {
3053         global $wp_settings_sections, $wp_settings_fields;
3054
3055         if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
3056                 return;
3057
3058         foreach ( (array) $wp_settings_sections[$page] as $section ) {
3059                 echo "<h3>{$section['title']}</h3>\n";
3060                 call_user_func($section['callback'], $section);
3061                 if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
3062                         continue;
3063                 echo '<table class="form-table">';
3064                 do_settings_fields($page, $section['id']);
3065                 echo '</table>';
3066         }
3067 }
3068
3069 /**
3070  * Print out the settings fields for a particular settings section
3071  *
3072  * Part of the Settings API. Use this in a settings page to output
3073  * a specific section. Should normally be called by do_settings_sections()
3074  * rather than directly.
3075  *
3076  * @global $wp_settings_fields Storage array of settings fields and their pages/sections
3077  *
3078  * @since unknown
3079  *
3080  * @param string $page Slug title of the admin page who's settings fields you want to show.
3081  * @param section $section Slug title of the settings section who's fields you want to show.
3082  */
3083 function do_settings_fields($page, $section) {
3084         global $wp_settings_fields;
3085
3086         if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
3087                 return;
3088
3089         foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
3090                 echo '<tr valign="top">';
3091                 if ( !empty($field['args']['label_for']) )
3092                         echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
3093                 else
3094                         echo '<th scope="row">' . $field['title'] . '</th>';
3095                 echo '<td>';
3096                 call_user_func($field['callback'], $field['args']);
3097                 echo '</td>';
3098                 echo '</tr>';
3099         }
3100 }
3101
3102 /**
3103  * Register a settings error to be displayed to the user
3104  *
3105  * Part of the Settings API. Use this to show messages to users about settings validation
3106  * problems, missing settings or anything else.
3107  *
3108  * Settings errors should be added inside the $sanitize_callback function defined in
3109  * register_setting() for a given setting to give feedback about the submission.
3110  *
3111  * By default messages will show immediately after the submission that generated the error.
3112  * Additional calls to settings_errors() can be used to show errors even when the settings
3113  * page is first accessed.
3114  *
3115  * @global array $wp_settings_errors Storage array of errors registered during this pageload
3116  *
3117  * @param string $setting Slug title of the setting to which this error applies
3118  * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
3119  * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>)
3120  * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
3121  */
3122 function add_settings_error( $setting, $code, $message, $type = 'error' ) {
3123         global $wp_settings_errors;
3124
3125         if ( !isset($wp_settings_errors) )
3126                 $wp_settings_errors = array();
3127
3128         $new_error = array(
3129                 'setting' => $setting,
3130                 'code' => $code,
3131                 'message' => $message,
3132                 'type' => $type
3133         );
3134         $wp_settings_errors[] = $new_error;
3135 }
3136
3137 /**
3138  * Fetch settings errors registered by add_settings_error()
3139  *
3140  * Checks the $wp_settings_errors array for any errors declared during the current
3141  * pageload and returns them.
3142  *
3143  * If changes were just submitted ($_GET['updated']) and settings errors were saved
3144  * to the 'settings_errors' transient then those errors will be returned instead. This
3145  * is used to pass errors back across pageloads.
3146  *
3147  * Use the $sanitize argument to manually re-sanitize the option before returning errors.
3148  * This is useful if you have errors or notices you want to show even when the user
3149  * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
3150  *
3151  * @global array $wp_settings_errors Storage array of errors registered during this pageload
3152  *
3153  * @param string $setting Optional slug title of a specific setting who's errors you want.
3154  * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
3155  * @return array Array of settings errors
3156  */
3157 function get_settings_errors( $setting = '', $sanitize = FALSE ) {
3158         global $wp_settings_errors;
3159
3160         // If $sanitize is true, manually re-run the sanitizisation for this option
3161         // This allows the $sanitize_callback from register_setting() to run, adding
3162         // any settings errors you want to show by default.
3163         if ( $sanitize )
3164                 sanitize_option( $setting, get_option($setting));
3165
3166         // If settings were passed back from options.php then use them
3167         // Ignore transients if $sanitize is true, we dont' want the old values anyway
3168         if ( isset($_GET['updated']) && $_GET['updated'] && get_transient('settings_errors') ) {
3169                 $settings_errors = get_transient('settings_errors');
3170                 delete_transient('settings_errors');
3171         // Otherwise check global in case validation has been run on this pageload
3172         } elseif ( count( $wp_settings_errors ) ) {
3173                 $settings_errors = $wp_settings_errors;
3174         } else {
3175                 return;
3176         }
3177
3178         // Filter the results to those of a specific setting if one was set
3179         if ( $setting ) {
3180                 foreach ( (array) $settings_errors as $key => $details )
3181                         if ( $setting != $details['setting'] )
3182                                 unset( $settings_errors[$key] );
3183         }
3184         return $settings_errors;
3185 }
3186
3187 /**
3188  * Display settings errors registered by add_settings_error()
3189  *
3190  * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
3191  *
3192  * This is called automatically after a settings page based on the Settings API is submitted.
3193  * Errors should be added during the validation callback function for a setting defined in register_setting()
3194  *
3195  * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
3196  * on its current value.
3197  *
3198  * The $hide_on_update option will cause errors to only show when the settings page is first loaded.
3199  * if the user has already saved new values it will be hidden to avoid repeating messages already
3200  * shown in the default error reporting after submission. This is useful to show general errors like missing
3201  * settings when the user arrives at the settings page.
3202  *
3203  * @param string $setting Optional slug title of a specific setting who's errors you want.
3204  * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
3205  * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
3206  * @return <type>
3207  */
3208 function settings_errors ( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
3209
3210         if ($hide_on_update AND $_GET['updated']) return;
3211
3212         $settings_errors = get_settings_errors( $setting, $sanitize );
3213
3214         if ( !is_array($settings_errors) ) return;
3215
3216         $output = '';
3217         foreach ( $settings_errors as $key => $details ) {
3218                 $css_id = 'setting-error-' . $details['code'];
3219                 $css_class = $details['type'] . ' settings-error';
3220                 $output .= "<div id='$css_id' class='$css_class'> \n";
3221                 $output .= "<p><strong>{$details['message']}</strong></p>";
3222                 $output .= "</div> \n";
3223         }
3224         echo $output;
3225 }
3226
3227 /**
3228  * {@internal Missing Short Description}}
3229  *
3230  * @since unknown
3231  *
3232  * @param unknown_type $page
3233  */
3234 function manage_columns_prefs( $page ) {
3235         $columns = get_column_headers( $page );
3236         $hidden  = get_hidden_columns( $page );
3237         $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username');
3238
3239         foreach ( $columns as $column => $title ) {
3240                 // Can't hide these or they are special
3241                 if ( in_array( $column, $special ) )
3242                         continue;
3243                 if ( empty( $title ) )
3244                         continue;
3245
3246                 if ( 'comments' == $column )
3247                         $title = __( 'Comments' );
3248                 $id = "$column-hide";
3249                 echo '<label for="' . $id . '">';
3250                 echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . (! in_array($column, $hidden) ? ' checked="checked"' : '') . ' />';
3251                 echo "$title</label>\n";
3252         }
3253 }
3254
3255 /**
3256  * {@internal Missing Short Description}}
3257  *
3258  * @since unknown
3259  *
3260  * @param unknown_type $found_action
3261  */
3262 function find_posts_div($found_action = '') {
3263 ?>
3264         <div id="find-posts" class="find-box" style="display:none;">
3265                 <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
3266                 <div class="find-box-inside">
3267                         <div class="find-box-search">
3268                                 <?php if ( $found_action ) { ?>
3269                                         <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
3270                                 <?php } ?>
3271
3272                                 <input type="hidden" name="affected" id="affected" value="" />
3273                                 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
3274                                 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
3275                                 <input type="text" id="find-posts-input" name="ps" value="" />
3276                                 <input type="button" onclick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
3277
3278                                 <?php
3279                                 $post_types = get_post_types( array('public' => true), 'objects' );
3280                                 foreach ( $post_types as $post ) {
3281                                         if ( 'attachment' == $post->name )
3282                                                 continue;
3283                                 ?>
3284                                 <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'); ?> />
3285                                 <label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label>
3286                                 <?php
3287                                 } ?>
3288                         </div>
3289                         <div id="find-posts-response"></div>
3290                 </div>
3291                 <div class="find-box-buttons">
3292                         <input type="button" class="button alignleft" onclick="findPosts.close();" value="<?php esc_attr_e('Close'); ?>" />
3293                         <input id="find-posts-submit" type="submit" class="button-primary alignright" value="<?php esc_attr_e('Select'); ?>" />
3294                 </div>
3295         </div>
3296 <?php
3297 }
3298
3299 /**
3300  * Display the post password.
3301  *
3302  * The password is passed through {@link esc_attr()} to ensure that it
3303  * is safe for placing in an html attribute.
3304  *
3305  * @uses attr
3306  * @since 2.7.0
3307  */
3308 function the_post_password() {
3309         global $post;
3310         if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
3311 }
3312
3313 /**
3314  * {@internal Missing Short Description}}
3315  *
3316  * @since unknown
3317  */
3318 function favorite_actions( $screen = null ) {
3319         $default_action = false;
3320
3321         if ( is_string($screen) )
3322                 $screen = convert_to_screen($screen);
3323
3324         if ( isset($screen->post_type) ) {
3325                 $post_type_object = get_post_type_object($screen->post_type);
3326                 if ( 'add' != $screen->action )
3327                         $default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->cap->edit_posts));
3328                 else
3329                         $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->name, $post_type_object->cap->edit_posts));
3330         }
3331
3332         if ( !$default_action ) {
3333                 switch ( $screen->id ) {
3334                         case 'upload':
3335                                 $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
3336                                 break;
3337                         case 'media':
3338                                 $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
3339                                 break;
3340                         case 'link-manager':
3341                         case 'link':
3342                                 if ( 'add' != $screen->action )
3343                                         $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
3344                                 else
3345                                         $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
3346                                 break;
3347                         case 'users':
3348                                 $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
3349                                 break;
3350                         case 'user':
3351                                 $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
3352                                 break;
3353                         case 'plugins':
3354                                 $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
3355                                 break;
3356                         case 'plugin-install':
3357                                 $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
3358                                 break;
3359                         case 'themes':
3360                                 $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
3361                                 break;
3362                         case 'theme-install':
3363                                 $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
3364                                 break;
3365                         default:
3366                                 $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
3367                                 break;
3368                 }
3369         }
3370
3371         $actions = array(
3372                 'post-new.php' => array(__('New Post'), 'edit_posts'),
3373                 'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
3374                 'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
3375                 'media-new.php' => array(__('Upload'), 'upload_files'),
3376                 'edit-comments.php' => array(__('Comments'), 'moderate_comments')
3377                 );
3378
3379         $default_key = array_keys($default_action);
3380         $default_key = $default_key[0];
3381         if ( isset($actions[$default_key]) )
3382                 unset($actions[$default_key]);
3383         $actions = array_merge($default_action, $actions);
3384         $actions = apply_filters('favorite_actions', $actions);
3385
3386         $allowed_actions = array();
3387         foreach ( $actions as $action => $data ) {
3388                 if ( current_user_can($data[1]) )
3389                         $allowed_actions[$action] = $data[0];
3390         }
3391
3392         if ( empty($allowed_actions) )
3393                 return;
3394
3395         $first = array_keys($allowed_actions);
3396         $first = $first[0];
3397         echo '<div id="favorite-actions">';
3398         echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
3399         echo '<div id="favorite-inside">';
3400
3401         array_shift($allowed_actions);
3402
3403         foreach ( $allowed_actions as $action => $label) {
3404                 echo "<div class='favorite-action'><a href='$action'>";
3405                 echo $label;
3406                 echo "</a></div>\n";
3407         }
3408         echo "</div></div>\n";
3409 }
3410
3411 /**
3412  * Get the post title.
3413  *
3414  * The post title is fetched and if it is blank then a default string is
3415  * returned.
3416  *
3417  * @since 2.7.0
3418  * @param int $id The post id. If not supplied the global $post is used.
3419  *
3420  */
3421 function _draft_or_post_title($post_id = 0) {
3422         $title = get_the_title($post_id);
3423         if ( empty($title) )
3424                 $title = __('(no title)');
3425         return $title;
3426 }
3427
3428 /**
3429  * Display the search query.
3430  *
3431  * A simple wrapper to display the "s" parameter in a GET URI. This function
3432  * should only be used when {@link the_search_query()} cannot.
3433  *
3434  * @uses attr
3435  * @since 2.7.0
3436  *
3437  */
3438 function _admin_search_query() {
3439         echo isset($_GET['s']) ? esc_attr( stripslashes( $_GET['s'] ) ) : '';
3440 }
3441
3442 /**
3443  * Generic Iframe header for use with Thickbox
3444  *
3445  * @since 2.7.0
3446  * @param string $title Title of the Iframe page.
3447  * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
3448  *
3449  */
3450 function iframe_header( $title = '', $limit_styles = false ) {
3451 global $hook_suffix;
3452 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3453 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
3454 <head>
3455 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
3456 <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
3457 <?php
3458 wp_enqueue_style( 'global' );
3459 if ( ! $limit_styles )
3460         wp_enqueue_style( 'wp-admin' );
3461 wp_enqueue_style( 'colors' );
3462 ?>
3463 <script type="text/javascript">
3464 //<![CDATA[
3465 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();}}};
3466 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
3467 //]]>
3468 </script>
3469 <?php
3470 do_action('admin_print_styles');
3471 do_action('admin_print_scripts');
3472 do_action('admin_head');
3473
3474 $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
3475 ?>
3476 </head>
3477 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>  class="no-js <?php echo $admin_body_class; ?>">
3478 <script type="text/javascript">
3479 //<![CDATA[
3480 (function(){
3481 var c = document.body.className;
3482 c = c.replace(/no-js/, 'js');
3483 document.body.className = c;
3484 })();
3485 //]]>
3486 </script>
3487 <?php
3488 }
3489
3490 /**
3491  * Generic Iframe footer for use with Thickbox
3492  *
3493  * @since 2.7.0
3494  *
3495  */
3496 function iframe_footer() {
3497         //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?>
3498         <div class="hidden">
3499 <?php
3500         do_action('admin_footer', '');
3501         do_action('admin_print_footer_scripts'); ?>
3502         </div>
3503 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
3504 </body>
3505 </html>
3506 <?php
3507 }
3508
3509 function _post_states($post) {
3510         $post_states = array();
3511         if ( isset($_GET['post_status']) )
3512                 $post_status = $_GET['post_status'];
3513         else
3514                 $post_status = '';
3515
3516         if ( !empty($post->post_password) )
3517                 $post_states[] = __('Password protected');
3518         if ( 'private' == $post->post_status && 'private' != $post_status )
3519                 $post_states[] = __('Private');
3520         if ( 'draft' == $post->post_status && 'draft' != $post_status )
3521                 $post_states[] = __('Draft');
3522         if ( 'pending' == $post->post_status && 'pending' != $post_status )
3523                 /* translators: post state */
3524                 $post_states[] = _x('Pending', 'post state');
3525         if ( is_sticky($post->ID) )
3526                 $post_states[] = __('Sticky');
3527
3528         $post_states = apply_filters( 'display_post_states', $post_states );
3529
3530         if ( ! empty($post_states) ) {
3531                 $state_count = count($post_states);
3532                 $i = 0;
3533                 echo ' - ';
3534                 foreach ( $post_states as $state ) {
3535                         ++$i;
3536                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
3537                         echo "<span class='post-state'>$state$sep</span>";
3538                 }
3539         }
3540 }
3541
3542 /**
3543  * Convert a screen string to a screen object
3544  *
3545  * @since 3.0.0
3546  *
3547  * @param string $screen The name of the screen
3548  * @return object An object containing the safe screen name and id
3549  */
3550 function convert_to_screen( $screen ) {
3551         $screen = str_replace( array('.php', '-new', '-add' ), '', $screen);
3552         $screen = (string) apply_filters( 'screen_meta_screen', $screen );
3553         $screen = (object) array('id' => $screen, 'base' => $screen);
3554         return $screen;
3555 }
3556
3557 function screen_meta($screen) {
3558         global $wp_meta_boxes, $_wp_contextual_help, $title;
3559
3560         if ( is_string($screen) )
3561                 $screen = convert_to_screen($screen);
3562
3563         $column_screens = get_column_headers($screen);
3564         $meta_screens = array('index' => 'dashboard');
3565
3566         if ( isset($meta_screens[$screen->id]) ) {
3567                 $screen->id = $meta_screens[$screen->id];
3568                 $screen->base = $screen->id;
3569         }
3570
3571         $show_screen = false;
3572         if ( !empty($wp_meta_boxes[$screen->id]) || !empty($column_screens) )
3573                 $show_screen = true;
3574
3575         $screen_options = screen_options($screen);
3576         if ( $screen_options )
3577                 $show_screen = true;
3578
3579         if ( !isset($_wp_contextual_help) )
3580                 $_wp_contextual_help = array();
3581
3582         $settings = apply_filters('screen_settings', '', $screen);
3583
3584         switch ( $screen->id ) {
3585                 case 'widgets':
3586                         $settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n";
3587                         $show_screen = true;
3588                         break;
3589         }
3590         if( ! empty( $settings ) )
3591                 $show_screen = true;
3592 ?>
3593 <div id="screen-meta">
3594 <?php if ( $show_screen ) : ?>
3595 <div id="screen-options-wrap" class="hidden">
3596         <form id="adv-settings" action="" method="post">
3597         <?php if ( isset($wp_meta_boxes[$screen->id]) ) : ?>
3598                 <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
3599                 <div class="metabox-prefs">
3600                         <?php meta_box_prefs($screen); ?>
3601                         <br class="clear" />
3602                 </div>
3603                 <?php endif;
3604                 if ( ! empty($column_screens) ) : ?>
3605                 <h5><?php echo ( isset( $column_screens['_title'] ) ?  $column_screens['_title'] :  _x('Show on screen', 'Columns') ) ?></h5>
3606                 <div class="metabox-prefs">
3607                         <?php manage_columns_prefs($screen); ?>
3608                         <br class="clear" />
3609                 </div>
3610         <?php endif;
3611         echo screen_layout($screen);
3612
3613         if ( !empty( $screen_options ) ) {
3614                 ?>
3615                 <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
3616                 <?php
3617         }
3618
3619         echo $screen_options;
3620         echo $settings; ?>
3621 <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
3622 </form>
3623 </div>
3624
3625 <?php endif; // $show_screen
3626
3627         $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen);
3628         ?>
3629         <div id="contextual-help-wrap" class="hidden">
3630         <?php
3631         $contextual_help = '';
3632         if ( isset($_wp_contextual_help[$screen->id]) ) {
3633                 $contextual_help .= '<div class="metabox-prefs">' . $_wp_contextual_help[$screen->id] . "</div>\n";
3634         } else {
3635                 $contextual_help .= '<div class="metabox-prefs">';
3636                 $default_help = __('<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>');
3637                 $default_help .= '<br />';
3638                 $default_help .= __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>');
3639                 $contextual_help .= apply_filters('default_contextual_help', $default_help);
3640                 $contextual_help .= "</div>\n";
3641         }
3642
3643         echo apply_filters('contextual_help', $contextual_help, $screen->id, $screen);
3644         ?>
3645         </div>
3646
3647 <div id="screen-meta-links">
3648 <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
3649 <a href="#contextual-help" id="contextual-help-link" class="show-settings"><?php _e('Help') ?></a>
3650 </div>
3651 <?php if ( $show_screen ) { ?>
3652 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
3653 <a href="#screen-options" id="show-settings-link" class="show-settings"><?php _e('Screen Options') ?></a>
3654 </div>
3655 <?php } ?>
3656 </div>
3657 </div>
3658 <?php
3659 }
3660
3661 /**
3662  * Add contextual help text for a page
3663  *
3664  * @since 2.7.0
3665  *
3666  * @param string $screen The handle for the screen to add help to.  This is usually the hook name returned by the add_*_page() functions.
3667  * @param string $help Arbitrary help text
3668  */
3669 function add_contextual_help($screen, $help) {
3670         global $_wp_contextual_help;
3671
3672         if ( is_string($screen) )
3673                 $screen = convert_to_screen($screen);
3674
3675         if ( !isset($_wp_contextual_help) )
3676                 $_wp_contextual_help = array();
3677
3678         $_wp_contextual_help[$screen->id] = $help;
3679 }
3680
3681 function drag_drop_help() {
3682         return '
3683         <p>' .  __('Most of the modules on this screen can be moved. If you hover your mouse over the title bar of a module you&rsquo;ll notice the 4 arrow cursor appears to let you know it is movable. Click on it, hold down the mouse button and start dragging the module to a new location. As you drag the module, notice the dotted gray box that also moves. This box indicates where the module will be placed when you release the mouse button.') . '</p>
3684         <p>' . __('The same modules can be expanded and collapsed by clicking once on their title bar and also completely hidden from the Screen Options tab.') . '</p>
3685 ';
3686 }
3687
3688 function plugins_search_help() {
3689         return '
3690         <p><strong>' . __('Search help') . '</strong></p>' .
3691         '<p>' . __('You may search based on 3 criteria:') . '<br />' .
3692         __('<strong>Term:</strong> Searches theme names and descriptions for the specified term.') . '<br />' .
3693         __('<strong>Tag:</strong> Searches for themes tagged as such.') . '<br />' .
3694         __('<strong>Author:</strong> Searches for themes created by the Author, or which the Author contributed to.') . '</p>
3695 ';
3696 }
3697
3698 function screen_layout($screen) {
3699         global $screen_layout_columns;
3700
3701         if ( is_string($screen) )
3702                 $screen = convert_to_screen($screen);
3703
3704         $columns = array('dashboard' => 4, 'link' => 2);
3705
3706         // Add custom post types
3707         foreach ( get_post_types( array('show_ui' => true) ) as $post_type )
3708                 $columns[$post_type] = 2;
3709
3710         $columns = apply_filters('screen_layout_columns', $columns, $screen->id, $screen);
3711
3712         if ( !isset($columns[$screen->id]) ) {
3713                 $screen_layout_columns = 0;
3714                 return '';
3715         }
3716
3717         $screen_layout_columns = get_user_option("screen_layout_$screen->id");
3718         $num = $columns[$screen->id];
3719
3720         if ( ! $screen_layout_columns )
3721                         $screen_layout_columns = 2;
3722
3723         $i = 1;
3724         $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n";
3725         while ( $i <= $num ) {
3726                 $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n";
3727                 ++$i;
3728         }
3729         $return .= "</div>\n";
3730         return $return;
3731 }
3732
3733 function screen_options($screen) {
3734         if ( is_string($screen) )
3735                 $screen = convert_to_screen($screen);
3736
3737         switch ( $screen->base ) {
3738                 case 'edit':
3739                 case 'edit-pages':
3740                         $post_type = 'post';
3741                         if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('public' => true ) ) ) )
3742                                 $post_type = $_GET['post_type'];
3743                         $post_type_object = get_post_type_object($post_type);
3744                         $per_page_label = $post_type_object->labels->name;
3745                         break;
3746                 case 'ms-sites':
3747                         $per_page_label = _x( 'Sites', 'sites per page (screen options)' );
3748                         break;
3749                 case 'ms-users':
3750                         $per_page_label = _x( 'Users', 'users per page (screen options)' );
3751                         break;
3752                 case 'edit-comments':
3753                         $per_page_label = _x( 'Comments', 'comments per page (screen options)' );
3754                         break;
3755                 case 'upload':
3756                         $per_page_label = _x( 'Media items', 'items per page (screen options)' );
3757                         break;
3758                 case 'edit-tags':
3759                         global $tax;
3760                         $per_page_label = $tax->labels->name;
3761                         break;
3762                 case 'plugins':
3763                         $per_page_label = _x( 'Plugins', 'plugins per page (screen options)' );
3764                         break;
3765                 default:
3766                         return '';
3767         }
3768
3769         $option = str_replace( '-', '_', "{$screen->id}_per_page" );
3770         if ( 'edit_tags_per_page' == $option ) {
3771                 if ( 'category' == $tax->name )
3772                         $option = 'categories_per_page';
3773                 elseif ( 'post_tag' != $tax->name )
3774                         $option = 'edit_' . $tax->name . '_per_page';
3775         }
3776
3777         $per_page = (int) get_user_option( $option );
3778         if ( empty( $per_page ) || $per_page < 1 ) {
3779                 if ( 'plugins' == $screen->id )
3780                         $per_page = 999;
3781                 else
3782                         $per_page = 20;
3783         }
3784
3785         if ( 'edit_comments_per_page' == $option )
3786                 $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' );
3787         elseif ( 'categories_per_page' == $option )
3788                 $per_page = apply_filters( 'edit_categories_per_page', $per_page );
3789         else
3790                 $per_page = apply_filters( $option, $per_page );
3791
3792         $return = "<div class='screen-options'>\n";
3793         if ( !empty($per_page_label) )
3794                 $return .= "<input type='text' class='screen-per-page' name='wp_screen_options[value]' id='$option' maxlength='3' value='$per_page' /> <label for='$option'>$per_page_label</label>\n";
3795         $return .= "<input type='submit' class='button' value='" . esc_attr__('Apply') . "' />";
3796         $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
3797         $return .= "</div>\n";
3798         return $return;
3799 }
3800
3801 function screen_icon($screen = '') {
3802         global $current_screen;
3803
3804         if ( empty($screen) )
3805                 $screen = $current_screen;
3806         elseif ( is_string($screen) )
3807                 $name = $screen;
3808
3809         if ( empty($name) ) {
3810                 if ( !empty($screen->parent_base) )
3811                         $name = $screen->parent_base;
3812                 else
3813                         $name = $screen->base;
3814
3815                 if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
3816                         $name = 'edit-pages';
3817         }
3818
3819 ?>
3820         <div id="icon-<?php echo $name; ?>" class="icon32"><br /></div>
3821 <?php
3822 }
3823
3824 /**
3825  * Test support for compressing JavaScript from PHP
3826  *
3827  * Outputs JavaScript that tests if compression from PHP works as expected
3828  * and sets an option with the result. Has no effect when the current user
3829  * is not an administrator. To run the test again the option 'can_compress_scripts'
3830  * has to be deleted.
3831  *
3832  * @since 2.8.0
3833  */
3834 function compression_test() {
3835 ?>
3836         <script type="text/javascript">
3837         /* <![CDATA[ */
3838         var testCompression = {
3839                 get : function(test) {
3840                         var x;
3841                         if ( window.XMLHttpRequest ) {
3842                                 x = new XMLHttpRequest();
3843                         } else {
3844                                 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
3845                         }
3846
3847                         if (x) {
3848                                 x.onreadystatechange = function() {
3849                                         var r, h;
3850                                         if ( x.readyState == 4 ) {
3851                                                 r = x.responseText.substr(0, 18);
3852                                                 h = x.getResponseHeader('Content-Encoding');
3853                                                 testCompression.check(r, h, test);
3854                                         }
3855                                 }
3856
3857                                 x.open('GET', 'admin-ajax.php?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
3858                                 x.send('');
3859                         }
3860                 },
3861
3862                 check : function(r, h, test) {
3863                         if ( ! r && ! test )
3864                                 this.get(1);
3865
3866                         if ( 1 == test ) {
3867                                 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
3868                                         this.get('no');
3869                                 else
3870                                         this.get(2);
3871
3872                                 return;
3873                         }
3874
3875                         if ( 2 == test ) {
3876                                 if ( '"wpCompressionTest' == r )
3877                                         this.get('yes');
3878                                 else
3879                                         this.get('no');
3880                         }
3881                 }
3882         };
3883         testCompression.check();
3884         /* ]]> */
3885         </script>
3886 <?php
3887 }
3888
3889 /**
3890  * Set the current screen object
3891  *
3892  * @since 3.0.0
3893  *
3894  * @uses $current_screen
3895  *
3896  * @param string $id Screen id, optional.
3897  */
3898 function set_current_screen( $id =  '' ) {
3899         global $current_screen, $hook_suffix, $typenow, $taxnow;
3900
3901         $action = '';
3902
3903         if ( empty($id) ) {
3904                 $current_screen = $hook_suffix;
3905                 $current_screen = str_replace('.php', '', $current_screen);
3906                 if ( preg_match('/-add|-new$/', $current_screen) )
3907                         $action = 'add';
3908                 $current_screen = str_replace('-new', '', $current_screen);
3909                 $current_screen = str_replace('-add', '', $current_screen);
3910                 $current_screen = array('id' => $current_screen, 'base' => $current_screen);
3911         } else {
3912                 $id = sanitize_key($id);
3913                 if ( false !== strpos($id, '-') ) {
3914                         list( $id, $typenow ) = explode('-', $id, 2);
3915                         if ( taxonomy_exists( $typenow ) ) {
3916                                 $id = 'edit-tags';
3917                                 $taxnow = $typenow;
3918                                 $typenow = '';
3919                         }
3920                 }
3921                 $current_screen = array('id' => $id, 'base' => $id);
3922         }
3923
3924         $current_screen = (object) $current_screen;
3925
3926         $current_screen->action = $action;
3927
3928         // Map index to dashboard
3929         if ( 'index' == $current_screen->base )
3930                 $current_screen->base = 'dashboard';
3931         if ( 'index' == $current_screen->id )
3932                 $current_screen->id = 'dashboard';
3933
3934         if ( 'edit' == $current_screen->id ) {
3935                 if ( empty($typenow) )
3936                         $typenow = 'post';
3937                 $current_screen->id .= '-' . $typenow;
3938                 $current_screen->post_type = $typenow;
3939         } elseif ( 'post' == $current_screen->id ) {
3940                 if ( empty($typenow) )
3941                         $typenow = 'post';
3942                 $current_screen->id = $typenow;
3943                 $current_screen->post_type = $typenow;
3944         } elseif ( 'edit-tags' == $current_screen->id ) {
3945                 if ( empty($taxnow) )
3946                         $taxnow = 'post_tag';
3947                 $current_screen->id = 'edit-' . $taxnow;
3948                 $current_screen->taxonomy = $taxnow;
3949         }
3950
3951         $current_screen = apply_filters('current_screen', $current_screen);
3952 }
3953
3954 ?>