<?php

/**
 * Custom Functions.
 *
 * @package Vintuna
 */

if (!function_exists('vintuna_fonts_url')) :

    //Google Fonts URL
    function vintuna_fonts_url()
    {

        $font_families = array(
            'Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900',
        );

        $fonts_url = add_query_arg(array(
            'family' => implode('&family=', $font_families),
            'display' => 'swap',
        ), 'https://fonts.googleapis.com/css2');

        return esc_url_raw($fonts_url);
    }

endif;

if (!function_exists('vintuna_sanitize_sidebar_option_meta')) :

    // Sidebar Option Sanitize.
    function vintuna_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('vintuna_page_lists')) :

    // Page List.
    function vintuna_page_lists()
    {

        $page_lists = array();
        $page_lists[''] = esc_html__('-- Select Page --', 'vintuna');
        $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('vintuna_sanitize_post_layout_option_meta')) :

    // Sidebar Option Sanitize.
    function vintuna_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('vintuna_sanitize_header_overlay_option_meta')) :

    // Sidebar Option Sanitize.
    function vintuna_sanitize_header_overlay_option_meta($input)
    {

        $metabox_options = array('global-layout', 'enable-overlay');
        if (in_array($input, $metabox_options)) {

            return $input;
        } else {

            return '';
        }
    }

endif;

/**
 * Vintuna SVG Icon helper functions
 *
 * @package Vintuna
 * @since 1.0.0
 */
if (!function_exists('vintuna_theme_svg')) :
    /**
     * Output and Get Theme SVG.
     * Output and get the SVG markup for an icon in the Vintuna_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 vintuna_theme_svg($svg_name, $return = false)
    {

        if ($return) {

            return vintuna_get_theme_svg($svg_name); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in vintuna_get_theme_svg();.

        } else {

            echo vintuna_get_theme_svg($svg_name); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in vintuna_get_theme_svg();.

        }
    }

endif;

if (!function_exists('vintuna_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 vintuna_get_theme_svg($svg_name)
    {

        // Make sure that only our allowed tags and attributes are included.
        $svg = wp_kses(
            Vintuna_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('vintuna_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 vintuna_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('vintuna_social_menu_icon')) :

    function vintuna_social_menu_icon($item_output, $item, $depth, $args)
    {

        // Add Icon
        if (isset($args->theme_location) && 'vintuna-social-menu' === $args->theme_location) {

            $svg = Vintuna_SVG_Icons::get_theme_svg_name($item->url);

            if (empty($svg)) {
                $svg = vintuna_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', 'vintuna_social_menu_icon', 10, 4);

if (!function_exists('vintuna_sub_menu_toggle_button')) :

    function vintuna_sub_menu_toggle_button($args, $item, $depth)
    {

        // Add sub menu toggles to the main menu with toggles
        if ($args->theme_location == 'vintuna-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', 'vintuna') . '</span>' . vintuna_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 == 'vintuna-primary-menu') {
            if (in_array('menu-item-has-children', $item->classes)) {
                $args->before = '<div class="link-icon-wrapper">';
                $args->after = vintuna_get_theme_svg('chevron-down') . '</div>';
            } else {
                $args->before = '';
                $args->after = '';
            }
        }
        return $args;
    }

    add_filter('nav_menu_item_args', 'vintuna_sub_menu_toggle_button', 10, 3);

endif;


if (!function_exists('vintuna_post_category_list')) :

    // Post Category List.
    function vintuna_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', 'vintuna');
        }

        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('vintuna_sanitize_meta_pagination')) :

    /** Sanitize Enable Disable Checkbox **/
    function vintuna_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('vintuna_header_ad')) :

    function vintuna_header_ad()
    {
        $vintuna_default = vintuna_get_default_theme_options();
        $ed_header_ad = get_theme_mod('ed_header_ad', $vintuna_default['ed_header_ad']);
        $ed_header_type = get_theme_mod('ed_header_type', $vintuna_default['ed_header_type']);
        $addvertisement_section_title = get_theme_mod('addvertisement_section_title', $vintuna_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', 'vintuna') ?></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', 'vintuna'); ?>"
                                 alt="<?php esc_attr_e('Header AD Image', 'vintuna'); ?>"/>
                        </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('vintuna_post_floating_nav')) :

    function vintuna_post_floating_nav()
    {

        $vintuna_default = vintuna_get_default_theme_options();
        $ed_floating_next_previous_nav = get_theme_mod('ed_floating_next_previous_nav', $vintuna_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', 'vintuna'); ?></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', 'vintuna'); ?></span>
                        <span class="floating-navigation-title"><?php echo esc_html(get_the_title($next_post->ID)); ?></span>
                    </a>
                </div>

                <?php
            }
        }
    }

endif;

add_action('vintuna_navigation_action', 'vintuna_post_floating_nav', 10);

if (!function_exists('vintuna_single_post_navigation')) :

    function vintuna_single_post_navigation()
    {

        $vintuna_default = vintuna_get_default_theme_options();
        $wpi_navigation_type = esc_attr(get_post_meta(get_the_ID(), 'wpi_disable_ajax_load_next_post', true));
        $vintuna_header_trending_page = get_theme_mod('vintuna_header_trending_page');
        $vintuna_header_popular_page = get_theme_mod('vintuna_header_popular_page');
        $vintuna_archive_layout = esc_attr(get_theme_mod('vintuna_archive_layout', $vintuna_default['vintuna_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', $vintuna_default['wpi_navigation_type']);
        }

        if ($vintuna_header_trending_page != $current_id && $vintuna_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">' . vintuna_theme_svg('arrow-left', $return = true) . '</span><span class="screen-reader-text">' . __('Previous post:', 'vintuna') . '</span><span class="post-title">%title</span>',
                            'next_text' => '<span class="arrow" aria-hidden="true">' . vintuna_theme_svg('arrow-right', $return = true) . '</span><span class="screen-reader-text">' . __('Next post:', 'vintuna') . '</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('vintuna_navigation_action', 'vintuna_single_post_navigation', 30);


if (!function_exists('vintuna_header_banner')) :

    function vintuna_header_banner()
    {

        global $post;

        if (have_posts()) :

            while (have_posts()) :
                the_post();

                global $post;

            endwhile;

        endif;

        $vintuna_post_layout = '';
        $vintuna_default = vintuna_get_default_theme_options();

        if (is_singular()) {

            $vintuna_post_layout = esc_html(get_post_meta($post->ID, 'vintuna_post_layout', true));
            if ($vintuna_post_layout == '' || $vintuna_post_layout == 'global-layout') {

                $vintuna_post_layout = get_theme_mod('vintuna_single_post_layout', $vintuna_default['vintuna_archive_layout']);
            }
        }

        if (isset($post->ID)) {

            $vintuna_page_layout = esc_html(get_post_meta($post->ID, 'vintuna_page_layout', true));
        }

        if ($vintuna_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');
                    $vintuna_ed_feature_image = esc_html(get_post_meta(get_the_ID(), 'vintuna_ed_feature_image', true));
                    ?>

                    <div class="single-featured-banner  <?php if (empty($vintuna_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()) {
                                    vintuna_breadcrumb_with_title_block();
                                } ?>

                                <div class="column-row">
                                    <div class="column column-12">
                                        <header class="entry-header">

                                            <div class="entry-meta">
                                                <?php
                                                vintuna_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
                                            vintuna_posted_by();
                                            ?>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>

                        <?php if (empty($vintuna_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') && $vintuna_page_layout == 'layout-2') {

            if (have_posts()) :

                while (have_posts()) :

                    the_post();

                    $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');

                    $vintuna_ed_feature_image = esc_html(get_post_meta(get_the_ID(), 'vintuna_ed_feature_image', true));
                    ?>

                    <div class="single-featured-banner  <?php if (empty($vintuna_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()) {
                                    vintuna_breadcrumb_with_title_block();
                                } ?>

                                <div class="column-row">
                                    <div class="column column-12">
                                        <header class="entry-header">

                                            <h1 class="entry-title entry-title-large">
                                                <?php the_title(); ?>
                                            </h1>
                                        </header>
                                    </div>
                                </div>

                            </div>
                        </div>

                        <?php if (empty($vintuna_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('vintuna_header_toggle_search')) :

    /**
     * Header Search
     **/
    function vintuna_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 vintuna_theme_svg('cross'); ?>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <?php
    }

endif;

add_action('vintuna_before_footer_content_action', 'vintuna_header_toggle_search', 10);


if (!function_exists('vintuna_content_offcanvas')) :

    // Offcanvas Contents
    function vintuna_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', 'vintuna'); ?>
                    </span>
                    <?php vintuna_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('vintuna-primary-menu')) {

                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'vintuna-primary-menu',
                                        'show_toggles' => true,
                                    )
                                );
                            } else {

                                wp_list_pages(
                                    array(
                                        'match_menu_classes' => true,
                                        'title_li' => false,
                                        'show_toggles' => true,
                                        'walker' => new Vintuna_Walker_Page(),
                                    )
                                );
                            } ?>

                        </ul>
                    </nav>
                </div>

                <?php if (has_nav_menu('vintuna-social-menu')) { ?>

                    <div id="social-nav-offcanvas" class="offcanvas-item offcanvas-social-navigation">

                        <?php
                        wp_nav_menu(
                            array(
                                'theme_location' => 'vintuna-social-menu',
                                'link_before' => '<span class="screen-reader-text">',
                                'link_after' => '</span>',
                                'container' => 'div',
                                'container_class' => 'vintuna-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('vintuna_before_footer_content_action', 'vintuna_content_offcanvas', 30);

if (!function_exists('vintuna_footer_content_widget')) :

    function vintuna_footer_content_widget()
    {

        $vintuna_default = vintuna_get_default_theme_options();
        if (
            is_active_sidebar('vintuna-footer-widget-0') ||
            is_active_sidebar('vintuna-footer-widget-1') ||
            is_active_sidebar('vintuna-footer-widget-2')
        ) :
            $x = 1;
            $footer_sidebar = 0;
            do {
                if ($x == 4 && is_active_sidebar('vintuna-footer-widget-3')) {
                    $footer_sidebar++;
                }
                if ($x == 3 && is_active_sidebar('vintuna-footer-widget-2')) {
                    $footer_sidebar++;
                }
                if ($x == 2 && is_active_sidebar('vintuna-footer-widget-1')) {
                    $footer_sidebar++;
                }
                if ($x == 1 && is_active_sidebar('vintuna-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', $vintuna_default['footer_column_layout'])); ?>

            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                        <?php if (is_active_sidebar('vintuna-footer-widget-0')) : ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-6 column-xs-12">
                                <?php dynamic_sidebar('vintuna-footer-widget-0'); ?>
                            </div>
                        <?php endif; ?>

                        <?php if (is_active_sidebar('vintuna-footer-widget-1')) : ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-6 column-xs-12">
                                <?php dynamic_sidebar('vintuna-footer-widget-1'); ?>
                            </div>
                        <?php endif; ?>

                        <?php if (is_active_sidebar('vintuna-footer-widget-2')) : ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-6 column-xs-12">
                                <?php dynamic_sidebar('vintuna-footer-widget-2'); ?>
                            </div>
                        <?php endif; ?>

                        <?php if (is_active_sidebar('vintuna-footer-widget-3')) : ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-6 column-xs-12">
                                <?php dynamic_sidebar('vintuna-footer-widget-3'); ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        <?php
        endif;
    }

endif;

add_action('vintuna_footer_content_action', 'vintuna_footer_content_widget', 10);

if (!function_exists('vintuna_footer_content_info')) :

    /**
     * Footer Copyright Area
     **/
    function vintuna_footer_content_info()
    {

        $vintuna_default = vintuna_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', $vintuna_default['footer_copyright_text']));
                            echo esc_html__('Copyright ', 'vintuna') . '&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: ', 'vintuna') . 'Vintuna ' . esc_html__('By ', 'vintuna') . '<a href="' . esc_url('https://www.wpinterface.com/themes/vintuna') . '"  title="' . esc_attr__('WPInterface', 'vintuna') . '" target="_blank" rel="author"><span>' . esc_html__('WPInterface. ', 'vintuna') . '</span></a>';
                            echo esc_html__('Powered by ', 'vintuna') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'vintuna') . '" target="_blank"><span>' . esc_html__('WordPress.', 'vintuna') . '</span></a>';

                            ?>
                        </div>
                    </div>

                    <div class="column column-4 column-sm-12">
                        <?php
                        if (has_nav_menu('vintuna-social-menu')) { ?>
                            <div class="footer-social-navigation">
                                <?php
                                wp_nav_menu(

                                    array(
                                        'theme_location' => 'vintuna-social-menu',
                                        'link_before' => '<span class="screen-reader-text">',
                                        'link_after' => '</span>',
                                        'container' => 'div',
                                        'container_class' => 'vintuna-social-menu',
                                        'depth' => 1,
                                    )

                                ); ?>

                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>

            <?php vintuna_footer_go_to_top(); ?>
        </div>

        <?php
    }

endif;

add_action('vintuna_footer_content_action', 'vintuna_footer_content_info', 20);


if (!function_exists('vintuna_footer_go_to_top')) :

    // Scroll to Top render content
    function vintuna_footer_go_to_top()
    {

        $vintuna_default = vintuna_get_default_theme_options();
        $ed_scroll_top_button = get_theme_mod('ed_scroll_top_button', $vintuna_default['ed_scroll_top_button']);

        if ($ed_scroll_top_button) {

            ?>

            <div class="hide-no-js">
                <button type="button" class="scroll-up">
                    <?php vintuna_theme_svg('chevron-up'); ?>
                </button>
            </div>

            <?php

        }
    }

endif;

add_action('wp_ajax_vintuna_tab_posts_callback', 'vintuna_tab_posts_callback');
add_action('wp_ajax_nopriv_vintuna_tab_posts_callback', 'vintuna_tab_posts_callback');

if (!function_exists('vintuna_tab_posts_callback')) :
    // Masonry Post Ajax Call Function.

    function vintuna_tab_posts_callback()
    {

        if (isset($_POST['_wpnonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'])), 'vintuna_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'
                )
            );

            $tab_post_query_1 = 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 = vintuna_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 vintuna_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('vintuna_header_ticker_posts')) :

    function vintuna_header_ticker_posts()
    {

        $vintuna_default = vintuna_get_default_theme_options();
        $ed_header_ticker_posts = get_theme_mod('ed_header_ticker_posts', $vintuna_default['ed_header_ticker_posts']);
        $ed_header_ticker_posts_title = get_theme_mod('ed_header_ticker_posts_title', $vintuna_default['ed_header_ticker_posts_title']);
        $vintuna_header_ticker_cat = get_theme_mod('vintuna_header_ticker_cat');

        if (is_rtl()) {
            $rtl = 'true';
        } else {
            $rtl = 'false';
        }

        if ($ed_header_ticker_posts) { ?>
 <div class="theme-ticker theme-block">
            <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 vintuna_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($vintuna_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>
            <?php
        }
    }

endif;


if (class_exists('WooCommerce')) {

    remove_action('woocommerce_sidebar', 'woocommerce_get_sidebar');
    add_action('woocommerce_before_main_content', 'vintuna_woo_before_main_content', 5);
    add_action('woocommerce_after_main_content', 'vintuna_woo_after_main_content', 15);
}
if (!function_exists('vintuna_woo_before_main_content')) :

    function vintuna_woo_before_main_content()
    {

        echo '<div class="wrapper">';
        echo '<div class="column-row">';
    }

endif;

if (!function_exists('vintuna_woo_after_main_content')) :

    function vintuna_woo_after_main_content()
    {

        $vintuna_default = vintuna_get_default_theme_options();
        $sidebar = esc_attr(get_theme_mod('global_sidebar_layout', $vintuna_default['global_sidebar_layout']));
        if ($sidebar != 'no-sidebar') {

            get_sidebar();
        }

        echo '</div>';
        echo '</div>';
    }

endif;


if (!function_exists('vintuna_content_loading')) {

    function vintuna_content_loading()
    { ?>

        <div class="content-loading-status">
            <div class="theme-ajax-loader"></div>
            <div class="screen-reader-text">
                <?php esc_html_e('Content Loading', 'vintuna'); ?>
            </div>
        </div>

        <?php
    }
}

if (!function_exists('vintuna_after_content_pagination')) :

    function vintuna_after_content_pagination($after_content)
    {

        $pagination_single = wp_link_pages(array(
            'before' => '<div class="page-links">' . esc_html__('Pages:', 'vintuna'),
            'after' => '</div>',
            'echo' => false
        ));

        $after_content = $pagination_single . $after_content;

        return $after_content;
    }

endif;


if (!function_exists('main_navigation_extras')) :

    function main_navigation_extras()
    {

        $vintuna_default = vintuna_get_default_theme_options();
        $ed_header_subscription_news = get_theme_mod('ed_header_subscription_news', $vintuna_default['ed_header_subscription_news']);
        $ed_header_subscription_button_text = get_theme_mod('ed_header_subscription_button_text', $vintuna_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', 'vintuna'); ?></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">
                <?php vintuna_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', 'vintuna'); ?>
                        </span>
                        <span class="navbar-control-icon">
                            <?php vintuna_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 vintuna_theme_svg('mail'); ?>
                    <?php echo esc_html($ed_header_subscription_button_text); ?>
                </button>
            <?php } ?>

        </div>

        <?php
    }

endif;

add_filter('comment_form_defaults', 'vintuna_comment_title_callback');

if (!function_exists('vintuna_comment_title_callback')) :


    function vintuna_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('vintuna_iframe_escape')) :

    /** Escape Iframe **/
    function vintuna_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( 'vintuna_get_fallback_image_url' ) ) :
    function vintuna_get_fallback_image_url() {

        $disable_fallback_image = get_theme_mod( 'vintuna_disable_fallback_image', false );

        if ( $disable_fallback_image ) return '';

        $fallback_image_id = get_theme_mod( 'vintuna_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;
