| @@ -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 | * |
| @@ -36,19 +38,20 @@ | ||
| 36 | 38 | * |
| 37 | 39 | * @param string $action Action for this view. |
| 38 | 40 | * @param array<string, mixed> $data Data for this view. |
| 39 | 41 | */ |
| 42 | + #[\Override] | |
| 40 | 43 | public function setup( /* string */ $action, array $data ) /* : void */ { |
| 41 | 44 | // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited. |
| 42 | 45 | |
| 43 | 46 | parent::setup( $action, $data ); |
| 44 | 47 | |
| 48 | + TablePress::enqueue_script( 'common', array( 'jquery-core', 'postbox' ) ); | |
| 49 | + | |
| 45 | 50 | $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' ); |
| 46 | 51 | |
| 47 | - $this->admin_page->enqueue_style( 'jsuites' ); | |
| 48 | - $this->admin_page->enqueue_style( 'import', array( 'tablepress-jsuites' ) ); | |
| 49 | - $this->admin_page->enqueue_script( 'jsuites' ); | |
| 50 | - $this->admin_page->enqueue_script( 'import', array( 'tablepress-jsuites' ) ); | |
| 52 | + TablePress::enqueue_style( 'import' ); | |
| 53 | + TablePress::enqueue_script( 'import' ); | |
| 51 | 54 | |
| 52 | 55 | $this->process_action_messages( array( |
| 53 | 56 | 'error_import' => __( 'Error: The import failed.', 'tablepress' ), |
| 54 | 57 | ) ); |
| @@ -55,10 +58,12 @@ | ||
| 55 | 58 | |
| 56 | 59 | $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' ); |
| 57 | 60 | $this->add_meta_box( 'import-form', __( 'Import Tables', 'tablepress' ), array( $this, 'postbox_import_form' ), 'normal' ); |
| 58 | 61 | $screen = get_current_screen(); |
| 59 | - add_filter( "postbox_classes_{$screen->id}_tablepress_{$this->action}-import-form", array( $this, 'postbox_classes' ) ); | |
| 60 | - $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 | + } | |
| 61 | 66 | } |
| 62 | 67 | |
| 63 | 68 | /** |
| 64 | 69 | * Print the screen head text. |
| @@ -88,29 +93,24 @@ | ||
| 88 | 93 | * @param array<string, mixed> $data Data for this screen. |
| 89 | 94 | * @param array<string, mixed> $box Information about the meta box. |
| 90 | 95 | */ |
| 91 | 96 | public function postbox_import_form( array $data, array $box ): void { |
| 92 | - $script_data = array( | |
| 93 | - 'tables' => $this->admin_page->convert_to_json_parse_output( $data['tables'] ), | |
| 94 | - 'importSource' => $this->admin_page->convert_to_json_parse_output( $data['import_source'] ), | |
| 95 | - 'importType' => $this->admin_page->convert_to_json_parse_output( $data['import_type'] ), | |
| 96 | - 'importUrl' => $this->admin_page->convert_to_json_parse_output( esc_url( $data['import_url'] ) ), | |
| 97 | - 'importServer' => $this->admin_page->convert_to_json_parse_output( $data['import_server'] ), | |
| 98 | - 'importFormField' => $this->admin_page->convert_to_json_parse_output( $data['import_form-field'] ), | |
| 99 | - 'importExistingTable' => $this->admin_page->convert_to_json_parse_output( $data['import_existing_table'] ), | |
| 100 | - 'zipSupportAvailable' => $this->admin_page->convert_to_json_parse_output( $data['zip_support_available'] ), | |
| 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 |