Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flowplayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
include_once(dirname( __FILE__ ) . '/models/conversion.php');
include_once(dirname( __FILE__ ) . '/models/email-subscription.php');

include_once(dirname( __FILE__ ) . '/models/import-export.php');


$fv_fp = new flowplayer_frontend();
Expand Down
103 changes: 103 additions & 0 deletions models/import-export.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

class FV_Player_Export_Import {

public function __construct() {
add_action('admin_init', array($this, 'init_options'));
add_action('admin_init', array($this, 'admin__add_meta_boxes'));
if (!empty($_GET['fv-settings-export']) && !empty($_GET['page']) && $_GET['page'] === 'fvplayer') {
add_action('admin_init', array($this, 'json_export'));
}
if (!empty($_GET['fv-settings-import']) && !empty($_GET['page']) && $_GET['page'] === 'fvplayer') {
if (isset($_FILES['fileToUpload']) && 0 !== $_FILES['fileToUpload']['size']) {
add_action('admin_init', array($this, 'json_import'));
}
}
}

public function init_options() {
return;
}

public function admin__add_meta_boxes() {
add_meta_box('fv_flowplayer_export_settings', __('Import settings', 'fv-wordpress-flowplayer'), array($this, 'import_box_admin'), 'fv_flowplayer_settings_exip', 'normal');
}

public function import_box_admin() {
?>
<table class="form-table2" style="margin: 5px; ">
<tr>
<td style="width: 160px"><?php _e('Import your settings', 'fv-wordpress-flowplayer'); ?>:</td>
</tr>
<tr>
<td>
<input type="file" id="fileToUpload" name="fileToUpload" />
<input type="submit" id="submitUpload" name="Upload File" value="Upload" style="cursor:pointer">
<p id="fileResult"></p>
</td>
</tr>

<script>
$('#submitUpload').click(function (event) {
event.preventDefault();
var file = $('#fileToUpload').get(0).files[0];
var formData = new FormData();
formData.append('fileToUpload', file);
formData.append("fv-settings-import", "complete");
$.ajax({
url: '<?php echo admin_url('options-general.php?page=fvplayer&fv-settings-import=all#postbox-container-tab_exip'); ?>',
beforeSend: function (e) {
alert('Are you sure you want to upload document.');
},
success: function (e) {
// console.log(e);
$("#fileResult").text("<?php _e('import completed successfully. I apply new settings ...', 'fv-wordpress-flowplayer'); ?>");
window.location.reload(this);
},
error: function (e) {
alert('error ' + e.message);
},
data: formData,
type: 'POST',
cache: false,
contentType: false,
processData: false
});
return false;
});
</script>
</table>
<?php
}

function json_export() {
$aLists = get_option('fvwpflowplayer');
$filename = 'export-fv-settings-' . date('Y-m-d') . '.json';
header('Content-Type: application/json');
header("Content-Disposition: attachment; filename=$filename");
header("Cache-Control: no-cache");
header("Expires: 0");

echo json_encode($aLists);

die;
}

function json_import() {
if (!current_user_can('manage_options')) {
return;
}
$extension = end(explode('.', $_FILES['fileToUpload']['name']));
if ($extension != 'json') {
wp_die(__('Please upload a valid .json file'));
}

$import_file = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
$settings = (array) json_decode($import_file, true);
//Update entire array
update_option('fvwpflowplayer', $settings);
}

}

$FV_Player_Export_Import = new FV_Player_Export_Import();
34 changes: 31 additions & 3 deletions view/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,8 @@ function fv_flowplayer_admin_interface_options() {
<?php $fv_fp->_get_checkbox(__('Subtitles', 'fv-wordpress-flowplayer'), array('interface', 'subtitles') ); ?>
<?php $fv_fp->_get_checkbox(__('Sticky', 'fv-wordpress-flowplayer'), array('interface', 'sticky') ); ?>
<?php $fv_fp->_get_checkbox(__('Video Actions', 'fv-wordpress-flowplayer'), array('interface', 'end_actions'), __('Enables end of playlist actions like Loop, Redirect, Show popup and Show splash screen', 'fv-wordpress-flowplayer') ); ?>

<?php do_action('fv_flowplayer_admin_interface_options_after'); ?>

<?php $fv_fp->_get_checkbox(__('Enable old interface', 'fv-wordpress-flowplayer'), array('interface', 'shortcode_editor_old'), __('Not recommended', 'fv-wordpress-flowplayer') ); ?>

<tr>
Expand Down Expand Up @@ -1333,6 +1332,32 @@ function fv_flowplayer_admin_usage() {
<?php
}

function fv_flowplayer_admin_description_imp_exp() {
?>
<table class="form-table">
<tr>
<td colspan="4">
<p><?php _e('You can export your player settings as an JSON file that you can later import into FV-player.', 'fv-wordpress-flowplayer'); ?></p>
<div class="clear"></div>
</td>
</tr>
</table>
<?php
}

function fv_flowplayer_admin_export() {
?>
<table class="form-table2" style="margin: 5px; ">
<tr>
<td style="width: 160px"><?php _e( 'Export your settings', 'fv-wordpress-flowplayer' ); ?>:</td>
<td>
<a class='fv-player-list-export' href='<?php echo admin_url( 'options-general.php?page=fvplayer&fv-settings-export=all' ); ?>' target="_blank" ><?php _e( 'Download JSON', 'fv-wordpress-flowplayer' ); ?></a>
<br />
</td>
</tr>
</table>
<?php
}

function fv_flowplayer_admin_checkbox( $name ) {
global $fv_fp;
Expand All @@ -1349,6 +1374,7 @@ function fv_flowplayer_admin_checkbox( $name ) {
array('id' => 'fv_flowplayer_settings_hosting', 'hash' => 'tab_hosting', 'name' => __('Hosting', 'fv-wordpress-flowplayer') ),
array('id' => 'fv_flowplayer_settings_actions', 'hash' => 'tab_actions', 'name' => __('Actions', 'fv-wordpress-flowplayer') ),
array('id' => 'fv_flowplayer_settings_video_ads', 'hash' => 'tab_video_ads', 'name' => __('Video Ads', 'fv-wordpress-flowplayer') ),
array('id' => 'fv_flowplayer_settings_exip', 'hash' => 'tab_exip', 'name' => __('Import / Export', 'fv-wordpress-flowplayer') ),
array('id' => 'fv_flowplayer_settings_help', 'hash' => 'tab_help', 'name' => __('Help', 'fv-wordpress-flowplayer') ),
);

Expand Down Expand Up @@ -1376,7 +1402,6 @@ function fv_flowplayer_admin_checkbox( $name ) {
add_meta_box( 'flowplayer-wrapper', __('Player Skin', 'fv-wordpress-flowplayer'), 'fv_flowplayer_admin_skin', 'fv_flowplayer_settings_skin', 'normal' );
add_meta_box( 'fv_flowplayer_skin_playlist', __('Playlist', 'fv-wordpress-flowplayer'), 'fv_flowplayer_admin_skin_playlist', 'fv_flowplayer_settings_skin', 'normal' );
add_meta_box( 'fv_flowplayer_skin_subtitles', __('Subtitles', 'fv-wordpress-flowplayer'), 'fv_flowplayer_admin_skin_subtitles', 'fv_flowplayer_settings_skin', 'normal' );
add_meta_box( 'fv_flowplayer_skin_sticky', __('Sticky Video', 'fv-wordpress-flowplayer'), 'fv_flowplayer_admin_skin_sticky', 'fv_flowplayer_settings_skin', 'normal' );

/* Hosting Tab */
add_meta_box( 'fv_flowplayer_description', ' ', 'fv_flowplayer_admin_description_hosting', 'fv_flowplayer_settings_hosting', 'normal', 'high' );
Expand All @@ -1393,6 +1418,9 @@ function fv_flowplayer_admin_checkbox( $name ) {
add_meta_box( 'fv_flowplayer_description', ' ', 'fv_flowplayer_admin_description_video_ads', 'fv_flowplayer_settings_video_ads', 'normal', 'high' );
add_meta_box( 'fv_flowplayer_ads', __('Video Ads', 'fv-wordpress-flowplayer'), 'fv_flowplayer_admin_video_ads', 'fv_flowplayer_settings_video_ads', 'normal' );
}
/* Import Export tab */
add_meta_box( 'fv_flowplayer_description_imp_exp', ' ', 'fv_flowplayer_admin_description_imp_exp', 'fv_flowplayer_settings_exip', 'normal', 'high' );
add_meta_box( 'fv_flowplayer_export', __('Export settings', 'fv-wordpress-flowplayer'), 'fv_flowplayer_admin_export', 'fv_flowplayer_settings_exip', 'normal', 'high' );

/* Help tab */
add_meta_box( 'fv_flowplayer_usage', __('Usage', 'fv-wordpress-flowplayer'), 'fv_flowplayer_admin_usage', 'fv_flowplayer_settings_help', 'normal', 'high' );
Expand Down