<?php

/*
**	One Click Installation System
**
**	Rockthemes - XanderRock
**	
**	we use xroc for XanderRock One Click
*/


function xroc_progress($step){
	
	if(isset($step) && !empty($step)){
		$step = json_decode(stripslashes($step), true);
	}else{
		die('error');	
	}
	
	$function_name = 'xroc_'.$step['function'];
	$return = $function_name();

	return $return;
	exit;
}


function xroc_import_xml(){
	
	if(isset($GLOBALS['xroc_demo_details'])){
		$import_filepath = OPTIONS_DIR.'demos/'.$GLOBALS['xroc_demo_details']['dir_name'].'/'.$GLOBALS['xroc_demo_details']['xml_filename'];
		if(!file_exists($import_filepath)) return 'success';
	}
	
	include_once(OPTIONS_DIR.'libs/xml_importer.php');
	$return = xroc_import_xml_ajax();

	if($return){
		return 'success xml';	
	}else{
		return 'error xml';	
	}
}

function xroc_import_backend(){
		
	include_once(OPTIONS_DIR.'rockthemes-to-import-export.php');
	//add_filter( 'intermediate_image_sizes', '__return_empty_array' );
	if(function_exists('rockthemes_to_import_all_predefined_datas_ajax')){
		ob_start();
		rockthemes_to_import_all_predefined_datas_func(array(
			'modules'			=>	array(
				'curvy_slider'			=>	'yes',
				'rock_form_builder'		=>	'yes',
				'rock_page_builder'		=>	'yes',
				'rock_theme_options'	=>	'yes',
				'rock_sidebar'			=>	'yes',
				'wordpress_details'		=>	'yes',
			),
			'curvy_slider'	=>	array(
				'fetch_images'		=>	true
			),
			'rock_theme_options'	=>	array(
				'use_demo_images'	=>	true
			),
		));	
		$return = ob_get_contents();
		ob_get_clean();

		if(strpos($return , 'error') > -1){
			return 'error backend';	
		}else{
			return 'success backed';
		}
	}
}

function xroc_import_wp_config(){

	//Set Permalinks	
	if( 1 == 1 ){
		global $wp_rewrite;
		$wp_rewrite->set_permalink_structure('/%postname%/');
		$wp_rewrite->flush_rules();
	}
	
	//Set Main Nav to the location
	if( 1 == 1 ){
		$menu = get_term_by('name', 'Main Navigation', 'nav_menu');
		if(isset($menu) && $menu){
			$menu_id = $menu->term_id;
	
			$locations = get_theme_mod('nav_menu_locations'); //get the menu locations
			$locations['primary'] = $menu_id; //set our new menu to be the main nav
			set_theme_mod('nav_menu_locations', $locations); //update 
		}
	}
	
	
	//Set Home Page and Blog Page
	if(1 == 1){
		$home = get_page_by_title('Home');
		if($home && isset($home->ID)){
			update_option('page_on_front',$home->ID);
			update_option('show_on_front','page');
		}
		
		// set the blog page
		$blog = get_page_by_title('Blog');
		if($blog && isset($blog->ID)){
			update_option('page_for_posts',$blog->ID);	
		}
	}
	
	$rockthemes_export_settings = maybe_serialize(get_option('rockthemes_export_settings',false));
	if(!empty($rockthemes_export_settings)){
		delete_option('rockthemes_export_settings');	
	}
	
	return 'success config';
}



?>