Projects : mp-wp : mp-wp_svg-screenshots-and-errorreporting-r2

mp-wp/wp-admin/includes/template.php

Dir - Raw

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