]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-links-list-table.php
WordPress 4.6.3
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-links-list-table.php
1 <?php
2 /**
3  * List Table API: WP_Links_List_Table class
4  *
5  * @package WordPress
6  * @subpackage Administration
7  * @since 3.1.0
8  */
9
10 /**
11  * Core class used to implement displaying links in a list table.
12  *
13  * @since 3.1.0
14  * @access private
15  *
16  * @see WP_List_Tsble
17  */
18 class WP_Links_List_Table extends WP_List_Table {
19
20         /**
21          * Constructor.
22          *
23          * @since 3.1.0
24          * @access public
25          *
26          * @see WP_List_Table::__construct() for more information on default arguments.
27          *
28          * @param array $args An associative array of arguments.
29          */
30         public function __construct( $args = array() ) {
31                 parent::__construct( array(
32                         'plural' => 'bookmarks',
33                         'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
34                 ) );
35         }
36
37         /**
38          *
39          * @return bool
40          */
41         public function ajax_user_can() {
42                 return current_user_can( 'manage_links' );
43         }
44
45         /**
46          *
47          * @global int    $cat_id
48          * @global string $s
49          * @global string $orderby
50          * @global string $order
51          */
52         public function prepare_items() {
53                 global $cat_id, $s, $orderby, $order;
54
55                 wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
56
57                 $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 );
58
59                 if ( 'all' != $cat_id )
60                         $args['category'] = $cat_id;
61                 if ( !empty( $s ) )
62                         $args['search'] = $s;
63                 if ( !empty( $orderby ) )
64                         $args['orderby'] = $orderby;
65                 if ( !empty( $order ) )
66                         $args['order'] = $order;
67
68                 $this->items = get_bookmarks( $args );
69         }
70
71         /**
72          * @access public
73          */
74         public function no_items() {
75                 _e( 'No links found.' );
76         }
77
78         /**
79          *
80          * @return array
81          */
82         protected function get_bulk_actions() {
83                 $actions = array();
84                 $actions['delete'] = __( 'Delete' );
85
86                 return $actions;
87         }
88
89         /**
90          *
91          * @global int $cat_id
92          * @param string $which
93          */
94         protected function extra_tablenav( $which ) {
95                 global $cat_id;
96
97                 if ( 'top' != $which )
98                         return;
99 ?>
100                 <div class="alignleft actions">
101 <?php
102                         $dropdown_options = array(
103                                 'selected' => $cat_id,
104                                 'name' => 'cat_id',
105                                 'taxonomy' => 'link_category',
106                                 'show_option_all' => get_taxonomy( 'link_category' )->labels->all_items,
107                                 'hide_empty' => true,
108                                 'hierarchical' => 1,
109                                 'show_count' => 0,
110                                 'orderby' => 'name',
111                         );
112
113                         echo '<label class="screen-reader-text" for="cat_id">' . __( 'Filter by category' ) . '</label>';
114                         wp_dropdown_categories( $dropdown_options );
115                         submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
116 ?>
117                 </div>
118 <?php
119         }
120
121         /**
122          *
123          * @return array
124          */
125         public function get_columns() {
126                 return array(
127                         'cb'         => '<input type="checkbox" />',
128                         'name'       => _x( 'Name', 'link name' ),
129                         'url'        => __( 'URL' ),
130                         'categories' => __( 'Categories' ),
131                         'rel'        => __( 'Relationship' ),
132                         'visible'    => __( 'Visible' ),
133                         'rating'     => __( 'Rating' )
134                 );
135         }
136
137         /**
138          *
139          * @return array
140          */
141         protected function get_sortable_columns() {
142                 return array(
143                         'name'    => 'name',
144                         'url'     => 'url',
145                         'visible' => 'visible',
146                         'rating'  => 'rating'
147                 );
148         }
149
150         /**
151          * Get the name of the default primary column.
152          *
153          * @since 4.3.0
154          * @access protected
155          *
156          * @return string Name of the default primary column, in this case, 'name'.
157          */
158         protected function get_default_primary_column_name() {
159                 return 'name';
160         }
161
162         /**
163          * Handles the checkbox column output.
164          *
165          * @since 4.3.0
166          * @access public
167          *
168          * @param object $link The current link object.
169          */
170         public function column_cb( $link ) {
171                 ?>
172                 <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label>
173                 <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" />
174                 <?php
175         }
176
177         /**
178          * Handles the link name column output.
179          *
180          * @since 4.3.0
181          * @access public
182          *
183          * @param object $link The current link object.
184          */
185         public function column_name( $link ) {
186                 $edit_link = get_edit_bookmark_link( $link );
187                 printf( '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>',
188                         $edit_link,
189                         /* translators: %s: link name */
190                         esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ),
191                         $link->link_name
192                 );
193         }
194
195         /**
196          * Handles the link URL column output.
197          *
198          * @since 4.3.0
199          * @access public
200          *
201          * @param object $link The current link object.
202          */
203         public function column_url( $link ) {
204                 $short_url = url_shorten( $link->link_url );
205                 echo "<a href='$link->link_url'>$short_url</a>";
206         }
207
208         /**
209          * Handles the link categories column output.
210          *
211          * @since 4.3.0
212          * @access public
213          *
214          * @global $cat_id
215          *
216          * @param object $link The current link object.
217          */
218         public function column_categories( $link ) {
219                 global $cat_id;
220
221                 $cat_names = array();
222                 foreach ( $link->link_category as $category ) {
223                         $cat = get_term( $category, 'link_category', OBJECT, 'display' );
224                         if ( is_wp_error( $cat ) ) {
225                                 echo $cat->get_error_message();
226                         }
227                         $cat_name = $cat->name;
228                         if ( $cat_id != $category ) {
229                                 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
230                         }
231                         $cat_names[] = $cat_name;
232                 }
233                 echo implode( ', ', $cat_names );
234         }
235
236         /**
237          * Handles the link relation column output.
238          *
239          * @since 4.3.0
240          * @access public
241          *
242          * @param object $link The current link object.
243          */
244         public function column_rel( $link ) {
245                 echo empty( $link->link_rel ) ? '<br />' : $link->link_rel;
246         }
247
248         /**
249          * Handles the link visibility column output.
250          *
251          * @since 4.3.0
252          * @access public
253          *
254          * @param object $link The current link object.
255          */
256         public function column_visible( $link ) {
257                 if ( 'Y' === $link->link_visible ) {
258                         _e( 'Yes' );
259                 } else {
260                         _e( 'No' );
261                 }
262         }
263
264         /**
265          * Handles the link rating column output.
266          *
267          * @since 4.3.0
268          * @access public
269          *
270          * @param object $link The current link object.
271          */
272         public function column_rating( $link ) {
273                 echo $link->link_rating;
274         }
275
276         /**
277          * Handles the default column output.
278          *
279          * @since 4.3.0
280          * @access public
281          *
282          * @param object $link        Link object.
283          * @param string $column_name Current column name.
284          */
285         public function column_default( $link, $column_name ) {
286                 /**
287                  * Fires for each registered custom link column.
288                  *
289                  * @since 2.1.0
290                  *
291                  * @param string $column_name Name of the custom column.
292                  * @param int    $link_id     Link ID.
293                  */
294                 do_action( 'manage_link_custom_column', $column_name, $link->link_id );
295         }
296
297         public function display_rows() {
298                 foreach ( $this->items as $link ) {
299                         $link = sanitize_bookmark( $link );
300                         $link->link_name = esc_attr( $link->link_name );
301                         $link->link_category = wp_get_link_cats( $link->link_id );
302 ?>
303                 <tr id="link-<?php echo $link->link_id; ?>">
304                         <?php $this->single_row_columns( $link ) ?>
305                 </tr>
306 <?php
307                 }
308         }
309
310         /**
311          * Generates and displays row action links.
312          *
313          * @since 4.3.0
314          * @access protected
315          *
316          * @param object $link        Link being acted upon.
317          * @param string $column_name Current column name.
318          * @param string $primary     Primary column name.
319          * @return string Row action output for links.
320          */
321         protected function handle_row_actions( $link, $column_name, $primary ) {
322                 if ( $primary !== $column_name ) {
323                         return '';
324                 }
325
326                 $edit_link = get_edit_bookmark_link( $link );
327
328                 $actions = array();
329                 $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
330                 $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>";
331                 return $this->row_actions( $actions );
332         }
333 }