<?php

add_action('hook_new_install','_newinstall');
function _newinstall(){ global $CORE, $wpdb; 

// THEME
$GLOBALS['theme_defaults']['template'] 		= "template_dealer_theme";

// WEBSITE LOGO
$GLOBALS['theme_defaults']['logo_text1'] 	= "DEALER THEME";
$GLOBALS['theme_defaults']['logo_text2'] 	= "Buy and Sell Cars Online With This Theme.";
$GLOBALS['theme_defaults']['logo_icon'] 	= "2";

// EXTRA DEMO CONTENT
$GLOBALS['theme_defaults']['hdata'] = array( 
"t1" => array("title1" => "Looking for a Car?", "title2" => "We've got a great range of cars available to buy now!"  ),
"t2" => array("title1" => "Want to sell a Car?", "title2" => "Add your car FREE to our website today!"  ),

"t3" => array(
"img1" => get_template_directory_uri()."/templates/".$GLOBALS['CORE_THEME']['template']."/img/slide1.jpg",
"img2" => get_template_directory_uri()."/templates/".$GLOBALS['CORE_THEME']['template']."/img/slide2.jpg",
),

); 

// CONTENT LAYOUT / SINGLE LAYOUT
$GLOBALS['theme_defaults']['content_layout'] = "listing-dealer";
$GLOBALS['theme_defaults']['single_layout'] = "listing-dealer";

// GOOGLE
$GLOBALS['theme_defaults']['google_required'] = 1;	

// HEADER STYLE
$GLOBALS['theme_defaults']['layout_header'] = 6;

// SET MENU
$GLOBALS['theme_defaults']['layout_menu'] = 2;

// GRID LAYOUT
$GLOBALS['theme_defaults']["display"] = array("default_gallery_style" => "grid"); 

// 5. DEFAULT TEMPLATE DATA
		$GLOBALS['theme_defaults']['widgetobject']["text"]["0"] = array(
			"fullw" => "yes",
			"autop" => "no",
			"text" => '<div class="row">

	<div class="col-md-8">
		
	 <img src="'.get_template_directory_uri()."/templates/".$GLOBALS['theme_defaults']['template'].'/img/demo/slide2.jpg"> 	
		
	</div>
	 
	<div class="col-md-4">	
	
		<div class="bannerboxside">
		
			<div><a href=\''.home_url().'/?s=\'><h1>Looking for a Car?</h1> <p>We\'ve got a great range of cars available to buy now! </p>  </a></div>  
			 
			<div  class="last alt2"><a href="'.$GLOBALS['CORE_THEME']['links']['add'].'"><h1>Want to sell a Car?</h1><p>Add your car FREE to our website today!</p></a>	</div>
			
		</div>	
		
	</div>
</div>
[CARTYPES]'); 
		
 
		
		$GLOBALS['theme_defaults']['widgetobject']["tabs"][2] 	= array(
		"title1" => "Featured Products",
		"query1" => "&order=asc&posts_per_page=8",
		"title2" => "Recently Added",
		"query2" => "&order=desc",
		"fullw" => "yes"
		); 		
		
		// ADD IN CUSTOM WIDGET BLOCK
		$GLOBALS['theme_defaults']['widgetobject']["text"]["3"] = array(
			"fullw" => "yes",
			"text" => '<div class="block"><div class="block-title"> <h3>Browse by Manufacturer </h3> </div>[MAKERS]</div>',			 
		); 
 	
		$GLOBALS['theme_defaults']['homepage']['widgetblock1'] = 'text_0,text_1,tabs_2,text_3';	 

 
$GLOBALS['theme_defaults']['itemcode'] 		= '[IMAGE][price]  
<h2>[TITLE]</h2>
<p> [miles] / [transmission]  / <span class="hidden_details"> [engine] [ctype] /</span> [petrol]</p>	
<div class="hidden_details">
[ICON id="map-marker"] [LOCATION]	
<hr />
[EXCERPT]	 
</div>   
<hr /><div class="right hidden_details">[FAVS]</div>[DISTANCE]'; 

update_option('wlt_reset_itemcode', $GLOBALS['theme_defaults']['itemcode']);


$GLOBALS['theme_defaults']['listingcode']		= '<h1>[TITLE-NOLINK] [price]</h1>
<p class="ebits"> [DISTANCE info=0] [miles]  [transmission]  [engine] [ctype]  [petrol]</p>	
<hr style="margin-top:0px;">
<div class="row">
<div class="col-md-6">[IMAGES]</div>        
<div class="col-md-6"> 
	[EXCERPT size="400" end="..."]	 
</div>
</div>
<div class="clearfix"></div>
[BTNBAR]
<ul class="nav nav-tabs navstyle1" id="Tabs">
  <li class="active"><a href="#t1" data-toggle="tab"><i class="fa fa-edit"></i> Description</a></li>
  <li><a href="#t4" data-toggle="tab"><i class="fa fa-comments"></i> Comments</a></li>
</ul> 
<div class="tab-content"><div class="tab-pane active" id="t1">[CONTENT] <h3><i class="fa fa-dashboard"></i> Vehicle Details</h3>[CARDETAILS]<h3> [ICON id="map-marker"] Location</h3><p>[LOCATION]</p>[GOOGLEMAP] </div>
<div class="tab-pane" id="t4">[COMMENTS]</div>  
</div> 
<h3 class="related">Related Vehicles</h3>[CAROUSEL related=true]'; 

update_option('wlt_reset_listingcode', $GLOBALS['theme_defaults']['listingcode']);

register_taxonomy( 'make', THEME_TAXONOMY.'_type', array( 'hierarchical' => true, 'labels' => array('name' => 'Make') , 'query_var' => true, 'rewrite' => true, 'rewrite' => array('slug' => 'make') ) );  
register_taxonomy( 'model', THEME_TAXONOMY.'_type', array( 'hierarchical' => true, 'labels' => array('name' => 'Model') , 'query_var' => true, 'rewrite' => true, 'rewrite' => array('slug' => 'model') ) );  

 
// 5. REINSTALL THE SAMPLE DATA CATEGORIES 
$new_cat_array = array("Acura","Alfa Romeo", "Austin Martin","Audi","Austin","Bentley","BMW","Bugatti","Buick","Cadillac","Chevrolet","Chrysler","Citroen","Daewoo","Dodge","Ferrari","Fiat","Ford","GMC","Honda","Hummer","Hyundai","Infiniti","Isuzu","Jaguar","Jeep","Kia", "Lamborghini","Lancia","Land Rover","Lexus", "Lincoln","Lotus", "Maserati","Maybach","Mazda","Mercedes-Benz","MG","Mini","Mitsubishi","Morgan", "Nissan","Oldsmobile", "Peugeot", "Pontiac","Porsche","Proton","Reliant","Renault","Riley","Rolls-Royce","Rover","Saab","Seat","Skoda","Smart","Ssangyong","Subaru","Suzuki","Talbot","Tata","Toyota","Trabant","Triumph","TVR","Vauxhall","Volkswagen","Volvo","Denza","extra2");
 
foreach($new_cat_array as $cat ){

	if ( is_term( $cat , 'make' ) ){	
		$term = get_term_by('slug', $cat, 'make');		 
		$nparent  = $term->term_id;
		$saved_cats_array[] = $term->term_id;
		
		// add in icon for this cat		
		$GLOBALS['theme_defaults']['category_icon_'.$nparent] = THEME_URI."/templates/".$GLOBALS['theme_defaults']['template']."/logos/".strtolower(str_replace(" ","-",$cat))."-logo-1.jpg";
		 
			
	}else{
	
		$cat_id = wp_insert_term($cat, 'make', array('cat_name' => $cat ));
	 
		if(!is_object($cat_id) && isset($cat_id['term_id'])){
		$saved_cats_array[] = $cat_id['term_id'];
		$nparent = $cat_id['term_id'];
		}else{
		$saved_cats_array[] = $cat_id->term_id;
		$nparent = $cat_id->term_id;
		}			
		// add in icon for this cat		
		$GLOBALS['theme_defaults']['category_icon_'.$nparent] = THEME_URI."/templates/".$GLOBALS['theme_defaults']['template']."/logos/".strtolower(str_replace(" ","-",$cat))."-logo-1.jpg";
		 
		$ff++; 
	}
 
}


$new_inner_array = array(

"Acura" => array("MDX","NSX","RL","RSX","TL","TSX"),
"Alfa Romeo" => array("145","146","147","155","156","159","1600","164","166","2000","2300","2600","33","75","8C","90","Alfasud","Alfetta","Brera","Crosswagon","Giulia","Giulietta","GT","GTA","GTV","MiTo","RZ/SZ","Spider","Sprint"),
"Alpina" => array("B10","B12","B3","B5","B6","B7","B8","D10","D3","Roadster S"),

"Aston Martin" => array("AR1","DB","DB7","DB9","DBS","Lagonda","Rapide","V12 Vanquish","V8","V8 Vantage","Vanquish","Vantage","Virage","Volante"),
"Audi" => array("100","200","80","90","A1","A2","A3","A4","A5","A6","A7","A8","Allroad","Cabriolet","Coupe","Q3","Q5","Q7","Quattro","R8","RS2","RS4","RS5","RS6","S2","S3","S4","S5","S6","S8","TT","V8"),
"Austin" => array("1100","1500","2000","Allegro","Ambassador","Maxi","Maxi 2","Princess"),
"Bentley" => array("Arnage","Azure","Brooklands","Continental","Eight","Mulsanne","Turbo R","Turbo RT","Turbo S"),
"BMW" => array("1 Series","1500","1600","1800","2000","2600","3 Series","5 Series","6 Series","7 Series","8 Series","M Series","M1","X1","X3","X5","X6","Z1","Z3","Z4","Z8"),
"Buick" => array("Century","Electra","LeSabre","Park Avenue","Regal","Riviera","Roadmaster","Sabre","Skylark"),

"Citroen" => array("2 CV","2000","2400","AX","Berlingo","BX","C-Crosser","C-Zero","C1","C2","C3","C3 Picasso","C4","C4 Picasso","C5","C6","C8","CX","Dispatch","DS","DS3","Dyane","Evasion","GS","GSA","Jumpy","LNA","Nemo Multispace","Saxo","SM","SM Maserati","Synergie","Visa","Xantia","XM","Xsara","Xsara Picasso","ZX"),

"Mercedes-Benz" => array("123","180","190","190-Series","200","212","220","230","240","250","260","270","280","280C","290","300","320","350","380","400","416","420","450","500","560","600 Series","A-Class","B-Class","C-Class","Cabriolet","CE 200","CE 220","CE 300","CL-Class","CLC-Class","CLK-Class","E-Class","G-Wagen","GL-Class","ML-Class","R-Class","S-Class","SL-Class","SLK-Class","SLR","Sprinter","V-Class","Vaneo","Vario","Viano","Vito"),


);
 
foreach($new_inner_array as $key=>$inner){
 
	$cat_id = wp_insert_term($key, 'model', array('cat_name' => $key ));
	foreach($inner as $in){
	
	if(!is_object($cat_id) && isset($cat_id['term_id'])){
		wp_insert_term($in, 'model', array('cat_name' => $in, 'parent' => $cat_id['term_id'] ));
	}else{
		wp_insert_term($in, 'model', array('cat_name' => $in, 'parent' => $cat_id->term_id ));
	}
	
	 
	}
} 




// 6. INSTALL THE SAMPLE DATA LISTINGS
 
		$fields = array(
		"price"			=> array('100000','1500','2000','3000','4000','5000','6000','7000','10000'),	 
		"ctype" 		=> array(2,3,4,5,6,7,8,9,10,12),		 
		"year" 			=> array('2000','2009','2010','2014'),
		"miles" 		=> array('10000','20000','30000'),
		"exterior" 		=> array('blue', 'green', 'red', ),
		"interior" 		=> array('Leather','White Leather', 'Plastic'),
		"drive" 		=> array(1,2),
		"transmission" 	=> array(1,2,3),
		"petrol" 		=> array(1,2),
		"engine" 		=> array("1L","1.6L","3L","6L","1.2L","2L"),	
		);

$i=1;
while($i < 16){
 
	$my_post = array();
	$my_post['post_title'] 		= "Example Car ".$i;
	$my_post['post_content'] 	= "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus eleifend risus ut congue. Pellentesque nec lacus elit. Pellentesque convallis nisi ac augue pharetra eu tristique neque consequat. Mauris ornare tempor nulla, vel sagittis diam convallis eget.</p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus eleifend risus ut congue. Pellentesque nec lacus elit. Pellentesque convallis nisi ac augue pharetra eu tristique neque consequat. Mauris ornare tempor nulla, vel sagittis diam convallis eget.</p><blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p><small>Someone famous <cite title='Source Title'>Source Title</cite></small>
</blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus eleifend risus ut congue. Pellentesque nec lacus elit. Pellentesque convallis nisi ac augue pharetra eu tristique neque consequat. Mauris ornare tempor nulla, vel sagittis diam convallis eget.</p><dl class='dl-horizontal'>
				<dt>Description lists</dt>
				<dd>A description list is perfect for defining terms.</dd>
				<dt>Euismod</dt>
				<dd>Vestibulum id ligula porta felis euismod semper eget lacinia odio sem nec elit.</dd>
				<dd>Donec id elit non mi porta gravida at eget metus.</dd>
				<dt>Malesuada porta</dt>
				<dd>Etiam porta sem malesuada magna mollis euismod.</dd>
				<dt>Felis euismod semper eget lacinia</dt>
				<dd>Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</dd>
			  </dl>";
	$my_post['post_type'] 		= THEME_TAXONOMY."_type";
	$my_post['post_status'] 	= "publish";
	$my_post['post_category'] 	= "";
	$my_post['tags_input'] 		= "";
	$POSTID 					= wp_insert_post( $my_post );	
 
	add_post_meta($POSTID, "image", get_template_directory_uri()."/framework/img/demo/noimage.png");
	
	add_post_meta($POSTID, "featured", "no");
	
	foreach($fields as $k => $t){
		if(is_array($t)){		
		$ig = array_rand($t,1);
		add_post_meta($POSTID, $k, $t[$ig]);
		}else{
		add_post_meta($POSTID, $k, $t);
		}	
	}
	
	// UPDATE CAT LIST
	wp_set_post_terms( $POSTID, $saved_cats_array, THEME_TAXONOMY );
	
	$i++;		
} 
 

} 

?>