| [ XREF Home ] [ Index ] |
PHP Cross Reference of WordPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Terms List Table class. 4 * 5 * @package WordPress 6 * @subpackage List_Table 7 * @since 3.1.0 8 * @access private 9 */ 10 class WP_Terms_List_Table extends WP_List_Table { 11 12 var $callback_args; 13 14 function __construct() { 15 global $post_type, $taxonomy, $tax; 16 17 wp_reset_vars( array( 'action', 'taxonomy', 'post_type' ) ); 18 19 if ( empty( $taxonomy ) ) 20 $taxonomy = 'post_tag'; 21 22 if ( !taxonomy_exists( $taxonomy ) ) 23 wp_die( __( 'Invalid taxonomy' ) ); 24 25 $tax = get_taxonomy( $taxonomy ); 26 27 if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'public' => true ) ) ) ) 28 $post_type = 'post'; 29 30 parent::__construct( array( 31 'plural' => 'tags', 32 'singular' => 'tag', 33 ) ); 34 } 35 36 function ajax_user_can() { 37 global $tax; 38 39 return current_user_can( $tax->cap->manage_terms ); 40 } 41 42 function prepare_items() { 43 global $taxonomy; 44 45 $tags_per_page = $this->get_items_per_page( 'edit_' . $taxonomy . '_per_page' ); 46 47 if ( 'post_tag' == $taxonomy ) { 48 $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page ); 49 $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter 50 } elseif ( 'category' == $taxonomy ) { 51 $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter 52 } 53 54 $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : ''; 55 56 $args = array( 57 'search' => $search, 58 'page' => $this->get_pagenum(), 59 'number' => $tags_per_page, 60 ); 61 62 if ( !empty( $_REQUEST['orderby'] ) ) 63 $args['orderby'] = trim( stripslashes( $_REQUEST['orderby'] ) ); 64 65 if ( !empty( $_REQUEST['order'] ) ) 66 $args['order'] = trim( stripslashes( $_REQUEST['order'] ) ); 67 68 $this->callback_args = $args; 69 70 $this->set_pagination_args( array( 71 'total_items' => wp_count_terms( $taxonomy, compact( 'search' ) ), 72 'per_page' => $tags_per_page, 73 ) ); 74 } 75 76 function has_items() { 77 // todo: populate $this->items in prepare_items() 78 return true; 79 } 80 81 function get_bulk_actions() { 82 $actions = array(); 83 $actions['delete'] = __( 'Delete' ); 84 85 return $actions; 86 } 87 88 function current_action() { 89 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) ) 90 return 'bulk-delete'; 91 92 return parent::current_action(); 93 } 94 95 function get_columns() { 96 global $taxonomy, $typenow; 97 98 $columns = array( 99 'cb' => '<input type="checkbox" />', 100 'name' => __( 'Name' ), 101 'description' => __( 'Description' ), 102 'slug' => __( 'Slug' ), 103 ); 104 105 if ( 'link_category' == $taxonomy ) { 106 $columns['links'] = __( 'Links' ); 107 } else { 108 $post_type = empty( $typenow ) ? 'post' : $typenow; 109 $post_type_object = get_post_type_object( $post_type ); 110 $columns['posts'] = $post_type_object ? $post_type_object->labels->name : __( 'Posts' ); 111 } 112 113 return $columns; 114 } 115 116 function get_sortable_columns() { 117 return array( 118 'name' => 'name', 119 'description' => 'description', 120 'slug' => 'slug', 121 'posts' => 'count', 122 'links' => 'count' 123 ); 124 } 125 126 function display_rows_or_placeholder() { 127 global $taxonomy; 128 129 $args = wp_parse_args( $this->callback_args, array( 130 'page' => 1, 131 'number' => 20, 132 'search' => '', 133 'hide_empty' => 0 134 ) ); 135 136 extract( $args, EXTR_SKIP ); 137 138 $args['offset'] = $offset = ( $page - 1 ) * $number; 139 140 // convert it to table rows 141 $out = ''; 142 $count = 0; 143 144 $terms = array(); 145 146 if ( is_taxonomy_hierarchical( $taxonomy ) && !isset( $orderby ) ) { 147 // We'll need the full set of terms then. 148 $args['number'] = $args['offset'] = 0; 149 150 $terms = get_terms( $taxonomy, $args ); 151 if ( !empty( $search ) ) // Ignore children on searches. 152 $children = array(); 153 else 154 $children = _get_term_hierarchy( $taxonomy ); 155 156 // Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake 157 $out .= $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count ); 158 } else { 159 $terms = get_terms( $taxonomy, $args ); 160 foreach ( $terms as $term ) 161 $out .= $this->single_row( $term, 0, $taxonomy ); 162 $count = $number; // Only displaying a single page. 163 } 164 165 if ( empty( $terms ) ) { 166 list( $columns, $hidden ) = $this->get_column_info(); 167 echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">'; 168 $this->no_items(); 169 echo '</td></tr>'; 170 } else { 171 echo $out; 172 } 173 } 174 175 function _rows( $taxonomy, $terms, &$children, $start = 0, $per_page = 20, &$count, $parent = 0, $level = 0 ) { 176 177 $end = $start + $per_page; 178 179 $output = ''; 180 foreach ( $terms as $key => $term ) { 181 182 if ( $count >= $end ) 183 break; 184 185 if ( $term->parent != $parent && empty( $_REQUEST['s'] ) ) 186 continue; 187 188 // If the page starts in a subtree, print the parents. 189 if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) { 190 $my_parents = $parent_ids = array(); 191 $p = $term->parent; 192 while ( $p ) { 193 $my_parent = get_term( $p, $taxonomy ); 194 $my_parents[] = $my_parent; 195 $p = $my_parent->parent; 196 if ( in_array( $p, $parent_ids ) ) // Prevent parent loops. 197 break; 198 $parent_ids[] = $p; 199 } 200 unset( $parent_ids ); 201 202 $num_parents = count( $my_parents ); 203 while ( $my_parent = array_pop( $my_parents ) ) { 204 $output .= "\t" . $this->single_row( $my_parent, $level - $num_parents, $taxonomy ); 205 $num_parents--; 206 } 207 } 208 209 if ( $count >= $start ) 210 $output .= "\t" . $this->single_row( $term, $level, $taxonomy ); 211 212 ++$count; 213 214 unset( $terms[$key] ); 215 216 if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) ) 217 $output .= $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 ); 218 } 219 220 return $output; 221 } 222 223 function single_row( $tag, $level = 0 ) { 224 static $row_class = ''; 225 $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); 226 227 $this->level = $level; 228 229 echo '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>'; 230 echo $this->single_row_columns( $tag ); 231 echo '</tr>'; 232 } 233 234 function column_cb( $tag ) { 235 global $taxonomy, $tax; 236 237 $default_term = get_option( 'default_' . $taxonomy ); 238 239 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) 240 return '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" />'; 241 else 242 return ' '; 243 } 244 245 function column_name( $tag ) { 246 global $taxonomy, $tax, $post_type; 247 248 $default_term = get_option( 'default_' . $taxonomy ); 249 250 $pad = str_repeat( '— ', max( 0, $this->level ) ); 251 $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); 252 $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); 253 $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $post_type ) ); 254 255 $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $name ) ) . '">' . $name . '</a></strong><br />'; 256 257 $actions = array(); 258 if ( current_user_can( $tax->cap->edit_terms ) ) { 259 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; 260 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick Edit' ) . '</a>'; 261 } 262 if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) 263 $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>"; 264 265 $actions = apply_filters( 'tag_row_actions', $actions, $tag ); 266 $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag ); 267 268 $out .= $this->row_actions( $actions ); 269 $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; 270 $out .= '<div class="name">' . $qe_data->name . '</div>'; 271 $out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>'; 272 $out .= '<div class="parent">' . $qe_data->parent . '</div></div>'; 273 274 return $out; 275 } 276 277 function column_description( $tag ) { 278 return $tag->description; 279 } 280 281 function column_slug( $tag ) { 282 return apply_filters( 'editable_slug', $tag->slug ); 283 } 284 285 function column_posts( $tag ) { 286 global $taxonomy, $post_type; 287 288 $count = number_format_i18n( $tag->count ); 289 290 $tax = get_taxonomy( $taxonomy ); 291 292 if ( ! $tax->public ) 293 return $count; 294 295 if ( $tax->query_var ) { 296 $args = array( $tax->query_var => $tag->slug ); 297 } else { 298 $args = array( 'taxonomy' => $tax->name, 'term' => $tag->slug ); 299 } 300 301 $args['post_type'] = $post_type; 302 303 return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>"; 304 } 305 306 function column_links( $tag ) { 307 $count = number_format_i18n( $tag->count ); 308 if ( $count ) 309 $count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>"; 310 return $count; 311 } 312 313 function column_default( $tag, $column_name ) { 314 $screen = get_current_screen(); 315 316 return apply_filters( "manage_{$screen->taxonomy}_custom_column", '', $column_name, $tag->term_id ); 317 } 318 319 /** 320 * Outputs the hidden row displayed when inline editing 321 * 322 * @since 3.1.0 323 */ 324 function inline_edit() { 325 global $tax; 326 327 if ( ! current_user_can( $tax->cap->edit_terms ) ) 328 return; 329 ?> 330 331 <form method="get" action=""><table style="display: none"><tbody id="inlineedit"> 332 <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange"> 333 334 <fieldset><div class="inline-edit-col"> 335 <h4><?php _e( 'Quick Edit' ); ?></h4> 336 337 <label> 338 <span class="title"><?php _e( 'Name' ); ?></span> 339 <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span> 340 </label> 341 <?php if ( !global_terms_enabled() ) { ?> 342 <label> 343 <span class="title"><?php _e( 'Slug' ); ?></span> 344 <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span> 345 </label> 346 <?php } ?> 347 </div></fieldset> 348 <?php 349 350 $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true ); 351 352 list( $columns ) = $this->get_column_info(); 353 354 foreach ( $columns as $column_name => $column_display_name ) { 355 if ( isset( $core_columns[$column_name] ) ) 356 continue; 357 358 do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $tax->name ); 359 } 360 361 ?> 362 363 <p class="inline-edit-save submit"> 364 <a accesskey="c" href="#inline-edit" title="<?php _e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a> 365 <?php $update_text = $tax->labels->update_item; ?> 366 <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a> 367 <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> 368 <span class="error" style="display:none;"></span> 369 <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?> 370 <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" /> 371 <br class="clear" /> 372 </p> 373 </td></tr> 374 </tbody></table></form> 375 <?php 376 } 377 } 378 379 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jun 1 08:30:02 2011 |
Cross-referenced by PHPXref 0.7 Provided by Yoast and awesome WordPress Hosting |