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

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

193 lines 7.2 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 * @package TablePress
17 * @subpackage Views
18 * @author Tobias Bäthge
19 * @since 1.0.0
20 */
21 class TablePress_Export_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->process_action_messages( array(
35 'error_export' => __( 'Error: The export failed.', 'tablepress' ),
36 'error_load_table' => __( 'Error: This table could not be loaded!', 'tablepress' ),
37 'error_table_corrupted' => __( 'Error: The internal data of this table is corrupted!', 'tablepress' ),
38 'error_create_zip_file' => __( 'Error: The ZIP file could not be created.', 'tablepress' ),
39 ) );
40
41 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
42 if ( 0 === $data['tables_count'] ) {
43 $this->add_meta_box( 'no-tables', __( 'Export Tables', 'tablepress' ), array( $this, 'postbox_no_tables' ), 'normal' );
44 } else {
45 $this->admin_page->enqueue_script( 'export', array( 'jquery' ) );
46 $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 }
50 }
51
52 /**
53 * Print the screen head text.
54 *
55 * @since 1.0.0
56 *
57 * @param array $data Data for this screen.
58 * @param array $box Information about the text box.
59 */
60 public function textbox_head( array $data, array $box ) {
61 ?>
62 <p>
63 <?php _e( 'Exporting a table allows you to use it in other programs, like spreadsheets applications.', 'tablepress' ); ?>
64 <?php _e( 'Regularly exporting tables is also recommended as a backup of your data.', 'tablepress' ); ?>
65 </p>
66 <p>
67 <?php _e( 'To export, select the tables and the desired export format.', 'tablepress' ); ?>
68 <?php _e( 'If you choose more than one table, the exported files will automatically be stored in a ZIP archive file.', 'tablepress' ); ?>
69 <br />
70 <?php _e( 'Be aware that for the CSV and HTML formats only the table data, but no table options are exported!', 'tablepress' ); ?>
71 <?php _e( 'For the JSON format, the table data and the table options are exported.', 'tablepress' ); ?>
72 </p>
73 <?php
74 }
75
76 /**
77 * Print the content of the "No tables found" 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_no_tables( array $data, array $box ) {
85 $add_url = TablePress::url( array( 'action' => 'add' ) );
86 $import_url = TablePress::url( array( 'action' => 'import' ) );
87 ?>
88 <p><?php _e( 'No tables found.', 'tablepress' ); ?></p>
89 <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>
90 <?php
91 }
92
93 /**
94 * Print the content of the "Export Tables" post meta box.
95 *
96 * @since 1.0.0
97 *
98 * @param array $data Data for this screen.
99 * @param array $box Information about the meta box.
100 */
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' );
183 }
184 ?>
185 </td>
186 </tr>
187 </tbody>
188 </table>
189 <?php
190 }
191
192 } // class TablePress_Export_View
193