PluginProbe
TablePress – Tables in WordPress made easy / 2.1.8
TablePress – Tables in WordPress made easy v2.1.8
3.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 All 45 releases
tablepress / views / view-list.php

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

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