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

279 lines 14.0 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 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 parent::setup( $action, $data );
43
44 add_thickbox(); // For the table preview.
45 $this->admin_page->enqueue_script( 'list' );
46
47 if ( $data['messages']['first_visit'] ) {
48 $message = '<p><strong style="font-size:14px;">' . __( 'Thank you for choosing TablePress, the most popular table plugin for WordPress!', 'tablepress' ) . '</strong></p>';
49 $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>';
50
51 if ( tb_tp_fs()->is_free_plan() ) {
52 $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>';
53 }
54
55 $message .= '<p style="margin-top:14px;">' . $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'first_visit', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>';
56
57 $title = '<em>' . __( 'Welcome!', 'tablepress' ) . '</em>';
58
59 $this->add_header_message( $message, 'notice-info not-dismissible', $title );
60 }
61
62 if ( $data['messages']['donation_message'] ) {
63 $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;" />'
64 . __( 'Hi, my name is Tobias, I&#8217;m the developer of the TablePress plugin.', 'tablepress' ) . '</p>';
65 $message .= '<p style="font-size:14px;">' . __( 'Thank you for using it!', 'tablepress' ) . ' ';
66 if ( $data['table_count'] > 0 ) {
67 $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'] );
68 } else {
69 $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/' );
70 }
71 $message .= '</p>';
72 $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 />'
73 . __( 'The available Pro and Max plans offer user support and many exciting and helpful features for your tables.', 'tablepress' ) . '</strong></p>';
74 $message .= '<p style="font-size:14px;">' . __( 'Sincerely, Tobias', 'tablepress' ) . '</p>';
75 $message .= '<p>' . sprintf( '<a href="%s" class="button button-primary" style="font-size:14px;margin-right:1em">%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=textlink&utm_content=upgrade-message', __( 'Tell me more about the Premium features', 'tablepress' ) )
76 . $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'donation_nag', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>';
77
78 $title = '<em>' . __( 'TablePress has more to offer!', 'tablepress' ) . '</em>';
79
80 $this->add_header_message( $message, 'notice-success not-dismissible', $title );
81 }
82
83 if ( $data['messages']['plugin_update_message'] ) {
84 $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/' ) . '</p>';
85
86 if ( tb_tp_fs()->is_free_plan() ) {
87 $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>';
88 }
89
90 $url = 'https://tablepress.org/modules/default-style-customizer/?utm_source=plugin&utm_medium=textlink&utm_content=plugin-update-message';
91 $button_label = __( 'Find out more', 'tablepress' );
92
93 /*
94 * Show the message only if the user is on
95 * the Free plan or has the "tablepress_edit_options" capability.
96 */
97 if ( tb_tp_fs()->is_free_plan() || current_user_can( 'tablepress_edit_options' ) ) {
98 $message .= '<p style="font-size:14px;"><strong>' . __( 'Here’s the latest great addition:', 'tablepress' ) . '</strong></p>';
99 $message .= '<div style="display:flex;max-width:625px;gap:20px;font-size:14px;border:1px solid #c3c4c7;box-shadow:0 1px 1px rgba(0, 0, 0, 0.04);padding:12px;">
100 <div>
101 <p style="font-size:14px;margin-top:0;">
102 ' . __( 'The TablePress premium versions come with a table default style customizer!', 'tablepress' ) . '
103 ' . __( 'Choose from multiple style variations or define your own color scheme in an easy-to-use visual tool!', 'tablepress' ) . '
104 <strong>' . __( 'Change your tables’ default style without touching CSS code!', 'tablepress' ) . '</strong>
105 </p>
106 <div class="buttons" style="text-align:center;">
107 <a href="' . $url . '" class="tablepress-button">
108 <span>' . $button_label . '</span>
109 <span class="dashicons dashicons-arrow-right-alt"></span>
110 </a>
111 </div>
112 </div>
113 <a href="' . $url . '"><img src="' . esc_url( plugins_url( 'admin/img/default-style-customizer.png', TABLEPRESS__FILE__ ) ) . '" width="305" height="172" alt="' . esc_attr__( 'Screenshot of the Default Style Customizer that is part of the TablePress premium versions.', 'tablepress' ) . '" /></a>
114 </div>';
115 }
116
117 $message .= '<p style="margin-top:14px;">' . $this->ajax_link( array( 'action' => 'hide_message', 'item' => 'plugin_update', 'return' => 'list' ), __( 'Hide this message', 'tablepress' ) ) . '</p>';
118
119 $title = '<em>' . sprintf( __( 'Thank you for updating to TablePress %s!', 'tablepress' ), TablePress::version ) . '</em>';
120
121 $this->add_header_message( $message, 'notice-info not-dismissible', $title );
122 }
123
124 $this->process_action_messages( array(
125 'success_delete' => _n( 'The table was deleted successfully.', 'The tables were deleted successfully.', 1, 'tablepress' ),
126 'success_delete_plural' => _n( 'The table was deleted successfully.', 'The tables were deleted successfully.', 2, 'tablepress' ),
127 'error_delete' => __( 'Error: The table could not be deleted.', 'tablepress' ),
128 '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'] ) ) : '' ),
129 'success_copy_plural' => _n( 'The table was copied successfully.', 'The tables were copied successfully.', 2, 'tablepress' ),
130 'error_copy' => __( 'Error: The table could not be copied.', 'tablepress' ),
131 'error_no_table' => __( 'Error: You did not specify a valid table ID.', 'tablepress' ),
132 'error_load_table' => __( 'Error: This table could not be loaded!', 'tablepress' ),
133 'error_bulk_action_invalid' => __( 'Error: This bulk action is invalid!', 'tablepress' ),
134 'error_no_selection' => __( 'Error: You did not select any tables!', 'tablepress' ),
135 'error_delete_not_all_tables' => __( 'Notice: Not all selected tables could be deleted!', 'tablepress' ),
136 'error_copy_not_all_tables' => __( 'Notice: Not all selected tables could be copied!', 'tablepress' ),
137 'success_import' => __( 'The tables were imported successfully.', 'tablepress' ),
138 ) );
139
140 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
141 $this->add_text_box( 'tables-list', array( $this, 'textbox_tables_list' ), 'normal' );
142
143 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.
144 $this->wp_list_table = TablePress::load_class( 'TablePress_All_Tables_List_Table', 'class-all-tables-list-table.php', 'views' );
145 $this->wp_list_table->set_items( $this->data['table_ids'] );
146 $this->wp_list_table->prepare_items();
147
148 // Cleanup Request URI string, which WP_List_Table uses to generate the sort URLs.
149 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message', 'table_id' ), $_SERVER['REQUEST_URI'] );
150 }
151
152 /**
153 * Render the current view (in this view: without form tag).
154 *
155 * @since 1.0.0
156 */
157 public function render(): void {
158 ?>
159 <div id="tablepress-page" class="wrap">
160 <?php
161 $this->print_nav_tab_menu();
162 ?>
163 <div id="tablepress-body">
164 <hr class="wp-header-end" />
165 <?php
166 // Print all header messages.
167 foreach ( $this->header_messages as $message ) {
168 echo $message;
169 }
170
171 // For this screen, this is done in textbox_tables_list(), to get the fields into the correct <form>:
172 // $this->do_text_boxes( 'header' );.
173 ?>
174 <div id="poststuff">
175 <div id="post-body" class="metabox-holder columns-<?php echo ( isset( $GLOBALS['screen_layout_columns'] ) && ( 2 === $GLOBALS['screen_layout_columns'] ) ) ? '2' : '1'; ?>">
176 <div id="postbox-container-2" class="postbox-container">
177 <?php
178 $this->do_text_boxes( 'normal' );
179 $this->do_meta_boxes( 'normal' );
180
181 $this->do_text_boxes( 'additional' );
182 $this->do_meta_boxes( 'additional' );
183
184 // Print all submit buttons.
185 $this->do_text_boxes( 'submit' );
186 ?>
187 </div>
188 <div id="postbox-container-1" class="postbox-container">
189 <?php
190 // Print all boxes in the sidebar.
191 $this->do_text_boxes( 'side' );
192 $this->do_meta_boxes( 'side' );
193 ?>
194 </div>
195 </div>
196 <br class="clear" />
197 </div>
198 </div>
199 </div>
200 <?php
201 }
202
203 /**
204 * Print the screen head text.
205 *
206 * @since 1.0.0
207 *
208 * @param array<string, mixed> $data Data for this screen.
209 * @param array<string, mixed> $box Information about the text box.
210 */
211 public function textbox_head( array $data, array $box ): void {
212 echo '<p>';
213 _e( 'This is a list of your tables.', 'tablepress' );
214 echo ' ';
215 // Show the instructions string depending on whether the Block Editor is used on the site or not.
216 if ( $data['site_uses_block_editor'] ) {
217 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' ) );
218 } else {
219 _e( 'To insert a table into a post or page, paste its Shortcode at the desired place in the editor.', 'tablepress' );
220 echo ' ';
221 _e( 'Each table has a unique ID that needs to be adjusted in that Shortcode.', 'tablepress' );
222 }
223 echo '</p>';
224 }
225
226 /**
227 * Print the content of the "All Tables" text box.
228 *
229 * @since 1.0.0
230 *
231 * @param array<string, mixed> $data Data for this screen.
232 * @param array<string, mixed> $box Information about the text box.
233 */
234 public function textbox_tables_list( array $data, array $box ): void {
235 if ( ! empty( $_GET['s'] ) ) {
236 printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;', 'tablepress' ) . '</span>', esc_html( wp_unslash( $_GET['s'] ) ) );
237 }
238 ?>
239 <form method="get" action="">
240 <?php
241 if ( isset( $_GET['page'] ) ) {
242 echo '<input type="hidden" name="page" value="' . esc_attr( $_GET['page'] ) . '" />' . "\n";
243 }
244 $this->wp_list_table->search_box( __( 'Search Tables', 'tablepress' ), 'tables_search' );
245 ?>
246 </form>
247 <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post">
248 <?php
249 // This prints the nonce and action fields for this screen (done here instead of render(), due to moved <form>).
250 $this->do_text_boxes( 'header' );
251 $this->wp_list_table->display();
252 ?>
253 </form>
254 <?php
255 }
256
257 /**
258 * Create HTML code for an AJAXified link.
259 *
260 * @since 1.0.0
261 *
262 * @param array<string, mixed> $params Parameters for the URL.
263 * @param string $text Text for the link.
264 * @return string HTML code for the link.
265 */
266 protected function ajax_link( array $params, string $text ): string {
267 $class = 'ajax-link';
268 if ( ! empty( $params['class'] ) ) {
269 $class .= ' ' . esc_attr( $params['class'] );
270 }
271 $url = TablePress::url( $params, true, 'admin-post.php' );
272 $action = esc_attr( $params['action'] );
273 $item = esc_attr( $params['item'] );
274 $target = esc_attr( $params['target'] ?? '' );
275 return "<a class=\"{$class}\" href=\"{$url}\" data-action=\"{$action}\" data-item=\"{$item}\" data-target=\"{$target}\">{$text}</a>";
276 }
277
278 } // class TablePress_List_View
279