<?php

// Load style.css and Javascripts
add_action('wp_enqueue_scripts', 'tsoft_enqueue_scripts');

function tsoft_enqueue_scripts() {

	// Get Theme Version
	$theme_version = wp_get_theme()->get( 'Version' );

	// Register and Enqueue Stylesheet
	wp_enqueue_style( 'tsoft-info-stylesheet', get_stylesheet_uri(), array(), $theme_version );

	// Register and enqueue navigation.js
	wp_enqueue_script( 'tsoft-info-jquery-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20160719' );

	// Passing Parameters to Navigation.js 
	wp_localize_script( 'tsoft-info-jquery-navigation', 'tsoft_navigation_params', array( 'menuTitle' => esc_html__( 'Menu', 'tsoft-info' ) ) );

	// Register Comment Reply Script for Threaded Comments
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	// Register and Enqueue Font
	wp_enqueue_style( 'tsoft-info-default-fonts', tsoft_fonts_url(), array(), null );

}


/*
* Retrieve Font URL to register default Google Fonts
*/
function tsoft_fonts_url() {
    $fonts_url = '';

	// Get Theme Options from Database
	$theme_options = tsoft_theme_options();

	// Only embed Google Fonts if not deactivated
	if ( ! ( isset($theme_options['deactivate_google_fonts']) and $theme_options['deactivate_google_fonts'] == true ) ) :

		// Set Default Fonts
		$font_families = array('Carme:400,700', 'Francois One');

		// Set Google Font Query Args
		$query_args = array(
			'family' => urlencode( implode( '|', $font_families ) ),
			'subset' => urlencode( 'latin,latin-ext' ),
		);

		// Create Fonts URL
		$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );

	endif;

	return apply_filters( 'tsoft_google_fonts_url', $fonts_url );

}


// Setup Function: Registers support for various WordPress features
add_action( 'after_setup_theme', 'tsoft_setup' );

function tsoft_setup() {

	// Set Content Width
	global $content_width;
	if ( ! isset( $content_width ) )
		$content_width = 675;

	// init Localization
	load_theme_textdomain('tsoft-info', get_template_directory() . '/languages' );

	// Add Theme Support
	add_theme_support('post-thumbnails');
	add_theme_support('automatic-feed-links');
	add_theme_support('title-tag');
	add_editor_style();

	// Add Custom Background
	add_theme_support('custom-background', array('default-color' => 'f0f0f0'));

	// Set up the WordPress core custom logo feature
	add_theme_support( 'custom-logo', apply_filters( 'tsoft_custom_logo_args', array(
		'height' => 40,
		'width' => 250,
		'flex-height' => true,
		'flex-width' => true,
	) ) );

	// Add Custom Header
	add_theme_support('custom-header', array(
		'header-text' => false,
		'width'	=> 1320,
		'height' => 240,
		'flex-height' => true));

	// Add Theme Support for wooCommerce
	add_theme_support( 'woocommerce' );

	// Register Navigation Menus
	register_nav_menus( array(
		'primary'   => esc_html__( 'Main Navigation', 'tsoft-info' ),
		'secondary' => esc_html__( 'Top Navigation', 'tsoft-info' ),
		)
	);

	// Add Theme Support for Selective Refresh in Customizer
	add_theme_support( 'customize-selective-refresh-widgets' );

}

// Add custom Image Sizes
add_action( 'after_setup_theme', 'tsoft_add_image_sizes' );

function tsoft_add_image_sizes() {

	// Add Custom Header Image Size
	add_image_size( 'featured-header-image', 1320, 240, true);

	// Add Featured Image Size
	add_image_size( 'post-thumbnail', 375, 210, true);

	// Add Featured Image Size
	add_image_size( 'featured-content', 460, 220, true);

}


// Register Sidebars
add_action( 'widgets_init', 'tsoft_register_sidebars' );
function tsoft_register_sidebars() {

	// Register Sidebars
	register_sidebar( array(
		'name' => esc_html__( 'Sidebar', 'tsoft-info' ),
		'id' => 'sidebar',
		'description' => esc_html__( 'Appears on posts and pages except the full width template.', 'tsoft-info' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widgettitle"><span>',
		'after_title' => '</span></h3>',
	));

}

/**
  Whether the checkbox is checked (tsoft_theme_options)
 */
function tsoft_sanitize_checkbox( $checked ) {

	// Boolean check.
	return ( ( isset( $checked ) && true == $checked ) ? true : false );
	
}




/*==================================== INCLUDE FILES ====================================*/

// include Theme Customizer Options
require( get_template_directory() . '/inc/customizer.php' );
require( get_template_directory() . '/inc/default.php' );

// include Template Functions
require( get_template_directory() . '/inc/template.php' );

