PluginProbe
TablePress – Tables in WordPress made easy / 3.0
TablePress – Tables in WordPress made easy v3.0
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
← All changes | views/view-export.php +41 -106 1.143.0 View file →
@@ -12,8 +12,9 @@
12 12 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13 13
14 14 /**
15 15 * Export Table View class
16 + *
16 17 * @package TablePress
17 18 * @subpackage Views
18 19 * @author Tobias Bäthge
19 20 * @since 1.0.0
@@ -24,14 +25,19 @@
24 25 * Set up the view with data and do things that are specific for this view.
25 26 *
26 27 * @since 1.0.0
27 28 *
28 - * @param string $action Action for this view.
29 - * @param array $data Data for this view.
29 + * @param string $action Action for this view.
30 + * @param array<string, mixed> $data Data for this view.
30 31 */
31 - public function setup( $action, array $data ) {
32 + #[\Override]
33 + public function setup( /* string */ $action, array $data ) /* : void */ {
34 + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
35 +
32 36 parent::setup( $action, $data );
33 37
38 + $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' );
39 +
34 40 $this->process_action_messages( array(
35 41 'error_export' => __( 'Error: The export failed.', 'tablepress' ),
36 42 'error_load_table' => __( 'Error: This table could not be loaded!', 'tablepress' ),
37 43 'error_table_corrupted' => __( 'Error: The internal data of this table is corrupted!', 'tablepress' ),
@@ -41,24 +47,22 @@
41 47 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
42 48 if ( 0 === $data['tables_count'] ) {
43 49 $this->add_meta_box( 'no-tables', __( 'Export Tables', 'tablepress' ), array( $this, 'postbox_no_tables' ), 'normal' );
44 50 } else {
45 - $this->admin_page->enqueue_script( 'export', array( 'jquery' ) );
51 + $this->admin_page->enqueue_script( 'export' );
46 52 $this->add_meta_box( 'export-form', __( 'Export Tables', 'tablepress' ), array( $this, 'postbox_export_form' ), 'normal' );
47 - $this->data['submit_button_caption'] = _x( 'Download Export File', 'button', 'tablepress' );
48 - $this->add_text_box( 'submit', array( $this, 'textbox_submit_button' ), 'submit' );
49 53 }
50 54 }
51 55
52 56 /**
53 - * Print the screen head text.
57 + * Prints the screen head text.
54 58 *
55 59 * @since 1.0.0
56 60 *
57 - * @param array $data Data for this screen.
58 - * @param array $box Information about the text box.
61 + * @param array<string, mixed> $data Data for this screen.
62 + * @param array<string, mixed> $box Information about the text box.
59 63 */
60 - public function textbox_head( array $data, array $box ) {
64 + public function textbox_head( array $data, array $box ): void {
61 65 ?>
62 66 <p>
63 67 <?php _e( 'Exporting a table allows you to use it in other programs, like spreadsheets applications.', 'tablepress' ); ?>
64 68 <?php _e( 'Regularly exporting tables is also recommended as a backup of your data.', 'tablepress' ); ?>
@@ -65,9 +69,9 @@
65 69 </p>
66 70 <p>
67 71 <?php _e( 'To export, select the tables and the desired export format.', 'tablepress' ); ?>
68 72 <?php _e( 'If you choose more than one table, the exported files will automatically be stored in a ZIP archive file.', 'tablepress' ); ?>
69 - <br />
73 + <br>
70 74 <?php _e( 'Be aware that for the CSV and HTML formats only the table data, but no table options are exported!', 'tablepress' ); ?>
71 75 <?php _e( 'For the JSON format, the table data and the table options are exported.', 'tablepress' ); ?>
72 76 </p>
73 77 <?php
@@ -73,16 +77,16 @@
73 77 <?php
74 78 }
75 79
76 80 /**
77 - * Print the content of the "No tables found" post meta box.
81 + * Prints the content of the "No tables found" post meta box.
78 82 *
79 83 * @since 1.0.0
80 84 *
81 - * @param array $data Data for this screen.
82 - * @param array $box Information about the meta box.
85 + * @param array<string, mixed> $data Data for this screen.
86 + * @param array<string, mixed> $box Information about the meta box.
83 87 */
84 - public function postbox_no_tables( array $data, array $box ) {
88 + public function postbox_no_tables( array $data, array $box ): void {
85 89 $add_url = TablePress::url( array( 'action' => 'add' ) );
86 90 $import_url = TablePress::url( array( 'action' => 'import' ) );
87 91 ?>
88 92 <p><?php _e( 'No tables found.', 'tablepress' ); ?></p>
@@ -90,103 +94,34 @@
90 94 <?php
91 95 }
92 96
93 97 /**
94 - * Print the content of the "Export Tables" post meta box.
98 + * Prints the content of the "Export Tables" post meta box.
95 99 *
96 100 * @since 1.0.0
97 101 *
98 - * @param array $data Data for this screen.
99 - * @param array $box Information about the meta box.
102 + * @param array<string, mixed> $data Data for this screen.
103 + * @param array<string, mixed> $box Information about the meta box.
100 104 */
101 - public function postbox_export_form( array $data, array $box ) {
102 - ?>
103 -<table class="tablepress-postbox-table fixed">
104 -<tbody>
105 - <tr>
106 - <th class="column-1 top-align" scope="row">
107 - <label for="tables-export"><?php _e( 'Tables to Export', 'tablepress' ); ?>:</label>
108 - <?php
109 - if ( $data['zip_support_available'] ) {
110 - echo '<br /><br /><label for="tables-export-select-all"><input type="checkbox" id="tables-export-select-all"> ' . __( 'Select all', 'tablepress' ) . '</label>';
111 - }
112 - ?>
113 - </th>
114 - <td class="column-2">
115 - <input type="hidden" name="export[tables_list]" id="tables-export-list" value="" />
116 - <?php
117 - $select_size = $data['tables_count'] + 1; // to show at least one empty row in the select
118 - $select_size = max( $select_size, 3 );
119 - $select_size = min( $select_size, 12 );
120 - $size_multiple = ( $data['zip_support_available'] ) ? " size=\"{$select_size}\" multiple=\"multiple\"" : '';
121 - ?>
122 - <select id="tables-export" name="export[tables][]"<?php echo $size_multiple; ?>>
123 - <?php
124 - foreach ( $data['table_ids'] as $table_id ) {
125 - // Load table, without table data, options, and visibility settings.
126 - $table = TablePress::$model_table->load( $table_id, false, false );
127 - if ( ! current_user_can( 'tablepress_export_table', $table['id'] ) ) {
128 - continue;
129 - }
130 - if ( '' === trim( $table['name'] ) ) {
131 - $table['name'] = __( '(no name)', 'tablepress' );
132 - }
133 - $text = esc_html( sprintf( __( 'ID %1$s: %2$s', 'tablepress' ), $table['id'], $table['name'] ) );
134 - $selected = selected( true, in_array( $table['id'], $data['export_ids'], true ), false );
135 - echo "<option{$selected} value=\"{$table['id']}\">{$text}</option>";
136 - }
137 - ?>
138 - </select>
139 - <?php
140 - if ( $data['zip_support_available'] ) {
141 - echo '<br /><span class="description">' . __( 'You can select multiple tables by holding down the &#8220;Ctrl&#8221; key (Windows) or the &#8220;Command&#8221; key (Mac).', 'tablepress' ) . '</span>';
142 - }
143 - ?>
144 - </td>
145 - </tr>
146 - <tr>
147 - <th class="column-1" scope="row"><label for="tables-export-format"><?php _e( 'Export Format', 'tablepress' ); ?>:</label></th>
148 - <td class="column-2">
149 - <select id="tables-export-format" name="export[format]">
150 - <?php
151 - foreach ( $data['export_formats'] as $format => $name ) {
152 - $selected = selected( $format, $data['export_format'], false );
153 - echo "<option{$selected} value=\"{$format}\">{$name}</option>";
154 - }
155 - ?>
156 - </select>
157 - </td>
158 - </tr>
159 - <tr>
160 - <th class="column-1" scope="row"><label for="tables-export-csv-delimiter"><?php _e( 'CSV Delimiter', 'tablepress' ); ?>:</label></th>
161 - <td class="column-2">
162 - <select id="tables-export-csv-delimiter" name="export[csv_delimiter]">
163 - <?php
164 - foreach ( $data['csv_delimiters'] as $delimiter => $name ) {
165 - $selected = selected( $delimiter, $data['csv_delimiter'], false );
166 - echo "<option{$selected} value=\"{$delimiter}\">{$name}</option>";
167 - }
168 - ?>
169 - </select> <span id="tables-export-csv-delimiter-description" class="description hide-if-js"><?php _e( '(Only needed for CSV export.)', 'tablepress' ); ?></span>
170 - </td>
171 - </tr>
172 - <tr>
173 - <th class="column-1" scope="row"><?php _e( 'ZIP file', 'tablepress' ); ?>:</th>
174 - <td class="column-2">
175 - <?php
176 - if ( $data['zip_support_available'] ) {
177 - ?>
178 - <input type="checkbox" id="tables-export-zip-file" name="export[zip_file]" value="true" />
179 - <label for="tables-export-zip-file"><?php _e( 'Create a ZIP archive.', 'tablepress' ); ?> <span id="tables-export-zip-file-description" class="description hide-if-js"><?php _e( '(Mandatory if more than one table is selected.)', 'tablepress' ); ?></span></label>
180 - <?php
181 - } else {
182 - _e( 'Note: Support for ZIP file creation seems not to be available on this server.', 'tablepress' );
105 + public function postbox_export_form( array $data, array $box ): void {
106 + $script_data = array(
107 + 'tables' => $this->admin_page->convert_to_json_parse_output( $data['tables'] ),
108 + 'exportFormats' => $this->admin_page->convert_to_json_parse_output( $data['export_formats'] ),
109 + 'csvDelimiters' => $this->admin_page->convert_to_json_parse_output( $data['csv_delimiters'] ),
110 + 'zipSupportAvailable' => $this->admin_page->convert_to_json_parse_output( $data['zip_support_available'] ),
111 + 'selectedTables' => $this->admin_page->convert_to_json_parse_output( $data['export_ids'] ),
112 + 'exportFormat' => $this->admin_page->convert_to_json_parse_output( $data['export_format'] ),
113 + 'csvDelimiter' => $this->admin_page->convert_to_json_parse_output( $data['csv_delimiter'] ),
114 + );
115 +
116 + echo "<script>\n";
117 + echo "window.tp = window.tp || {};\n";
118 + echo "tp.export = {};\n";
119 + foreach ( $script_data as $variable => $value ) {
120 + echo "tp.export.{$variable} = {$value};\n";
183 121 }
184 - ?>
185 - </td>
186 - </tr>
187 -</tbody>
188 -</table>
189 - <?php
122 + echo "</script>\n";
123 +
124 + echo '<div id="tablepress-export-screen"></div>';
190 125 }
191 126
192 127 } // class TablePress_Export_View