WordPress 3.8
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-links-list-table.php
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( $args = array() ) {
13                 parent::__construct( array(
14                         'plural' => 'bookmarks',
15                         'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
16                 ) );
17         }
18
19         function ajax_user_can() {
20                 return current_user_can( 'manage_links' );
21         }
22
23         function prepare_items() {
24                 global $cat_id, $s, $orderby, $order;
25
26                 wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
27
28                 $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
29
30                 if ( 'all' != $cat_id )
31                         $args['category'] = $cat_id;
32                 if ( !empty( $s ) )
33                         $args['search'] = $s;
34                 if ( !empty( $orderby ) )
35                         $args['orderby'] = $orderby;
36                 if ( !empty( $order ) )
37                         $args['order'] = $order;
38
39                 $this->items = get_bookmarks( $args );
40         }
41
42         function no_items() {
43                 _e( 'No links found.' );
44         }
45
46         function get_bulk_actions() {
47                 $actions = array();
48                 $actions['delete'] = __( 'Delete' );
49
50                 return $actions;
51         }
52
53         function extra_tablenav( $which ) {
54                 global $cat_id;
55
56                 if ( 'top' != $which )
57                         return;
58 ?>
59                 <div class="alignleft actions">
60 <?php
61                         $dropdown_options = array(
62                                 'selected' => $cat_id,
63                                 'name' => 'cat_id',
64                                 'taxonomy' => 'link_category',
65                                 'show_option_all' => __( 'View all categories' ),
66                                 'hide_empty' => true,
67                                 'hierarchical' => 1,
68                                 'show_count' => 0,
69                                 'orderby' => 'name',
70                         );
71                         wp_dropdown_categories( $dropdown_options );
72                         submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) );
73 ?>
74                 </div>
75 <?php
76         }
77
78         function get_columns() {
79                 return array(
80                         'cb'         => '<input type="checkbox" />',
81                         'name'       => _x( 'Name', 'link name' ),
82                         'url'        => __( 'URL' ),
83                         'categories' => __( 'Categories' ),
84                         'rel'        => __( 'Relationship' ),
85                         'visible'    => __( 'Visible' ),
86                         'rating'     => __( 'Rating' )
87                 );
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                                                 <th scope="row" class="check-column">
134                                                         <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label>
135                                                         <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
136                                                 </th>
137                                                 <?php
138                                                 break;
139
140                                         case 'name':
141                                                 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 />";
142
143                                                 $actions = array();
144                                                 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
145                                                 $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>";
146                                                 echo $this->row_actions( $actions );
147
148                                                 echo '</td>';
149                                                 break;
150                                         case 'url':
151                                                 echo "<td $attributes><a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a></td>";
152                                                 break;
153                                         case 'categories':
154                                                 ?><td <?php echo $attributes ?>><?php
155                                                 $cat_names = array();
156                                                 foreach ( $link->link_category as $category ) {
157                                                         $cat = get_term( $category, 'link_category', OBJECT, 'display' );
158                                                         if ( is_wp_error( $cat ) )
159                                                                 echo $cat->get_error_message();
160                                                         $cat_name = $cat->name;
161                                                         if ( $cat_id != $category )
162                                                                 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
163                                                         $cat_names[] = $cat_name;
164                                                 }
165                                                 echo implode( ', ', $cat_names );
166                                                 ?></td><?php
167                                                 break;
168                                         case 'rel':
169                                                 ?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php
170                                                 break;
171                                         case 'visible':
172                                                 ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php
173                                                 break;
174                                         case 'rating':
175                                                 ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php
176                                                 break;
177                                         default:
178                                                 /**
179                                                  * Fires for each registered custom link column.
180                                                  *
181                                                  * @since 2.1.0
182                                                  *
183                                                  * @param string $column_name Name of the custom column.
184                                                  * @param int    $link_id     Link ID.
185                                                  */
186                                                 ?>
187                                                 <td <?php echo $attributes ?>><?php do_action( 'manage_link_custom_column', $column_name, $link->link_id ); ?></td>
188                                                 <?php
189                                                 break;
190                                 }
191                         }
192 ?>
193                 </tr>
194 <?php
195                 }
196         }
197 }