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-export.php

view-export.php in TablePress – Tables in WordPress made easy 2.1.7, at views/view-export.php

201 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Export 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 * Export Table View class
16 *
17 * @package TablePress
18 * @subpackage Views
19 * @author Tobias Bäthge
20 * @since 1.0.0
21 */
22 class TablePress_Export_View extends TablePress_View {
23
24 /**
25 * Set up the view with data and do things that are specific for this view.
26 *
27 * @since 1.0.0
28 *
29 * @param string $action Action for this view.
30 * @param array $data Data for this view.
31 */
32 public function setup( $action, array $data ) {
33 parent::setup( $action, $data );
34
35 $this->process_action_messages( array(
36 'error_export' => __( 'Error: The export failed.', 'tablepress' ),
37 'error_load_table' => __( 'Error: This table could not be loaded!', 'tablepress' ),
38 'error_table_corrupted' => __( 'Error: The internal data of this table is corrupted!', 'tablepress' ),
39 'error_create_zip_file' => __( 'Error: The ZIP file could not be created.', 'tablepress' ),
40 ) );
41
42 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
43 if ( 0 === $data['tables_count'] ) {
44 $this->add_meta_box( 'no-tables', __( 'Export Tables', 'tablepress' ), array( $this, 'postbox_no_tables' ), 'normal' );
45 } else {
46 $this->admin_page->enqueue_script( 'export' );
47 $this->add_meta_box( 'export-form', __( 'Export Tables', 'tablepress' ), array( $this, 'postbox_export_form' ), 'normal' );
48 }
49 }
50
51 /**
52 * Print the screen head text.
53 *
54 * @since 1.0.0
55 *
56 * @param array $data Data for this screen.
57 * @param array $box Information about the text box.
58 */
59 public function textbox_head( array $data, array $box ) {
60 ?>
61 <p>
62 <?php _e( 'Exporting a table allows you to use it in other programs, like spreadsheets applications.', 'tablepress' ); ?>
63 <?php _e( 'Regularly exporting tables is also recommended as a backup of your data.', 'tablepress' ); ?>
64 </p>
65 <p>
66 <?php _e( 'To export, select the tables and the desired export format.', 'tablepress' ); ?>
67 <?php _e( 'If you choose more than one table, the exported files will automatically be stored in a ZIP archive file.', 'tablepress' ); ?>
68 <br />
69 <?php _e( 'Be aware that for the CSV and HTML formats only the table data, but no table options are exported!', 'tablepress' ); ?>
70 <?php _e( 'For the JSON format, the table data and the table options are exported.', 'tablepress' ); ?>
71 </p>
72 <?php
73 }
74
75 /**
76 * Print the content of the "No tables found" post meta box.
77 *
78 * @since 1.0.0
79 *
80 * @param array $data Data for this screen.
81 * @param array $box Information about the meta box.
82 */
83 public function postbox_no_tables( array $data, array $box ) {
84 $add_url = TablePress::url( array( 'action' => 'add' ) );
85 $import_url = TablePress::url( array( 'action' => 'import' ) );
86 ?>
87 <p><?php _e( 'No tables found.', 'tablepress' ); ?></p>
88 <p><?php printf( __( 'You should <a href="%1$s">add</a> or <a href="%2$s">import</a> a table to get started!', 'tablepress' ), $add_url, $import_url ); ?></p>
89 <?php
90 }
91
92 /**
93 * Print the content of the "Export Tables" post meta box.
94 *
95 * @since 1.0.0
96 *
97 * @param array $data Data for this screen.
98 * @param array $box Information about the meta box.
99 */
100 public function postbox_export_form( array $data, array $box ) {
101 ?>
102 <table class="tablepress-postbox-table fixed">
103 <tr>
104 <th class="column-1 top-align" scope="row">
105 <label for="tables-export"><?php _e( 'Tables to Export', 'tablepress' ); ?>:</label>
106 <?php
107 if ( $data['zip_support_available'] ) {
108 // Show a "Select all" checkbox to select all entries in the export tables dropdown.
109 echo '<br /><br /><label for="tables-export-select-all"><input type="checkbox" id="tables-export-select-all" /> ' . __( 'Select all', 'tablepress' ) . '</label>';
110
111 // Show a "Reverse List" checkbox if more tables are shown than what the height of the export tables dropdown holds.
112 if ( $data['tables_count'] > 12 ) {
113 echo '<br /><br /><label for="tables-export-reverse-list"><input type="checkbox" id="tables-export-reverse-list" /> ' . __( 'Reverse list', 'tablepress' ) . '</label>';
114 }
115 }
116 ?>
117 </th>
118 <td class="column-2">
119 <input type="hidden" name="export[tables_list]" id="tables-export-list" value="" />
120 <?php
121 $select_size = $data['tables_count'] + 1; // Show at least one empty row in the select.
122 $select_size = max( $select_size, 3 );
123 $select_size = min( $select_size, 12 );
124 $size_multiple = ( $data['zip_support_available'] ) ? " size=\"{$select_size}\" multiple=\"multiple\"" : '';
125 ?>
126 <select id="tables-export" name="export[tables][]" autofocus<?php echo $size_multiple; ?>>
127 <?php
128 foreach ( $data['table_ids'] as $table_id ) {
129 // Load table, without table data, options, and visibility settings.
130 $table = TablePress::$model_table->load( $table_id, false, false );
131 if ( ! current_user_can( 'tablepress_export_table', $table['id'] ) ) {
132 continue;
133 }
134 if ( '' === trim( $table['name'] ) ) {
135 $table['name'] = __( '(no name)', 'tablepress' );
136 }
137 $text = esc_html( sprintf( __( 'ID %1$s: %2$s', 'tablepress' ), $table['id'], $table['name'] ) );
138 $selected = selected( true, in_array( $table['id'], $data['export_ids'], true ), false );
139 echo "<option{$selected} value=\"{$table['id']}\">{$text}</option>";
140 }
141 ?>
142 </select>
143 <?php
144 if ( $data['zip_support_available'] ) {
145 // The keyboard shortcuts in this description are for Windows keyboard layouts. The Mac keys (⌘ and shift) are set via JS in export.js.
146 echo '<br /><span id="tables-export-shortcut-description" class="description">' . sprintf( __( 'You can select multiple tables by holding down the “%1$s” key or the “%2$s” key for ranges.', 'tablepress' ), _x( 'Ctrl', 'keyboard key', 'tablepress' ), _x( 'Shift', 'keyboard key', 'tablepress' ) ) . '</span>';
147 }
148 ?>
149 </td>
150 </tr>
151 <tr>
152 <th class="column-1" scope="row"><label for="tables-export-format"><?php _e( 'Export Format', 'tablepress' ); ?>:</label></th>
153 <td class="column-2">
154 <select id="tables-export-format" name="export[format]">
155 <?php
156 foreach ( $data['export_formats'] as $format => $name ) {
157 $selected = selected( $format, $data['export_format'], false );
158 echo "<option{$selected} value=\"{$format}\">{$name}</option>";
159 }
160 ?>
161 </select>
162 </td>
163 </tr>
164 <tr>
165 <th class="column-1" scope="row"><label for="tables-export-csv-delimiter"><?php _e( 'CSV Delimiter', 'tablepress' ); ?>:</label></th>
166 <td class="column-2">
167 <select id="tables-export-csv-delimiter" name="export[csv_delimiter]">
168 <?php
169 foreach ( $data['csv_delimiters'] as $delimiter => $name ) {
170 $selected = selected( $delimiter, $data['csv_delimiter'], false );
171 echo "<option{$selected} value=\"{$delimiter}\">{$name}</option>";
172 }
173 ?>
174 </select> <span id="tables-export-csv-delimiter-description" class="description hide-if-js"><?php _e( '(Only needed for CSV export.)', 'tablepress' ); ?></span>
175 </td>
176 </tr>
177 <tr class="bottom-border">
178 <th class="column-1" scope="row"><?php _e( 'ZIP file', 'tablepress' ); ?>:</th>
179 <td class="column-2">
180 <?php
181 if ( $data['zip_support_available'] ) {
182 ?>
183 <input type="checkbox" id="tables-export-zip-file" name="export[zip_file]" value="true" />
184 <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>
185 <?php
186 } else {
187 _e( 'Note: Support for ZIP file creation seems not to be available on this server.', 'tablepress' );
188 }
189 ?>
190 </td>
191 </tr>
192 <tr class="top-border">
193 <td class="column-1"></td>
194 <td class="column-2"><input type="submit" value="<?php echo esc_attr_x( 'Download Export File', 'button', 'tablepress' ); ?>" class="button button-primary button-large" /></td>
195 </tr>
196 </table>
197 <?php
198 }
199
200 } // class TablePress_Export_View
201