. * * @package ReduxFramework * @subpackage field_import_export * @author Dovy Paukstys * @author Kevin Provance (kprovance) * @version 3.1.8 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } if ( ! class_exists( 'Redux_import_export' ) ) { /** * Main ReduxFramework_import_export class * * @since 1.0.0 */ class Redux_import_export { public $is_field = false; public $field_args = array(); public function __construct( $parent ) { $this->parent = $parent; add_action( "wp_ajax_redux_link_options", array( $this, "link_options" ) ); add_action( "wp_ajax_nopriv_redux_link_options", array( $this, "link_options" ) ); add_action( "wp_ajax_redux_download_options", array( $this, "download_options" ) ); add_action( "wp_ajax_nopriv_redux_download_options", array( $this, "download_options" ) ); } /** * Field Render Function. * Takes the vars and outputs the HTML for the field in the settings * * @since 1.0.0 * @access public * @return void */ public function render() { $secret = md5( md5( AUTH_KEY . SECURE_AUTH_KEY ) . '-' . $this->parent->args['opt_name'] ); if ( true == $this->is_field ) { $fullWidth = $this->field_args['full_width']; } $c = ''; $bDoClose = false; if ( false == $this->is_field ) { $c = 'redux-group-tab hide'; } elseif ( true == $this->is_field && false == $fullWidth ) { echo '
'; $bDoClose = true; } echo '
'; if ( false == $this->is_field ) { echo '

' . __( 'Import / Export Options', 'redux-framework' ) . '

'; } echo '

' . __( 'Import Options', 'redux-framework' ) . '

'; echo '

' . __( 'Import from file', 'redux-framework' ) . ' ' . __( 'Import from URL', 'redux-framework' ) . '

'; echo '
'; echo '

' . apply_filters( 'redux-import-file-description', __( 'Input your backup file below and hit Import to restore your sites options from a backup.', 'redux-framework' ) ) . '

'; echo ''; echo '
'; echo ''; echo '

  ' . apply_filters( 'redux-import-warning', __( 'WARNING! This will overwrite all existing option values, please proceed with caution!', 'redux-framework' ) ) . '

'; echo '
 
'; echo '

' . __( 'Export Options', 'redux-framework' ) . '

'; echo '
'; echo '

' . apply_filters( 'redux-backup-description', __( 'Here you can copy/download your current option settings. Keep this safe as you can use it as a backup should anything go wrong, or you can use it to restore your settings on this site (or any other site).', 'redux-framework' ) ) . '

'; echo '
'; $link = admin_url( 'admin-ajax.php?action=redux_download_options&secret=' . $secret ); echo '

' . __( 'Copy', 'redux-framework' ) . ' ' . __( 'Download', 'redux-framework' ) . ' ' . __( 'Copy Link', 'redux-framework' ) . '

'; $backup_options = $this->parent->options; $backup_options['redux-backup'] = '1'; echo "

"; echo ''; $link = admin_url( 'admin-ajax.php?action=redux_link_options&secret=' . $secret ); echo ''; echo "

"; echo '
'; if ( true == $bDoClose ) { echo '
'; } } public function in_field() { $this->is_field = Redux_Helpers::isFieldInUse( $this->parent, 'import_export' ); } public function render_tab() { echo ''; echo '
  •  
  • '; } public function add_submenu() { add_theme_page( $this->parent->args['page_slug'], __( 'Import / Export', 'redux-framework' ), __( 'Import / Export', 'redux-framework' ), $this->parent->args['page_permissions'], $this->parent->args['page_slug'] . '&tab=import_export_default', '__return_null' ); } public function enqueue() { wp_enqueue_script( 'redux-field-import-export-js', ReduxFramework::$_url . 'assets/js/import_export/import_export' . Redux_Functions::isMin() . '.js', array( 'jquery', 'redux-js' ), time(), true ); wp_enqueue_style( 'redux-field-import-export-css', ReduxFramework::$_url . 'assets/css/import_export/import_export.css', time(), true ); } function link_options() { if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != md5( md5( AUTH_KEY . SECURE_AUTH_KEY ) . '-' . $this->parent->args['opt_name'] ) ) { wp_die( 'Invalid Secret for options use' ); exit; } $var = $this->parent->options; $var['redux-backup'] = '1'; if ( isset( $var['REDUX_imported'] ) ) { unset( $var['REDUX_imported'] ); } echo json_encode( $var ); die(); } public function download_options() { if ( ! isset( $_GET['secret'] ) || $_GET['secret'] != md5( md5( AUTH_KEY . SECURE_AUTH_KEY ) . '-' . $this->parent->args['opt_name'] ) ) { wp_die( 'Invalid Secret for options use' ); exit; } $this->parent->get_options(); $backup_options = $this->parent->options; $backup_options['redux-backup'] = '1'; if ( isset( $var['REDUX_imported'] ) ) { unset( $var['REDUX_imported'] ); } $content = json_encode( $backup_options ); if ( isset( $_GET['action'] ) && $_GET['action'] == 'redux_download_options' ) { header( 'Content-Description: File Transfer' ); header( 'Content-type: application/txt' ); header( 'Content-Disposition: attachment; filename="redux_options_' . $this->parent->args['opt_name'] . '_backup_' . date( 'd-m-Y' ) . '.json"' ); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate' ); header( 'Pragma: public' ); echo $content; exit; } else { header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); header( 'Cache-Control: no-store, no-cache, must-revalidate' ); header( 'Cache-Control: post-check=0, pre-check=0', false ); header( 'Pragma: no-cache' ); // Can't include the type. Thanks old Firefox and IE. BAH. //header("Content-type: application/json"); echo $content; exit; } } } }