PluginProbe
TablePress – Tables in WordPress made easy / 3.2
TablePress – Tables in WordPress made easy v3.2
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 2.4.4 All 44 releases
tablepress / views / view-import.php

view-import.php in TablePress – Tables in WordPress made easy 3.2, at views/view-import.php

172 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Import Table View
4 *
5 * @package TablePress
6 * @subpackage Views
7 * @author Tobias Bäthge
8 * @since 1.0.0
9 */
10
11 // Prohibit direct script loading.
12 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13
14 /**
15 * Import Table View class
16 *
17 * @package TablePress
18 * @subpackage Views
19 * @author Tobias Bäthge
20 * @since 1.0.0
21 */
22 class TablePress_Import_View extends TablePress_View {
23
24 /**
25 * List of WP feature pointers for this view.
26 *
27 * @since 2.0.0
28 * @var string[]
29 */
30 protected array $wp_pointers = array( 'tp20_import_drag_drop_detect_format' );
31
32 /**
33 * Set up the view with data and do things that are specific for this view.
34 *
35 * @since 1.0.0
36 *
37 * @param string $action Action for this view.
38 * @param array<string, mixed> $data Data for this view.
39 */
40 #[\Override]
41 public function setup( /* string */ $action, array $data ) /* : void */ {
42 // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
43
44 parent::setup( $action, $data );
45
46 $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' );
47
48 $this->admin_page->enqueue_style( 'import' );
49 $this->admin_page->enqueue_script( 'import' );
50
51 $this->process_action_messages( array(
52 'error_import' => __( 'Error: The import failed.', 'tablepress' ),
53 ) );
54
55 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
56 $this->add_meta_box( 'import-form', __( 'Import Tables', 'tablepress' ), array( $this, 'postbox_import_form' ), 'normal' );
57 $screen = get_current_screen();
58 add_filter( "postbox_classes_{$screen->id}_tablepress_{$this->action}-import-form", array( $this, 'postbox_classes' ) ); // @phpstan-ignore property.nonObject
59 if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW ) {
60 $this->add_meta_box( 'tables-auto-import', __( 'Automatic Periodic Table Import', 'tablepress' ), array( $this, 'postbox_auto_import' ), 'additional' );
61 }
62 }
63
64 /**
65 * Print the screen head text.
66 *
67 * @since 1.0.0
68 *
69 * @param array<string, mixed> $data Data for this screen.
70 * @param array<string, mixed> $box Information about the text box.
71 */
72 public function textbox_head( array $data, array $box ): void {
73 ?>
74 <p>
75 <?php _e( 'TablePress can import tables from common spreadsheet applications, like XLSX files from Excel, or CSV, ODS, HTML, and JSON files.', 'tablepress' ); ?>
76 </p>
77 <p>
78 <?php _e( 'To import tables, select and enter the import source in the following form.', 'tablepress' ); ?>
79 <?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' ); ?>
80 </p>
81 <?php
82 }
83
84 /**
85 * Prints the content of the "Import Tables" post meta box.
86 *
87 * @since 1.0.0
88 *
89 * @param array<string, mixed> $data Data for this screen.
90 * @param array<string, mixed> $box Information about the meta box.
91 */
92 public function postbox_import_form( array $data, array $box ): void {
93 $this->print_script_data_json(
94 'import',
95 array(
96 'tables' => $data['tables'],
97 'importSource' => $data['import_source'],
98 'importType' => $data['import_type'],
99 'importUrl' => esc_url( $data['import_url'] ),
100 'importServer' => $data['import_server'],
101 'importFormField' => $data['import_form-field'],
102 'importExistingTable' => $data['import_existing_table'],
103 'showImportSourceServer' => ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ),
104 'showImportSourceUrl' => current_user_can( 'tablepress_import_tables_url' ),
105 'legacyImport' => $data['legacy_import'],
106 ),
107 );
108
109 echo '<div id="tablepress-import-screen"></div>';
110 }
111
112 /**
113 * Adds the "no-validation-highlighting" class to the "Import Tables" post meta box.
114 *
115 * @since 2.2.0
116 *
117 * @param string[] $classes The array of postbox classes.
118 * @return string[] The modified array of postbox classes.
119 */
120 public function postbox_classes( array $classes ): array {
121 $classes[] = 'no-validation-highlighting';
122 return $classes;
123 }
124
125 /**
126 * Prints the content of the "Automatic Periodic Table Import Screen" post meta box.
127 *
128 * @since 2.2.0
129 *
130 * @param array<string, mixed> $data Data for this screen.
131 * @param array<string, mixed> $box Information about the meta box.
132 *
133 * @phpstan-ignore missingType.return (The method is extended elsewhere and can't have type hints.)
134 */
135 public function postbox_auto_import( /* array */ $data, /* array */ $box ) /* : void */ {
136 // 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.
137
138 if ( tb_tp_fs()->is_free_plan() ) :
139 ?>
140 <p style="font-size:14px;">
141 <span class="dashicons dashicons-info-outline"></span>
142 <strong><?php _e( 'Pro Tip:', 'tablepress' ); ?></strong>
143 <?php
144 /* translators: %1$s: URL to TablePress website, %2$s: Module name */
145 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' ) );
146 ?>
147 </p>
148 <?php
149 endif;
150 }
151
152 /**
153 * Sets the content for the WP feature pointer about the drag and drop import and format detection on the "Import" screen.
154 *
155 * @since 2.0.0
156 */
157 public function wp_pointer_tp20_import_drag_drop_detect_format(): void {
158 $content = '<h3>' . __( 'TablePress feature: Drag and Drop Import with Format Detection', 'tablepress' ) . '</h3>';
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>';
160
161 $this->admin_page->print_wp_pointer_js(
162 'tp20_import_drag_drop_detect_format',
163 '#tables-import-file-upload-dropzone span',
164 array(
165 'content' => $content,
166 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
167 ),
168 );
169 }
170
171 } // class TablePress_Import_View
172