<?php
/**
 * Online News functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Online_News
 */

if ( ! function_exists( 'online_news_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 online_news_setup() {
	/*
	 * Make theme available for translation.
	 * Translations can be filed in the /languages/ directory.
	 * If you're building a theme based on Online News, use a find and replace
	 * to change 'online-news' to the name of your theme in all the template files.
	 */
	load_theme_textdomain( 'online-news', 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( 'online-news-slider', 1366, 640, true);
	add_image_size( 'online-news-article-thumb', 70, 70, true);
	add_image_size( 'online-news-sidebar-thumb', 255, 139, true);	
	add_image_size( 'online-news-post-thumb', 255, 166, true);	
	add_image_size( 'online-news-postthumb-medium', 1270, 650, true);
	add_image_size( 'online-news-post-side-thumb', 620, 404, true);
	add_image_size( 'online-news-feature-thumb', 945, 421, true);
	add_image_size( 'online-news-postthumb-thumb', 87, 59, true);
	add_image_size( 'online-news-post-mediumthumb', 837, 428, true);



	// Enable support for custom logo.
	add_theme_support( 'custom-logo' );

	// This theme uses wp_nav_menu() in one location.
	register_nav_menus( array(
		'primary' => esc_html__( 'Primary', 'online-news' ),
		'top-menu' => esc_html__( 'Top Menu', 'online-news' ),
		'footer-top-menu' => esc_html__( ' Footer Top Menu', 'online-news' ),
		'footer-menu' => esc_html__( ' Footer Menu', 'online-news' ),
		) );

	/*
	 * 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( 'online_news_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
		) ) );

	// Add theme support for selective refresh for widgets.
	add_theme_support( 'customize-selective-refresh-widgets' );

	// Add support for Block Styles.
	add_theme_support( 'wp-block-styles' );

	// Add support for full and wide align images.
	add_theme_support( 'align-wide' );

    // Responsive embeds
    add_theme_support( 'responsive-embeds' );
		
}
endif;
add_action( 'after_setup_theme', 'online_news_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 online_news_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'online_news_content_width', 640 );
}
add_action( 'after_setup_theme', 'online_news_content_width', 0 );

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

	register_sidebar( array(
		'name'          => esc_html__( 'News Section 1:Tab Section', 'online-news' ),
		'id'            => 'news-section1-breaking-news',
		'description'   => esc_html__( 'Widget for breaking news in News Section 1', 'online-news' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
		) );

	register_sidebar( array(
		'name'          => esc_html__( 'News Section 1:Sidebar', 'online-news' ),
		'id'            => 'news-section1-sidebar',
		'description'   => esc_html__( 'Widget for sidebar in News Section 1', 'online-news' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
		) );

	register_sidebar( array(
		'name'          => esc_html__( 'News Section 2:Sidebar', 'online-news' ),
		'id'            => 'news-section2-sidebar',
		'description'   => esc_html__( 'Widget for sidebar in News Section 2', 'online-news' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
		) );

	register_sidebar( array(
		'name'          => esc_html__( 'News Section 3:Sidebar', 'online-news' ),
		'id'            => 'news-section3-sidebar',
		'description'   => esc_html__( 'Widget for sidebar in News Section 3', 'online-news' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
		) );

	register_sidebar( array(
		'name'          => esc_html__( 'News Section 3:News Section', 'online-news' ),
		'id'            => 'news-section3-news-section',
		'description'   => esc_html__( 'Widget for sidebar in News Section 3', 'online-news' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
		) );

	register_sidebar( array(
		'name'          => esc_html__( 'News Section 4:Sidebar', 'online-news' ),
		'id'            => 'news-section4-sidebar',
		'description'   => esc_html__( 'Widget for sidebar in News Section 4', 'online-news' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
		) );

	register_sidebar( array(
		'name'          => esc_html__( 'Section 1 Advertisement', 'online-news' ),
		'id'            => 'advertisement-section',		
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
		) );

	register_sidebar( array(
		'name'          => esc_html__( 'Section 2 Advertisement', 'online-news' ),
		'id'            => 'advertisement-section1',		
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
		) );

	register_sidebar( array(
		'name'          => esc_html__( 'Section 3 Advertisement', 'online-news' ),
		'id'            => 'advertisement-section2',		
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
		) );


}
add_action( 'widgets_init', 'online_news_widgets_init' );

/**
 * Register custom fonts.
 */
function online_news_fonts_url() {
	$fonts_url = '';

	/**
	 * Translators: If there are characters in your language that are not
	 * supported by Libre Franklin, translate this to 'off'. Do not translate
	 * into your own language.
	 */
	$poppins = _x( 'on', 'Poppins font: on or off', 'online-news' );

	if ( 'off' !== $poppins ) {
		$font_families = array();

		$font_families[] = 'Poppins:300,400,500,600,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 online_news_scripts() {

	$fonts_url = online_news_fonts_url();
	if ( ! empty( $fonts_url ) ) {
		wp_enqueue_style( 'online-news-google-fonts', $fonts_url, array(), null );}

	
	wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/font-awesome/css/font-awesome.min.css', '', '4.7.0' );
	
	wp_enqueue_style( 'owl-carousel', get_template_directory_uri() .'/css/owl.carousel.min.css', '', 'v2.2.0');

	wp_enqueue_style( 'owl-theme', get_template_directory_uri() .'/css/owl.theme.css', '', 'v2.2.0');
	wp_enqueue_style( 'meanmenu', get_template_directory_uri() .'/css/meanmenu.css', '', '2.0.7');

	wp_enqueue_style( 'online-news-style', get_stylesheet_uri(), array(), '1.0.0' );
    add_editor_style( 'online-news-style', get_stylesheet_uri());

	wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/js/owl.carousel.min.js', array('jquery'), '20151215', true );

	wp_enqueue_script( 'easyResponsiveTabs', get_template_directory_uri() . '/js/easyResponsiveTabs.js', array('jquery'), '20151215', true );

	wp_enqueue_script( 'nicescroll', get_template_directory_uri() . '/js/jquery.nicescroll.js', array('jquery'), '20151215', true );

	wp_enqueue_script( 'easy-ticker', get_template_directory_uri() . '/js/jquery.easy-ticker.min.js', array('jquery'), '20151215', true );

	wp_enqueue_script( 'meanmenu', get_template_directory_uri() . '/js/jquery.meanmenu.js', array(), '2.0.8', true );

	wp_enqueue_script( 'online-news-custom', get_template_directory_uri() . '/js/custom.js', array('jquery'), '20151215', true );
	
	wp_enqueue_script( 'online-news-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );

	wp_enqueue_script( 'online-news-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );

    wp_enqueue_script( 'online-news-keyboard-navigation', get_template_directory_uri() . '/js/keyboard-navigation.js', array(), '20151215', true );

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


/**
 * Load init.
 */
require_once get_template_directory() . '/inc/init.php';