PluginProbe
TablePress – Tables in WordPress made easy / 3.0.4
TablePress – Tables in WordPress made easy v3.0.4
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 3.0.4, at views/view-list.php

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