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

173 lines 6.6 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 $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( '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
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' ) );
61 $this->add_meta_box( 'tables-auto-import', __( 'Automatic Periodic Table Import', 'tablepress' ), array( $this, 'postbox_auto_import' ), 'additional' );
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 $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'] ),
103 );
104
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 echo '<div id="tablepress-import-screen"></div>';
114 }
115
116 /**
117 * Adds the "no-validation-highlighting" class to the "Import Tables" post meta box.
118 *
119 * @since 2.2.0
120 *
121 * @param string[] $classes The array of postbox classes.
122 * @return string[] The modified array of postbox classes.
123 */
124 public function postbox_classes( array $classes ): array {
125 $classes[] = 'no-validation-highlighting';
126 return $classes;
127 }
128
129 /**
130 * Prints the content of the "Automatic Periodic Table Import Screen" post meta box.
131 *
132 * @since 2.2.0
133 *
134 * @param array<string, mixed> $data Data for this screen.
135 * @param array<string, mixed> $box Information about the meta box.
136 *
137 * @phpstan-ignore-next-line (PHPStan would like to see a type hint.)
138 */
139 public function postbox_auto_import( /* array */ $data, /* array */ $box ) /* : void */ {
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
142 if ( tb_tp_fs()->is_free_plan() ) :
143 ?>
144 <p style="font-size:14px;">
145 <span class="dashicons dashicons-info-outline"></span>
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' ) ); ?>
148 </p>
149 <?php
150 endif;
151 }
152
153 /**
154 * Sets the content for the WP feature pointer about the drag and drop import and format detection on the "Import" screen.
155 *
156 * @since 2.0.0
157 */
158 public function wp_pointer_tp20_import_drag_drop_detect_format(): void {
159 $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>';
161
162 $this->admin_page->print_wp_pointer_js(
163 'tp20_import_drag_drop_detect_format',
164 '#tables-import-file-upload-dropzone span',
165 array(
166 'content' => $content,
167 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
168 )
169 );
170 }
171
172 } // class TablePress_Import_View
173