<?php

/*-----------------------------------------------------------------------------------*/
/* Enqueu scripts */
/*-----------------------------------------------------------------------------------*/   

if (!function_exists('nomad_press_enqueue_scripts')) {

	function nomad_press_enqueue_scripts() {
        
		wp_deregister_style('google-fonts');
		wp_deregister_style('avventura-lite-style' );
		
        wp_enqueue_style('avventura-lite-parent-style' , get_template_directory_uri() . '/style.css' ); 
		wp_enqueue_style('nomad-press-style' , get_stylesheet_directory_uri() . '/style.css' ); 

        wp_enqueue_style(
			'nomad-press-' . esc_attr(get_theme_mod('avventura_lite_skin', 'orange')),
			get_stylesheet_directory_uri() . '/assets/skins/' . esc_attr(get_theme_mod('avventura_lite_skin', 'orange')) . '.css',
			array( 'nomad-press-style' ),
			'1.0.0'
		); 
		
        $googleFontsArgs = array(
			'family' =>    str_replace('|', '%7C', nomad_press_google_font_args()),
			'subset' =>    'latin,latin-ext'
		);

		wp_enqueue_style('google-fonts', add_query_arg ( $googleFontsArgs, "https://fonts.googleapis.com/css" ), array(), '1.0.0' );

		wp_enqueue_script(
			'jquery-marquee',
			get_stylesheet_directory_uri() . '/assets/js/jquery.marquee.js',
			array('jquery'),
			'2.3.4',
			TRUE
		);

		wp_enqueue_script(
			'nomad-press-template',
			get_stylesheet_directory_uri() . '/assets/js/template.js',
			array('jquery'),
			'1.0.0', 
			TRUE
		);

	}
	
	add_action( 'wp_enqueue_scripts', 'nomad_press_enqueue_scripts', 999);

}

/*-----------------------------------------------------------------------------------*/
/* Customize preview init */
/*-----------------------------------------------------------------------------------*/ 

if (!function_exists('nomad_press_customize_preview_init')) {

	function nomad_press_customize_preview_init() {

		wp_enqueue_script(
			'nomad-press-customizer-preview',
			get_stylesheet_directory_uri() . '/core/assets/js/customizer.js',
			array(
				'jquery',
				'customize-preview'
			),
			'',
			true
		);

	}

	add_action ('customize_preview_init' , 'nomad_press_customize_preview_init');

}

/*-----------------------------------------------------------------------------------*/
/* Replace hooks */
/*-----------------------------------------------------------------------------------*/ 

if (!function_exists('nomad_press_replace_hooks')) {

	function nomad_press_replace_hooks() {
	
		remove_action('avventura_lite_mobile_menu', 'avventura_lite_mobile_menu_function');
		remove_action('avventura_lite_top_sidebar', 'avventura_lite_top_sidebar_function');
		remove_action('avventura_lite_slick_slider', 'avventura_lite_slick_slider_function');
		remove_action('avventura_lite_thumbnail', 'avventura_lite_thumbnail_function');
		remove_action('avventura_lite_before_content', 'avventura_lite_before_content_function' );

		remove_action( 'avventura_lite_default_format', 'avventura_lite_default_format_function' );
		remove_action( 'avventura_lite_image_format', 'avventura_lite_image_format_function' );
		remove_action( 'avventura_lite_page_format', 'avventura_lite_page_format_function' );
		remove_action( 'woocommerce_before_main_content', 'avventura_lite_woocommerce_before_main_content');

    }
	
	add_action('init','nomad_press_replace_hooks', 9999);

}

/*-----------------------------------------------------------------------------------*/
/* Woocommerce before content */
/*-----------------------------------------------------------------------------------*/ 

if (!function_exists('nomad_press_woocommerce_before_main_content')) {

	function nomad_press_woocommerce_before_main_content() { 
	
		if ( is_product() ) {
			
			$classes = "product-wrapper" ;
	
		} else {
	
			$classes = "product-wrapper products-list" ;
	
		}
		
		get_sidebar('top');
		get_sidebar('header');
		get_template_part('core/templates/breadcrumb'); 

?>
	
	<div class="container">
	
		<div class="row">
		
			<div class="<?php echo avventura_lite_template('span') . " " . avventura_lite_template('sidebar') . " " . $classes; ?>" >
	
<?php
	
	}
	
	add_action('woocommerce_before_main_content', 'nomad_press_woocommerce_before_main_content');

}

/*-----------------------------------------------------------------------------------*/
/* Replace hooks */
/*-----------------------------------------------------------------------------------*/ 

if (!function_exists('nomad_press_mobile_menu_function')) {

	function nomad_press_mobile_menu_function() {

?>

        <div id="sidebar-wrapper">
            
            <div id="scroll-sidebar" class="clearfix">

                <div class="wrap">

                	<a class="mobile-navigation" href="#modal-sidebar">
                		<i class="fa fa-times open"></i>
                	</a>
                	
	                <div class="mobilemenu-box">
					
                        <nav id="mobilemenu">
                        
                            <?php
                                            
                                wp_nav_menu(
                                    
                                    array(
                                        'theme_location' => 'main-menu', 
                                        'container' => 'false',
                                        'depth' => 3
                                    )
                                
                                );
                            
								if ( has_nav_menu( 'secondary-menu' ) ) :

									wp_nav_menu(

										array(
											'theme_location' => 'secondary-menu',
											'container' => 'false',
											'depth' => 3
										)

									);

								endif;

                            ?>
                        
                        </nav> 
					
                    </div>

					<div class="post-article">
			
						<div class="copyright">
								
							<p>
							
								<?php 
								
									echo esc_html__('Copyright ','nomad-press') . esc_html(get_bloginfo("name")) . " " . date("Y");
									echo ' | <a href="' . esc_url('https://www.themeinprogress.com/') . '" target="_blank">' . sprintf(esc_html__('Theme by %s', 'nomad-press'), 'ThemeinProgress') . '</a>';
									echo ' | <a href="' . esc_url('http://wordpress.org/') . '" title="' . esc_attr__('A Semantic Personal Publishing Platform', 'nomad-press') . '" rel="generator">' . sprintf(esc_html__('Proudly powered by %s', 'nomad-press'), 'WordPress') . '</a>';
		
								?> 
								
							</p>
									
						</div>
			
					</div>

            	</div>

            </div>
        
        </div>
        
<?php
	
	}

	add_action( 'nomad_press_mobile_menu', 'nomad_press_mobile_menu_function' );

}


/*-----------------------------------------------------------------------------------*/
/* Get categories */
/*-----------------------------------------------------------------------------------*/ 

if (!function_exists('nomad_press_get_categories')) {

	function nomad_press_get_categories($first_element = 'none') {

		if ( $first_element == 'none') {
			$return['none'] = esc_attr__( 'None','nomad-press');
		} else {
			$return['all'] = esc_attr__( 'All categories','nomad-press');
		}

		$args = array(
			'taxonomy' => 'category',
			'hide_empty' => true,
		);


		foreach ( get_terms($args) as $cat) {
			$return[$cat->term_id] = $cat->name;
		}
		
		return $return;

	}

}

/*-----------------------------------------------------------------------------------*/
/* Get current date */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('nomad_press_get_current_date')) {

	function nomad_press_get_current_date() {

		$date_format = esc_attr(avventura_lite_setting('nomad_press_topbar_date_format', 'l, F j Y'));

		if ( strtotime(wp_date($date_format)) ) {
			$current_date = wp_date($date_format);
		} else {
			$current_date = wp_date('l, F j Y');
		}

		return $current_date;

	}

}

/*-----------------------------------------------------------------------------------*/
/* Customize register */
/*-----------------------------------------------------------------------------------*/   

if (!function_exists('nomad_press_customize_register')) {

	function nomad_press_customize_register( $wp_customize ) {

		$wp_customize->remove_section( 'slideshow_section');

		$wp_customize->remove_setting( 'avventura_lite_sticky_header');
		$wp_customize->remove_control( 'avventura_lite_sticky_header');

		$wp_customize->remove_setting( 'avventura_lite_header_layout');
		$wp_customize->remove_control( 'avventura_lite_header_layout');

		$wp_customize->remove_setting( 'avventura_lite_post_icon');
		$wp_customize->remove_control( 'avventura_lite_post_icon');

		$wp_customize->remove_setting( 'avventura_lite_view_category_title');
		$wp_customize->remove_control( 'avventura_lite_view_category_title');

		$wp_customize->remove_setting( 'avventura_lite_view_searched_item');
		$wp_customize->remove_control( 'avventura_lite_view_searched_item');

		$wp_customize->remove_setting( 'avventura_lite_view_readmore');
		$wp_customize->remove_control( 'avventura_lite_view_readmore');

		$wp_customize->remove_control( 'avventura_lite_menu_font_weight');
		$wp_customize->remove_control( 'avventura_lite_titles_font_weight');

		$wp_customize->remove_section( 'pagewidth_section');

		$wp_customize->remove_control( 'avventura_lite_screen1');
		$wp_customize->remove_control( 'avventura_lite_screen1');

		$wp_customize->remove_control( 'avventura_lite_screen2');
		$wp_customize->remove_control( 'avventura_lite_screen2');

		$wp_customize->remove_control( 'avventura_lite_screen3');
		$wp_customize->remove_control( 'avventura_lite_screen3');

		$wp_customize->remove_control( 'avventura_lite_screen4');
		$wp_customize->remove_control( 'avventura_lite_screen4');

		/**
		* Site identity > Site identity > Hide Tagline option
		*/

		$wp_customize->add_setting( 'nomad_press_hide_tagline', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));
		
		$wp_customize->add_control( 'nomad_press_hide_tagline', array(
			'label' => esc_html__( 'Hide Tagline','nomad-press'),
			'section' => 'title_tagline',
			'type' => 'checkbox',
		));

		/**
		* Colors > Header text option
		*/

		$wp_customize->add_setting( 'nomad_press_header_text_color', array(
			'default' => '#616161',
			'sanitize_callback' => 'sanitize_hex_color',
		));

		$wp_customize->add_control( 'nomad_press_header_text_color' , array(
			'type' => 'color',
			'section' => 'colors',
			'label' => esc_html__('Header text color','nomad-press'),
			'description' => esc_html__('Choose the header text color.','nomad-press'),
		));

		/* Main settings panel > Topbar section
		========================================================================== */

		$wp_customize->add_section( 'nomad_press_topbar_section', array(
			'title' => esc_html__( 'Topbar','nomad-press'),
			'description' => esc_html__( 'From this section you can manage the topbar.','nomad-press'),
			'panel' => 'general_panel',
			'priority' => 8,
		));

		/**
		* Main settings panel > Topbar section > Date format option
		*/

		$wp_customize->add_setting( 'nomad_press_topbar_date_format', array(
			'default' => 'l, F j Y',
			'sanitize_callback' => 'sanitize_text_field',
		));

		$wp_customize->add_control( 'nomad_press_topbar_date_format' , array(
			'type' => 'text',
			'section' => 'nomad_press_topbar_section',
			'label' => esc_html__( 'Date format','nomad-press'),
			'description' => sprintf(
				wp_kses(
					__( '<a href="%s" target="_blank">To format the date, please refer to the online documentation for detailed instructions</a>.', 'nomad-press' ),
					array( 'a' => array( 'href' => array(), 'target' => array() ) )
				),
				esc_url( 'https://wordpress.org/support/article/formatting-date-and-time' )
			),
		));

		/**
		* Main settings panel > Topbar section > Header search form option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_header_search_form', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh',
		));
		
		$wp_customize->add_control( 'nomad_press_enable_header_search_form', array(
			'label' => esc_html__( 'Header search form','nomad-press'),
			'description' => esc_html__( 'Would you like to show the header search form?','nomad-press'),
			'section' => 'nomad_press_topbar_section',
			'type' => 'checkbox',
		));

		/* Typography panel > Google Fonts section
		========================================================================== */

		$wp_customize->add_section( 'nomad_press_fonts', array(
			'title' => esc_html__( 'Google Fonts','nomad-press'),
			'panel' => 'typography_panel',
			'priority' => 9,
			'description' => esc_html__('From this section you can select one of the 17 Google Fonts included with Nomad Press','nomad-press'),
		));

		/**
		 * Typography panel > Google Fonts section > Site font option
		 */

		$wp_customize->add_setting( 'nomad_press_body_font_family', array(
			'default' => 'Josefin+Sans:100,100italic,300,300italic,400,400italic,600,600italic,700,700italic',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));

		$wp_customize->add_control( 'nomad_press_body_font_family' , array(
			'priority' => 9,
			'type' => 'select',
			'section' => 'nomad_press_fonts',
			'label' => esc_html__('Site font','nomad-press'),
			'description' => esc_html__('Choose the font for your website.','nomad-press'),
			'choices' => nomad_press_google_fonts(),
		));
        
		/**
		 * Typography panel > Menu section > Menu weight
		 */

        $wp_customize->add_control( 'avventura_lite_menu_font_weight' , array(
			'type' => 'select',
			'section' => 'menu_section',
			'label' => esc_html__('Menu weight.', 'nomad-press'),
			'description' => esc_html__('Choose a font weight for the menu', 'nomad-press'),
            'choices' => array(
                '100' => esc_html__( '100','nomad-press'),
                '300' => esc_html__( '300','nomad-press'),
                '400' => esc_html__( '400','nomad-press'),
                '600' => esc_html__( '600','nomad-press'),
                '700' => esc_html__( '700','nomad-press'),
            ),
		));
        
		/**
		 * Typography panel > Menu section > Titles weight
		 */

        $wp_customize->add_control( 'avventura_lite_titles_font_weight' , array(
			'type' => 'select',
			'section' => 'headlines_section',
			'label' => esc_html__('Titles weight', 'nomad-press'),
			'description' => esc_html__('Choose a font weight for the titles.', 'nomad-press'),
            'choices' => array(
                '100' => esc_html__( '100','nomad-press'),
                '300' => esc_html__( '300','nomad-press'),
                '400' => esc_html__( '400','nomad-press'),
                '600' => esc_html__( '600','nomad-press'),
                '700' => esc_html__( '700','nomad-press'),
            ),
		));

		/* Main settings panel > Featured posts section
		========================================================================== */

		$wp_customize->add_section('nomad_press_featured_posts_section', array(
			'title' => esc_html__( 'Featured posts', 'nomad-press' ),
			'description' => esc_html__( 'From this section you can manage the featured posts on the homepage', 'nomad-press' ),
			'panel' => 'general_panel',
			'priority' => 10,

		));

		/**
		* Main settings panel > Featured posts section > Enable featured posts option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_featured_posts', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh',
		));
		
		$wp_customize->add_control( 'nomad_press_enable_featured_posts', array(
			'label' => esc_html__( 'Enable featured posts','nomad-press'),
			'description' => esc_html__( 'Would you like to enable the featured posts on the homepage?', 'nomad-press' ),
			'section' => 'nomad_press_featured_posts_section',
			'type' => 'checkbox',
		));

		/**
		* Main settings panel > Featured posts section > Featured posts only on the first page of pagination option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_featured_posts_only_first_page_pagination', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh',
		));
		
		$wp_customize->add_control( 'nomad_press_enable_featured_posts_only_first_page_pagination', array(
			'label' => esc_html__( 'Featured posts only on the first page of pagination','nomad-press'),
			'description' => esc_html__( 'Would you like to show the featured posts only on the first page of pagination on your homepage? Enable this option to display the featured posts exclusively on the first page.', 'nomad-press' ),
			'section' => 'nomad_press_featured_posts_section',
			'type' => 'checkbox',
		));

	   /**
	   * Main settings panel > Featured posts section > Main column - Label option
		*/

		$wp_customize->add_setting( 'nomad_press_main_column_label', array(
			'default' => esc_html__('Recent','nomad-press'),
			'sanitize_callback' => 'sanitize_text_field',
		));
 
		$wp_customize->add_control( 'nomad_press_main_column_label' , array(
			'type' => 'text',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Main column &raquo; Label','nomad-press'),
			'description' => esc_html__('Please insert the label of the main column','nomad-press'),
		));

	   /**
		* Main settings panel > Featured posts section > Main column - Post category option
		*/

		$wp_customize->add_setting( 'nomad_press_main_column_posts_category', array(
			'default' => 'all',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));
 
		$wp_customize->add_control( 'nomad_press_main_column_posts_category' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Main column &raquo; Post category','nomad-press'),
			'description' => esc_html__('Please select the category for featured posts in the main column.','nomad-press'),
			'choices'  => nomad_press_get_categories('all'),
		));

		/**
		* Main settings panel > Featured posts section > Main column - Sort articles option
		*/

		$wp_customize->add_setting( 'nomad_press_main_column_posts_orderby', array(
			'default' => 'date',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));

		$wp_customize->add_control( 'nomad_press_main_column_posts_orderby' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Main column &raquo; Sort articles','nomad-press'),
			'description' => esc_html__('How you want to order the articles in the main column?','nomad-press'),
			'choices' => array (
				'ID' => esc_html__( 'ID','nomad-press'),
				'author' => esc_html__( 'Author','nomad-press'),
				'title' => esc_html__( 'Post title','nomad-press'),
				'date' => esc_html__( 'Date','nomad-press'),
				'comment_count' => esc_html__( 'Number of comments','nomad-press'),
			),
		));

		/**
		* Main settings panel > Featured posts section > Main column - Order articles option
		*/

		$wp_customize->add_setting( 'nomad_press_main_column_posts_sort_order', array(
			'default' => 'desc',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));

		$wp_customize->add_control( 'nomad_press_main_column_posts_sort_order' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Main column &raquo; Order articles','nomad-press'),
			'description' => esc_html__('Select whether to sort articles in ascending (oldest to newest) or descending (newest to oldest) order in the main column','nomad-press'),
			'choices' => array (
				'asc' => esc_html__( 'Ascending','nomad-press'),
				'desc' => esc_html__( 'Descending','nomad-press'),
			),
		));

		/**
		 * Main settings panel > Featured posts section > Main column - Post limit option
		 */
 
		$wp_customize->add_setting( 'nomad_press_main_column_posts_limit', array(
			'sanitize_callback' => 'nomad_press_limit_sanitize',
			'default' => 5,
		));
 
		$wp_customize->add_control( 'nomad_press_main_column_posts_limit' , array(
			'type' => 'number',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Main column &raquo; Post limit','nomad-press'),
			'description' => esc_html__('Please set the limit of articles in the main column.','nomad-press'),
			'input_attrs' => array(
				'min' => 1,
			),
		));

		/**
		* Main settings panel > Featured posts section > Main column - Slider transition option
		*/

		$wp_customize->add_setting( 'nomad_press_main_column_slider_transition', array(
			'default' => 'fade',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));

		$wp_customize->add_control( 'nomad_press_main_column_slider_transition' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Main column &raquo; Slider transition','nomad-press'),
			'description' => esc_html__('Select the type of transition effect for the slider in the main column','nomad-press'),
			'choices' => array (
				'fade' => esc_html__( 'Fade', 'nomad-press' ),
				'slide' => esc_html__( 'Slide', 'nomad-press' ),
			),
		));

	   /**
	   * Main settings panel > Featured posts section > Main column - Post author label option
		*/

		$wp_customize->add_setting( 'nomad_press_featured_posts_post_author_label', array(
			'default' => esc_html__('By','nomad-press'),
			'sanitize_callback' => 'sanitize_text_field',
		));
 
		$wp_customize->add_control( 'nomad_press_featured_posts_post_author_label' , array(
			'type' => 'text',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Main column &raquo; Post author label','nomad-press'),
			'description' => esc_html__('Insert the label of post author','nomad-press'),
		));

	   /**
	   * Main settings panel > Featured posts section > Secondary column - Label option
		*/

		$wp_customize->add_setting( 'nomad_press_secondary_column_label', array(
			'default' => esc_html__('Oldest post','nomad-press'),
			'sanitize_callback' => 'sanitize_text_field',
		));
 
		$wp_customize->add_control( 'nomad_press_secondary_column_label' , array(
			'type' => 'text',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Secondary column &raquo; Label','nomad-press'),
			'description' => esc_html__('Please insert the label of the secondary column','nomad-press'),
		));

	   /**
		* Main settings panel > Featured posts section > Secondary column - Post category option
		*/

		$wp_customize->add_setting( 'nomad_press_secondary_column_posts_category', array(
			'default' => 'all',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));
 
		$wp_customize->add_control( 'nomad_press_secondary_column_posts_category' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Secondary column &raquo; Post category','nomad-press'),
			'description' => esc_html__('Please select the category for featured posts in the secondary column.','nomad-press'),
			'choices'  => nomad_press_get_categories('all'),
		));

		/**
		* Main settings panel > Featured posts section > Secondary column - Sort articles option
		*/

		$wp_customize->add_setting( 'nomad_press_secondary_column_posts_orderby', array(
			'default' => 'date',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));

		$wp_customize->add_control( 'nomad_press_secondary_column_posts_orderby' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Secondary column &raquo; Sort articles','nomad-press'),
			'description' => esc_html__('How you want to order the articles in the secondary column?','nomad-press'),
			'choices' => array (
				'ID' => esc_html__( 'ID','nomad-press'),
				'author' => esc_html__( 'Author','nomad-press'),
				'title' => esc_html__( 'Post title','nomad-press'),
				'date' => esc_html__( 'Date','nomad-press'),
				'comment_count' => esc_html__( 'Number of comments','nomad-press'),
			),
		));

		/**
		* Main settings panel > Featured posts section > Secondary column - Order articles option
		*/

		$wp_customize->add_setting( 'nomad_press_secondary_column_posts_sort_order', array(
			'default' => 'asc',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));

		$wp_customize->add_control( 'nomad_press_secondary_column_posts_sort_order' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Secondary column &raquo; Order articles','nomad-press'),
			'description' => esc_html__('Select whether to sort articles in ascending (oldest to newest) or descending (newest to oldest) order in the secondary column','nomad-press'),
			'choices' => array (
				'asc' => esc_html__( 'Ascending','nomad-press'),
				'desc' => esc_html__( 'Descending','nomad-press'),
			),
		));

		/**
		 * Main settings panel > Featured posts section > Secondary column - Post limit option
		 */
 
		$wp_customize->add_setting( 'nomad_press_secondary_column_posts_limit', array(
			'sanitize_callback' => 'nomad_press_limit_sanitize',
			'default' => 8,
		));
 
		$wp_customize->add_control( 'nomad_press_secondary_column_posts_limit' , array(
			'type' => 'number',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Secondary column &raquo; Post limit','nomad-press'),
			'description' => esc_html__('Please set the limit of articles in the secondary column','nomad-press'),
			'input_attrs' => array(
				'min' => 1,
			),
		));

	   /**
	   * Main settings panel > Featured posts section > Side column - Label option
		*/

		$wp_customize->add_setting( 'nomad_press_side_column_label', array(
			'default' => esc_html__('Popular','nomad-press'),
			'sanitize_callback' => 'sanitize_text_field',
		));
 
		$wp_customize->add_control( 'nomad_press_side_column_label' , array(
			'type' => 'text',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Side column &raquo; Label','nomad-press'),
			'description' => esc_html__('Please insert the label of side column','nomad-press'),
		));

	   /**
		* Main settings panel > Featured posts section > Side column - Post category option
		*/

		$wp_customize->add_setting( 'nomad_press_side_column_posts_category', array(
			'default' => 'all',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));
 
		$wp_customize->add_control( 'nomad_press_side_column_posts_category' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Side column &raquo; Post category','nomad-press'),
			'description' => esc_html__('Please select the category for featured posts in the side column','nomad-press'),
			'choices'  => nomad_press_get_categories('all'),
		));

		/**
		* Main settings panel > Featured posts section > Side column - Sort articles option
		*/

		$wp_customize->add_setting( 'nomad_press_side_column_posts_orderby', array(
			'default' => 'comment_count',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));

		$wp_customize->add_control( 'nomad_press_side_column_posts_orderby' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Side column &raquo; Sort articles','nomad-press'),
			'description' => esc_html__('How you want to order the articles in the side column?','nomad-press'),
			'choices' => array (
				'ID' => esc_html__( 'ID','nomad-press'),
				'author' => esc_html__( 'Author','nomad-press'),
				'title' => esc_html__( 'Post title','nomad-press'),
				'date' => esc_html__( 'Date','nomad-press'),
				'comment_count' => esc_html__( 'Number of comments','nomad-press'),
			),
		));

		/**
		* Main settings panel > Featured posts section > Side column - Order articles option
		*/

		$wp_customize->add_setting( 'nomad_press_side_column_posts_sort_order', array(
			'default' => 'desc',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));

		$wp_customize->add_control( 'nomad_press_side_column_posts_sort_order' , array(
			'type' => 'select',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Side column &raquo; Order articles','nomad-press'),
			'description' => esc_html__('Select whether to sort articles in ascending (oldest to newest) or descending (newest to oldest) order in the side column','nomad-press'),
			'choices' => array (
				'asc' => esc_html__( 'Ascending','nomad-press'),
				'desc' => esc_html__( 'Descending','nomad-press'),
			),
		));

		/**
		 * Main settings panel > Featured posts section > Side column - Post limit option
		 */
 
		$wp_customize->add_setting( 'nomad_press_side_column_posts_limit', array(
			'sanitize_callback' => 'nomad_press_limit_sanitize',
			'default' => 8,
		));
 
		$wp_customize->add_control( 'nomad_press_side_column_posts_limit' , array(
			'type' => 'number',
			'section' => 'nomad_press_featured_posts_section',
			'label' => esc_html__('Side column &raquo; Post limit','nomad-press'),
			'description' => esc_html__('Please set the limit of articles in the side column','nomad-press'),
			'input_attrs' => array(
				'min' => 1,
			),
		));

		/* Main settings panel > Nomad Press newsticker section
		========================================================================== */

		$wp_customize->add_section('nomad_press_newsticker', array(
			'title' => esc_html__( 'Newsticker', 'nomad-press' ),
			'description' => esc_html__('From this section you can manage the news ticker','nomad-press'),
			'panel' => 'general_panel',
			'priority' => 9,
		));

	   /**
		* Main settings panel > Nomad Press newsticker section > Enable news ticker option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_news_ticker', array(
			'default' => 'on',
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));

		$wp_customize->add_control( 'nomad_press_enable_news_ticker' , array(
			'type' => 'checkbox',
			'section' => 'nomad_press_newsticker',
			'label' => esc_html__('News ticker','nomad-press'),
			'description' => esc_html__('Do you want to enable the news ticker?','nomad-press'),
		));

	   /**
	   * Main settings panel > Nomad Press newsticker section > News ticker title option
		*/

		$wp_customize->add_setting( 'nomad_press_news_ticker_title', array(
			'default' => esc_html__('HOT','nomad-press'),
			'sanitize_callback' => 'sanitize_text_field',
		));
 
		$wp_customize->add_control( 'nomad_press_news_ticker_title' , array(
			'type' => 'text',
			'section' => 'nomad_press_newsticker',
			'label' => esc_html__('News ticker title','nomad-press'),
			'description' => esc_html__('Insert the title for the news ticker','nomad-press'),
		));
 
	   /**
		* Main settings panel > Nomad Press newsticker section > News ticker category option
		*/

		$wp_customize->add_setting( 'nomad_press_news_ticker_category', array(
			'default' => 'all',
			 'sanitize_callback' => 'nomad_press_select_sanitize',
		));
 
		$wp_customize->add_control( 'nomad_press_news_ticker_category' , array(
			'type' => 'select',
			'section' => 'nomad_press_newsticker',
			'label' => esc_html__('News ticker category','nomad-press'),
			'description' => esc_html__('Please select the category of the news ticker.','nomad-press'),
			'choices'  => nomad_press_get_categories('all'),
		));
 
		/**
		* Main settings panel > Nomad Press newsticker section > News ticker order option
		 */
 
		$wp_customize->add_setting( 'nomad_press_news_ticker_order', array(
			'default' => 'date',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));
 
		$wp_customize->add_control( 'nomad_press_news_ticker_order' , array(
			'type' => 'select',
			'section' => 'nomad_press_newsticker',
			'label' => esc_html__('News ticker order by','nomad-press'),
			'description' => esc_html__('How you want to order the articles?.','nomad-press'),
			'choices'  => array (
				'title' => esc_html__( 'Post title','nomad-press'),
				'rand' => esc_html__( 'Randomly','nomad-press'),
				'comment_count' => esc_html__( 'Comment count','nomad-press'),
				'date' => esc_html__( 'Post date','nomad-press'),
			),
		));
 
		/**
		* Main settings panel > Nomad Press newsticker section > News ticker sort order option
		 */
 
		$wp_customize->add_setting( 'nomad_press_news_ticker_sort_order', array(
			'default' => 'desc',
			'sanitize_callback' => 'nomad_press_select_sanitize',
		));
 
		$wp_customize->add_control( 'nomad_press_news_ticker_sort_order' , array(
			'type' => 'select',
			'section' => 'nomad_press_newsticker',
			'label' => esc_html__('News ticker sort order','nomad-press'),
			'description' => esc_html__('Select the order of the articles.','nomad-press'),
			'choices'  => array (
				'asc' => esc_html__( 'Ascending','nomad-press'),
				'desc' => esc_html__( 'Descending','nomad-press'),
			),
		));
 
		/**
		 * Main settings panel > Nomad Press newsticker section > News ticker limit option
		 */
 
		$wp_customize->add_setting( 'nomad_press_news_ticker_limit', array(
			'sanitize_callback' => 'nomad_press_limit_sanitize',
			'default' => 5,
		));
 
		$wp_customize->add_control( 'nomad_press_news_ticker_limit' , array(
			'type' => 'number',
			'section' => 'nomad_press_newsticker',
			'label' => esc_html__('News ticker post limit','nomad-press'),
			'description' => esc_html__('Please set the max items for the news ticker.','nomad-press'),
			'input_attrs' => array('min' => 1)
		));

		/**
		* Main settings panel > General settings section > Enable breadcrumb option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_breadcrumb', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));
		
		$wp_customize->add_control( 'nomad_press_enable_breadcrumb', array(
			'priority' => 1,
			'label' => esc_html__( 'Enable the breadcrumb','nomad-press'),
			'description' => esc_html__('Would you like to enable the breadcrumb on whole website (except the homepage)?','nomad-press'),
			'section' => 'settings_section',
			'type' => 'checkbox',
		));

		/**
		* Main settings panel > General settings section > Enable post category option
		*/

		$wp_customize->add_setting( 'nomad_press_view_category_title', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));
		
		$wp_customize->add_control( 'nomad_press_view_category_title', array(
			'priority' => 2,
			'label' => esc_html__( 'Category title','nomad-press'),
			'description' => esc_html__('Do you want to view the category title?','nomad-press'),
			'section' => 'settings_section',
			'type' => 'checkbox',
		));

		/**
		* Main settings panel > General settings section > Enable post category option
		*/

		$wp_customize->add_setting( 'nomad_press_view_searched_item', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));
		
		$wp_customize->add_control( 'nomad_press_view_searched_item', array(
			'priority' => 3,
			'label' => esc_html__( 'Searched item','nomad-press'),
			'description' => esc_html__('Do you want to view the searched item?','nomad-press'),
			'section' => 'settings_section',
			'type' => 'checkbox',
		));

		/* Main settings panel > Single post section
		========================================================================== */

		$wp_customize->add_section('nomad_press_post_single_post_section', array(
			'title' => esc_html__( 'Single post', 'nomad-press' ),
			'description' => esc_html__( 'From this section, you can manage (show or hide) various elements within individual posts, such as the category, publication date, author, etc.', 'nomad-press' ),
			'panel' => 'general_panel',
			'priority' => 13,

		));

		/**
		* Main settings panel > Single post section > Enable post category option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_post_category', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));
		
		$wp_customize->add_control( 'nomad_press_enable_post_category', array(
			'label' => esc_html__( 'Show post category','nomad-press'),
			'section' => 'nomad_press_post_single_post_section',
			'type' => 'checkbox',
		));

		/**
		* Main settings panel > Single post section > Enable post icon option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_post_icon', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));
		
		$wp_customize->add_control( 'nomad_press_enable_post_icon', array(
			'label' => esc_html__( 'Show post icon','nomad-press'),
			'section' => 'nomad_press_post_single_post_section',
			'type' => 'checkbox',
		));

		/**
		* Main settings panel > Single post section > Enable post date option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_post_date', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));
		
		$wp_customize->add_control( 'nomad_press_enable_post_date', array(
			'label' => esc_html__( 'Show post date','nomad-press'),
			'section' => 'nomad_press_post_single_post_section',
			'type' => 'checkbox',
		));

		/**
		* Main settings panel > Single post section > Enable post author option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_post_author', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));
		
		$wp_customize->add_control( 'nomad_press_enable_post_author', array(
			'label' => esc_html__( 'Show author','nomad-press'),
			'section' => 'nomad_press_post_single_post_section',
			'type' => 'checkbox',
		));

		/**
		* Main settings panel > Single post section > Post author label
		 */

		$wp_customize->add_setting( 'nomad_press_post_author_label', array(
			'default' => esc_html__(' by ','nomad-press'),
			'sanitize_callback' => 'sanitize_text_field',
		));

		$wp_customize->add_control( 'nomad_press_post_author_label' , array(
			'type' => 'text',
			'section' => 'nomad_press_post_single_post_section',
			'label' => esc_html__('Post author label','nomad-press'),
			'description' => esc_html__( 'Replace the default label','nomad-press'),
		));

		/**
		* Main settings panel > Single post section > Enable related posts option
		*/

		$wp_customize->add_setting( 'nomad_press_enable_related_posts', array(
			'default' => true,
			'sanitize_callback' => 'nomad_press_checkbox_sanize',
			'transport'  => 'refresh'
		));
		
		$wp_customize->add_control( 'nomad_press_enable_related_posts', array(
			'label' => esc_html__( 'Show related posts','nomad-press'),
			'section' => 'nomad_press_post_single_post_section',
			'type' => 'checkbox',
		));

		/**
		* Main settings panel > Single post section > Related posts label
		 */

		 $wp_customize->add_setting( 'nomad_press_related_posts_label', array(
			'default' => esc_html__('You may also like','nomad-press'),
			'sanitize_callback' => 'sanitize_text_field',
		));

		$wp_customize->add_control( 'nomad_press_related_posts_label' , array(
			'type' => 'text',
			'section' => 'nomad_press_post_single_post_section',
			'label' => esc_html__('Related posts section label','nomad-press'),
			'description' => esc_html__( 'Replace the default label','nomad-press'),
		));

		function nomad_press_select_sanitize ($value, $setting) {
		
			global $wp_customize;
					
			$control = $wp_customize->get_control( $setting->id );
				 
			if ( array_key_exists( $value, $control->choices ) ) {
					
				return $value;
					
			} else {
					
				return $setting->default;
					
			}
			
		}

		function nomad_press_checkbox_sanize( $input ) {
			return $input ? true : false;
		}

		function nomad_press_limit_sanitize($value, $setting) {

			global $wp_customize;

			$getSetting = $wp_customize->get_setting($setting->id);
			$newValue = ($value <= 0) ? $getSetting->default : absint($value);
			return $newValue;

		}

	}
	
	add_action( 'customize_register', 'nomad_press_customize_register', 11 );

}

/*-----------------------------------------------------------------------------------*/
/* Theme setup */
/*-----------------------------------------------------------------------------------*/ 

if (!function_exists('nomad_press_theme_setup')) {

	function nomad_press_theme_setup() {

		load_child_theme_textdomain( 'nomad-press', get_stylesheet_directory() . '/languages' );

		register_nav_menu( 'secondary-menu', esc_html__( 'Secondary Menu', 'nomad-press' ) );
		
        require_once( trailingslashit( get_stylesheet_directory() ) . 'core/functions/function-style.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/functions/google-fonts.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/post/featured-posts/horizontal-featured-posts.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/post/featured-posts/vertical-featured-posts.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/post/featured-posts/vertical-list-featured-posts.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/post/related-post.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/templates/media.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/templates/post-icon.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/templates/before-content.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/templates/after-content.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/post-formats/default-format.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/post-formats/image-format.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/post-formats/page-format.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/templates/related-posts.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/templates/top-section.php' );
		require_once( trailingslashit( get_stylesheet_directory() ) . 'core/sidebars/top-sidebar.php' );

		if ( !get_theme_mod('avventura_lite_logo_font_size') )
			set_theme_mod( 'avventura_lite_logo_font_size', '50px' );

		if ( !get_theme_mod('avventura_lite_menu_font_weight') )
			set_theme_mod( 'avventura_lite_menu_font_weight', '700' );

		if ( !get_theme_mod('avventura_lite_titles_font_weight') )
			set_theme_mod( 'avventura_lite_titles_font_weight', '700' );

		if ( !get_theme_mod('background_color') )
			set_theme_mod( 'background_color', 'ffffff' );

		add_image_size( 'nomad_press_related_post', 600, 400, true );
		add_image_size( 'nomad_press_featured_post_large', 549, 410, true );
		add_image_size( 'nomad_press_featured_post_small', 89, 89, true );

    }

	add_action( 'after_setup_theme', 'nomad_press_theme_setup', 999);

}

/*-----------------------------------------------------------------------------------*/
/* Nomad Press Is Archive */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('nomad_press_is_archive')) {

	function nomad_press_is_archive() {

		if ( 
			is_category() ||
			is_tag() ||
			is_author() ||
			is_year() ||
			is_month()
			
		) {
		
			return true;
		
		} else {
		
			return false;
		
		}

	}

}

/*-----------------------------------------------------------------------------------*/
/* Theme setup */
/*-----------------------------------------------------------------------------------*/ 

if (!function_exists('nomad_press_widgets_init')) {

	function nomad_press_widgets_init() {

		unregister_sidebar('avventura-lite-scroll-widget-area');

	}

	add_action( 'widgets_init', 'nomad_press_widgets_init', 999);

}

/*-----------------------------------------------------------------------------------*/
/* Function to check if the searchform.php file is loaded inside a sidebar area */
/*-----------------------------------------------------------------------------------*/

if ( ! function_exists( 'nomad_press_is_sidebar_area' ) ) {

	function nomad_press_is_sidebar_area() {

		$result = false;

		$activeSidebars = array(
			'avventura_lite_side_sidebar',
			'avventura_lite_top_sidebar',
			'avventura_lite_header_sidebar',
			'avventura_lite_bottom_sidebar',
			'avventura_lite_ooter_sidebar'
		);

		if ( in_array(current_filter(), $activeSidebars) ) {
			$result = true;
		}

		return $result;

	}

}

/*-----------------------------------------------------------------------------------*/
/* BODY CLASSES */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('nomad_press_body_classes_function')) {

	function nomad_press_body_classes_function($classes) {

		if ( 
			is_home() ||
			nomad_press_is_archive() ||
			is_search()
		) :

			$classes[] = 'nomad_press_archives';

		endif;

		if (
			( 
				!get_background_image() &&
				get_theme_mod('background_color','ffffff') == 'ffffff'
			)
		) :

			$classes[] = 'is_minimal_layout';

		endif;

		return $classes;

	}

	add_filter('body_class', 'nomad_press_body_classes_function');

}

?>
