PluginProbe
User Access Manager / 0.9.1
User Access Manager v0.9.1
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / core_files / wp-admin / includes / template.php

template.php in User Access Manager 0.9.1, at core_files/wp-admin/includes/template.php

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