first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
<?php
/**
* Base class for caching method. All caching methods must be extends from this class.
* All methods are required for child classes
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Cache_Handler' ) ) {
/**
* Define Jet_Data_Importer_Cache_Handler class
*/
class Jet_Data_Importer_Cache_Handler {
/**
* Store passed value in cache with passed key.
*
* @param string $key Caching key.
* @param mixed $value Value to save.
* @param string $group Caching group.
* @return bool
*/
public function update( $key = null, $value = null, $group = 'global' ) {}
/**
* Create base caching group if not exist.
*/
public function setup_cahe() {}
/**
* Create new group in base caching group if not exists
*/
public function setup_cahe_group( $group = 'global' ) {}
/**
* Returns all stored cache
*
* @return array
*/
public function get_all() {}
/**
* Returns whole stored group
*
* @return array
*/
public function get_group( $group = 'global' ) {}
/**
* Returns whole stored group
*
* @return void
*/
public function clear_cache( $group = null ) {}
/**
* Returns current value by key
*
* @return array
*/
public function get( $key = null, $group = 'global' ) {}
/**
* Write object cahe to static cache (if current handler requires this)
*
* @return void
*/
public function write_cache() {}
}
}

View File

@@ -0,0 +1,156 @@
<?php
/**
* Base class for caching method. All caching methods must be extends from this class.
* All methods are required for child classes
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_File_Cache' ) ) {
/**
* Define Jet_Data_Importer_File_Cache class
*/
class Jet_Data_Importer_File_Cache extends Jet_Data_Importer_Cache_Handler {
private $_object_cache = null;
private $_updated = false;
/**
* Store passed value in cache with passed key.
*
* @param string $key Caching key.
* @param mixed $value Value to save.
* @param string $group Caching group.
* @return bool
*/
public function update( $key = null, $value = null, $group = 'global' ) {
$this->setup_cache_group( $group );
$this->_object_cache[ $group ][ $key ] = $value;
$this->_updated = true;
}
/**
* Returns all stored cache
*
* @return array
*/
public function get_all() {
if ( ! $this->_object_cache ) {
return array();
} else {
$this->_object_cache;
}
}
/**
* Returns whole stored group
*
* @return array
*/
public function get_group( $group = 'global' ) {
$this->setup_cache_group( $group );
if ( ! isset( $this->_object_cache[ $group ] ) ) {
return array();
}
return $this->_object_cache[ $group ];
}
/**
* Returns current value by key
*
* @return array
*/
public function get( $key = null, $group = 'global' ) {
$this->setup_cache_group( $group );
if ( ! isset( $this->_object_cache[ $group ] ) ) {
return false;
}
if ( ! isset( $this->_object_cache[ $group ][ $key ] ) ) {
return false;
}
return $this->_object_cache[ $group ][ $key ];
}
/**
* Create base caching group if not exist.
*/
public function setup_cache() {
if ( null === $this->_object_cache ) {
$current = jdi_files_manager()->get_json( 'cache.json' );
if ( ! $current ) {
$this->_object_cache = array();
} else {
$this->_object_cache = $current;
}
}
}
/**
* Create new group in base caching group if not exists
*/
public function setup_cache_group( $group = 'global' ) {
$this->setup_cache();
if ( ! isset( $this->_object_cache[ $group ] ) ) {
$this->_object_cache[ $group ] = array();
}
}
/**
* Returns whole stored group
*
* @return void
*/
public function clear_cache( $group = null ) {
if ( isset( $this->_object_cache['mapping'] ) ) {
update_option( 'cache', $this->_object_cache['mapping'] );
}
if ( null !== $group ) {
$this->_object_cache[ $group ] = array();
jdi_files_manager()->write_cache();
} else {
$this->_object_cache = array();
jdi_files_manager()->delete( 'cache.json' );
}
}
/**
* Write static cache
*
* @return [type] [description]
*/
public function write_cache() {
if ( true === $this->_updated ) {
jdi_files_manager()->put_json( 'cache.json', $this->_object_cache );
}
}
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* Seesion cahce handler
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Session_Cache' ) ) {
/**
* Define Jet_Data_Importer_Session_Cache class
*/
class Jet_Data_Importer_Session_Cache extends Jet_Data_Importer_Cache_Handler {
/**
* Base caching group name
*
* @var string
*/
private $base_group = null;
/**
* Constructor for the class
*/
public function __construct( $base_group ) {
$this->base_group = $base_group;
}
/**
* Store passed value in cache with passed key.
*
* @param string $key Caching key.
* @param mixed $value Value to save.
* @param string $group Caching group.
* @return bool
*/
public function update( $key = null, $value = null, $group = 'global' ) {
$this->setup_cahe_group( $group );
$_SESSION[ $this->base_group ][ $group ][ $key ] = $value;
}
/**
* Returns all stored cache
*
* @return array
*/
public function get_all() {
if ( ! isset( $_SESSION[ $this->base_group ] ) ) {
return array();
}
}
/**
* Returns whole stored group
*
* @return array
*/
public function get_group( $group = 'global' ) {
if ( ! isset( $_SESSION[ $this->base_group ][ $group ] ) ) {
return array();
}
return $_SESSION[ $this->base_group ][ $group ];
}
/**
* Returns current value by key
*
* @return array
*/
public function get( $key = null, $group = 'global' ) {
if ( ! isset( $_SESSION[ $this->base_group ][ $group ] ) ) {
return false;
}
if ( ! isset( $_SESSION[ $this->base_group ][ $group ][ $key ] ) ) {
return false;
}
return $_SESSION[ $this->base_group ][ $group ][ $key ];
}
/**
* Create base caching group if not exist.
*/
public function setup_cahe() {
if ( ! isset( $_SESSION[ $this->base_group ] ) ) {
$_SESSION[ $this->base_group ] = array();
}
}
/**
* Create new group in base caching group if not exists
*/
public function setup_cahe_group( $group = 'global' ) {
$this->setup_cahe();
if ( ! isset( $_SESSION[ $this->base_group ][ $group ] ) ) {
$_SESSION[ $this->base_group ][ $group ] = array();
}
}
/**
* Returns whole stored group
*
* @return void
*/
public function clear_cache( $group = null ) {
if ( isset( $_SESSION[ $this->base_group ]['mapping'] ) ) {
update_option( 'cache', $_SESSION[ $this->base_group ]['mapping'] );
}
if ( null !== $group ) {
$_SESSION[ $this->base_group ][ $group ] = array();
} else {
$_SESSION[ $this->base_group ] = array();
}
}
}
}

View File

@@ -0,0 +1,199 @@
<?php
/**
* Data cache handler
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Cache' ) ) {
/**
* Define Jet_Data_Importer_Cache class
*/
class Jet_Data_Importer_Cache {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Import data caching metod.
*
* @var string
*/
private $caching_method = 'session';
/**
* Active cache handler instance
*
* @var null
*/
private $handler = null;
/**
* Registered cache handlers array
*
* @var array
*/
private $handlers = array();
/**
* Base caching group name
*
* @var string
*/
public $base_group = 'jet-importer';
/**
* Constructor for the class
*/
public function __construct() {
$this->handlers = array(
'session' => 'Jet_Data_Importer_Session_Cache',
'file' => 'Jet_Data_Importer_File_Cache',
);
require_once jdi()->path( 'includes/cache-handlers/class-jet-data-importer-cache-handler.php' );
$method = $this->get_caching_method();
if ( isset( $this->handlers[ $method ] ) ) {
$handler = $this->handlers[ $method ];
} else {
$handler = 'Jet_Data_Importer_Session_Cache';
}
$file = $this->get_file_name( $handler );
require_once jdi()->path( 'includes/cache-handlers/' . $file );
$this->handler = new $handler( $this->base_group );
}
/**
* Returns handler file name by class name.
*
* @param string $handler Handler class name.
* @return string
*/
private function get_file_name( $handler ) {
$file = str_replace( '_', ' ', $handler );
$file = strtolower( $file );
$file = str_replace( ' ', '-', $file );
return sprintf( 'class-%s.php', $file );
}
/**
* Returns appropriate caching method for current server/
*
* @return string
*/
private function get_caching_method() {
if ( ! session_id() ) {
$this->caching_method = 'file';
} else {
$this->caching_method = 'session';
}
$cache_handler = get_option( 'jdi_cache_handler', 'session' );
if ( $cache_handler ) {
$this->caching_method = $cache_handler;
}
return $this->caching_method;
}
/**
* Store passed value in cache with passed key.
*
* @param string $key Caching key.
* @param mixed $value Value to save.
* @param string $group Caching group.
* @return bool
*/
public function update( $key = null, $value = null, $group = 'global' ) {
$this->handler->update( $key, $value, $group );
}
/**
* Get value from cache by key.
*
* @param string $key Caching key.
* @param string $group Caching group.
* @return bool
*/
public function get( $key = null, $group = 'global' ) {
return $this->handler->get( $key, $group );
}
/**
* Get all group values from cache by group name.
*
* @param string $group Caching group.
* @return bool
*/
public function get_group( $group = 'global' ) {
return $this->handler->get_group( $group );
}
/**
* Clear cache for passed group or all cache if group not provided.
*
* @param string $group Caching group to clear.
* @return bool
*/
public function clear_cache( $group = null ) {
return $this->handler->clear_cache( $group );
}
/**
* Write object cahce to static.
*
* @param string $group Caching group to clear.
* @return bool
*/
public function write_cache() {
return $this->handler->write_cache();
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Data_Importer_Cache
*
* @return object
*/
function jdi_cache() {
return Jet_Data_Importer_Cache::get_instance();
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* Files manager
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Files_Manager' ) ) {
/**
* Define Jet_Data_Importer_Files_Manager class
*/
class Jet_Data_Importer_Files_Manager {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Data inmporter file manager base path
* @var [type]
*/
private $base_path = false;
/**
* Returns base path
*
* @return string
*/
public function base_path() {
if ( ! $this->base_path ) {
$upload_dir = wp_upload_dir();
$upload_base_dir = $upload_dir['basedir'];
$this->base_path = trailingslashit( $upload_base_dir ) . 'jet-skins/';
if ( ! is_dir( $this->base_path ) ) {
mkdir( $this->base_path );
}
}
return $this->base_path;
}
/**
* Returns base path
*
* @return string
*/
public function put_json( $relative_path = null, $data = '' ) {
file_put_contents( $this->base_path() . $relative_path, json_encode( $data ) );
}
/**
* Returns base path
*
* @return string|bool
*/
public function get_json( $relative_path = null ) {
$file = $this->base_path() . $relative_path;
if ( ! is_file( $file ) ) {
return false;
}
ob_start();
include $file;
$content = ob_get_clean();
return json_decode( $content, true );
}
/**
* Delete file if exists
*
* @param [type] $relative_path [description]
* @return [type] [description]
*/
public function delete( $relative_path = null ) {
$file = $this->base_path() . $relative_path;
if ( is_file( $file ) ) {
unlink( $file );
}
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Data_Importer_Files_Manager
*
* @return object
*/
function jdi_files_manager() {
return Jet_Data_Importer_Files_Manager::get_instance();
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* Logger class
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Logger' ) ) {
/**
* Define Jet_Data_Importer_Logger class
*/
class Jet_Data_Importer_Logger {
/**
* Add warning message into log.
*
* @param string $message Log message.
* @return void
*/
public function warning( $message = null ) {
$this->add_message( $message, 'warnings' );
}
/**
* Add info message into log.
*
* @param string $message Log message.
* @return void
*/
public function info( $message = null ) {
$this->add_message( $message, 'info' );
}
/**
* Add notice message into log.
*
* @param string $message Log message.
* @return void
*/
public function notice( $message = null ) {
$this->add_message( $message, 'notice' );
}
/**
* Add debug message into log.
*
* @param string $message Log message.
* @return void
*/
public function debug( $message = null ) {
$this->add_message( $message, 'debug' );
}
/**
* Add error message into log.
*
* @param string $message Log message.
* @return void
*/
public function error( $message = null ) {
$this->add_message( $message, 'error' );
}
/**
* Add passed message into passed log group.
*
* @param string $message Log message.
* @param string $type Message type.
* @return void
*/
public function add_message( $message = null, $type = 'info' ) {
$messages = jdi_cache()->get( $type, 'log' );
if ( empty( $messages ) || ! is_array( $messages ) ) {
$messages = array();
}
$messages[] = $message;
jdi_cache()->update( $type, $messages, 'log' );
}
}
}

View File

@@ -0,0 +1,193 @@
<?php
/**
* Import page slider
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Slider' ) ) {
/**
* Define Jet_Data_Importer_Slider class
*/
class Jet_Data_Importer_Slider {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Slides list
*
* @var array
*/
private $slides = null;
/**
* Slider data
*
* @var array
*/
private $data = null;
/**
* Constructor for the class
*/
function __construct() {
$slider_data = jdi()->get_setting( array( 'slider' ) );
if ( empty( $slider_data ) || empty( $slider_data['path'] ) ) {
return;
}
$this->data = $slider_data;
if ( ! $this->get_slides() ) {
return;
}
}
/**
* Enqueue slider assets
*
* @return void
*/
public function slider_assets() {
wp_enqueue_script(
'swiper-jquery',
jdi()->url( 'assets/js/swiper.min.js' ),
array( 'jquery' ),
'2.0.0',
true
);
}
/**
* Render slider
*
* @return string|void
*/
public function render( $echo = true ) {
$slides = $this->get_slides();
if ( empty( $slides ) ) {
return;
}
$format = '<div class="swiper-slide">
<div class="slider-content">
<img src="%1$s" alt="" data-swiper-parallax="-100">
<h4 class="slider-title" data-swiper-parallax="-400">%2$s</h4>
<div class="slider-desc" data-swiper-parallax="-900">%3$s</div>
</div>
</div>';
$result = '';
foreach ( $slides as $slide ) {
$url = ! empty( $slide['image'] ) ? esc_url( $slide['image'] ) : false;
$title = ! empty( $slide['title'] ) ? wp_kses_post( $slide['title'] ) : false;
$desc = ! empty( $slide['desc'] ) ? wp_kses_post( $slide['desc'] ) : false;
$result .= sprintf( $format, $url, $title, $desc );
}
$result = sprintf(
'<div class="cdi-slider">
<div class="swiper-container">
<div class="swiper-wrapper">%1$s</div>
</div>
%2$s
</div>',
$result,
'<div class="slider-pagination"></div>'
);
if ( $echo ) {
echo $result;
} else {
return $result;
}
}
/**
* Retrieve slides list
*
* @return array|bool false
*/
public function get_slides() {
if ( ! empty( $this->slides ) ) {
return $this->slides;
}
$slides = get_transient( 'jet_data_importer_slides' );
if ( ! $slides ) {
$response = wp_remote_get( $this->data['path'], array( 'timeout' => 30 ) );
if ( ! $response || is_wp_error( $response ) ) {
return false;
}
$body = wp_remote_retrieve_body( $response );
if ( ! $body || is_wp_error( $body ) ) {
return false;
}
$slides = json_decode( $body, true );
if ( ! $slides ) {
return false;
}
}
$this->slides = $slides;
set_transient( 'jet_data_importer_slides', $this->slides, DAY_IN_SECONDS );
return $this->slides;
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Data_Importer_Slider
*
* @return object
*/
function jdi_slider() {
return Jet_Data_Importer_Slider::get_instance();
}

View File

@@ -0,0 +1,292 @@
<?php
/**
* Tools class
*
* @package Jet_Data_Importer
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Tools' ) ) {
/**
* Define Jet_Data_Importer_Tools class
*/
class Jet_Data_Importer_Tools {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Returns available widgets data.
*
* @return array
*/
public function available_widgets() {
global $wp_registered_widget_controls;
$widget_controls = $wp_registered_widget_controls;
$available_widgets = array();
foreach ( $widget_controls as $widget ) {
if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base']] ) ) {
$available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base'];
$available_widgets[ $widget['id_base'] ]['name'] = $widget['name'];
}
}
return apply_filters( 'jet-data-importer/export/available-widgets', $available_widgets );
}
/**
* Get page title
*
* @param string $before HTML before title.
* @param string $after HTML after title.
* @param bool $echo Echo or return.
* @return string|void
*/
public function get_page_title( $before = '', $after = '', $echo = false ) {
if ( ! isset( jdi()->current_tab ) || empty( jdi()->current_tab ) ) {
return;
}
$title = jdi()->current_tab['name'];
if ( 'import' === jdi()->current_tab['id'] ) {
$step = ! empty( $_GET['step'] ) ? intval( $_GET['step'] ) : 1;
switch ( $step ) {
case 2:
$title = esc_html__( 'Importing sample data', 'jet-data-importer' );
break;
case 3:
$title = esc_html__( 'Regenerating thumbnails', 'jet-data-importer' );
break;
case 4:
$title = esc_html__( 'Congratulations! Youre all Set!', 'jet-data-importer' );
break;
default:
$title = esc_html__( 'Select source to import', 'jet-data-importer' );
break;
}
}
$title = $before . apply_filters( 'jet-data-importer/tab-title', $title ) . $after;
if ( $echo ) {
echo $title;
} else {
return $title;
}
}
/**
* Get current page URL
*
* @return string
*/
public function get_page_url() {
return sprintf(
'%1$s://%2$s%3$s',
is_ssl() ? 'https' : 'http',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
);
}
/**
* Get recommended server params
*
* @return array
*/
public function server_params() {
return apply_filters(
'jet-data-importer/recommended-params',
array(
'memory_limit' => array(
'value' => 128,
'units' => 'Mb',
),
'post_max_size' => array(
'value' => 8,
'units' => 'Mb',
),
'upload_max_filesize' => array(
'value' => 8,
'units' => 'Mb',
),
'max_input_time' => array(
'value' => 45,
'units' => 's',
),
'max_execution_time' => array(
'value' => 30,
'units' => 's',
),
)
);
}
/**
* Check if passed table is exists in database
*
* @param string $table Table name.
* @return boolean
*/
public function is_db_table_exists( $table = '' ) {
global $wpdb;
$table_name = $wpdb->prefix . $table;
return ( $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) ) === $table_name );
}
/**
* Escape unsecure for public usage part of file path and return base64 encoded result.
*
* @param string $file Full file path
* @return string
*/
public function secure_path( $file ) {
if ( false !== strpos( $file, '/wpcom' ) ) {
return base64_encode( $file );
}
if ( false === strpos( $file, ABSPATH ) ) {
return 'remote';
}
return base64_encode( str_replace( ABSPATH, '', $file ) );
}
/**
* Gets base64 encoded part of path, decode it and adds server path
*
* @param string $file Encoded part of path.
* @return string
*/
public function esc_path( $file ) {
if ( 'remote' === $file ) {
return false;
}
$file = base64_decode( $file );
if ( false !== strpos( $file, '/wpcom' ) ) {
return $file;
}
return ABSPATH . $file;
}
/**
* Remove existing content from website
*
* @since 1.1.0
* @return null
*/
public function clear_content() {
if ( ! current_user_can( 'delete_users' ) ) {
return;
}
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
) );
if ( ! empty( $attachments ) ) {
foreach ( $attachments as $attachment ) {
wp_delete_attachment( $attachment->ID, true );
}
}
global $wpdb;
$tables_to_clear = array(
$wpdb->commentmeta,
$wpdb->comments,
$wpdb->links,
$wpdb->postmeta,
$wpdb->posts,
$wpdb->termmeta,
$wpdb->terms,
$wpdb->term_relationships,
$wpdb->term_taxonomy,
);
foreach ( $tables_to_clear as $table ) {
$wpdb->query( "TRUNCATE {$table};" );
}
$options = apply_filters( 'jet-data-importer/clear-options-on-remove', array(
'sidebars_widgets',
) );
foreach ( $options as $option ) {
delete_option( $option );
}
/**
* Clear widgets data
*/
$widgets = $wpdb->get_results(
"SELECT * FROM $wpdb->options WHERE `option_name` LIKE 'widget_%'"
);
if ( ! empty( $widgets ) ) {
foreach ( $widgets as $widget ) {
delete_option( $widget->option_name );
}
}
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Data_Importer_Tools
*
* @return object
*/
function jdi_tools() {
return Jet_Data_Importer_Tools::get_instance();
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* Default config file
*
* @var array
*/
$config = array(
'xml' => array(
'enabled' => true,
'use_upload' => true,
'path' => false,
),
'import' => array(
'chunk_size' => $this->chunk_size,
'regenerate_chunk_size' => 3,
'allow_types' => false,
),
'remap' => array(
'post_meta' => array(),
'term_meta' => array(),
'options' => array(
'jet_woo_builder',
'woocommerce_catalog_columns',
'woocommerce_catalog_rows',
),
),
'export' => array(
'message' => __( 'Export all content with Jet Data Export tool', 'jet-data-importer' ),
'logo' => $this->url( 'assets/img/monster-logo.png' ),
'options' => array(),
'tables' => array(),
),
'success-links' => array(
'home' => array(
'label' => __( 'View your site', 'jet-data-importer' ),
'type' => 'primary',
'target' => '_self',
'icon' => 'dashicons-welcome-view-site',
'desc' => __( 'Take a look at your site', 'jet-data-importer' ),
'url' => home_url( '/' ),
),
'edit' => array(
'label' => __( 'Start editing', 'jet-data-importer' ),
'type' => 'primary',
'target' => '_self',
'icon' => 'dashicons-welcome-write-blog',
'desc' => __( 'Proceed to editing pages', 'jet-data-importer' ),
'url' => admin_url( 'edit.php?post_type=page' ),
),
'documentation' => array(
'label' => __( 'Check documentation', 'jet-data-importer' ),
'type' => 'primary',
'target' => '_blank',
'icon' => 'dashicons-welcome-learn-more',
'desc' => __( 'Get more info from documentation', 'jet-data-importer' ),
'url' => 'http://documentation.zemez.io/wordpress/index.php?project=crocoblock',
),
'knowledge-base' => array(
'label' => __( 'Knowledge Base', 'jet-data-importer' ),
'type' => 'primary',
'target' => '_blank',
'icon' => 'dashicons-sos',
'desc' => __( 'Access the vast knowledge base', 'jet-data-importer' ),
'url' => 'https://zemez.io/wordpress/support/knowledge-base/',
),
'community' => array(
'label' => __( 'Community', 'jet-data-importer' ),
'type' => 'primary',
'target' => '_blank',
'icon' => 'dashicons-facebook',
'desc' => __( 'Join community to stay tuned to the latest news', 'jet-data-importer' ),
'url' => 'https://www.facebook.com/groups/CrocoblockCommunity/',
),
),
'slider' => array(
'path' => 'https://raw.githubusercontent.com/ZemezLab/kava-slider/master/slides.json',
),
'advanced_import' => array(
'from_path' => 'https://account.crocoblock.com/wp-content/uploads/static/wizard-skins.json'
)
/*
'advanced_import' => array(
'default' => array(
'full' => get_template_directory() . '/assets/demo-content/default/default-full.xml',
'lite' => get_template_directory() . '/assets/demo-content/default/default-min.xml',
'thumb' => get_template_directory_uri() . '/assets/demo-content/default/default-thumb.png',
'plugins' => array(
'booked-appointments' => 'Booked Appointments',
'buddypress' => 'BuddyPress',
'cherry-projects' => 'Cherry Projects'
),
),
),
or
'advanced_import' => array(
'from_path' => 'https://account.crocoblock.com/wp-content/uploads/static/wizard-skins.json'
),
*/
);

View File

@@ -0,0 +1,150 @@
<?php
/**
* Exporter interface
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Export_Interface' ) ) {
/**
* Define Jet_Data_Export_Interface class
*/
class Jet_Data_Export_Interface {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Constructor for the class
*/
function __construct() {
add_action( 'admin_menu', array( $this, 'menu_page' ) );
add_action( 'export_filters', array( $this, 'render_export_form' ) );
add_action( 'wp_ajax_jet-data-export', array( $this, 'run_export' ) );
}
/**
* Init exporter page
*
* @return void
*/
public function menu_page() {
jdi()->register_tab(
array(
'id' => 'export',
'name' => esc_html__( 'Export', 'jet-data-importer' ),
'cb' => array( $this, 'render_export_form' ),
)
);
}
/**
* Render export form HTML
*
* @return void
*/
public function render_export_form() {
ob_start();
jdi()->get_template( 'export.php' );
return ob_get_clean();
}
/**
* Run export process
*
* @return void
*/
public function run_export() {
if ( ! current_user_can( 'export' ) ) {
wp_send_json_error( array( 'message' => 'You don\'t have permissions to do this' ) );
}
if ( empty( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'jet-data-export' ) ) {
wp_send_json_error( array( 'message' => 'You don\'t have permissions to do this' ) );
}
require jdi()->path( 'includes/export/class-jet-wxr-exporter.php' );
$xml = jdi_exporter()->do_export( false );
$this->download_headers( jdi_exporter()->get_filename() );
echo $xml;
die();
}
/**
* Send download headers
*
* @return void
*/
public function download_headers( $file = 'sample-data.xml' ) {
session_write_close();
header( 'Pragma: public' );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Cache-Control: public' );
header( 'Content-Description: File Transfer' );
header( 'Content-type: application/octet-stream' );
header( 'Content-Disposition: attachment; filename="' . $file . '"' );
header( 'Content-Transfer-Encoding: binary' );
}
/**
* Returns URL to generate export file (nonce must be added via JS, otherwise will not be processed)
*
* @return string
*/
public function get_export_url() {
return add_query_arg( array( 'action' => 'jet-data-export' ), admin_url( 'admin-ajax.php' ) );
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Data_Export_Interface
*
* @return object
*/
function jdi_export_interface() {
return Jet_Data_Export_Interface::get_instance();
}
jdi_export_interface();

View File

@@ -0,0 +1,355 @@
<?php
/**
* Main exporter class
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_WXR_Exporter' ) ) {
/**
* Define Jet_WXR_Exporter class
*/
class Jet_WXR_Exporter {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Options array to export
*
* @var array
*/
public $export_options = null;
/**
* Constructor for the class
*/
function __construct() {
include_once( ABSPATH . '/wp-admin/includes/class-pclzip.php' );
require_once( ABSPATH . '/wp-admin/includes/export.php' );
}
/**
* Get array of options to export with content
*
* @return void
*/
public function get_options_to_export() {
if ( null === $this->export_options ) {
$theme = get_option( 'stylesheet' );
$default_options = apply_filters( 'jet-data-importer/export/options-to-export', array(
'blogname',
'blogdescription',
'users_can_register',
'posts_per_page',
'date_format',
'time_format',
'thumbnail_size_w',
'thumbnail_size_h',
'thumbnail_crop',
'medium_size_w',
'medium_size_h',
'large_size_w',
'large_size_h',
'theme_mods_' . $theme,
'show_on_front',
'page_on_front',
'page_for_posts',
'permalink_structure',
$theme . '_sidebars',
$theme . '_sidbars',
'jet_site_conditions',
'elementor_container_width',
'jet-elements-settings',
) );
$user_options = jdi()->get_setting( array( 'export', 'options' ) );
if ( ! $user_options || ! is_array( $user_options ) ) {
$user_options = array();
}
$this->export_options = array_unique( array_merge( $default_options, $user_options ) );
}
return $this->export_options;
}
/**
* Process XML export
*
* @return string
*/
public function do_export( $into_file = true ) {
ob_start();
ini_set( 'max_execution_time', -1 );
set_time_limit( 0 );
$use_custom_export = apply_filters( 'jet-data-importer/export/use-custom-export', false );
if ( $use_custom_export && function_exists( $use_custom_export ) ) {
call_user_func( $use_custom_export );
} else {
export_wp();
}
$xml = ob_get_clean();
$xml = $this->add_extra_data( $xml );
if ( true === $into_file ) {
$upload_dir = wp_upload_dir();
$upload_base_dir = $upload_dir['basedir'];
$upload_base_url = $upload_dir['baseurl'];
$filename = $this->get_filename();
$xml_dir = $upload_base_dir . '/' . $filename;
$xml_url = $upload_base_url . '/' . $filename;
file_put_contents( $xml_dir, $xml );
return $xml_url;
} else {
return $xml;
}
}
/**
* Returns filename for exported sample data
*
* @return void
*/
public function get_filename() {
$date = date( 'm-d-Y' );
$template = get_template();
return apply_filters(
'jet-data-importer/export/filename',
'sample-data-' . $template . '-' . $date . '.xml'
);
}
/**
* Add options and widgets to XML
*
* @param string $xml Exported XML.
* @return string
*/
private function add_extra_data( $xml ) {
ini_set( 'max_execution_time', -1 );
ini_set( 'memory_limit', -1 );
set_time_limit( 0 );
$xml = str_replace(
"</wp:base_blog_url>",
"</wp:base_blog_url>\r\n" . $this->get_options() . $this->get_widgets() . $this->get_tables(),
$xml
);
return $xml;
}
/**
* Get options list in XML format.
*
* @return string
*/
public function get_options() {
$options = '';
$format = "\t\t<wp:%1$s>%2$s</wp:%1$s>\r\n";
$export_options = $this->get_options_to_export();
foreach ( $export_options as $option ) {
$value = get_option( $option );
if ( is_array( $value ) ) {
$value = json_encode( $value );
}
if ( ! empty( $option ) ) {
$value = wxr_cdata( $value );
$options .= "\t\t<wp:{$option}>{$value}</wp:{$option}>\r\n";
}
}
return "\t<wp:options>\r\n" . $options . "\t</wp:options>\r\n";
}
/**
* Get tables to export
*
* @return string
*/
public function get_tables() {
$user_tables = jdi()->get_setting( array( 'export', 'tables' ) );
if ( ! is_array( $user_tables ) ) {
$user_tables = array();
}
if ( class_exists( 'WooCommerce' ) && ! in_array( 'woocommerce_attribute_taxonomies', $user_tables ) ) {
$user_tables[] = 'woocommerce_attribute_taxonomies';
}
if ( empty( $user_tables ) ) {
return;
}
global $wpdb;
$result = '';
foreach ( $user_tables as $table ) {
if ( ! jdi_tools()->is_db_table_exists( $table ) ) {
continue;
}
$name = esc_attr( $wpdb->prefix . $table );
$data = $wpdb->get_results( "SELECT * FROM $name WHERE 1", ARRAY_A );
if ( empty( $data ) ) {
continue;
}
$data = maybe_serialize( $data );
$result .= "\t\t<" . $table . ">" . wxr_cdata( $data ) . "</" . $table . ">\r\n";
}
if ( empty( $result ) ) {
return;
}
return "\t<wp:user_tables>\r\n" . $result . "\r\n\t</wp:user_tables>\r\n";
}
/**
* Get widgets data to export
*
* @return string
*/
private function get_widgets() {
// Get all available widgets site supports
$available_widgets = jdi_tools()->available_widgets();
// Get all widget instances for each widget
$widget_instances = array();
foreach ( $available_widgets as $widget_data ) {
// Get all instances for this ID base
$instances = get_option( 'widget_' . $widget_data['id_base'] );
// Have instances
if ( ! empty( $instances ) ) {
// Loop instances
foreach ( $instances as $instance_id => $instance_data ) {
// Key is ID (not _multiwidget)
if ( is_numeric( $instance_id ) ) {
$unique_instance_id = $widget_data['id_base'] . '-' . $instance_id;
$widget_instances[ $unique_instance_id ] = $instance_data;
}
}
}
}
// Gather sidebars with their widget instances
$sidebars_widgets = get_option( 'sidebars_widgets' ); // get sidebars and their unique widgets IDs
$sidebars_widget_instances = array();
foreach ( $sidebars_widgets as $sidebar_id => $widget_ids ) {
// Skip inactive widgets
if ( 'wp_inactive_widgets' == $sidebar_id ) {
continue;
}
// Skip if no data or not an array (array_version)
if ( ! is_array( $widget_ids ) || empty( $widget_ids ) ) {
continue;
}
// Loop widget IDs for this sidebar
foreach ( $widget_ids as $widget_id ) {
// Is there an instance for this widget ID?
if ( isset( $widget_instances[ $widget_id ] ) ) {
// Add to array
$sidebars_widget_instances[ $sidebar_id ][ $widget_id ] = $widget_instances[ $widget_id ];
}
}
}
// Filter pre-encoded data
$data = apply_filters( 'jet-data-importer/export/pre-get-widgets', $sidebars_widget_instances );
// Encode the data for file contents
$encoded_data = json_encode( $data );
$encoded_data = apply_filters( 'jet-data-importer/export/get-widgets', $encoded_data );
// Return contents
return "\t<wp:widgets_data>" . wxr_cdata( $encoded_data ) . "</wp:widgets_data>\r\n";
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_WXR_Exporter
*
* @return object
*/
function jdi_exporter() {
return Jet_WXR_Exporter::get_instance();
}

View File

@@ -0,0 +1,216 @@
<?php
/**
* Importer extensions
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Extensions' ) ) {
/**
* Define Jet_Data_Importer_Extensions class
*/
class Jet_Data_Importer_Extensions {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Constructor for the class
*/
public function __construct() {
// Prevent from errors triggering while MotoPress Booking posts importing (loving it)
add_filter( 'jet-data-importer/import/skip-post', array( $this, 'prevent_import_errors' ), 10, 2 );
// Clear fonts cache after import
add_action( 'jet-data-importer/import/finish', array( $this, 'clear_fonts_cache' ) );
// Allow switch Monstroid2 skins
add_action( 'jet-data-importer/import/before-skip-redirect', array( $this, 'switch_skin_on_skip' ) );
add_action( 'jet-data-importer/import/before-options-processing', array( $this, 'set_container_width' ) );
add_action( 'jet-data-importer/import/after-options-processing', array( $this, 'set_required_options' ) );
add_action( 'jet-data-importer/import/after-import-tables', array( $this, 'clear_woo_transients' ) );
}
/**
* Delete WooCommerce-related transients after new tables are imported
*
* @return void
*/
public function clear_woo_transients() {
delete_transient( 'wc_attribute_taxonomies' );
}
/**
* Preset elemntor container width if it was not passed in XML
*/
public function set_container_width( $data ) {
if ( ! isset( $data['elementor_container_width'] ) ) {
update_option( 'elementor_container_width', 1200 );
}
}
/**
* Set required Kava Extra and Jet Elements options
*/
public function set_required_options() {
if ( class_exists( 'Kava_Extra' ) ) {
$options = get_option( 'kava-extra-settings' );
if ( ! $options ) {
update_option( 'kava-extra-settings', array(
'nucleo-mini-package' => 'true',
) );
}
unset( $options );
}
if ( class_exists( 'Jet_Elements' ) ) {
$options = get_option( 'jet-elements-settings' );
if ( empty( $options ) ) {
$options = array();
}
if ( empty( $options['api_key'] ) ) {
$options['api_key'] = 'AIzaSyDlhgz2x94h0UZb7kZXOBjwAtszoCRtDLM';
}
update_option( 'jet-elements-settings', $options );
}
}
/**
* Switch Monstroid2 skin on skip demo content import.
*
* @return null
*/
public function switch_skin_on_skip() {
if ( ! isset( $_GET['file'] ) ) {
return;
}
preg_match( '/demo-content\/(.*?)\//', base64_decode( $_GET['file'] ), $matches );
if ( empty( $matches ) || ! isset( $matches[1] ) ) {
return;
}
$skin = esc_attr( $matches[1] );
$map = array(
'default' => 'default',
'skin-1' => 'skin1',
'skin-2' => 'skin2',
'skin-3' => 'skin8',
'skin-4' => 'skin3',
'skin-5' => 'skin4',
'skin-6' => 'skin9',
'skin-7' => 'skin5',
'skin-8' => 'skin7',
'skin-9' => 'skin6',
);
$mapped_skin = isset( $map[ $skin ] ) ? $map[ $skin ] : false;
if ( ! $mapped_skin ) {
return;
}
$skin_file = get_stylesheet_directory() . '/tm-style-switcher-pressets/' . $mapped_skin . '.json';
if ( ! file_exists( $skin_file ) ) {
return;
}
ob_start();
include $skin_file;
$skin_data = ob_get_clean();
$skin_data = json_decode( $skin_data, true );
if ( empty( $skin_data ) || ! isset( $skin_data['mods'] ) ) {
return;
}
foreach ( $skin_data['mods'] as $mod => $value ) {
set_theme_mod( $mod, $value );
}
}
/**
* Ckear Google fonts cache.
*
* @return void
*/
public function clear_fonts_cache() {
delete_transient( 'cherry_google_fonts_url' );
delete_transient( 'cx_google_fonts_url_kava' );
}
/**
* Prevent PHP errors on import.
*
* @param bool $skip Default skip value.
* @param array $data Plugin data.
* @return bool
*/
public function prevent_import_errors( $skip, $data ) {
if ( isset( $data['post_type'] ) && 'mphb_booking' === $data['post_type'] ) {
return true;
}
return $skip;
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Data_Importer_Extensions
*
* @return object
*/
function jdi_extensions() {
return Jet_Data_Importer_Extensions::get_instance();
}
jdi_extensions();

View File

@@ -0,0 +1,956 @@
<?php
/**
* Importer interface
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Interface' ) ) {
/**
* Define Jet_Data_Importer_Interface class
*/
class Jet_Data_Importer_Interface {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Variable for settings array.
*
* @var array
*/
public $settings = array();
/**
* Importer instance
*
* @var object
*/
private $importer = null;
/**
* Path to import file
*
* @var string|bool
*/
private $import_file = null;
/**
* Returns XML-files count
*
* @var int
*/
private $xml_count = null;
/**
* Importer slug
*
* @var string
*/
public $slug = 'import';
/**
* Data storage.
*
* @var array
*/
public $data = array();
/**
* Constructor for the class
*/
function __construct() {
add_action( 'admin_menu', array( $this, 'menu_page' ) );
add_action( 'wp_ajax_jet-data-import-chunk', array( $this, 'import_chunk' ) );
add_action( 'wp_ajax_jet-data-thumbnails', array( $this, 'regenerate_chunk' ) );
add_action( 'wp_ajax_jet-data-import-get-file-path', array( $this, 'get_file_path' ) );
add_action( 'wp_ajax_jet-data-import-remove-content', array( $this, 'remove_content' ) );
add_action( 'cherry-data-importer/before-messages', array( $this, 'check_server_params' ) );
add_action( 'admin_footer', array( $this, 'advanced_popup' ) );
add_action( 'init', array( $this, 'maybe_skip_installation' ), 20 );
}
/**
* Maybe skip demo content installation
*
* @return bool|void
*/
public function maybe_skip_installation() {
if ( ! isset( $_GET['page'] ) || jdi()->slug !== $_GET['page'] ) {
return false;
}
if ( ! isset( $_GET['step'] ) || '2' !== $_GET['step'] ) {
return false;
}
if ( isset( $_GET['type'] ) && 'skip' === $_GET['type'] ) {
require_once jdi()->path( 'includes/import/class-jet-data-importer-extensions.php' );
/**
* Hook before redirect on demo content installation skip
*/
do_action( 'jet-data-importer/import/before-skip-redirect' );
wp_redirect( jdi()->page_url( array( 'step' => 4 ) ) );
die();
}
return false;
}
/**
* Check user password before content replacing.
*
* @return void
*/
public function remove_content() {
$this->validate_request();
if ( empty( $_REQUEST['password'] ) ) {
jdi_cache()->write_cache();
wp_send_json_error( array(
'message' => esc_html__( 'Password is empty', 'jet-data-importer' ),
) );
}
$password = esc_attr( $_REQUEST['password'] );
$user_id = get_current_user_id();
$data = get_userdata( $user_id );
if ( wp_check_password( $password, $data->user_pass, $user_id ) ) {
jdi_tools()->clear_content();
jdi_cache()->write_cache();
wp_send_json_success( array(
'message' => esc_html__( 'Content successfully removed', 'jet-data-importer' ),
'slider' => jdi_slider()->render( false ),
) );
} else {
jdi_cache()->write_cache();
wp_send_json_error( array(
'message' => esc_html__( 'Entered password is invalid', 'jet-data-importer' ),
) );
}
}
/**
* PopUp installation
*/
public function advanced_popup() {
if ( ! $this->is_advanced_import() ) {
return;
}
if ( ! isset( $_GET['tab'] ) || 'import' !== $_GET['tab'] ) {
return;
}
jdi()->get_template( 'advanced-popup.php' );
}
/**
* Show content install type after plugins installation finished by Wizard.
*
* @return void
*/
public function wizard_popup() {
if ( ! isset( $_GET['step'] ) || 2 !== intval( $_GET['step'] ) ) {
return;
}
jdi()->get_template( 'advanced-popup.php' );
}
/**
* Check server params and show warning message if some of them don't meet requirements
*
* @return void
*/
public function check_server_params() {
$messages = '';
$format = esc_html__( '%1$s: %2$s required, yours - %3$s', 'jet-data-importer' );
foreach ( jdi_tools()->server_params() as $param => $data ) {
$val = ini_get( $param );
$val = ini_get( $param );
$current_value = wp_convert_hr_to_bytes( $val );
$recommended_value = wp_convert_hr_to_bytes( $data['value'] . $data['units'] );
if ( $current_value < $recommended_value ) {
$current = sprintf(
$format,
$param,
'<strong>' . $data['value'] . $data['units'] . '</strong>',
'<strong>' . (int) $val . $data['units'] . '</strong>'
);
$messages .= '<div>' . $current . '</div>';
}
}
if ( empty( $messages ) ) {
return;
}
$heading = '<div class="cdi-server-messages__heading">' . esc_html__( 'Some parameters from your server don\'t meet the requirements:', 'jet-data-importer' ) . '</div>';
echo '<div class="cdi-server-messages">' . $heading . $messages . '</div>';
}
/**
* Returns current chunk size
*
* @return void
*/
public function chunk_size() {
$size = jdi()->get_setting( array( 'import', 'chunk_size' ) );
$size = intval( $size );
if ( ! $size ) {
return jdi()->chunk_size;
} else {
return $size;
}
}
/**
* Init importer
*
* @return void
*/
public function menu_page() {
jdi()->register_tab(
array(
'id' => $this->slug,
'name' => esc_html__( 'Import', 'jet-data-importer' ),
'cb' => array( $this, 'dispatch' ),
)
);
}
/**
* Run Jet importer
*
* @return void
*/
public function dispatch() {
$step = ! empty( $_GET['step'] ) ? intval( $_GET['step'] ) : 1;
ob_start();
jdi_tools()->get_page_title( '<h2 class="page-title">', '</h2>', true );
wp_enqueue_script( 'jet-data-import' );
switch ( $step ) {
case 2:
$this->import_step();
break;
case 3:
$this->regenerate_thumbnails();
break;
case 4:
$this->import_after();
break;
default:
$this->import_before();
break;
}
return ob_get_clean();
}
/**
* First import step
*
* @return void
*/
private function import_before() {
jdi()->get_template( 'import-before.php' );
}
/**
* Last import step
*
* @return void
*/
private function import_after() {
jdi()->get_template( 'import-after.php' );
}
/**
* Show main content import step
*
* @return void
*/
private function import_step() {
if ( empty( $_GET['file'] ) || 'null' === $_GET['file'] ) {
wp_redirect( add_query_arg(
array(
'page' => jdi()->slug,
'tab' => $this->slug,
'step' => 1,
),
esc_url( admin_url( 'admin.php' ) )
) );
die();
}
$importer = $this->get_importer();
if ( ! $importer ) {
_e( 'Error! Import file not found. Please contact our support team.', 'jet-data-importer' );
return;
}
$importer->prepare_import();
$count = jdi_cache()->get( 'total_count' );
$chunks_count = ceil( intval( $count ) / $this->chunk_size() );
// Adds final step with ID and URL remapping. Sometimes it's expensice step separate it
$chunks_count++;
jdi_cache()->update( 'chunks_count', $chunks_count );
jdi()->get_template( 'import.php' );
jdi_cache()->write_cache();
}
/**
* Process regenerate thumbnails step.
*
* @return void
*/
public function regenerate_thumbnails() {
$count = wp_count_attachments();
$count = (array) $count;
$step = jdi()->get_setting( array( 'import', 'regenerate_chunk_size' ) );
$total = 0;
foreach ( $count as $mime => $num ) {
if ( false === strpos( $mime, 'image' ) ) {
continue;
}
$total = $total + (int) $num;
}
wp_localize_script( 'jet-data-import', 'JetRegenerateData', array(
'totalImg' => $total,
'totalSteps' => ceil( $total / $step ),
'step' => $step,
) );
jdi()->get_template( 'regenerate.php' );
}
/**
* Returns true if regenerate thumbnails step is required, false - if not.
*
* @return boolean
*/
private function is_regenerate_required() {
$count = wp_count_attachments();
$count = (array) $count;
if ( empty( $count ) ) {
return false;
}
$total = 0;
if ( ! empty( $count['image/jpeg'] ) ) {
$total += absint( $count['image/jpeg'] );
}
if ( ! empty( $count['image/png'] ) ) {
$total += absint( $count['image/png'] );
}
if ( 0 === $total ) {
return false;
}
return true;
}
/**
* Validate import-related ajax request.
*
* @return void
*/
private function validate_request() {
if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'jet-data-import' ) ) {
jdi_cache()->write_cache();
wp_send_json_error( array(
'message' => esc_html__( 'You don\'t have permissions to do this', 'jet-data-importer' ),
) );
}
if ( ! current_user_can( 'import' ) ) {
jdi_cache()->write_cache();
wp_send_json_error( array(
'message' => esc_html__( 'You don\'t have permissions to do this', 'jet-data-importer' ),
) );
}
}
/**
* Process single regenerate chunk
*
* @return void
*/
public function regenerate_chunk() {
$this->validate_request();
$required = array(
'offset',
'step',
'total',
);
foreach ( $required as $field ) {
if ( ! isset( $_REQUEST[ $field ] ) ) {
jdi_cache()->write_cache();
wp_send_json_error( array(
'message' => sprintf(
esc_html__( '%s is missing in request', 'jet-data-importer' ), $field
),
) );
}
}
$offset = (int) $_REQUEST['offset'];
$step = (int) $_REQUEST['step'];
$total = (int) $_REQUEST['total'];
$is_last = ( $total * $step <= $offset + $step ) ? true : false;
$attachments = get_posts( array(
'post_type' => 'attachment',
'numberposts' => $step,
'offset' => $offset,
) );
if ( ! empty( $attachments ) ) {
foreach ( $attachments as $attachment ) {
$id = $attachment->ID;
$file = get_attached_file( $id );
$metadata = wp_generate_attachment_metadata( $id, $file );
wp_update_attachment_metadata( $id, $metadata );
}
}
$data = array(
'action' => 'jet-data-thumbnails',
'offset' => $offset + $step,
'step' => $step,
'total' => $total,
'isLast' => $is_last,
'complete' => round( ( $offset + $step ) * 100 / ( $total * $step ) ),
);
if ( $is_last ) {
$data['redirect'] = jdi()->page_url( array( 'tab' => $this->slug, 'step' => 4 ) );
}
jdi_cache()->write_cache();
wp_send_json_success( $data );
}
/**
* Process single chunk import
*
* @return void
*/
public function import_chunk() {
$this->validate_request();
if ( empty( $_REQUEST['chunk'] ) ) {
jdi_cache()->write_cache();
wp_send_json_error( array(
'message' => esc_html__( 'Chunk number is missing in request', 'jet-data-importer' ),
) );
}
$chunk = intval( $_REQUEST['chunk'] );
$chunks = jdi_cache()->get( 'chunks_count' );
$processed = jdi_cache()->get( 'processed_summary' );
require_once jdi()->path( 'includes/import/class-jet-data-importer-extensions.php' );
switch ( $chunk ) {
case $chunks:
// Process last step (remapping and finalizing)
$this->remap_all();
jdi_cache()->clear_cache();
flush_rewrite_rules();
$redirect = jdi()->page_url(
array(
'tab' => $this->slug,
'step' => $this->is_regenerate_required() ? 3 : 4,
)
);
/**
* Hook on last import chunk
*/
do_action( 'jet-data-importer/import/finish' );
$data = array(
'isLast' => true,
'complete' => 100,
'processed' => $processed,
'redirect' => $redirect,
);
// Remove XML file for remote files after successfull import.
$file = $this->get_import_file();
if ( $file && isset( $_REQUEST['file'] ) && 'remote' === $_REQUEST['file'] ) {
unlink( $file );
}
break;
default:
// Process regular step
$offset = $this->chunk_size() * ( $chunk - 1 );
$importer = $this->get_importer();
$importer->chunked_import( $this->chunk_size(), $offset );
/**
* Hook on last import chunk
*/
do_action( 'jet-data-importer/import/chunk', $chunk );
$data = array(
'action' => 'jet-data-import-chunk',
'chunk' => $chunk + 1,
'complete' => round( ( $chunk * 100 ) / $chunks ),
'processed' => $processed,
);
break;
}
jdi_cache()->write_cache();
wp_send_json_success( $data );
}
/**
* Return importer object
*
* @return object
*/
public function get_importer() {
if ( null !== $this->importer ) {
return $this->importer;
}
require_once jdi()->path( 'includes/import/class-jet-wxr-importer.php' );
$options = array();
$file = $this->get_import_file();
if ( ! $file ) {
return false;
}
return $this->importer = new Jet_WXR_Importer( $options, $file );
}
/**
* Get path to imported XML file
*
* @return [type] [description]
*/
public function get_import_file() {
if ( null !== $this->import_file ) {
return $this->import_file;
}
$file = null;
if ( ! empty( $_REQUEST['file'] ) ) {
$file = jdi_tools()->esc_path( esc_attr( $_REQUEST['file'] ) );
}
if ( ! $file || ! file_exists( $file ) ) {
$file = jdi()->get_setting( array( 'xml', 'path' ) );
}
if ( is_array( $file ) ) {
$file = $file[0];
}
if ( isset( $_REQUEST['file'] ) && 'remote' === $_REQUEST['file'] ) {
$import_settings = jdi()->get_setting( array( 'advanced_import' ) );
$slug = isset( $_REQUEST['skin'] ) ? esc_attr( $_REQUEST['skin'] ) : 'default';
$xml_type = isset( $_REQUEST['xml_type'] ) ? esc_attr( $_REQUEST['xml_type'] ) : 'lite';
if ( isset( $import_settings[ $slug ][ $xml_type ] ) ) {
$file = $this->get_remote_file( $import_settings[ $slug ][ $xml_type ] );
}
}
if ( ! $file ) {
return false;
} else {
$this->import_file = $file;
return $this->import_file;
}
}
/**
* Get remoe file by URL
*
* @param [type] $file_path [description]
* @return [type] [description]
*/
public function get_remote_file( $file_url ) {
$filename = basename( $file_url );
$base_path = jdi_files_manager()->base_path();
if ( is_file( $base_path . $filename ) ) {
return $base_path . $filename;
}
$tmpath = download_url( esc_url( $file_url ) );
if ( ! $tmpath ) {
return false;
}
if ( ! copy( $tmpath, $base_path . $filename ) ) {
return false;
}
unlink( $tmpath );
return $base_path . $filename;
}
/**
* Remap all required data after installation completed
*
* @return void
*/
public function remap_all() {
require_once jdi()->path( 'includes/import/class-jet-data-importer-remap-callbacks.php' );
/**
* Attach all posts remapping related callbacks to this hook
*
* @param array Posts remapping data. Format: old_id => new_id
*/
do_action( 'jet-data-importer/import/remap-posts', jdi_cache()->get( 'posts', 'mapping' ) );
/**
* Attach all terms remapping related callbacks to this hook
*
* @param array Terms remapping data. Format: old_id => new_id
*/
do_action( 'jet-data-importer/import/remap-terms', jdi_cache()->get( 'term_id', 'mapping' ) );
/**
* Attach all comments remapping related callbacks to this hook
*
* @param array COmments remapping data. Format: old_id => new_id
*/
do_action( 'jet-data-importer/import/remap-comments', jdi_cache()->get( 'comments', 'mapping' ) );
/**
* Attach all posts_meta remapping related callbacks to this hook
*
* @param array posts_meta data. Format: new_id => related keys array
*/
do_action( 'jet-data-importer/import/remap-posts-meta', jdi_cache()->get( 'posts_meta', 'requires_remapping' ) );
/**
* Attach all terms meta remapping related callbacks to this hook
*
* @param array terms meta data. Format: new_id => related keys array
*/
do_action( 'jet-data-importer/import/remap-terms-meta', jdi_cache()->get( 'terms_meta', 'requires_remapping' ) );
}
/**
* Get welcome message for importer starter page
*
* @return string
*/
public function get_welcome_message() {
$files = $this->get_xml_count();
if ( 0 === $files ) {
$message = __( 'Upload XML file with demo content', 'jet-data-importer' );
}
if ( 1 === $files ) {
$message = __( 'We found 1 XML file with demo content in your theme, install it?', 'jet-data-importer' );
}
if ( 1 < $files ) {
$message = sprintf(
__( 'We found %s XML files in your theme. Please select one of them to install', 'jet-data-importer' ),
$files
);
}
return '<div class="cdi-message">' . $message . '</div>';
}
/**
* Get available XML count
*
* @return int
*/
public function get_xml_count() {
if ( null !== $this->xml_count ) {
return $this->xml_count;
}
$files = jdi()->get_setting( array( 'xml', 'path' ) );
if ( ! $files ) {
$this->xml_count = 0;
} elseif ( ! is_array( $files ) ) {
$this->xml_count = 1;
} else {
$this->xml_count = count( $files );
}
return $this->xml_count;
}
/**
* Returns HTML-markup of import files select
*
* @return string
*/
public function get_import_files_select( $before = '<div>', $after = '</div>' ) {
$files = jdi()->get_setting( array( 'xml', 'path' ) );
if ( ! $files && ! is_array( $files ) ) {
return;
}
if ( 1 > count( $files ) ) {
return;
}
$wrap_format = '<select name="import_file">%1$s</select>';
$item_format = '<option value="%1$s" %3$s>%2$s</option>';
$selected = 'selected="selected"';
$result = '';
foreach ( $files as $name => $file ) {
$result .= sprintf( $item_format, jdi_tools()->secure_path( $file ), $name, $selected );
$selected = '';
}
return $before . sprintf( $wrap_format, $result ) . $after;
}
/**
* Retuns HTML markup for import file uploader
*
* @param string $before HTML markup before input.
* @param string $after HTML markup after input.
* @return string
*/
public function get_import_file_input( $before = '<div>', $after = '</div>' ) {
if ( ! jdi()->get_setting( array( 'xml', 'use_upload' ) ) ) {
return;
}
$result = '<div class="import-file">';
$result .= '<input type="hidden" name="upload_file" class="import-file__input">';
$result .= '<input type="text" name="upload_file_nicename" class="import-file__placeholder">';
$result .= '<button class="cdi-btn primary" id="jet-file-upload">';
$result .= esc_html__( 'Upload File', 'jet-data-importer' );
$result .= '</button>';
$result .= '</div>';
return $before . $result . $after;
}
/**
* Check if advanced import is allowed
*
* @since 1.1.0
* @return boolean
*/
public function is_advanced_import() {
$advanced = jdi()->get_setting( array( 'advanced_import' ) );
return ! empty( $advanced );
}
/**
* Show advanced import block.
*
* @since 1.1.0
* @return null
*/
public function advanced_import() {
if ( ! $this->is_advanced_import() ) {
return;
}
$advanced = jdi()->get_setting( array( 'advanced_import' ) );
foreach ( $advanced as $slug => $item ) {
$this->data['advanced-item'] = $item;
$this->data['advanced-slug'] = $slug;
jdi()->get_template( 'import-advanced.php' );
}
}
/**
* Show password form if is replace installation type.
*
* @since 1.1.0
* @return null
*/
public function remove_content_form() {
if ( ! isset( $_GET['type'] ) || 'replace' !== $_GET['type'] ) {
return;
}
if ( ! current_user_can( 'delete_users' ) ) {
esc_html_e(
'You don\'t have permissions to replace content, please re-enter with admiistrator account',
'jet-data-importer'
);
return;
}
jdi()->get_template( 'remove-content-form.php' );
}
/**
* Retrieve XML file path by URL
*
* @return string
*/
public function get_file_path() {
$this->validate_request();
if ( ! isset( $_REQUEST['file'] ) ) {
jdi_cache()->write_cache();
wp_send_json_error( array(
'message' => esc_html__( 'XML file not passed', 'jet-data-importer' ),
) );
}
$path = str_replace( home_url( '/' ), ABSPATH, esc_url( $_REQUEST['file'] ) );
jdi_cache()->write_cache();
wp_send_json_success( array(
'path' => jdi_tools()->secure_path( $path ),
) );
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Data_Importer_Interface
*
* @return object
*/
function jdi_interface() {
return Jet_Data_Importer_Interface::get_instance();
}

View File

@@ -0,0 +1,694 @@
<?php
/**
* Jimporter post processing callbacks
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Data_Importer_Callbacks' ) ) {
/**
* Define Jet_Data_Importer_Callbacks class
*/
class Jet_Data_Importer_Callbacks {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Holder for terms data
*
* @var array
*/
public $terms = array();
public $pages = null;
/**
* Store processed shortcodes data
*
* @var array
*/
private $shortcodes_data = array();
/**
* Constructor for the class
*/
public function __construct() {
// Manipulations with posts remap array
add_action( 'jet-data-importer/import/remap-posts', array( $this, 'process_options' ) );
add_action( 'jet-data-importer/import/remap-posts', array( $this, 'postprocess_posts' ) );
add_action( 'jet-data-importer/import/remap-posts', array( $this, 'process_thumbs' ) );
add_action( 'jet-data-importer/import/remap-posts', array( $this, 'process_elementor_pages_posts' ) );
add_action( 'jet-data-importer/import/remap-posts', array( $this, 'process_home_page' ) );
// Manipulations with terms remap array
add_action( 'jet-data-importer/import/remap-terms', array( $this, 'process_term_parents' ) );
add_action( 'jet-data-importer/import/remap-terms', array( $this, 'process_nav_menu' ) );
add_action( 'jet-data-importer/import/remap-terms', array( $this, 'process_nav_menu_widgets' ) );
add_action( 'jet-data-importer/import/remap-terms', array( $this, 'process_elementor_pages_terms' ) );
add_action( 'jet-data-importer/import/remap-terms', array( $this, 'process_home_page' ) );
}
public function elementor_pages() {
if ( null === $this->pages ) {
$this->pages = get_posts( array(
'post_type' => array( 'page', 'jet-theme-core', 'elementor_library' ),
'posts_per_page' => -1,
) );
}
return $this->pages;
}
/**
* Remap elementor images
*
* @todo remplace images in elementor widgets with imported.
* @return void
*/
public function process_elementor_pages_posts( $data ) {
$pages = $this->elementor_pages();
foreach ( $pages as $page ) {
$elementor_data = get_post_meta( $page->ID, '_elementor_data', true );
if ( empty( $elementor_data ) ) {
continue;
}
$new_data = preg_replace_callback(
'/(\"id\":\"?(\d+)\"?,\"url\":\"([^\"\']*?)\"|\"url\":\"([^\"\']*?)\",\"id\":\"?(\d+)\"?)/',
function( $match ) use ( $data ) {
$id = false;
if ( ! empty( $match[1] ) ) {
$id = $match[1];
} elseif ( ! empty( $match[4] ) ) {
$id = $match[4];
}
if ( ! $id || ! isset( $data[ $id ] ) ) {
return $match[0];
} else {
$result = sprintf(
'"url":%2$s,"id":%1$s',
$data[ $id ],
json_encode( wp_get_attachment_url( $data[ $id ] ) )
);
return $result;
}
},
$elementor_data
);
$ids_keys = apply_filters( 'jet-data-importer/import/posts/elementor-ids-to-remap', array(
'panel_template_id',
'item_template_id',
) );
$ids_keys = implode( '|', $ids_keys );
$ids_regex = "/\\\"({$ids_keys})\\\":\\\"(\d+)\\\"/";
$new_data = preg_replace_callback( $ids_regex, function( $match ) use ( $data ) {
if ( isset( $data[ $match[2] ] ) ) {
return sprintf(
'"%1$s":"%2$s"',
$match[1],
$data[ $match[2] ]
);
} else {
return $match[0];
}
}, $new_data );
update_post_meta( $page->ID, '_elementor_data', wp_slash( $new_data ) );
}
}
public function process_elementor_pages_terms( $data ) {
$pages = $this->elementor_pages();
$ids_keys = apply_filters( 'jet-data-importer/import/terms/elementor-ids-to-remap', array(
'category_ids',
'menu',
'nav_menu',
) );
$ids_keys = implode( '|', $ids_keys );
$regex = '\"(' . $ids_keys . ')\":(\".*?\"|\[.*?\])';
foreach ( $pages as $page ) {
$elementor_data = get_post_meta( $page->ID, '_elementor_data', true );
if ( empty( $elementor_data ) ) {
continue;
}
$new_data = preg_replace_callback( '/' . $regex . '/', function( $match ) use ( $data ) {
$val = json_decode( $match[2], true );
if ( ! is_array( $val ) ) {
$new = isset( $data[ $val ] ) ? $data[ $val ] : $val;
$new = '"' . $new . '"';
} else {
$new = array();
foreach ( $val as $old_id ) {
$new = isset( $data[ $old_id ] ) ? $data[ $old_id ] : $old_id;
}
$new = json_encode( $new );
}
return sprintf(
'"%1$s":%2$s',
$match[1],
$new
);
}, $elementor_data );
update_post_meta( $page->ID, '_elementor_data', wp_slash( $new_data ) );
}
}
/**
* Remap IDs in home page content
*
* @param array $data Mapped terms data.
* @return void|false
*/
public function process_home_page( $data ) {
$regex = apply_filters( 'jet-data-importer/import/home-regex-replace', array() );
if ( empty( $regex ) ) {
return false;
}
$pages = apply_filters( 'jet-data-importer/import/add-pages-to-replace', array() );
if ( ! empty( $pages ) ) {
$pages = array_map( array( $this, 'get_page_ids' ), $pages );
}
$home_id = get_option( 'page_on_front' );
$pages = array_merge( array( $home_id ), $pages );
$pages = array_filter( $pages );
if ( ! $pages ) {
return false;
}
$regex = array_map( array( $this, 'prepare_regex' ), $regex );
foreach ( $pages as $page_id ) {
$page = get_post( $page_id );
$this->terms = $data;
$content = preg_replace_callback( $regex, array( $this, 'replace_ids' ), $page->post_content );
$new_page = array(
'ID' => $page_id,
'post_content' => $content,
);
wp_update_post( $new_page );
}
}
/**
* Get page ids by slug
*
* @return int|bool
*/
public function get_page_ids( $slug ) {
$page = get_page_by_path( $slug );
if ( $page ) {
return $page->ID;
} else {
return false;
}
return get_page_by_path( $slug );
}
/**
* Replace ids in shortcodes
*
* @return string
*/
public function replace_ids( $matches ) {
if ( 5 !== count( $matches ) ) {
return $matches[0];
}
$tag = $matches[2];
$attr = $matches[3];
$data = $this->shortcodes_data;
$delimiter = isset( $data[ $tag ][ $attr ] ) ? $data[ $tag ][ $attr ] : ',';
$ids = explode( $delimiter, $matches[4] );
$new_ids = array();
foreach ( $ids as $id ) {
if ( isset( $this->terms[ $id ] ) ) {
$new_ids[] = $this->terms[ $id ];
} else {
$new_ids[] = $id;
}
}
$new_ids = implode( $delimiter, $new_ids );
$return = sprintf( '%1$s="%2$s"', $matches[1], $new_ids );
return $return;
}
/**
* Callback for regex map
*
* @param array $item Regex item.
* @return string
*/
public function prepare_regex( $item ) {
$delimiter = isset( $item['delimiter'] ) ? $item['delimiter'] : ',';
$tag = $item['shortcode'];
$attr = $item['attr'];
if ( ! isset( $this->shortcodes_data[ $tag ] ) ) {
$this->shortcodes_data[ $tag ] = array();
}
$this->shortcodes_data[ $tag ][ $attr ] = $delimiter;
return '/(\[(' . $item['shortcode'] . ')[^\]]*(' . $item['attr'] . '))="([0-9\,\s]*)"/';
}
/**
* Set correctly term parents
*
* @param array $data Mapped terms data.
* @return void|false
*/
public function process_term_parents( $data ) {
$remap_terms = jdi_cache()->get( 'terms', 'requires_remapping' );
$processed_term_slug = jdi_cache()->get( 'term_slug', 'mapping' );
if ( empty( $remap_terms ) ) {
return false;
}
foreach ( $remap_terms as $term_id => $taxonomy ) {
$parent_slug = get_term_meta( $term_id, '_wxr_import_parent', true );
if ( ! $parent_slug ) {
continue;
}
$term_mapping_key = $taxonomy . '-' . $parent_slug;
if ( empty( $processed_term_slug[ $term_mapping_key ] ) ) {
continue;
}
wp_update_term( $term_id, $taxonomy, array(
'parent' => (int) $processed_term_slug[ $term_mapping_key ],
) );
}
}
/**
* Replace term thumbnails IDs with new ones
*
* @param array $data
* @return void
*/
public function process_thumbs( $data ) {
global $wpdb;
$query_term = "
SELECT term_id, meta_key, meta_value
FROM $wpdb->termmeta
WHERE meta_key LIKE '%_thumb'
";
$thumb_term = $wpdb->get_results( $query_term, ARRAY_A );
$query_post = "
SELECT post_id, meta_key, meta_value
FROM $wpdb->postmeta
WHERE meta_key = '_thumbnail_id'
";
$thumb_post = $wpdb->get_results( $query_post, ARRAY_A );
if ( empty( $thumb_term ) ) {
$thumb_term = array();
}
if ( empty( $thumb_post ) ) {
$thumb_post = array();
}
$thumbnails = array_merge( $thumb_term, $thumb_post );
foreach ( $thumbnails as $thumb_data ) {
$meta_key = $thumb_data['meta_key'];
$current = $thumb_data['meta_value'];
if ( '_thumbnail_id' === $meta_key ){
$id = $thumb_data['post_id'];
$func = 'update_post_meta';
} else {
$id = $thumb_data['term_id'];
$func = 'update_term_meta';
}
if ( ! empty( $data[ $current ] ) ) {
call_user_func( $func, $id, $meta_key, $data[ $current ] );
}
}
}
/**
* Post-process posts.
*
* @param array $todo Remap data.
* @return void
*/
public function postprocess_posts( $mapping ) {
$todo = jdi_cache()->get( 'posts', 'requires_remapping' );
$user_slug = jdi_cache()->get( 'user_slug', 'mapping' );
$url_remap = jdi_cache()->get_group( 'url_remap' );
foreach ( $todo as $post_id => $_ ) {
$data = array();
$updated_links = '';
$old_links = '';
$post = get_post( $post_id );
$parent_id = get_post_meta( $post_id, '_wxr_import_parent', true );
if ( ! empty( $parent_id ) && isset( $mapping['post'][ $parent_id ] ) ) {
$data['post_parent'] = $mapping['post'][ $parent_id ];
}
$author_slug = get_post_meta( $post_id, '_wxr_import_user_slug', true );
if ( ! empty( $author_slug ) && isset( $user_slug[ $author_slug ] ) ) {
$data['post_author'] = $user_slug[ $author_slug ];
}
$has_attachments = get_post_meta( $post_id, '_wxr_import_has_attachment_refs', true );
if ( ! empty( $has_attachments ) ) {
$content = $post->post_content;
// Replace all the URLs we've got
$new_content = str_replace( array_keys( $url_remap ), $url_remap, $content );
if ( $new_content !== $content ) {
$data['post_content'] = $new_content;
}
}
if ( in_array( get_post_type( $post_id ), array( 'page', 'post' ) ) ) {
$old_links = ! empty( $data['post_content'] ) ? $data['post_content'] : $post->post_content;
$updated_links = str_replace( jdi_cache()->get( 'home' ), home_url(), $old_links );
if ( $updated_links !== $old_links ) {
$data['post_content'] = $updated_links;
}
}
if ( get_post_type( $post_id ) === 'nav_menu_item' ) {
$this->postprocess_menu_item( $post_id );
}
// Do we have updates to make?
if ( empty( $data ) ) {
continue;
}
// Run the update
$data['ID'] = $post_id;
$result = wp_update_post( $data, true );
if ( is_wp_error( $result ) ) {
continue;
}
// Clear out our temporary meta keys
delete_post_meta( $post_id, '_wxr_import_parent' );
delete_post_meta( $post_id, '_wxr_import_user_slug' );
delete_post_meta( $post_id, '_wxr_import_has_attachment_refs' );
}
}
/**
* Post-process menu items.
*
* @param int $post_id Processed post ID
* @return void
*/
public function postprocess_menu_item( $post_id ) {
$menu_object_id = get_post_meta( $post_id, '_wxr_import_menu_item', true );
if ( empty( $menu_object_id ) ) {
// No processing needed!
return;
}
$processed_term_id = jdi_cache()->get( 'term_id', 'mapping' );
$processed_posts = jdi_cache()->get( 'posts', 'mapping' );
$menu_item_type = get_post_meta( $post_id, '_menu_item_type', true );
switch ( $menu_item_type ) {
case 'taxonomy':
if ( isset( $processed_term_id[ $menu_object_id ] ) ) {
$menu_object = $processed_term_id[ $menu_object_id ];
}
break;
case 'post_type':
if ( isset( $processed_posts[ $menu_object_id ] ) ) {
$menu_object = $processed_posts[ $menu_object_id ];
}
break;
default:
// Cannot handle this.
return;
}
if ( ! empty( $menu_object ) ) {
update_post_meta( $post_id, '_menu_item_object_id', wp_slash( $menu_object ) );
}
delete_post_meta( $post_id, '_wxr_import_menu_item' );
}
/**
* Remap page ids in imported options
*
* @param array $data Remap data.
* @return void
*/
public function process_options( $data ) {
$options_to_process = array(
'page_on_front',
'page_for_posts',
);
foreach ( $options_to_process as $key ) {
$current = get_option( $key );
if ( ! $current || ! isset( $data[ $current ] ) ) {
continue;
}
update_option( $key, $data[ $current ] );
}
// Update Jet Theme Core conditions
$conditions = get_option( 'jet_site_conditions' );
if ( ! empty( $conditions ) ) {
$new_conditions = array();
foreach ( $conditions as $location => $condition ) {
$new_conditions[ $location ] = array();
foreach ( $condition as $template_id => $rules ) {
if ( isset( $data[ $template_id ] ) ) {
$new_conditions[ $location ][ $data[ $template_id ] ] = $rules;
} else {
$new_conditions[ $location ][ $template_id ] = $rules;
}
}
}
update_option( 'jet_site_conditions', $new_conditions );
}
}
/**
* Remap nav menu ids
*
* @param array $data Remap data.
* @return void
*/
public function process_nav_menu( $data ) {
$locations = get_nav_menu_locations();
if ( empty( $locations ) ) {
return;
}
$new_locations = array();
foreach ( $locations as $location => $id ) {
if ( isset( $data[ $id ] ) ) {
$new_locations[ $location ] = $data[ $id ];
} else {
$new_locations[ $location ] = $id;
}
}
set_theme_mod( 'nav_menu_locations', $new_locations );
}
/**
* Remap menu IDs in widgets
*
* @param array $data Remap data.
* @return void
*/
public function process_nav_menu_widgets( $data ) {
$widget_menus = get_option( 'widget_nav_menu' );
if ( empty( $widget_menus ) ) {
return;
}
$new_widgets = array();
foreach ( $widget_menus as $key => $widget ) {
if ( '_multiwidget' === $key ) {
$new_widgets['_multiwidget'] = $widget;
continue;
}
if ( empty( $widget['nav_menu'] ) ) {
$new_widgets[] = $widget;
continue;
}
$id = $widget['nav_menu'];
if ( isset( $data[ $id ] ) ) {
$widget['nav_menu'] = $data[ $id ];
}
$new_widgets[ $key ] = $widget;
}
update_option( 'widget_nav_menu', $new_widgets );
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Data_Importer_Callbacks
*
* @return object
*/
function jdi_remap_callbacks() {
return Jet_Data_Importer_Callbacks::get_instance();
}
jdi_remap_callbacks();

File diff suppressed because it is too large Load Diff