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

128 lines 4.7 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<string, mixed> $data Data for this view.
31 */
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
36 parent::setup( $action, $data );
37
38 $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' );
39
40 $this->process_action_messages( array(
41 'error_export' => __( 'Error: The export failed.', 'tablepress' ),
42 'error_load_table' => __( 'Error: This table could not be loaded!', 'tablepress' ),
43 'error_table_corrupted' => __( 'Error: The internal data of this table is corrupted!', 'tablepress' ),
44 'error_create_zip_file' => __( 'Error: The ZIP file could not be created.', 'tablepress' ),
45 ) );
46
47 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
48 if ( 0 === $data['tables_count'] ) {
49 $this->add_meta_box( 'no-tables', __( 'Export Tables', 'tablepress' ), array( $this, 'postbox_no_tables' ), 'normal' );
50 } else {
51 $this->admin_page->enqueue_script( 'export' );
52 $this->add_meta_box( 'export-form', __( 'Export Tables', 'tablepress' ), array( $this, 'postbox_export_form' ), 'normal' );
53 }
54 }
55
56 /**
57 * Prints the screen head text.
58 *
59 * @since 1.0.0
60 *
61 * @param array<string, mixed> $data Data for this screen.
62 * @param array<string, mixed> $box Information about the text box.
63 */
64 public function textbox_head( array $data, array $box ): void {
65 ?>
66 <p>
67 <?php _e( 'Exporting a table allows you to use it in other programs, like spreadsheets applications.', 'tablepress' ); ?>
68 <?php _e( 'Regularly exporting tables is also recommended as a backup of your data.', 'tablepress' ); ?>
69 </p>
70 <p>
71 <?php _e( 'To export, select the tables and the desired export format.', 'tablepress' ); ?>
72 <?php _e( 'If you choose more than one table, the exported files will automatically be stored in a ZIP archive file.', 'tablepress' ); ?>
73 <br>
74 <?php _e( 'Be aware that for the CSV and HTML formats only the table data, but no table options are exported!', 'tablepress' ); ?>
75 <?php _e( 'For the JSON format, the table data and the table options are exported.', 'tablepress' ); ?>
76 </p>
77 <?php
78 }
79
80 /**
81 * Prints the content of the "No tables found" post meta box.
82 *
83 * @since 1.0.0
84 *
85 * @param array<string, mixed> $data Data for this screen.
86 * @param array<string, mixed> $box Information about the meta box.
87 */
88 public function postbox_no_tables( array $data, array $box ): void {
89 $add_url = TablePress::url( array( 'action' => 'add' ) );
90 $import_url = TablePress::url( array( 'action' => 'import' ) );
91 ?>
92 <p><?php _e( 'No tables found.', 'tablepress' ); ?></p>
93 <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>
94 <?php
95 }
96
97 /**
98 * Prints the content of the "Export Tables" post meta box.
99 *
100 * @since 1.0.0
101 *
102 * @param array<string, mixed> $data Data for this screen.
103 * @param array<string, mixed> $box Information about the meta box.
104 */
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";
121 }
122 echo "</script>\n";
123
124 echo '<div id="tablepress-export-screen"></div>';
125 }
126
127 } // class TablePress_Export_View
128