Submit
Path:
~
/
home
/
getwphos
/
public_html
/
perfumehousedhaka
/
wp-content
/
plugins
/
themesky
/
importer
/
File Content:
importer.php
<?php if( !class_exists('TS_Importer') ){ class TS_Importer{ function __construct(){ add_filter( 'ocdi/plugin_page_title', array($this, 'import_notice') ); add_filter( 'ocdi/plugin_page_setup', array($this, 'import_page_setup') ); add_action( 'ocdi/before_widgets_import', array($this, 'before_widgets_import') ); add_filter( 'ocdi/import_files', array($this, 'import_files') ); add_filter( 'ocdi/regenerate_thumbnails_in_content_import', '__return_false' ); add_action( 'ocdi/after_import', array($this, 'after_import_setup') ); if( wp_doing_ajax() && isset($_POST['action']) && 'ocdi_import_demo_data' == $_POST['action'] ){ add_filter('upload_mimes', array($this, 'allow_upload_font_files')); } } function import_notice( $plugin_title ){ $allowed_html = array( 'a' => array( 'href' => array(), 'target' => array() ) ); ob_start(); ?> <div class="ts-ocdi-notice-info"> <p> <i class="fas fa-exclamation-circle"></i> <span><?php echo wp_kses( __('If you have any problem with importer, please read this article <a href="https://ocdi.com/import-issues/" target="_blank">https://ocdi.com/import-issues/</a> and check your hosting configuration, or contact our support team here <a href="https://skygroup.ticksy.com/" target="_blank">https://skygroup.ticksy.com/</a>.', 'themesky'), $allowed_html ); ?></span> </p> </div> <?php $plugin_title .= ob_get_clean(); return $plugin_title; } function allow_upload_font_files( $existing_mimes = array() ){ $existing_mimes['svg'] = 'font/svg'; return $existing_mimes; } function import_page_setup( $default_settings ){ $default_settings['parent_slug'] = 'themes.php'; $default_settings['page_title'] = esc_html__( 'Yobazar - Import Demo Content' , 'themesky' ); $default_settings['menu_title'] = esc_html__( 'Yobazar Importer' , 'themesky' ); $default_settings['capability'] = 'import'; $default_settings['menu_slug'] = 'yobazar-importer'; return $default_settings; } function before_widgets_import(){ global $wp_registered_sidebars; $file_path = dirname(__FILE__) . '/data/custom_sidebars.txt'; if( file_exists($file_path) ){ $file_url = plugin_dir_url(__FILE__) . 'data/custom_sidebars.txt'; $custom_sidebars = wp_remote_get( $file_url ); $custom_sidebars = maybe_unserialize( trim( $custom_sidebars['body'] ) ); update_option('ts_custom_sidebars', $custom_sidebars); if( is_array($custom_sidebars) && !empty($custom_sidebars) ){ foreach( $custom_sidebars as $name ){ $custom_sidebar = array( 'name' => ''.$name.'' ,'id' => sanitize_title($name) ,'description' => '' ,'class' => 'ts-custom-sidebar' ); if( !isset($wp_registered_sidebars[$custom_sidebar['id']]) ){ $wp_registered_sidebars[$custom_sidebar['id']] = $custom_sidebar; } } } } } function import_files(){ return array( array( 'import_file_name' => 'Demo Import', 'import_file_url' => plugin_dir_url( __FILE__ ) . 'data/content.xml', 'import_widget_file_url' => plugin_dir_url( __FILE__ ) . 'data/widget_data.wie', 'import_redux' => array( array( 'file_url' => plugin_dir_url( __FILE__ ) . 'data/redux.json', 'option_name' => 'yobazar_theme_options', ), ) ) ); } function after_import_setup(){ set_time_limit(0); $this->woocommerce_settings(); $this->menu_locations(); $this->set_homepage(); $this->import_revslider(); $this->change_url(); $this->set_elementor_site_settings(); $this->update_product_category_id_in_homepage_content(); $this->update_mega_menu_content(); $this->update_footer_content(); $this->update_theme_options(); $this->delete_transients(); $this->update_woocommerce_lookup_table(); $this->update_menu_term_count(); } function get_post_by_title($post_title, $post_type = 'page'){ $query = new WP_Query( array( 'post_type' => $post_type ,'title' => $post_title ,'post_status' => 'publish' ,'posts_per_page' => 1 ,'no_found_rows' => true ,'ignore_sticky_posts' => true ,'update_post_term_cache' => false ,'update_post_meta_cache' => false ,'orderby' => 'post_date ID' ,'order' => 'ASC' ) ); if( ! empty( $query->post ) ){ return $query->post; } return null; } /* WooCommerce Settings */ function woocommerce_settings(){ $woopages = array( 'woocommerce_shop_page_id' => 'Shop' ,'woocommerce_cart_page_id' => 'Shopping Cart' ,'woocommerce_checkout_page_id' => 'Checkout' ,'woocommerce_myaccount_page_id' => 'My Account' ); foreach( $woopages as $woo_page_name => $woo_page_title ) { $woopage = $this->get_post_by_title( $woo_page_title ); if( isset( $woopage->ID ) && $woopage->ID ) { update_option($woo_page_name, $woopage->ID); } } if( class_exists('WC_Admin_Notices') ){ WC_Admin_Notices::remove_notice('install'); } delete_transient( '_wc_activation_redirect' ); flush_rewrite_rules(); } /* Menu Locations */ function menu_locations(){ $locations = get_theme_mod( 'nav_menu_locations' ); $menus = wp_get_nav_menus(); if( $menus ){ foreach( $menus as $menu ){ if( $menu->name == 'Main Menu' ){ $locations['primary'] = $menu->term_id; } if( $menu->name == 'Mobile Menu' ){ $locations['mobile'] = $menu->term_id; } } } set_theme_mod( 'nav_menu_locations', $locations ); } /* Set Homepage */ function set_homepage(){ $homepage = $this->get_post_by_title( 'Home' ); if( isset( $homepage->ID ) ){ update_option('show_on_front', 'page'); update_option('page_on_front', $homepage->ID); } } /* Import Revolution Slider */ function import_revslider(){ if ( class_exists( 'RevSliderSliderImport' ) ) { $rev_directory = dirname(__FILE__) . '/data/revslider/'; foreach( glob( $rev_directory . '*.zip' ) as $file ){ $import = new RevSliderSliderImport(); $import->import_slider(true, $file); } } } /* Change url */ function change_url(){ global $wpdb; $wp_prefix = $wpdb->prefix; $import_url = 'https://demo.theme-sky.com/yobazar-import'; $site_url = get_option( 'siteurl', '' ); $wpdb->query("update `{$wp_prefix}posts` set `guid` = replace(`guid`, '{$import_url}', '{$site_url}');"); $wpdb->query("update `{$wp_prefix}posts` set `post_content` = replace(`post_content`, '{$import_url}', '{$site_url}');"); $wpdb->query("update `{$wp_prefix}posts` set `post_title` = replace(`post_title`, '{$import_url}', '{$site_url}') where post_type='nav_menu_item';"); $wpdb->query("update `{$wp_prefix}postmeta` set `meta_value` = replace(`meta_value`, '{$import_url}', '{$site_url}');"); $wpdb->query("update `{$wp_prefix}postmeta` set `meta_value` = replace(`meta_value`, '" . str_replace( '/', '\\\/', $import_url ) . "', '" . str_replace( '/', '\\\/', $site_url ) . "') where `meta_key` = '_elementor_data';"); $option_name = 'yobazar_theme_options'; $option_ids = array( 'ts_logo' ,'ts_logo_mobile' ,'ts_logo_sticky' ,'ts_favicon' ,'ts_custom_loading_image' ,'ts_header_store_notice' ,'ts_header_info' ,'ts_bg_breadcrumbs' ,'ts_prod_placeholder_img' ,'ts_prod_cat_bottom_content' ); $theme_options = get_option($option_name); if( is_array($theme_options) ){ foreach( $option_ids as $option_id ){ if( isset($theme_options[$option_id]) ){ $theme_options[$option_id] = str_replace($import_url, $site_url, $theme_options[$option_id]); } } update_option($option_name, $theme_options); } } /* Set Elementor Site Settings */ function set_elementor_site_settings(){ $id = 0; $args = array( 'post_type' => 'elementor_library' ,'post_status' => 'public' ,'posts_per_page' => 1 ,'orderby' => 'date' ,'order' => 'ASC' /* Date is not changed when import. Use imported post */ ); $posts = new WP_Query( $args ); if( $posts->have_posts() ){ $id = $posts->post->ID; update_option('elementor_active_kit', $id); } if( $id ){ /* Fixed width, space, ... if query does not return the imported post */ $page_settings = get_post_meta($id, '_elementor_page_settings', true); if( !is_array($page_settings) ){ $page_settings = array(); } if( !isset($page_settings['container_width']) ){ $page_settings['container_width'] = array(); } $page_settings['container_width']['unit'] = 'px'; $page_settings['container_width']['size'] = 1230; $page_settings['container_width']['sizes'] = array(); if( !isset($page_settings['space_between_widgets']) ){ $page_settings['space_between_widgets'] = array(); } $page_settings['space_between_widgets']['unit'] = 'px'; $page_settings['space_between_widgets']['size'] = 16; $page_settings['space_between_widgets']['column'] = 16; $page_settings['space_between_widgets']['row'] = 16; $page_settings['space_between_widgets']['sizes'] = array(); update_post_meta($id, '_elementor_page_settings', $page_settings); } /* Use color, font from theme */ update_option('elementor_disable_color_schemes', 'yes'); update_option('elementor_disable_typography_schemes', 'yes'); } /* Update Product Category Id In Homepage Content */ function update_product_category_id_in_homepage_content(){ wp_cache_flush(); global $wpdb; $wp_prefix = $wpdb->prefix; $product_cats = get_terms( array( 'taxonomy' => 'product_cat' ,'hide_empty' => true ,'orderby' => 'count' ,'order' => 'desc' ,'fields' => 'ids' ) ); if( is_array($product_cats) && count($product_cats) > 0 ){ $pages = array( 'Home 5' => array( array('product_cats' => '30') ) ,'Home 6' => array( array('ids' => '15') ,array('ids' => '29') ,array('ids' => '30') ,array('ids' => '17') ) ,'Home 7' => array( array('ids' => '29') ,array('ids' => '15') ,array('ids' => '30') ) ); foreach( $pages as $page_title => $need_replaced_cats ){ $page = $this->get_post_by_title( $page_title ); if( is_object( $page ) ){ $index = 0; foreach( $need_replaced_cats as $need_replaced_cat ){ $key = key($need_replaced_cat); $need_replaced_cat = array_map('trim', explode(',', current($need_replaced_cat))); $num_cat = count( $need_replaced_cat ); $replaced_cats = array(); for( $i = 0; $i < $num_cat; $i++ ){ if( !isset($product_cats[$index]) ){ $index = 0; } $replaced_cats[] = $product_cats[$index]; $index++; } $replaced_cats = array_unique($replaced_cats); $old_string = '"' . $key . '":["' . implode('","', $need_replaced_cat) . '"]'; $new_string = '"' . $key . '":["' . implode('","', $replaced_cats) . '"]'; $wpdb->query("update `{$wp_prefix}postmeta` set `meta_value` = replace(`meta_value`, '" . $old_string . "', '" . $new_string . "') where `meta_key` = '_elementor_data' and post_id=" . $page->ID . ";"); } } } } /* Update special categories */ $pages = array( 'Home' => array( 'ids' => array( '17,31,34,35,36,37' , array( 'Shoes', 'Glasses', 'Shirts', 'Trousers', 'Swimwear', 'Hats' ) ) ) ,'Home 2' => array( 'ids' => array( '17,31,34,35,36,37' , array( 'Shoes', 'Glasses', 'Shirts', 'Trousers', 'Swimwear', 'Hats' ) ) ) ); $loaded_categories = array(); foreach( $pages as $page_title => $cat_ids_names ){ $page = $this->get_post_by_title( $page_title ); if( is_object( $page ) ){ foreach( $cat_ids_names as $key => $cat_id_name ){ $old_ids = explode(',', $cat_id_name[0]); $new_ids = array(); foreach( $cat_id_name[1] as $cat_name ){ $loaded_id = array_search($cat_name, $loaded_categories); if( $loaded_id ){ $new_ids[] = $loaded_id; } else{ $cat = get_term_by('name', $cat_name, 'product_cat'); if( isset($cat->term_id) ){ $new_ids[] = $cat->term_id; $loaded_categories[$cat->term_id] = $cat_name; } } } $old_string = '"' . $key . '":["' . implode('","', $old_ids) . '"]'; $new_string = '"' . $key . '":["' . implode('","', $new_ids) . '"]'; $wpdb->query("update `{$wp_prefix}postmeta` set `meta_value` = replace(`meta_value`, '" . $old_string . "', '" . $new_string . "') where `meta_key` = '_elementor_data' and post_id=" . $page->ID . ";"); } } } } /* Update Mega Menu Content */ function update_mega_menu_content(){ global $wpdb; $wp_prefix = $wpdb->prefix; /* Update Product Category */ $mega_menus = array( 'Shop' => array(29 => 'Men', 15 => 'Women') ); foreach( $mega_menus as $title => $product_cats ){ $mega_menu_post = $this->get_post_by_title( $title, 'ts_mega_menu' ); if( is_object( $mega_menu_post ) ){ foreach( $product_cats as $old_id => $cat_name ){ $cat = get_term_by( 'name', $cat_name, 'product_cat' ); if( isset($cat->term_id) ){ $old_string = '"parent":"' . $old_id . '"'; $new_string = '"parent":"' . $cat->term_id . '"'; $wpdb->query("update `{$wp_prefix}postmeta` set `meta_value` = replace(`meta_value`, '" . $old_string . "', '" . $new_string . "') where `meta_key` = '_elementor_data' and post_id=" . $mega_menu_post->ID . ";"); } } } } /* Update Nav Menu */ $mega_menus = array( 'Pages' => array(83 => 'Pages - Homes', 81 => 'Pages - Shop', 82 => 'Pages - Other') ); foreach( $mega_menus as $title => $menus ){ $mega_menu_post = $this->get_post_by_title( $title, 'ts_mega_menu' ); if( is_object( $mega_menu_post ) ){ foreach( $menus as $old_id => $menu_name ){ $menu = get_term_by( 'name', $menu_name, 'nav_menu' ); if( isset($menu->term_id) ){ $old_string = '"nav_menu":"' . $old_id . '"'; $new_string = '"nav_menu":"' . $menu->term_id . '"'; $wpdb->query("update `{$wp_prefix}postmeta` set `meta_value` = replace(`meta_value`, '" . $old_string . "', '" . $new_string . "') where `meta_key` = '_elementor_data' and post_id=" . $mega_menu_post->ID . ";"); } } } } } /* Update Footer Content */ function update_footer_content(){ global $wpdb; $wp_prefix = $wpdb->prefix; $footers = array( 'Footer 5' => array(29 => 'Men', 15 => 'Women') ,'Footer 4' => array(29 => 'Men', 15 => 'Women') ,'Footer 3' => array(29 => 'Men', 15 => 'Women') ,'Footer 2' => array(29 => 'Men', 15 => 'Women') ,'Footer 1' => array(29 => 'Men') ); foreach( $footers as $title => $product_cats ){ $footer_post = $this->get_post_by_title( $title, 'ts_footer_block' ); if( is_object( $footer_post ) ){ foreach( $product_cats as $old_id => $cat_name ){ $cat = get_term_by( 'name', $cat_name, 'product_cat' ); if( isset($cat->term_id) ){ $old_string = '"parent":"' . $old_id . '"'; $new_string = '"parent":"' . $cat->term_id . '"'; $wpdb->query("update `{$wp_prefix}postmeta` set `meta_value` = replace(`meta_value`, '" . $old_string . "', '" . $new_string . "') where `meta_key` = '_elementor_data' and post_id=" . $footer_post->ID . ";"); } } } } } /* Update Theme Options */ function update_theme_options(){ $option_name = 'yobazar_theme_options'; $theme_options = get_option($option_name); if( !is_array($theme_options) ){ return; } $posts = array( array( 'ts_footer_block' ,'Footer 1' ,'ts_footer_block' ) ,array( 'ts_wishlist_page' ,'Wishlist' ,'page' ) ,array( 'ts_compare_page' ,'Compare' ,'page' ) ); foreach( $posts as $post ){ $key = $post[0]; $post_title = $post[1]; $post_type = $post[2]; $p = $this->get_post_by_title( $post_title, $post_type ); if( isset( $p->ID ) ){ $theme_options[$key] = $p->ID; } } update_option($option_name, $theme_options); } /* Delete transient */ function delete_transients(){ delete_transient('ts_mega_menu_custom_css'); delete_transient('ts_product_deals_ids'); delete_transient('wc_products_onsale'); } /* Update WooCommerce Loolup Table */ function update_woocommerce_lookup_table(){ if( function_exists('wc_update_product_lookup_tables_is_running') && function_exists('wc_update_product_lookup_tables') ){ if( !wc_update_product_lookup_tables_is_running() ){ if( !defined('WP_CLI') ){ define('WP_CLI', true); } wc_update_product_lookup_tables(); } } } /* Update Menu Term Count - Keep this function until One Click Demo Import fixed */ function update_menu_term_count(){ wp_cache_flush(); $args = array( 'taxonomy' => 'nav_menu' ,'hide_empty' => 0 ,'fields' => 'ids' ); $menus = get_terms( $args ); if( is_array($menus) ){ wp_update_term_count_now( $menus, 'nav_menu' ); } } } new TS_Importer(); } ?>
Submit
FILE
FOLDER
Name
Size
Permission
Action
data
---
0755
importer.php
18270 bytes
0644
N4ST4R_ID | Naxtarrr