<?php
/**
 * Ratio Lite functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Ratio_Lite
 */

if ( ! function_exists( 'ratio_lite_setup' ) ) :
	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */
	function ratio_lite_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Ratio Lite, use a find and replace
		 * to change 'ratio-lite' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'ratio-lite', get_template_directory() . '/languages' );

		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );

		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */
		add_theme_support( 'title-tag' );

		/*
		 * Enable support for Post Thumbnails on posts and pages.
		 *
		 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		 */
		add_theme_support( 'post-thumbnails' );
		add_image_size( 'ratio_lite_image_840_430', 840,430, true );

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( array(
			'menu-1' => esc_html__( 'Primary', 'ratio-lite' ),
		) );

		/*
		 * 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',
		) );

		// Set up the WordPress core custom background feature.
		add_theme_support( 'custom-background', apply_filters( 'ratio_lite_custom_background_args', array(
			'default-color' => 'ffffff',
			'default-image' => '',
		) ) );

		// Heading Image Size
		  add_theme_support( 'custom-header', apply_filters( 'ratio_lite_custom_header_args', array(
				'width'                  => 1200,
				'height'                 => 240,
				'flex-height'            => true,
			) ) );		
		
		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );

		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support( 'custom-logo', array(
			'height'      => 250,
			'width'       => 250,
			'flex-width'  => true,
			'flex-height' => true,
		) );
	}
	add_editor_style( array( 'css/editor-style.css', ratio_lite_google_fonts_url() ) );
endif;
add_action( 'after_setup_theme', 'ratio_lite_setup' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function ratio_lite_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'ratio_lite_content_width', 640 );
}
add_action( 'after_setup_theme', 'ratio_lite_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function ratio_lite_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar', 'ratio-lite' ),
		'id'            => 'sidebar-1',
		'description'   => esc_html__( 'Add widgets here.', 'ratio-lite' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
}
add_action( 'widgets_init', 'ratio_lite_widgets_init' );


/**
 * Register Google Fonts
 */
function ratio_lite_google_fonts_url() {
	$fonts_url = '';
	
	/* Translators: If there are characters in your language that are not
	* supported by Hind, translate this to 'off'. Do not translate
	* into your own language.
	*/
	$hind = esc_html_x( 'on', 'Hind font: on or off', 'ratio-lite' );

	/* Translators: If there are characters in your language that are not
	* supported by Montserrat, translate this to 'off'. Do not translate
	* into your own language.
	*/
	
	$montserrat = esc_html_x( 'on', 'Montserrat font: on or off', 'ratio-lite' );
	
	if ( 'off' !== $hind || 'off' !== $montserrat ) {
	$font_families = array();
	 
	if ( 'off' !== $hind ) {
	$font_families[] = 'Hind:400,500,600,700';
	}
	 
	
	if ( 'off' !== $montserrat ) {
	$font_families[] = 'Montserrat:400,700';
	}
	 
	$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 );	
}

/**
 * Enqueue scripts and styles.
 */
function ratio_lite_scripts() {
	//Load Css Files
	wp_enqueue_style( 'ratio-lite-google-fonts', ratio_lite_google_fonts_url(), array(), null );	
	wp_enqueue_style('bootstrap' , get_template_directory_uri(). '/css/bootstrap.css');
	wp_enqueue_style('font-awesome' , get_template_directory_uri(). '/css/font-awesome.css');
	wp_enqueue_style('themify-icons' , get_template_directory_uri(). '/css/themify-icons.css');
	wp_enqueue_style('meanmenu' , get_template_directory_uri(). '/css/meanmenu.css');
	wp_enqueue_style( 'ratio-lite-style', get_stylesheet_uri() );

	wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.js', array('jquery'), '6857', true );
	
	wp_enqueue_script( 'jquery.meanmenu.min', get_template_directory_uri() . '/js/jquery.meanmenu.js', array('jquery'), '6857', true );
	
	wp_enqueue_script( 'ratio-lite-main', get_template_directory_uri() . '/js/main.js', array('jquery'), '6857', true );
	
	

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'ratio_lite_scripts' );


function ratio_wp_kses($val){
	return wp_kses($val, array(
	
	'p' => array(),
	'span' => array(),
	'div' => array(),
	'strong' => array(),
	'b' => array(),
	'br' => array(),
	'h1' => array(),
	'h2' => array(),
	'h3' => array(),
	'h4' => array(),
	'h5' => array(),
	'h6' => array(),
	'a'=> array('href' => array(),'target' => array()),
	'iframe'=> array('src' => array(),'height' => array(),'width' => array()),
	
	), '');
}

function ratio_lite_main_menu() {
		wp_nav_menu( array(
			'theme_location'    => 'menu-1',
			'depth'             => 5,
			'container'         => false,
			'menu_class'        => 'nav navbar-nav navbar-right',	
		)
	); 	
}

function ratio_lite_mobile_menu() {
		wp_nav_menu( array(
			'theme_location'    => 'menu-1',
			'depth'             => 5,
			'container'         => false,	
		)
	); 	

}


// modify search widget
function ratio_lite_my_search_form( $form ) {
	$form = '
		<div class="form-group search-input">
			<div class="search_form">
				<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url(home_url( '/' )) . '" >
				<input type="text" value="' . get_search_query() . '" name="s" id="s" class="form-control search_field" placeholder="' . esc_attr__('Search...' , 'ratio-lite') .'">
				</form>
			</div>
		</div>
        ';
	return $form;
}
add_filter( 'get_search_form', 'ratio_lite_my_search_form' );

// comment box title change
add_filter( 'comment_form_defaults', 'ratio_lite_remove_comment_form_allowed_tags' );
function ratio_lite_remove_comment_form_allowed_tags( $defaults ) {

	$defaults['comment_notes_after'] = '';
	$defaults['comment_notes_before'] = '';
	return $defaults;

}

function ratio_lite_comment_reform ($arg) {

$arg['title_reply'] = esc_html__('Write your comment Here','ratio-lite');
$arg['comment_field'] = '<div class="row"><div class="form-group col-md-12"><textarea id="comment" class="comment_field form-control" name="comment" cols="77" rows="3" placeholder="'. esc_attr__("Write your Comment", "ratio-lite").'" aria-required="true"></textarea></div></div>';


return $arg;

}
add_filter('comment_form_defaults','ratio_lite_comment_reform');

// comment form modify

function ratio_lite_modify_comment_form_fields($fields){
	$commenter = wp_get_current_commenter();
	$req	   = get_option( 'require_name_email' );

	$fields['author'] = '<div class="row"><div class="form-group col-md-4"><input type="text" name="author" id="author" value="'. esc_attr( $commenter['comment_author'] ) .'" placeholder="'. esc_attr__("Your Name *", "ratio-lite").'" size="22" tabindex="1"'. ( $req ? 'aria-required="true"' : '' ).' class="input-name form-control" /></div>';

	$fields['email'] = '<div class="form-group col-md-4"><input type="text" name="email" id="email" value="'. esc_attr( $commenter['comment_author_email'] ) .'" placeholder="'.esc_attr__("Your Email *", "ratio-lite").'" size="22" tabindex="2"'. ( $req ? 'aria-required="true"' : '' ).' class="input-email form-control"  /></div>';
	
	$fields['url'] = '<div class="form-group col-md-4"><input type="text" name="url" id="url" value="'. esc_attr( $commenter['comment_author_url'] ) .'" placeholder="'. esc_attr__("Website", "ratio-lite").'" size="22" tabindex="2"'. ( $req ? 'aria-required="false"' : '' ).' class="input-url form-control"  /></div></div>';

	return $fields;
}
add_filter('comment_form_default_fields','ratio_lite_modify_comment_form_fields');

/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/template-functions.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/custom-functions.php';


/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require get_template_directory() . '/inc/jetpack.php';
}

