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

202 lines 9.9 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 array
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 $data Data for this view.
39 */
40 public function setup( $action, array $data ) {
41 parent::setup( $action, $data );
42
43 $this->admin_page->enqueue_style( 'jsuites' );
44 $this->admin_page->enqueue_style( 'import', array( 'tablepress-jsuites' ) );
45 $this->admin_page->enqueue_script( 'jsuites' );
46 $this->admin_page->enqueue_script( 'import', array( 'tablepress-jsuites' ) );
47
48 $this->process_action_messages( array(
49 'error_import' => __( 'Error: The import failed.', 'tablepress' ),
50 ) );
51
52 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
53 $this->add_meta_box( 'import-form', __( 'Import Tables', 'tablepress' ), array( $this, 'postbox_import_form' ), 'normal' );
54 }
55
56 /**
57 * Print the screen head text.
58 *
59 * @since 1.0.0
60 *
61 * @param array $data Data for this screen.
62 * @param array $box Information about the text box.
63 */
64 public function textbox_head( array $data, array $box ) {
65 ?>
66 <p>
67 <?php _e( 'TablePress can import tables from common spreadsheet applications, like XLSX files fom Excel, or CSV, ODS, HTML, and JSON files.', 'tablepress' ); ?>
68 </p>
69 <p>
70 <?php _e( 'To import tables, select and enter the import source in the following form.', 'tablepress' ); ?>
71 <?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' ); ?>
72 </p>
73 <?php
74 }
75
76 /**
77 * Print the content of the "Import Tables" post meta box.
78 *
79 * @since 1.0.0
80 *
81 * @param array $data Data for this screen.
82 * @param array $box Information about the meta box.
83 */
84 public function postbox_import_form( array $data, array $box ) {
85 ?>
86 <table class="tablepress-postbox-table fixed">
87 <tr id="row-import-source">
88 <th class="column-1" scope="row" id="import-source-header"><?php _e( 'Import Source', 'tablepress' ); ?>:</th>
89 <td class="column-2">
90 <label for="tables-import-source-file-upload"><input name="import[source]" id="tables-import-source-file-upload" type="radio" aria-labelledby="import-source-header" value="file-upload"<?php checked( $data['import_source'], 'file-upload', true ); ?> /> <?php _e( 'File Upload', 'tablepress' ); ?></label>
91 <label for="tables-import-source-url"><input name="import[source]" id="tables-import-source-url" type="radio" aria-labelledby="import-source-header" value="url"<?php checked( $data['import_source'], 'url', true ); ?> /> <?php _e( 'URL', 'tablepress' ); ?></label>
92 <?php if ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) { ?>
93 <label for="tables-import-source-server"><input name="import[source]" id="tables-import-source-server" type="radio" aria-labelledby="import-source-header" value="server"<?php checked( $data['import_source'], 'server', true ); ?> /> <?php _e( 'File on server', 'tablepress' ); ?></label>
94 <?php } ?>
95 <label for="tables-import-source-form-field"><input name="import[source]" id="tables-import-source-form-field" type="radio" aria-labelledby="import-source-header" value="form-field"<?php checked( $data['import_source'], 'form-field', true ); ?> /> <?php _e( 'Manual Input', 'tablepress' ); ?></label>
96 </td>
97 </tr>
98 <tr id="row-import-source-file-upload" class="top-border bottom-border">
99 <th class="column-1 top-align" scope="row"><label for="tables-import-file-upload"><?php _e( 'Select files', 'tablepress' ); ?>:</label></th>
100 <td class="column-2">
101 <div class="file-upload-area">
102 <input name="import_file_upload[]" id="tables-import-file-upload" type="file" multiple />
103 <div id="tables-import-file-upload-dropzone" class="dropzone hide-if-no-js">
104 <span><?php _e( 'Click to select files, or drag them here.', 'tablepress' ); ?></span>
105 </div>
106 </div>
107 <?php
108 if ( $data['zip_support_available'] ) {
109 echo '<span class="description">' . __( 'You can also import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
110 }
111 ?>
112 </td>
113 </tr>
114 <tr id="row-import-source-url" class="top-border bottom-border">
115 <th class="column-1 top-align" scope="row"><label for="tables-import-url"><?php _e( 'File URL', 'tablepress' ); ?>:</label></th>
116 <td class="column-2">
117 <input type="text" name="import[url]" id="tables-import-url" class="large-text code" value="<?php echo esc_url( $data['import_url'] ); ?>" />
118 <?php
119 if ( $data['zip_support_available'] ) {
120 echo '<br /><span class="description">' . __( 'You can also import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
121 }
122 ?>
123 </td>
124 </tr>
125 <?php if ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) { ?>
126 <tr id="row-import-source-server" class="top-border bottom-border">
127 <th class="column-1 top-align" scope="row"><label for="tables-import-server"><?php _e( 'Server Path to file', 'tablepress' ); ?>:</label></th>
128 <td class="column-2">
129 <input type="text" name="import[server]" id="tables-import-server" class="large-text code" value="<?php echo esc_attr( $data['import_server'] ); ?>" />
130 <?php
131 if ( $data['zip_support_available'] ) {
132 echo '<br /><span class="description">' . __( 'You can also import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
133 }
134 ?>
135 </td>
136 </tr>
137 <?php } ?>
138 <tr id="row-import-source-form-field" class="top-border bottom-border">
139 <th class="column-1 top-align" scope="row"><label for="tables-import-form-field"><?php _e( 'Import data', 'tablepress' ); ?>:</label></th>
140 <td class="column-2">
141 <textarea name="import[form-field]" id="tables-import-form-field" rows="15" cols="40" class="large-text code"><?php echo esc_textarea( $data['import_form-field'] ); ?></textarea>
142 </td>
143 </tr>
144 <tr id="row-import-type" class="top-border">
145 <th class="column-1" scope="row" id="import-type-header"><?php _e( 'Add, Replace, or Append?', 'tablepress' ); ?>:</th>
146 <td class="column-2">
147 <label for="tables-import-type-add"><input name="import[type]" id="tables-import-type-add" type="radio" aria-labelledby="import-type-header" value="add"<?php checked( $data['import_type'], 'add', true ); ?> /> <?php _e( 'Add as new table', 'tablepress' ); ?></label>
148 <label for="tables-import-type-replace"><input name="import[type]" id="tables-import-type-replace" type="radio" aria-labelledby="import-type-header" value="replace"<?php checked( $data['import_type'], 'replace', true ); ?><?php disabled( $data['tables_count'] > 0, false, true ); ?> /> <?php _e( 'Replace existing table', 'tablepress' ); ?></label>
149 <label for="tables-import-type-append"><input name="import[type]" id="tables-import-type-append" type="radio" aria-labelledby="import-type-header" value="append"<?php checked( $data['import_type'], 'append', true ); ?><?php disabled( $data['tables_count'] > 0, false, true ); ?> /> <?php _e( 'Append rows to existing table', 'tablepress' ); ?></label>
150 </td>
151 </tr>
152 <tr id="row-import-existing-table" class="top-border bottom-border">
153 <th class="column-1" scope="row"><label for="tables-import-existing-table"><?php _e( 'Table to replace or append to', 'tablepress' ); ?>:</label></th>
154 <td class="column-2">
155 <select id="tables-import-existing-table" name="import[existing_table]"<?php disabled( $data['tables_count'] > 0, false, true ); ?>>
156 <option value=""><?php _e( '— Select or type —', 'tablepress' ); ?></option>
157 <?php
158 foreach ( $data['table_ids'] as $table_id ) {
159 $table = TablePress::$model_table->load( $table_id, false, false ); // Load table, without table data, options, and visibility settings.
160 if ( ! current_user_can( 'tablepress_edit_table', $table['id'] ) ) {
161 continue;
162 }
163 if ( '' === trim( $table['name'] ) ) {
164 $table['name'] = __( '(no name)', 'tablepress' );
165 }
166 $text = esc_html( sprintf( __( 'ID %1$s: %2$s', 'tablepress' ), $table['id'], $table['name'] ) );
167 $selected = selected( $table['id'], $data['import_existing_table'], false );
168 echo "<option{$selected} value=\"{$table['id']}\">{$text}</option>";
169 }
170 ?>
171 </select>
172 </td>
173 </tr>
174 <tr class="top-border">
175 <td class="column-1"></td>
176 <td class="column-2"><input type="hidden" name="import[legacy_import]" value="<?php echo ( 'true' === $data['legacy_import'] ) ? 'true' : 'false'; ?>" /><input type="submit" value="<?php echo esc_attr_x( 'Import', 'button', 'tablepress' ); ?>" class="button button-primary button-large" id="import-submit-button" /></td>
177 </tr>
178 </table>
179 <?php
180 }
181
182 /**
183 * Sets the content for the WP feature pointer about the drag and drop import and format detection on the "Import" screen.
184 *
185 * @since 2.0.0
186 */
187 public function wp_pointer_tp20_import_drag_drop_detect_format() {
188 $content = '<h3>' . __( 'TablePress feature: Drag and Drop Import with Format Detection', 'tablepress' ) . '</h3>';
189 $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>';
190
191 $this->admin_page->print_wp_pointer_js(
192 'tp20_import_drag_drop_detect_format',
193 '#tables-import-file-upload-dropzone span',
194 array(
195 'content' => $content,
196 'position' => array( 'edge' => 'bottom', 'align' => 'center' ),
197 )
198 );
199 }
200
201 } // class TablePress_Import_View
202