| 1 |
<?php |
| 2 |
/** |
| 3 |
* Javascript to import and export AO CCSS settings. |
| 4 |
*/ |
| 5 |
|
| 6 |
?> |
| 7 |
// Export and download settings |
| 8 |
function exportSettings( idToEdit ) { |
| 9 |
console.log('Exporting...'); |
| 10 |
var data = { |
| 11 |
'action': 'ao_ccss_export', |
| 12 |
'ao_ccss_export_nonce': '<?php echo wp_create_nonce( 'ao_ccss_export_nonce' ); ?>', |
| 13 |
}; |
| 14 |
|
| 15 |
jQuery.post(ajaxurl, data, function(response) { |
| 16 |
response_array=JSON.parse(response); |
| 17 |
if (response_array['code'] == 200) { |
| 18 |
<?php |
| 19 |
if ( is_multisite() ) { |
| 20 |
$blog_id = '/' . get_current_blog_id() . '/'; |
| 21 |
} else { |
| 22 |
$blog_id = '/'; |
| 23 |
} |
| 24 |
?> |
| 25 |
export_url = '<?php echo content_url(); ?>/uploads/ao_ccss' + '<?php echo $blog_id; ?>' + response_array['file']; |
| 26 |
msg = "Download export-file from: <a href=\"" + export_url + "\" target=\"_blank\">"+ export_url + "</a>"; |
| 27 |
} else { |
| 28 |
msg = response_array['msg']; |
| 29 |
} |
| 30 |
jQuery("#importdialog").html(msg); |
| 31 |
jQuery("#importdialog").dialog({ |
| 32 |
autoOpen: true, |
| 33 |
height: 210, |
| 34 |
width: 700, |
| 35 |
title: "<?php _e( 'Export settings result', 'autoptimize' ); ?>", |
| 36 |
modal: true, |
| 37 |
buttons: { |
| 38 |
OK: function() { |
| 39 |
jQuery( this ).dialog( "close" ); |
| 40 |
} |
| 41 |
} |
| 42 |
}); |
| 43 |
}); |
| 44 |
} |
| 45 |
|
| 46 |
// Upload and import settings |
| 47 |
function upload(){ |
| 48 |
var fd = new FormData(); |
| 49 |
var file = jQuery(document).find('#settingsfile'); |
| 50 |
var settings_file = file[0].files[0]; |
| 51 |
fd.append('file', settings_file); |
| 52 |
fd.append('action', 'ao_ccss_import'); |
| 53 |
fd.append('ao_ccss_import_nonce', '<?php echo wp_create_nonce( 'ao_ccss_import_nonce' ); ?>'); |
| 54 |
|
| 55 |
jQuery.ajax({ |
| 56 |
url: ajaxurl, |
| 57 |
type: 'POST', |
| 58 |
data: fd, |
| 59 |
contentType: false, |
| 60 |
processData: false, |
| 61 |
success: function(response) { |
| 62 |
response_array=JSON.parse(response); |
| 63 |
if (response_array['code'] == 200) { |
| 64 |
window.location.reload(); |
| 65 |
} |
| 66 |
} |
| 67 |
}); |
| 68 |
} |
| 69 |
|