<?php
add_action('after_setup_theme', 'tycheproperty_theme_setup');
function tycheproperty_theme_setup()
{
	global $wp_version;
	if(!defined('BUNCH_VERSION')) define('BUNCH_VERSION', '1.0');
	if( !defined( 'BUNCH_ROOT' ) ) define('BUNCH_ROOT', get_template_directory().'/');
	if( !defined( 'BUNCH_URL' ) ) define('BUNCH_URL', get_template_directory_uri().'/');	
	include_once get_template_directory() . '/includes/loader.php';
	
	load_theme_textdomain('tycheproperty', get_template_directory() . '/languages');
	//ADD THUMBNAIL SUPPORT
	add_theme_support('post-thumbnails');
	add_theme_support('menus'); //Add menu support
	add_theme_support('automatic-feed-links'); //Enables post and comment RSS feed links to head.
	add_theme_support('widgets'); //Add widgets and sidebar support
	add_theme_support( 'woocommerce' );
	add_theme_support( "title-tag" );
	/*
	 * Switch default core markup for search form, comment form, and comments
	 * to output valid HTML5.
	 */
	add_theme_support( 'html5', array(
		'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
	) );
	/** Register wp_nav_menus */
	if(function_exists('register_nav_menu'))
	{
		register_nav_menus(
			array(
				/** Register Main Menu location header */
				'main_menu' => esc_html__('Main Menu', 'tycheproperty'),
				'topbar_menu' => esc_html__('Topbar Menu', 'tycheproperty'),
			)
		);
	}
	if ( ! isset( $content_width ) ) $content_width = 960;
	add_image_size( 'tycheproperty_235x235', 235, 235, true ); //'235x235 Property Description' 
	add_image_size( 'tycheproperty_370x235', 370, 235, true ); //'370x235 Villa Gallery' 
	add_image_size( 'tycheproperty_770x500', 770, 500, true ); //'770x500 Villa Gallery' 
	add_image_size( 'tycheproperty_370x278', 370, 278, true ); //'370x278 Latest News' 
	add_image_size( 'tycheproperty_336x260', 336, 260, true ); //'336x260 Villa Gallery Two' 
	add_image_size( 'tycheproperty_777x320', 777, 320, true ); //'777x320 Gallery masonery' 
	add_image_size( 'tycheproperty_383x650', 383, 650, true ); //'383x650 Gallery masonery' 
	add_image_size( 'tycheproperty_383x320', 383, 320, true ); //'383x320 Gallery masonery' 
	add_image_size( 'tycheproperty_1170x450', 1170, 450, true ); //'1170x450 Blog Post' 
	add_image_size( 'tycheproperty_954x503', 954, 503, true ); //'954x503 Floor Plan'
	add_image_size( 'tycheproperty_400x267', 400, 267, true ); //'400x267 Floor Plan V2'
	add_image_size( 'tycheproperty_80x80', 80, 80, true ); //'80x80 Recent Post' 
	add_image_size( 'tycheproperty_370x260', 370, 260, true ); //'370x260 Recent Post' 
}
function tycheproperty_widget_init()
{
	global $wp_registered_sidebars;
	$theme_options = _WSH()->option();
	if( class_exists( 'Bunch_Recent_Post_With_Image' ) )register_widget( 'Bunch_Recent_Post_With_Image' );
	if( class_exists( 'Bunch_Twitter' ) )register_widget( 'Bunch_Twitter' );
	
	
	
	register_sidebar(array(
	  'name' => esc_html__( 'Default Sidebar', 'tycheproperty' ),
	  'id' => 'default-sidebar',
	  'description' => esc_html__( 'Widgets in this area will be shown on the right-hand side.', 'tycheproperty' ),
	  'before_widget'=>'<div id="%1$s" class="widget sidebar-widget %2$s">',
	  'after_widget'=>'</div>',
	  'before_title' => '<div class="sidebar-title"><h2>',
	  'after_title' => '</h2></div>'
	));
	register_sidebar(array(
	  'name' => esc_html__( 'Footer Sidebar', 'tycheproperty' ),
	  'id' => 'footer-sidebar',
	  'description' => esc_html__( 'Widgets in this area will be shown in Footer Area.', 'tycheproperty' ),
	  'before_widget'=>'<article id="%1$s"  class="col-lg-3 col-md-3 col-sm-6 col-xs-12 bottom_area_colum_1 wow fadeInUp %2$s">',
	  'after_widget'=>'</article>',
	  'before_title' => '<h3>',
	  'after_title' => '</h3>'
	));
	
	register_sidebar(array(
	  'name' => esc_html__( 'Blog Listing', 'tycheproperty' ),
	  'id' => 'blog-sidebar',
	  'description' => esc_html__( 'Widgets in this area will be shown on the right-hand side.', 'tycheproperty' ),
	  'before_widget'=>'<div id="%1$s" class="widget sidebar-widget %2$s">',
	  'after_widget'=>'</div>',
	  'before_title' => '<div class="sidebar-title"><h2>',
	  'after_title' => '</h2></div>'
	));
	if( !is_object( _WSH() )  )  return;
	$sidebars = tycheproperty_set(tycheproperty_set( $theme_options, 'dynamic_sidebar' ) , 'dynamic_sidebar' ); 
	foreach( array_filter((array)$sidebars) as $sidebar)
	{
		if(tycheproperty_set($sidebar , 'topcopy')) continue ;
		
		$name = tycheproperty_set( $sidebar, 'sidebar_name' );
		
		if( ! $name ) continue;
		$slug = tycheproperty_slug( $name ) ;
		
		register_sidebar( array(
			'name' => $name,
			'id' =>  $slug ,
			'before_widget' => '<div id="%1$s" class="widget sidebar_widget wow fadeInUp %2$s">',
			'after_widget' => "</div>",
			'before_title' => '<h2 class="widget_title">',
			'after_title' => '</h2>',
		) );		
	}
	
	update_option('wp_registered_sidebars' , $wp_registered_sidebars) ;
}
add_action( 'widgets_init', 'tycheproperty_widget_init' );
// Update items in cart via AJAX
add_filter('add_to_cart_fragments', 'tycheproperty_woo_add_to_cart_ajax');
function tycheproperty_woo_add_to_cart_ajax( $fragments ) {
    
	global $woocommerce;
    ob_start();
	
	include get_template_directory() . '/includes/modules/wc_cart.php';
	
	$fragments['li.wc-header-cart'] = ob_get_clean();
	
    return $fragments;
}
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
function tycheproperty_animate_it( $atts, $contents = null )
{
	return include get_template_directory() . '/includes/modules/shortcodes/animate_it.php';
}
function tycheproperty_load_head_scripts() {
	$options = _WSH()->option();
	if ( !is_admin() ) {
    $protocol = is_ssl() ? 'https://' : 'http://';
	$map_path = '?key='.tycheproperty_set($options, 'map_api_key');
	wp_enqueue_script( 'map_api', ''.$protocol.'maps.google.com/maps/api/js'.$map_path, array(), false, false );
	wp_enqueue_script( 'googlemap', get_template_directory_uri().'/js/jquery.gmap.js', array(), false, false );
	}
    }
    add_action( 'wp_enqueue_scripts', 'tycheproperty_load_head_scripts' );
function tycheproperty_bunch_global_variable() {
    global $wp_query;
}
/*----------------------------Enqueue scripts---------------------------------*/
function tycheproperty_enqueue_scripts() {
	//styles
	wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.css' );
	wp_enqueue_style( 'fontawesom', get_template_directory_uri() . '/css/font-awesome.css' );
	wp_enqueue_style( 'flaticon', get_template_directory_uri() . '/css/flaticon.css' );
	wp_enqueue_style( 'animate', get_template_directory_uri() . '/css/animate.css' );
	wp_enqueue_style( 'owl', get_template_directory_uri() . '/css/owl.css' );
	wp_enqueue_style( 'masterslider', get_template_directory_uri() . '/css/masterslider/style/masterslider.css' );
	wp_enqueue_style( 'masterslider-skins', get_template_directory_uri() . '/css/masterslider/skins/default/style.css' );
	wp_enqueue_style( 'masterslider-verticle', get_template_directory_uri() . '/css/masterslider/style/ms-vertical.css' );
	wp_enqueue_style( 'fancybox', get_template_directory_uri() . '/css/jquery.fancybox.css' );
	wp_enqueue_style( 'hover', get_template_directory_uri() . '/css/hover.css' );
	wp_enqueue_style( 'timepicker', get_template_directory_uri() . '/css/jquery.timepicker.css' );
	wp_enqueue_style( 'jquery-ui', get_template_directory_uri() . '/css/jquery-ui/jquery-ui.css' );
	wp_enqueue_style( 'monthly', get_template_directory_uri() . '/css/monthly.css' );
	wp_enqueue_style( 'tycheproperty_main-style', get_stylesheet_uri() );
	wp_enqueue_style( 'tycheproperty_responsive', get_template_directory_uri() . '/css/responsive.css' );
	wp_enqueue_style( 'tycheproperty_custom-style', get_template_directory_uri() . '/css/custom.css' );
	//scripts
	wp_enqueue_script( 'bootstrap', get_template_directory_uri().'/js/bootstrap.min.js', array(), false, true );
	wp_enqueue_script( 'jquery-fancybox', get_template_directory_uri().'/js/jquery.fancybox.pack.js', array(), false, true );
	wp_enqueue_script( 'jquery-fancybox-media', get_template_directory_uri().'/js/jquery.fancybox-media.js', array(), false, true );
	wp_enqueue_script( 'jquery-mixitup', get_template_directory_uri().'/js/mixitup.js', array(), false, true );
	wp_enqueue_script( 'jquery-owl', get_template_directory_uri().'/js/owl.js', array(), false, true );
	wp_enqueue_script( 'isotop', get_template_directory_uri().'/js/isotope.js', array(), false, true );
	wp_enqueue_script( 'map-script', get_template_directory_uri().'/js/map-script.js', array(), false, true );
	wp_enqueue_script( 'gmap', get_template_directory_uri().'/js/jquery.gmap.js', array(), false, true );
	wp_enqueue_script( 'easing', get_template_directory_uri().'/js/jquery.easing.min.js', array(), false, true );
	wp_enqueue_script( 'masterslider', get_template_directory_uri().'/js/masterslider.js', array(), false, true );
	wp_enqueue_script( 'timepicker', get_template_directory_uri().'/js/jquery.timepicker.min.js', array(), false, true );
	wp_enqueue_script( 'jquery-ui-core' );
	wp_enqueue_script( 'monthly', get_template_directory_uri().'/js/monthly.js', array(), false, true );
	wp_enqueue_script( 'wow', get_template_directory_uri().'/js/wow.js', array(), false, true );
	wp_enqueue_script( 'tycheproperty_main_script', get_template_directory_uri().'/js/script.js', array(), false, true );
	
}
add_action( 'wp_enqueue_scripts', 'tycheproperty_enqueue_scripts' );
/*-------------------------------------------------------------*/
function tycheproperty_theme_slug_fonts_url() {
    $fonts_url = '';
 
    /* Translators: If there are characters in your language that are not
    * supported by Lora, translate this to 'off'. Do not translate
    * into your own language.
    */
    $montserrat = _x( 'on', 'Montserrat font: on or off', 'tycheproperty' );
	$bitter = _x( 'on', 'Bitter font: on or off', 'tycheproperty' );
	$open_sans = _x( 'on', 'Open sans font: on or off', 'tycheproperty' );
 	$raleway = _x( 'on', 'Raleway font: on or off', 'tycheproperty' );
 	$roboto = _x( 'on', 'Roboto font: on or off', 'tycheproperty' );
 
    /* Translators: If there are characters in your language that are not
    * supported by Open Sans, translate this to 'off'. Do not translate
    * into your own language.
    */
    $open_sans = _x( 'on', 'Open Sans font: on or off', 'tycheproperty' );
 
    if ( 'off' !== $montserrat || 'off' !== $bitter || 'off' !== $open_sans || 'off' !== $raleway  || 'off' !== $roboto ){
        $font_families = array();
 
        if ( 'off' !== $montserrat ) {
            $font_families[] = 'Montserrat:400,700';
        }
		
		if ( 'off' !== $bitter ) {
            $font_families[] = 'Bitter:400,400italic,700';
        }
		
		if ( 'off' !== $roboto ) {
            $font_families[] = 'Roboto:300,300i,400,400i,500,500i,700,700i';
        }
		
		if ( 'off' !== $raleway ) {
            $font_families[] = 'Raleway:700,800';
        }
 
        if ( 'off' !== $open_sans ) {
            $font_families[] = 'Open Sans:400,400italic,600,300italic,300';
        }
 
        $query_args = array(
            'family' => urlencode( implode( '|', $font_families ) ),
            'subset' => urlencode( 'latin,latin-ext' ),
        );
 
        $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
    }
 
    return esc_url_raw( $fonts_url );
}
function tycheproperty_theme_slug_scripts_styles() {
    wp_enqueue_style( 'theme-slug-fonts', tycheproperty_theme_slug_fonts_url(), array(), null );
}
add_action( 'wp_enqueue_scripts', 'tycheproperty_theme_slug_scripts_styles' );
//on comments of page by default
function tycheproperty_default_comments_on( $data ) {
    if( $data['post_type'] == 'page' ) {
        $data['comment_status'] = 'open';
    }
    return $data;
}
add_filter( 'wp_insert_post_data', 'tycheproperty_default_comments_on' );
//---custome-editor-style
function tycheproperty_add_editor_styles() {
    add_editor_style( 'custom-editor-style.css' );
}
add_action( 'admin_init', 'tycheproperty_add_editor_styles' );