<?php

function stockie_ocdi_import_files() {
	return array(
		array(
			'import_file_name' => 'Engaging Store',
			'preview_url'  => 'https://stockie.colabr.io/demo1',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/01/content.xml',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/01/widgets.json',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/01/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/01/preview.jpg',
		),
		array(
			'import_file_name' => 'Minimal Store',
			'preview_url'  => 'https://stockie.colabr.io/demo2',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/02/content.xml',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/02/widgets.json',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/02/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/02/preview.jpg',
		),
		array(
			'import_file_name' => 'Carousel Store',
			'preview_url'  => 'https://stockie.colabr.io/demo3',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/03/content.xml',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/02/widgets.json',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/03/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/03/preview.jpg',
		),
		array(
			'import_file_name' => 'Fashion Store',
			'preview_url'  => 'https://stockie.colabr.io/demo4',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/04/content.xml',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/04/widgets.json',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/04/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/04/preview.jpg',
		),
		array(
			'import_file_name' => 'Classic Store',
			'preview_url'  => 'https://stockie.colabr.io/demo5',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/05/content.xml',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/02/widgets.json',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/05/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/05/preview.jpg',
		),
		array(
			'import_file_name' => 'Elegant Store',
			'preview_url'  => 'https://stockie.colabr.io/demo6',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/06/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/06/content.php',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/06/widgets.json',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/06/preview.jpg',
		),
		array(
			'import_file_name' => 'Split Slider Store',
			'preview_url'  => 'https://stockie.colabr.io/demo7',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/07/content.xml',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/07/widgets.json',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/07/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/07/preview.jpg',
		),
		array(
			'import_file_name' => 'Traditional Store',
			'preview_url'  => 'https://stockie.colabr.io/demo8',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/08/content.xml',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/08/widgets.json',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/08/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/08/preview.jpg',
		),
		array(
			'import_file_name' => 'Onepage Store',
			'preview_url'  => 'https://stockie.colabr.io/demo9',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/09/content.xml',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/09/widgets.json',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/09/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/09/preview.jpg',
		),
		array(
			'import_file_name' => 'Clean Store',
			'preview_url'  => 'https://stockie.colabr.io/demo10',
			'categories' => array( esc_html__( 'Demo', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/10/content.xml',
			'local_import_widget_file' => trailingslashit( get_template_directory() ) . 'demo/10/widgets.json',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/10/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/10/preview.jpg',
		),
		array(
			'import_file_name' => 'About - Minimal',
			'preview_url'  => 'https://stockie.colabr.io/pages/about-minimal/',
			'categories' => array( esc_html__( 'About', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/about-minimal/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/about-minimal/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/about-minimal/preview.jpg'
		),
		array(
			'import_file_name' => 'About - Classic',
			'preview_url'  => 'https://stockie.colabr.io/pages/about-classic/',
			'categories' => array( esc_html__( 'About', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/about-classic/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/about-classic/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/about-classic/preview.jpg'
		),
		array(
			'import_file_name' => 'About - Extended',
			'preview_url'  => 'https://stockie.colabr.io/pages/about-extended/',
			'categories' => array( esc_html__( 'About', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/about-extended/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/about-extended/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/about-extended/preview.jpg'
		),
		array(
			'import_file_name' => 'About - Studio',
			'preview_url'  => 'https://stockie.colabr.io/pages/about-studio/',
			'categories' => array( esc_html__( 'About', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/about-studio/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/about-studio/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/about-studio/preview.jpg'
		),
		array(
			'import_file_name' => 'Contact - Minimal',
			'preview_url'  => 'https://stockie.colabr.io/pages/contact-minimal/',
			'categories' => array( esc_html__( 'Contact', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/contact-minimal/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/contact-minimal/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/contact-minimal/preview.jpg'
		),
		array(
			'import_file_name' => 'Contact - Classic',
			'preview_url'  => 'https://stockie.colabr.io/pages/contact-classic/',
			'categories' => array( esc_html__( 'Contact', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/contact-classic/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/contact-classic/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/contact-classic/preview.jpg'
		),
		array(
			'import_file_name' => 'Contact - Blocks',
			'preview_url'  => 'https://stockie.colabr.io/pages/contact-blocks/',
			'categories' => array( esc_html__( 'Contact', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/contact-blocks/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/contact-blocks/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/contact-blocks/preview.jpg'
		),
		array(
			'import_file_name' => 'Contact - Extended',
			'preview_url'  => 'https://stockie.colabr.io/pages/contact-extended/',
			'categories' => array( esc_html__( 'Contact', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/contact-extended/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/contact-extended/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/contact-extended/preview.jpg'
		),
		array(
			'import_file_name' => 'Shopping FAQs',
			'preview_url'  => 'https://stockie.colabr.io/shopping-faqs/',
			'categories' => array( esc_html__( 'FAQs', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/shopping-faqs/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/shopping-faqs/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/shopping-faqs/preview.jpg'
		),
		array(
			'import_file_name' => 'Pricing - Classic',
			'preview_url'  => 'https://stockie.colabr.io/pages/pricing-classic/',
			'categories' => array( esc_html__( 'Pricing', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/pricing-classic/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/pricing-classic/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/pricing-classic/preview.jpg'
		),
		array(
			'import_file_name' => 'Pricing - One Page',
			'preview_url'  => 'https://stockie.colabr.io/pages/pricing-one-page/',
			'categories' => array( esc_html__( 'Pricing', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/pricing-one-page/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/pricing-one-page/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/pricing-one-page/preview.jpg'
		),
		// array(
		// 	'import_file_name' => 'Gift - Vouchers',
		// 	'preview_url'  => 'https://stockie.colabr.io/pages/gift-vouchers/',
		// 	'categories' => array( esc_html__( 'Gift', 'stockie' ) ),
		// 	'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/gift-vouchers/content.xml',
		// 	'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/gift-vouchers/content.php',
		// 	'import_preview_image_url' => get_template_directory_uri() . '/demo/gift-vouchers/preview.jpg'
		// ),
		array(
			'import_file_name' => 'Coming Soon',
			'preview_url'  => 'https://stockie.colabr.io/pages/coming-soon/',
			'categories' => array( esc_html__( 'Coming Soon', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/coming-soon/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/coming-soon/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/coming-soon/preview.jpg'
		),
		array(
			'import_file_name' => 'Contact Form 7 - Contact & Subscribe',
			'preview_url'  => '',
			'categories' => array( esc_html__( 'Contact Forms', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/contact-forms/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/contact-forms/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/contact-forms/preview.jpg'
		),
		array(
			'import_file_name' => 'Shortcodes',
			'preview_url'  => '',
			'categories' => array( esc_html__( 'Shortcodes', 'stockie' ) ),
			'local_import_file' => trailingslashit( get_template_directory() ) . 'demo/shortcodes/content.xml',
			'import_execute_file' => trailingslashit( get_template_directory() ) . 'demo/shortcodes/content.php',
			'import_preview_image_url' => get_template_directory_uri() . '/demo/shortcodes/preview.jpg'
		)
	);
}

add_filter( 'pt-ocdi/import_files', 'stockie_ocdi_import_files' );


function stockie_ocdi_after_import_setup( $selected_import ) {
	global $wpdb;

	$front_page_id = get_page_by_title( str_replace( esc_html( '&' ), 'n', $selected_import['import_file_name'] ) );

	if ( $selected_import['import_file_name'] === 'Classic Blog' ) { // i dont know why
		$front_page_id = get_page_by_title( 'Blog Classic' );
	}

	if ( isset( $front_page_id ) and is_object( $front_page_id ) ) {
		update_option( 'show_on_front', 'page' );
		update_option( 'page_on_front', $front_page_id->ID );
	}

	// Set menu
	$main_menu = wp_get_nav_menus();
	if ( is_array( $main_menu ) && count( $main_menu ) > 0 ) {
		$main_menu = $main_menu[0];
	}
	if ( is_object( $main_menu ) ) {
		$locations = get_theme_mod('nav_menu_locations');
		$locations['primary'] = $main_menu->term_id;
		set_theme_mod( 'nav_menu_locations', $locations );
	}

	// VC background images fix
	$site_url = get_site_url();
	$wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->postmeta . ' SET meta_value = REPLACE( meta_value, \'{{this_domain}}\', %s )', $site_url ) );
	$wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->posts . ' SET post_content = REPLACE( post_content, \'{{this_domain}}\', %s )', $site_url ) );

	// Update stockie portfolio categories count
	$wpdb->query( 'UPDATE wp_term_taxonomy SET count = (
	SELECT COUNT(*) FROM wp_term_relationships rel 
		LEFT JOIN wp_posts po ON (po.ID = rel.object_id) 
		WHERE 
			rel.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id 
			AND 
			wp_term_taxonomy.taxonomy NOT IN (\'link_category\')
			AND 
			po.post_status IN (\'publish\', \'future\')' );
}

add_action( 'pt-ocdi/after_import', 'stockie_ocdi_after_import_setup' );