PluginProbe
TablePress – Tables in WordPress made easy / trunk
TablePress – Tables in WordPress made easy vtrunk
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 trunk, at views/view-import.php

174 lines 6.2 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 TablePress::enqueue_script( 'common', array( 'jquery-core', 'postbox' ) );
47
48 $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' );
49
50 TablePress::enqueue_style( 'import' );
51 TablePress::enqueue_script( 'import' );
52
53 $this->process_action_messages( array(
54 'error_import' => __( 'Error: The import failed.', 'tablepress' ),
55 ) );
56
57 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
58 $this->add_meta_box( 'import-form', __( 'Import Tables', 'tablepress' ), array( $this, 'postbox_import_form' ), 'normal' );
59 $screen = get_current_screen();
60 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 }
64 }
65
66 /**
67 * Print the screen head text.
68 *
69 * @since 1.0.0
70 *
71 * @param array<string, mixed> $data Data for this screen.
72 * @param array<string, mixed> $box Information about the text box.
73 */
74 public function textbox_head( array $data, array $box ): void {
75 ?>
76 <p>
77 <?php _e( 'TablePress can import tables from common spreadsheet applications, like XLSX files from Excel, or CSV, ODS, HTML, and JSON files.', 'tablepress' ); ?>
78 </p>
79 <p>
80 <?php _e( 'To import tables, select and enter the import source in the following form.', 'tablepress' ); ?>
81 <?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' ); ?>
82 </p>
83 <?php
84 }
85
86 /**
87 * Prints the content of the "Import Tables" post meta box.
88 *
89 * @since 1.0.0
90 *
91 * @param array<string, mixed> $data Data for this screen.
92 * @param array<string, mixed> $box Information about the meta box.
93 */
94 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 ),
109 );
110
111 echo '<div id="tablepress-import-screen"></div>';
112 }
113
114 /**
115 * Adds the "no-validation-highlighting" class to the "Import Tables" post meta box.
116 *
117 * @since 2.2.0
118 *
119 * @param string[] $classes The array of postbox classes.
120 * @return string[] The modified array of postbox classes.
121 */
122 public function postbox_classes( array $classes ): array {
123 $classes[] = 'no-validation-highlighting';
124 return $classes;
125 }
126
127 /**
128 * Prints the content of the "Automatic Periodic Table Import Screen" post meta box.
129 *
130 * @since 2.2.0
131 *
132 * @param array<string, mixed> $data Data for this screen.
133 * @param array<string, mixed> $box Information about the meta box.
134 *
135 * @phpstan-ignore missingType.return (The method is extended elsewhere and can't have type hints.)
136 */
137 public function postbox_auto_import( /* array */ $data, /* array */ $box ) /* : void */ {
138 // 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.
139
140 if ( tb_tp_fs()->is_free_plan() ) :
141 ?>
142 <p style="font-size:14px;">
143 <span class="dashicons dashicons-info-outline"></span>
144 <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 ?>
149 </p>
150 <?php
151 endif;
152 }
153
154 /**
155 * Sets the content for the WP feature pointer about the drag and drop import and format detection on the "Import" screen.
156 *
157 * @since 2.0.0
158 */
159 public function wp_pointer_tp20_import_drag_drop_detect_format(): void {
160 $content = '<h3>' . __( 'TablePress feature: Drag and Drop Import with Format Detection', 'tablepress' ) . '</h3>';
161 $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
163 $this->print_wp_pointer_js(
164 'tp20_import_drag_drop_detect_format',
165 '#tables-import-file-upload-dropzone span',
166 array(
167 'content' => $content,
168 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
169 ),
170 );
171 }
172
173 } // class TablePress_Import_View
174