PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.47
Code Manager v1.0.47
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 1 week ago Code_Manager_Dashboard.php 1 week ago Code_Manager_Export.php 1 week ago Code_Manager_Form.php 1 week ago Code_Manager_Import.php 1 week ago Code_Manager_Import_File.php 1 week ago Code_Manager_List.php 1 week ago Code_Manager_List_View.php 1 week ago Code_Manager_Model.php 1 week ago Code_Manager_Preview.php 1 week ago Code_Manager_Settings.php 1 week ago Code_Manager_Tabs.php 1 week ago Message_Box.php 1 week ago WP_List_Table.php 1 week ago
Code_Manager_Export.php
124 lines
1 <?php
2 /**
3 * Code Manager export code
4 *
5 * @package Code_Manager
6 */
7
8 namespace Code_Manager {
9
10 use PHPMailer\PHPMailer\Exception;
11
12 /**
13 * Class Code_Manager_Export
14 *
15 * Add export feature to plugin (reached from list table).
16 *
17 * @author Peter Schulz
18 * @since 1.0.0
19 */
20 class Code_Manager_Export {
21
22 /**
23 * Start code export
24 *
25 * @return void
26 */
27 public static function export() {
28 $wp_nonce = isset( $_REQUEST['wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpnonce'] ) ) : ''; // input var okay.
29 if ( ! wp_verify_nonce( $wp_nonce, 'code-manager-export' . Code_manager::get_current_user_login() ) ) {
30 wp_die( __( 'ERROR: Not authorized', 'code-manager' ) );
31 }
32 if ( isset( $_REQUEST['cid'] ) && is_array( $_REQUEST['cid'] ) ) {
33 self::export_rows( wp_unslash( $_REQUEST['cid'] ) );
34 }
35 }
36
37 /**
38 * Start export from ajax request
39 *
40 * @return void
41 */
42 public static function export_ajax() {
43 self::export();
44 wp_die();
45 }
46
47 /**
48 * Export table row = code block
49 *
50 * @param array $code_ids Array of code IDs.
51 * @return void
52 */
53 protected static function export_rows( $code_ids ) {
54 if ( defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
55 $wp_memory_limit = WP_MAX_MEMORY_LIMIT;
56 $current_memory_limit = @ini_get( 'memory_limit' );
57 if ( false === $current_memory_limit ||
58 self::convert_memory_to_decimal( $current_memory_limit ) <
59 self::convert_memory_to_decimal( $wp_memory_limit )
60 ) {
61 @ini_set( 'memory_limit', $wp_memory_limit );
62 }
63 }
64
65 header( 'Content-type: text/plain; charset=utf-8' );
66 header( "Content-Disposition: attachment; filename=code_manager_export.sql" );
67 header( 'Pragma: no-cache' );
68 header( 'Expires: 0' );
69
70 echo "--\n";
71 echo "-- Code Manager table export\n";
72 echo "-- Code IDs are not exported. New IDs are generated on import.\n";
73 echo "--\n";
74
75 $valid_ids = array(); // Hold sanitized array values.
76 $in_operator = ''; // Placeholders used for IN operator.
77 foreach ( $code_ids as $code_id ) {
78 $valid_ids[] = sanitize_text_field( wp_unslash( $code_id ) );
79 if ( '' !== $in_operator ) {
80 $in_operator .= ',';
81 }
82 $in_operator .= '%d';
83 }
84
85 global $wpdb;
86 $query = 'select * from ' . Code_Manager_Model::get_base_table_name() . " where code_id in ({$in_operator})";
87 $rows = $wpdb->get_results( $wpdb->prepare( $query, $valid_ids ), 'ARRAY_A' );
88
89 foreach ( $rows as $row ) {
90 $table_name = Code_Manager_Model::BASE_TABLE_NAME;
91 $code = str_replace( "\t", "\\t", $wpdb->remove_placeholder_escape( esc_sql( $row['code'] ) ) );
92 $code_description = str_replace( "\t", "\\t", $wpdb->remove_placeholder_escape( esc_sql( $row['code_description'] ) ) );
93 $insert =
94 "insert into {wp_prefix}{$table_name} " .
95 '(code_name, code_type, code, code_author, code_description) ' .
96 'values ' .
97 "('{$row['code_name']}','{$row['code_type']}','{$code}','{$row['code_author']}','{$code_description}');\n";
98
99 echo $insert;
100 }
101 }
102
103 /**
104 * Convert bytes to decimal
105 *
106 * @param string $memory_value Memory in G|M|K bytes.
107 * @return float|int|void
108 */
109 public static function convert_memory_to_decimal( $memory_value ) {
110 if ( preg_match( '/^(\d+)(.)$/', $memory_value, $matches ) ) {
111 if ( 'G' === $matches[2] ) {
112 return $matches[1] * 1024 * 1024 * 1024;
113 } elseif ( 'M' === $matches[2] ) {
114 return $matches[1] * 1024 * 1024;
115 } elseif ( 'K' === $matches[2] ) {
116 return $matches[1] * 1024;
117 }
118 }
119 }
120
121 }
122
123 }
124