Skip to content

Commit 0de0dfd

Browse files
committed
Export Post Type now is json file :-)
1 parent ec1dec8 commit 0de0dfd

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

admin/mf_admin.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,30 @@ public function js_css_post($post_type){
320320
}
321321
}
322322

323-
public function import($file_path,$overwrite){
323+
public function import($file_data,$overwrite){
324+
325+
$file_path = $file_data['file']['tmp_name'];
326+
$data = "";
327+
$content = file_get_contents($file_path);
328+
if ( $file_data['file']['type'] == 'application/json') {
329+
//json
330+
$data = json_decode($content,true);
331+
if (!$data) {
332+
return;
333+
}
334+
} elseif ( $file_data['file']['type'] == 'application/octet-stream') {
335+
//pnl (serialize)
336+
if(!is_serialized($content)){
337+
return;
338+
}
339+
$data = unserialize($content);
340+
} else {
341+
return;
342+
}
324343

325-
$data = unserialize(file_get_contents($file_path));
344+
if ( !is_array($data) ) {
345+
return;
346+
}
326347

327348
$name = $data['name'];
328349
$post_type = $data['post_type'];

admin/mf_posttype.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,9 @@ public function export_post_type(){
883883
//post type
884884
$data['post_type'] = $p;
885885

886-
header('Content-type: binary');
887-
header('Content-Disposition: attachment; filename="'.$post_type.'.pnl"');
888-
print serialize($data);
886+
header('Content-type: application/javascript');
887+
header('Content-Disposition: attachment; filename="'.$post_type.'.json"');
888+
print json_encode($data);
889889
die;
890890
}
891891

@@ -942,7 +942,7 @@ public function upload_import_post_type(){
942942
if ($_FILES['file']['error'] == UPLOAD_ERR_OK){
943943
$file_path = $_FILES['file']['tmp_name'];
944944
$overwrite = $_POST['mf_post_type']['import']['overwrite'];
945-
$this->import($file_path,$overwrite);
945+
$this->import($_FILES,$overwrite);
946946
unlink($file_path);
947947
$this->mf_redirect(null,null,array('message' => 'success'));
948948
}else{

0 commit comments

Comments
 (0)