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

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