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
82 changes: 82 additions & 0 deletions admin/class-gdpr-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function add_menu() {
$icon_url = 'dashicons-id';

$requests = get_option( 'gdpr_requests', array() );

$confirmed_requests = array_filter(
$requests, function( $item ) {
return true === $item['confirmed'];
Expand Down Expand Up @@ -135,9 +136,16 @@ public function add_menu() {

$settings_hook = add_submenu_page( $parent_slug, $menu_title, $menu_title, $capability, $menu_slug, $function );

$menu_title = esc_html__( 'Export/Import', 'gdpr' );
$menu_slug = 'gdpr-export';
$function = array( $this, 'export_page_template' );

$export_hook = add_submenu_page( $parent_slug, $menu_title, $menu_title, $capability, $menu_slug, $function );

add_action( "load-{$requests_hook}", array( 'GDPR_Help', 'add_requests_help' ) );
add_action( "load-{$tools_hook}", array( 'GDPR_Help', 'add_tools_help' ) );
add_action( "load-{$settings_hook}", array( 'GDPR_Help', 'add_settings_help' ) );
add_action( "load-{$export_hook}", array( 'GDPR_Help', 'add_export_help' ) );
}

/**
Expand Down Expand Up @@ -514,6 +522,35 @@ public function audit_log() {
wp_send_json_success( $log );
}

/**
* Export/Import Pluging Settings Page Template
*
* @since 1.0.0
* @author Moutushi Mandal <moutushi82@gmail.com>
*/
public function export_page_template() {
global $wpdb;
$setting_data = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}options WHERE option_name like 'gdpr_%'", ARRAY_A );
$plugin_settings_json = array();
$option_data = array();

if ( ! empty ( $setting_data ) ) {
foreach ( $setting_data as $value ) {
$temp_arr = array();
$temp_arr['option_name'] = $value['option_name'];
$temp_arr['option_value'] = $value['option_value'];
$temp_arr['autoload'] = $value['autoload'];

$option_data[] = $temp_arr;
}
}
$encrypt_key = 'TrewK123456789';
$iv = openssl_random_pseudo_bytes( openssl_cipher_iv_length( 'aes-256-cbc' ) );
$encrypted_plugin_settings_data = openssl_encrypt( json_encode( $option_data ), 'aes-256-cbc', $encrypt_key, 0, $iv );
$gdpr_settings_data = base64_encode( $encrypted_plugin_settings_data . '::' . $iv );
include plugin_dir_path( __FILE__ ) . 'partials/import_export_settings.php';
}

public function review_settings_after_v2_notice() {
// Check the transient to see if we've just updated the plugin
if ( get_transient( 'gdpr_updated' ) && '2.0.0' === $this->version ) {
Expand Down Expand Up @@ -1010,4 +1047,49 @@ public function sort_logic_for_consents_from_user_table( $query ) {
}
}

/**
* Import plugin settings
* @since 1.0.0
* @author Moutushi Mandal <moutushi82@gmail.com>
*/
public function gdpr_import_plugin_settings() {
if ( ! isset( $_POST['gdpr_settings_import_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['gdpr_settings_import_nonce'] ), 'gdpr-import-settings' ) ) { // phpcs:ignore
wp_send_json_error( esc_html__( 'We could not verify the security token. Please try again.', 'gdpr' ) );
}
$settings_data = sanitize_text_field( wp_unslash( $_POST['import_settings'] ) );
if ( ! empty ( $settings_data ) ) {
list( $encrypted_data, $iv ) = explode( '::', base64_decode( $settings_data ), 2 );
$decrypted_plugin_settings = openssl_decrypt( $encrypted_data, 'aes-256-cbc', 'TrewK123456789', 0, $iv );
$plugin_settings_data = json_decode( $decrypted_plugin_settings );

if ( ! empty ( $plugin_settings_data ) ) {
foreach( $plugin_settings_data as $option_data ) {
$option_name = sanitize_text_field( wp_unslash( $option_data->option_name ) );

if ( is_serialized( $option_data->option_value ) ) {
$option_value = maybe_unserialize( $option_data->option_value );
} else {
$option_value = wp_filter_post_kses( $option_data->option_value );
}

$autoload = sanitize_text_field( wp_unslash( $option_data->autoload ) );
update_option( $option_name, $option_value, $autoload );
}
}

}
GDPR_Audit_Log::log( $user->ID, sprintf( esc_html__( 'Plugin settings imported on %1$s.', 'gdpr' ), date( 'm/d/Y' ) ) );
wp_safe_redirect(
esc_url_raw(
add_query_arg(
array(
'settings-imported' => true,
),
wp_get_referer() . '#import'
)
)
);
exit;
}

}
39 changes: 39 additions & 0 deletions admin/partials/import_export_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

$import_msg = '';
if ( ! empty ( $_GET['settings-imported'] ) && $_GET['settings-imported'] == 1 ) :
$import_msg = 'All settings imported successfully!';
endif;

?>
<div class="wrap gdpr">
<h1><?php esc_html_e( 'Export/Import', 'gdpr' ); ?></h1>
<?php settings_errors(); ?>
<div class="nav-tab-wrapper">
<a href="<?php echo esc_url( '#export' ); ?>" class="nav-tab"><?php echo esc_html__( 'Export', 'gdpr' ); ?></a>
<a href="<?php echo esc_url( '#import' ); ?>" class="nav-tab"><?php echo esc_html__( 'Import', 'gdpr' ); ?></a>
</div>

<div class="gdpr-tab hidden" data-id="export">
<h2><?php esc_html_e( 'Export Settings', 'gdpr' ); ?></h2>
<div class="inside">
<?php wp_nonce_field( 'gdpr-export-settings', 'gdpr_export_settings_nonce' ); ?>
<textarea id="gdpr_settings_data" name="export_settings" class="large-text" rows="30"><?php echo $gdpr_settings_data; ?></textarea>
<button class="button button-primary copy-settings"><?php esc_html_e( 'Copy', 'gdpr' ); ?></button>
<span class="spinner"></span>
</div>
</div>

<div class="gdpr-tab hidden" data-id="import">
<h2><?php esc_html_e( 'Import', 'gdpr' ); ?></h2>
<div class="gdpr-import-msg"><?php echo esc_html( $import_msg ); ?></div>
<form class="gdpr-import-settings-form" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
<?php wp_nonce_field( 'gdpr-import-settings', 'gdpr_settings_import_nonce' ); ?>
<input type="hidden" name="action" value="gdpr_import_settings">
<textarea id="import-settings" name="import_settings" class="large-text" rows="30"></textarea>
<?php submit_button( esc_html__( 'Import', 'gdpr' ), 'primary gdpr-import', '', false ); ?>
</form>
</div>
<!-- #poststuff -->
</div>

18 changes: 18 additions & 0 deletions includes/class-gdpr-help.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,22 @@ public static function add_settings_help() {
)
);
}

/**
* Add the export data page help tabs.
* @since 1.0.0
* @author Moutushi Mandal <moutushi82n@gmail.com>
* @static
*/
public static function add_export_help() {
$general_settings_help = '<h2>' . esc_html__( 'Export Data', 'gdpr' ) . '</h2>' .
'<p>' . esc_html__( 'Export plugin data.', 'gdpr' ) . '</p>';
get_current_screen()->add_help_tab(
array(
'id' => 'export_data',
'title' => esc_html__( 'Export Data', 'gdpr' ),
'content' => $general_export_data_help,
)
);
}
}
3 changes: 2 additions & 1 deletion includes/class-gdpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ private function define_admin_hooks() {
add_action( 'admin_post_gdpr_mark_resolved', array( $requests_admin, 'mark_resolved' ) );
add_action( 'wp_ajax_gdpr_anonymize_comments', array( $requests_admin, 'anonymize_comments' ) );
add_action( 'wp_ajax_gdpr_reassign_content', array( $requests_admin, 'reassign_content' ) );

add_action( 'admin_post_gdpr_import_settings', array( $plugin_admin, 'gdpr_import_plugin_settings' ) );

// CRON JOBS
add_action( 'clean_gdpr_requests', array( $requests, 'clean_requests' ) );
add_action( 'clean_gdpr_user_request_key', array( $requests, 'clean_user_request_key' ), 10, 2 );
Expand Down
10 changes: 10 additions & 0 deletions src/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,14 @@ $( function() {
);
} );

$( document ).on( 'click', '.copy-settings', function( e ) {
e.preventDefault();
$( '#gdpr_settings_data' ).select();

//$( '#gdpr_settings_data' ).setSelectionRange( 0, 99999 ); /*For mobile devices*/

/* Copy the text inside the text field */
document.execCommand( 'copy' );
});

} );
4 changes: 4 additions & 0 deletions src/scss/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,7 @@
}
}
}
.gdpr-import-msg{
padding: 13px 0;
font-size: 17px;
}