PageRenderTime 70ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/class-wp-links-list-table.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 186 lines | 149 code | 29 blank | 8 comment | 13 complexity | 5f1aa06443590041fcec2ff17b7fde9d MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * Links Manager List Table class.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. * @access private
  9. */
  10. class WP_Links_List_Table extends WP_List_Table {
  11. function __construct() {
  12. parent::__construct( array(
  13. 'plural' => 'bookmarks',
  14. ) );
  15. }
  16. function ajax_user_can() {
  17. return current_user_can( 'manage_links' );
  18. }
  19. function prepare_items() {
  20. global $cat_id, $s, $orderby, $order;
  21. wp_reset_vars( array( 'action', 'cat_id', 'linkurl', 'name', 'image', 'description', 'visible', 'target', 'category', 'link_id', 'submit', 'orderby', 'order', 'links_show_cat_id', 'rating', 'rel', 'notes', 'linkcheck[]', 's' ) );
  22. $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
  23. if ( 'all' != $cat_id )
  24. $args['category'] = $cat_id;
  25. if ( !empty( $s ) )
  26. $args['search'] = $s;
  27. if ( !empty( $orderby ) )
  28. $args['orderby'] = $orderby;
  29. if ( !empty( $order ) )
  30. $args['order'] = $order;
  31. $this->items = get_bookmarks( $args );
  32. }
  33. function no_items() {
  34. _e( 'No links found.' );
  35. }
  36. function get_bulk_actions() {
  37. $actions = array();
  38. $actions['delete'] = __( 'Delete' );
  39. return $actions;
  40. }
  41. function extra_tablenav( $which ) {
  42. global $cat_id;
  43. if ( 'top' != $which )
  44. return;
  45. ?>
  46. <div class="alignleft actions">
  47. <?php
  48. $dropdown_options = array(
  49. 'selected' => $cat_id,
  50. 'name' => 'cat_id',
  51. 'taxonomy' => 'link_category',
  52. 'show_option_all' => __( 'View all categories' ),
  53. 'hide_empty' => true,
  54. 'hierarchical' => 1,
  55. 'show_count' => 0,
  56. 'orderby' => 'name',
  57. );
  58. wp_dropdown_categories( $dropdown_options );
  59. submit_button( __( 'Filter' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) );
  60. ?>
  61. </div>
  62. <?php
  63. }
  64. function get_columns() {
  65. return array(
  66. 'cb' => '<input type="checkbox" />',
  67. 'name' => _x( 'Name', 'link name' ),
  68. 'url' => __( 'URL' ),
  69. 'categories' => __( 'Categories' ),
  70. 'rel' => __( 'Relationship' ),
  71. 'visible' => __( 'Visible' ),
  72. 'rating' => __( 'Rating' )
  73. );
  74. }
  75. function get_sortable_columns() {
  76. return array(
  77. 'name' => 'name',
  78. 'url' => 'url',
  79. 'visible' => 'visible',
  80. 'rating' => 'rating'
  81. );
  82. }
  83. function display_rows() {
  84. global $cat_id;
  85. $alt = 0;
  86. foreach ( $this->items as $link ) {
  87. $link = sanitize_bookmark( $link );
  88. $link->link_name = esc_attr( $link->link_name );
  89. $link->link_category = wp_get_link_cats( $link->link_id );
  90. $short_url = url_shorten( $link->link_url );
  91. $visible = ( $link->link_visible == 'Y' ) ? __( 'Yes' ) : __( 'No' );
  92. $rating = $link->link_rating;
  93. $style = ( $alt++ % 2 ) ? '' : ' class="alternate"';
  94. $edit_link = get_edit_bookmark_link( $link );
  95. ?>
  96. <tr id="link-<?php echo $link->link_id; ?>" valign="middle" <?php echo $style; ?>>
  97. <?php
  98. list( $columns, $hidden ) = $this->get_column_info();
  99. foreach ( $columns as $column_name => $column_display_name ) {
  100. $class = "class='column-$column_name'";
  101. $style = '';
  102. if ( in_array( $column_name, $hidden ) )
  103. $style = ' style="display:none;"';
  104. $attributes = $class . $style;
  105. switch ( $column_name ) {
  106. case 'cb':
  107. echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="'. esc_attr( $link->link_id ) .'" /></th>';
  108. break;
  109. case 'name':
  110. echo "<td $attributes><strong><a class='row-title' href='$edit_link' title='" . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ) . "'>$link->link_name</a></strong><br />";
  111. $actions = array();
  112. $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
  113. $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ) . "' onclick=\"if ( confirm( '" . esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . "' ) ) { return true;}return false;\">" . __( 'Delete' ) . "</a>";
  114. echo $this->row_actions( $actions );
  115. echo '</td>';
  116. break;
  117. case 'url':
  118. echo "<td $attributes><a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a></td>";
  119. break;
  120. case 'categories':
  121. ?><td <?php echo $attributes ?>><?php
  122. $cat_names = array();
  123. foreach ( $link->link_category as $category ) {
  124. $cat = get_term( $category, 'link_category', OBJECT, 'display' );
  125. if ( is_wp_error( $cat ) )
  126. echo $cat->get_error_message();
  127. $cat_name = $cat->name;
  128. if ( $cat_id != $category )
  129. $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
  130. $cat_names[] = $cat_name;
  131. }
  132. echo implode( ', ', $cat_names );
  133. ?></td><?php
  134. break;
  135. case 'rel':
  136. ?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php
  137. break;
  138. case 'visible':
  139. ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
  140. break;
  141. case 'rating':
  142. ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
  143. break;
  144. default:
  145. ?>
  146. <td <?php echo $attributes ?>><?php do_action( 'manage_link_custom_column', $column_name, $link->link_id ); ?></td>
  147. <?php
  148. break;
  149. }
  150. }
  151. ?>
  152. </tr>
  153. <?php
  154. }
  155. }
  156. }
  157. ?>