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

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