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

174 lines 6.7 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 'zipSupportAvailable' => $this->admin_page->convert_to_json_parse_output( $data['zip_support_available'] ),
102 'showImportSourceServer' => ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) ? 'true' : 'false',
103 'legacyImport' => $this->admin_page->convert_to_json_parse_output( $data['legacy_import'] ),
104 );
105
106 echo "<script>\n";
107 echo "window.tp = window.tp || {};\n";
108 echo "tp.import = {};\n";
109 foreach ( $script_data as $variable => $value ) {
110 echo "tp.import.{$variable} = {$value};\n";
111 }
112 echo "</script>\n";
113
114 echo '<div id="tablepress-import-screen"></div>';
115 }
116
117 /**
118 * Adds the "no-validation-highlighting" class to the "Import Tables" post meta box.
119 *
120 * @since 2.2.0
121 *
122 * @param string[] $classes The array of postbox classes.
123 * @return string[] The modified array of postbox classes.
124 */
125 public function postbox_classes( array $classes ): array {
126 $classes[] = 'no-validation-highlighting';
127 return $classes;
128 }
129
130 /**
131 * Prints the content of the "Automatic Periodic Table Import Screen" post meta box.
132 *
133 * @since 2.2.0
134 *
135 * @param array<string, mixed> $data Data for this screen.
136 * @param array<string, mixed> $box Information about the meta box.
137 *
138 * @phpstan-ignore-next-line (PHPStan would like to see a type hint.)
139 */
140 public function postbox_auto_import( /* array */ $data, /* array */ $box ) /* : void */ {
141 // 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.
142
143 if ( tb_tp_fs()->is_free_plan() ) :
144 ?>
145 <p style="font-size:14px;">
146 <span class="dashicons dashicons-info-outline"></span>
147 <strong><?php _e( 'Pro Tip:', 'tablepress' ); ?></strong>
148 <?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 </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' ) . ' ' . __( '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>';
162
163 $this->admin_page->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