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 -30 2.3.1 → 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,28 +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 - 'showImportSourceServer' => ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) ? 'true' : 'false',
102 - '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 + ),
103 111 );
104 112
105 - echo "<script>\n";
106 - echo "window.tp = window.tp || {};\n";
107 - echo "tp.import = {};\n";
108 - foreach ( $script_data as $variable => $value ) {
109 - echo "tp.import.{$variable} = {$value};\n";
110 - }
111 - echo "</script>\n";
112 -
113 113 echo '<div id="tablepress-import-screen"></div>';
114 114 }
115 115
116 116 /**
@@ -133,9 +133,9 @@
133 133 *
134 134 * @param array<string, mixed> $data Data for this screen.
135 135 * @param array<string, mixed> $box Information about the meta box.
136 136 *
137 - * @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.)
138 138 */
139 139 public function postbox_auto_import( /* array */ $data, /* array */ $box ) /* : void */ {
140 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 141
@@ -143,9 +143,12 @@
143 143 ?>
144 144 <p style="font-size:14px;">
145 145 <span class="dashicons dashicons-info-outline"></span>
146 146 <strong><?php _e( 'Pro Tip:', 'tablepress' ); ?></strong>
147 - <?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 + ?>
148 151 </p>
149 152 <?php
150 153 endif;
151 154 }
@@ -156,17 +159,17 @@
156 159 * @since 2.0.0
157 160 */
158 161 public function wp_pointer_tp20_import_drag_drop_detect_format(): void {
159 162 $content = '<h3>' . __( 'TablePress feature: Drag and Drop Import with Format Detection', 'tablepress' ) . '</h3>';
160 - $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>';
161 164
162 - $this->admin_page->print_wp_pointer_js(
165 + $this->print_wp_pointer_js(
163 166 'tp20_import_drag_drop_detect_format',
164 167 '#tables-import-file-upload-dropzone span',
165 168 array(
166 169 'content' => $content,
167 170 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
168 - )
171 + ),
169 172 );
170 173 }
171 174
172 175 } // class TablePress_Import_View