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 +33 -31 2.2.4 → 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 /**
@@ -26,9 +28,9 @@
26 28 *
27 29 * @since 2.0.0
28 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 *
@@ -42,14 +44,14 @@
42 44 // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
43 45
44 46 parent::setup( $action, $data );
45 47
48 + TablePress::enqueue_script( 'common', array( 'jquery-core', 'postbox' ) );
49 +
46 50 $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' );
47 51
48 - $this->admin_page->enqueue_style( 'jsuites' );
49 - $this->admin_page->enqueue_style( 'import', array( 'tablepress-jsuites' ) );
50 - $this->admin_page->enqueue_script( 'jsuites' );
51 - $this->admin_page->enqueue_script( 'import', array( 'tablepress-jsuites' ) );
52 + TablePress::enqueue_style( 'import' );
53 + TablePress::enqueue_script( 'import' );
52 54
53 55 $this->process_action_messages( array(
54 56 'error_import' => __( 'Error: The import failed.', 'tablepress' ),
55 57 ) );
@@ -56,10 +58,12 @@
56 58
57 59 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
58 60 $this->add_meta_box( 'import-form', __( 'Import Tables', 'tablepress' ), array( $this, 'postbox_import_form' ), 'normal' );
59 61 $screen = get_current_screen();
60 - add_filter( "postbox_classes_{$screen->id}_tablepress_{$this->action}-import-form", array( $this, 'postbox_classes' ) );
61 - $this->add_meta_box( 'tables-auto-import', __( 'Automatic Periodic Table Import', 'tablepress' ), array( $this, 'postbox_auto_import' ), 'additional' );
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 + }
62 66 }
63 67
64 68 /**
65 69 * Print the screen head text.
@@ -89,29 +93,24 @@
89 93 * @param array<string, mixed> $data Data for this screen.
90 94 * @param array<string, mixed> $box Information about the meta box.
91 95 */
92 96 public function postbox_import_form( array $data, array $box ): void {
93 - $script_data = array(
94 - 'tables' => $this->admin_page->convert_to_json_parse_output( $data['tables'] ),
95 - 'importSource' => $this->admin_page->convert_to_json_parse_output( $data['import_source'] ),
96 - 'importType' => $this->admin_page->convert_to_json_parse_output( $data['import_type'] ),
97 - 'importUrl' => $this->admin_page->convert_to_json_parse_output( esc_url( $data['import_url'] ) ),
98 - 'importServer' => $this->admin_page->convert_to_json_parse_output( $data['import_server'] ),
99 - 'importFormField' => $this->admin_page->convert_to_json_parse_output( $data['import_form-field'] ),
100 - 'importExistingTable' => $this->admin_page->convert_to_json_parse_output( $data['import_existing_table'] ),
101 - 'zipSupportAvailable' => $this->admin_page->convert_to_json_parse_output( $data['zip_support_available'] ),
102 - 'showImportSourceServer' => ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) ? 'true' : 'false',
103 - 'legacyImport' => $this->admin_page->convert_to_json_parse_output( $data['legacy_import'] ),
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 + ),
104 111 );
105 112
106 - echo "<script>\n";
107 - echo "window.tp = window.tp || {};\n";
108 - echo "tp.import = {};\n";
109 - foreach ( $script_data as $variable => $value ) {
110 - echo "tp.import.{$variable} = {$value};\n";
111 - }
112 - echo "</script>\n";
113 -
114 113 echo '<div id="tablepress-import-screen"></div>';
115 114 }
116 115
117 116 /**
@@ -134,9 +133,9 @@
134 133 *
135 134 * @param array<string, mixed> $data Data for this screen.
136 135 * @param array<string, mixed> $box Information about the meta box.
137 136 *
138 - * @phpstan-ignore-next-line (PHPStan would like to see a type hint.)
137 + * @phpstan-ignore missingType.return (The method is extended elsewhere and can't have type hints.)
139 138 */
140 139 public function postbox_auto_import( /* array */ $data, /* array */ $box ) /* : void */ {
141 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.
142 141
@@ -144,9 +143,12 @@
144 143 ?>
145 144 <p style="font-size:14px;">
146 145 <span class="dashicons dashicons-info-outline"></span>
147 146 <strong><?php _e( 'Pro Tip:', 'tablepress' ); ?></strong>
148 - <?php 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' ) ); ?>
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 + ?>
149 151 </p>
150 152 <?php
151 153 endif;
152 154 }
@@ -157,17 +159,17 @@
157 159 * @since 2.0.0
158 160 */
159 161 public function wp_pointer_tp20_import_drag_drop_detect_format(): void {
160 162 $content = '<h3>' . __( 'TablePress feature: Drag and Drop Import with Format Detection', 'tablepress' ) . '</h3>';
161 - $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>';
162 164
163 - $this->admin_page->print_wp_pointer_js(
165 + $this->print_wp_pointer_js(
164 166 'tp20_import_drag_drop_detect_format',
165 167 '#tables-import-file-upload-dropzone span',
166 168 array(
167 169 'content' => $content,
168 170 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
169 - )
171 + ),
170 172 );
171 173 }
172 174
173 175 } // class TablePress_Import_View