| @@ -42,14 +42,12 @@ | ||
| 42 | 42 | // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited. |
| 43 | 43 | |
| 44 | 44 | parent::setup( $action, $data ); |
| 45 | 45 | |
| 46 | - TablePress::enqueue_script( 'common', array( 'jquery-core', 'postbox' ) ); | |
| 47 | - | |
| 48 | 46 | $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' ); |
| 49 | 47 | |
| 50 | - TablePress::enqueue_style( 'import' ); | |
| 51 | - TablePress::enqueue_script( 'import' ); | |
| 48 | + $this->admin_page->enqueue_style( 'import' ); | |
| 49 | + $this->admin_page->enqueue_script( 'import' ); | |
| 52 | 50 | |
| 53 | 51 | $this->process_action_messages( array( |
| 54 | 52 | 'error_import' => __( 'Error: The import failed.', 'tablepress' ), |
| 55 | 53 | ) ); |
| @@ -57,11 +55,9 @@ | ||
| 57 | 55 | $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' ); |
| 58 | 56 | $this->add_meta_box( 'import-form', __( 'Import Tables', 'tablepress' ), array( $this, 'postbox_import_form' ), 'normal' ); |
| 59 | 57 | $screen = get_current_screen(); |
| 60 | 58 | add_filter( "postbox_classes_{$screen->id}_tablepress_{$this->action}-import-form", array( $this, 'postbox_classes' ) ); // @phpstan-ignore property.nonObject |
| 61 | - if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW ) { | |
| 62 | - $this->add_meta_box( 'tables-auto-import', __( 'Automatic Periodic Table Import', 'tablepress' ), array( $this, 'postbox_auto_import' ), 'additional' ); | |
| 63 | - } | |
| 59 | + $this->add_meta_box( 'tables-auto-import', __( 'Automatic Periodic Table Import', 'tablepress' ), array( $this, 'postbox_auto_import' ), 'additional' ); | |
| 64 | 60 | } |
| 65 | 61 | |
| 66 | 62 | /** |
| 67 | 63 | * Print the screen head text. |
| @@ -91,24 +87,29 @@ | ||
| 91 | 87 | * @param array<string, mixed> $data Data for this screen. |
| 92 | 88 | * @param array<string, mixed> $box Information about the meta box. |
| 93 | 89 | */ |
| 94 | 90 | public function postbox_import_form( array $data, array $box ): void { |
| 95 | - $this->print_script_data_json( | |
| 96 | - 'import', | |
| 97 | - array( | |
| 98 | - 'tables' => $data['tables'], | |
| 99 | - 'importSource' => $data['import_source'], | |
| 100 | - 'importType' => $data['import_type'], | |
| 101 | - 'importUrl' => $data['import_url'], | |
| 102 | - 'importServer' => $data['import_server'], | |
| 103 | - 'importFormField' => $data['import_form-field'], | |
| 104 | - 'importExistingTable' => $data['import_existing_table'], | |
| 105 | - 'showImportSourceServer' => ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ), | |
| 106 | - 'showImportSourceUrl' => current_user_can( 'tablepress_import_tables_url' ), | |
| 107 | - 'legacyImport' => $data['legacy_import'], | |
| 108 | - ), | |
| 91 | + $script_data = array( | |
| 92 | + 'tables' => $this->admin_page->convert_to_json_parse_output( $data['tables'] ), | |
| 93 | + 'importSource' => $this->admin_page->convert_to_json_parse_output( $data['import_source'] ), | |
| 94 | + 'importType' => $this->admin_page->convert_to_json_parse_output( $data['import_type'] ), | |
| 95 | + 'importUrl' => $this->admin_page->convert_to_json_parse_output( esc_url( $data['import_url'] ) ), | |
| 96 | + 'importServer' => $this->admin_page->convert_to_json_parse_output( $data['import_server'] ), | |
| 97 | + 'importFormField' => $this->admin_page->convert_to_json_parse_output( $data['import_form-field'] ), | |
| 98 | + 'importExistingTable' => $this->admin_page->convert_to_json_parse_output( $data['import_existing_table'] ), | |
| 99 | + 'showImportSourceServer' => ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) ? 'true' : 'false', | |
| 100 | + 'showImportSourceUrl' => current_user_can( 'tablepress_import_tables_url' ) ? 'true' : 'false', | |
| 101 | + 'legacyImport' => $this->admin_page->convert_to_json_parse_output( $data['legacy_import'] ), | |
| 109 | 102 | ); |
| 110 | 103 | |
| 104 | + echo "<script>\n"; | |
| 105 | + echo "window.tp = window.tp || {};\n"; | |
| 106 | + echo "tp.import = {};\n"; | |
| 107 | + foreach ( $script_data as $variable => $value ) { | |
| 108 | + echo "tp.import.{$variable} = {$value};\n"; | |
| 109 | + } | |
| 110 | + echo "</script>\n"; | |
| 111 | + | |
| 111 | 112 | echo '<div id="tablepress-import-screen"></div>'; |
| 112 | 113 | } |
| 113 | 114 | |
| 114 | 115 | /** |
| @@ -141,12 +142,9 @@ | ||
| 141 | 142 | ?> |
| 142 | 143 | <p style="font-size:14px;"> |
| 143 | 144 | <span class="dashicons dashicons-info-outline"></span> |
| 144 | 145 | <strong><?php _e( 'Pro Tip:', 'tablepress' ); ?></strong> |
| 145 | - <?php | |
| 146 | - /* translators: %1$s: URL to TablePress website, %2$s: Module name */ | |
| 147 | - 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' ) ); | |
| 148 | - ?> | |
| 146 | + <?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' ) ); ?> | |
| 149 | 147 | </p> |
| 150 | 148 | <?php |
| 151 | 149 | endif; |
| 152 | 150 | } |
| @@ -159,9 +157,9 @@ | ||
| 159 | 157 | public function wp_pointer_tp20_import_drag_drop_detect_format(): void { |
| 160 | 158 | $content = '<h3>' . __( 'TablePress feature: Drag and Drop Import with Format Detection', 'tablepress' ) . '</h3>'; |
| 161 | 159 | $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 | 160 | |
| 163 | - $this->print_wp_pointer_js( | |
| 161 | + $this->admin_page->print_wp_pointer_js( | |
| 164 | 162 | 'tp20_import_drag_drop_detect_format', |
| 165 | 163 | '#tables-import-file-upload-dropzone span', |
| 166 | 164 | array( |
| 167 | 165 | 'content' => $content, |