<?php
/**
 * Functions which enhance the theme by hooking into WordPress
 *
 * @package One Newspaper
 */
use OneNewspaper\CustomizerDefault as ONP;
/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function one_newspaper_body_classes( $classes ) {
	global $post;

	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}

	$classes[] = 'one-newspaper-variables';
	$classes[] = esc_attr( 'one-newspaper-title-' . ONP\one_newspaper_get_customizer_option( 'post_title_hover_effects'  ) ); // post title hover effects
	$classes[] = esc_attr( 'one-newspaper-image-hover--effect-' . ONP\one_newspaper_get_customizer_option( 'site_image_hover_effects' ) ); // site image hover effects
	$classes[] = esc_attr( 'site-' . ONP\one_newspaper_get_customizer_option( 'website_layout' ) ); // site layout
	$classes[] = 'one-newspaper-light-mode';
	$classes[] = 'block-title--layout-eight';
	$classes[] = ' is-desktop';

	if( \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'search' ) ) :
		$classes[] = esc_attr( 'search-popup--one' );
	endif;

	if( \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'off-canvas' ) ) :
		$off_canvas_position = ONP\one_newspaper_get_customizer_option('off_canvas_position');
		$classes[] = esc_attr( 'off-canvas-sidebar-appear--' . $off_canvas_position );
	endif;
	
	// page layout
	if( is_page() || is_404() || is_search() ) :
		if( is_front_page() ) {
			$frontpage_sidebar_layout = ONP\one_newspaper_get_customizer_option( 'frontpage_sidebar_layout' );
			$frontpage_sidebar_sticky_option = ONP\one_newspaper_get_customizer_option( 'frontpage_sidebar_sticky_option' );
			if( $frontpage_sidebar_sticky_option ) $classes[] = esc_attr( 'sidebar-sticky' );
			$classes[] = esc_attr( $frontpage_sidebar_layout );
		} else {
			if( is_page() ) {
				// default value set for post sidebar layout.
				if( !metadata_exists( 'post', $post->ID, 'post_sidebar_layout' ) ) {
					// add post sidebar layout value "custmomizer-setting".
					update_post_meta( $post->ID, 'post_sidebar_layout', 'customizer-setting' );
				}
				$post_sidebar_layout = get_post_meta( $post->ID, 'post_sidebar_layout', true );
				$post_sidebar_layout = ( $post_sidebar_layout ) ? $post_sidebar_layout : 'customizer-setting';
				if( $post_sidebar_layout == 'customizer-setting' ){
					$page_sidebar_layout = ONP\one_newspaper_get_customizer_option( 'page_sidebar_layout' );
				} else {
					$page_sidebar_layout = $post_sidebar_layout;
				}
			} else {
				$page_sidebar_layout = ONP\one_newspaper_get_customizer_option( 'page_sidebar_layout' );
			}
			$page_sidebar_sticky_option = ONP\one_newspaper_get_customizer_option( 'page_sidebar_sticky_option' );
			if( $page_sidebar_sticky_option ) $classes[] = esc_attr( 'sidebar-sticky' );
			$classes[] = esc_attr( $page_sidebar_layout );
		}
	endif;

	// single post layout
	if( is_single() ) :
		// default value set for post sidebar layout.
		if( !metadata_exists( 'post', $post->ID, 'post_sidebar_layout' ) ) {
			// add post sidebar layout value "custmomizer-setting".
			update_post_meta( $post->ID, 'post_sidebar_layout', 'customizer-setting' );
		}
		$post_sidebar_layout = get_post_meta( $post->ID, 'post_sidebar_layout', true );
		$post_sidebar_layout = ( $post_sidebar_layout ) ? $post_sidebar_layout : 'customizer-setting';
		if( $post_sidebar_layout == 'customizer-setting' ){
			$single_sidebar_layout = ONP\one_newspaper_get_customizer_option( 'single_sidebar_layout' );
		} else {
			$single_sidebar_layout = $post_sidebar_layout;
		}
		$single_sidebar_sticky_option = ONP\one_newspaper_get_customizer_option( 'single_sidebar_sticky_option' );
		if( $single_sidebar_sticky_option ) $classes[] = esc_attr( 'sidebar-sticky' );
		$single_layout = ONP\one_newspaper_get_customizer_option( 'single_layout' ); 
		$single_layout_meta = ( metadata_exists( 'post', get_the_ID(), 'single_layout' ) ) ? get_post_meta( get_the_ID(), 'single_layout', true ) : 'customizer-layout';
		$is_customizer_layout = ( $single_layout_meta === 'customizer-layout' );
		$classes[] = esc_attr( 'single-layout--' . ( $is_customizer_layout ? $single_layout : $single_layout_meta ) );
		$classes[] = esc_attr( $single_sidebar_layout );
	endif;

	// archive layout
	if( is_archive() || is_home() || is_search() ) :
		$archive_sidebar_layout = ONP\one_newspaper_get_customizer_option( 'archive_sidebar_layout' );
		$archive_page_layout = ONP\one_newspaper_get_customizer_option( 'archive_page_layout' );
		$archive_layout_meta = one_newspaper_get_archive_layout_meta();
		$archive_sidebar_meta = one_newspaper_get_archive_sidebar_meta();
		$is_customizer_layout = ( $archive_layout_meta == 'customizer-layout' );
		$is_customizer_settings = ( $archive_sidebar_meta == 'customizer-setting' );
		$archive_sidebar_sticky_option = ONP\one_newspaper_get_customizer_option( 'archive_sidebar_sticky_option' );
		if( $archive_sidebar_sticky_option ) $classes[] = esc_attr( 'sidebar-sticky' );
		$classes[] = esc_attr( 'post-layout--'. ( $is_customizer_layout ? $archive_page_layout : $archive_layout_meta ) );
		$classes[] = esc_attr( $is_customizer_settings ? $archive_sidebar_layout : $archive_sidebar_meta );
	endif;

	$site_background_animation = ONP\one_newspaper_get_customizer_option( 'site_background_animation' );
	$classes[] = 'background-animation--' . $site_background_animation;

	$website_content_layout = ONP\one_newspaper_get_customizer_option( 'website_content_layout' );
    $classes[] = 'global-content-layout--' . $website_content_layout;

	$ticker_news_frontpage = ONP\one_newspaper_get_customizer_option( 'ticker_news_frontpage' );
    if( $ticker_news_frontpage ) $classes[] = 'ticker-news-frontpage';

	return $classes;
}
add_filter( 'body_class', 'one_newspaper_body_classes' );


/**
 * Add a pingback url auto-discovery header for single posts, pages, or attachments.
 */
function one_newspaper_pingback_header() {
	if ( is_singular() && pings_open() ) {
		printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );
	}
}
add_action( 'wp_head', 'one_newspaper_pingback_header' );

//define constant
define( 'ONE_NEWSPAPER_INCLUDES_PATH', get_template_directory() . '/inc/' );

/**
 * Enqueue theme scripts and styles.
 */
function one_newspaper_scripts() {
	global $wp_query;
	require_once get_theme_file_path( 'inc/wptt-webfont-loader.php' );
	$preloader_option = ONP\one_newspaper_get_customizer_option('preloader_option');
	$header_ticker_news_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'ticker-news' );
	$hr_ticker_news_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'ticker-news' );
	$homepage_content_order = json_decode( ONP\one_newspaper_get_customizer_option( 'homepage_content_order' ), true );
	$header_buiilder_header_sticky = ONP\one_newspaper_get_customizer_option( 'header_buiilder_header_sticky' );
	$web_stories_option = $homepage_content_order[ 'web_stories_section' ];
	$enqueue_scripts_args = [ 'strategy' => 'defer', 'in_footer' => true ];
	$css_dependency = [];
	$js_dependency = [ 'jquery' ];
	$theme_js_dependency = is_search() ? [ 'jquery', 'jquery-ui-datepicker' ] : $js_dependency;
	$template_directory_uri = get_template_directory_uri();
	wp_enqueue_style( 'fontawesome', $template_directory_uri . '/assets/lib/fontawesome/css/all.min.css', $css_dependency, '6.5.1', 'all' );
	wp_enqueue_style( 'slick', $template_directory_uri . '/assets/lib/slick/slick.css', $css_dependency, '1.8.1', 'all' );
	wp_enqueue_style( 'magnific-popup', $template_directory_uri . '/assets/lib/magnific-popup/magnific-popup.css', $css_dependency, '1.1.0', 'all' );
	wp_enqueue_style( 'one-newspaper-typo-fonts', wptt_get_webfont_url( one_newspaper_typo_fonts_url() ), $css_dependency, null );
	// enqueue inline style
	wp_enqueue_style( 'one-newspaper-style', get_stylesheet_uri(), $css_dependency, ONE_NEWSPAPER_VERSION );
	wp_add_inline_style( 'one-newspaper-style', one_newspaper_current_styles() );
	wp_enqueue_style( 'one-newspaper-main-style', $template_directory_uri.'/assets/css/main.css', $css_dependency, ONE_NEWSPAPER_VERSION );
	wp_enqueue_style( 'one-newspaper-builder-style', $template_directory_uri.'/assets/css/builder.css', $css_dependency, ONE_NEWSPAPER_VERSION );
	// additional css
	wp_enqueue_style( 'one-newspaper-main-style-additional', $template_directory_uri.'/assets/css/add.css', $css_dependency, ONE_NEWSPAPER_VERSION );
	if( $preloader_option ) wp_enqueue_style( 'one-newspaper-loader-style', $template_directory_uri.'/assets/css/loader.css', $css_dependency, ONE_NEWSPAPER_VERSION );
	wp_enqueue_style( 'one-newspaper-responsive-style', $template_directory_uri.'/assets/css/responsive.css', $css_dependency, ONE_NEWSPAPER_VERSION );
	wp_enqueue_style( 'jquery-ui', get_template_directory_uri() .'/assets/lib/jquery-ui/jquery-ui.min.css', $css_dependency, ONE_NEWSPAPER_VERSION, 'all' );
	wp_style_add_data( 'one-newspaper-style', 'rtl', 'replace' );

	wp_enqueue_script( 'slick', $template_directory_uri . '/assets/lib/slick/slick.min.js', $js_dependency, '1.8.1', $enqueue_scripts_args );
	wp_enqueue_script( 'magnific-popup', $template_directory_uri . '/assets/lib/magnific-popup/magnific-popup.min.js', $js_dependency, '1.1.0', $enqueue_scripts_args );
	if( $header_ticker_news_option || $hr_ticker_news_option ) wp_enqueue_script( 'js-marquee', $template_directory_uri . '/assets/lib/js-marquee/jquery.marquee.min.js', $js_dependency, '1.6.0', $enqueue_scripts_args );
	wp_enqueue_script( 'js-cookie', $template_directory_uri . '/assets/lib/jquery-cookie/jquery-cookie.js', $js_dependency, '1.4.1', $enqueue_scripts_args );
	wp_enqueue_script( 'one-newspaper-navigation', $template_directory_uri . '/assets/js/navigation.js', array(), ONE_NEWSPAPER_VERSION, $enqueue_scripts_args );
	wp_enqueue_script( 'one-newspaper-theme', $template_directory_uri . '/assets/js/theme.js', $theme_js_dependency, ONE_NEWSPAPER_VERSION, $enqueue_scripts_args );
	
	$scriptVars['_wpnonce'] = wp_create_nonce( 'one-newspaper-nonce' );
	$scriptVars['ajaxUrl'] 	= esc_url(admin_url('admin-ajax.php'));
	$scriptVars['stt']	= ONP\one_newspaper_get_customizer_option('stt_responsive_option');
	$scriptVars['headerAdsBannerOption']	= ONP\one_newspaper_get_customizer_option( 'header_ads_banner_responsive_option' );
	$scriptVars['ajaxPostsLoad'] = false;
	$scriptVars['is_customizer'] = is_customize_preview();
	$scriptVars['isRtl'] = is_rtl();	
	if( $header_buiilder_header_sticky ) :
		$scriptVars[ 'headerSticky' ] = ONP\one_newspaper_get_customizer_option( 'header_buiilder_header_sticky' );
	endif;
	
	if( is_single() || is_page() || is_archive() || is_search() ) $scriptVars[ 'themeColor' ]	= ONP\one_newspaper_get_customizer_option( 'theme_color' );

	// localize scripts
	wp_localize_script( 'one-newspaper-theme', 'oneNewspaperObject' , $scriptVars);

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

/**
 * Minify dynamic css
 * 
 * @since 1.0.0
 */
if( ! function_exists( 'one_newspaper_minifyCSS' ) ) :
	function one_newspaper_minifyCSS( $css ) {
		// Remove comments
		$css = preg_replace( '!/\*.*?\*/!s', '', $css );
		// Remove space after colons
		$css = preg_replace( '/\s*:\s*/', ':', $css );
		// Remove whitespace
		$css = preg_replace( '/\s+/', ' ', $css );
		// Remove space before/after brackets and semicolons
		$css = preg_replace( '/\s*{\s*/', '{', $css );
		$css = preg_replace( '/\s*}\s*/', '}', $css );
		$css = preg_replace( '/\s*;\s*/', ';', $css );
		// Remove final semicolon in a block
		$css = preg_replace( '/;}/', '}', $css );
		// Trim the final output
		return trim( $css );
	}
endif;

if( ! function_exists( 'one_newspaper_current_styles' ) ) :
	/**
	 * Generates the current changes in styling of the theme.
	 * 
	 * @package One Newspaper
	 * @since 1.0.0
	 */
	function one_newspaper_current_styles() {
		$website_layout = ONP\one_newspaper_get_customizer_option('website_layout');
		$archive_post_element_order = json_decode( ONP\one_newspaper_get_customizer_option('archive_post_element_order'), true );
		$homepage_content_order = json_decode( ONP\one_newspaper_get_customizer_option('homepage_content_order'), true );
		$sticky_posts_option = ONP\one_newspaper_get_customizer_option( 'sticky_posts_option' );
		$site_background_animation = ONP\one_newspaper_get_customizer_option( 'site_background_animation' );
		
		// Header Builder
		$header_site_logo_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'site-logo' );
		$header_off_canvas_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'off-canvas' );
		$header_custom_button_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'button' );
		$header_search_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'search' );
		$header_menu_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'menu' );
		$header_random_news_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'random-news' );
		$header_newsletter_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'newsletter' );
		$header_date_time_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'date-time' );
		$header_theme_mode_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'theme-mode' );
		$header_secondary_menu_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'secondary-menu' );
		$header_ticker_news_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'header_builder', 'ticker-news' );
		
		// Responsive Header Builder
		$hr_site_logo_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'site-logo' );
		$hr_off_canvas_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'off-canvas' );
		$hr_custom_button_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'button' );
		$hr_search_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'search' );
		$hr_menu_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'menu' );
		$hr_random_news_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'random-news' );
		$hr_newsletter_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'newsletter' );
		$hr_date_time_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'date-time' );
		$hr_theme_mode_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'theme-mode' );
		$hr_secondary_menu_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'secondary-menu' );
		$hr_ticker_news_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'responsive_header_builder', 'ticker-news' );
		
		// Footer Builder
		$footer_menu_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'footer_builder', 'menu' );
		$footer_copyright_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'footer_builder', 'copyright' );
		$footer_logo_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'footer_builder', 'logo' );
		$footer_scroll_to_top_option = \One_Newspaper_Builder\Builder_Base::widget_exists( 'footer_builder', 'scroll-to-top' );

		// enqueue inline style
		ob_start();
			// site colors
			one_newspaper_assign_variable( 'theme_color', '--one-newspaper-global-preset-theme-color' );
			one_newspaper_preset_color_css( 'solid_color_preset', '--one-newspaper-global-preset-color-' );
			one_newspaper_preset_color_css( 'gradient_color_preset', '--one-newspaper-global-preset-gradient-color-' );

			// Mobile Menu
			one_newspaper_color_css( 'mobile_canvas_icon_color', 'body.one-newspaper-light-mode .site .toggle-button-wrapper .canvas-menu-icon', 'color' );
			one_newspaper_color_css( 'mobile_canvas_text_color', 'body.one-newspaper-light-mode .main-navigation.toggled #header-menu li > a, body.one-newspaper-light-mode nav.main-navigation.toggled ul.menu > li > a, body.one-newspaper-light-mode nav.main-navigation.toggled ul.nav-menu > li > a', 'color' );
			one_newspaper_color_css( 'mobile_canvas_background', ' nav.main-navigation.toggled ul.menu, nav.main-navigation.toggled ul.nav-menu' );

			one_newspaper_visibility_options( 'header_ads_banner_responsive_option', '.ads-banner' );
			one_newspaper_visibility_options( 'stt_responsive_option', 'body #one-newspaper-scroll-to-top.show' );

			// Widget Styles
			one_newspaper_border_option( 'widgets_styles_image_border', '.widget .post_thumb_image, .widget .opinions-items-wrap .opinion-item figure, .widget .widget-tabs-content .post-thumb, .widget .popular-posts-wrap article .post-thumb, .widget.widget_one_newspaper_news_filter_tabbed_widget .tabs-content-wrap .post-thumb, .widget .one-newspaper-widget-carousel-posts .post-thumb-wrap, .author-wrap.layout-two .post-thumb, .widget_one_newspaper_category_collection_widget .categories-wrap .category-item, .widget .one-newspaper-advertisement-block img', 'border' );
			one_newspaper_value_change_responsive( 'widgets_styles_image_border_radius', '.widget .post_thumb_image, .widget .opinions-items-wrap .opinion-item figure, .widget .widget-tabs-content .post-thumb, .widget .popular-posts-wrap article .post-thumb, .widget.widget_one_newspaper_news_filter_tabbed_widget .tabs-content-wrap .post-thumb, .widget .one-newspaper-widget-carousel-posts .post-thumb-wrap, .author-wrap.layout-two .post-thumb, .widget .one-newspaper-widget-carousel-posts.layout--two .slick-list, .widget_one_newspaper_category_collection_widget .categories-wrap .category-item, .widget .one-newspaper-advertisement-block img', 'border-radius' );
			one_newspaper_box_shadow_styles( 'widgets_styles_image_box_shadow', '.widget .post_thumb_image, .widget .opinions-items-wrap .opinion-item figure, .widget .widget-tabs-content .post-thumb, .widget .popular-posts-wrap article .post-thumb, .widget.widget_one_newspaper_news_filter_tabbed_widget .tabs-content-wrap .post-thumb, .widget .one-newspaper-widget-carousel-posts.layout--two .slick-list, .author-wrap.layout-two .post-thumb, .widget_one_newspaper_category_collection_widget .categories-wrap .category-item, .widget .one-newspaper-advertisement-block img' );

			// Website Layout
			if( $website_layout === 'boxed--layout' ) :
				one_newspaper_color_css( 'website_layout_background_color', 'body .site' );
				one_newspaper_box_shadow_styles( 'website_box_shadow', 'body #page.site' );
				one_newspaper_responsive_range_css( 'website_layout_horizontal_gap', 'body #page.site', 'margin-inline' );
				one_newspaper_responsive_range_css( 'website_layout_vertical_gap', 'body #page.site', 'margin-top' );
				one_newspaper_responsive_range_css( 'website_layout_vertical_gap', 'body #page.site', 'margin-bottom' );

			endif;
			one_newspaper_typography_control( 'site_block_title_typo', "--block-title" );

			// Global button
			if( ( is_archive() || is_date() || is_search() || is_home() || is_front_page() ) && $archive_post_element_order[ 'button' ] ) :
				one_newspaper_typography_control( 'global_button_typo', "--post-link-btn" );
			endif;

			// category Colors
			one_newspaper_typography_control( 'global_category_typography', "--category" );
			one_newspaper_category_colors_styles();

			// Global Typography
			one_newspaper_typography_preset();
			one_newspaper_typography_control( 'site_post_title_typo', "--post-title" );
			one_newspaper_typography_control( 'site_post_meta_typo', "--meta" );
			one_newspaper_typography_control( 'site_post_content_typo', "--content" );

			// Header Builder
			one_newspaper_color_css( 'header_builder_background', 'body.one-newspaper-light-mode .site .site-header' );

			// Header Builder 1st Row
			one_newspaper_color_css( 'header_first_row_background', 'body.one-newspaper-light-mode .site .site-header .row-one.full-width, body.one-newspaper-light-mode .site .site-header .row-one .full-width' );

			// Header Builder 2nd Row
			one_newspaper_color_css( 'header_second_row_background', 'body.one-newspaper-light-mode .site .site-header .row-two.full-width, body.one-newspaper-light-mode .site .site-header .row-two .full-width' );

			// Header Builder 3rd Row
			one_newspaper_color_css( 'header_third_row_background', 'body.one-newspaper-light-mode .site .site-header .row-three.full-width, body.one-newspaper-light-mode .site .site-header .row-three .full-width' );

			// Secondary Menu Options
			if( $header_secondary_menu_option || $hr_secondary_menu_option ) :
				one_newspaper_typography_control( 'secondary_menu_typo', 'body .site header.site-header .top-nav-menu:not(.use-primary) ul li a', false );
				one_newspaper_color_css( 'secondary_menu_color', 'body.one-newspaper-variables.one-newspaper-light-mode', '--secondary-menu-color' );
			endif;

			// Site logo and Title
			if( $header_site_logo_option || $hr_site_logo_option ) :
				if( get_theme_mod( 'custom_logo' ) ) one_newspaper_responsive_range_css( 'site_logo_width', "body .site-header .site-branding img" );
				one_newspaper_typography_control( 'site_title_typo', "--site-title" );
				one_newspaper_typography_control( 'site_tagline_typo', "--site-tagline" );
			endif;

			// Off canvas
			if( $header_off_canvas_option || $hr_site_logo_option ) one_newspaper_color_css( 'canvas_menu_icon_color', 'body.one-newspaper-variables.one-newspaper-light-mode', '--sidebar-toggle-color' );

			// Primary Menu Options
			if( $header_menu_option || $hr_menu_option ) :
				one_newspaper_typography_control( 'header_menu_typo', "--menu" );
				one_newspaper_typography_control( 'header_sub_menu_typo', "--submenu" );
				one_newspaper_color_css( 'header_menu_color', 'body.one-newspaper-variables.one-newspaper-light-mode', '--menu-color' );
				one_newspaper_color_css( 'header_sub_menu_color', 'body.one-newspaper-variables.one-newspaper-light-mode', '--menu-color-submenu' );
			endif;

			// Random News
			if( $header_random_news_option || $hr_random_news_option ) :
				one_newspaper_typography_control( 'random_news_typography', ".site .site-header .random-news-element a", false );
				one_newspaper_color_css( 'random_news_label_color', 'body.one-newspaper-variables.one-newspaper-light-mode', '--random-news-color' );
			endif;

			// Header Search
			if( $header_search_option || $hr_search_option ) :
				one_newspaper_responsive_range_css( 'search_icon_size', '.site .site-header .search-wrap .search-action i', 'font-size' );
				one_newspaper_color_css( 'search_icon_color', 'body.one-newspaper-variables.one-newspaper-light-mode', '--search-color' );
			endif;

			// Custom Button
			if( $header_custom_button_option || $hr_custom_button_option ) :
				one_newspaper_responsive_range_css( 'custom_button_icon_size', "body.one-newspaper-variables", '--custom-btn-icon-size' );
				one_newspaper_typography_control( 'custom_button_text_typo', "--custom-btn" );
				one_newspaper_color_css( 'custom_button_color_group', 'body.one-newspaper-variables.one-newspaper-light-mode', '--custom-btn-color' );
			endif;

			// Newsletter / subscribe button
			if( $header_newsletter_option || $hr_newsletter_option ) :
				one_newspaper_color_css( 'header_newsletter_label_color', 'body.one-newspaper-variables.one-newspaper-light-mode', '--newsletter-color' );
				one_newspaper_typography_control( 'header_newsletter_typography', '.site .site-header .newsletter-element a', false );
			endif;

			// Date Time
			if( $header_date_time_option || $hr_date_time_option ) :
				one_newspaper_typography_control( 'date_time_typography', ".site .site-header .top-date-time .top-date-time-inner", false );
				one_newspaper_color_css( 'date_color', 'body.one-newspaper-variables.one-newspaper-light-mode', '--top-header-date-color' );
				one_newspaper_color_css( 'time_color', 'body.one-newspaper-variables.one-newspaper-light-mode', '--top-header-time-color' );
			endif;

			// Theme Mode
			if( $header_theme_mode_option || $hr_theme_mode_option ) :
				one_newspaper_color_css( 'theme_mode_light_icon_color', 'body.one-newspaper-light-mode .site-header .mode-toggle .light','color' );
				one_newspaper_color_css( 'theme_mode_dark_icon_color', 'body.one-newspaper-dark-mode .site-header .mode-toggle .dark','color' );
			endif;

			// Ticker News Section
			if( $header_ticker_news_option || $hr_ticker_news_option ) :
				one_newspaper_color_css( 'ticker_news_background_color_group', 'body.one-newspaper-light-mode .site #one-newspaper-ticker-news.full-width--on, body.one-newspaper-light-mode .site #one-newspaper-ticker-news.full-width--off .row' );
				one_newspaper_color_css( 'ticker_news_title_color', '.site .ticker-news-wrap.one-newspaper-ticker .ticker-item h2.post-title a', 'color' );
				one_newspaper_color_css( 'ticker_news_date_color', '.site .ticker-item-wrap .post-date a, .ticker-item-wrap span.post-date:before ', 'color' );
				one_newspaper_border_option( 'ticker_news_border', 'body .site #one-newspaper-ticker-news.full-width--on, body .site #one-newspaper-ticker-news.full-width--off .row', 'border' );
				one_newspaper_number_control( 'ticker_section_border_radius', 'body #one-newspaper-ticker-news .feature_image , body .site #one-newspaper-ticker-news.full-width--on, body .site #one-newspaper-ticker-news.full-width--off .row', 'border-radius' );
			endif;

			// Sticky Posts
			if( $sticky_posts_option ) :
				one_newspaper_typography_control( 'sticky_posts_label_typography', "body .one-newspaper-sticky-posts .label-wrapper .label", false );
				one_newspaper_typography_control( 'sticky_posts_title_typography', "body .one-newspaper-sticky-posts .post-list article .post-content .post-title", false );
			endif;

			// Main Banner
			if( $homepage_content_order[ 'main_banner_section' ] ) :
				one_newspaper_color_css( 'main_banner_background_color_group', 'body.one-newspaper-light-mode .site #main-banner-section.full-width--on, body.one-newspaper-light-mode .site #main-banner-section.full-width--off .row' );
				one_newspaper_border_option( 'main_banner_section_border', 'body .site #main-banner-section.full-width--on, body .site #main-banner-section.full-width--off .row', 'border' );
				one_newspaper_number_control( 'main_banner_section_border_radius', 'body #main-banner-section article, body .site #main-banner-section.full-width--on, body .site #main-banner-section.full-width--off .row', 'border-radius' );
			endif;

			// Web stories
			if( $homepage_content_order[ 'web_stories_section' ] ) :
				one_newspaper_color_css( 'web_stories_background_color_group', 'body.one-newspaper-light-mode .site .one-newspaper-web-stories.full-width--on, body.one-newspaper-light-mode .site .one-newspaper-web-stories.full-width--off .row' );
				one_newspaper_border_option( 'web_stories_section_border', 'body .site .one-newspaper-web-stories.full-width--on, body .site .one-newspaper-web-stories.full-width--off .row', 'border' );
				one_newspaper_number_control( 'web_stories_section_border_radius', 'body .one-newspaper-web-stories .preview-thumb, body .site .one-newspaper-web-stories, body .site .one-newspaper-web-stories.full-width--off .row', 'border-radius' );
				one_newspaper_image_ratio( 'web_stories_image_ratio', 'body .one-newspaper-web-stories .stories-wrap .preview:before' );
				one_newspaper_typography_control( 'web_stories_preview_count_typo', ".site .one-newspaper-web-stories .stories-wrap .preview .story-count", false );
				one_newspaper_typography_control( 'web_stories_preview_title_typo', ".site .one-newspaper-web-stories .stories-wrap .story-title", false );
				one_newspaper_typography_control( 'web_stories_title_typo', ".site .one-newspaper-web-stories .inner-stories-wrap .content-wrap .title", false );
			endif;

			// Full widget section
			if( $homepage_content_order[ 'full_width_section' ] ) :
				one_newspaper_color_css( 'full_width_blocks_background_color_group', 'body.one-newspaper-light-mode .site #full-width-section.full-width--on, body.one-newspaper-light-mode .site #full-width-section.full-width--off .row' );
				one_newspaper_border_option( 'full_width_section_border', 'body .site #full-width-section.full-width--on, body .site #full-width-section.full-width--off .row', 'border' );
				one_newspaper_number_control( 'full_width_section_border_radius', 'body #full-width-section, body .site #full-width-section .post-thumb-wrap, body .site #full-width-section.full-width--off .row', 'border-radius' );
			endif;

			// Left content - right sidebar
			if( $homepage_content_order[ 'leftc_rights_section' ] ) :
				one_newspaper_color_css( 'leftc_rights_blocks_background_color_group', 'body.one-newspaper-light-mode .site #leftc-rights-section.full-width--on, body.one-newspaper-light-mode .site #leftc-rights-section.full-width--off .row' );
				one_newspaper_border_option( 'leftc_rights_section_border', 'body .site #leftc-rights-section.full-width--on, body .site #leftc-rights-section.full-width--off .row', 'border' );
				one_newspaper_number_control( 'leftc_rights_section_border_radius', 'body #leftc-rights-section, body .site #leftc-rights-section .post-thumb-wrap , body .site #leftc-rights-section.full-width--off .row', 'border-radius' );

				one_newspaper_color_css( 'leftc_rights_sidebar_background_color_group', 'body.one-newspaper-light-mode .site #leftc-rights-section .secondary-sidebar ' );
				one_newspaper_border_option( 'leftc_rights_sidebar_section_border', 'body .site #leftc-rights-section.full-width--on .secondary-sidebar , body .site #leftc-rights-section.full-width--off .row .secondary-sidebar', 'border' );
				one_newspaper_number_control( 'leftc_rights_section_sidebar_border_radius', 'body .site #leftc-rights-section .secondary-sidebar ', 'border-radius' );
				one_newspaper_spacing_control( 'leftc_rights_section_sidebar_padding', 'body .site #leftc-rights-section .secondary-sidebar', 'padding' );
			endif;

			// Left sidebar - right content
			if( $homepage_content_order[ 'lefts_rightc_section' ] ) :
				one_newspaper_color_css( 'lefts_rightc_blocks_background_color_group', 'body.one-newspaper-light-mode .site #lefts-rightc-section.full-width--on, body.one-newspaper-light-mode .site #lefts-rightc-section.full-width--off .row' );
				one_newspaper_border_option( 'lefts_rightc_section_border', 'body .site #lefts-rightc-section.full-width--on, body .site #lefts-rightc-section.full-width--off .row', 'border' );
				one_newspaper_number_control( 'lefts_rightc_section_border_radius', 'body #lefts-rightc-section, body .site #lefts-rightc-section .post-thumb-wrap , body .site #lefts-rightc-section.full-width--off .row', 'border-radius' );

				one_newspaper_color_css( 'lefts_rightc_sidebar_background_color_group', 'body.one-newspaper-light-mode .site #lefts-rightc-section .secondary-sidebar ' );
				one_newspaper_border_option( 'lefts_rightc_sidebar_section_border', 'body .site #lefts-rightc-section.full-width--on .secondary-sidebar , body .site #lefts-rightc-section.full-width--off .row .secondary-sidebar', 'border' );
				one_newspaper_number_control( 'lefts_rightc_section_sidebar_border_radius', 'body .site #lefts-rightc-section .secondary-sidebar ', 'border-radius' );
				one_newspaper_spacing_control( 'lefts_rightc_section_sidebar_padding', 'body .site #lefts-rightc-section .secondary-sidebar', 'padding' );
			endif;

			// Bottom full width
			if( $homepage_content_order[ 'bottom_full_width_section' ] ) :
				one_newspaper_color_css( 'bottom_full_width_blocks_background_color_group', 'body.one-newspaper-light-mode .site #bottom-full-width-section.full-width--on, body.one-newspaper-light-mode .site #bottom-full-width-section.full-width--off .row' );
				one_newspaper_border_option( 'bottom_full_width_section_border', 'body .site #bottom-full-width-section.full-width--on, body .site #bottom-full-width-section.full-width--off .row', 'border' );
				one_newspaper_number_control( 'bottom_full_width_section_border_radius', 'body #bottom-full-width-section, body .site #bottom-full-width-section .post-thumb-wrap , body .site #bottom-full-width-section.full-width--off .row', 'border-radius' );
			endif;

			// Two column section
			if( $homepage_content_order[ 'two_column_section' ] ) :
				one_newspaper_color_css( 'two_column_background_color_group', 'body.one-newspaper-light-mode .site #two-column-section.full-width--on, body.one-newspaper-light-mode .site #two-column-section.full-width--off .row' );
				one_newspaper_border_option( 'two_column_section_border', 'body .site #two-column-section.full-width--on, body .site #two-column-section.full-width--off .row', 'border' );
				one_newspaper_number_control( 'two_column_section_border_radius', 'body #two-column-section, body .site #two-column-section .post-thumb-wrap , body .site #two-column-section.full-width--off .row', 'border-radius' );
			endif;

			// Archive || Latest Posts
			if( ( is_home() || is_front_page() || is_archive() || is_search() || is_date() ) && $homepage_content_order[ 'latest_posts' ] ) :
				one_newspaper_image_ratio_variable( 'archive_image_ratio', '--one-newspaper-archive-image-ratio' );

				one_newspaper_color_css( 'archive_color_group', 'body.one-newspaper-light-mode .site #theme-content.full-width--on, body.one-newspaper-light-mode .site #theme-content.full-width--off .row' );
				one_newspaper_border_option( 'archive_section_border', 'body .site #theme-content.full-width--on, body .site #theme-content.full-width--off .row', 'border' );
				one_newspaper_number_control( 'archive_border_radius', 'body #theme-content, body .site #theme-content article .one-newspaper-card, body .site #theme-content .post-thumb-wrap, body .site #theme-content.full-width--off .row', 'border-radius' );
			endif;

			one_newspaper_color_css( 'archive_sidebar_color_group', 'body.one-newspaper-light-mode .site #theme-content .widget-area' );
			one_newspaper_border_option( 'archive_sidebar_section_border', ' body .site #theme-content .widget-area', 'border' );
			one_newspaper_number_control( 'archive_sidebar_border_radius', 'body #theme-content .widget-area ', 'border-radius' );
			one_newspaper_spacing_control( 'archive_sidebar_padding', 'body #theme-content .widget-area ', 'padding' );

			// Pagination Settings
			one_newspaper_get_pagination_text_color();

			// Single
			if( is_single() ) :
				one_newspaper_image_ratio_variable( 'single_post_image_ratio', '--one-newspaper-single-image-ratio' );
				one_newspaper_typography_control( 'single_post_title_typo', "--single-title" );
				one_newspaper_typography_control( 'single_post_meta_typo', "--single-meta" );
				one_newspaper_typography_control( 'single_post_content_typo', "--single-content" );
			endif;

			// Page
			if( is_page() ) one_newspaper_image_ratio_variable( 'page_image_ratio', '--one-newspaper-page-image-ratio' );

			// Footer builder
			one_newspaper_color_css( 'footer_builder_background', 'body.one-newspaper-light-mode footer.site-footer ' );
			one_newspaper_typography_control( 'footer_title_typography', '.site .site-footer h2.one-newspaper-block-title, .site .site-footer h2.one-newspaper-block-title span, .site .site-footer h2.widget-title span, .site .site-footer h2.one-newspaper-widget-title span', false );
			one_newspaper_typography_control( 'footer_text_typography', '.site-footer .post-item .post-element .post-title a, .site-footer .widget_one_newspaper_opinions_widget .your-opinions-block-widget .opinion-content .post-title a, .site-footer .widget .posts-wrap .post-item .post-title a ', false );

			// Footer Builder 1st Row
			one_newspaper_color_css( 'footer_first_row_background', 'body.one-newspaper-light-mode .site-footer .bb-bldr--normal .row-one.full-width, body.one-newspaper-light-mode .site-footer .bb-bldr--normal .row-one .full-width' );

			// Footer Builder 2nd Row
			one_newspaper_color_css( 'footer_second_row_background', 'body.one-newspaper-light-mode .site-footer .bb-bldr--normal .row-two.full-width, body.one-newspaper-light-mode .site-footer .bb-bldr--normal .row-two .full-width' );

			// Footer Builder 3rd Row
			one_newspaper_color_css( 'footer_third_row_background', 'body.one-newspaper-light-mode .site-footer .bb-bldr--normal .row-three.full-width, body.one-newspaper-light-mode .site-footer .bb-bldr--normal .row-three .full-width' );

			// Footer Menu
			if( $footer_menu_option ) :
				one_newspaper_typography_control( 'footer_menu_typography', '.site footer.site-footer .bb-bldr-widget:not(.has-sidebar) .menu li a', False );
				one_newspaper_color_css( 'footer_menu_color', 'body.one-newspaper-light-mode .site footer.site-footer .bb-bldr-widget:not(.has-sidebar) .menu li a', 'color' );
			endif;

			// Copyright
			if( $footer_copyright_option ) one_newspaper_typography_control( 'bottom_footer_text_typography', 'footer.site-footer .site-info', False );

			// Footer Logo
			if( $footer_logo_option ) one_newspaper_responsive_range_css( 'bottom_footer_logo_width', '.site .site-footer .footer-logo img ', 'width' );

			// Scroll to Top
			if( $footer_scroll_to_top_option ) one_newspaper_color_css( 'stt_color_group', 'body.one-newspaper-variables', '--move-to-top-color' );

			// Site Background
			one_newspaper_color_css( 'site_background_color', 'body.one-newspaper-variables', '--site-bk-color' );

			// front sections image settings styles
		$current_styles = ob_get_clean();
		return apply_filters( 'one_newspaper_current_styles', wp_strip_all_tags( one_newspaper_minifyCSS( $current_styles ) ) );
	}
endif;

if( ! function_exists( 'one_newspaper_get_brand_name' ) ) :
	/**
	 * Return brand name from fontawesome icon class
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_get_brand_name( string $icon ): string {
		// remove prefix
		$name = str_replace( "fa-brands fa-", "", $icon );

		// replace dashes with spaces
		$name = str_replace( "-", " ", $name );

		// remove unwanted words
		$remove = [ "square", "circle", "alt", "official", "logo", "simple", "cc", 'f', 'ios', 'w', 'v', 's', 'stroke', 'p', 'pp', 'hat', 'alien', 'directional', 'symbol', 'framework', 'squadron', 'k', 'in', 'note', 'browser', 'fi', 'g', 'legacy', 'by', 'nc', 'nc-eu', 'nc-jp', 'nd', 'pd', 'pd-alt', 'sa', 'sampling', 'sampling-plus', 'share', 'zero', 'beyond', 'b', 'reverse' ];
		$name = preg_replace( '/\b(' . implode( '|', $remove ) . ')\b/i', '', $name );

		// clean up multiple spaces
		$name = trim( preg_replace( '/\s+/', ' ', $name ) );

		if( $name === 'x twitter' ) $name = 'x';

		// ucfirst every word
		return ucwords( $name );
	}
endif;

if( ! function_exists( 'one_newspaper_customizer_social_icons' ) ) :
	/**
	 * Function to get social icons from customizer
	 * 
	 * @since 1.0.0
	 * @package One Newspaper
	 */
	function one_newspaper_customizer_social_icons( $type = '', $limit = '', $inherit = false, $args = [] ) {
        $placement = ( $type !== '' ) ? $type . '_' : '';
		$social_icons = ONP\one_newspaper_get_customizer_option( $placement . 'social_icons' );
		$decoded_social_icons = json_decode( $social_icons, true );
		$display_count = $display_label = false;
		$columns = 2;
        if( $type === 'footer' ) :
            $display_label = ONP\one_newspaper_get_customizer_option( 'footer_social_icons_display_label' );
			if( isset( $args[ 'display_label' ] ) ) $display_label = $args[ 'display_label' ];
        endif;

        $socialIconClasses[] = 'one-newspaper-social-icon';
        if( isset( $args[ 'columns' ] ) && is_int( $args[ 'columns' ] ) ) $socialIconClasses[] = 'column--' . one_newspaper_convert_number_to_numeric_string( $args[ 'columns' ] );
        if( isset( $args[ 'display_count' ] ) ) $display_count = $args[ 'display_count' ];
		if( $display_label ) $socialIconClasses[] = 'is-title';
		if( $inherit ) $socialIconClasses[] .= ' official-color--enabled';

        echo '<div class="', implode( ' ', $socialIconClasses ), '">';
			foreach( $decoded_social_icons as $index => $icon ) :
				if( $limit !== '' && $index >= $limit ) break;
				if( $icon[ 'item_option' ] === 'show' ) :
					$label = one_newspaper_get_brand_name( $icon[ 'icon_class' ] );
					$iconClass = 'social-icon ' . strtolower( $label );
					?>
						<a class="<?php echo esc_attr( $iconClass ); ?>" href="<?php echo esc_url( $icon[ 'icon_url' ] ); ?>" target="_blank">
							<i class="<?php echo esc_attr( $icon[ 'icon_class' ] ); ?>"></i>
							<?php if( $display_label && $label ) echo '<span class="icon-label">', esc_html( $label ), '</span>'; ?>
							<?php if( $display_count ) echo '<span class="icon-count">', esc_html( $icon[ 'icon_count' ] ), '</span>'; ?>
						</a>
					<?php
				endif;
			endforeach;
		echo '</div>';
	}
endif;

if( ! function_exists( 'one_newspaper_get_date_filter_choices_array' ) ) :
	/**
	 * Return array of date filter choices.
	 * 
	 */
	function one_newspaper_get_date_filter_choices_array() {
		return apply_filters( 'one_newspaper_get_date_filter_choices_array_filter', [
			'all'	=> esc_html__('All', 'one-newspaper' ),
			'last-seven-days'	=> esc_html__('Last 7 days', 'one-newspaper' ),
			'today'	=> esc_html__('Today', 'one-newspaper' ),
			'this-week'	=> esc_html__('This Week', 'one-newspaper' ),
			'last-week'	=> esc_html__('Last Week', 'one-newspaper' ),
			'this-month'	=> esc_html__('This Month', 'one-newspaper' ),
			'last-month'	=> esc_html__('Last Month', 'one-newspaper' ),
			'this-year'	=> esc_html__('This Year', 'one-newspaper' )
		]);
	}
endif;

if( ! function_exists( 'one_newspaper_get_array_key_string_to_int' ) ) :
	/**
	 * Return array of int values.
	 * 
	 */
	function one_newspaper_get_array_key_string_to_int( $array ) {
		if( ! isset( $array ) || empty( $array ) ) return;
		$filtered_array = array_map( function($arr) {
			if( is_numeric( $arr ) ) return (int) $arr;
		}, $array);
		return apply_filters( 'one_newspaper_array_with_int_values', $filtered_array );
	}
endif;

/**
 * Return string with "implode" execution in param
 * 
 */
 function one_newspaper_get_categories_for_args($array) {
	if( ! $array ) return apply_filters( 'one_newspaper_categories_for_argument', '' );
	foreach( $array as $value ) {
		if( is_array( $value ) ) $string_array[] = $value['value'];
		if( is_object( $value ) ) $string_array[] = $value->value;
	}
	return apply_filters( 'one_newspaper_categories_for_argument', implode( ',', $string_array ) );
}

/**
 * Return array with execution in param
 * 
 */
function one_newspaper_get_post_id_for_args($array) {
	if( ! $array ) return apply_filters( 'one_newspaper_posts_slugs_for_argument', '' );
	foreach( $array as $value ) {
		if( is_array( $value ) ) $string_array[] = $value['value'];
		if( is_object( $value ) ) $string_array[] = $value->value;
	}
	return apply_filters( 'one_newspaper_posts_slugs_for_argument', $string_array );
}

if( !function_exists( 'one_newspaper_typo_fonts_url' ) ) :
	/**
	 * Filter and Enqueue typography fonts
	 * 
	 * @package One Newspaper
	 * @since 1.0.0
	 */
	function one_newspaper_typo_fonts_url() {
		$filter = ONE_NEWSPAPER_PREFIX . 'typo_combine_filter';

		$typography_presets = ONP\one_newspaper_get_customizer_option( 'typography_presets' );
		if( array_key_exists( 'typographies', $typography_presets ) ) :
			$typographies = $typography_presets[ 'typographies' ]; 
			foreach( $typographies as $typography ) :
				$fonts[] = apply_filters( $filter, 'typography_presets', $typography );
			endforeach;
		endif;
		$fonts[] = apply_filters( $filter, 'site_title_typo' );
		$fonts[] = apply_filters( $filter, 'site_tagline_typo' );
		$fonts[] = apply_filters( $filter, 'date_time_typography' );
		$fonts[] = apply_filters( $filter, 'header_menu_typo' );
		$fonts[] = apply_filters( $filter, 'header_sub_menu_typo' );
		$fonts[] = apply_filters( $filter, 'global_button_typo' );
		$fonts[] = apply_filters( $filter, 'footer_title_typography' );
		$fonts[] = apply_filters( $filter, 'footer_text_typography' );
		$fonts[] = apply_filters( $filter, 'bottom_footer_text_typography' );
		$fonts[] = apply_filters( $filter, 'footer_menu_typography' );
		$fonts[] = apply_filters( $filter, 'global_category_typography' );
		$fonts[] = apply_filters( $filter, 'sticky_posts_label_typography' );
		$fonts[] = apply_filters( $filter, 'sticky_posts_title_typography' );
		$fonts[] = apply_filters( $filter, 'secondary_menu_typo' );
		$fonts[] = apply_filters( $filter, 'site_block_title_typo' );
		$fonts[] = apply_filters( $filter, 'site_post_title_typo' );
		$fonts[] = apply_filters( $filter, 'site_post_meta_typo' );
		$fonts[] = apply_filters( $filter, 'site_post_content_typo' );
		$fonts[] = apply_filters( $filter, 'custom_button_text_typo' );
		$fonts[] = apply_filters( $filter, 'single_post_title_typo' );
		$fonts[] = apply_filters( $filter, 'single_post_meta_typo' );
		$fonts[] = apply_filters( $filter, 'single_post_content_typo' );
		$fonts[] = apply_filters( $filter, 'web_stories_preview_count_typo' );
		$fonts[] = apply_filters( $filter, 'web_stories_preview_title_typo' );
		$fonts[] = apply_filters( $filter, 'web_stories_title_typo' );
		$fonts[] = apply_filters( $filter, 'default_typo_one' );
		$fonts[] = apply_filters( $filter, 'default_typo_two' );

		$get_filtered_fonts = apply_filters( 'one_newspaper_get_fonts_toparse', $fonts );
		$_new_fonts_array = [];
		foreach( $get_filtered_fonts as $fonts ) {
			if( ! isset( $_new_fonts_array[$fonts['font_family']] ) ) {
				$_new_fonts_array[$fonts['font_family']] = [
					$fonts['variant']	=> [$fonts['font_weight']]
				];
			} else {
				if( ! isset( $_new_fonts_array[$fonts['font_family']][$fonts['variant']] ) ) {
					$_new_fonts_array[$fonts['font_family']][$fonts['variant']] = [$fonts['font_weight']];
				} else {
					if( ! in_array( $fonts['font_weight'], $_new_fonts_array[$fonts['font_family']][$fonts['variant']] ) ) $_new_fonts_array[$fonts['font_family']][$fonts['variant']][] = $fonts['font_weight'];
				}
			}
		}
		$_new_fonts_string = '';
		$_new_fonts_strings = [];
		foreach( $_new_fonts_array as $_new_font_key => $_new_font_value ) {
			$prefix_weight = false;
			$normal_weight = false;
			$_new_fonts_string = $_new_font_key . ':';
			if( isset( $_new_font_value['italic'] ) ) {
				$prefix_weight = true;
				$_new_fonts_string .= 'ital,';
			}
			$_new_fonts_string .= 'wght@';
			if( isset( $_new_font_value['normal'] ) && is_array( $_new_font_value['normal'] ) ) {
				$sorted_new_font_value = $_new_font_value['normal'];
				sort( $sorted_new_font_value, SORT_NUMERIC );
				foreach( $sorted_new_font_value as $font_weight_key => $font_weight_value ) {
					if( $font_weight_key > 0 ) $_new_fonts_string .= ';';
					if( $prefix_weight ) $_new_fonts_string .= '0,'. $font_weight_value;
					if( ! $prefix_weight ) $_new_fonts_string .= $font_weight_value;
				}
				$normal_weight = true;
			}

			if( isset( $_new_font_value['italic'] ) && is_array( $_new_font_value['italic'] ) ) {
				$sorted_new_font_value = $_new_font_value['italic'];
				sort( $sorted_new_font_value, SORT_NUMERIC );
				foreach( $sorted_new_font_value as $font_weight_key => $font_weight_value ) {
					if( $normal_weight ) $_new_fonts_string .= ';';
					if( ! $normal_weight && $font_weight_key > 0 ) $_new_fonts_string .= ';';
					if( $prefix_weight ) $_new_fonts_string .= '1,'. $font_weight_value;
					if( ! $prefix_weight ) $_new_fonts_string .= $font_weight_value;
				}
			}
			$_new_fonts_strings[] = urlencode($_new_fonts_string);
		}
		$google_fonts_url = add_query_arg( [
			'family'	=> implode( '&family=', $_new_fonts_strings ),
			'display'	=> 'swap'
		], 'https://fonts.googleapis.com/css2' );
		return $google_fonts_url;
	}
endif;

if(! function_exists('one_newspaper_get_color_format')):
    function one_newspaper_get_color_format( $color ) {
		if( is_array( $color ) ) return $color;
		if( str_contains( $color, '--one-newspaper-global-preset' ) ) {
			return( 'var( ' .esc_html( $color ). ' )' );
		} else {
			return $color;
		}
    }
endif;

if( ! function_exists( 'one_newspaper_get_rcolor_code' ) ) :
	/**
	 * Returns randon color code
	 * 
	 * @package One Newspaper
	 * @since 1.0.0
	 */
	function one_newspaper_get_rcolor_code() {
		$color_array["color"] = "#333333";
		$color_array["hover"] = "#448bef";
		return apply_filters( 'one_newspaper_apply_random_color_shuffle_value', $color_array );
	}
endif;

require get_template_directory() . '/inc/theme-starter.php'; // theme starter functions.
require get_template_directory() . '/inc/customizer/customizer.php'; // Customizer additions.
require get_template_directory() . '/inc/extras/helpers.php'; // helpers files.
require get_template_directory() . '/inc/extras/extras.php'; // extras files.
require get_template_directory() . '/inc/extras/extend-api.php'; // extras files.
require get_template_directory() . '/inc/widgets/widgets.php'; // widget handlers
require get_template_directory() . '/inc/metaboxes/metabox.php'; // metabox handlers
include get_template_directory() . '/inc/styles.php';
include get_template_directory() . '/inc/admin/admin.php';
new One_Newspaper_Admin\Admin_Page();
new One_Newspaper_Extend_Api();

/**
 * Filter posts ajax function
 *
 * @package One Newspaper
 * @since 1.0.0
 */
function one_newspaper_filter_posts_load_tab_content() {
	check_ajax_referer( 'one-newspaper-nonce', 'security' );
	$options = isset( $_GET['options'] ) ? json_decode( stripslashes( $_GET['options'] ) ): '';
	if( empty( $options ) ) return;
	$query = $options->query;
	$layout = $options->layout;
	$orderArray = explode( '-', $query->order );
	$posts_args = array(
		'posts_per_page'   => absint( $query->count ),
		'order' => esc_html( $orderArray[1] ),
		'orderby' => esc_html( $orderArray[0] ),
		'cat' => esc_html( $options->category_id ),
		'ignore_sticky_posts'    => true
	);
	if( $query->ids ) $post_args['post__not_in'] = one_newspaper_get_array_key_string_to_int( $query->ids );
	$n_posts = new \WP_Query( $posts_args );
	$total_posts = $n_posts->post_count;
	if( $n_posts -> have_posts() ):
		ob_start();
		echo '<div class="tab-content content-' .esc_html( $options->category_id ). '">';
			while( $n_posts->have_posts() ) : $n_posts->the_post();
				$options->featuredPosts = false;
				$res['loaded'] = true;
				$current_post = $n_posts->current_post;
				if( $layout == 'four' ) {
					if( $current_post === 0 ) echo '<div class="featured-post">';
					if( $current_post === 0 || $current_post === 1 ) $options->featuredPosts = true;
					if( $current_post === 2 ) {
						?>
						<div class="trailing-post">
						<?php
					}
				} else {
					if( ($current_post % 5) === 0 ) echo '<div class="row-wrap">';
						if( $current_post === 0 ) {
							echo '<div class="featured-post">';
							$options->featuredPosts = true;
						}
							if( $current_post === 1 || $current_post === 5 ) {
								?>
								<div class="trailing-post <?php if($current_post === 5) echo esc_attr('bottom-trailing-post'); ?>">
								<?php
							}
				}
								// get template file w.r.t par
								get_template_part( 'template-parts/news-filter/content', 'one', json_decode( json_encode( $options ), true ) );
				if( $layout == 'four' ) {
					if( $total_posts === $current_post + 1 ) echo '</div><!-- .trailing-post -->';
						if( $current_post === 1 ) echo '</div><!-- .featured-post-->';
				} else {
							if( $current_post === 4 || ( $total_posts === $current_post + 1 ) ) echo '</div><!-- .trailing-post -->';
						if( $current_post === 0 ) echo '</div><!-- .featured-post-->';
					if( ($current_post % 5) === 4 || ( $total_posts === $current_post + 1 ) ) echo '</div><!-- .row-wrap -->';
				}
			endwhile;
		echo '</div>';	
		$res['posts'] = ob_get_clean();
	else :
		$res['loaded'] = false;
		$res['posts'] = esc_html__( 'No posts found', 'one-newspaper' );
	endif;
	wp_send_json_success( $res );
	wp_die();
}
add_action( 'wp_ajax_one_newspaper_filter_posts_load_tab_content', 'one_newspaper_filter_posts_load_tab_content');
add_action( 'wp_ajax_nopriv_one_newspaper_filter_posts_load_tab_content', 'one_newspaper_filter_posts_load_tab_content' );

/**
 * Filter posts layout 6 ajax function
 *
 * @package One Newspaper
 * @since 1.0.0
 */
function one_newspaper_filter_layout_five_posts_load_tab_content() {
	check_ajax_referer( 'one-newspaper-nonce', 'security' );
	$options = isset( $_GET['options'] ) ? json_decode( stripslashes( $_GET['options'] ) ): '';
	if( empty( $options ) ) return;
	$query = $options->query;
	$layout = $options->layout;
	$orderArray = explode( '-', $query->order );
	$posts_args = array(
		'posts_per_page'   => absint( $query->count ),
		'order' => esc_html( $orderArray[1] ),
		'orderby' => esc_html( $orderArray[0] ),
		'cat' => esc_html( $options->category_id ),
		'ignore_sticky_posts'    => true
	);
	if( $query->ids ) $posts_args['post__not_in'] = one_newspaper_get_array_key_string_to_int( $query->ids );
	$post_query = new \WP_Query( $posts_args );
	$total_posts = $post_query->post_count;
	if( $post_query->have_posts() ):
		ob_start();
		?>
			<div class="tab-content content-<?php echo esc_attr( $options->category_id )?>">
                <?php
                    unset( $posts_args['category_name'] );
					$delay = 0;
					$row_count = 0;
					while( $post_query->have_posts() ) : $post_query->the_post();
						$res['loaded'] = true;
						$options->featuredPosts = ( $layout === 'six' );
						if( $layout === 'five' ) {
							$current_post = $post_query->current_post;
							$last_item = ( $total_posts === ( $current_post + 1 ) );
							if( ( $current_post % 5 ) === 0 && $row_count < 2  ) {
								echo '<div class="row-wrap">';
								$row_count++;
							}
								if( $current_post === 0 ) {
									echo '<div class="featured-post">';
									$options->featuredPosts = true;
								}
									if( $current_post === 1 || $current_post === 5 ) {
										?>
										<div class="trailing-post <?php if($current_post === 5) echo esc_attr('bottom-trailing-post'); ?>">
										<?php
									}
										if( $current_post === 1 ) echo '<div class="grid-posts">';
										if( $current_post === 3 ) echo '<div class="list-posts">';
						}
									$options->delay = $delay;
									// get template file w.r.t par
										get_template_part( 'template-parts/news-filter/content', 'one', json_decode( json_encode( $options ), true ) );
						if( $layout === 'five' ) {
												if( $current_post === 2 || ( $last_item && $total_posts <= 3 && $total_posts >= 2 ) ) echo '</div><!-- .grid-posts -->';
										if( $current_post === 4 || ( $last_item && $total_posts <= 5 && $total_posts >= 4 ) ) echo '</div><!-- .list-posts -->';
									if( $current_post === 4 || $last_item ) echo '</div><!-- .trailing-post -->';
								if( $current_post === 0 ) echo '</div><!-- .featured-post-->';
								if( ! in_array( $current_post, [ 0, 4 ] ) && $last_item ) echo '</div><!-- .total-posts-close -->';
							if( $current_post === 4 && $row_count <= 2 ) echo '</div><!-- .row-wrap -->';
						}
						$delay += 50;
					endwhile;
                ?>
            </div>
		<?php
		$res['posts'] = ob_get_clean();
	else :
		$res['loaded'] = false;
		$res['posts'] = esc_html__( 'No posts found', 'one-newspaper' );
	endif;
	wp_send_json_success( $res );
	wp_die();
}
add_action( 'wp_ajax_one_newspaper_filter_layout_five_posts_load_tab_content', 'one_newspaper_filter_layout_five_posts_load_tab_content');
add_action( 'wp_ajax_nopriv_one_newspaper_filter_layout_five_posts_load_tab_content', 'one_newspaper_filter_layout_five_posts_load_tab_content' );

if( ! function_exists( 'one_newspaper_lazy_load_value' ) ) :
	/**
	 * Echos lazy load attribute value.
	 * 
	 * @package One Newspaper
	 * @since 1.0.0
	 */
	function one_newspaper_lazy_load_value() {
		echo esc_attr( apply_filters( 'one_newspaper_lazy_load_value', 'lazy' ) );
	}
endif;

if( ! function_exists( 'one_newspaper_add_menu_description' ) ) :
	// merge menu description element to the menu 
	function one_newspaper_add_menu_description( $item_output, $item, $depth, $args ) {
		if($args->theme_location != 'menu-2') return $item_output;
		
		if ( !empty( $item->description ) ) {
			$item_output = str_replace( $args->link_after . '</a>', '<span class="menu-item-description">' . $item->description . '</span>' . $args->link_after . '</a>', $item_output );
		}
		return $item_output;
	}
	add_filter( 'walker_nav_menu_start_el', 'one_newspaper_add_menu_description', 10, 4 );
endif;

if( ! function_exists( 'one_newspaper_bool_to_string' ) ) :
	// boolean value to string 
	function one_newspaper_bool_to_string( $bool ) {
		$string = ( $bool ) ? '1' : '0';
		return $string;
	}
endif;

if( ! function_exists( 'one_newspaper_get_image_sizes_option_array' ) ) :
	/**
	 * Get list of image sizes
	 * 
	 * @since 1.0.0
	 * @package One Newspaper
	 */
	function one_newspaper_get_image_sizes_option_array() {
		$image_sizes = get_intermediate_image_sizes();
		foreach( $image_sizes as $image_size ) :
			$sizes[] = [
				'label'	=> esc_html( $image_size ),
				'value'	=> esc_html( $image_size )
			];
		endforeach;
		return $sizes;
	}
endif;

if( ! function_exists( 'one_newspaper_get_style_tag' ) ) :
	/**
	 * Generate Style tag for image ratio and image radius for news grid, list, carousel
	 * 
	 * @since 1.0.0
	 * @package One Newspaper
	 */
	function one_newspaper_get_style_tag( $variables, $selectors = '' ) {
		echo '<style id="'. esc_attr( $variables['unique_id'] ) .'-style">';
			if( isset( $variables['image_ratio'] ) ) {
				$image_ratio = $variables['image_ratio'];

				if( $image_ratio[ 'desktop' ] > 0 ) echo "#" . $variables['unique_id']. " article figure.post-thumb-wrap { padding-bottom: calc( " . $image_ratio[ 'desktop' ] . " * 100% ) }\n";

				if( $image_ratio[ 'tablet' ] > 0 ) echo " @media (max-width: 769px){ #" . $variables['unique_id']. " article figure.post-thumb-wrap { padding-bottom: calc( " . $image_ratio[ 'tablet' ] . " * 100% ) } }\n";

				if( $image_ratio[ 'smartphone' ] > 0 ) echo " @media (max-width: 548px){ #" . $variables['unique_id']. " article figure.post-thumb-wrap { padding-bottom: calc( " . $image_ratio[ 'smartphone' ] . " * 100% ) }}\n";

			}
		echo "</style>";
	}
endif;

if( ! function_exists( 'one_newspaper_get_style_tag_fb' ) ) :
	/**
	 * Generates style tag for image ratio and image radius for news filter and new block
	 * 
	 * @since 1.0.0
	 * @package One Newspaper
	 */
	function one_newspaper_get_style_tag_fb( $variables, $selectors = '' ) {
		echo '<style id="'. esc_attr( $variables['unique_id'] ) .'-style">';
			if( isset( $variables['image_ratio'] ) ) {
				$image_ratio = $variables['image_ratio'];
				// for featured post
				if( $variables['layout'] == 'three' ) {

					if( $image_ratio[ 'desktop' ] > 0 ) echo "#" . $variables['unique_id']. ".one-newspaper-block.layout--three .featured-post figure { padding-bottom: calc( " . ( $image_ratio[ 'desktop' ] * 0.4 ) . " * 100% ) }\n";

					if( $image_ratio[ 'tablet' ] > 0 ) echo "@media (max-width: 769px) {#" . $variables['unique_id']. ".one-newspaper-block.layout--three .featured-post figure { padding-bottom: calc( " . ( $image_ratio[ 'tablet' ] * 0.4 ) . " * 100% ) } }\n";

					if( $image_ratio[ 'smartphone' ] > 0 ) echo "@media (max-width: 769px) {#" . $variables['unique_id']. ".one-newspaper-block.layout--three .featured-post figure { padding-bottom: calc( " . ( $image_ratio[ 'smartphone' ] * 0.4 ) . " * 100% ) } }\n";	

				} else {

					if( $image_ratio[ 'desktop' ] > 0 ) echo "#" . $variables['unique_id']. ".one-newspaper-block .featured-post figure { padding-bottom: calc( " . $image_ratio[ 'desktop' ] . " * 100% ) }\n";

					if( $image_ratio[ 'tablet' ] > 0 ) echo "@media (max-width: 769px) {#" . $variables['unique_id']. ".one-newspaper-block .featured-post figure { padding-bottom: calc( " . $image_ratio[ 'tablet' ] . " * 100% ) } }\n";

					if( $image_ratio[ 'smartphone' ] > 0 ) echo "@media (max-width: 769px) {#" . $variables['unique_id']. ".one-newspaper-block .featured-post figure { padding-bottom: calc( " . $image_ratio[ 'smartphone' ] . " * 100% ) } }\n";

				}

				// for trailing post
				if( $variables['layout'] == 'two' ) {
					
					if( $image_ratio[ 'desktop' ] > 0 ) echo "#" . $variables['unique_id']. ".one-newspaper-block.layout--two .trailing-post figure { padding-bottom: calc( " . ( $image_ratio[ 'desktop' ] * 0.78 ) . " * 100% ) }\n";

					if( $image_ratio[ 'tablet' ] > 0 ) echo "@media (max-width: 769px) {#" . $variables['unique_id']. ".one-newspaper-block .trailing-post figure { padding-bottom: calc( " . ( $image_ratio[ 'tablet' ] * 0.78 ) . " * 100% ) } }\n";

					if( $image_ratio[ 'smartphone' ] > 0 ) echo "@media (max-width: 769px) {#" . $variables['unique_id']. ".one-newspaper-block.layout--two .trailing-post figure { padding-bottom: calc( " . ( $image_ratio[ 'smartphone' ] * 0.78 ) . " * 100% ) } }\n";

				} else {

					if( $image_ratio[ 'desktop' ] > 0 ) echo "#" . $variables['unique_id']. ".one-newspaper-block .trailing-post figure { padding-bottom: calc( " . ( $image_ratio[ 'desktop' ] * 0.3 ) . " * 100% ) }\n";

					if( $image_ratio[ 'tablet' ] > 0 ) echo "@media (max-width: 769px) {#" . $variables['unique_id']. ".one-newspaper-block .trailing-post figure { padding-bottom: calc( " . ( $image_ratio[ 'tablet' ] * 0.3 ) . " * 100% ) } }\n";

					if( $image_ratio[ 'smartphone' ] > 0 ) echo "@media (max-width: 769px) {#" . $variables['unique_id']. ".one-newspaper-block .trailing-post figure { padding-bottom: calc( " . ( $image_ratio[ 'smartphone' ] * 0.3 ) . " * 100% ) } }\n";

				}

			}
		echo "</style>";
	}
endif;

if( ! function_exists( 'one_newspaper_get_image_sizes' ) ) :
	/**
	 * get a list of all images sizes
	 * 
	 * @since 1.0.0
	 * @package One Newspaper
	 */
	function one_newspaper_get_image_sizes() {
		$image_sizes_args = get_intermediate_image_sizes();
		$image_size_elements_args = [];
		if( ! empty( $image_sizes_args ) ) :
			foreach( $image_sizes_args as $image_size ) :
				$image_size_elements_args[$image_size] = esc_html( $image_size );
			endforeach;
		endif;
		return $image_size_elements_args;
	}
endif;

if( ! function_exists( 'one_newspaper_parse_icon_picker_value' ) ) :
	/**
	 * Function to return image url for icon picker
	 */
	function one_newspaper_parse_icon_picker_value ( $control ) {
		if( $control['type'] == 'svg' ) :
			$control['url'] = wp_get_attachment_image_url( $control['value'], 'full' );
		endif;
		return $control;
	}
endif;

if( ! function_exists( 'one_newspaper_get_all_social_share' ) ) :
	/**
	 * All social share icons and urls
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_get_all_social_share( $icon = '' ) {
		$postUrl = 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
        $allIcons = [
			'fa-brands fa-facebook'	=>	[
				'label'	=>	esc_html__( 'Facebook', 'one-newspaper' ),
				'value'	=>	'https://www.facebook.com/sharer/sharer.php?u=',
			],
			'fa-brands fa-facebook-f'	=>	[
				'label'	=>	esc_html__( 'Facebook', 'one-newspaper' ),
				'value'	=>	'https://www.facebook.com/sharer/sharer.php?u=',
			],
			'fa-brands fa-square-facebook'	=>	[
				'label'	=>	esc_html__( 'Facebook', 'one-newspaper' ),
				'value'	=>	'https://www.facebook.com/sharer/sharer.php?u=',
			],
			'fa-brands fa-square-x-twitter'	=>	[
				'label'	=>	esc_html__( 'Twitter', 'one-newspaper' ),
				'value'	=>	'https://twitter.com/intent/tweet?url=',
			],
			'fa-brands fa-x-twitter'	=>	[
				'label'	=>	esc_html__( 'Twitter', 'one-newspaper' ),
				'value'	=>	'https://twitter.com/intent/tweet?url=',
			],
			'fa-brands fa-twitter'	=>	[
				'label'	=>	esc_html__( 'Twitter', 'one-newspaper' ),
				'value'	=>	'https://twitter.com/intent/tweet?url=',
			],
			'fa-brands fa-linkedin'	=>	[
				'label'	=>	esc_html__( 'Linkedin', 'one-newspaper' ),
				'value'	=>	'https://www.linkedin.com/sharing/share-offsite/?url=',
			],
			'fa-brands fa-linkedin-in'	=>	[
				'label'	=>	esc_html__( 'Linkedin', 'one-newspaper' ),
				'value'	=>	'https://www.linkedin.com/sharing/share-offsite/?url=',
			],
			'fa-solid fa-envelope'	=>	[
				'label'	=>	esc_html__( 'Envelope', 'one-newspaper' ),
				'value'	=>	'mailto:?subject={title}&body=',
			],
			'fa-regular fa-envelope'	=>	[
				'label'	=>	esc_html__( 'Envelope', 'one-newspaper' ),
				'value'	=>	'https://mail.google.com/mail/?view=cm&to={email_address}&su={title}&body=',
			],
			'fa-brands fa-instagram'	=>	[
				'label'	=>	esc_html__( 'Instagram', 'one-newspaper' ),
				'value'	=>	'http://www.instagram.com',
			],
			'fa-brands fa-square-instagram'	=>	[
				'label'	=>	esc_html__( 'Instagram', 'one-newspaper' ),
				'value'	=>	'http://www.instagram.com',
			],
			'fa-brands fa-whatsapp'	=>	[
				'label'	=>	esc_html__( 'Whatsapp', 'one-newspaper' ),
				'value'	=>	'https://api.whatsapp.com/send?phone={phone_number}&text=',
			],
			'fa-brands fa-square-whatsapp'	=>	[
				'label'	=>	esc_html__( 'Whatsapp', 'one-newspaper' ),
				'value'	=>	'https://api.whatsapp.com/send?phone={phone_number}&text=',
			],
			'fa-brands fa-reddit'	=>	[
				'label'	=>	esc_html__( 'Reddit', 'one-newspaper' ),
				'value'	=>	'https://reddit.com/submit?url=',
			],
			'fa-brands fa-reddit-alien'	=>	[
				'label'	=>	esc_html__( 'Reddit', 'one-newspaper' ),
				'value'	=>	'https://reddit.com/submit?url=',
			],
			'fa-brands fa-square-reddit'	=>	[
				'label'	=>	esc_html__( 'Reddit', 'one-newspaper' ),
				'value'	=>	'https://reddit.com/submit?url=',
			],
			'fa-brands fa-weixin'	=>	[
				'label'	=>	esc_html__( 'Weixin', 'one-newspaper' ),
				'value'	=>	'https://widget.wechat.com/o/qrcode/',
			],
			'fa-brands fa-tumblr'	=>	[
				'label'	=>	esc_html__( 'Tumblr', 'one-newspaper' ),
				'value'	=>	'https://www.tumblr.com/widgets/share/tool?canonicalUrl=',
			],
			'fa-brands fa-square-tumblr'	=>	[
				'label'	=>	esc_html__( 'Tumblr', 'one-newspaper' ),
				'value'	=>	'https://www.tumblr.com/widgets/share/tool?canonicalUrl=',
			],
			'fa-brands fa-weibo'	=>	[
				'label'	=>	esc_html__( 'Weibo', 'one-newspaper' ),
				'value'	=>	'http://service.weibo.com/share/share.php?url=',
			],
			'fa-brands fa-google-plus'	=>	[
				'label'	=>	esc_html__( 'Google Plus', 'one-newspaper' ),
				'value'	=>	'https://plus.google.com/share?url=',
			],
			'fa-brands fa-google-plus-g'	=>	[
				'label'	=>	esc_html__( 'Google Plus', 'one-newspaper' ),
				'value'	=>	'https://plus.google.com/share?url=',
			],
			'fa-brands fa-square-google-plus'	=>	[
				'label'	=>	esc_html__( 'Google Plus', 'one-newspaper' ),
				'value'	=>	'https://plus.google.com/share?url=',
			],
			'fa-brands fa-skype'	=>	[
				'label'	=>	esc_html__( 'Skype', 'one-newspaper' ),
				'value'	=>	'https://web.skype.com/share?url=',
			],
			'fa-brands fa-telegram'	=>	[
				'label'	=>	esc_html__( 'Telegram', 'one-newspaper' ),
				'value'	=>	'https://telegram.me/share/url?url=',
			],
			'fa-brands fa-pinterest'	=>	[
				'label'	=>	esc_html__( 'Pinterest', 'one-newspaper' ),
				'value'	=>	'http://pinterest.com/pin/create/link/?url=',
			],
			'fa-brands fa-pinterest-p'	=>	[
				'label'	=>	esc_html__( 'Pinterest', 'one-newspaper' ),
				'value'	=>	'http://pinterest.com/pin/create/link/?url=',
			],
			'fa-brands fa-square-pinterest'	=>	[
				'label'	=>	esc_html__( 'Pinterest', 'one-newspaper' ),
				'value'	=>	'http://pinterest.com/pin/create/link/?url=',
			],
			'fa-brands fa-vk'	=>	[
				'label'	=>	esc_html__( 'VK', 'one-newspaper' ),
				'value'	=>	'http://vk.com/share.php?url=',
			],
			'fa-brands fa-line'	=>	[
				'label'	=>	esc_html__( 'Line', 'one-newspaper' ),
				'value'	=>	'https://social-plugins.line.me/lineit/share?url=',
			],
			'fa-brands fa-blogger'	=>	[
				'label'	=>	esc_html__( 'Blogger', 'one-newspaper' ),
				'value'	=>	'https://www.blogger.com/blog-this.g?u=',
			],
			'fa-brands fa-blogger-b'	=>	[
				'label'	=>	esc_html__( 'Blogger', 'one-newspaper' ),
				'value'	=>	'https://www.blogger.com/blog-this.g?u=',
			],
			'fa-brands fa-evernote'	=>	[
				'label'	=>	esc_html__( 'Evernote', 'one-newspaper' ),
				'value'	=>	'https://www.evernote.com/clip.action?url=',
			],
			'fa-brands fa-yahoo'	=>	[
				'label'	=>	esc_html__( 'Yahoo', 'one-newspaper' ),
				'value'	=>	'http://compose.mail.yahoo.com/?to={email_address}&subject={title}&body=',
			],
			'fa-brands fa-odnoklassniki'	=>	[
				'label'	=>	esc_html__( 'Odnoklassniki', 'one-newspaper' ),
				'value'	=>	'https://connect.ok.ru/dk?st.cmd=WidgetSharePreview&st.shareUrl=',
			],
			'fa-brands fa-square-odnoklassniki'	=>	[
				'label'	=>	esc_html__( 'Odnoklassniki', 'one-newspaper' ),
				'value'	=>	'https://connect.ok.ru/dk?st.cmd=WidgetSharePreview&st.shareUrl=',
			],
			'fa-brands fa-viber'	=>	[
				'label'	=>	esc_html__( 'Viber', 'one-newspaper' ),
				'value'	=>	'viber://forward?text=',
			],
			'fa-brands fa-get-pocket'	=>	[
				'label'	=>	esc_html__( 'Get Pocket', 'one-newspaper' ),
				'value'	=>	'https://getpocket.com/edit?url=',
			],
			'fa-brands fa-mix'	=>	[
				'label'	=>	esc_html__( 'Mix', 'one-newspaper' ),
				'value'	=>	'https://mix.com/add?url=',
			],
			'fa-brands fa-flipboard'	=>	[
				'label'	=>	esc_html__( 'Flipboard', 'one-newspaper' ),
				'value'	=>	'https://share.flipboard.com/bookmarklet/popout?v=2&title=[TITLE]&url=',
			],
			'fa-brands fa-square-xing'	=>	[
				'label'	=>	esc_html__( 'Xing', 'one-newspaper' ),
				'value'	=>	'https://www.xing.com/app/user?op=share;url=',
			],
			'fa-brands fa-xing'	=>	[
				'label'	=>	esc_html__( 'Xing', 'one-newspaper' ),
				'value'	=>	'https://www.xing.com/app/user?op=share;url=',
			],
			'fa-brands fa-digg'	=>	[
				'label'	=>	esc_html__( 'Digg', 'one-newspaper' ),
				'value'	=>	'http://digg.com/submit?url=',
			],
			'fa-brands fa-stumbleupon-circle'	=>	[
				'label'	=>	esc_html__( 'Stumbleupon', 'one-newspaper' ),
				'value'	=>	'http://www.stumbleupon.com/submit?url=',
			],
			'fa-brands fa-stumbleupon'	=>	[
				'label'	=>	esc_html__( 'Stumbleupon', 'one-newspaper' ),
				'value'	=>	'http://www.stumbleupon.com/submit?url=',
			],
			'fa-brands fa-delicious'	=>	[
				'label'	=>	esc_html__( 'Delicious', 'one-newspaper' ),
				'value'	=>	'https://delicious.com/save?v=5&provider=[PROVIDER]&noui&jump=close&url=',
			],
			'fa-brands fa-buffer'	=>	[
				'label'	=>	esc_html__( 'Buffer', 'one-newspaper' ),
				'value'	=>	'http://bufferapp.com/add?text=[post-title]&url=',
			],
			'fa-brands fa-diaspora'	=>	[
				'label'	=>	esc_html__( 'Diaspora', 'one-newspaper' ),
				'value'	=>	'https://share.diasporafoundation.org/?title={title}&url=',
			],
			'fa-brands fa-hacker-news'	=>	[
				'label'	=>	esc_html__( 'Hacker News', 'one-newspaper' ),
				'value'	=>	'https://news.ycombinator.com/submitlink?u=',
			],
			'fa-solid fa-comment-sms'	=>	[
				'label'	=>	esc_html__( 'SMS', 'one-newspaper' ),
				'value'	=>	'sms:{phone_number}?body=',
			],
			'fa-brands fa-wordpress'	=>	[
				'label'	=>	esc_html__( 'Wordpress', 'one-newspaper' ),
				'value'	=>	'https://wordpress.com/press-this.php?u=',
			],
			'fa-brands fa-wordpress-simple'	=>	[
				'label'	=>	esc_html__( 'Wordpress', 'one-newspaper' ),
				'value'	=>	'https://wordpress.com/press-this.php?u=',
			],
			'fa-solid fa-copy'	=>	[
				'label'	=>	esc_html__( 'Copy', 'one-newspaper' ),
				'value'	=>	$postUrl,
			],
			'fa-solid fa-print'	=>	[
				'label'	=>	esc_html__( 'Print', 'one-newspaper' ),
				'value'	=>	'print',
			],
			'fa-brands fa-amazon'	=>	[
				'label'	=>	esc_html__( 'Amazon', 'one-newspaper' ),
				'value'	=>	'http://www.amazon.com/wishlist/add?u=',
			],
			'fa-brands fa-renren'	=>	[
				'label'	=>	esc_html__( 'Renren', 'one-newspaper' ),
				'value'	=>	'https://www.connect.renren.com/share/sharer?url=',
			],
			'fa-brands fa-trello'	=>	[
				'label'	=>	esc_html__( 'Trello', 'one-newspaper' ),
				'value'	=>	'https://trello.com/add-card?mode=popup&url=',
			],
			'fa-brands fa-viadeo'	=>	[
				'label'	=>	esc_html__( 'Viadeo', 'one-newspaper' ),
				'value'	=>	'http://www.viadeo.com/shareit/share/?url=',
			],
			'fa-brands fa-square-viadeo'	=>	[
				'label'	=>	esc_html__( 'Viadeo', 'one-newspaper' ),
				'value'	=>	'http://www.viadeo.com/shareit/share/?url='
			]
		];
		if( $icon === '' ) :
			return $allIcons;
		else:
			return $allIcons[ $icon ];
		endif;
	}
endif;

if ( ! function_exists( 'one_newspaper_create_elementor_kit' ) ) {
    /**
     * Create Elementor default kit
     *
     * @since 1.0.0
     */
    function one_newspaper_create_elementor_kit() {
        if ( ! did_action( 'elementor/loaded' ) ) return;
        $kit = Elementor\Plugin::$instance->kits_manager->get_active_kit();
        if ( ! $kit->get_id() ) :
            $created_default_kit = Elementor\Plugin::$instance->kits_manager->create_default();
            update_option( 'elementor_active_kit', $created_default_kit );
		endif;
    }
    add_action( 'init', 'one_newspaper_create_elementor_kit' );
}

 if( ! function_exists( 'one_newspaper_get_archive_layout_meta' ) ) :
	/**
	 * Get archive layout
	 * 
	 * @since 1.0.0
	 */
 	function one_newspaper_get_archive_layout_meta() {
		$current_id = get_queried_object_id();
		$archive_layout_meta = 'customizer-layout';
		if( is_category() ) :
			$archive_meta_key = '_one_newspaper_category_archive_custom_meta_field';
			$archive_layout_meta = metadata_exists( 'term', $current_id, $archive_meta_key ) ? get_term_meta( $current_id, $archive_meta_key, true ) : 'customizer-layout';
		elseif ( is_tag() ) :
			$archive_meta_key = '_one_newspaper_post_tag_archive_custom_meta_field';
			$archive_layout_meta = metadata_exists( 'term', $current_id, $archive_meta_key ) ? get_term_meta( $current_id, $archive_meta_key, true ) : 'customizer-layout';
		endif;

		return $archive_layout_meta;
	}
 endif;

 if( ! function_exists( 'one_newspaper_get_archive_sidebar_meta' ) ) :
	/**
	 * Get archive sidebar layout
	 * 
	 * @since 1.0.0
	 */
 	function one_newspaper_get_archive_sidebar_meta() {
		$current_id = get_queried_object_id();
		$archive_sidebar_meta = 'customizer-setting';
		if( is_category() ) :
			$archive_meta_key = '_one_newspaper_category_sidebar_custom_meta_field';
			$archive_sidebar_meta = metadata_exists( 'term', $current_id, $archive_meta_key ) ? get_term_meta( $current_id, $archive_meta_key, true ) : 'customizer-setting';
		elseif ( is_tag() ) :
			$archive_meta_key = '_one_newspaper_post_tag_sidebar_custom_meta_field';
			$archive_sidebar_meta = metadata_exists( 'term', $current_id, $archive_meta_key ) ? get_term_meta( $current_id, $archive_meta_key, true ) : 'customizer-setting';
		endif;

		return $archive_sidebar_meta;
	}
 endif;

 if( ! function_exists( 'one_newspaper_post_order_args' ) ) :
	/**
	 * Return post order args
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_post_order_args() {
		return [
			'date-desc' =>  esc_html__( 'Newest - Oldest', 'one-newspaper' ),
			'date-asc' =>  esc_html__( 'Oldest - Newest', 'one-newspaper' ),
			'rand-desc' =>  esc_html__( 'Random', 'one-newspaper' )
		];
	}
endif;

if( ! function_exists( 'one_newspaper_stories_ajax_call' ) ) :
	/**
	 * Add stories to web stories according to current active story
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_stories_ajax_call() {
		check_ajax_referer( 'one-newspaper-nonce', '_wpnonce' );
		$story_ids = ( isset( $_POST[ 'storyIds' ] ) ) ? $_POST[ 'storyIds' ] : '';
		$count = ( isset( $_POST[ 'count' ] ) ) ? $_POST[ 'count' ] : '';
		if( $story_ids ) :
			$query_args = [
				'post_type'	=>	'post',
				'post_status'	=>	'publish',
				'no_found_rows'	=>	true
			];
			$post_per_page = ONP\one_newspaper_get_customizer_option( 'web_stories_max_no_of_inner_stories' );
			$query_args[ 'posts_per_page' ] = absint( $post_per_page );
			$success_flag = false;
			ob_start();
			foreach( $story_ids as $cat_id ) :
				$query_args[ 'cat' ] = $cat_id;
				$query_instance = new WP_Query( apply_filters( 'one_newspaper_query_args_filter', $query_args ) );
				if( $query_instance->have_posts() ) :
					$success_flag = true;
						echo '<div class="inner-story">';
	
							echo '<div class="inner-story-wrap" data-id="', esc_attr( $cat_id ) ,'">';
	
								while( $query_instance->have_posts() ) : $query_instance->the_post();
									?>
										<div class="story-item<?php if( ! has_post_thumbnail() ) echo ' no-thumb'; ?>">
	
											<div class="story-cover-wrap">
	
												<figure class="story-cover">
	
													<?php 
														// thumbnail
														the_post_thumbnail( 'post-thumbnail', [
															'loading'	=>	'lazy'
														]);
	
													?>
	
												</figure>
	
											</div>
	
											<?php
	
												echo '<div class="content-wrap">';
														
													// categories
													one_newspaper_get_post_categories( get_the_ID(), 2 );
	
													// title
													the_title( '<h2 class="title"><a href="'. get_the_permalink() .'">', '</a></h2>' );
	
													// Meta
	
													echo '<div class="meta-wrap">';
		
														// author
														one_newspaper_posted_by();
		
														// date
														one_newspaper_posted_on();
		
													echo '</div>';
	
												echo '</div>';
	
											?>
	
										</div>
	
									<?php
								endwhile;
	
							echo '</div>';
	
						echo '</div>';
						wp_reset_postdata();
					endif;
			endforeach;
			$res = ob_get_clean();
		endif;
		$success_flag ? wp_send_json_success( $res ) : wp_send_json_error( esc_html__( 'No stories found', 'one-newspaper' ) );
		wp_die();
	}
	add_action( 'wp_ajax_one_newspaper_stories_ajax_call', 'one_newspaper_stories_ajax_call' );
	add_action( 'wp_ajax_nopriv_one_newspaper_stories_ajax_call', 'one_newspaper_stories_ajax_call' );
endif;

if( ! function_exists( 'one_newspaper_sticky_posts_ajax_call' ) ) :
	/**
	 * Fetch append posts for sticky posts
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_sticky_posts_ajax_call() {
		check_ajax_referer( 'one-newspaper-nonce', '_wpnonce' );
		$args[ 'classes' ] = 'append';
		$posts_to_append = ONP\one_newspaper_get_customizer_option( 'sticky_posts_posts_to_append' );
		$total_posts = ONP\one_newspaper_get_customizer_option( 'sticky_posts_to_show' );
		$query_args = one_newspaper_get_query_args( 'sticky' );
		$query_args[ 'posts_per_page' ] = absint( $posts_to_append );
		$query_args[ 'offset' ] = absint( $total_posts - $posts_to_append );
		$query_args[ 'offset' ] = absint( $total_posts - $posts_to_append );
		$success_flag = false;
		ob_start();
		$query_instance = new WP_Query( $query_args );
		if( $query_instance->have_posts() ) :
			$success_flag = true;
			$count = $total_posts - $posts_to_append;
			while( $query_instance->have_posts() ) : $query_instance->the_post();
				$count++;
				$args[ 'count' ] = $count;
				get_template_part( 'template-parts/content', 'sticky-posts', $args );
			endwhile;
		endif;
		$res = ob_get_clean();
		$success_flag ? wp_send_json_success( $res ) : wp_send_json_error( esc_html__( 'No posts to append.', 'one-newspaper' ) );
		wp_die();
	}
	add_action( 'wp_ajax_one_newspaper_sticky_posts_ajax_call', 'one_newspaper_sticky_posts_ajax_call' );
	add_action( 'wp_ajax_nopriv_one_newspaper_sticky_posts_ajax_call', 'one_newspaper_sticky_posts_ajax_call' );
endif;

if( ! function_exists( 'one_newspaper_get_query_args' ) ) :
	/**
	 * Get Query Parameters of WP Query
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_get_query_args( $prefix = '' ) {
		$category_ids = ONP\one_newspaper_get_customizer_option( $prefix . '_posts_categories' );
		$posts_to_include = ONP\one_newspaper_get_customizer_option( $prefix . '_posts_to_include' );
		$post_order = ONP\one_newspaper_get_customizer_option( $prefix . '_posts_order' );
		$exploded_order = explode( '-', $post_order );
		$posts_to_show = ONP\one_newspaper_get_customizer_option( $prefix . '_posts_to_show' );
		$hide_empty = ONP\one_newspaper_get_customizer_option( $prefix . '_hide_empty' );

		$posts_args = [
            'post_type' =>  'post',
            'post_status'  =>  'publish',
            'posts_per_page'    =>  absint( $posts_to_show ),
            'order' =>  $exploded_order[ 1 ],
            'orderby'   =>  $exploded_order[ 0 ],
            'ignore_sticky_posts'   =>  true,
            'fields'    =>  'ids',
            'no_found_rows' =>  true
        ];

		$post_categories_id_args = ( ! empty( $category_ids ) ) ? implode( ",", array_column( $category_ids, 'value' ) ) : '';
        $post_to_include_id_args = ( ! empty( $posts_to_include ) ) ? array_column( $posts_to_include, 'value' ) : '';

		if( isset( $category_ids ) ) $posts_args[ 'cat' ] = $post_categories_id_args;
        if( isset( $posts_to_include ) ) $posts_args[ 'post__in' ] = $post_to_include_id_args;

		if( $hide_empty ) :
            $posts_args[ 'meta_query' ] = [
                [
                    'key'   =>  '_thumbnail_id',
                    'compare'   =>  'EXISTS'
                ]
            ];
        endif;
		return $posts_args;
	}
endif;

if( ! function_exists( 'one_newspaper_get_reorder_value' ) ) :
	/**
	 * Get Reorder value
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_get_reorder_value( $reorder ) {
		if( is_array( $reorder ) ) :
			$filtered_value = [];
			foreach( $reorder as $section ) :
				$filtered_value[ $section[ 'value' ] ] = $section[ 'option' ];
			endforeach;
			return $filtered_value;
		endif;
		return $reorder;
	}
endif;

if( ! function_exists( 'one_newspaper_search_query_section' ) ) :
	/**
	 * Search Query Section
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_search_query_section() {
		$term_args = [
			'fields'	=>	'id=>name',
			'hide_empty'	=>	true
		];
		$categories = get_categories( $term_args );
		$tags = get_tags( $term_args );
		$user_query = new \WP_User_Query([
			'fields'    =>  [ 'ID', 'display_name' ]
		]);
		$post_types = [
			'post'	=>	esc_html__( 'Posts', 'one-newspaper' ),
			'page'	=>	esc_html__( 'Pages', 'one-newspaper' ),
		];
		?>
			<div class="filter-wrapper">
				<div class="filter has-dropdown type">
					<div class="head">
						<span class="label"><?php esc_html_e( 'Types', 'one-newspaper' ); ?></span>
						<span class="icon"><i class="fa-solid fa-angle-down"></i></span>
					</div>
					<div class="body">
						<?php
							if( is_array( $post_types ) && ! empty( $post_types ) ) :
								echo '<div class="items">';
								foreach( $post_types as $key => $type ) :
									?>
										<div class="item">
											<input type="checkbox" name="type-<?php echo esc_attr( $key ); ?>" id="type-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>">
											<label for="type-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $type ); ?></label>
										</div>
									<?php
								endforeach;
								echo '</div>';
							endif;
						?>
						<button class="clear"><?php esc_html_e( 'Clear', 'one-newspaper' ); ?></button>
					</div>
				</div>
				<div class="filter has-dropdown authors">
					<div class="head">
						<span class="label"><?php esc_html_e( 'Authors', 'one-newspaper' ); ?></span>
						<span class="icon"><i class="fa-solid fa-angle-down"></i></span>
					</div>
					<div class="body">
						<?php
							if( is_array( $user_query->get_results() ) && ! empty( $user_query->get_results() ) ) :
								echo '<div class="items">';
								foreach( $user_query->get_results() as $user ) :
									$user_id = $user->ID;
									?>
										<div class="item">
											<input type="checkbox" name="user-<?php echo esc_attr( $user_id ); ?>" id="user-<?php echo esc_attr( $user_id ); ?>" value="<?php echo esc_attr( $user_id ); ?>">
											<label for="user-<?php echo esc_attr( $user_id ); ?>"><?php echo esc_html( $user->display_name ); ?></label>
										</div>
									<?php
								endforeach;
								echo '</div>';
							endif;
						?>
						<button class="clear"><?php esc_html_e( 'Clear', 'one-newspaper' ); ?></button>
					</div>
				</div>
				<button class="action-btn filter-button disabled"><?php esc_html_e( 'Filter', 'one-newspaper' ); ?></button>
				<button class="action-btn clear-button disabled"><?php esc_html_e( 'Clear', 'one-newspaper' ); ?></button>
			</div>
		<?php
	}
endif;

if( ! function_exists( 'one_newspaper_search_page_ajax_call' ) ) :
	/**
	 * Search page ajax call
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_search_page_ajax_call() {
		check_ajax_referer( 'one-newspaper-nonce', '_wpnonce' );
		$query_args = ( isset( $_POST[ 'query' ] ) ) ? $_POST[ 'query' ] : [];
		$clicked_button = ( isset( $_POST[ 'clickedButton' ] ) ) ? $_POST[ 'clickedButton' ] : 'load-more';
		$search_page_content = esc_html__( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'one-newspaper' );
		if( isset( $query_args[ 'before' ] ) ) $query_args[ 'date_query' ] = [ ...$query_args[ 'date_query' ], $query_args[ 'before' ] ];
		if( isset( $query_args[ 'after' ] ) ) $query_args[ 'date_query' ] = [ ...$query_args[ 'date_query' ], $query_args[ 'after' ] ];
		unset( $query_args[ 'before' ] );
		unset( $query_args[ 'after' ] );
		$query_args[ 'posts_per_page' ] =  get_option( 'posts_per_page' );
		$instance = new WP_Query( $query_args );
		$success_flag = false;
		if( $instance->have_posts() ) :
			$success_flag = true;
			ob_start();
			if( $instance->max_num_pages === ( $query_args[ 'paged' ] )  ) $res[ 'completed' ] = true;
			while( $instance->have_posts() ) : $instance->the_post();

				get_template_part( 'template-parts/content', 'search' );
				
			endwhile;
			wp_reset_postdata();
			$res = ob_get_clean();
		endif;
		if( ! $success_flag ) $res[ 'message' ] = '<p class="failure-message">'. esc_html( ( $clicked_button === 'load-more' ) ? esc_html__( 'No more results', 'one-newspaper' ) : $search_page_content ) . '</p>';
		$success_flag ? wp_send_json_success( $res ) : wp_send_json_error( $res );
		wp_die();
	}
	add_action( 'wp_ajax_one_newspaper_search_page_ajax_call', 'one_newspaper_search_page_ajax_call' );
	add_action( 'wp_ajax_nopriv_one_newspaper_search_page_ajax_call', 'one_newspaper_search_page_ajax_call' );
endif;

if( ! function_exists( 'one_newspaper_random_post_archive_advertisement_number' ) ) :
    /**
     * One Newspaper archive ads number
     * 
     * @since 1.0.0
     */
    function one_newspaper_random_post_archive_advertisement_number() {
        $advertisement_repeater = ONP\one_newspaper_get_customizer_option( 'advertisement_repeater' );
        $advertisement_repeater_decoded = json_decode( $advertisement_repeater );
        $random_post_archive_advertisement = array_filter( $advertisement_repeater_decoded, function( $element ) {
            if( property_exists( $element, 'item_checkbox_random_post_archives' ) ) return ( $element->item_checkbox_random_post_archives == true && $element->item_option == 'show' ) ? $element : ''; 
        });
        return sizeof( $random_post_archive_advertisement );
    }
 endif;

if( ! function_exists( 'one_newspaper_algorithm_to_push_ads_in_archive' ) ) :
	/**
	 * Algorithm to push ads into archive
	 * 
	 * @since 1.0.0
	 */
	function one_newspaper_algorithm_to_push_ads_in_archive( $args = [] ) {
		global $wp_query;
		$archive_ads_number = one_newspaper_random_post_archive_advertisement_number();
		if( $archive_ads_number <= 0 ) return;
		if( empty( $args ) ) :
			$max_number_of_pages = absint( $wp_query->max_num_pages );
			$paged = absint( ( get_query_var( 'paged' ) == 0 ) ? 0 : ( get_query_var( 'paged' ) - 1 ) );
		else:
			if( ( $args['paged'] - 1 ) == $archive_ads_number ) return;
			$max_number_of_pages = absint( $args['max_number_of_pages'] );
			$paged = absint( $args['paged'] - 1 );
		endif;
		$count = 1;
		$ads_id = 0;
		$loop_var = 0;
		for( $i = $archive_ads_number ; $i > 0; $i-- ) :
			if( $count <= $max_number_of_pages ):
				$ads_to_render_in_a_single_page = ceil( $i / $max_number_of_pages );
				$ads_to_render = [];
				if( $ads_to_render_in_a_single_page > 1 ) :
					$to_loop = $ads_id + $ads_to_render_in_a_single_page;
					for( $j = $ads_id; $j < $to_loop; $j++ ) :
						if( ! in_array( $ads_id, $ads_to_render ) ) $ads_to_render[] = $ads_id;
						$ads_id++;
					endfor;
					$ads_to_render_in_current_page[$loop_var] = $ads_to_render;
				else:
					$ads_to_render_in_current_page[$loop_var] = $ads_id;
					$ads_id++;
				endif;
				$count++;
				$loop_var++;
			endif;
		endfor;
		$current_page_count = empty( $args ) ? absint( $wp_query->post_count ) : absint( $args['post_count'] );
		$ads_of_current_page = array_key_exists( $paged, $ads_to_render_in_current_page ) ? $ads_to_render_in_current_page[$paged] : null;
		$ads_count = is_array( $ads_of_current_page ) ? sizeof( $ads_of_current_page ) : 1;
		$random_numbers = [];
		for( $i = 0; $i < $ads_count; $i++ ) :
			if( ! in_array( $i, $random_numbers ) ) :
				$random_numbers[] = rand( 0, ( $current_page_count - 1 ) );
			else:
				$random_numbers[] = rand( 0, ( $current_page_count - 1 ) );
			endif;
		endfor;
		return [
			'random_numbers'	=>	$random_numbers,
			'ads_to_render'	=>	$ads_of_current_page
		];
	}
 endif;

if( ! function_exists( 'one_newspaper_random_post_archive_advertisement_part' ) ) :
    /**
     * One Newspaper random advertisement in archive part
     * 
     * @since 1.0.0
     */
    function one_newspaper_random_post_archive_advertisement_part( $ads_rendered ) {
		if( is_null( $ads_rendered ) ) return;
        $advertisement_repeater = ONP\one_newspaper_get_customizer_option( 'advertisement_repeater' );
        $advertisement_repeater_decoded = json_decode( $advertisement_repeater );
        $random_post_archive_advertisement = array_values(array_filter( $advertisement_repeater_decoded, function( $element ) {
            if( property_exists( $element, 'item_checkbox_random_post_archives' ) ) return ( $element->item_checkbox_random_post_archives == true && $element->item_option == 'show' ) ? $element : ''; 
        }));
        if( empty( $random_post_archive_advertisement ) ) return;
        $image_option = array_column( $random_post_archive_advertisement, 'item_image_option' );
        $alignment = array_column( $random_post_archive_advertisement, 'item_alignment' );
        $elementClass = 'alignment--' . $alignment[0];
        $elementClass .= ' image-option--' . ( ( $image_option[0] == 'full_width' ) ? 'full-width' : 'original' );
        ?>
            <div class="one-newspaper-advertisement-block post <?php echo esc_html( $elementClass ); ?>">
                <a href="<?php echo esc_url( $random_post_archive_advertisement[$ads_rendered]->item_url ); ?>" target="<?php echo esc_attr( $random_post_archive_advertisement[$ads_rendered]->item_target ); ?>" rel="<?php echo esc_attr( $random_post_archive_advertisement[$ads_rendered]->item_rel_attribute ); ?>">
                    <img src="<?php echo esc_url( wp_get_attachment_image_url( $random_post_archive_advertisement[$ads_rendered]->item_image, 'full' ) ); ?>" loading="lazy">
                </a>
            </div>
        <?php
    }
 endif;

if( ! function_exists( 'one_newspaper_check_youtube_api_key' ) ) :
	/**
	 * function to check whether the api key is valid or not
	 * 
	 * @since 1.0.0
	 * @package One Newspaper
	 */
	function one_newspaper_check_youtube_api_key( $api_key ) {
		$api_url = "https://www.googleapis.com/youtube/v3/videos?key=" . $api_key . "&part=snippet,contentDetails";
        $remote_get_video_info = wp_remote_get( $api_url );
		return $remote_get_video_info;
	}
endif;

 if( ! function_exists( 'one_newspaper_get_current_page_sidebar' ) ) :
	/**
	 * Get archive meta
	 * 
	 * @since 1.0.0
	 */
 	function one_newspaper_get_current_page_sidebar() {
		$current_id = get_queried_object_id();
		$sidebar_meta_key = '';
		if( is_category() ) :
			$sidebar_meta_key = '_one_newspaper_category_sidebar_custom_meta_field';
		elseif( is_tag() ) :
			$sidebar_meta_key = '_one_newspaper_post_tag_sidebar_custom_meta_field';
		elseif( is_single() ) :
			$sidebar_meta_key = 'post_sidebar_layout';
		elseif( is_page() ) :
			$sidebar_meta_key = 'post_sidebar_layout';
		else:
			return 'customizer-setting';
		endif;

		if( is_category() || is_tag() ) $sidebar_layout_meta = metadata_exists( 'term', $current_id, $sidebar_meta_key ) ? get_term_meta( $current_id, $sidebar_meta_key, true ) : 'customizer-setting';
		if( is_single() || is_page() ) $sidebar_layout_meta = metadata_exists( 'post', $current_id, $sidebar_meta_key ) ? get_post_meta( $current_id, $sidebar_meta_key, true ) : 'customizer-setting';
		return $sidebar_layout_meta;
	}
 endif;