PageRenderTime 56ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

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