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