PluginProbe
Friends / 2.7.9
Friends v2.7.9
4.3.2 4.3.1 4.3.0 4.2.2 4.2.1 4.2.0 4.1.0 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.1 All 88 releases
friends / includes / class-automatic-status-list-table.php

class-automatic-status-list-table.php in Friends 2.7.9, at includes/class-automatic-status-list-table.php

338 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Friends_Automatic_Status_List_Table class
4 *
5 * @package Friends
6 */
7
8 namespace Friends;
9
10 /**
11 * Class used to implement displaying automatic status posts in a list table.
12 *
13 * @see \WP_Posts_List_Table
14 */
15 class Automatic_Status_List_Table extends \WP_Posts_List_Table {
16 /**
17 * Constructor
18 *
19 * @param array $args Array of arguments.
20 */
21 public function __construct( $args = array() ) {
22 parent::__construct(
23 array(
24 'plural' => 'posts',
25 'screen' => \WP_Screen::get( 'edit' ),
26 )
27 );
28 }
29
30 /**
31 * Prepares the list of items for displaying.
32 */
33 public function prepare_items() {
34 global $mode, $avail_post_stati, $wp_query, $per_page;
35 $mode = 'excerpt';
36
37 $post_data = array(
38 'post_type' => 'post',
39 'post_format' => 'status',
40 'post_status' => 'private',
41 'post_author' => get_current_user_id(),
42 );
43
44 $avail_post_stati = get_available_post_statuses( $post_data['post_type'] );
45 if ( ! empty( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati ) ) {
46 $post_data['post_status'] = $_REQUEST['post_status'];
47 } elseif ( isset( $_REQUEST['all_posts'] ) ) {
48 unset( $post_data['post_status'] );
49 }
50
51 wp( $post_data );
52
53 $post_type = $this->screen->post_type;
54 $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
55
56 /** This filter is documented in wp-admin/includes/post.php */
57 $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
58
59 $this->is_trash = 'trash' === $post_data['post_status'];
60 }
61
62 /**
63 * Gets the post status counts.
64 *
65 * @param string $post_type The post type.
66 *
67 * @return object The counts.
68 */
69 protected function get_post_status_counts( $post_type ) {
70 global $wpdb;
71
72 $counts = array();
73 $post_status_counts = $wpdb->get_results(
74 $wpdb->prepare(
75 "SELECT posts.post_status, COUNT(posts.ID) AS count
76 FROM {$wpdb->posts} AS posts
77 JOIN {$wpdb->term_relationships} AS relationships
78 JOIN {$wpdb->term_taxonomy} AS taxonomy
79 JOIN {$wpdb->terms} AS terms
80
81 WHERE posts.post_author = %d
82 AND posts.post_type = %s
83 AND relationships.object_id = posts.ID
84 AND relationships.term_taxonomy_id = taxonomy.term_taxonomy_id
85 AND taxonomy.taxonomy = 'post_format'
86
87 AND terms.slug = 'post-format-status'
88
89 GROUP BY posts.post_status",
90 get_current_user_id(),
91 $post_type
92 )
93 );
94
95 foreach ( $post_status_counts as $row ) {
96 $counts[ $row->post_status ] = $row->count;
97 }
98 return (object) $counts;
99 }
100
101 /**
102 * The no items text.
103 */
104 public function no_items() {
105 if (
106 ( ! isset( $_REQUEST['post_status'] ) && ! isset( $_REQUEST['all_posts'] ) )
107 || ( isset( $_REQUEST['post_status'] ) && 'draft' === $_REQUEST['post_status'] )
108 ) {
109 esc_html_e( 'No unpublished automatically generated statuses found.', 'friends' );
110 } else {
111 esc_html_e( 'No automatically generated statuses found.', 'friends' );
112 }
113 }
114
115 /**
116 * Helper to create links to edit.php with params.
117 *
118 * @param string[] $args Associative array of URL parameters for the link.
119 * @param string $label Link text.
120 * @param string $class_attribute Optional. Class attribute. Default empty string.
121 * @return string The formatted link string.
122 */
123 protected function get_edit_link( $args, $label, $class_attribute = '' ) {
124 $args = array_merge(
125 array(
126 'post_type' => 'post',
127 'post_format' => 'status',
128 'post_author' => get_current_user_id(),
129 ),
130 $args
131 );
132 $url = add_query_arg( $args, self_admin_url( 'admin.php?page=friends-auto-status' ) );
133 $url = remove_query_arg( 'post_type', $url );
134
135 $class_html = '';
136 $aria_current = '';
137
138 if ( ! empty( $class_attribute ) ) {
139 $class_html = sprintf(
140 ' class="%s"',
141 esc_attr( $class_attribute )
142 );
143
144 if ( 'current' === $class_attribute ) {
145 $aria_current = ' aria-current="page"';
146 }
147 }
148
149 return sprintf(
150 '<a href="%s"%s%s>%s</a>',
151 esc_url( $url ),
152 $class_html,
153 $aria_current,
154 $label
155 );
156 }
157
158 /**
159 * Handles the title column output.
160 *
161 * @global string $mode List table view mode.
162 *
163 * @param \WP_Post $post The current \WP_Post object.
164 */
165 public function column_title( $post ) {
166 if ( current_user_can( 'read_post', $post->ID ) ) {
167 echo wp_kses(
168 get_the_content(),
169 array(
170 'img' => array( 'src' => array() ),
171 'a' => array( 'href' => array() ),
172 )
173 );
174 }
175
176 get_inline_data( $post );
177 }
178
179 /**
180 * Gets the list of views available on this table.
181 *
182 * The format is an associative array:
183 * - `'id' => 'link'`
184 *
185 * @return array
186 */
187 protected function get_views() {
188 global $locked_post_status, $avail_post_stati;
189
190 $post_type = $this->screen->post_type;
191
192 if ( ! empty( $locked_post_status ) ) {
193 return array();
194 }
195
196 $status_links = array();
197 $num_posts = $this->get_post_status_counts( $post_type );
198
199 $total_posts = array_sum( (array) $num_posts );
200 $class = '';
201
202 $current_user_id = get_current_user_id();
203 $all_args = array(
204 'post_type' => $post_type,
205 'all_posts' => 1,
206 );
207 $mine = '';
208
209 // Subtract post types that are not included in the admin all list.
210 foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
211 if ( isset( $num_posts->$state ) ) {
212 $total_posts -= $num_posts->$state;
213 }
214 }
215
216 if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) {
217 $class = 'current';
218 }
219
220 $all_inner_html = sprintf(
221 /* translators: %s: Number of posts. */
222 _nx( // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
223 'All <span class="count">(%s)</span>',
224 'All <span class="count">(%s)</span>',
225 $total_posts,
226 'posts'
227 ),
228 number_format_i18n( $total_posts )
229 );
230
231 $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
232
233 if ( $mine ) {
234 $status_links['mine'] = $mine;
235 }
236
237 foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) {
238 $class = '';
239
240 $status_name = $status->name;
241
242 if ( ! in_array( $status_name, $avail_post_stati, true ) || empty( $num_posts->$status_name ) ) {
243 continue;
244 }
245
246 if ( isset( $_REQUEST['post_status'] ) && $status_name === $_REQUEST['post_status'] ) {
247 $class = 'current';
248 } elseif ( ! isset( $_REQUEST['post_status'] ) && ! isset( $_REQUEST['all_posts'] ) && 'draft' === $status_name ) {
249 $class = 'current';
250 }
251
252 $status_args = array(
253 'post_status' => $status_name,
254 'post_type' => $post_type,
255 );
256
257 $status_label = sprintf(
258 translate_nooped_plural( $status->label_count, $num_posts->$status_name ),
259 number_format_i18n( $num_posts->$status_name )
260 );
261
262 $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class );
263 }
264
265 if ( ! empty( $this->sticky_posts_count ) ) {
266 $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : '';
267
268 $sticky_args = array(
269 'post_type' => $post_type,
270 'show_sticky' => 1,
271 );
272
273 $sticky_inner_html = sprintf(
274 /* translators: %s: Number of posts. */
275 _nx( // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
276 'Sticky <span class="count">(%s)</span>',
277 'Sticky <span class="count">(%s)</span>',
278 $this->sticky_posts_count,
279 'posts'
280 ),
281 number_format_i18n( $this->sticky_posts_count )
282 );
283
284 $sticky_link = array(
285 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ),
286 );
287
288 // Sticky comes after Publish, or if not listed, after All.
289 $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ), true );
290 $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
291 }
292 return $status_links;
293 }
294
295 /**
296 * Retrieves the list of bulk actions available for this table.
297 *
298 * @return array
299 */
300 protected function get_bulk_actions() {
301 $actions = array();
302 $post_type_obj = get_post_type_object( $this->screen->post_type );
303
304 if ( current_user_can( $post_type_obj->cap->publish_posts ) ) {
305 $actions['publish'] = __( 'Publish' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
306 }
307
308 if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
309 if ( $this->is_trash ) {
310 $actions['untrash'] = __( 'Restore' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
311 } else {
312 if ( apply_filters( 'friends_debug', false ) ) {
313 $actions['edit'] = __( 'Edit' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
314 }
315 $actions['publish-private'] = __( 'Publish Privately' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
316 }
317 }
318
319 if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
320 if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
321 $actions['delete'] = __( 'Delete permanently' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
322 } else {
323 $actions['trash'] = __( 'Move to Trash' ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain
324 }
325 }
326
327 return $actions;
328 }
329
330 /**
331 * Generates the extra table navigation above or below the table
332 *
333 * @param string $which The location of the bulk actions: 'top' or 'bottom'.
334 */
335 protected function extra_tablenav( $which ) {
336 }
337 }
338