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1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / ProductDownloads / ApprovedDirectories / Admin / Table.php
woocommerce / src / Internal / ProductDownloads / ApprovedDirectories / Admin Last commit date
SyncUI.php 4 years ago Table.php 4 years ago UI.php 4 years ago
Table.php
331 lines
1 <?php
2
3 namespace Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Admin;
4
5 use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Register;
6 use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\StoredUrl;
7 use WP_List_Table;
8 use WP_Screen;
9
10 /**
11 * Admin list table used to render our current list of approved directories.
12 */
13 class Table extends WP_List_Table {
14 /**
15 * Initialize the webhook table list.
16 */
17 public function __construct() {
18 parent::__construct(
19 array(
20 'singular' => 'url',
21 'plural' => 'urls',
22 'ajax' => false,
23 )
24 );
25
26 add_filter( 'manage_woocommerce_page_wc-settings_columns', array( $this, 'get_columns' ) );
27 $this->items_per_page();
28 set_screen_options();
29 }
30
31 /**
32 * Sets up an items-per-page control.
33 */
34 private function items_per_page() {
35 add_screen_option(
36 'per_page',
37 array(
38 'default' => 20,
39 'option' => 'edit_approved_directories_per_page',
40 )
41 );
42
43 add_filter( 'set_screen_option_edit_approved_directories_per_page', array( $this, 'set_items_per_page' ), 10, 3 );
44 }
45
46 /**
47 * Saves the items-per-page setting.
48 *
49 * @param mixed $default The default value.
50 * @param string $option The option being configured.
51 * @param int $value The submitted option value.
52 *
53 * @return mixed
54 */
55 public function set_items_per_page( $default, string $option, int $value ) {
56 return 'edit_approved_directories_per_page' === $option ? absint( $value ) : $default;
57 }
58
59 /**
60 * No items found text.
61 */
62 public function no_items() {
63 esc_html_e( 'No approved directory URLs found.', 'woocommerce' );
64 }
65
66 /**
67 * Displays the list of views available on this table.
68 */
69 public function render_views() {
70 $register = wc_get_container()->get( Register::class );
71
72 $enabled_count = $register->count( true );
73 $disabled_count = $register->count( false );
74 $all_count = $enabled_count + $disabled_count;
75 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
76 $selected_view = isset( $_REQUEST['view'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['view'] ) ) : 'all';
77
78 $all_url = esc_url( add_query_arg( 'view', 'all', $this->get_base_url() ) );
79 $all_class = 'all' === $selected_view ? 'class="current"' : '';
80 $all_text = sprintf(
81 /* translators: %s is the count of approved directory list entries. */
82 _nx(
83 'All <span class="count">(%s)</span>',
84 'All <span class="count">(%s)</span>',
85 $all_count,
86 'Approved product download directory views',
87 'woocommerce'
88 ),
89 $all_count
90 );
91
92 $enabled_url = esc_url( add_query_arg( 'view', 'enabled', $this->get_base_url() ) );
93 $enabled_class = 'enabled' === $selected_view ? 'class="current"' : '';
94 $enabled_text = sprintf(
95 /* translators: %s is the count of enabled approved directory list entries. */
96 _nx(
97 'Enabled <span class="count">(%s)</span>',
98 'Enabled <span class="count">(%s)</span>',
99 $enabled_count,
100 'Approved product download directory views',
101 'woocommerce'
102 ),
103 $enabled_count
104 );
105
106 $disabled_url = esc_url( add_query_arg( 'view', 'disabled', $this->get_base_url() ) );
107 $disabled_class = 'disabled' === $selected_view ? 'class="current"' : '';
108 $disabled_text = sprintf(
109 /* translators: %s is the count of disabled directory list entries. */
110 _nx(
111 'Disabled <span class="count">(%s)</span>',
112 'Disabled <span class="count">(%s)</span>',
113 $disabled_count,
114 'Approved product download directory views',
115 'woocommerce'
116 ),
117 $disabled_count
118 );
119
120 $views = array(
121 'all' => "<a href='{$all_url}' {$all_class}>{$all_text}</a>",
122 'enabled' => "<a href='{$enabled_url}' {$enabled_class}>{$enabled_text}</a>",
123 'disabled' => "<a href='{$disabled_url}' {$disabled_class}>{$disabled_text}</a>",
124 );
125
126 $this->screen->render_screen_reader_content( 'heading_views' );
127
128 echo '<ul class="subsubsub list-table-filters">';
129 foreach ( $views as $slug => $view ) {
130 $views[ $slug ] = "<li class='{$slug}'>{$view}";
131 }
132 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
133 echo implode( ' | </li>', $views ) . "</li>\n";
134 echo '</ul>';
135 }
136
137 /**
138 * Get list columns.
139 *
140 * @return array
141 */
142 public function get_columns() {
143 return array(
144 'cb' => '<input type="checkbox" />',
145 'title' => _x( 'URL', 'Approved product download directories', 'woocommerce' ),
146 'enabled' => _x( 'Enabled', 'Approved product download directories', 'woocommerce' ),
147 );
148 }
149
150 /**
151 * Checklist column, used for selecting items for processing by a bulk action.
152 *
153 * @param StoredUrl $item The approved directory information for the current row.
154 *
155 * @return string
156 */
157 public function column_cb( $item ) {
158 return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', esc_attr( $this->_args['singular'] ), esc_attr( $item->get_id() ) );
159 }
160
161 /**
162 * URL column.
163 *
164 * @param StoredUrl $item The approved directory information for the current row.
165 *
166 * @return string
167 */
168 public function column_title( $item ) {
169 $id = (int) $item->get_id();
170 $url = esc_html( $item->get_url() );
171 $enabled = $item->is_enabled();
172
173 $edit_url = esc_url( $this->get_action_url( 'edit', $id ) );
174 $enable_disable_url = esc_url( $enabled ? $this->get_action_url( 'disable', $id ) : $this->get_action_url( 'enable', $id ) );
175 $enable_disable_text = esc_html( $enabled ? __( 'Disable', 'woocommerce' ) : __( 'Enable', 'woocommerce' ) );
176 $delete_url = esc_url( $this->get_action_url( 'delete', $id ) );
177 $edit_link = "<a href='{$edit_url}'>" . esc_html_x( 'Edit', 'Product downloads list', 'woocommerce' ) . '</a>';
178 $enable_disable_link = "<a href='{$enable_disable_url}'>{$enable_disable_text}</a>";
179 $delete_link = "<a href='{$delete_url}' class='submitdelete wc-confirm-delete'>" . esc_html_x( 'Delete permanently', 'Product downloads list', 'woocommerce' ) . '</a>';
180 $url_link = "<a href='{$edit_url}'>{$url}</a>";
181
182 return "
183 <strong>{$url_link}</strong>
184 <div class='row-actions'>
185 <span class='id'>ID: {$id}</span> |
186 <span class='edit'>{$edit_link}</span> |
187 <span class='enable-disable'>{$enable_disable_link}</span> |
188 <span class='delete'><a class='submitdelete'>{$delete_link}</a></span>
189 </div>
190 ";
191 }
192
193 /**
194 * Rule-is-enabled column.
195 *
196 * @param StoredUrl $item The approved directory information for the current row.
197 *
198 * @return string
199 */
200 public function column_enabled( StoredUrl $item ): string {
201 return $item->is_enabled()
202 ? '<mark class="yes" title="' . esc_html__( 'Enabled', 'woocommerce' ) . '"><span class="dashicons dashicons-yes"></span></mark>'
203 : '<mark class="no" title="' . esc_html__( 'Disabled', 'woocommerce' ) . '">&ndash;</mark>';
204 }
205
206 /**
207 * Get bulk actions.
208 *
209 * @return array
210 */
211 protected function get_bulk_actions() {
212 return array(
213 'enable' => __( 'Enable rule', 'woocommerce' ),
214 'disable' => __( 'Disable rule', 'woocommerce' ),
215 'delete' => __( 'Delete permanently', 'woocommerce' ),
216 );
217 }
218
219 /**
220 * Builds an action URL (ie, to edit or delete a row).
221 *
222 * @param string $action The action to be created.
223 * @param int $id The ID that is the subject of the action.
224 * @param string $nonce_action Action used to add a nonce to the URL.
225 *
226 * @return string
227 */
228 public function get_action_url( string $action, int $id, string $nonce_action = 'modify_approved_directories' ): string {
229 return add_query_arg(
230 array(
231 'check' => wp_create_nonce( $nonce_action ),
232 'action' => $action,
233 'url' => $id,
234 ),
235 $this->get_base_url()
236 );
237 }
238
239 /**
240 * Supplies the 'base' admin URL for this admin table.
241 *
242 * @return string
243 */
244 public function get_base_url(): string {
245 return add_query_arg(
246 array(
247 'page' => 'wc-settings',
248 'tab' => 'products',
249 'section' => 'download_urls',
250 ),
251 admin_url( 'admin.php' )
252 );
253 }
254
255 /**
256 * Generate the table navigation above or below the table.
257 * Included to remove extra nonce input.
258 *
259 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
260 */
261 protected function display_tablenav( $which ) {
262 $directories = wc_get_container()->get( Register::class );
263 echo '<div class="tablenav ' . esc_attr( $which ) . '">';
264
265 if ( $this->has_items() ) {
266 echo '<div class="alignleft actions bulkactions">';
267 $this->bulk_actions( $which );
268
269 if ( $directories->count( false ) > 0 ) {
270 echo '<a href="' . esc_url( $this->get_action_url( 'enable-all', 0 ) ) . '" class="wp-core-ui button">' . esc_html_x( 'Enable All', 'Approved product download directories', 'woocommerce' ) . '</a> ';
271 }
272
273 if ( $directories->count( true ) > 0 ) {
274 echo '<a href="' . esc_url( $this->get_action_url( 'disable-all', 0 ) ) . '" class="wp-core-ui button">' . esc_html_x( 'Disable All', 'Approved product download directories', 'woocommerce' ) . '</a>';
275 }
276
277 echo '</div>';
278 }
279
280 $this->pagination( $which );
281 echo '<br class="clear" />';
282 echo '</div>';
283 }
284
285 /**
286 * Prepare table list items.
287 */
288 public function prepare_items() {
289 // phpcs:disable WordPress.Security.NonceVerification.Recommended
290 // phpcs:disable WordPress.Security.NonceVerification.Missing
291 $current_page = $this->get_pagenum();
292 $per_page = $this->get_items_per_page( 'edit_approved_directories_per_page' );
293 $search = sanitize_text_field( wp_unslash( $_REQUEST['s'] ?? '' ) );
294
295 switch ( $_REQUEST['view'] ?? '' ) {
296 case 'enabled':
297 $enabled = true;
298 break;
299
300 case 'disabled':
301 $enabled = false;
302 break;
303
304 default:
305 $enabled = null;
306 break;
307 }
308 // phpcs:enable
309
310 $approved_directories = wc_get_container()->get( Register::class )->list(
311 array(
312 'page' => $current_page,
313 'per_page' => $per_page,
314 'search' => $search,
315 'enabled' => $enabled,
316 )
317 );
318
319 $this->items = $approved_directories['approved_directories'];
320
321 // Set the pagination.
322 $this->set_pagination_args(
323 array(
324 'total_items' => $approved_directories['total_urls'],
325 'total_pages' => $approved_directories['total_pages'],
326 'per_page' => $per_page,
327 )
328 );
329 }
330 }
331