PluginProbe
TablePress – Tables in WordPress made easy / 2.4.2
TablePress – Tables in WordPress made easy v2.4.2
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
tablepress / views / view-list.php

view-list.php in TablePress – Tables in WordPress made easy 2.4.2, at views/view-list.php

408 lines 21.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * List Tables View
4 *
5 * @package TablePress
6 * @subpackage Views
7 * @author Tobias Bäthge
8 * @since 1.0.0
9 */
10
11 // Prohibit direct script loading.
12 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13
14 /**
15 * List Tables View class
16 *
17 * @package TablePress
18 * @subpackage Views
19 * @author Tobias Bäthge
20 * @since 1.0.0
21 */
22 class TablePress_List_View extends TablePress_View {
23
24 /**
25 * Object for the All Tables List Table.
26 *
27 * @since 1.0.0
28 * @var TablePress_All_Tables_List_Table
29 */
30 protected $wp_list_table;
31
32 /**
33 * Set up the view with data and do things that are specific for this view.
34 *
35 * @since 1.0.0
36 *
37 * @param string $action Action for this view.
38 * @param array<string, mixed> $data Data for this view.
39 */
40 #[\Override]
41 public function setup( /* string */ $action, array $data ) /* : void */ {
42 // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
43
44 parent::setup( $action, $data );
45
46 add_thickbox(); // For the table preview.
47 $this->admin_page->enqueue_script( 'list' );
48
49 if ( $data['messages']['superseded_extensions'] ) {
50 $superseded_extensions = array(
51 'tablepress-advanced-access-rights/tablepress-advanced-access-rights.php' => array(
52 'name' => 'TablePress Extension: Advanced Access Rights',
53 'compatible' => true,
54 ),
55 'tablepress-auto-export-tables/tablepress-auto-export-tables.php' => array(
56 'name' => 'TablePress Extension: Automatic Table Export',
57 'compatible' => true,
58 ),
59 'tablepress-cell-highlighting/tablepress-cell-highlighting.php' => array(
60 'name' => 'TablePress Extension: Cell Highlighting',
61 'compatible' => true,
62 ),
63 'tablepress-datatables-alphabetsearch/tablepress-datatables-alphabetsearch.php' => array(
64 'name' => 'TablePress Extension: DataTables AlphabetSearch',
65 'compatible' => false,
66 ),
67 'tablepress-datatables-buttons/tablepress-datatables-buttons.php' => array(
68 'name' => 'TablePress Extension: DataTables Buttons',
69 'compatible' => true,
70 ),
71 'tablepress-datatables-column-filter-widgets/tablepress-datatables-column-filter-widgets.php' => array(
72 'name' => 'TablePress Extension: DataTables ColumnFilterWidgets',
73 'compatible' => false,
74 ),
75 'tablepress-datatables-columnfilter/tablepress-datatables-columnfilter.php' => array(
76 'name' => 'TablePress Extension: DataTables Column Filter',
77 'compatible' => false,
78 ),
79 'tablepress-datatables-counter-column/tablepress-datatables-counter-column.php' => array(
80 'name' => 'TablePress Extension: DataTables Counter Column',
81 'compatible' => true,
82 ),
83 'tablepress-datatables-fixedcolumns/tablepress-datatables-fixedcolumns.php' => array(
84 'name' => 'TablePress Extension: DataTables FixedColumns',
85 'compatible' => false,
86 ),
87 'tablepress-datatables-fixedheader/tablepress-datatables-fixedheader.php' => array(
88 'name' => 'TablePress Extension: DataTables FixedHeader',
89 'compatible' => true,
90 ),
91 'tablepress-datatables-row-details/tablepress-datatables-row-details.php' => array(
92 'name' => 'TablePress Extension: DataTables Row Details',
93 'compatible' => false,
94 ),
95 'tablepress-datatables-rowgroup/tablepress-datatables-rowgroup.php' => array(
96 'name' => 'TablePress Extension: DataTables RowGroup',
97 'compatible' => false,
98 ),
99 'tablepress-responsive-tables/tablepress-responsive-tables.php' => array(
100 'name' => 'TablePress Extension: Responsive Tables',
101 'compatible' => false,
102 ),
103 'tablepress-row-filter/tablepress-row-filter.php' => array(
104 'name' => 'TablePress Extension: Row Filtering',
105 'compatible' => true,
106 ),
107 'tablepress-row-highlighting/tablepress-row-highlighting.php' => array(
108 'name' => 'TablePress Extension: Row Highlighting',
109 'compatible' => true,
110 ),
111 'tablepress-table-auto-update/tablepress-table-auto-update.php' => array(
112 'name' => 'TablePress Extension: Table Auto Update',
113 'compatible' => true,
114 ),
115 'tablepress-table-column-order/tablepress-table-column-order.php' => array(
116 'name' => 'TablePress Extension: Table Column Order',
117 'compatible' => true,
118 ),
119 );
120
121 $active_compatible_superseded_extensions = array();
122 $active_incompatible_superseded_extensions = array();
123 foreach ( $superseded_extensions as $plugin => $extension ) {
124 if ( is_plugin_active( $plugin ) ) {
125 if ( $extension['compatible'] ) {
126 $active_compatible_superseded_extensions[] = $extension['name'];
127 } else {
128 $active_incompatible_superseded_extensions[] = $extension['name'];
129 }
130 }
131 }
132
133 /*
134 * If no superseded extensions are used, hide the message, to prevent running the checks on every load of the view.
135 * This leaves a small risk of an Extension being activated later, but that's acceptable as they are no longer publicly available.
136 */
137 if ( empty( $active_incompatible_superseded_extensions ) && ( empty( $active_compatible_superseded_extensions ) || ! tb_tp_fs()->is_free_plan() ) ) {
138 TablePress::$model_options->update( 'message_superseded_extensions', false );
139 }
140
141 $message = '';
142
143 $notice_css_classes = 'not-dismissible';
144
145 if ( ! empty( $active_incompatible_superseded_extensions ) ) {
146 $notice_css_classes .= ' notice-error notice-large';
147
148 $message .= '<p style="font-size:16px;">' . __( 'You are using <strong>TablePress Extension plugins</strong> on this website that have been retired more than 2 years ago.', 'tablepress' ) . '<br>' . __( 'For technical reasons, some or all features of these outdated plugins <strong>will stop working with TablePress 3</strong> later this year:', 'tablepress' ) . '</p>';
149 $message .= '<ul style="list-style:disc;margin:0.5em 1em;font-size:16px;">';
150 foreach ( $active_incompatible_superseded_extensions as $extension ) {
151 $message .= '<li>' . esc_html( $extension ) . '</li>';
152 }
153 $message .= '</ul>';
154 $message .= '<p style="font-size:16px;"><strong>' . __( 'Keeping them activated can lead to errors on your website.', 'tablepress' ) . '</strong></p>';
155
156 if ( tb_tp_fs()->is_free_plan() ) {
157 $message .= '<p style="font-size:16px;"><strong>' . sprintf( __( 'To continue using these features, <a href="%s">upgrade to a TablePress Premium license plan</a>!', 'tablepress' ), 'https://tablepress.org/upgrade-extensions/?utm_source=plugin&utm_medium=textlink&utm_content=superseded-extensions-message' ) . '</strong><br>'
158 . __( 'TablePress Pro and TablePress Max come with updated and heavily improved versions of these features and include direct priority email support.', 'tablepress' ) . '</p>';
159 }
160
161 if ( ! empty( $active_compatible_superseded_extensions ) && tb_tp_fs()->is_free_plan() ) {
162 $message .= '<p style="margin-top:1em;font-size:14px;">' . __( 'In addition, these TablePress Extension plugins have been retired and might become incompatible in the future as well:', 'tablepress' ) . '</strong></p>';
163 $message .= '<ul style="list-style:disc;margin:0.5em 1em;font-size:14px;">';
164 foreach ( $active_compatible_superseded_extensions as $extension ) {
165 $message .= '<li>' . esc_html( $extension ) . '</li>';
166 }
167 $message .= '</ul>';
168 }
169 } elseif ( ! empty( $active_compatible_superseded_extensions ) && tb_tp_fs()->is_free_plan() ) {
170 $notice_css_classes .= ' notice-warning notice-alt';
171
172 $message .= '<p style="font-size:14px;"><strong>' . __( 'You are using TablePress Extension plugins on this website that have been retired and will no longer receive updates or support:', 'tablepress' ) . '</strong></p>';
173 $message .= '<ul style="list-style:disc;margin:0.5em 1em;">';
174 foreach ( $active_compatible_superseded_extensions as $extension ) {
175 $message .= '<li>' . esc_html( $extension ) . '</li>';
176 }
177 $message .= '</ul>';
178 $message .= '<p style="font-size:14px;"><strong>' . __( 'It is possible that these become incompatible with TablePress or WordPress in the future!', 'tablepress' ) . '</strong></p>';
179 $message .= '<p style="margin-top:1em;font-size:14px;">' . sprintf( __( 'However, their features were heavily improved and are now part of the up-to-date <a href="%s">TablePress Premium versions</a>!', 'tablepress' ), 'https://tablepress.org/upgrade-extensions/?utm_source=plugin&utm_medium=textlink&utm_content=superseded-extensions-message' ) . '</p>';
180 }
181
182 if ( '' !== $message ) {
183 if ( tb_tp_fs()->is_free_plan() ) {
184 $message .= '<p style="font-size:16px;margin-top:1.5em;"><strong>' . __( 'Upgrade to a TablePress Premium license plan now and get:', 'tablepress' ) . '</strong></p>';
185 $message .= '<ul style="list-style:disc;margin:0.5em 1em;font-size:16px;">';
186 $message .= '<li>' . __( 'Updated and heavily improved versions of these features!', 'tablepress' ) . '</li>';
187 $message .= '<li>' . __( 'Direct integration into the user interface!', 'tablepress' ) . '</li>';
188 $message .= '<li>' . __( 'Regular updates that ensure compatibility with WordPress!', 'tablepress' ) . '</li>';
189 $message .= '<li>' . __( 'Priority email support!', 'tablepress' ) . '</li>';
190 $message .= '</ul>';
191 $message .= '<p style="font-size:16px;"><strong>' . sprintf( __( 'And the best: %s', 'tablepress' ), sprintf( __( 'Use the promo code %1$s during the checkout process and save %2$s now!', 'tablepress' ), '<code>THANKYOU30</code>', '30%' ) ) . '</strong></p>';
192 $message .= '<p style="margin-top:2em;">' . sprintf( '<a href="%s" class="button button-primary" style="font-size:14px;margin-right:3em;background:linear-gradient(135deg,#00d184 0%%,#0791e3 100%%);border:none;font-weight:bold;">%s<span class="dashicons dashicons-arrow-right-alt" style="vertical-align:middle;margin:0 0 4px 4px"></span></a>', 'https://tablepress.org/upgrade-extensions/?utm_source=plugin&utm_medium=button&utm_content=superseded-extensions-message', __( 'Upgrade to a TablePress Premium version now!', 'tablepress' ) );
193 }
194 $message .= $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'superseded_extensions', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>';
195
196 $title = '<em>' . __( 'Important Notice!', 'tablepress' ) . '</em>';
197
198 $this->add_header_message( $message, $notice_css_classes, $title );
199 }
200 }
201
202 if ( $data['messages']['first_visit'] ) {
203 $message = '<p style="font-size:14px;"><strong>' . __( 'Thank you for choosing TablePress, the most popular table plugin for WordPress!', 'tablepress' ) . '</strong></p>';
204 $message .= '<p>' . sprintf( __( 'If you encounter any questions or problems, please visit the <a href="%1$s">FAQ</a>, the <a href="%2$s">Documentation</a>, and the <a href="%3$s">Support</a> section on the <a href="%4$s">plugin website</a>.', 'tablepress' ), 'https://tablepress.org/faq/', 'https://tablepress.org/documentation/', 'https://tablepress.org/support/', 'https://tablepress.org/' ) . '</p>';
205
206 if ( tb_tp_fs()->is_free_plan() ) {
207 $message .= '<p style="font-size:14px;"><strong>' . sprintf( __( 'More great features for you and your site’s visitors and priority email support are available with a Premium license plan of TablePress. <a href="%s">Go check them out!</a>', 'tablepress' ), 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=first-visit-message' ) . '</strong></p>';
208 }
209
210 $message .= '<p style="margin-top:1em;">' . $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'first_visit', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>';
211
212 $title = '<em>' . __( 'Welcome!', 'tablepress' ) . '</em>';
213
214 $this->add_header_message( $message, 'notice-info not-dismissible', $title );
215 }
216
217 if ( $data['messages']['donation_nag'] ) {
218 $message = '<p style="font-size:14px;"><img alt="' . esc_attr__( 'Tobias Bäthge, developer of TablePress', 'tablepress' ) . '" src="https://secure.gravatar.com/avatar/50f1cff2e27a1f522b18ce229c057bc5?s=300" height="150" width="150" style="float:left;margin:2px 15px 30px 0;">'
219 . __( 'Hi, my name is Tobias, I&#8217;m the developer of the TablePress plugin.', 'tablepress' ) . '</p>';
220 $message .= '<p style="font-size:14px;">' . __( 'Thank you for using it!', 'tablepress' ) . ' ';
221 if ( $data['table_count'] > 0 ) {
222 $message .= sprintf( _n( 'I hope that everything works and that you are satisfied with the results of managing your %s table.', 'I hope that everything works and that you are satisfied with the results of managing your %s tables.', $data['table_count'], 'tablepress' ), $data['table_count'] );
223 } else {
224 $message .= sprintf( __( 'It looks like you haven’t added a table yet. If you need help to get started, please find more information in the FAQ and Documentation on the <a href="%s">TablePress website</a>.', 'tablepress' ), 'https://tablepress.org/' );
225 }
226 $message .= '</p>';
227 $message .= '<p style="font-size:14px;"><strong>' . sprintf( __( 'I would like to invite you to check out the <a href="%s">Premium versions of TablePress</a>.', 'tablepress' ), 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=upgrade-message' ) . '<br>'
228 . __( 'The available Pro and Max plans offer user support and many exciting and helpful features for your tables.', 'tablepress' ) . '</strong></p>';
229 $message .= '<p style="font-size:14px;">' . __( 'Sincerely, Tobias', 'tablepress' ) . '</p>';
230 $message .= '<p style="margin-top:1em;">' . sprintf( '<a href="%s" class="button button-primary" style="font-size:14px;margin-right:3em;">%s<span class="dashicons dashicons-arrow-right-alt" style="vertical-align:middle;margin:0 0 4px 4px"></span></a>', 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=button&utm_content=upgrade-message', __( 'Tell me more about the Premium features', 'tablepress' ) )
231 . $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'donation_nag', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>';
232
233 $title = '<em>' . __( 'TablePress has more to offer!', 'tablepress' ) . '</em>';
234
235 $this->add_header_message( $message, 'notice-success not-dismissible', $title );
236 }
237
238 if ( $data['messages']['plugin_update'] ) {
239 $message = '<p>' . sprintf( __( 'To find out more about what’s new, please read the <a href="%s"><strong>release announcement</strong></a>.', 'tablepress' ), 'https://tablepress.org/news/?utm_source=plugin&utm_medium=textlink&utm_content=plugin-update-message' ) . '</p>';
240
241 if ( tb_tp_fs()->is_free_plan() ) {
242 $message .= '<p><strong>' . sprintf( __( 'More great features and priority email support are available with a Premium license plan. <a href="%s">Check them out!</a>', 'tablepress' ), 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=plugin-update-message' ) . '</strong></p>';
243 }
244
245 $message .= '<p style="margin-top:1em;">' . $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'plugin_update', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>';
246
247 $title = '<em>' . sprintf( __( 'Thank you for updating to TablePress %s!', 'tablepress' ), TablePress::version ) . '</em>';
248
249 $this->add_header_message( $message, 'notice-info not-dismissible', $title );
250 }
251
252 $this->process_action_messages( array(
253 'success_delete' => _n( 'The table was deleted successfully.', 'The tables were deleted successfully.', 1, 'tablepress' ),
254 'success_delete_plural' => _n( 'The table was deleted successfully.', 'The tables were deleted successfully.', 2, 'tablepress' ),
255 'error_delete' => __( 'Error: The table could not be deleted.', 'tablepress' ),
256 'success_copy' => _n( 'The table was copied successfully.', 'The tables were copied successfully.', 1, 'tablepress' ) . ( ( false !== $data['table_id'] ) ? ' ' . sprintf( __( 'The copied table has the table ID &#8220;%s&#8221;.', 'tablepress' ), esc_html( $data['table_id'] ) ) : '' ),
257 'success_copy_plural' => _n( 'The table was copied successfully.', 'The tables were copied successfully.', 2, 'tablepress' ),
258 'error_copy' => __( 'Error: The table could not be copied.', 'tablepress' ),
259 'error_no_table' => __( 'Error: You did not specify a valid table ID.', 'tablepress' ),
260 'error_load_table' => __( 'Error: This table could not be loaded!', 'tablepress' ),
261 'error_bulk_action_invalid' => __( 'Error: This bulk action is invalid!', 'tablepress' ),
262 'error_no_selection' => __( 'Error: You did not select any tables!', 'tablepress' ),
263 'error_delete_not_all_tables' => __( 'Notice: Not all selected tables could be deleted!', 'tablepress' ),
264 'error_copy_not_all_tables' => __( 'Notice: Not all selected tables could be copied!', 'tablepress' ),
265 'success_import' => __( 'The tables were imported successfully.', 'tablepress' ),
266 ) );
267
268 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
269 $this->add_text_box( 'tables-list', array( $this, 'textbox_tables_list' ), 'normal' );
270
271 add_screen_option( 'per_page', array( 'label' => __( 'Tables', 'tablepress' ), 'default' => 20 ) ); // Admin_Controller contains function to allow changes to this in the Screen Options to be saved.
272 $this->wp_list_table = TablePress::load_class( 'TablePress_All_Tables_List_Table', 'class-all-tables-list-table.php', 'views' );
273 $this->wp_list_table->set_items( $this->data['table_ids'] );
274 $this->wp_list_table->prepare_items();
275
276 // Cleanup Request URI string, which WP_List_Table uses to generate the sort URLs.
277 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message', 'table_id' ), $_SERVER['REQUEST_URI'] );
278 }
279
280 /**
281 * Render the current view (in this view: without form tag).
282 *
283 * @since 1.0.0
284 */
285 #[\Override]
286 public function render(): void {
287 ?>
288 <div id="tablepress-page" class="wrap">
289 <?php
290 $this->print_nav_tab_menu();
291 ?>
292 <div id="tablepress-body">
293 <hr class="wp-header-end">
294 <?php
295 // Print all header messages.
296 foreach ( $this->header_messages as $message ) {
297 echo $message;
298 }
299
300 // For this screen, this is done in textbox_tables_list(), to get the fields into the correct <form>:
301 // $this->do_text_boxes( 'header' );.
302 ?>
303 <div id="poststuff">
304 <div id="post-body" class="metabox-holder columns-<?php echo ( isset( $GLOBALS['screen_layout_columns'] ) && ( 2 === $GLOBALS['screen_layout_columns'] ) ) ? '2' : '1'; ?>">
305 <div id="postbox-container-2" class="postbox-container">
306 <?php
307 $this->do_text_boxes( 'normal' );
308 $this->do_meta_boxes( 'normal' );
309
310 $this->do_text_boxes( 'additional' );
311 $this->do_meta_boxes( 'additional' );
312
313 // Print all submit buttons.
314 $this->do_text_boxes( 'submit' );
315 ?>
316 </div>
317 <div id="postbox-container-1" class="postbox-container">
318 <?php
319 // Print all boxes in the sidebar.
320 $this->do_text_boxes( 'side' );
321 $this->do_meta_boxes( 'side' );
322 ?>
323 </div>
324 </div>
325 <br class="clear">
326 </div>
327 </div>
328 </div>
329 <?php
330 }
331
332 /**
333 * Print the screen head text.
334 *
335 * @since 1.0.0
336 *
337 * @param array<string, mixed> $data Data for this screen.
338 * @param array<string, mixed> $box Information about the text box.
339 */
340 public function textbox_head( array $data, array $box ): void {
341 echo '<p>';
342 _e( 'This is a list of your tables.', 'tablepress' );
343 echo ' ';
344 // Show the instructions string depending on whether the Block Editor is used on the site or not.
345 if ( $data['site_uses_block_editor'] ) {
346 printf( __( 'To insert a table into a post or page, add a “%1$s” block in the block editor and select the desired table.', 'tablepress' ), __( 'TablePress table', 'tablepress' ) );
347 } else {
348 _e( 'To insert a table into a post or page, paste its Shortcode at the desired place in the editor.', 'tablepress' );
349 echo ' ';
350 _e( 'Each table has a unique ID that needs to be adjusted in that Shortcode.', 'tablepress' );
351 }
352 echo '</p>';
353 }
354
355 /**
356 * Print the content of the "All Tables" text box.
357 *
358 * @since 1.0.0
359 *
360 * @param array<string, mixed> $data Data for this screen.
361 * @param array<string, mixed> $box Information about the text box.
362 */
363 public function textbox_tables_list( array $data, array $box ): void {
364 if ( ! empty( $_GET['s'] ) ) {
365 printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;', 'tablepress' ) . '</span>', esc_html( wp_unslash( $_GET['s'] ) ) );
366 }
367 ?>
368 <form method="get">
369 <?php
370 if ( isset( $_GET['page'] ) ) {
371 echo '<input type="hidden" name="page" value="' . esc_attr( $_GET['page'] ) . '">' . "\n";
372 }
373 $this->wp_list_table->search_box( __( 'Search Tables', 'tablepress' ), 'tables_search' );
374 ?>
375 </form>
376 <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post">
377 <?php
378 // This prints the nonce and action fields for this screen (done here instead of render(), due to moved <form>).
379 $this->do_text_boxes( 'header' );
380 $this->wp_list_table->display();
381 ?>
382 </form>
383 <?php
384 }
385
386 /**
387 * Create HTML code for an AJAXified link.
388 *
389 * @since 1.0.0
390 *
391 * @param array<string, mixed> $params Parameters for the URL.
392 * @param string $text Text for the link.
393 * @return string HTML code for the link.
394 */
395 protected function ajax_link( array $params, string $text ): string {
396 $class = 'ajax-link';
397 if ( ! empty( $params['class'] ) ) {
398 $class .= ' ' . esc_attr( $params['class'] );
399 }
400 $url = TablePress::url( $params, true, 'admin-post.php' );
401 $action = esc_attr( $params['action'] );
402 $item = esc_attr( $params['item'] );
403 $target = esc_attr( $params['target'] ?? '' );
404 return "<a class=\"{$class}\" href=\"{$url}\" data-action=\"{$action}\" data-item=\"{$item}\" data-target=\"{$target}\">{$text}</a>";
405 }
406
407 } // class TablePress_List_View
408