<?php
/**
 * Custom Functions.
 *
 * @package NewsNation
 */
if (!function_exists('newsnation_fonts_url')) :
    //Google Fonts URL
    function newsnation_fonts_url()
    {
        $font_families = array(
            'PT+Serif:ital,wght@0,400;0,700;1,400;1,700',
            'Oswald:wght@200..700',
            'Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900',
        );
        $font_families = array(
            'PT+Serif:ital,wght@0,400;0,700;1,400;1,700',
            'Oswald:wght@200..700',
            'Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900',
        );
        $fonts_url = 'https://fonts.googleapis.com/css2?family=' . implode('&family=', $font_families) . '&display=swap';
        return esc_url_raw($fonts_url);
    }
endif;
if (!function_exists('newsnation_sanitize_sidebar_option_meta')) :
    // Sidebar Option Sanitize.
    function newsnation_sanitize_sidebar_option_meta($input)
    {
        $metabox_options = array('global-sidebar', 'left-sidebar', 'right-sidebar', 'no-sidebar');
        if (in_array($input, $metabox_options)) {
            return $input;
        } else {
            return '';
        }
    }
endif;
if (!function_exists('newsnation_page_lists')) :
    // Page List.
    function newsnation_page_lists()
    {
        $page_lists = array();
        $page_lists[''] = esc_html__('-- Select Page --', 'newsnation');
        $pages = get_pages(
            array(
                'parent' => 0, // replaces 'depth' => 1,
            )
        );
        foreach ($pages as $page) {
            $page_lists[$page->ID] = $page->post_title;
        }
        return $page_lists;
    }
endif;
if (!function_exists('newsnation_sanitize_post_layout_option_meta')) :
    // Sidebar Option Sanitize.
    function newsnation_sanitize_post_layout_option_meta($input)
    {
        $metabox_options = array('global-layout', 'layout-1', 'layout-2');
        if (in_array($input, $metabox_options)) {
            return $input;
        } else {
            return '';
        }
    }
endif;
if (!function_exists('newsnation_sanitize_header_overlay_option_meta')) :
    // Sidebar Option Sanitize.
    function newsnation_sanitize_header_overlay_option_meta($input)
    {
        $metabox_options = array('global-layout', 'enable-overlay');
        if (in_array($input, $metabox_options)) {
            return $input;
        } else {
            return '';
        }
    }
endif;
/**
 * NewsNation SVG Icon helper functions
 *
 * @package NewsNation
 * @since 1.0.0
 */
if (!function_exists('newsnation_theme_svg')) :
    /**
     * Output and Get Theme SVG.
     * Output and get the SVG markup for an icon in the NewsNation_SVG_Icons class.
     *
     * @param string $svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function newsnation_theme_svg($svg_name, $return = false)
    {
        if ($return) {
            return newsnation_get_theme_svg($svg_name); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in newsnation_get_theme_svg();.
        } else {
            echo newsnation_get_theme_svg($svg_name); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in newsnation_get_theme_svg();.
        }
    }
endif;
if (!function_exists('newsnation_get_theme_svg')) :
    /**
     * Get information about the SVG icon.
     *
     * @param string $svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function newsnation_get_theme_svg($svg_name)
    {
        // Make sure that only our allowed tags and attributes are included.
        $svg = wp_kses(
            NewsNation_SVG_Icons::get_svg($svg_name),
            array(
                'svg' => array(
                    'class' => true,
                    'xmlns' => true,
                    'width' => true,
                    'height' => true,
                    'viewbox' => true,
                    'aria-hidden' => true,
                    'role' => true,
                    'focusable' => true,
                ),
                'path' => array(
                    'fill' => true,
                    'fill-rule' => true,
                    'd' => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill' => true,
                    'fill-rule' => true,
                    'points' => true,
                    'transform' => true,
                    'focusable' => true,
                ),
                'line' => array(
                    'stroke' => true,
                    'x1' => true,
                    'x2' => true,
                    'y1' => true,
                    'y2' => true,
                ),
            )
        );
        if (!$svg) {
            return false;
        }
        return $svg;
    }
endif;
if (!function_exists('newsnation_svg_escape')) :
    /**
     * Get information about the SVG icon.
     *
     * @param string $svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function newsnation_svg_escape($input)
    {
        // Make sure that only our allowed tags and attributes are included.
        $svg = wp_kses(
            $input,
            array(
                'svg' => array(
                    'class' => true,
                    'xmlns' => true,
                    'width' => true,
                    'height' => true,
                    'viewbox' => true,
                    'aria-hidden' => true,
                    'role' => true,
                    'focusable' => true,
                ),
                'path' => array(
                    'fill' => true,
                    'fill-rule' => true,
                    'd' => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill' => true,
                    'fill-rule' => true,
                    'points' => true,
                    'transform' => true,
                    'focusable' => true,
                ),
            )
        );
        if (!$svg) {
            return false;
        }
        return $svg;
    }
endif;
if (!function_exists('newsnation_social_menu_icon')) :
    function newsnation_social_menu_icon($item_output, $item, $depth, $args)
    {
        // Add Icon
        if (isset($args->theme_location) && 'newsnation-social-menu' === $args->theme_location) {
            $svg = NewsNation_SVG_Icons::get_theme_svg_name($item->url);
            if (empty($svg)) {
                $svg = newsnation_theme_svg('link', $return = true);
            }
            $item_output = str_replace($args->link_after, '</span>' . $svg, $item_output);
        }
        return $item_output;
    }
endif;
add_filter('walker_nav_menu_start_el', 'newsnation_social_menu_icon', 10, 4);
if (!function_exists('newsnation_sub_menu_toggle_button')) :
    function newsnation_sub_menu_toggle_button($args, $item, $depth)
    {
        // Add sub menu toggles to the main menu with toggles
        if ($args->theme_location == 'newsnation-primary-menu' && isset($args->show_toggles)) {
            // Wrap the menu item link contents in a div, used for positioning
            $args->before = '<div class="submenu-wrapper">';
            $args->after = '';
            // Add a toggle to items with children
            if (in_array('menu-item-has-children', $item->classes)) {
                $toggle_target_string = '.menu-item.menu-item-' . $item->ID . ' > .sub-menu';
                // Add the sub menu toggle
                $args->after .= '<button type="button" class="theme-aria-button submenu-toggle" data-toggle-target="' . $toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="250" aria-expanded="false"><span class="screen-reader-text">' . __('Show sub menu', 'newsnation') . '</span>' . newsnation_get_theme_svg('chevron-down') . '</button>';
            }
            // Close the wrapper
            $args->after .= '</div><!-- .submenu-wrapper -->';
            // Add sub menu icons to the main menu without toggles (the fallback menu)
        } elseif ($args->theme_location == 'newsnation-primary-menu') {
            if (in_array('menu-item-has-children', $item->classes)) {
                $args->before = '<div class="link-icon-wrapper">';
                $args->after = newsnation_get_theme_svg('chevron-down') . '</div>';
            } else {
                $args->before = '';
                $args->after = '';
            }
        }
        return $args;
    }
    add_filter('nav_menu_item_args', 'newsnation_sub_menu_toggle_button', 10, 3);
endif;
if (!function_exists('newsnation_post_category_list')) :
    // Post Category List.
    function newsnation_post_category_list($select_cat = true)
    {
        $post_cat_lists = get_categories(
            array(
                'hide_empty' => '0',
                'exclude' => '1',
            )
        );
        $post_cat_cat_array = array();
        if ($select_cat) {
            $post_cat_cat_array[''] = esc_html__('Select Category', 'newsnation');
        }
        foreach ($post_cat_lists as $post_cat_list) {
            $post_cat_cat_array[$post_cat_list->slug] = $post_cat_list->name;
        }
        return $post_cat_cat_array;
    }
endif;
if (!function_exists('newsnation_sanitize_meta_pagination')) :
    /** Sanitize Enable Disable Checkbox **/
    function newsnation_sanitize_meta_pagination($input)
    {
        $valid_keys = array('global-layout', 'no-navigation', 'norma-navigation', 'ajax-next-post-load');
        if (in_array($input, $valid_keys)) {
            return $input;
        }
        return '';
    }
endif;
if (!function_exists('newsnation_header_ad')) :
    function newsnation_header_ad()
    {
        $newsnation_default = newsnation_get_default_theme_options();
        $ed_header_ad = get_theme_mod('ed_header_ad', $newsnation_default['ed_header_ad']);
        $ed_header_type = get_theme_mod('ed_header_type', $newsnation_default['ed_header_type']);
        $addvertisement_section_title = get_theme_mod('addvertisement_section_title', $newsnation_default['addvertisement_section_title']);
        $header_ad_image = get_theme_mod('header_ad_image');
        $ed_header_link = get_theme_mod('ed_header_link');
        if ($ed_header_ad) {
            ?>
            <div class="theme-header-ads">
                <div class="<?php echo esc_attr($ed_header_type); ?>">
                    <div class="header-ads-cta">
                        <span class="header-ads-title">
                            <?php echo esc_html($addvertisement_section_title); ?>
                        </span>
                        <div class="cta-btn-container">
                            <span class="ad-countdown-timer"> </span>
                            <button class="cta-btn top-header-add"> <?php echo esc_html__('Skip This', 'newsnation') ?></button>
                        </div>
                    </div>
                    <?php if ($header_ad_image) { ?>
                        <a target="_blank" href="<?php echo esc_url($ed_header_link); ?>">
                            <img src="<?php echo esc_url($header_ad_image); ?>"
                                 title="<?php esc_attr_e('Header AD Image', 'newsnation'); ?>"
                                 alt="<?php esc_attr_e('Header AD Image', 'newsnation'); ?>"/>
                        </a>
                    <?php } ?>
                    <?php if ($ed_header_type == 'wpi-img-full-width-header') { ?>
                        <button type="button" class="top-header-add">
                            <span></span>
                            <span></span>
                            <span></span>
                        </button>
                    <?php } ?>
                </div>
            </div>
            <?php
        }
    }
endif;
if (!function_exists('newsnation_post_floating_nav')) :
    function newsnation_post_floating_nav()
    {
        $newsnation_default = newsnation_get_default_theme_options();
        $ed_floating_next_previous_nav = get_theme_mod('ed_floating_next_previous_nav', $newsnation_default['ed_floating_next_previous_nav']);
        if ('post' === get_post_type() && $ed_floating_next_previous_nav) {
            $next_post = get_next_post();
            $prev_post = get_previous_post();
            if (isset($prev_post->ID)) {
                $prev_link = get_permalink($prev_post->ID); ?>
                <div class="floating-post-navigation floating-navigation-prev">
                    <?php if (get_the_post_thumbnail($prev_post->ID, 'medium')) { ?>
                        <?php echo wp_kses_post(get_the_post_thumbnail($prev_post->ID, 'medium')); ?>
                    <?php } ?>
                    <a href="<?php echo esc_url($prev_link); ?>">
                        <span class="floating-navigation-label"><?php echo esc_html__('Previous post', 'newsnation'); ?></span>
                        <span class="floating-navigation-title"><?php echo esc_html(get_the_title($prev_post->ID)); ?></span>
                    </a>
                </div>
            <?php }
            if (isset($next_post->ID)) {
                $next_link = get_permalink($next_post->ID); ?>
                <div class="floating-post-navigation floating-navigation-next">
                    <?php if (get_the_post_thumbnail($next_post->ID, 'medium')) { ?>
                        <?php echo wp_kses_post(get_the_post_thumbnail($next_post->ID, 'medium')); ?>
                    <?php } ?>
                    <a href="<?php echo esc_url($next_link); ?>">
                        <span class="floating-navigation-label"><?php echo esc_html__('Next post', 'newsnation'); ?></span>
                        <span class="floating-navigation-title"><?php echo esc_html(get_the_title($next_post->ID)); ?></span>
                    </a>
                </div>
                <?php
            }
        }
    }
endif;
add_action('newsnation_navigation_action', 'newsnation_post_floating_nav', 10);
if (!function_exists('newsnation_single_post_navigation')) :
    function newsnation_single_post_navigation()
    {
        $newsnation_default = newsnation_get_default_theme_options();
        $wpi_navigation_type = esc_attr(get_post_meta(get_the_ID(), 'wpi_disable_ajax_load_next_post', true));
        $newsnation_header_trending_page = get_theme_mod('newsnation_header_trending_page');
        $newsnation_header_popular_page = get_theme_mod('newsnation_header_popular_page');
        $newsnation_archive_layout = esc_attr(get_theme_mod('newsnation_archive_layout', $newsnation_default['newsnation_archive_layout']));
        $current_id = '';
        $article_wrap_class = '';
        global $post;
        $current_id = $post->ID;
        if ($wpi_navigation_type == '' || $wpi_navigation_type == 'global-layout') {
            $wpi_navigation_type = get_theme_mod('wpi_navigation_type', $newsnation_default['wpi_navigation_type']);
        }
        if ($newsnation_header_trending_page != $current_id && $newsnation_header_popular_page != $current_id) {
            if ($wpi_navigation_type != 'no-navigation' && 'post' === get_post_type()) {
                if ($wpi_navigation_type == 'norma-navigation') { ?>
                    <div class="navigation-wrapper">
                        <?php
                        // Previous/next post navigation.
                        the_post_navigation(array(
                            'prev_text' => '<span class="arrow" aria-hidden="true">' . newsnation_theme_svg('arrow-left', $return = true) . '</span><span class="screen-reader-text">' . __('Previous post:', 'newsnation') . '</span><span class="post-title">%title</span>',
                            'next_text' => '<span class="arrow" aria-hidden="true">' . newsnation_theme_svg('arrow-right', $return = true) . '</span><span class="screen-reader-text">' . __('Next post:', 'newsnation') . '</span><span class="post-title">%title</span>',
                        )); ?>
                    </div>
                    <?php
                } else {
                    $next_post = get_next_post();
                    if (isset($next_post->ID)) {
                        $next_post_id = $next_post->ID;
                        echo '<div loop-count="1" next-post="' . absint($next_post_id) . '" class="wpi-single-infinity"></div>';
                    }
                }
            }
        }
    }
endif;
add_action('newsnation_navigation_action', 'newsnation_single_post_navigation', 30);
if (!function_exists('newsnation_header_banner')) :
    function newsnation_header_banner()
    {
        global $post;
        if (have_posts()) :
            while (have_posts()) :
                the_post();
                global $post;
            endwhile;
        endif;
        $newsnation_post_layout = '';
        $newsnation_default = newsnation_get_default_theme_options();
        if (is_singular()) {
            $newsnation_post_layout = esc_html(get_post_meta($post->ID, 'newsnation_post_layout', true));
            if ($newsnation_post_layout == '' || $newsnation_post_layout == 'global-layout') {
                $newsnation_post_layout = get_theme_mod('newsnation_single_post_layout', $newsnation_default['newsnation_archive_layout']);
            }
        }
        if (isset($post->ID)) {
            $newsnation_page_layout = esc_html(get_post_meta($post->ID, 'newsnation_page_layout', true));
        }
        if ($newsnation_post_layout == 'layout-2' && is_singular('post')) {
            if (have_posts()) :
                while (have_posts()) :
                    the_post();
                    $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                    $newsnation_ed_feature_image = esc_html(get_post_meta(get_the_ID(), 'newsnation_ed_feature_image', true));
                    ?>
                    <div class="single-featured-banner  <?php if (empty($newsnation_ed_feature_image) && isset($featured_image[0]) && $featured_image[0]) {
                        echo 'banner-has-image';
                    } ?>">
                        <div class="featured-banner-content">
                            <div class="wrapper">
                                <?php
                                if (!is_404() && !is_home() && !is_front_page()) {
                                    newsnation_breadcrumb_with_title_block();
                                } ?>
                                <header class="entry-header">
                                    <div class="entry-meta">
                                        <?php
                                        newsnation_entry_footer($cats = true, $tags = false, $edits = false, $text = false, $icon = false);
                                        ?>
                                    </div>
                                    <h1 class="entry-title entry-title-large">
                                        <?php the_title(); ?>
                                    </h1>
                                </header>
                                <div class="entry-meta">
                                    <?php
                                    newsnation_posted_by();
                                    ?>
                                </div>
                            </div>
                        </div>
                        <?php if (empty($newsnation_ed_feature_image) && isset($featured_image[0]) && $featured_image[0]) { ?>
                            <div class="featured-banner-media">
                                <div class="data-bg data-bg-fixed data-bg-banner"
                                     data-background="<?php echo esc_url($featured_image[0]); ?>"></div>
                            </div>
                        <?php } ?>
                    </div>
                <?php
                endwhile;
                wp_reset_postdata();
            endif;
        }
        if (is_singular('page') && $newsnation_page_layout == 'layout-2') {
            if (have_posts()) :
                while (have_posts()) :
                    the_post();
                    $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                    $newsnation_ed_feature_image = esc_html(get_post_meta(get_the_ID(), 'newsnation_ed_feature_image', true));
                    ?>
                    <div class="single-featured-banner  <?php if (empty($newsnation_ed_feature_image) && isset($featured_image[0]) && $featured_image[0]) {
                        echo 'banner-has-image';
                    } ?>">
                        <div class="featured-banner-content">
                            <div class="wrapper">
                                <?php
                                if (!is_404() && !is_home() && !is_front_page()) {
                                    newsnation_breadcrumb_with_title_block();
                                } ?>
                                <header class="entry-header">
                                    <h1 class="entry-title entry-title-large">
                                        <?php the_title(); ?>
                                    </h1>
                                </header>
                            </div>
                        </div>
                        <?php if (empty($newsnation_ed_feature_image) && isset($featured_image[0]) && $featured_image[0]) { ?>
                            <div class="featured-banner-media">
                                <div class="data-bg data-bg-fixed data-bg-banner"
                                     data-background="<?php echo esc_url($featured_image[0]); ?>"></div>
                            </div>
                        <?php } ?>
                    </div>
                <?php
                endwhile;
                wp_reset_postdata();
            endif;
        }
    }
endif;
if (!function_exists('newsnation_header_toggle_search')) :
    /**
     * Header Search
     **/
    function newsnation_header_toggle_search()
    { ?>
        <div class="header-searchbar">
            <div class="header-searchbar-inner">
                <div class="wrapper">
                    <div class="header-searchbar-panel">
                        <div class="header-searchbar-area">
                            <a class="skip-link-search-top" href="javascript:void(0)"></a>
                            <?php get_search_form(); ?>
                        </div>
                        <button type="button" id="search-closer" class="navbar-control button-close-popup">
                            <?php newsnation_theme_svg('cross'); ?>
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <?php
    }
endif;
add_action('newsnation_before_footer_content_action', 'newsnation_header_toggle_search', 10);
if (!function_exists('newsnation_content_offcanvas')) :
    // Offcanvas Contents
    function newsnation_content_offcanvas()
    {
        ?>
        <div id="offcanvas-menu">
            <div class="offcanvas-wraper">
                <a class="skip-link-off-canvas" href="javascript:void(0)"></a>
                <button type="button" class="navbar-control button-offcanvas-close">
                    <span class="screen-reader-text">
                        <?php echo esc_html__('Close', 'newsnation'); ?>
                    </span>
                    <?php newsnation_theme_svg('cross'); ?>
                </button>
                <div id="primary-nav-offcanvas" class="offcanvas-item offcanvas-main-navigation">
                    <nav class="primary-menu-wrapper">
                        <ul class="primary-menu theme-menu">
                            <?php
                            if (has_nav_menu('newsnation-primary-menu')) {
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'newsnation-primary-menu',
                                        'show_toggles' => true,
                                    )
                                );
                            } else {
                                wp_list_pages(
                                    array(
                                        'match_menu_classes' => true,
                                        'title_li' => false,
                                        'show_toggles' => true,
                                        'walker' => new NewsNation_Walker_Page(),
                                    )
                                );
                            } ?>
                        </ul>
                    </nav>
                </div>
                <?php if (has_nav_menu('newsnation-social-menu')) { ?>
                    <div id="social-nav-offcanvas" class="offcanvas-item offcanvas-social-navigation">
                        <?php
                        wp_nav_menu(
                            array(
                                'theme_location' => 'newsnation-social-menu',
                                'link_before' => '<span class="screen-reader-text">',
                                'link_after' => '</span>',
                                'container' => 'div',
                                'container_class' => 'newsnation-social-menu',
                                'depth' => 1,
                            )
                        ); ?>
                    </div>
                <?php } ?>
                <a class="skip-link-offcanvas screen-reader-text" href="javascript:void(0)"></a>
            </div>
        </div>
        <?php
    }
endif;
add_action('newsnation_before_footer_content_action', 'newsnation_content_offcanvas', 30);
if (!function_exists('newsnation_footer_content_widget')) :
    function newsnation_footer_content_widget()
    {
        $newsnation_default = newsnation_get_default_theme_options();
        if (
            is_active_sidebar('newsnation-footer-widget-0') ||
            is_active_sidebar('newsnation-footer-widget-1') ||
            is_active_sidebar('newsnation-footer-widget-2')
        ) :
            $x = 1;
            $footer_sidebar = 0;
            do {
                if ($x == 4 && is_active_sidebar('newsnation-footer-widget-3')) {
                    $footer_sidebar++;
                }
                if ($x == 3 && is_active_sidebar('newsnation-footer-widget-2')) {
                    $footer_sidebar++;
                }
                if ($x == 2 && is_active_sidebar('newsnation-footer-widget-1')) {
                    $footer_sidebar++;
                }
                if ($x == 1 && is_active_sidebar('newsnation-footer-widget-0')) {
                    $footer_sidebar++;
                }
                $x++;
            } while ($x <= 4);
            if ($footer_sidebar == 1) {
                $footer_sidebar_class = 12;
            } elseif ($footer_sidebar == 2) {
                $footer_sidebar_class = 6;
            } elseif ($footer_sidebar == 3) {
                $footer_sidebar_class = 4;
            } else {
                $footer_sidebar_class = 3;
            }
            $footer_column_layout = absint(get_theme_mod('footer_column_layout', $newsnation_default['footer_column_layout'])); ?>
            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                        <?php if (is_active_sidebar('newsnation-footer-widget-0')) : ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-6 column-xs-12">
                                <?php dynamic_sidebar('newsnation-footer-widget-0'); ?>
                            </div>
                        <?php endif; ?>
                        <?php if (is_active_sidebar('newsnation-footer-widget-1')) : ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-6 column-xs-12">
                                <?php dynamic_sidebar('newsnation-footer-widget-1'); ?>
                            </div>
                        <?php endif; ?>
                        <?php if (is_active_sidebar('newsnation-footer-widget-2')) : ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-6 column-xs-12">
                                <?php dynamic_sidebar('newsnation-footer-widget-2'); ?>
                            </div>
                        <?php endif; ?>
                        <?php if (is_active_sidebar('newsnation-footer-widget-3')) : ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-6 column-xs-12">
                                <?php dynamic_sidebar('newsnation-footer-widget-3'); ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        <?php
        endif;
    }
endif;
add_action('newsnation_footer_content_action', 'newsnation_footer_content_widget', 10);
if (!function_exists('newsnation_footer_content_info')) :
    /**
     * Footer Copyright Area
     **/
    function newsnation_footer_content_info()
    {
        $newsnation_default = newsnation_get_default_theme_options(); ?>
        <div class="site-info">
            <div class="wrapper">
                <div class="column-row">
                    <div class="column column-8 column-sm-12">
                        <div class="footer-copyright">
                            <?php
                            $footer_copyright_text = wp_kses_post(get_theme_mod('footer_copyright_text', $newsnation_default['footer_copyright_text']));
                            echo esc_html__('Copyright ', 'newsnation') . '&copy ' . absint(date('Y')) . ' <a href="' . esc_url(home_url('/')) . '" title="' . esc_attr(get_bloginfo('name', 'display')) . '" ><span>' . esc_html(get_bloginfo('name', 'display')) . '. </span></a> ' . esc_html($footer_copyright_text);
                            echo esc_html__('Theme: ', 'newsnation') . 'NewsNation ' . esc_html__('By ', 'newsnation') . '<a href="' . esc_url('https://www.wpinterface.com/themes/newsnation') . '"  title="' . esc_attr__('WPInterface', 'newsnation') . '" target="_blank" rel="author"><span>' . esc_html__('WPInterface. ', 'newsnation') . '</span></a>';
                            echo esc_html__('Powered by ', 'newsnation') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'newsnation') . '" target="_blank"><span>' . esc_html__('WordPress.', 'newsnation') . '</span></a>';
                            ?>
                        </div>
                    </div>
                    <div class="column column-4 column-sm-12">
                        <?php
                        if (has_nav_menu('newsnation-social-menu')) { ?>
                            <div class="footer-social-navigation">
                                <?php
                                wp_nav_menu(
                                    array(
                                        'theme_location' => 'newsnation-social-menu',
                                        'link_before' => '<span class="screen-reader-text">',
                                        'link_after' => '</span>',
                                        'container' => 'div',
                                        'container_class' => 'newsnation-social-menu',
                                        'depth' => 1,
                                    )
                                ); ?>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>
            <?php newsnation_footer_go_to_top(); ?>
        </div>
        <?php
    }
endif;
add_action('newsnation_footer_content_action', 'newsnation_footer_content_info', 20);
if (!function_exists('newsnation_footer_go_to_top')) :
    // Scroll to Top render content
    function newsnation_footer_go_to_top()
    {
        $newsnation_default = newsnation_get_default_theme_options();
        $ed_scroll_top_button = get_theme_mod('ed_scroll_top_button', $newsnation_default['ed_scroll_top_button']);
        if ($ed_scroll_top_button) {
            ?>
            <div class="hide-no-js">
                <button type="button" class="scroll-up">
                    <?php newsnation_theme_svg('chevron-up'); ?>
                </button>
            </div>
            <?php
        }
    }
endif;
add_action('wp_ajax_newsnation_tab_posts_callback', 'newsnation_tab_posts_callback');
add_action('wp_ajax_nopriv_newsnation_tab_posts_callback', 'newsnation_tab_posts_callback');
if (!function_exists('newsnation_tab_posts_callback')) :
    // Masonry Post Ajax Call Function.
    function newsnation_tab_posts_callback()
    {
        if (isset($_POST['_wpnonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'])), 'newsnation_ajax_nonce') && isset($_POST['category'])) {
            $category = sanitize_text_field(wp_unslash($_POST['category']));
            $tab_post_query = new WP_Query(
                array(
                    'post_type' => 'post',
                    'posts_per_page' => 5,
                    'post__not_in' => get_option("sticky_posts"),
                    'category_name' => esc_html($category),
                    'post_status' => 'publish'
                )
            );
            if ($tab_post_query->have_posts()) : ?>
                <div class="tab-content-container">
                    <?php
                    $post_count = 1;
                    while ($tab_post_query->have_posts()) {
                        $tab_post_query->the_post();
                        ?>
                        <article
                                id="theme-post-<?php the_ID(); ?>" <?php post_class('news-article news-article-list article-has-border'); ?>>
                            <?php
                            $fallback_image_url = newsnation_get_fallback_image_url();
                            if (has_post_thumbnail() || $fallback_image_url) : ?>
                                <div class="entry-image entry-image-thumbnail image-hover-effect hover-effect-shine">
                                    <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"
                                       tabindex="-1">
                                        <?php
                                        if (has_post_thumbnail()) {
                                            the_post_thumbnail('medium', [
                                                'alt' => the_title_attribute(['echo' => false]),
                                            ]);
                                        } else {
                                            echo '<img src="' . esc_url($fallback_image_url) . '" alt="' . esc_attr(get_the_title()) . '" />';
                                        }
                                        ?>
                                    </a>
                                </div>
                            <?php endif; ?>
                            <div class="article-content">
                                <h3 class="entry-title entry-title-xsmall line-clamp-2">
                                    <a href="<?php the_permalink(); ?>" tabindex="0" rel="bookmark"
                                       title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                                </h3>
                                <div class="entry-meta">
                                    <?php newsnation_posted_by(); ?>
                                </div>
                            </div>
                        </article>
                        <?php
                        if ($post_count == 5) {
                            break;
                        }
                        $post_count++;
                    }
                    wp_reset_postdata(); ?>
                </div>
                <?php
                wp_reset_postdata();
            endif;
        }
        wp_die();
    }
endif;
if (!function_exists('newsnation_header_ticker_posts')) :
    function newsnation_header_ticker_posts()
    {
        $newsnation_default = newsnation_get_default_theme_options();
        $ed_header_ticker_posts = get_theme_mod('ed_header_ticker_posts', $newsnation_default['ed_header_ticker_posts']);
        $ed_header_ticker_posts_title = get_theme_mod('ed_header_ticker_posts_title', $newsnation_default['ed_header_ticker_posts_title']);
        $newsnation_header_ticker_cat = get_theme_mod('newsnation_header_ticker_cat');
        if (is_rtl()) {
            $rtl = 'true';
        } else {
            $rtl = 'false';
        }
        if ($ed_header_ticker_posts) { ?>
            <div class="theme-ticker theme-block">
                <div class="wrapper">
                    <div class="header-news-ticker hide-no-js">
                        <?php if ($ed_header_ticker_posts_title) { ?>
                            <div class="theme-ticker-title">
                                <?php echo esc_html($ed_header_ticker_posts_title); ?><?php newsnation_theme_svg('bolt'); ?>
                            </div>
                        <?php } ?>
                        <div class="theme-ticker-area">
                            <?php
                            $ticker_posts_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 10, 'post__not_in' => get_option("sticky_posts"), 'category_name' => esc_html($newsnation_header_ticker_cat)));
                            if ($ticker_posts_query->have_posts()) : ?>
                                <div class="ticker-slides">
                                    <?php
                                    while ($ticker_posts_query->have_posts()) :
                                        $ticker_posts_query->the_post();
                                        ?>
                                        <div class="ticker-item">
                                            <?php if (has_post_thumbnail()) : ?>
                                                <div class="entry-image entry-image-tiny">
                                                    <a href="<?php the_permalink(); ?>" aria-hidden="true"
                                                       tabindex="-1">
                                                        <?php the_post_thumbnail('thumbnail', ['alt' => the_title_attribute(['echo' => false])]); ?>
                                                    </a>
                                                </div>
                                            <?php endif; ?>
                                            <h3 class="entry-title entry-title-xsmall">
                                                <a href="<?php the_permalink(); ?>" tabindex="0" rel="bookmark"
                                                   title="<?php the_title_attribute(); ?>">
                                                    <?php the_title(); ?>
                                                </a>
                                            </h3>
                                        </div>
                                    <?php
                                    endwhile; ?>
                                </div>
                                <?php
                                wp_reset_postdata();
                            endif; ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php
        }
    }
endif;
if (class_exists('WooCommerce')) {
    remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar');
    add_action('woocommerce_before_main_content', 'newsnation_woo_before_main_content', 5);
    add_action('woocommerce_after_main_content', 'newsnation_woo_after_main_content', 15);
}
if (!function_exists('newsnation_woo_before_main_content')) :
    function newsnation_woo_before_main_content()
    {
        echo '<div class="wrapper">';
        echo '<div class="column-row">';
    }
endif;
if (!function_exists('newsnation_woo_after_main_content')) :
    function newsnation_woo_after_main_content()
    {
        $newsnation_default = newsnation_get_default_theme_options();
        $sidebar = esc_attr(get_theme_mod('global_sidebar_layout', $newsnation_default['global_sidebar_layout']));
        if ($sidebar != 'no-sidebar') {
            get_sidebar();
        }
        echo '</div>';
        echo '</div>';
    }
endif;
if (!function_exists('newsnation_content_loading')) {
    function newsnation_content_loading()
    { ?>
        <div class="content-loading-status">
            <div class="theme-ajax-loader"></div>
            <div class="screen-reader-text">
                <?php esc_html_e('Content Loading', 'newsnation'); ?>
            </div>
        </div>
        <?php
    }
}
if (!function_exists('newsnation_after_content_pagination')) :
    function newsnation_after_content_pagination($after_content)
    {
        $pagination_single = wp_link_pages(array(
            'before' => '<div class="page-links">' . esc_html__('Pages:', 'newsnation'),
            'after' => '</div>',
            'echo' => false
        ));
        $after_content = $pagination_single . $after_content;
        return $after_content;
    }
endif;
if (!function_exists('main_navigation_extras')) :
    function main_navigation_extras()
    {
        $newsnation_default = newsnation_get_default_theme_options();
        $ed_header_subscription_news = get_theme_mod('ed_header_subscription_news', $newsnation_default['ed_header_subscription_news']);
        $ed_header_subscription_button_text = get_theme_mod('ed_header_subscription_button_text', $newsnation_default['ed_header_subscription_button_text']);
        ?>
        <div class="navbar-controls hide-no-js">
            <button type="button" class="navbar-control theme-colormode-switcher">
                <span class="screen-reader-text"><?php _e('Switch color mode', 'newsnation'); ?></span>
                <span id="colormode-switch-area">
                    <span id="mode-icon-switch"></span>
                    <span class="mode-icon-change"></span>
                </span>
            </button>
            <button type="button" class="navbar-control navbar-control-search">
                <span class="screen-reader-text"><?php esc_html_e('Search', 'newsnation'); ?></span>
                <?php newsnation_theme_svg('search'); ?>
            </button>
            <button type="button" class="navbar-control navbar-control-offcanvas">
                    <span class="navbar-control-info">
                        <span class="navbar-control-label">
                            <?php esc_html_e('Menu', 'newsnation'); ?>
                        </span>
                        <span class="navbar-control-icon">
                            <?php newsnation_theme_svg('menu'); ?>
                        </span>
                    </span>
            </button>
            <?php if ($ed_header_subscription_news) { ?>
                <button type="button" class="navbar-control navbar-control-subscription theme-btn theme-primary-btn">
                    <?php newsnation_theme_svg('mail'); ?>
                    <?php echo esc_html($ed_header_subscription_button_text); ?>
                </button>
            <?php } ?>
        </div>
        <?php
    }
endif;
add_filter('comment_form_defaults', 'newsnation_comment_title_callback');
if (!function_exists('newsnation_comment_title_callback')) :
    function newsnation_comment_title_callback($defaults)
    {
        $defaults['title_reply_before'] = '<header class="theme-block-header"><h2 class="theme-block-title">';
        $defaults['title_reply_after'] = '</h2></header>';
        return $defaults;
    }
endif;
if (!function_exists('newsnation_iframe_escape')) :
    /** Escape Iframe **/
    function newsnation_iframe_escape($input)
    {
        $all_tags = array(
            'iframe' => array(
                'width' => array(),
                'height' => array(),
                'src' => array(),
                'frameborder' => array(),
                'allow' => array(),
                'allowfullscreen' => array(),
            ),
            'video' => array(
                'width' => array(),
                'height' => array(),
                'src' => array(),
                'style' => array(),
                'controls' => array(),
            )
        );
        return wp_kses($input, $all_tags);
    }
endif;
/* ---------------------------------------------------------------------------------------------
GET FALLBACK IMAGE
------------------------------------------------------------------------------------------------ */
if (!function_exists('newsnation_get_fallback_image_url')) :
    function newsnation_get_fallback_image_url()
    {
        $disable_fallback_image = get_theme_mod('newsnation_disable_fallback_image', false);
        if ($disable_fallback_image) return '';
        $fallback_image_id = get_theme_mod('newsnation_fallback_image');
        if ($fallback_image_id) {
            $fallback_image = wp_get_attachment_image_src($fallback_image_id, 'full');
        }
        $fallback_image_url = isset($fallback_image) ? esc_url($fallback_image[0]) : get_template_directory_uri() . '/assets/images/default-fallback-image.png';
        return $fallback_image_url;
    }
endif;
