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