PluginProbe
TablePress – Tables in WordPress made easy / 1.9.2
TablePress – Tables in WordPress made easy v1.9.2
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-import.php

view-import.php in TablePress – Tables in WordPress made easy 1.9.2, at views/view-import.php

311 lines 16.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Import Table 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 * Import Table View class
16 * @package TablePress
17 * @subpackage Views
18 * @author Tobias Bäthge
19 * @since 1.0.0
20 */
21 class TablePress_Import_View extends TablePress_View {
22
23 /**
24 * List of WP feature pointers for this view.
25 *
26 * @since 1.0.0
27 * @var array
28 */
29 protected $wp_pointers = array( 'tp100_wp_table_reloaded_import' );
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 $data Data for this view.
38 */
39 public function setup( $action, array $data ) {
40 parent::setup( $action, $data );
41
42 $this->admin_page->enqueue_script( 'import', array( 'jquery-core' ), array(
43 'import' => array(
44 'error_wp_table_reloaded_nothing_selected' => __( 'Error: You did not select what to import from WP-Table Reloaded!', 'tablepress' ),
45 ),
46 ) );
47
48 $this->process_action_messages( array(
49 'error_import' => __( 'Error: The import failed.', 'tablepress' ),
50 'error_no_zip_import' => __( 'Error: Import of ZIP files is not available on this server.', 'tablepress' ),
51 'error_import_zip_open' => __( 'Error: The ZIP file could not be opened.', 'tablepress' ),
52 'error_import_zip_content' => __( 'Error: The data in the ZIP file is invalid.', 'tablepress' ),
53 'error_import_no_existing_id' => __( 'Error: You selected to replace or append to an existing table, but did not select a table.', 'tablepress' ),
54 'error_import_source_invalid' => __( 'Error: The source for the import is invalid or could not be accessed.', 'tablepress' ),
55 'error_import_data' => __( 'Error: The data for the import is invalid.', 'tablepress' ),
56 'error_wp_table_reloaded_nothing_selected' => __( 'Error: You did not select what to import from WP-Table Reloaded!', 'tablepress' ),
57 'error_wp_table_reloaded_not_installed' => __( 'Error: Existing WP-Table Reloaded tables were not found in the database.', 'tablepress' ),
58 'error_import_wp_table_reloaded' => __( 'Error: The tables from WP-Table Reloaded could not be imported.', 'tablepress' ),
59 'error_wp_table_reloaded_dump_file' => __( 'Error: The WP-Table Reloaded Dump File could not be imported!', 'tablepress' ),
60 ) );
61
62 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
63 $this->add_meta_box( 'import-form', __( 'Import Tables', 'tablepress' ), array( $this, 'postbox_import_form' ), 'normal' );
64 if ( current_user_can( 'tablepress_import_tables_wptr' ) ) {
65 $this->add_meta_box( 'import-wp-table-reloaded', __( 'Import from WP-Table Reloaded', 'tablepress' ), array( $this, 'postbox_wp_table_reloaded_import' ), 'additional' );
66 }
67
68 add_filter( 'default_hidden_meta_boxes', array( $this, 'hide_import_wptr_postbox' ), 10, 2 );
69 }
70
71 /**
72 * Hide the "Import from WP-Table Reloaded postbox" by default, if WP-Table Reloaded is not installed. It can still be opened manually from the "Screen Options".
73 *
74 * @since 1.0.0
75 */
76 public function hide_import_wptr_postbox( $hidden, $screen ) {
77 if ( 'tablepress_import' !== $screen->id ) {
78 return $hidden;
79 }
80 if ( ! $this->data['wp_table_reloaded_installed'] ) {
81 $hidden[] = 'tablepress_import-import-wp-table-reloaded';
82 }
83 return $hidden;
84 }
85
86 /**
87 * Print the screen head text.
88 *
89 * @since 1.0.0
90 *
91 * @param array $data Data for this screen.
92 * @param array $box Information about the text box.
93 */
94 public function textbox_head( array $data, array $box ) {
95 ?>
96 <p>
97 <?php _e( 'TablePress can import tables from existing data, like from a CSV, XLS, or XLSX file from a spreadsheet application (e.g. Excel), an HTML file resembling a webpage, or its own JSON format.', 'tablepress' ); ?>
98 <?php _e( 'You can also import existing tables from the WP-Table Reloaded plugin below.', 'tablepress' ); ?>
99 </p>
100 <p>
101 <?php
102 _e( 'To import a table, select and enter the import source in the following form.', 'tablepress' );
103 if ( 0 < $data['tables_count'] ) {
104 echo ' ';
105 _e( 'You can also choose to import it as a new table, to replace an existing table, or to append the rows to an existing table.', 'tablepress' );
106 }
107
108 ?>
109 </p>
110 <?php
111 }
112
113 /**
114 * Print the content of the "Import Tables" post meta box.
115 *
116 * @since 1.0.0
117 *
118 * @param array $data Data for this screen.
119 * @param array $box Information about the meta box.
120 */
121 public function postbox_import_form( array $data, array $box ) {
122 ?>
123 <table class="tablepress-postbox-table fixed">
124 <tbody>
125 <tr id="row-import-source">
126 <th class="column-1" scope="row" id="import-source-header"><?php _e( 'Import Source', 'tablepress' ); ?>:</th>
127 <td class="column-2">
128 <label for="tables-import-source-file-upload"><input name="import[source]" id="tables-import-source-file-upload" type="radio" aria-labelledby="import-source-header" value="file-upload"<?php checked( $data['import_source'], 'file-upload', true ); ?> /> <?php _e( 'File Upload', 'tablepress' ); ?></label>
129 <label for="tables-import-source-url"><input name="import[source]" id="tables-import-source-url" type="radio" aria-labelledby="import-source-header" value="url"<?php checked( $data['import_source'], 'url', true ); ?> /> <?php _e( 'URL', 'tablepress' ); ?></label>
130 <?php if ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) { ?>
131 <label for="tables-import-source-server"><input name="import[source]" id="tables-import-source-server" type="radio" aria-labelledby="import-source-header" value="server"<?php checked( $data['import_source'], 'server', true ); ?> /> <?php _e( 'File on server', 'tablepress' ); ?></label>
132 <?php } ?>
133 <label for="tables-import-source-form-field"><input name="import[source]" id="tables-import-source-form-field" type="radio" aria-labelledby="import-source-header" value="form-field"<?php checked( $data['import_source'], 'form-field', true ); ?> /> <?php _e( 'Manual Input', 'tablepress' ); ?></label>
134 </td>
135 </tr>
136 <tr id="row-import-source-file-upload" class="bottom-border">
137 <th class="column-1 top-align" scope="row"><label for="tables-import-file-upload"><?php _e( 'Select file', 'tablepress' ); ?>:</label></th>
138 <td class="column-2">
139 <input name="import_file_upload" id="tables-import-file-upload" type="file" class="large-text" style="box-sizing: border-box;" />
140 <?php
141 if ( $data['zip_support_available'] ) {
142 echo '<br /><span class="description">' . __( 'You can import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
143 }
144 ?>
145 </td>
146 </tr>
147 <tr id="row-import-source-url" class="bottom-border">
148 <th class="column-1 top-align" scope="row"><label for="tables-import-url"><?php _e( 'File URL', 'tablepress' ); ?>:</label></th>
149 <td class="column-2">
150 <input type="text" name="import[url]" id="tables-import-url" class="large-text" value="<?php echo esc_attr( $data['import_url'] ); ?>" />
151 <?php
152 if ( $data['zip_support_available'] ) {
153 echo '<br /><span class="description">' . __( 'You can import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
154 }
155 ?>
156 </td>
157 </tr>
158 <?php if ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) { ?>
159 <tr id="row-import-source-server" class="bottom-border">
160 <th class="column-1 top-align" scope="row"><label for="tables-import-server"><?php _e( 'Server Path to file', 'tablepress' ); ?>:</label></th>
161 <td class="column-2">
162 <input type="text" name="import[server]" id="tables-import-server" class="large-text" value="<?php echo esc_attr( $data['import_server'] ); ?>" />
163 <?php
164 if ( $data['zip_support_available'] ) {
165 echo '<br /><span class="description">' . __( 'You can import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
166 }
167 ?>
168 </td>
169 </tr>
170 <?php } ?>
171 <tr id="row-import-source-form-field" class="bottom-border">
172 <th class="column-1 top-align" scope="row"><label for="tables-import-form-field"><?php _e( 'Import data', 'tablepress' ); ?>:</label></th>
173 <td class="column-2">
174 <textarea name="import[form_field]" id="tables-import-form-field" rows="15" cols="40" class="large-text"><?php echo esc_textarea( $data['import_form_field'] ); ?></textarea>
175 </td>
176 </tr>
177 <tr class="top-border bottom-border">
178 <th class="column-1" scope="row"><label for="tables-import-format"><?php _e( 'Import Format', 'tablepress' ); ?>:</label></th>
179 <td class="column-2">
180 <select id="tables-import-format" name="import[format]">
181 <?php
182 foreach ( $data['import_formats'] as $format => $name ) {
183 $selected = selected( $format, $data['import_format'], false );
184 echo "<option{$selected} value=\"{$format}\">{$name}</option>";
185 }
186 ?>
187 </select>
188 <?php
189 if ( ! $data['html_import_support_available'] ) {
190 echo '<br /><span class="description">' . __( 'Import of HTML files is not available on your server.', 'tablepress' ) . '</span>';
191 }
192 ?>
193 </td>
194 </tr>
195 <tr id="row-import-type" class="top-border">
196 <th class="column-1" scope="row" id="import-type-header"><?php _e( 'Add, Replace, or Append?', 'tablepress' ); ?>:</th>
197 <td class="column-2">
198 <label for="tables-import-type-add"><input name="import[type]" id="tables-import-type-add" type="radio" aria-labelledby="import-type-header" value="add"<?php checked( $data['import_type'], 'add', true ); ?> /> <?php _e( 'Add as new table', 'tablepress' ); ?></label>
199 <label for="tables-import-type-replace"><input name="import[type]" id="tables-import-type-replace" type="radio" aria-labelledby="import-type-header" value="replace"<?php checked( $data['import_type'], 'replace', true ); ?><?php disabled( $data['tables_count'] > 0, false, true ); ?> /> <?php _e( 'Replace existing table', 'tablepress' ); ?></label>
200 <label for="tables-import-type-append"><input name="import[type]" id="tables-import-type-append" type="radio" aria-labelledby="import-type-header" value="append"<?php checked( $data['import_type'], 'append', true ); ?><?php disabled( $data['tables_count'] > 0, false, true ); ?> /> <?php _e( 'Append rows to existing table', 'tablepress' ); ?></label>
201 </td>
202 </tr>
203 <tr id="row-import-existing-table" class="bottom-border">
204 <th class="column-1" scope="row"><label for="tables-import-existing-table"><?php _e( 'Table to replace or append to', 'tablepress' ); ?>:</label></th>
205 <td class="column-2">
206 <select id="tables-import-existing-table" name="import[existing_table]"<?php disabled( $data['tables_count'] > 0, false, true ); ?>>
207 <option value=""><?php _e( '&mdash; Select &mdash;', 'tablepress' ); ?></option>
208 <?php
209 foreach ( $data['table_ids'] as $table_id ) {
210 $table = TablePress::$model_table->load( $table_id, false, false ); // Load table, without table data, options, and visibility settings
211 if ( ! current_user_can( 'tablepress_edit_table', $table['id'] ) ) {
212 continue;
213 }
214 if ( '' === trim( $table['name'] ) ) {
215 $table['name'] = __( '(no name)', 'tablepress' );
216 }
217 $text = esc_html( sprintf( __( 'ID %1$s: %2$s', 'tablepress' ), $table['id'], $table['name'] ) );
218 $selected = selected( $table['id'], $data['import_existing_table'], false );
219 echo "<option{$selected} value=\"{$table['id']}\">{$text}</option>";
220 }
221 ?>
222 </select>
223 </td>
224 </tr>
225 <tr class="top-border">
226 <td class="column-1"></td>
227 <td class="column-2"><input type="submit" value="<?php echo esc_attr_x( 'Import', 'button', 'tablepress' ); ?>" class="button button-primary button-large" name="submit" /></td>
228 </tr>
229 </tbody>
230 </table>
231 <?php
232 }
233
234 /**
235 * Print the content of the "Import from WP-Table Reloaded" post meta box.
236 *
237 * @since 1.0.0
238 *
239 * @param array $data Data for this screen.
240 * @param array $box Information about the meta box.
241 */
242 public function postbox_wp_table_reloaded_import( array $data, array $box ) {
243 ?>
244 <p>
245 <?php _e( 'To import all tables from a WP-Table Reloaded installation, choose the relevant import source below.', 'tablepress' ); ?>
246 <br />
247 <?php _e( 'If WP-Table Reloaded is installed on this site, the &#8220;WordPress database&#8221; option is recommended.', 'tablepress' ); ?>
248 <?php _e( 'If you want to import tables from another site, create a &#8220;WP-Table Reloaded Dump File&#8221; there and upload it below, after choosing &#8220;WP-Table Reloaded Dump File&#8221;.', 'tablepress' ); ?>
249 <br />
250 <?php printf( __( 'Before doing this, it is highly recommended to read the <a href="%s">migration guide</a> on the TablePress website.', 'tablepress' ), 'https://tablepress.org/migration-from-wp-table-reloaded/' ); ?>
251 </p>
252 <table class="tablepress-postbox-table fixed">
253 <tbody>
254 <tr id="row-import-wp-table-reloaded-source">
255 <th class="column-1" scope="row"><?php _e( 'Import Source', 'tablepress' ); ?>:</th>
256 <td class="column-2">
257 <label for="import-wp-table-reloaded-source-db"><input name="import[wp_table_reloaded][source]" id="import-wp-table-reloaded-source-db" type="radio" value="db" <?php
258 checked( $data['import_wp_table_reloaded_source'], 'db', true );
259 disabled( $data['wp_table_reloaded_installed'], false, true );
260 ?> /> <?php _e( 'WordPress database', 'tablepress' ); ?></label>
261 <label for="import-wp-table-reloaded-source-dump-file"><input name="import[wp_table_reloaded][source]" id="import-wp-table-reloaded-source-dump-file" type="radio" value="dump-file"<?php checked( $data['import_wp_table_reloaded_source'], 'dump-file', true ); ?> /> <?php _e( 'WP-Table Reloaded Dump File', 'tablepress' ); ?></label>
262 </td>
263 </tr>
264 <tr id="row-import-wp-table-reloaded-source-dump-file" class="bottom-border">
265 <th class="column-1 top-align" scope="row"><label for="tables-import-wp-table-reloaded-dump-file"><?php _e( 'Select file', 'tablepress' ); ?>:</label></th>
266 <td class="column-2">
267 <input name="import_wp_table_reloaded_file_upload" id="tables-import-wp-table-reloaded-dump-file" type="file" class="large-text" style="box-sizing: border-box;" />
268 </td>
269 </tr>
270 <tr id="row-import-wp-table-reloaded-source-db" class="bottom-border">
271 <td class="column-1 top-align" scope="row" style="padding:2px;"></td>
272 <td class="column-2" style="padding:2px;"></td>
273 </tr>
274 <tr class="top-border">
275 <th class="column-1" scope="row"><?php _e( 'Import tables', 'tablepress' ); ?>:</th>
276 <td class="column-2"><label for="import-wp-table-reloaded-tables"> <input type="checkbox" id="import-wp-table-reloaded-tables" name="import[wp_table_reloaded][tables]" value="true" checked="checked" /> <?php _e( 'Import all tables and their settings from WP-Table Reloaded.', 'tablepress' ); ?> <span class="description"><?php _e( '(recommended)', 'tablepress' ); ?></span></label></td>
277 </tr>
278 <tr class="bottom-border">
279 <th class="column-1" scope="row"><?php _e( 'Import styling', 'tablepress' ); ?>:</th>
280 <td class="column-2"><label for="import-wp-table-reloaded-css"> <input type="checkbox" id="import-wp-table-reloaded-css" name="import[wp_table_reloaded][css]" value="true" checked="checked" /> <?php _e( 'Try to automatically convert the &#8220;Custom CSS&#8221; code from the &#8220;Plugin Options&#8221; screen of WP-Table Reloaded.', 'tablepress' ); ?></label></td>
281 </tr>
282 <tr class="top-border">
283 <td class="column-1" scope="row"></td>
284 <td class="column-2"><input type="submit" value="<?php echo esc_attr_x( 'Import from WP-Table Reloaded', 'button', 'tablepress' ); ?>" class="button button-large" id="submit_wp_table_reloaded_import" name="submit_wp_table_reloaded_import" /></td>
285 </tr>
286 </tbody>
287 </table>
288 <?php
289 }
290
291 /**
292 * Set the content for the WP feature pointer about the WP-Table Reloaded import feature.
293 *
294 * @since 1.0.0
295 */
296 public function wp_pointer_tp100_wp_table_reloaded_import() {
297 if ( ! $this->data['wp_table_reloaded_installed'] ) {
298 return;
299 }
300
301 $content = '<h3>' . __( 'TablePress Feature: Import from WP-Table Reloaded', 'tablepress' ) . '</h3>';
302 $content .= '<p>' . __( 'You can import your existing tables and &#8220;Custom CSS&#8221; from WP-Table Reloaded into TablePress.', 'tablepress' ) . '</p>';
303
304 $this->admin_page->print_wp_pointer_js( 'tp100_wp_table_reloaded_import', '#tablepress_import-import-wp-table-reloaded', array(
305 'content' => $content,
306 'position' => array( 'edge' => 'bottom', 'align' => 'left', 'offset' => '16 -16' ),
307 ) );
308 }
309
310 } // class TablePress_Import_View
311