]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/template.php
Wordpress 3.0.6
[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 $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( get_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 = htmlspecialchars( trim( $post->post_title ), ENT_QUOTES );
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">' . esc_html( $post->comment_status ) . '</div>
1196         <div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
1197         <div class="_status">' . esc_html( $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_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 = ( get_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?post_type={$post->post_type}&amp;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?post_type={$post->post_type}&amp;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         if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
1799                 $user_object = new WP_User( (int) $user_object );
1800         $user_object = sanitize_user_object($user_object, 'display');
1801         $email = $user_object->user_email;
1802         $url = $user_object->user_url;
1803         $short_url = str_replace( 'http://', '', $url );
1804         $short_url = str_replace( 'www.', '', $short_url );
1805         if ('/' == substr( $short_url, -1 ))
1806                 $short_url = substr( $short_url, 0, -1 );
1807         if ( strlen( $short_url ) > 35 )
1808                 $short_url = substr( $short_url, 0, 32 ).'...';
1809         $checkbox = '';
1810         // Check if the user for this row is editable
1811         if ( current_user_can( 'list_users' ) ) {
1812                 // Set up the user editing link
1813                 // TODO: make profile/user-edit determination a separate function
1814                 if ( get_current_user_id() == $user_object->ID) {
1815                         $edit_link = 'profile.php';
1816                 } else {
1817                         $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" ) );
1818                 }
1819                 $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
1820
1821                 // Set up the hover actions for this user
1822                 $actions = array();
1823
1824                 if ( current_user_can('edit_user',  $user_object->ID) ) {
1825                         $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
1826                         $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1827                 } else {
1828                         $edit = "<strong>$user_object->user_login</strong><br />";
1829                 }
1830
1831                 if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('delete_user', $user_object->ID) )
1832                         $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=delete&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Delete') . "</a>";
1833                 if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('remove_user', $user_object->ID) )
1834                         $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=remove&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Remove') . "</a>";
1835                 $actions = apply_filters('user_row_actions', $actions, $user_object);
1836                 $action_count = count($actions);
1837                 $i = 0;
1838                 $edit .= '<div class="row-actions">';
1839                 foreach ( $actions as $action => $link ) {
1840                         ++$i;
1841                         ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
1842                         $edit .= "<span class='$action'>$link$sep</span>";
1843                 }
1844                 $edit .= '</div>';
1845
1846                 // Set up the checkbox (because the user is editable, otherwise its empty)
1847                 $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
1848
1849         } else {
1850                 $edit = '<strong>' . $user_object->user_login . '</strong>';
1851         }
1852         $role_name = isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : __('None');
1853         $r = "<tr id='user-$user_object->ID'$style>";
1854         $columns = get_column_headers('users');
1855         $hidden = get_hidden_columns('users');
1856         $avatar = get_avatar( $user_object->ID, 32 );
1857         foreach ( $columns as $column_name => $column_display_name ) {
1858                 $class = "class=\"$column_name column-$column_name\"";
1859
1860                 $style = '';
1861                 if ( in_array($column_name, $hidden) )
1862                         $style = ' style="display:none;"';
1863
1864                 $attributes = "$class$style";
1865
1866                 switch ($column_name) {
1867                         case 'cb':
1868                                 $r .= "<th scope='row' class='check-column'>$checkbox</th>";
1869                                 break;
1870                         case 'username':
1871                                 $r .= "<td $attributes>$avatar $edit</td>";
1872                                 break;
1873                         case 'name':
1874                                 $r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>";
1875                                 break;
1876                         case 'email':
1877                                 $r .= "<td $attributes><a href='mailto:$email' title='" . sprintf( __('E-mail: %s' ), $email ) . "'>$email</a></td>";
1878                                 break;
1879                         case 'role':
1880                                 $r .= "<td $attributes>$role_name</td>";
1881                                 break;
1882                         case 'posts':
1883                                 $attributes = 'class="posts column-posts num"' . $style;
1884                                 $r .= "<td $attributes>";
1885                                 if ( $numposts > 0 ) {
1886                                         $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
1887                                         $r .= $numposts;
1888                                         $r .= '</a>';
1889                                 } else {
1890                                         $r .= 0;
1891                                 }
1892                                 $r .= "</td>";
1893                                 break;
1894                         default:
1895                                 $r .= "<td $attributes>";
1896                                 $r .= apply_filters('manage_users_custom_column', '', $column_name, $user_object->ID);
1897                                 $r .= "</td>";
1898                 }
1899         }
1900         $r .= '</tr>';
1901
1902         return $r;
1903 }
1904
1905 /**
1906  * {@internal Missing Short Description}}
1907  *
1908  * @since unknown
1909  *
1910  * @param string $status Comment status (approved, spam, trash, etc)
1911  * @param string $s Term to search for
1912  * @param int $start Offset to start at for pagination
1913  * @param int $num Maximum number of comments to return
1914  * @param int $post Post ID or 0 to return all comments
1915  * @param string $type Comment type (comment, trackback, pingback, etc)
1916  * @return array [0] contains the comments and [1] contains the total number of comments that match (ignoring $start and $num)
1917  */
1918 function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0, $type = '' ) {
1919         global $wpdb;
1920
1921         $start = abs( (int) $start );
1922         $num = (int) $num;
1923         $post = (int) $post;
1924         $count = wp_count_comments();
1925         $index = '';
1926
1927         if ( 'moderated' == $status ) {
1928                 $approved = "c.comment_approved = '0'";
1929                 $total = $count->moderated;
1930         } elseif ( 'approved' == $status ) {
1931                 $approved = "c.comment_approved = '1'";
1932                 $total = $count->approved;
1933         } elseif ( 'spam' == $status ) {
1934                 $approved = "c.comment_approved = 'spam'";
1935                 $total = $count->spam;
1936         } elseif ( 'trash' == $status ) {
1937                 $approved = "c.comment_approved = 'trash'";
1938                 $total = $count->trash;
1939         } else {
1940                 $approved = "( c.comment_approved = '0' OR c.comment_approved = '1' )";
1941                 $total = $count->moderated + $count->approved;
1942                 $index = 'USE INDEX (c.comment_date_gmt)';
1943         }
1944
1945         if ( $post ) {
1946                 $total = '';
1947                 $post = " AND c.comment_post_ID = '$post'";
1948         } else {
1949                 $post = '';
1950         }
1951
1952         $orderby = "ORDER BY c.comment_date_gmt DESC LIMIT $start, $num";
1953
1954         if ( 'comment' == $type )
1955                 $typesql = "AND c.comment_type = ''";
1956         elseif ( 'pings' == $type )
1957                 $typesql = "AND ( c.comment_type = 'pingback' OR c.comment_type = 'trackback' )";
1958         elseif ( 'all' == $type )
1959                 $typesql = '';
1960         elseif ( !empty($type) )
1961                 $typesql = $wpdb->prepare("AND c.comment_type = %s", $type);
1962         else
1963                 $typesql = '';
1964
1965         if ( !empty($type) )
1966                 $total = '';
1967
1968         $query = "FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ";
1969         if ( $s ) {
1970                 $total = '';
1971                 $s = $wpdb->escape($s);
1972                 $query .= "AND
1973                         (c.comment_author LIKE '%$s%' OR
1974                         c.comment_author_email LIKE '%$s%' OR
1975                         c.comment_author_url LIKE ('%$s%') OR
1976                         c.comment_author_IP LIKE ('%$s%') OR
1977                         c.comment_content LIKE ('%$s%') ) AND
1978                         $approved
1979                         $typesql";
1980         } else {
1981                 $query .= "AND $approved $post $typesql";
1982         }
1983
1984         $comments = $wpdb->get_results("SELECT * $query $orderby");
1985         if ( '' === $total )
1986                 $total = $wpdb->get_var("SELECT COUNT(c.comment_ID) $query");
1987
1988         update_comment_cache($comments);
1989
1990         return array($comments, $total);
1991 }
1992
1993 /**
1994  * {@internal Missing Short Description}}
1995  *
1996  * @since unknown
1997  *
1998  * @param unknown_type $comment_id
1999  * @param unknown_type $mode
2000  * @param unknown_type $comment_status
2001  * @param unknown_type $checkbox
2002  */
2003 function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true, $from_ajax = false ) {
2004         global $comment, $post, $_comment_pending_count;
2005         $comment = get_comment( $comment_id );
2006         $post = get_post($comment->comment_post_ID);
2007         $the_comment_status = wp_get_comment_status($comment->comment_ID);
2008         $post_type_object = get_post_type_object($post->post_type);
2009         $user_can = current_user_can($post_type_object->cap->edit_post, $post->ID);
2010
2011         $comment_url = esc_url(get_comment_link($comment->comment_ID));
2012         $author_url = get_comment_author_url();
2013         if ( 'http://' == $author_url )
2014                 $author_url = '';
2015         $author_url_display = preg_replace('|http://(www\.)?|i', '', $author_url);
2016         if ( strlen($author_url_display) > 50 )
2017                 $author_url_display = substr($author_url_display, 0, 49) . '...';
2018
2019         $ptime = date('G', strtotime( $comment->comment_date ) );
2020         if ( ( abs(time() - $ptime) ) < 86400 )
2021                 $ptime = sprintf( __('%s ago'), human_time_diff( $ptime ) );
2022         else
2023                 $ptime = mysql2date(__('Y/m/d \a\t g:i A'), $comment->comment_date );
2024
2025         if ( $user_can ) {
2026                 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
2027                 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
2028
2029                 $approve_url = esc_url( "comment.php?action=approvecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
2030                 $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
2031                 $spam_url = esc_url( "comment.php?action=spamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2032                 $unspam_url = esc_url( "comment.php?action=unspamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2033                 $trash_url = esc_url( "comment.php?action=trashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2034                 $untrash_url = esc_url( "comment.php?action=untrashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2035                 $delete_url = esc_url( "comment.php?action=deletecomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2036         }
2037
2038         echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>";
2039         $columns = get_column_headers('edit-comments');
2040         $hidden = get_hidden_columns('edit-comments');
2041         foreach ( $columns as $column_name => $column_display_name ) {
2042                 $class = "class=\"$column_name column-$column_name\"";
2043
2044                 $style = '';
2045                 if ( in_array($column_name, $hidden) )
2046                         $style = ' style="display:none;"';
2047
2048                 $attributes = "$class$style";
2049
2050                 switch ($column_name) {
2051                         case 'cb':
2052                                 if ( !$checkbox ) break;
2053                                 echo '<th scope="row" class="check-column">';
2054                                 if ( $user_can ) echo "<input type='checkbox' name='delete_comments[]' value='$comment->comment_ID' />";
2055                                 echo '</th>';
2056                                 break;
2057                         case 'comment':
2058                                 echo "<td $attributes>";
2059                                 echo '<div id="submitted-on">';
2060                                 /* translators: 2: comment date, 3: comment time */
2061                                 printf( __( '<a href="%1$s">%2$s at %3$s</a>' ), $comment_url,
2062                                         /* translators: comment date format. See http://php.net/date */ get_comment_date( __('Y/m/d') ),
2063                                         /* translators: comment time format. See http://php.net/date */ get_comment_date( get_option( 'time_format' ) ) );
2064
2065                                 if ( $comment->comment_parent ) {
2066                                         $parent = get_comment( $comment->comment_parent );
2067                                         $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
2068                                         $name = apply_filters( 'get_comment_author', $parent->comment_author ); // there's no API function for this
2069                                         printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
2070                                 }
2071
2072                                 echo '</div>';
2073                                 comment_text();
2074                                 if ( $user_can ) { ?>
2075                                 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
2076                                 <textarea class="comment" rows="1" cols="1"><?php echo htmlspecialchars( apply_filters('comment_edit_pre', $comment->comment_content), ENT_QUOTES ); ?></textarea>
2077                                 <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
2078                                 <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
2079                                 <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
2080                                 <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
2081                                 </div>
2082                                 <?php
2083                                 }
2084
2085                                 if ( $user_can ) {
2086                                         // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
2087                                         $actions = array(
2088                                                 'approve' => '', 'unapprove' => '',
2089                                                 'reply' => '',
2090                                                 'quickedit' => '',
2091                                                 'edit' => '',
2092                                                 'spam' => '', 'unspam' => '',
2093                                                 'trash' => '', 'untrash' => '', 'delete' => ''
2094                                         );
2095
2096                                         if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
2097                                                 if ( 'approved' == $the_comment_status )
2098                                                         $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>';
2099                                                 else if ( 'unapproved' == $the_comment_status )
2100                                                         $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>';
2101                                         } else {
2102                                                 $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>';
2103                                                 $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>';
2104                                         }
2105
2106                                         if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
2107                                                 $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>';
2108                                         } elseif ( 'spam' == $the_comment_status ) {
2109                                                 $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>';
2110                                         } elseif ( 'trash' == $the_comment_status ) {
2111                                                 $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
2112                                         }
2113
2114                                         if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
2115                                                 $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>';
2116                                         } else {
2117                                                 $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>';
2118                                         }
2119
2120                                         if ( 'trash' != $the_comment_status ) {
2121                                                 $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
2122                                                 $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>';
2123                                                 if ( 'spam' != $the_comment_status )
2124                                                         $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>';
2125                                         }
2126
2127                                         $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
2128
2129                                         $i = 0;
2130                                         echo '<div class="row-actions">';
2131                                         foreach ( $actions as $action => $link ) {
2132                                                 ++$i;
2133                                                 ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
2134
2135                                                 // Reply and quickedit need a hide-if-no-js span when not added with ajax
2136                                                 if ( ('reply' == $action || 'quickedit' == $action) && ! $from_ajax )
2137                                                         $action .= ' hide-if-no-js';
2138                                                 elseif ( ($action == 'untrash' && $the_comment_status == 'trash') || ($action == 'unspam' && $the_comment_status == 'spam') ) {
2139                                                         if ('1' == get_comment_meta($comment_id, '_wp_trash_meta_status', true))
2140                                                                 $action .= ' approve';
2141                                                         else
2142                                                                 $action .= ' unapprove';
2143                                                 }
2144
2145                                                 echo "<span class='$action'>$sep$link</span>";
2146                                         }
2147                                         echo '</div>';
2148                                 }
2149
2150                                 echo '</td>';
2151                                 break;
2152                         case 'author':
2153                                 echo "<td $attributes><strong>"; comment_author(); echo '</strong><br />';
2154                                 if ( !empty($author_url) )
2155                                         echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />";
2156                                 if ( $user_can ) {
2157                                         if ( !empty($comment->comment_author_email) ) {
2158                                                 comment_author_email_link();
2159                                                 echo '<br />';
2160                                         }
2161                                         echo '<a href="edit-comments.php?s=';
2162                                         comment_author_IP();
2163                                         echo '&amp;mode=detail';
2164                                         if ( 'spam' == $comment_status )
2165                                                 echo '&amp;comment_status=spam';
2166                                         echo '">';
2167                                         comment_author_IP();
2168                                         echo '</a>';
2169                                 } //current_user_can
2170                                 echo '</td>';
2171                                 break;
2172                         case 'date':
2173                                 echo "<td $attributes>" . get_comment_date(__('Y/m/d \a\t g:ia')) . '</td>';
2174                                 break;
2175                         case 'response':
2176                                 if ( 'single' !== $mode ) {
2177                                         if ( isset( $_comment_pending_count[$post->ID] ) ) {
2178                                                 $pending_comments = $_comment_pending_count[$post->ID];
2179                                         } else {
2180                                                 $_comment_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
2181                                                 $pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp[$post->ID];
2182                                         }
2183                                         if ( $user_can ) {
2184                                                 $post_link = "<a href='" . get_edit_post_link($post->ID) . "'>";
2185                                                 $post_link .= get_the_title($post->ID) . '</a>';
2186                                         } else {
2187                                                 $post_link = get_the_title($post->ID);
2188                                         }
2189                                         echo "<td $attributes>\n";
2190                                         echo '<div class="response-links"><span class="post-com-count-wrapper">';
2191                                         echo $post_link . '<br />';
2192                                         $pending_phrase = esc_attr(sprintf( __('%s pending'), number_format( $pending_comments ) ));
2193                                         if ( $pending_comments )
2194                                                 echo '<strong>';
2195                                         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>');
2196                                         if ( $pending_comments )
2197                                                 echo '</strong>';
2198                                         echo '</span> ';
2199                                         echo "<a href='" . get_permalink( $post->ID ) . "'>#</a>";
2200                                         echo '</div>';
2201                                         if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) )
2202                                                 echo $thumb;
2203                                         echo '</td>';
2204                                 }
2205                                 break;
2206                         default:
2207                                 echo "<td $attributes>\n";
2208                                 do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
2209                                 echo "</td>\n";
2210                                 break;
2211                 }
2212         }
2213         echo "</tr>\n";
2214 }
2215
2216 /**
2217  * {@internal Missing Short Description}}
2218  *
2219  * @since unknown
2220  *
2221  * @param unknown_type $position
2222  * @param unknown_type $checkbox
2223  * @param unknown_type $mode
2224  */
2225 function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
2226         // allow plugin to replace the popup content
2227         $content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) );
2228
2229         if ( ! empty($content) ) {
2230                 echo $content;
2231                 return;
2232         }
2233
2234         $columns = get_column_headers('edit-comments');
2235         $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns('edit-comments') ) );
2236         $col_count = count($columns) - count($hidden);
2237
2238 ?>
2239 <form method="get" action="">
2240 <?php if ( $table_row ) : ?>
2241 <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $col_count; ?>">
2242 <?php else : ?>
2243 <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
2244 <?php endif; ?>
2245         <div id="replyhead" style="display:none;"><?php _e('Reply to Comment'); ?></div>
2246
2247         <div id="edithead" style="display:none;">
2248                 <div class="inside">
2249                 <label for="author"><?php _e('Name') ?></label>
2250                 <input type="text" name="newcomment_author" size="50" value="" tabindex="101" id="author" />
2251                 </div>
2252
2253                 <div class="inside">
2254                 <label for="author-email"><?php _e('E-mail') ?></label>
2255                 <input type="text" name="newcomment_author_email" size="50" value="" tabindex="102" id="author-email" />
2256                 </div>
2257
2258                 <div class="inside">
2259                 <label for="author-url"><?php _e('URL') ?></label>
2260                 <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" tabindex="103" />
2261                 </div>
2262                 <div style="clear:both;"></div>
2263         </div>
2264
2265         <div id="replycontainer"><textarea rows="8" cols="40" name="replycontent" tabindex="104" id="replycontent"></textarea></div>
2266
2267         <p id="replysubmit" class="submit">
2268         <a href="#comments-form" class="cancel button-secondary alignleft" tabindex="106"><?php _e('Cancel'); ?></a>
2269         <a href="#comments-form" class="save button-primary alignright" tabindex="104">
2270         <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
2271         <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
2272         <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
2273         <span class="error" style="display:none;"></span>
2274         <br class="clear" />
2275         </p>
2276
2277         <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" />
2278         <input type="hidden" name="action" id="action" value="" />
2279         <input type="hidden" name="comment_ID" id="comment_ID" value="" />
2280         <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
2281         <input type="hidden" name="status" id="status" value="" />
2282         <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
2283         <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
2284         <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
2285         <?php wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false ); ?>
2286         <?php wp_comment_form_unfiltered_html_nonce(); ?>
2287 <?php if ( $table_row ) : ?>
2288 </td></tr></tbody></table>
2289 <?php else : ?>
2290 </div></div>
2291 <?php endif; ?>
2292 </form>
2293 <?php
2294 }
2295
2296 /**
2297  * Output 'undo move to trash' text for comments
2298  *
2299  * @since 2.9.0
2300  */
2301 function wp_comment_trashnotice() {
2302 ?>
2303 <div class="hidden" id="trash-undo-holder">
2304         <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>
2305 </div>
2306 <div class="hidden" id="spam-undo-holder">
2307         <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>
2308 </div>
2309 <?php
2310 }
2311
2312 /**
2313  * {@internal Missing Short Description}}
2314  *
2315  * @since unknown
2316  *
2317  * @param unknown_type $meta
2318  */
2319 function list_meta( $meta ) {
2320         // Exit if no meta
2321         if ( ! $meta ) {
2322                 echo '
2323 <table id="list-table" style="display: none;">
2324         <thead>
2325         <tr>
2326                 <th class="left">' . __( 'Name' ) . '</th>
2327                 <th>' . __( 'Value' ) . '</th>
2328         </tr>
2329         </thead>
2330         <tbody id="the-list" class="list:meta">
2331         <tr><td></td></tr>
2332         </tbody>
2333 </table>'; //TBODY needed for list-manipulation JS
2334                 return;
2335         }
2336         $count = 0;
2337 ?>
2338 <table id="list-table">
2339         <thead>
2340         <tr>
2341                 <th class="left"><?php _e( 'Name' ) ?></th>
2342                 <th><?php _e( 'Value' ) ?></th>
2343         </tr>
2344         </thead>
2345         <tbody id='the-list' class='list:meta'>
2346 <?php
2347         foreach ( $meta as $entry )
2348                 echo _list_meta_row( $entry, $count );
2349 ?>
2350         </tbody>
2351 </table>
2352 <?php
2353 }
2354
2355 /**
2356  * {@internal Missing Short Description}}
2357  *
2358  * @since unknown
2359  *
2360  * @param unknown_type $entry
2361  * @param unknown_type $count
2362  * @return unknown
2363  */
2364 function _list_meta_row( $entry, &$count ) {
2365         static $update_nonce = false;
2366         if ( !$update_nonce )
2367                 $update_nonce = wp_create_nonce( 'add-meta' );
2368
2369         $r = '';
2370         ++ $count;
2371         if ( $count % 2 )
2372                 $style = 'alternate';
2373         else
2374                 $style = '';
2375         if ('_' == $entry['meta_key'] { 0 } )
2376                 $style .= ' hidden';
2377
2378         if ( is_serialized( $entry['meta_value'] ) ) {
2379                 if ( is_serialized_string( $entry['meta_value'] ) ) {
2380                         // this is a serialized string, so we should display it
2381                         $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
2382                 } else {
2383                         // this is a serialized array/object so we should NOT display it
2384                         --$count;
2385                         return;
2386                 }
2387         }
2388
2389         $entry['meta_key'] = esc_attr($entry['meta_key']);
2390         $entry['meta_value'] = htmlspecialchars($entry['meta_value']); // using a <textarea />
2391         $entry['meta_id'] = (int) $entry['meta_id'];
2392
2393         $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
2394
2395         $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
2396         $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']}' />";
2397
2398         $r .= "\n\t\t<div class='submit'><input name='deletemeta[{$entry['meta_id']}]' type='submit' ";
2399         $r .= "class='delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta' tabindex='6' value='". esc_attr__( 'Delete' ) ."' />";
2400         $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>";
2401         $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
2402         $r .= "</td>";
2403
2404         $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>";
2405         return $r;
2406 }
2407
2408 /**
2409  * {@internal Missing Short Description}}
2410  *
2411  * @since unknown
2412  */
2413 function meta_form() {
2414         global $wpdb;
2415         $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
2416         $keys = $wpdb->get_col( "
2417                 SELECT meta_key
2418                 FROM $wpdb->postmeta
2419                 GROUP BY meta_key
2420                 HAVING meta_key NOT LIKE '\_%'
2421                 ORDER BY meta_key
2422                 LIMIT $limit" );
2423         if ( $keys )
2424                 natcasesort($keys);
2425 ?>
2426 <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
2427 <table id="newmeta">
2428 <thead>
2429 <tr>
2430 <th class="left"><label for="metakeyselect"><?php _e( 'Name' ) ?></label></th>
2431 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
2432 </tr>
2433 </thead>
2434
2435 <tbody>
2436 <tr>
2437 <td id="newmetaleft" class="left">
2438 <?php if ( $keys ) { ?>
2439 <select id="metakeyselect" name="metakeyselect" tabindex="7">
2440 <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
2441 <?php
2442
2443         foreach ( $keys as $key ) {
2444                 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
2445         }
2446 ?>
2447 </select>
2448 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
2449 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
2450 <span id="enternew"><?php _e('Enter new'); ?></span>
2451 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
2452 <?php } else { ?>
2453 <input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
2454 <?php } ?>
2455 </td>
2456 <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td>
2457 </tr>
2458
2459 <tr><td colspan="2" class="submit">
2460 <input type="submit" id="addmetasub" name="addmeta" class="add:the-list:newmeta" tabindex="9" value="<?php esc_attr_e( 'Add Custom Field' ) ?>" />
2461 <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
2462 </td></tr>
2463 </tbody>
2464 </table>
2465 <?php
2466
2467 }
2468
2469 /**
2470  * {@internal Missing Short Description}}
2471  *
2472  * @since unknown
2473  *
2474  * @param unknown_type $edit
2475  * @param unknown_type $for_post
2476  * @param unknown_type $tab_index
2477  * @param unknown_type $multi
2478  */
2479 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
2480         global $wp_locale, $post, $comment;
2481
2482         if ( $for_post )
2483                 $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
2484
2485         $tab_index_attribute = '';
2486         if ( (int) $tab_index > 0 )
2487                 $tab_index_attribute = " tabindex=\"$tab_index\"";
2488
2489         // 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 />';
2490
2491         $time_adj = current_time('timestamp');
2492         $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
2493         $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
2494         $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
2495         $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
2496         $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
2497         $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
2498         $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
2499
2500         $cur_jj = gmdate( 'd', $time_adj );
2501         $cur_mm = gmdate( 'm', $time_adj );
2502         $cur_aa = gmdate( 'Y', $time_adj );
2503         $cur_hh = gmdate( 'H', $time_adj );
2504         $cur_mn = gmdate( 'i', $time_adj );
2505
2506         $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
2507         for ( $i = 1; $i < 13; $i = $i +1 ) {
2508                 $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
2509                 if ( $i == $mm )
2510                         $month .= ' selected="selected"';
2511                 $month .= '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
2512         }
2513         $month .= '</select>';
2514
2515         $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
2516         $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
2517         $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
2518         $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
2519
2520         echo '<div class="timestamp-wrap">';
2521         /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
2522         printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
2523
2524         echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
2525
2526         if ( $multi ) return;
2527
2528         echo "\n\n";
2529         foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) {
2530                 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
2531                 $cur_timeunit = 'cur_' . $timeunit;
2532                 echo '<input type="hidden" id="'. $cur_timeunit . '" name="'. $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
2533         }
2534 ?>
2535
2536 <p>
2537 <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
2538 <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
2539 </p>
2540 <?php
2541 }
2542
2543 /**
2544  * {@internal Missing Short Description}}
2545  *
2546  * @since unknown
2547  *
2548  * @param unknown_type $default
2549  */
2550 function page_template_dropdown( $default = '' ) {
2551         $templates = get_page_templates();
2552         ksort( $templates );
2553         foreach (array_keys( $templates ) as $template )
2554                 : if ( $default == $templates[$template] )
2555                         $selected = " selected='selected'";
2556                 else
2557                         $selected = '';
2558         echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
2559         endforeach;
2560 }
2561
2562 /**
2563  * {@internal Missing Short Description}}
2564  *
2565  * @since unknown
2566  *
2567  * @param unknown_type $default
2568  * @param unknown_type $parent
2569  * @param unknown_type $level
2570  * @return unknown
2571  */
2572 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
2573         global $wpdb, $post_ID;
2574         $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) );
2575
2576         if ( $items ) {
2577                 foreach ( $items as $item ) {
2578                         // A page cannot be its own parent.
2579                         if (!empty ( $post_ID ) ) {
2580                                 if ( $item->ID == $post_ID ) {
2581                                         continue;
2582                                 }
2583                         }
2584                         $pad = str_repeat( '&nbsp;', $level * 3 );
2585                         if ( $item->ID == $default)
2586                                 $current = ' selected="selected"';
2587                         else
2588                                 $current = '';
2589
2590                         echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";
2591                         parent_dropdown( $default, $item->ID, $level +1 );
2592                 }
2593         } else {
2594                 return false;
2595         }
2596 }
2597
2598 /**
2599  * {@internal Missing Short Description}}
2600  *
2601  * @since unknown
2602  *
2603  * @param unknown_type $id
2604  * @return unknown
2605  */
2606 function the_attachment_links( $id = false ) {
2607         $id = (int) $id;
2608         $post = & get_post( $id );
2609
2610         if ( $post->post_type != 'attachment' )
2611                 return false;
2612
2613         $icon = wp_get_attachment_image( $post->ID, 'thumbnail', true );
2614         $attachment_data = wp_get_attachment_metadata( $id );
2615         $thumb = isset( $attachment_data['thumb'] );
2616 ?>
2617 <form id="the-attachment-links">
2618 <table>
2619         <col />
2620         <col class="widefat" />
2621         <tr>
2622                 <th scope="row"><?php _e( 'URL' ) ?></th>
2623                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
2624         </tr>
2625 <?php if ( $icon ) : ?>
2626         <tr>
2627                 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
2628                 <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>
2629         </tr>
2630         <tr>
2631                 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
2632                 <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>
2633         </tr>
2634 <?php else : ?>
2635         <tr>
2636                 <th scope="row"><?php _e( 'Link to file' ) ?></th>
2637                 <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>
2638         </tr>
2639         <tr>
2640                 <th scope="row"><?php _e( 'Link to page' ) ?></th>
2641                 <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>
2642         </tr>
2643 <?php endif; ?>
2644 </table>
2645 </form>
2646 <?php
2647 }
2648
2649
2650 /**
2651  * Print out <option> html elements for role selectors based on $wp_roles
2652  *
2653  * @package WordPress
2654  * @subpackage Administration
2655  * @since 2.1
2656  *
2657  * @uses $wp_roles
2658  * @param string $default slug for the role that should be already selected
2659  */
2660 function wp_dropdown_roles( $selected = false ) {
2661         $p = '';
2662         $r = '';
2663
2664         $editable_roles = get_editable_roles();
2665
2666         foreach ( $editable_roles as $role => $details ) {
2667                 $name = translate_user_role($details['name'] );
2668                 if ( $selected == $role ) // Make default first in list
2669                         $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
2670                 else
2671                         $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
2672         }
2673         echo $p . $r;
2674 }
2675
2676 /**
2677  * {@internal Missing Short Description}}
2678  *
2679  * @since unknown
2680  *
2681  * @param unknown_type $size
2682  * @return unknown
2683  */
2684 function wp_convert_hr_to_bytes( $size ) {
2685         $size = strtolower($size);
2686         $bytes = (int) $size;
2687         if ( strpos($size, 'k') !== false )
2688                 $bytes = intval($size) * 1024;
2689         elseif ( strpos($size, 'm') !== false )
2690                 $bytes = intval($size) * 1024 * 1024;
2691         elseif ( strpos($size, 'g') !== false )
2692                 $bytes = intval($size) * 1024 * 1024 * 1024;
2693         return $bytes;
2694 }
2695
2696 /**
2697  * {@internal Missing Short Description}}
2698  *
2699  * @since unknown
2700  *
2701  * @param unknown_type $bytes
2702  * @return unknown
2703  */
2704 function wp_convert_bytes_to_hr( $bytes ) {
2705         $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
2706         $log = log( $bytes, 1024 );
2707         $power = (int) $log;
2708         $size = pow(1024, $log - $power);
2709         return $size . $units[$power];
2710 }
2711
2712 /**
2713  * {@internal Missing Short Description}}
2714  *
2715  * @since unknown
2716  *
2717  * @return unknown
2718  */
2719 function wp_max_upload_size() {
2720         $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
2721         $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
2722         $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
2723         return $bytes;
2724 }
2725
2726 /**
2727  * Outputs the form used by the importers to accept the data to be imported
2728  *
2729  * @since 2.0
2730  *
2731  * @param string $action The action attribute for the form.
2732  */
2733 function wp_import_upload_form( $action ) {
2734         $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
2735         $size = wp_convert_bytes_to_hr( $bytes );
2736         $upload_dir = wp_upload_dir();
2737         if ( ! empty( $upload_dir['error'] ) ) :
2738                 ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
2739                 <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
2740         else :
2741 ?>
2742 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
2743 <p>
2744 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
2745 <input type="file" id="upload" name="import" size="25" />
2746 <input type="hidden" name="action" value="save" />
2747 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
2748 </p>
2749 <p class="submit">
2750 <input type="submit" class="button" value="<?php esc_attr_e( 'Upload file and import' ); ?>" />
2751 </p>
2752 </form>
2753 <?php
2754         endif;
2755 }
2756
2757 /**
2758  * Add a meta box to an edit form.
2759  *
2760  * @since 2.5.0
2761  *
2762  * @param string $id String for use in the 'id' attribute of tags.
2763  * @param string $title Title of the meta box.
2764  * @param string $callback Function that fills the box with the desired content. The function should echo its output.
2765  * @param string $page The type of edit page on which to show the box (post, page, link).
2766  * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
2767  * @param string $priority The priority within the context where the boxes should show ('high', 'low').
2768  */
2769 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
2770         global $wp_meta_boxes;
2771
2772         if ( !isset($wp_meta_boxes) )
2773                 $wp_meta_boxes = array();
2774         if ( !isset($wp_meta_boxes[$page]) )
2775                 $wp_meta_boxes[$page] = array();
2776         if ( !isset($wp_meta_boxes[$page][$context]) )
2777                 $wp_meta_boxes[$page][$context] = array();
2778
2779         foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
2780         foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
2781                 if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
2782                         continue;
2783
2784                 // If a core box was previously added or removed by a plugin, don't add.
2785                 if ( 'core' == $priority ) {
2786                         // If core box previously deleted, don't add
2787                         if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
2788                                 return;
2789                         // If box was added with default priority, give it core priority to maintain sort order
2790                         if ( 'default' == $a_priority ) {
2791                                 $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
2792                                 unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
2793                         }
2794                         return;
2795                 }
2796                 // If no priority given and id already present, use existing priority
2797                 if ( empty($priority) ) {
2798                         $priority = $a_priority;
2799                 // 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.
2800                 } elseif ( 'sorted' == $priority ) {
2801                         $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
2802                         $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
2803                         $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
2804                 }
2805                 // An id can be in only one priority and one context
2806                 if ( $priority != $a_priority || $context != $a_context )
2807                         unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
2808         }
2809         }
2810
2811         if ( empty($priority) )
2812                 $priority = 'low';
2813
2814         if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
2815                 $wp_meta_boxes[$page][$context][$priority] = array();
2816
2817         $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
2818 }
2819
2820 /**
2821  * Meta-Box template function
2822  *
2823  * @since 2.5.0
2824  *
2825  * @param string $page page identifier, also known as screen identifier
2826  * @param string $context box context
2827  * @param mixed $object gets passed to the box callback function as first parameter
2828  * @return int number of meta_boxes
2829  */
2830 function do_meta_boxes($page, $context, $object) {
2831         global $wp_meta_boxes;
2832         static $already_sorted = false;
2833
2834         $hidden = get_hidden_meta_boxes($page);
2835
2836         printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context));
2837
2838         $i = 0;
2839         do {
2840                 // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
2841                 if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
2842                         foreach ( $sorted as $box_context => $ids )
2843                                 foreach ( explode(',', $ids) as $id )
2844                                         if ( $id )
2845                                                 add_meta_box( $id, null, null, $page, $box_context, 'sorted' );
2846                 }
2847                 $already_sorted = true;
2848
2849                 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
2850                         break;
2851
2852                 foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
2853                         if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
2854                                 foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
2855                                         if ( false == $box || ! $box['title'] )
2856                                                 continue;
2857                                         $i++;
2858                                         $style = '';
2859                                         $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
2860                                         echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
2861                                         echo '<div class="handlediv" title="' . __('Click to toggle') . '"><br /></div>';
2862                                         echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
2863                                         echo '<div class="inside">' . "\n";
2864                                         call_user_func($box['callback'], $object, $box);
2865                                         echo "</div>\n";
2866                                         echo "</div>\n";
2867                                 }
2868                         }
2869                 }
2870         } while(0);
2871
2872         echo "</div>";
2873
2874         return $i;
2875
2876 }
2877
2878 /**
2879  * Remove a meta box from an edit form.
2880  *
2881  * @since 2.6.0
2882  *
2883  * @param string $id String for use in the 'id' attribute of tags.
2884  * @param string $page The type of edit page on which to show the box (post, page, link).
2885  * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
2886  */
2887 function remove_meta_box($id, $page, $context) {
2888         global $wp_meta_boxes;
2889
2890         if ( !isset($wp_meta_boxes) )
2891                 $wp_meta_boxes = array();
2892         if ( !isset($wp_meta_boxes[$page]) )
2893                 $wp_meta_boxes[$page] = array();
2894         if ( !isset($wp_meta_boxes[$page][$context]) )
2895                 $wp_meta_boxes[$page][$context] = array();
2896
2897         foreach ( array('high', 'core', 'default', 'low') as $priority )
2898                 $wp_meta_boxes[$page][$context][$priority][$id] = false;
2899 }
2900
2901 /**
2902  * {@internal Missing Short Description}}
2903  *
2904  * @since unknown
2905  *
2906  * @param unknown_type $screen
2907  */
2908 function meta_box_prefs($screen) {
2909         global $wp_meta_boxes;
2910
2911         if ( is_string($screen) )
2912                 $screen = convert_to_screen($screen);
2913
2914         if ( empty($wp_meta_boxes[$screen->id]) )
2915                 return;
2916
2917         $hidden = get_hidden_meta_boxes($screen);
2918
2919         foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
2920                 foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
2921                         foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
2922                                 if ( false == $box || ! $box['title'] )
2923                                         continue;
2924                                 // Submit box cannot be hidden
2925                                 if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
2926                                         continue;
2927                                 $box_id = $box['id'];
2928                                 echo '<label for="' . $box_id . '-hide">';
2929                                 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"' : '') . ' />';
2930                                 echo "{$box['title']}</label>\n";
2931                         }
2932                 }
2933         }
2934 }
2935
2936 /**
2937  * Get Hidden Meta Boxes
2938  *
2939  * @since 2.7
2940  *
2941  * @param string|object $screen Screen identifier
2942  * @return array Hidden Meta Boxes
2943  */
2944 function get_hidden_meta_boxes( $screen ) {
2945         if ( is_string( $screen ) )
2946                 $screen = convert_to_screen( $screen );
2947
2948         $hidden = get_user_option( "metaboxhidden_{$screen->id}" );
2949
2950         // Hide slug boxes by default
2951         if ( !is_array( $hidden ) )
2952                 $hidden = array('slugdiv');
2953
2954         return $hidden;
2955 }
2956
2957 /**
2958  * Add a new section to a settings page.
2959  *
2960  * Part of the Settings API. Use this to define new settings sections for an admin page.
2961  * Show settings sections in your admin page callback function with do_settings_sections().
2962  * Add settings fields to your section with add_settings_field()
2963  *
2964  * The $callback argument should be the name of a function that echoes out any
2965  * content you want to show at the top of the settings section before the actual
2966  * fields. It can output nothing if you want.
2967  *
2968  * @since 2.7.0
2969  *
2970  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
2971  *
2972  * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
2973  * @param string $title Formatted title of the section. Shown as the heading for the section.
2974  * @param string $callback Function that echos out any content at the top of the section (between heading and fields).
2975  * @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();
2976  */
2977 function add_settings_section($id, $title, $callback, $page) {
2978         global $wp_settings_sections;
2979
2980         if ( 'misc' == $page ) {
2981                 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
2982                 $page = 'general';
2983         }
2984
2985         if ( !isset($wp_settings_sections) )
2986                 $wp_settings_sections = array();
2987         if ( !isset($wp_settings_sections[$page]) )
2988                 $wp_settings_sections[$page] = array();
2989         if ( !isset($wp_settings_sections[$page][$id]) )
2990                 $wp_settings_sections[$page][$id] = array();
2991
2992         $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
2993 }
2994
2995 /**
2996  * Add a new field to a section of a settings page
2997  *
2998  * Part of the Settings API. Use this to define a settings field that will show
2999  * as part of a settings section inside a settings page. The fields are shown using
3000  * do_settings_fields() in do_settings-sections()
3001  *
3002  * The $callback argument should be the name of a function that echoes out the
3003  * html input tags for this setting field. Use get_option() to retrive existing
3004  * values to show.
3005  *
3006  * @since 2.7.0
3007  *
3008  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
3009  *
3010  * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
3011  * @param string $title Formatted title of the field. Shown as the label for the field during output.
3012  * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
3013  * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
3014  * @param string $section The slug-name of the section of the settingss page in which to show the box (default, ...).
3015  * @param array $args Additional arguments
3016  */
3017 function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
3018         global $wp_settings_fields;
3019
3020         if ( 'misc' == $page ) {
3021                 _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
3022                 $page = 'general';
3023         }
3024
3025         if ( !isset($wp_settings_fields) )
3026                 $wp_settings_fields = array();
3027         if ( !isset($wp_settings_fields[$page]) )
3028                 $wp_settings_fields[$page] = array();
3029         if ( !isset($wp_settings_fields[$page][$section]) )
3030                 $wp_settings_fields[$page][$section] = array();
3031
3032         $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
3033 }
3034
3035 /**
3036  * Prints out all settings sections added to a particular settings page
3037  *
3038  * Part of the Settings API. Use this in a settings page callback function
3039  * to output all the sections and fields that were added to that $page with
3040  * add_settings_section() and add_settings_field()
3041  *
3042  * @global $wp_settings_sections Storage array of all settings sections added to admin pages
3043  * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
3044  * @since unknown
3045  *
3046  * @param string $page The slug name of the page whos settings sections you want to output
3047  */
3048 function do_settings_sections($page) {
3049         global $wp_settings_sections, $wp_settings_fields;
3050
3051         if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
3052                 return;
3053
3054         foreach ( (array) $wp_settings_sections[$page] as $section ) {
3055                 echo "<h3>{$section['title']}</h3>\n";
3056                 call_user_func($section['callback'], $section);
3057                 if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
3058                         continue;
3059                 echo '<table class="form-table">';
3060                 do_settings_fields($page, $section['id']);
3061                 echo '</table>';
3062         }
3063 }
3064
3065 /**
3066  * Print out the settings fields for a particular settings section
3067  *
3068  * Part of the Settings API. Use this in a settings page to output
3069  * a specific section. Should normally be called by do_settings_sections()
3070  * rather than directly.
3071  *
3072  * @global $wp_settings_fields Storage array of settings fields and their pages/sections
3073  *
3074  * @since unknown
3075  *
3076  * @param string $page Slug title of the admin page who's settings fields you want to show.
3077  * @param section $section Slug title of the settings section who's fields you want to show.
3078  */
3079 function do_settings_fields($page, $section) {
3080         global $wp_settings_fields;
3081
3082         if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
3083                 return;
3084
3085         foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
3086                 echo '<tr valign="top">';
3087                 if ( !empty($field['args']['label_for']) )
3088                         echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
3089                 else
3090                         echo '<th scope="row">' . $field['title'] . '</th>';
3091                 echo '<td>';
3092                 call_user_func($field['callback'], $field['args']);
3093                 echo '</td>';
3094                 echo '</tr>';
3095         }
3096 }
3097
3098 /**
3099  * Register a settings error to be displayed to the user
3100  *
3101  * Part of the Settings API. Use this to show messages to users about settings validation
3102  * problems, missing settings or anything else.
3103  *
3104  * Settings errors should be added inside the $sanitize_callback function defined in
3105  * register_setting() for a given setting to give feedback about the submission.
3106  *
3107  * By default messages will show immediately after the submission that generated the error.
3108  * Additional calls to settings_errors() can be used to show errors even when the settings
3109  * page is first accessed.
3110  *
3111  * @global array $wp_settings_errors Storage array of errors registered during this pageload
3112  *
3113  * @param string $setting Slug title of the setting to which this error applies
3114  * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
3115  * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>)
3116  * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
3117  */
3118 function add_settings_error( $setting, $code, $message, $type = 'error' ) {
3119         global $wp_settings_errors;
3120
3121         if ( !isset($wp_settings_errors) )
3122                 $wp_settings_errors = array();
3123
3124         $new_error = array(
3125                 'setting' => $setting,
3126                 'code' => $code,
3127                 'message' => $message,
3128                 'type' => $type
3129         );
3130         $wp_settings_errors[] = $new_error;
3131 }
3132
3133 /**
3134  * Fetch settings errors registered by add_settings_error()
3135  *
3136  * Checks the $wp_settings_errors array for any errors declared during the current
3137  * pageload and returns them.
3138  *
3139  * If changes were just submitted ($_GET['updated']) and settings errors were saved
3140  * to the 'settings_errors' transient then those errors will be returned instead. This
3141  * is used to pass errors back across pageloads.
3142  *
3143  * Use the $sanitize argument to manually re-sanitize the option before returning errors.
3144  * This is useful if you have errors or notices you want to show even when the user
3145  * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
3146  *
3147  * @global array $wp_settings_errors Storage array of errors registered during this pageload
3148  *
3149  * @param string $setting Optional slug title of a specific setting who's errors you want.
3150  * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
3151  * @return array Array of settings errors
3152  */
3153 function get_settings_errors( $setting = '', $sanitize = FALSE ) {
3154         global $wp_settings_errors;
3155
3156         // If $sanitize is true, manually re-run the sanitizisation for this option
3157         // This allows the $sanitize_callback from register_setting() to run, adding
3158         // any settings errors you want to show by default.
3159         if ( $sanitize )
3160                 sanitize_option( $setting, get_option($setting));
3161
3162         // If settings were passed back from options.php then use them
3163         // Ignore transients if $sanitize is true, we dont' want the old values anyway
3164         if ( isset($_GET['updated']) && $_GET['updated'] && get_transient('settings_errors') ) {
3165                 $settings_errors = get_transient('settings_errors');
3166                 delete_transient('settings_errors');
3167         // Otherwise check global in case validation has been run on this pageload
3168         } elseif ( count( $wp_settings_errors ) ) {
3169                 $settings_errors = $wp_settings_errors;
3170         } else {
3171                 return;
3172         }
3173
3174         // Filter the results to those of a specific setting if one was set
3175         if ( $setting ) {
3176                 foreach ( (array) $settings_errors as $key => $details )
3177                         if ( $setting != $details['setting'] )
3178                                 unset( $settings_errors[$key] );
3179         }
3180         return $settings_errors;
3181 }
3182
3183 /**
3184  * Display settings errors registered by add_settings_error()
3185  *
3186  * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
3187  *
3188  * This is called automatically after a settings page based on the Settings API is submitted.
3189  * Errors should be added during the validation callback function for a setting defined in register_setting()
3190  *
3191  * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
3192  * on its current value.
3193  *
3194  * The $hide_on_update option will cause errors to only show when the settings page is first loaded.
3195  * if the user has already saved new values it will be hidden to avoid repeating messages already
3196  * shown in the default error reporting after submission. This is useful to show general errors like missing
3197  * settings when the user arrives at the settings page.
3198  *
3199  * @param string $setting Optional slug title of a specific setting who's errors you want.
3200  * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
3201  * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
3202  * @return <type>
3203  */
3204 function settings_errors ( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
3205
3206         if ($hide_on_update AND $_GET['updated']) return;
3207
3208         $settings_errors = get_settings_errors( $setting, $sanitize );
3209
3210         if ( !is_array($settings_errors) ) return;
3211
3212         $output = '';
3213         foreach ( $settings_errors as $key => $details ) {
3214                 $css_id = 'setting-error-' . $details['code'];
3215                 $css_class = $details['type'] . ' settings-error';
3216                 $output .= "<div id='$css_id' class='$css_class'> \n";
3217                 $output .= "<p><strong>{$details['message']}</strong></p>";
3218                 $output .= "</div> \n";
3219         }
3220         echo $output;
3221 }
3222
3223 /**
3224  * {@internal Missing Short Description}}
3225  *
3226  * @since unknown
3227  *
3228  * @param unknown_type $page
3229  */
3230 function manage_columns_prefs( $page ) {
3231         $columns = get_column_headers( $page );
3232         $hidden  = get_hidden_columns( $page );
3233         $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username');
3234
3235         foreach ( $columns as $column => $title ) {
3236                 // Can't hide these or they are special
3237                 if ( in_array( $column, $special ) )
3238                         continue;
3239                 if ( empty( $title ) )
3240                         continue;
3241
3242                 if ( 'comments' == $column )
3243                         $title = __( 'Comments' );
3244                 $id = "$column-hide";
3245                 echo '<label for="' . $id . '">';
3246                 echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . (! in_array($column, $hidden) ? ' checked="checked"' : '') . ' />';
3247                 echo "$title</label>\n";
3248         }
3249 }
3250
3251 /**
3252  * {@internal Missing Short Description}}
3253  *
3254  * @since unknown
3255  *
3256  * @param unknown_type $found_action
3257  */
3258 function find_posts_div($found_action = '') {
3259 ?>
3260         <div id="find-posts" class="find-box" style="display:none;">
3261                 <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
3262                 <div class="find-box-inside">
3263                         <div class="find-box-search">
3264                                 <?php if ( $found_action ) { ?>
3265                                         <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
3266                                 <?php } ?>
3267
3268                                 <input type="hidden" name="affected" id="affected" value="" />
3269                                 <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
3270                                 <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
3271                                 <input type="text" id="find-posts-input" name="ps" value="" />
3272                                 <input type="button" onclick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
3273
3274                                 <?php
3275                                 $post_types = get_post_types( array('public' => true), 'objects' );
3276                                 foreach ( $post_types as $post ) {
3277                                         if ( 'attachment' == $post->name )
3278                                                 continue;
3279                                 ?>
3280                                 <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'); ?> />
3281                                 <label for="find-posts-<?php echo esc_attr($post->name); ?>"><?php echo $post->label; ?></label>
3282                                 <?php
3283                                 } ?>
3284                         </div>
3285                         <div id="find-posts-response"></div>
3286                 </div>
3287                 <div class="find-box-buttons">
3288                         <input type="button" class="button alignleft" onclick="findPosts.close();" value="<?php esc_attr_e('Close'); ?>" />
3289                         <input id="find-posts-submit" type="submit" class="button-primary alignright" value="<?php esc_attr_e('Select'); ?>" />
3290                 </div>
3291         </div>
3292 <?php
3293 }
3294
3295 /**
3296  * Display the post password.
3297  *
3298  * The password is passed through {@link esc_attr()} to ensure that it
3299  * is safe for placing in an html attribute.
3300  *
3301  * @uses attr
3302  * @since 2.7.0
3303  */
3304 function the_post_password() {
3305         global $post;
3306         if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
3307 }
3308
3309 /**
3310  * {@internal Missing Short Description}}
3311  *
3312  * @since unknown
3313  */
3314 function favorite_actions( $screen = null ) {
3315         $default_action = false;
3316
3317         if ( is_string($screen) )
3318                 $screen = convert_to_screen($screen);
3319
3320         if ( isset($screen->post_type) ) {
3321                 $post_type_object = get_post_type_object($screen->post_type);
3322                 if ( 'add' != $screen->action )
3323                         $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));
3324                 else
3325                         $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->name, $post_type_object->cap->edit_posts));
3326         }
3327
3328         if ( !$default_action ) {
3329                 switch ( $screen->id ) {
3330                         case 'upload':
3331                                 $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
3332                                 break;
3333                         case 'media':
3334                                 $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
3335                                 break;
3336                         case 'link-manager':
3337                         case 'link':
3338                                 if ( 'add' != $screen->action )
3339                                         $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
3340                                 else
3341                                         $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
3342                                 break;
3343                         case 'users':
3344                                 $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
3345                                 break;
3346                         case 'user':
3347                                 $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
3348                                 break;
3349                         case 'plugins':
3350                                 $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
3351                                 break;
3352                         case 'plugin-install':
3353                                 $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
3354                                 break;
3355                         case 'themes':
3356                                 $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
3357                                 break;
3358                         case 'theme-install':
3359                                 $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
3360                                 break;
3361                         default:
3362                                 $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
3363                                 break;
3364                 }
3365         }
3366
3367         $actions = array(
3368                 'post-new.php' => array(__('New Post'), 'edit_posts'),
3369                 'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
3370                 'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
3371                 'media-new.php' => array(__('Upload'), 'upload_files'),
3372                 'edit-comments.php' => array(__('Comments'), 'moderate_comments')
3373                 );
3374
3375         $default_key = array_keys($default_action);
3376         $default_key = $default_key[0];
3377         if ( isset($actions[$default_key]) )
3378                 unset($actions[$default_key]);
3379         $actions = array_merge($default_action, $actions);
3380         $actions = apply_filters('favorite_actions', $actions);
3381
3382         $allowed_actions = array();
3383         foreach ( $actions as $action => $data ) {
3384                 if ( current_user_can($data[1]) )
3385                         $allowed_actions[$action] = $data[0];
3386         }
3387
3388         if ( empty($allowed_actions) )
3389                 return;
3390
3391         $first = array_keys($allowed_actions);
3392         $first = $first[0];
3393         echo '<div id="favorite-actions">';
3394         echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
3395         echo '<div id="favorite-inside">';
3396
3397         array_shift($allowed_actions);
3398
3399         foreach ( $allowed_actions as $action => $label) {
3400                 echo "<div class='favorite-action'><a href='$action'>";
3401                 echo $label;
3402                 echo "</a></div>\n";
3403         }
3404         echo "</div></div>\n";
3405 }
3406
3407 /**
3408  * Get the post title.
3409  *
3410  * The post title is fetched and if it is blank then a default string is
3411  * returned.
3412  *
3413  * @since 2.7.0
3414  * @param int $id The post id. If not supplied the global $post is used.
3415  *
3416  */
3417 function _draft_or_post_title($post_id = 0) {
3418         $title = get_the_title($post_id);
3419         if ( empty($title) )
3420                 $title = __('(no title)');
3421         return $title;
3422 }
3423
3424 /**
3425  * Display the search query.
3426  *
3427  * A simple wrapper to display the "s" parameter in a GET URI. This function
3428  * should only be used when {@link the_search_query()} cannot.
3429  *
3430  * @uses attr
3431  * @since 2.7.0
3432  *
3433  */
3434 function _admin_search_query() {
3435         echo isset($_GET['s']) ? esc_attr( stripslashes( $_GET['s'] ) ) : '';
3436 }
3437
3438 /**
3439  * Generic Iframe header for use with Thickbox
3440  *
3441  * @since 2.7.0
3442  * @param string $title Title of the Iframe page.
3443  * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
3444  *
3445  */
3446 function iframe_header( $title = '', $limit_styles = false ) {
3447 global $hook_suffix;
3448 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3449 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
3450 <head>
3451 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
3452 <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
3453 <?php
3454 wp_enqueue_style( 'global' );
3455 if ( ! $limit_styles )
3456         wp_enqueue_style( 'wp-admin' );
3457 wp_enqueue_style( 'colors' );
3458 ?>
3459 <script type="text/javascript">
3460 //<![CDATA[
3461 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();}}};
3462 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
3463 //]]>
3464 </script>
3465 <?php
3466 do_action('admin_print_styles');
3467 do_action('admin_print_scripts');
3468 do_action('admin_head');
3469
3470 $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
3471 ?>
3472 </head>
3473 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>  class="no-js <?php echo $admin_body_class; ?>">
3474 <script type="text/javascript">
3475 //<![CDATA[
3476 (function(){
3477 var c = document.body.className;
3478 c = c.replace(/no-js/, 'js');
3479 document.body.className = c;
3480 })();
3481 //]]>
3482 </script>
3483 <?php
3484 }
3485
3486 /**
3487  * Generic Iframe footer for use with Thickbox
3488  *
3489  * @since 2.7.0
3490  *
3491  */
3492 function iframe_footer() {
3493         //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?>
3494         <div class="hidden">
3495 <?php
3496         do_action('admin_footer', '');
3497         do_action('admin_print_footer_scripts'); ?>
3498         </div>
3499 <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
3500 </body>
3501 </html>
3502 <?php
3503 }
3504
3505 function _post_states($post) {
3506         $post_states = array();
3507         if ( isset($_GET['post_status']) )
3508                 $post_status = $_GET['post_status'];
3509         else
3510                 $post_status = '';
3511
3512         if ( !empty($post->post_password) )
3513                 $post_states[] = __('Password protected');
3514         if ( 'private' == $post->post_status && 'private' != $post_status )
3515                 $post_states[] = __('Private');
3516         if ( 'draft' == $post->post_status && 'draft' != $post_status )
3517                 $post_states[] = __('Draft');
3518         if ( 'pending' == $post->post_status && 'pending' != $post_status )
3519                 /* translators: post state */
3520                 $post_states[] = _x('Pending', 'post state');
3521         if ( is_sticky($post->ID) )
3522                 $post_states[] = __('Sticky');
3523
3524         $post_states = apply_filters( 'display_post_states', $post_states );
3525
3526         if ( ! empty($post_states) ) {
3527                 $state_count = count($post_states);
3528                 $i = 0;
3529                 echo ' - ';
3530                 foreach ( $post_states as $state ) {
3531                         ++$i;
3532                         ( $i == $state_count ) ? $sep = '' : $sep = ', ';
3533                         echo "<span class='post-state'>$state$sep</span>";
3534                 }
3535         }
3536 }
3537
3538 /**
3539  * Convert a screen string to a screen object
3540  *
3541  * @since 3.0.0
3542  *
3543  * @param string $screen The name of the screen
3544  * @return object An object containing the safe screen name and id
3545  */
3546 function convert_to_screen( $screen ) {
3547         $screen = str_replace( array('.php', '-new', '-add' ), '', $screen);
3548         $screen = (string) apply_filters( 'screen_meta_screen', $screen );
3549         $screen = (object) array('id' => $screen, 'base' => $screen);
3550         return $screen;
3551 }
3552
3553 function screen_meta($screen) {
3554         global $wp_meta_boxes, $_wp_contextual_help, $title;
3555
3556         if ( is_string($screen) )
3557                 $screen = convert_to_screen($screen);
3558
3559         $column_screens = get_column_headers($screen);
3560         $meta_screens = array('index' => 'dashboard');
3561
3562         if ( isset($meta_screens[$screen->id]) ) {
3563                 $screen->id = $meta_screens[$screen->id];
3564                 $screen->base = $screen->id;
3565         }
3566
3567         $show_screen = false;
3568         if ( !empty($wp_meta_boxes[$screen->id]) || !empty($column_screens) )
3569                 $show_screen = true;
3570
3571         $screen_options = screen_options($screen);
3572         if ( $screen_options )
3573                 $show_screen = true;
3574
3575         if ( !isset($_wp_contextual_help) )
3576                 $_wp_contextual_help = array();
3577
3578         $settings = apply_filters('screen_settings', '', $screen);
3579
3580         switch ( $screen->id ) {
3581                 case 'widgets':
3582                         $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";
3583                         $show_screen = true;
3584                         break;
3585         }
3586         if( ! empty( $settings ) )
3587                 $show_screen = true;
3588 ?>
3589 <div id="screen-meta">
3590 <?php if ( $show_screen ) : ?>
3591 <div id="screen-options-wrap" class="hidden">
3592         <form id="adv-settings" action="" method="post">
3593         <?php if ( isset($wp_meta_boxes[$screen->id]) ) : ?>
3594                 <h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
3595                 <div class="metabox-prefs">
3596                         <?php meta_box_prefs($screen); ?>
3597                         <br class="clear" />
3598                 </div>
3599                 <?php endif;
3600                 if ( ! empty($column_screens) ) : ?>
3601                 <h5><?php echo ( isset( $column_screens['_title'] ) ?  $column_screens['_title'] :  _x('Show on screen', 'Columns') ) ?></h5>
3602                 <div class="metabox-prefs">
3603                         <?php manage_columns_prefs($screen); ?>
3604                         <br class="clear" />
3605                 </div>
3606         <?php endif;
3607         echo screen_layout($screen);
3608
3609         if ( !empty( $screen_options ) ) {
3610                 ?>
3611                 <h5><?php _ex('Show on screen', 'Screen Options') ?></h5>
3612                 <?php
3613         }
3614
3615         echo $screen_options;
3616         echo $settings; ?>
3617 <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
3618 </form>
3619 </div>
3620
3621 <?php endif; // $show_screen
3622
3623         $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen);
3624         ?>
3625         <div id="contextual-help-wrap" class="hidden">
3626         <?php
3627         $contextual_help = '';
3628         if ( isset($_wp_contextual_help[$screen->id]) ) {
3629                 $contextual_help .= '<div class="metabox-prefs">' . $_wp_contextual_help[$screen->id] . "</div>\n";
3630         } else {
3631                 $contextual_help .= '<div class="metabox-prefs">';
3632                 $default_help = __('<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>');
3633                 $default_help .= '<br />';
3634                 $default_help .= __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>');
3635                 $contextual_help .= apply_filters('default_contextual_help', $default_help);
3636                 $contextual_help .= "</div>\n";
3637         }
3638
3639         echo apply_filters('contextual_help', $contextual_help, $screen->id, $screen);
3640         ?>
3641         </div>
3642
3643 <div id="screen-meta-links">
3644 <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
3645 <a href="#contextual-help" id="contextual-help-link" class="show-settings"><?php _e('Help') ?></a>
3646 </div>
3647 <?php if ( $show_screen ) { ?>
3648 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
3649 <a href="#screen-options" id="show-settings-link" class="show-settings"><?php _e('Screen Options') ?></a>
3650 </div>
3651 <?php } ?>
3652 </div>
3653 </div>
3654 <?php
3655 }
3656
3657 /**
3658  * Add contextual help text for a page
3659  *
3660  * @since 2.7.0
3661  *
3662  * @param string $screen The handle for the screen to add help to.  This is usually the hook name returned by the add_*_page() functions.
3663  * @param string $help Arbitrary help text
3664  */
3665 function add_contextual_help($screen, $help) {
3666         global $_wp_contextual_help;
3667
3668         if ( is_string($screen) )
3669                 $screen = convert_to_screen($screen);
3670
3671         if ( !isset($_wp_contextual_help) )
3672                 $_wp_contextual_help = array();
3673
3674         $_wp_contextual_help[$screen->id] = $help;
3675 }
3676
3677 function drag_drop_help() {
3678         return '
3679         <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>
3680         <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>
3681 ';
3682 }
3683
3684 function plugins_search_help() {
3685         return '
3686         <p><strong>' . __('Search help') . '</strong></p>' .
3687         '<p>' . __('You may search based on 3 criteria:') . '<br />' .
3688         __('<strong>Term:</strong> Searches theme names and descriptions for the specified term.') . '<br />' .
3689         __('<strong>Tag:</strong> Searches for themes tagged as such.') . '<br />' .
3690         __('<strong>Author:</strong> Searches for themes created by the Author, or which the Author contributed to.') . '</p>
3691 ';
3692 }
3693
3694 function screen_layout($screen) {
3695         global $screen_layout_columns;
3696
3697         if ( is_string($screen) )
3698                 $screen = convert_to_screen($screen);
3699
3700         $columns = array('dashboard' => 4, 'link' => 2);
3701
3702         // Add custom post types
3703         foreach ( get_post_types( array('show_ui' => true) ) as $post_type )
3704                 $columns[$post_type] = 2;
3705
3706         $columns = apply_filters('screen_layout_columns', $columns, $screen->id, $screen);
3707
3708         if ( !isset($columns[$screen->id]) ) {
3709                 $screen_layout_columns = 0;
3710                 return '';
3711         }
3712
3713         $screen_layout_columns = get_user_option("screen_layout_$screen->id");
3714         $num = $columns[$screen->id];
3715
3716         if ( ! $screen_layout_columns )
3717                         $screen_layout_columns = 2;
3718
3719         $i = 1;
3720         $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n";
3721         while ( $i <= $num ) {
3722                 $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n";
3723                 ++$i;
3724         }
3725         $return .= "</div>\n";
3726         return $return;
3727 }
3728
3729 function screen_options($screen) {
3730         if ( is_string($screen) )
3731                 $screen = convert_to_screen($screen);
3732
3733         switch ( $screen->base ) {
3734                 case 'edit':
3735                 case 'edit-pages':
3736                         $post_type = 'post';
3737                         if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('public' => true ) ) ) )
3738                                 $post_type = $_GET['post_type'];
3739                         $post_type_object = get_post_type_object($post_type);
3740                         $per_page_label = $post_type_object->labels->name;
3741                         break;
3742                 case 'ms-sites':
3743                         $per_page_label = _x( 'Sites', 'sites per page (screen options)' );
3744                         break;
3745                 case 'ms-users':
3746                         $per_page_label = _x( 'Users', 'users per page (screen options)' );
3747                         break;
3748                 case 'edit-comments':
3749                         $per_page_label = _x( 'Comments', 'comments per page (screen options)' );
3750                         break;
3751                 case 'upload':
3752                         $per_page_label = _x( 'Media items', 'items per page (screen options)' );
3753                         break;
3754                 case 'edit-tags':
3755                         global $tax;
3756                         $per_page_label = $tax->labels->name;
3757                         break;
3758                 case 'plugins':
3759                         $per_page_label = _x( 'Plugins', 'plugins per page (screen options)' );
3760                         break;
3761                 default:
3762                         return '';
3763         }
3764
3765         $option = str_replace( '-', '_', "{$screen->id}_per_page" );
3766         if ( 'edit_tags_per_page' == $option ) {
3767                 if ( 'category' == $tax->name )
3768                         $option = 'categories_per_page';
3769                 elseif ( 'post_tag' != $tax->name )
3770                         $option = 'edit_' . $tax->name . '_per_page';
3771         }
3772
3773         $per_page = (int) get_user_option( $option );
3774         if ( empty( $per_page ) || $per_page < 1 ) {
3775                 if ( 'plugins' == $screen->id )
3776                         $per_page = 999;
3777                 else
3778                         $per_page = 20;
3779         }
3780
3781         if ( 'edit_comments_per_page' == $option )
3782                 $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' );
3783         elseif ( 'categories_per_page' == $option )
3784                 $per_page = apply_filters( 'edit_categories_per_page', $per_page );
3785         else
3786                 $per_page = apply_filters( $option, $per_page );
3787
3788         $return = "<div class='screen-options'>\n";
3789         if ( !empty($per_page_label) )
3790                 $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";
3791         $return .= "<input type='submit' class='button' value='" . esc_attr__('Apply') . "' />";
3792         $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
3793         $return .= "</div>\n";
3794         return $return;
3795 }
3796
3797 function screen_icon($screen = '') {
3798         global $current_screen;
3799
3800         if ( empty($screen) )
3801                 $screen = $current_screen;
3802         elseif ( is_string($screen) )
3803                 $name = $screen;
3804
3805         if ( empty($name) ) {
3806                 if ( !empty($screen->parent_base) )
3807                         $name = $screen->parent_base;
3808                 else
3809                         $name = $screen->base;
3810
3811                 if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
3812                         $name = 'edit-pages';
3813         }
3814
3815 ?>
3816         <div id="icon-<?php echo $name; ?>" class="icon32"><br /></div>
3817 <?php
3818 }
3819
3820 /**
3821  * Test support for compressing JavaScript from PHP
3822  *
3823  * Outputs JavaScript that tests if compression from PHP works as expected
3824  * and sets an option with the result. Has no effect when the current user
3825  * is not an administrator. To run the test again the option 'can_compress_scripts'
3826  * has to be deleted.
3827  *
3828  * @since 2.8.0
3829  */
3830 function compression_test() {
3831 ?>
3832         <script type="text/javascript">
3833         /* <![CDATA[ */
3834         var testCompression = {
3835                 get : function(test) {
3836                         var x;
3837                         if ( window.XMLHttpRequest ) {
3838                                 x = new XMLHttpRequest();
3839                         } else {
3840                                 try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
3841                         }
3842
3843                         if (x) {
3844                                 x.onreadystatechange = function() {
3845                                         var r, h;
3846                                         if ( x.readyState == 4 ) {
3847                                                 r = x.responseText.substr(0, 18);
3848                                                 h = x.getResponseHeader('Content-Encoding');
3849                                                 testCompression.check(r, h, test);
3850                                         }
3851                                 }
3852
3853                                 x.open('GET', 'admin-ajax.php?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
3854                                 x.send('');
3855                         }
3856                 },
3857
3858                 check : function(r, h, test) {
3859                         if ( ! r && ! test )
3860                                 this.get(1);
3861
3862                         if ( 1 == test ) {
3863                                 if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
3864                                         this.get('no');
3865                                 else
3866                                         this.get(2);
3867
3868                                 return;
3869                         }
3870
3871                         if ( 2 == test ) {
3872                                 if ( '"wpCompressionTest' == r )
3873                                         this.get('yes');
3874                                 else
3875                                         this.get('no');
3876                         }
3877                 }
3878         };
3879         testCompression.check();
3880         /* ]]> */
3881         </script>
3882 <?php
3883 }
3884
3885 /**
3886  * Set the current screen object
3887  *
3888  * @since 3.0.0
3889  *
3890  * @uses $current_screen
3891  *
3892  * @param string $id Screen id, optional.
3893  */
3894 function set_current_screen( $id =  '' ) {
3895         global $current_screen, $hook_suffix, $typenow, $taxnow;
3896
3897         $action = '';
3898
3899         if ( empty($id) ) {
3900                 $current_screen = $hook_suffix;
3901                 $current_screen = str_replace('.php', '', $current_screen);
3902                 if ( preg_match('/-add|-new$/', $current_screen) )
3903                         $action = 'add';
3904                 $current_screen = str_replace('-new', '', $current_screen);
3905                 $current_screen = str_replace('-add', '', $current_screen);
3906                 $current_screen = array('id' => $current_screen, 'base' => $current_screen);
3907         } else {
3908                 $id = sanitize_key($id);
3909                 if ( false !== strpos($id, '-') ) {
3910                         list( $id, $typenow ) = explode('-', $id, 2);
3911                         if ( taxonomy_exists( $typenow ) ) {
3912                                 $id = 'edit-tags';
3913                                 $taxnow = $typenow;
3914                                 $typenow = '';
3915                         }
3916                 }
3917                 $current_screen = array('id' => $id, 'base' => $id);
3918         }
3919
3920         $current_screen = (object) $current_screen;
3921
3922         $current_screen->action = $action;
3923
3924         // Map index to dashboard
3925         if ( 'index' == $current_screen->base )
3926                 $current_screen->base = 'dashboard';
3927         if ( 'index' == $current_screen->id )
3928                 $current_screen->id = 'dashboard';
3929
3930         if ( 'edit' == $current_screen->id ) {
3931                 if ( empty($typenow) )
3932                         $typenow = 'post';
3933                 $current_screen->id .= '-' . $typenow;
3934                 $current_screen->post_type = $typenow;
3935         } elseif ( 'post' == $current_screen->id ) {
3936                 if ( empty($typenow) )
3937                         $typenow = 'post';
3938                 $current_screen->id = $typenow;
3939                 $current_screen->post_type = $typenow;
3940         } elseif ( 'edit-tags' == $current_screen->id ) {
3941                 if ( empty($taxnow) )
3942                         $taxnow = 'post_tag';
3943                 $current_screen->id = 'edit-' . $taxnow;
3944                 $current_screen->taxonomy = $taxnow;
3945         }
3946
3947         $current_screen = apply_filters('current_screen', $current_screen);
3948 }
3949
3950 ?>