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