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

196 lines 9.8 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 * @package TablePress
17 * @subpackage Views
18 * @author Tobias Bäthge
19 * @since 1.0.0
20 */
21 class TablePress_Import_View extends TablePress_View {
22
23 /**
24 * Set up the view with data and do things that are specific for this view.
25 *
26 * @since 1.0.0
27 *
28 * @param string $action Action for this view.
29 * @param array $data Data for this view.
30 */
31 public function setup( $action, array $data ) {
32 parent::setup( $action, $data );
33
34 $this->admin_page->enqueue_script( 'import', array( 'jquery' ) );
35
36 $this->process_action_messages( array(
37 'error_import' => __( 'Error: The import failed.', 'tablepress' ),
38 'error_no_zip_import' => __( 'Error: Import of ZIP files is not available on this server.', 'tablepress' ),
39 'error_import_zip_open' => __( 'Error: The ZIP file could not be opened.', 'tablepress' ),
40 'error_import_zip_content' => __( 'Error: The data in the ZIP file is invalid.', 'tablepress' ),
41 'error_import_no_existing_id' => __( 'Error: You selected to replace or append to an existing table, but did not select a table.', 'tablepress' ),
42 'error_import_source_invalid' => __( 'Error: The source for the import is invalid or could not be accessed.', 'tablepress' ),
43 'error_import_data' => __( 'Error: The data for the import is invalid.', 'tablepress' ),
44 ) );
45
46 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
47 $this->add_meta_box( 'import-form', __( 'Import Tables', 'tablepress' ), array( $this, 'postbox_import_form' ), 'normal' );
48 }
49
50 /**
51 * Print the screen head text.
52 *
53 * @since 1.0.0
54 *
55 * @param array $data Data for this screen.
56 * @param array $box Information about the text box.
57 */
58 public function textbox_head( array $data, array $box ) {
59 ?>
60 <p>
61 <?php _e( 'TablePress can import tables from existing data, like from a CSV, XLS, or XLSX file from a spreadsheet application (e.g. Excel), an HTML file resembling a webpage, or its own JSON format.', 'tablepress' ); ?>
62 </p>
63 <p>
64 <?php _e( 'To import a table, select and enter the import source in the following form.', 'tablepress' ); ?>
65 <?php
66 if ( 0 < $data['tables_count'] ) {
67 _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' );
68 }
69 ?>
70 </p>
71 <?php
72 }
73
74 /**
75 * Print the content of the "Import Tables" post meta box.
76 *
77 * @since 1.0.0
78 *
79 * @param array $data Data for this screen.
80 * @param array $box Information about the meta box.
81 */
82 public function postbox_import_form( array $data, array $box ) {
83 ?>
84 <table class="tablepress-postbox-table fixed">
85 <tbody>
86 <tr id="row-import-source">
87 <th class="column-1" scope="row" id="import-source-header"><?php _e( 'Import Source', 'tablepress' ); ?>:</th>
88 <td class="column-2">
89 <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>
90 <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>
91 <?php if ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) { ?>
92 <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>
93 <?php } ?>
94 <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>
95 </td>
96 </tr>
97 <tr id="row-import-source-file-upload" class="bottom-border">
98 <th class="column-1 top-align" scope="row"><label for="tables-import-file-upload"><?php _e( 'Select file', 'tablepress' ); ?>:</label></th>
99 <td class="column-2">
100 <input name="import_file_upload" id="tables-import-file-upload" type="file" class="large-text" style="box-sizing: border-box;" />
101 <?php
102 if ( $data['zip_support_available'] ) {
103 echo '<br /><span class="description">' . __( 'You can import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
104 }
105 ?>
106 </td>
107 </tr>
108 <tr id="row-import-source-url" class="bottom-border">
109 <th class="column-1 top-align" scope="row"><label for="tables-import-url"><?php _e( 'File URL', 'tablepress' ); ?>:</label></th>
110 <td class="column-2">
111 <input type="text" name="import[url]" id="tables-import-url" class="large-text" value="<?php echo esc_attr( $data['import_url'] ); ?>" />
112 <?php
113 if ( $data['zip_support_available'] ) {
114 echo '<br /><span class="description">' . __( 'You can import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
115 }
116 ?>
117 </td>
118 </tr>
119 <?php if ( ( ! is_multisite() && current_user_can( 'manage_options' ) ) || is_super_admin() ) { ?>
120 <tr id="row-import-source-server" class="bottom-border">
121 <th class="column-1 top-align" scope="row"><label for="tables-import-server"><?php _e( 'Server Path to file', 'tablepress' ); ?>:</label></th>
122 <td class="column-2">
123 <input type="text" name="import[server]" id="tables-import-server" class="large-text" value="<?php echo esc_attr( $data['import_server'] ); ?>" />
124 <?php
125 if ( $data['zip_support_available'] ) {
126 echo '<br /><span class="description">' . __( 'You can import multiple tables by placing them in a ZIP file.', 'tablepress' ) . '</span>';
127 }
128 ?>
129 </td>
130 </tr>
131 <?php } ?>
132 <tr id="row-import-source-form-field" class="bottom-border">
133 <th class="column-1 top-align" scope="row"><label for="tables-import-form-field"><?php _e( 'Import data', 'tablepress' ); ?>:</label></th>
134 <td class="column-2">
135 <textarea name="import[form_field]" id="tables-import-form-field" rows="15" cols="40" class="large-text"><?php echo esc_textarea( $data['import_form_field'] ); ?></textarea>
136 </td>
137 </tr>
138 <tr class="top-border bottom-border">
139 <th class="column-1" scope="row"><label for="tables-import-format"><?php _e( 'Import Format', 'tablepress' ); ?>:</label></th>
140 <td class="column-2">
141 <select id="tables-import-format" name="import[format]">
142 <?php
143 foreach ( $data['import_formats'] as $format => $name ) {
144 $selected = selected( $format, $data['import_format'], false );
145 echo "<option{$selected} value=\"{$format}\">{$name}</option>";
146 }
147 ?>
148 </select>
149 <?php
150 if ( ! $data['html_import_support_available'] ) {
151 echo '<br /><span class="description">' . __( 'Import of HTML files is not available on your server.', 'tablepress' ) . '</span>';
152 }
153 ?>
154 </td>
155 </tr>
156 <tr id="row-import-type" class="top-border">
157 <th class="column-1" scope="row" id="import-type-header"><?php _e( 'Add, Replace, or Append?', 'tablepress' ); ?>:</th>
158 <td class="column-2">
159 <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>
160 <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>
161 <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>
162 </td>
163 </tr>
164 <tr id="row-import-existing-table" class="bottom-border">
165 <th class="column-1" scope="row"><label for="tables-import-existing-table"><?php _e( 'Table to replace or append to', 'tablepress' ); ?>:</label></th>
166 <td class="column-2">
167 <select id="tables-import-existing-table" name="import[existing_table]"<?php disabled( $data['tables_count'] > 0, false, true ); ?>>
168 <option value=""><?php _e( '&mdash; Select &mdash;', 'tablepress' ); ?></option>
169 <?php
170 foreach ( $data['table_ids'] as $table_id ) {
171 $table = TablePress::$model_table->load( $table_id, false, false ); // Load table, without table data, options, and visibility settings
172 if ( ! current_user_can( 'tablepress_edit_table', $table['id'] ) ) {
173 continue;
174 }
175 if ( '' === trim( $table['name'] ) ) {
176 $table['name'] = __( '(no name)', 'tablepress' );
177 }
178 $text = esc_html( sprintf( __( 'ID %1$s: %2$s', 'tablepress' ), $table['id'], $table['name'] ) );
179 $selected = selected( $table['id'], $data['import_existing_table'], false );
180 echo "<option{$selected} value=\"{$table['id']}\">{$text}</option>";
181 }
182 ?>
183 </select>
184 </td>
185 </tr>
186 <tr class="top-border">
187 <td class="column-1"></td>
188 <td class="column-2"><input type="submit" value="<?php echo esc_attr_x( 'Import', 'button', 'tablepress' ); ?>" class="button button-primary button-large" name="submit" /></td>
189 </tr>
190 </tbody>
191 </table>
192 <?php
193 }
194
195 } // class TablePress_Import_View
196