PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
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
← All changes | views/view-import.php +88 -114 2.1.8 → 3.4 View file →
@@ -7,8 +7,10 @@
7 7 * @author Tobias Bäthge
8 8 * @since 1.0.0
9 9 */
10 10
11 +declare(strict_types=1);
12 +
11 13 // Prohibit direct script loading.
12 14 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13 15
14 16 /**
@@ -24,11 +26,11 @@
24 26 /**
25 27 * List of WP feature pointers for this view.
26 28 *
27 29 * @since 2.0.0
28 - * @var array
30 + * @var string[]
29 31 */
30 - protected $wp_pointers = array( 'tp20_import_drag_drop_detect_format' );
32 + protected array $wp_pointers = array( 'tp20_import_drag_drop_detect_format' );
31 33
32 34 /**
33 35 * Set up the view with data and do things that are specific for this view.
34 36 *
@@ -33,19 +35,24 @@
33 35 * Set up the view with data and do things that are specific for this view.
34 36 *
35 37 * @since 1.0.0
36 38 *
37 - * @param string $action Action for this view.
38 - * @param array $data Data for this view.
39 + * @param string $action Action for this view.
40 + * @param array<string, mixed> $data Data for this view.
39 41 */
40 - public function setup( $action, array $data ) {
42 + #[\Override]
43 + public function setup( /* string */ $action, array $data ) /* : void */ {
44 + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
45 +
41 46 parent::setup( $action, $data );
42 47
43 - $this->admin_page->enqueue_style( 'jsuites' );
44 - $this->admin_page->enqueue_style( 'import', array( 'tablepress-jsuites' ) );
45 - $this->admin_page->enqueue_script( 'jsuites' );
46 - $this->admin_page->enqueue_script( 'import', array( 'tablepress-jsuites' ) );
48 + TablePress::enqueue_script( 'common', array( 'jquery-core', 'postbox' ) );
47 49
50 + $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' );
51 +
52 + TablePress::enqueue_style( 'import' );
53 + TablePress::enqueue_script( 'import' );
54 +
48 55 $this->process_action_messages( array(
49 56 'error_import' => __( 'Error: The import failed.', 'tablepress' ),
50 57 ) );
51 58
@@ -50,8 +57,13 @@
50 57 ) );
51 58
52 59 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
53 60 $this->add_meta_box( 'import-form', __( 'Import Tables', 'tablepress' ), array( $this, 'postbox_import_form' ), 'normal' );
61 + $screen = get_current_screen();
62 + add_filter( "postbox_classes_{$screen->id}_tablepress_{$this->action}-import-form", array( $this, 'postbox_classes' ) ); // @phpstan-ignore property.nonObject
63 + if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW ) {
64 + $this->add_meta_box( 'tables-auto-import', __( 'Automatic Periodic Table Import', 'tablepress' ), array( $this, 'postbox_auto_import' ), 'additional' );
65 + }
54 66 }
55 67
56 68 /**
57 69 * Print the screen head text.
@@ -57,15 +69,15 @@
57 69 * Print the screen head text.
58 70 *
59 71 * @since 1.0.0
60 72 *
61 - * @param array $data Data for this screen.
62 - * @param array $box Information about the text box.
73 + * @param array<string, mixed> $data Data for this screen.
74 + * @param array<string, mixed> $box Information about the text box.
63 75 */
64 - public function textbox_head( array $data, array $box ) {
76 + public function textbox_head( array $data, array $box ): void {
65 77 ?>
66 78 <p>
67 - <?php _e( 'TablePress can import tables from common spreadsheet applications, like XLSX files fom Excel, or CSV, ODS, HTML, and JSON files.', 'tablepress' ); ?>
79 + <?php _e( 'TablePress can import tables from common spreadsheet applications, like XLSX files from Excel, or CSV, ODS, HTML, and JSON files.', 'tablepress' ); ?>
68 80 </p>
69 81 <p>
70 82 <?php _e( 'To import tables, select and enter the import source in the following form.', 'tablepress' ); ?>
71 83 <?php _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' ); ?>
@@ -73,111 +85,73 @@
73 85 <?php
74 86 }
75 87
76 88 /**
77 - * Print the content of the "Import Tables" post meta box.
89 + * Prints the content of the "Import Tables" post meta box.
78 90 *
79 91 * @since 1.0.0
80 92 *
81 - * @param array $data Data for this screen.
82 - * @param array $box Information about the meta box.
93 + * @param array<string, mixed> $data Data for this screen.
94 + * @param array<string, mixed> $box Information about the meta box.
83 95 */
84 - public function postbox_import_form( array $data, array $box ) {
85 - ?>
86 -<table class="tablepress-postbox-table fixed">
87 - <tr id="row-import-source">
88 - <th class="column-1" scope="row" id="import-source-header"><?php _e( 'Import Source', 'tablepress' ); ?>:</th>
89 - <td class="column-2">
90 - <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>
91 - <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>
92 - <?php if ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) { ?>
93 - <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>
94 - <?php } ?>
95 - <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>
96 - </td>
97 - </tr>
98 - <tr id="row-import-source-file-upload" class="top-border bottom-border">
99 - <th class="column-1 top-align" scope="row"><label for="tables-import-file-upload"><?php _e( 'Select files', 'tablepress' ); ?>:</label></th>
100 - <td class="column-2">
101 - <div class="file-upload-area">
102 - <input name="import_file_upload[]" id="tables-import-file-upload" type="file" multiple />
103 - <div id="tables-import-file-upload-dropzone" class="dropzone hide-if-no-js">
104 - <span><?php _e( 'Click to select files, or drag them here.', 'tablepress' ); ?></span>
105 - </div>
106 - </div>
107 - <?php
108 - if ( $data['zip_support_available'] ) {
109 - echo '<span class="description">' . __( 'You can also import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
110 - }
96 + public function postbox_import_form( array $data, array $box ): void {
97 + $this->print_script_data_json(
98 + 'import',
99 + array(
100 + 'tables' => $data['tables'],
101 + 'importSource' => $data['import_source'],
102 + 'importType' => $data['import_type'],
103 + 'importUrl' => $data['import_url'],
104 + 'importServer' => $data['import_server'],
105 + 'importFormField' => $data['import_form-field'],
106 + 'importExistingTable' => $data['import_existing_table'],
107 + 'showImportSourceServer' => ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ),
108 + 'showImportSourceUrl' => current_user_can( 'tablepress_import_tables_url' ),
109 + 'legacyImport' => $data['legacy_import'],
110 + ),
111 + );
112 +
113 + echo '<div id="tablepress-import-screen"></div>';
114 + }
115 +
116 + /**
117 + * Adds the "no-validation-highlighting" class to the "Import Tables" post meta box.
118 + *
119 + * @since 2.2.0
120 + *
121 + * @param string[] $classes The array of postbox classes.
122 + * @return string[] The modified array of postbox classes.
123 + */
124 + public function postbox_classes( array $classes ): array {
125 + $classes[] = 'no-validation-highlighting';
126 + return $classes;
127 + }
128 +
129 + /**
130 + * Prints the content of the "Automatic Periodic Table Import Screen" post meta box.
131 + *
132 + * @since 2.2.0
133 + *
134 + * @param array<string, mixed> $data Data for this screen.
135 + * @param array<string, mixed> $box Information about the meta box.
136 + *
137 + * @phpstan-ignore missingType.return (The method is extended elsewhere and can't have type hints.)
138 + */
139 + public function postbox_auto_import( /* array */ $data, /* array */ $box ) /* : void */ {
140 + // Don't use type hints in the method declaration, as the method is extended in the TablePress Table Auto Update Extension which is no longer updated.
141 +
142 + if ( tb_tp_fs()->is_free_plan() ) :
111 143 ?>
112 - </td>
113 - </tr>
114 - <tr id="row-import-source-url" class="top-border bottom-border">
115 - <th class="column-1 top-align" scope="row"><label for="tables-import-url"><?php _e( 'File URL', 'tablepress' ); ?>:</label></th>
116 - <td class="column-2">
117 - <input type="text" name="import[url]" id="tables-import-url" class="large-text code" value="<?php echo esc_url( $data['import_url'] ); ?>" />
144 + <p style="font-size:14px;">
145 + <span class="dashicons dashicons-info-outline"></span>
146 + <strong><?php _e( 'Pro Tip:', 'tablepress' ); ?></strong>
147 + <?php
148 + /* translators: %1$s: URL to TablePress website, %2$s: Module name */
149 + printf( __( 'You can automate the import of tables from URLs or server files with the <a href="%1$s">“%2$s” premium feature</a>!', 'tablepress' ), 'https://tablepress.org/modules/automatic-periodic-table-import/?utm_source=plugin&utm_medium=textlink&utm_content=import-screen', __( 'Automatic Periodic Table Import', 'tablepress' ) );
150 + ?>
151 + </p>
118 152 <?php
119 - if ( $data['zip_support_available'] ) {
120 - echo '<br /><span class="description">' . __( 'You can also import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
121 - }
122 - ?>
123 - </td>
124 - </tr>
125 - <?php if ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) { ?>
126 - <tr id="row-import-source-server" class="top-border bottom-border">
127 - <th class="column-1 top-align" scope="row"><label for="tables-import-server"><?php _e( 'Server Path to file', 'tablepress' ); ?>:</label></th>
128 - <td class="column-2">
129 - <input type="text" name="import[server]" id="tables-import-server" class="large-text code" value="<?php echo esc_attr( $data['import_server'] ); ?>" />
130 - <?php
131 - if ( $data['zip_support_available'] ) {
132 - echo '<br /><span class="description">' . __( 'You can also import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
133 - }
134 - ?>
135 - </td>
136 - </tr>
137 - <?php } ?>
138 - <tr id="row-import-source-form-field" class="top-border bottom-border">
139 - <th class="column-1 top-align" scope="row"><label for="tables-import-form-field"><?php _e( 'Import data', 'tablepress' ); ?>:</label></th>
140 - <td class="column-2">
141 - <textarea name="import[form-field]" id="tables-import-form-field" rows="15" cols="40" class="large-text code"><?php echo esc_textarea( $data['import_form-field'] ); ?></textarea>
142 - </td>
143 - </tr>
144 - <tr id="row-import-type" class="top-border">
145 - <th class="column-1" scope="row" id="import-type-header"><?php _e( 'Add, Replace, or Append?', 'tablepress' ); ?>:</th>
146 - <td class="column-2">
147 - <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>
148 - <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>
149 - <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>
150 - </td>
151 - </tr>
152 - <tr id="row-import-existing-table" class="top-border bottom-border">
153 - <th class="column-1" scope="row"><label for="tables-import-existing-table"><?php _e( 'Table to replace or append to', 'tablepress' ); ?>:</label></th>
154 - <td class="column-2">
155 - <select id="tables-import-existing-table" name="import[existing_table]"<?php disabled( $data['tables_count'] > 0, false, true ); ?>>
156 - <option value=""><?php _e( '— Select or type —', 'tablepress' ); ?></option>
157 - <?php
158 - foreach ( $data['table_ids'] as $table_id ) {
159 - $table = TablePress::$model_table->load( $table_id, false, false ); // Load table, without table data, options, and visibility settings.
160 - if ( ! current_user_can( 'tablepress_edit_table', $table['id'] ) ) {
161 - continue;
162 - }
163 - if ( '' === trim( $table['name'] ) ) {
164 - $table['name'] = __( '(no name)', 'tablepress' );
165 - }
166 - $text = esc_html( sprintf( __( 'ID %1$s: %2$s', 'tablepress' ), $table['id'], $table['name'] ) );
167 - $selected = selected( $table['id'], $data['import_existing_table'], false );
168 - echo "<option{$selected} value=\"{$table['id']}\">{$text}</option>";
169 - }
170 - ?>
171 - </select>
172 - </td>
173 - </tr>
174 - <tr class="top-border">
175 - <td class="column-1"></td>
176 - <td class="column-2"><input type="hidden" name="import[legacy_import]" value="<?php echo ( 'true' === $data['legacy_import'] ) ? 'true' : 'false'; ?>" /><input type="submit" value="<?php echo esc_attr_x( 'Import', 'button', 'tablepress' ); ?>" class="button button-primary button-large" id="import-submit-button" /></td>
177 - </tr>
178 -</table>
179 - <?php
153 + endif;
180 154 }
181 155
182 156 /**
183 157 * Sets the content for the WP feature pointer about the drag and drop import and format detection on the "Import" screen.
@@ -183,19 +157,19 @@
183 157 * Sets the content for the WP feature pointer about the drag and drop import and format detection on the "Import" screen.
184 158 *
185 159 * @since 2.0.0
186 160 */
187 - public function wp_pointer_tp20_import_drag_drop_detect_format() {
161 + public function wp_pointer_tp20_import_drag_drop_detect_format(): void {
188 162 $content = '<h3>' . __( 'TablePress feature: Drag and Drop Import with Format Detection', 'tablepress' ) . '</h3>';
189 - $content .= '<p>' . __( 'Did you know?', 'tablepress' ) . ' ' . __( 'The import of tables is now even more powerful! You can simply drag and drop your files into this area and TablePress will automatically detect the file format!', 'tablepress' ) . '</p>';
163 + $content .= '<p>' . __( 'Did you know?', 'tablepress' ) . ' ' . __( 'To import tables, you can simply drag and drop your spreadsheet files into this area and TablePress will automatically detect the file format!', 'tablepress' ) . '</p>';
190 164
191 - $this->admin_page->print_wp_pointer_js(
165 + $this->print_wp_pointer_js(
192 166 'tp20_import_drag_drop_detect_format',
193 167 '#tables-import-file-upload-dropzone span',
194 168 array(
195 169 'content' => $content,
196 170 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
197 - )
171 + ),
198 172 );
199 173 }
200 174
201 175 } // class TablePress_Import_View