PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 2.0.1
Admin Columns v2.0.1
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / export_import.php
codepress-admin-columns / classes Last commit date
column 12 years ago storage_model 12 years ago api.php 12 years ago column.php 12 years ago deprecated.php 12 years ago export_import.php 12 years ago settings.php 12 years ago storage_model.php 12 years ago third_party.php 12 years ago upgrade.php 12 years ago utility.php 12 years ago
export_import.php
180 lines
1 <?php
2
3 /**
4 * CPAC_Export_Import Class
5 *
6 * @since 1.4.6.5
7 *
8 */
9 class CPAC_Export_Import {
10
11 private $cpac;
12
13 /**
14 * Constructor
15 *
16 * @since 1.4.6.5
17 */
18 function __construct( $cpac ) {
19
20 $this->cpac = $cpac;
21
22 add_action( 'admin_init', array( $this, 'download_export' ) );
23 add_action( 'admin_init', array( $this, 'handle_file_import' ) );
24 }
25
26 /**
27 * Get export string
28 *
29 * @since 2.0.0
30 */
31 function get_export_string( $types = array() ) {
32
33 if ( empty( $types ) )
34 return false;
35
36 $columns = array();
37
38 // get stored columns
39 foreach ( $this->cpac->storage_models as $storage_model ) {
40
41 if ( ! in_array( $storage_model->key, $types ) )
42 continue;
43
44 $columns[ $storage_model->key ] = $storage_model->get_stored_columns();
45 }
46
47 if ( empty( $columns ) )
48 return false;
49
50 return "<!-- START: Admin Columns export -->\n" . base64_encode( serialize( array_filter( $columns ) ) ) . "\n<!-- END: Admin Columns export -->";
51 }
52
53 /**
54 * Download Export
55 *
56 * @since 2.0.0
57 */
58 function download_export() {
59 if ( ! isset( $_REQUEST['_cpac_nonce'] ) || ! wp_verify_nonce( $_REQUEST['_cpac_nonce'], 'download-export' ) )
60 return false;
61
62 if ( empty( $_REQUEST['export_types'] ) ) {
63
64 cpac_admin_message( __( 'Export field is empty. Please select your types from the left column.', 'cpac' ), 'error' );
65
66 return false;
67 }
68
69 $single_type = '';
70 if ( 1 == count( $_REQUEST['export_types'] ) ) {
71 $single_type = '_' . $_REQUEST['export_types'][0];
72 }
73
74 $filename = 'admin-columns-export_' . date('Y-m-d', time() ) . $single_type;
75
76 // generate text file
77 header( "Content-disposition: attachment; filename={$filename}.txt" );
78 header( 'Content-type: text/plain' );
79 echo $this->get_export_string( $_REQUEST['export_types'] );
80 exit;
81 }
82
83 /**
84 * Handle file import
85 *
86 * @uses wp_import_handle_upload()
87 * @since 2.0.0
88 */
89 function handle_file_import() {
90 if ( ! isset( $_REQUEST['_cpac_nonce'] ) || ! wp_verify_nonce( $_REQUEST['_cpac_nonce'], 'file-import' ) || empty( $_FILES['import'] ) )
91 return false;
92
93 // handles upload
94 $file = wp_import_handle_upload();
95
96 // any errors?
97 $error = false;
98 if ( isset( $file['error'] ) ) {
99 $error = __( 'Sorry, there has been an error.', 'cpac' ) . '<br />' . esc_html( $file['error'] );
100 } else if ( ! file_exists( $file['file'] ) ) {
101 $error = __( 'Sorry, there has been an error.', 'cpac' ) . '<br />' . sprintf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'cpac' ), esc_html( $file['file'] ) );
102 }
103
104 if ( $error ) {
105 cpac_admin_message( $error, 'error' );
106
107 return false;
108 }
109 // read file contents and start the import
110 $content = file_get_contents( $file['file'] );
111
112 // cleanup
113 wp_delete_attachment( $file['id'] );
114
115 // decode file contents
116 $columns = $this->get_decoded_settings( $content );
117
118 if ( ! $columns ) {
119 cpac_admin_message( __( 'Import failed. File does not contain Admin Column settings.', 'cpac' ), 'error' );
120 return false;
121 }
122
123 // store settings
124 foreach( $columns as $type => $cols ) {
125
126 $storage_model = $this->cpac->get_storage_model( $type );
127 $storage_model->store( $cols );
128 }
129 }
130
131 /**
132 * Get decoded settings
133 *
134 * @since 2.0.0
135 *
136 * @param string $encoded_string
137 * @return array Columns
138 */
139 function get_decoded_settings( $encoded_string = '' ) {
140 if( ! $encoded_string || ! is_string( $encoded_string ) || strpos( $encoded_string, '<!-- START: Admin Columns export -->' ) === false )
141 return false;
142
143 // decode
144 $encoded_string = str_replace( "<!-- START: Admin Columns export -->\n", "", $encoded_string );
145 $encoded_string = str_replace( "\n<!-- END: Admin Columns export -->", "", $encoded_string);
146 $decoded = maybe_unserialize( base64_decode( trim( $encoded_string ) ) );
147
148 if ( empty( $decoded ) || ! is_array( $decoded ) )
149 return false;
150
151 return $decoded;
152 }
153
154 /**
155 * Update settings
156 *
157 * @since 2.0.0
158 *
159 * @param array $columns Columns
160 * @return bool
161 */
162 function update_settings( $columns ) {
163 $options = get_option( 'cpac_options' );
164
165 // merge saved setting if they exist..
166 if ( ! empty( $options['columns'] ) ) {
167 $options['columns'] = array_merge( $options['columns'], $columns );
168 }
169
170 // .. if there are no setting yet use the import
171 else {
172 $options = array(
173 'columns' => $columns
174 );
175 }
176
177 return update_option( 'cpac_options', array_filter( $options ) );
178 }
179 }
180