PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.11
Code Manager v1.0.11
1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / Code_Manager / Code_Manager_Export.php
code-manager / Code_Manager Last commit date
Code_Manager.php 4 years ago Code_Manager_Dashboard.php 4 years ago Code_Manager_Export.php 4 years ago Code_Manager_Form.php 4 years ago Code_Manager_Import.php 4 years ago Code_Manager_Import_File.php 4 years ago Code_Manager_List.php 4 years ago Code_Manager_List_View.php 4 years ago Code_Manager_Model.php 4 years ago Code_Manager_Preview.php 4 years ago Code_Manager_Settings.php 4 years ago Code_Manager_Tabs.php 4 years ago Message_Box.php 4 years ago WP_List_Table.php 4 years ago
Code_Manager_Export.php
92 lines
1 <?php
2
3 namespace Code_Manager {
4
5 /**
6 * Class Code_Manager_Export
7 *
8 * Add export feature to plugin (reached from list table).
9 *
10 * @author Peter Schulz
11 * @since 1.0.0
12 */
13 class Code_Manager_Export {
14
15 public static function export() {
16 $wp_nonce = isset( $_REQUEST['wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpnonce'] ) ) : ''; // input var okay.
17 if ( ! wp_verify_nonce( $wp_nonce, 'code-manager-export' . Code_manager::get_current_user_login() ) ) {
18 wp_die( __( 'ERROR: Not authorized', 'code-manager' ) );
19 }
20
21 if ( isset( $_REQUEST['cid'] ) && is_array( $_REQUEST['cid'] ) ) {
22 $valid_ids = [];
23 foreach ( $_REQUEST['cid'] as $code_id ) {
24 if ( is_numeric( $code_id ) ) {
25 $valid_ids[] = $code_id;
26 }
27 }
28 self::export_rows( implode( ',', $valid_ids ) );
29 }
30 }
31
32 public static function export_ajax() {
33 self::export();
34 wp_die();
35 }
36
37 protected static function export_rows( $code_ids ) {
38 if ( defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
39 $wp_memory_limit = WP_MAX_MEMORY_LIMIT;
40 $current_memory_limit = @ini_set( 'memory_limit' );
41 if ( false === $current_memory_limit ||
42 self::convert_memory_to_decimal( $current_memory_limit ) <
43 self::convert_memory_to_decimal( $wp_memory_limit )
44 ) {
45 @ini_set( 'memory_limit', $wp_memory_limit );
46 }
47 }
48
49 header( 'Content-type: text/plain; charset=utf-8' );
50 header( "Content-Disposition: attachment; filename=code_manager_export.sql" );
51 header( 'Pragma: no-cache' );
52 header( 'Expires: 0' );
53
54 echo "--\n";
55 echo "-- Code Manager table export\n";
56 echo "-- Code IDs are not exported. New IDs are generated on import.\n";
57 echo "--\n";
58
59 global $wpdb;
60 $query = 'select * from ' . Code_Manager_Model::get_base_table_name() . ' ' .
61 "where code_id in ({$code_ids})";
62 $rows = $wpdb->get_results( $query, 'ARRAY_A' );
63
64 foreach ( $rows as $row ) {
65 $table_name = Code_Manager_Model::BASE_TABLE_NAME;
66 $code = str_replace( "\t", "\\t", $wpdb->remove_placeholder_escape( esc_sql( $row['code'] ) ) );
67 $code_description = str_replace( "\t", "\\t", $wpdb->remove_placeholder_escape( esc_sql( $row['code_description'] ) ) );
68 $insert =
69 "insert into {wp_prefix}{$table_name} " .
70 "(code_name, code_type, code, code_author, code_description) " .
71 "values " .
72 "('{$row['code_name']}','{$row['code_type']}','{$code}','{$row['code_author']}','{$code_description}');\n";
73
74 echo $insert;
75 }
76 }
77
78 public static function convert_memory_to_decimal( $memory_value ) {
79 if ( preg_match( '/^(\d+)(.)$/', $memory_value, $matches ) ) {
80 if ( $matches[2] == 'G' ) {
81 return $matches[1] * 1024 * 1024 * 1024;
82 } else if ( $matches[2] == 'M' ) {
83 return $matches[1] * 1024 * 1024;
84 } else if ( $matches[2] == 'K' ) {
85 return $matches[1] * 1024;
86 }
87 }
88 }
89
90 }
91
92 }