<?php
/**
 * Custom Functions.
 *
 * @package Aerial Drone
 */

if( !function_exists( 'aerial_drone_fonts_url' ) ) :

    //Google Fonts URL
    function aerial_drone_fonts_url(){

        $font_families = array(
            'Work+Sans:ital,wght@0,100..900;1,100..900', // font-family: "Work Sans", sans-serif;
        );

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

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

        // Add sub menu toggles to the main menu with toggles
        if ( $args->theme_location == 'aerial-drone-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="btn__content" tabindex="-1"><span class="screen-reader-text">' . esc_html__( 'Show sub menu', 'aerial-drone' ) . '</span>' . aerial_drone_get_theme_svg( 'chevron-down' ) . '</span></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 == 'aerial-drone-primary-menu' ) {

            if ( in_array( 'menu-item-has-children', $item->classes ) ) {

                $args->before = '<div class="link-icon-wrapper">';
                $args->after  = aerial_drone_get_theme_svg( 'chevron-down' ) . '</div>';

            } else {

                $args->before = '';
                $args->after  = '';

            }

        }

        return $args;

    }

endif;

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

if ( ! function_exists( 'aerial_drone_the_theme_svg' ) ):
    
    function aerial_drone_the_theme_svg( $aerial_drone_svg_name, $return = false ) {

        if( $return ){

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

        }else{

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

        }
    }

endif;

if ( ! function_exists( 'aerial_drone_get_theme_svg' ) ):

    function aerial_drone_get_theme_svg( $aerial_drone_svg_name ) {

        // Make sure that only our allowed tags and attributes are included.
        $aerial_drone_svg = wp_kses(
            Aerial_Drone_SVG_Icons::get_svg( $aerial_drone_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,
                ),
                'polyline' => array(
                    'fill'      => true,
                    'points'    => true,
                ),
                'line' => array(
                    'fill'      => true,
                    'x1'      => true,
                    'x2' => true,
                    'y1'    => true,
                    'y2' => true,
                ),
            )
        );
        if ( ! $aerial_drone_svg ) {
            return false;
        }
        return $aerial_drone_svg;

    }

endif;

if( !function_exists( 'aerial_drone_post_category_list' ) ) :

    // Post Category List.
    function aerial_drone_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 --','aerial-drone' );

        }

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

    function aerial_drone_single_post_navigation(){

        $aerial_drone_default = aerial_drone_get_default_theme_options();
        $twp_navigation_type = esc_attr( get_post_meta( get_the_ID(), 'twp_disable_ajax_load_next_post', true ) );
        $current_id = '';
        $article_wrap_class = '';
        global $post;
        $current_id = $post->ID;
        if( $twp_navigation_type == '' || $twp_navigation_type == 'global-layout' ){
            $twp_navigation_type = get_theme_mod('twp_navigation_type', $aerial_drone_default['twp_navigation_type']);
        }

        if( $twp_navigation_type != 'no-navigation' && 'post' === get_post_type() ){

            if( $twp_navigation_type == 'theme-normal-navigation' ){ ?>

                <div class="navigation-wrapper">
                    <?php
                    // Previous/next post navigation.
                    the_post_navigation(array(
                        'prev_text' => '<span class="arrow" aria-hidden="true">' . aerial_drone_the_theme_svg('arrow-left',$return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Previous post:', 'aerial-drone') . '</span><span class="post-title">%title</span>',
                        'next_text' => '<span class="arrow" aria-hidden="true">' . aerial_drone_the_theme_svg('arrow-right',$return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Next post:', 'aerial-drone') . '</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="twp-single-infinity"></div>';

                }
            }

        }

    }

endif;

add_action( 'aerial_drone_navigation_action','aerial_drone_single_post_navigation',30 );

if( !function_exists('aerial_drone_footer_content_widget') ):

    function aerial_drone_footer_content_widget(){
        
        $aerial_drone_default = aerial_drone_get_default_theme_options();
        
        $aerial_drone_footer_column_layout = absint(get_theme_mod('aerial_drone_footer_column_layout', $aerial_drone_default['aerial_drone_footer_column_layout']));
        $aerial_drone_footer_sidebar_class = 12;
        
        if($aerial_drone_footer_column_layout == 2) {
            $aerial_drone_footer_sidebar_class = 6;
        }
        
        if($aerial_drone_footer_column_layout == 3) {
            $aerial_drone_footer_sidebar_class = 4;
        }
        ?>
        
        <?php if ( get_theme_mod('aerial_drone_display_footer', true) == true ) : ?>
            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                    
                        <?php for ($i = 0; $i < $aerial_drone_footer_column_layout; $i++) : ?>
                            
                            <div class="column <?php echo 'column-' . absint($aerial_drone_footer_sidebar_class); ?> column-sm-12">
                                
                                <?php 
                                // If no widgets are assigned, display default widgets
                                if ( ! is_active_sidebar( 'aerial-drone-footer-widget-' . $i ) ) : 

                                    if ($i === 0) : ?>
                                        <div id="media_image-3" class="widget widget_media_image">
                                            <img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/logo.png'); ?>" alt="<?php echo esc_attr__( 'Footer Image', 'aerial-drone' ); ?>" style="max-width: 100%; height: auto;">
                                        </div>
                                        <div id="text-3" class="widget widget_text">
                                            <div class="textwidget">
                                                <p class="widget_text">
                                                    <?php esc_html_e('The Aerial Drone WordPress Theme is a modern, visually captivating theme designed for drone enthusiasts and professionals alike, whether involved in drone photography, drone videography, or specialized commercial drone services. Tailored for the drone industry, this theme is perfect for businesses offering drone mapping, drone inspection, and even drone repair services.', 'aerial-drone'); ?>
                                                </p>
                                            </div>
                                        </div>

                                    <?php elseif ($i === 1) : ?>
                                        <div id="pages-2" class="widget widget_pages">
                                            <h2 class="widget-title"><?php esc_html_e('Calendar', 'aerial-drone'); ?></h2>
                                            <?php get_calendar(); ?>
                                        </div>

                                    <?php elseif ($i === 2) : ?>
                                        <div id="search-2" class="widget widget_search">
                                            <h2 class="widget-title"><?php esc_html_e('Enter Keywords Here', 'aerial-drone'); ?></h2>
                                            <?php get_search_form(); ?>
                                        </div>
                                    <?php endif; 
                                    
                                else :
                                    // Display dynamic sidebar widget if assigned
                                    dynamic_sidebar('aerial-drone-footer-widget-' . $i);
                                endif;
                                ?>
                                
                            </div>
                            
                        <?php endfor; ?>

                    </div>
                </div>
            </div>
        <?php endif; ?> 

    <?php
    }

endif;

add_action( 'aerial_drone_footer_content_action', 'aerial_drone_footer_content_widget', 10 );


if( !function_exists('aerial_drone_content_offcanvas') ):

    // Offcanvas Contents
    function aerial_drone_content_offcanvas(){ ?>

        <div id="offcanvas-menu">
            <div class="offcanvas-wraper">
                <div class="close-offcanvas-menu">
                    <div class="offcanvas-close">
                        <a href="javascript:void(0)" class="skip-link-menu-start"></a>
                        <button type="button" class="button-offcanvas-close">
                            <span class="offcanvas-close-label">
                                <?php echo esc_html__('Close', 'aerial-drone'); ?>
                            </span>
                        </button>
                    </div>
                </div>
                <div id="primary-nav-offcanvas" class="offcanvas-item offcanvas-main-navigation">
                    <nav class="primary-menu-wrapper" aria-label="<?php esc_attr_e('Horizontal', 'aerial-drone'); ?>" role="navigation">
                        <ul class="primary-menu theme-menu">
                            <?php
                            if (has_nav_menu('aerial-drone-primary-menu')) {
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'aerial-drone-primary-menu',
                                        'show_toggles' => true,
                                    )
                                );
                            }else{

                                wp_list_pages(
                                    array(
                                        'match_menu_classes' => true,
                                        'show_sub_menu_icons' => true,
                                        'title_li' => false,
                                        'show_toggles' => true,
                                        'walker' => new Aerial_Drone_Walker_Page(),
                                    )
                                );
                            }
                            ?>
                        </ul>
                    </nav><!-- .primary-menu-wrapper -->
                </div>
                <a href="javascript:void(0)" class="skip-link-menu-end"></a>
            </div>
        </div>

    <?php
    }

endif;

add_action( 'aerial_drone_before_footer_content_action','aerial_drone_content_offcanvas',30 );


if( !function_exists('aerial_drone_footer_content_info') ):

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

        $aerial_drone_default = aerial_drone_get_default_theme_options(); ?>
        <div class="site-info">
            <div class="wrapper">
                <div class="column-row">
                    <div class="column column-9">
                        <div class="footer-credits">
                            <div class="footer-copyright">
                                <?php
                                    $aerial_drone_footer_copyright_text = wp_kses_post( get_theme_mod( 'aerial_drone_footer_copyright_text', $aerial_drone_default['aerial_drone_footer_copyright_text'] ) );
                                        echo esc_html( $aerial_drone_footer_copyright_text );
                                        echo '<br>';
                                        echo esc_html__('Theme: ', 'aerial-drone') . '<a href="' . esc_url('https://www.omegathemes.com/products/free-drone-wordpress-theme') . '" title="' . esc_attr__('AERIAL DRONE', 'aerial-drone') . '" target="_blank"><span>' . esc_html__('AERIAL DRONE', 'aerial-drone') . '</span></a>' . esc_html__(' By ', 'aerial-drone') . '  <span>' . esc_html__('OMEGA ', 'aerial-drone') . '</span>';
                                        echo esc_html__('Powered by ', 'aerial-drone') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'aerial-drone') . '" target="_blank"><span>' . esc_html__('WordPress.', 'aerial-drone') . '</span></a>';
                                    ?>
                            </div>
                        </div>
                    </div>
                    <div class="column column-3 align-text-right">
                        <a class="to-the-top" href="#site-header">
                            <span class="to-the-top-long">
                                <?php if ( get_theme_mod('aerial_drone_enable_to_the_top', true) == true ) : ?>
                                    <?php
                                    $aerial_drone_to_the_top_text = get_theme_mod( 'aerial_drone_to_the_top_text', __( 'To the Top', 'aerial-drone' ) );
                                    printf( 
                                        wp_kses( 
                                            /* translators: %s is the arrow icon markup */
                                            '%s %s', 
                                            array( 'span' => array( 'class' => array(), 'aria-hidden' => array() ) ) 
                                        ), 
                                        esc_html( $aerial_drone_to_the_top_text ),
                                        '<span class="arrow" aria-hidden="true">&uarr;</span>' 
                                    );
                                    ?>
                                <?php endif; ?>
                            </span>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    <?php
    }

endif;

add_action( 'aerial_drone_footer_content_action','aerial_drone_footer_content_info',20 );


if ( ! function_exists( 'aerial_drone_main_slider' ) ) :

    function aerial_drone_main_slider() {
        $output = '';
        $aerial_drone_defaults = aerial_drone_get_default_theme_options();
        $aerial_drone_header_slider = get_theme_mod( 'aerial_drone_header_slider', $aerial_drone_defaults['aerial_drone_header_slider'] );

        $aerial_drone_slider_short_heading = esc_html( get_theme_mod( 'aerial_drone_slider_short_heading',
        $aerial_drone_defaults['aerial_drone_slider_short_heading'] ) );

        // Debugging header slider status
        if ( ! $aerial_drone_header_slider ) {
            error_log('Header slider is not enabled or has a falsy value.');
            return '';  // Exit early if no slider
        }

        $aerial_drone_banner_background_image = get_theme_mod( 'aerial_drone_banner_background_image', $aerial_drone_defaults['aerial_drone_banner_background_image'] );
        $aerial_drone_header_banner_cat = get_theme_mod( 'aerial_drone_header_banner_cat' );

        $banner_query = new WP_Query( array(
            'post_type' => 'post',
            'posts_per_page' => 4,
            'post__not_in' => get_option( 'sticky_posts' ),
            'category_name' => esc_html( $aerial_drone_header_banner_cat ),
        ) );

        // Check if the query has posts
        if ( ! $banner_query->have_posts() ) {
            error_log('No posts found for the banner query.');
            return '';  // Exit early if no posts
        }

        ob_start();  // Start output buffering
        ?>
        <div id="site-content" class="main-banner" style="background: url(<?php echo esc_url( $aerial_drone_banner_background_image ); ?>);">
            <div class="slider-box" >
                <div class="main-slider">
                    <div class="swiper-container theme-main-carousel" <?php echo is_rtl() ? 'dir="rtl"' : ''; ?>>
                        <div class="swiper-wrapper">
                            <?php while ( $banner_query->have_posts() ) : $banner_query->the_post();
                                $aerial_drone_featured_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' )[0] ?? get_template_directory_uri() . '/assets/images/default.png';
                                ?>
                                <div class="swiper-slide main-carousel-item">
                                    <div class="slider-main">
                                        <div class="left-box">
                                            <div class="slide-heading-main">
                                                <div class="main-carousel-caption">
                                                    <div class="post-content">
                                                        <?php if( $aerial_drone_slider_short_heading ){ ?>
                                                            <h3 class="short-heading"><?php echo esc_html( $aerial_drone_slider_short_heading ); ?></h3>
                                                        <?php } ?>
                                                        <header class="entry-header">
                                                            <h2 class="slider-heading">
                                                                <a href="<?php the_permalink(); ?>" rel="bookmark"><span><?php echo esc_html( get_the_title() ); ?></span></a>
                                                            </h2>
                                                        </header>
                                                        <div class="slide-btn">
                                                            <?php if(get_theme_mod('aerial_drone_slider_video_button_url','#') != ''){ ?>
                                                            <span class="slide-btn">
                                                              <!-- Button to open the modal -->
                                                              <a id="openModalButton" data-modal-src="<?php echo esc_url(get_theme_mod('aerial_drone_slider_video_button_url','#')); ?>"><svg xmlns="http://www.w3.org/2000/svg" height="1.5em" viewBox="0 0 192 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M0 384.7V127.3c0-17.8 21.5-26.7 34.1-14.1l128.7 128.7c7.8 7.8 7.8 20.5 0 28.3L34.1 398.8C21.5 411.4 0 402.5 0 384.7z"/></svg></a>
                                                              <!-- The modal -->
                                                              <div id="myModal" class="modal">
                                                                <!-- Modal content -->
                                                                <div class="modal-content">
                                                                  <span id="closeModalButton" class="close">&times;</span>
                                                                  <?php if( get_theme_mod('aerial_drone_slider_video_button_url','#') != ''){ ?>
                                                                  <embed id="videoPlayer" height="369" src="<?php echo esc_url(get_theme_mod('aerial_drone_slider_video_button_url','#')); ?>"  allow="accelerometer; autoplay; classipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></embed>
                                                                  <?php }else{ ?>
                                                                    <h3><?php esc_html_e('Add Video Url In Customizer To Display Video Here','aerial-drone'); ?></h3>
                                                                  <?php } ?>
                                                                </div>
                                                              </div> 
                                                            </span>
                                                        <?php } ?>
                                                            <a href="<?php the_permalink(); ?>" class="btn-fancy btn-fancy-primary slider-btn">
                                                                <?php echo esc_html__( 'shop now', 'aerial-drone' ); ?> <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M190.5 66.9l22.2-22.2c9.4-9.4 24.6-9.4 33.9 0L441 239c9.4 9.4 9.4 24.6 0 33.9L246.6 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.2-22.2c-9.5-9.5-9.3-25 .4-34.3L311.4 296H24c-13.3 0-24-10.7-24-24v-32c0-13.3 10.7-24 24-24h287.4L190.9 101.2c-9.8-9.3-10-24.8-.4-34.3z"/></svg>
                                                            </a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="right-box">
                                            <div class="image-main-box">
                                                <div class="data-bg banner-img" data-background="<?php echo esc_url( $aerial_drone_featured_image ); ?>">
                                                    <a href="<?php the_permalink(); ?>" class="theme-image-responsive"></a>
                                                </div>
                                                <?php aerial_drone_post_format_icon(); ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endwhile; ?>
                        </div>
                        <div class="swiper-pagination"></div>
                    </div>
                </div>
            </div>
        </div>
        <?php
        wp_reset_postdata();
        $output = ob_get_clean(); // Get buffered output and clean buffer
        return $output; // Return the output instead of echoing
    }

endif;


if( !function_exists( 'aerial_drone_product_section' ) ) :

    function aerial_drone_product_section(){ 

        $aerial_drone_default = aerial_drone_get_default_theme_options();
        $aerial_drone_locations_post = get_theme_mod( 'aerial_drone_locations_post', $aerial_drone_default['aerial_drone_locations_post'] );
        $aerial_drone_locations_post_cat = get_theme_mod( 'aerial_drone_locations_post_cat','uncategorized' );

        $aerial_drone_team_section_subtitle = esc_html( get_theme_mod( 'aerial_drone_team_section_subtitle',
        $aerial_drone_default['aerial_drone_team_section_subtitle'] ) );

        $aerial_drone_team_section_title = esc_html( get_theme_mod( 'aerial_drone_team_section_title',
        $aerial_drone_default['aerial_drone_team_section_title'] ) );

        $aerial_drone_locations_query = new WP_Query( array('post_type' => 'post', 'posts_per_page' => 6,'post__not_in' => get_option("sticky_posts"), 'category_name' => esc_html( $aerial_drone_locations_post_cat ) ) );
            if( $aerial_drone_locations_query->have_posts() ): ?>
            <div class="theme-product-block">
                <div class="wrapper">
                    <div class="services-box">
                        <div class="section-heading">
                            <?php if( $aerial_drone_team_section_subtitle ){ ?>
                                <h6><?php echo esc_html( $aerial_drone_team_section_subtitle ); ?></h6>
                            <?php } ?>
                            <?php if( $aerial_drone_team_section_title ){ ?>
                                <h4><?php echo esc_html( $aerial_drone_team_section_title ); ?></h4>
                            <?php } ?>
                        </div>
                        <div class="owl-carousel" role="listbox">
                            <?php
                                $s=1;
                                while( $aerial_drone_locations_query->have_posts() ):
                                $aerial_drone_locations_query->the_post();
                                $aerial_drone_featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
                                $aerial_drone_featured_image = isset( $aerial_drone_featured_image[0] ) ? $aerial_drone_featured_image[0] : ''; 

                                $aerial_drone_showcase_video_button_url = esc_url( get_theme_mod( 'aerial_drone_showcase_video_button_url' . $s,'#' ) );

                                ?>                                
                                <div class="theme-article-post slider-post-content">
                                    <div class="entry-thumbnail">
                                        <div class="data-bg featured-img" data-background="<?php echo esc_url($aerial_drone_featured_image ? $aerial_drone_featured_image : get_template_directory_uri() . '/assets/images/default.png'); ?>">
                                            <a href="<?php the_permalink(); ?>" class="theme-image-responsive" tabindex="0"></a>
                                        </div>
                                        <?php aerial_drone_post_format_icon(); ?>
                                        <span class="post-date"><?php echo get_the_date('j M'); ?></span>
                                        <?php if( $aerial_drone_showcase_video_button_url ){ ?>
                                            <span class="video-btn"><a href="<?php echo esc_url( $aerial_drone_showcase_video_button_url ); ?>"><svg xmlns="http://www.w3.org/2000/svg" height="1.5em" viewBox="0 0 192 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M0 384.7V127.3c0-17.8 21.5-26.7 34.1-14.1l128.7 128.7c7.8 7.8 7.8 20.5 0 28.3L34.1 398.8C21.5 411.4 0 402.5 0 384.7z"/></svg></a></span>
                                        <?php } ?>
                                    </div>
                                    <div class="main-owl-caption">
                                        <div class="post-content-location">
                                            <header class="entry-header">
                                                <h2 class="entry-title entry-title-big">
                                                    <a href="<?php the_permalink(); ?>" rel="bookmark"><span><?php the_title(); ?></span></a>
                                                </h2>
                                                <div class="entry-content">
                                                    <?php
                                                    if (has_excerpt()) {

                                                        the_excerpt();

                                                    } else {

                                                        echo esc_html(wp_trim_words(get_the_content(), 25, '...'));

                                                    } ?> 
                                                </div> 
                                                <a class="banner-btn" href="<?php the_permalink(); ?>"><?php echo esc_html('LEARN MORE','aerial-drone'); ?></a>
                                            </header>
                                        </div>
                                    </div>
                                </div>
                            <?php $s++; endwhile; ?>
                        </div>
                    </div>
                </div>
            </div>
             <?php
            wp_reset_postdata();
            endif;
          ?>
    <?php }

endif;
if (!function_exists('aerial_drone_post_format_icon')):

    // Post Format Icon.
    function aerial_drone_post_format_icon() {

        $aerial_drone_format = get_post_format(get_the_ID()) ?: 'standard';
        $aerial_drone_icon = '';
        $aerial_drone_title = '';
        if( $aerial_drone_format == 'video' ){
            $aerial_drone_icon = aerial_drone_get_theme_svg( 'video' );
            $aerial_drone_title = esc_html__('Video','aerial-drone');
        }elseif( $aerial_drone_format == 'audio' ){
            $aerial_drone_icon = aerial_drone_get_theme_svg( 'audio' );
            $aerial_drone_title = esc_html__('Audio','aerial-drone');
        }elseif( $aerial_drone_format == 'gallery' ){
            $aerial_drone_icon = aerial_drone_get_theme_svg( 'gallery' );
            $aerial_drone_title = esc_html__('Gallery','aerial-drone');
        }elseif( $aerial_drone_format == 'quote' ){
            $aerial_drone_icon = aerial_drone_get_theme_svg( 'quote' );
            $aerial_drone_title = esc_html__('Quote','aerial-drone');
        }elseif( $aerial_drone_format == 'image' ){
            $aerial_drone_icon = aerial_drone_get_theme_svg( 'image' );
            $aerial_drone_title = esc_html__('Image','aerial-drone');
        } elseif( $aerial_drone_format == 'link' ){
            $aerial_drone_icon = aerial_drone_get_theme_svg( 'link' );
            $aerial_drone_title = esc_html__('Link','aerial-drone');
        } elseif( $aerial_drone_format == 'status' ){
            $aerial_drone_icon = aerial_drone_get_theme_svg( 'status' );
            $aerial_drone_title = esc_html__('Status','aerial-drone');
        } elseif( $aerial_drone_format == 'aside' ){
            $aerial_drone_icon = aerial_drone_get_theme_svg( 'aside' );
            $aerial_drone_title = esc_html__('Aside','aerial-drone');
        } elseif( $aerial_drone_format == 'chat' ){
            $aerial_drone_icon = aerial_drone_get_theme_svg( 'chat' );
            $aerial_drone_title = esc_html__('Chat','aerial-drone');
        }
        
        if (!empty($aerial_drone_icon)) { ?>
            <div class="theme-post-format">
                <span class="post-format-icom"><?php echo aerial_drone_svg_escape($aerial_drone_icon); ?></span>
                <?php if( $aerial_drone_title ){ echo '<span class="post-format-label">'.esc_html( $aerial_drone_title ).'</span>'; } ?>
            </div>
        <?php }
    }

endif;

if ( ! function_exists( 'aerial_drone_svg_escape' ) ):

    /**
     * Get information about the SVG icon.
     *
     * @param string $aerial_drone_svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function aerial_drone_svg_escape( $aerial_drone_input ) {

        // Make sure that only our allowed tags and attributes are included.
        $aerial_drone_svg = wp_kses(
            $aerial_drone_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 ( ! $aerial_drone_svg ) {
            return false;
        }

        return $aerial_drone_svg;

    }

endif;

if( !function_exists( 'aerial_drone_sanitize_sidebar_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function aerial_drone_sanitize_sidebar_option_meta( $aerial_drone_input ){

        $metabox_options = array( 'global-sidebar','left-sidebar','right-sidebar','no-sidebar' );
        if( in_array( $aerial_drone_input,$metabox_options ) ){

            return $aerial_drone_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'aerial_drone_sanitize_pagination_meta' ) ) :

    // Sidebar Option Sanitize.
    function aerial_drone_sanitize_pagination_meta( $aerial_drone_input ){

        $aerial_drone_metabox_options = array( 'Center','Right','Left');
        if( in_array( $aerial_drone_input,$aerial_drone_metabox_options ) ){

            return $aerial_drone_input;

        }else{

            return '';

        }
    }

endif;

// Sanitize the enable/disable setting for pagination
if( !function_exists('aerial_drone_sanitize_enable_pagination') ) :
    function aerial_drone_sanitize_enable_pagination( $aerial_drone_input ) {
        return (bool) $aerial_drone_input;
    }
endif;

if( !function_exists( 'aerial_drone_sanitize_pagination_type' ) ) :

    /**
     * Sanitize the pagination type setting.
     *
     * @param string $aerial_drone_input The input value from the Customizer.
     * @return string The sanitized value.
     */
    function aerial_drone_sanitize_pagination_type( $aerial_drone_input ) {
        // Define valid options for the pagination type.
        $aerial_drone_valid_options = array( 'numeric', 'newer_older' ); // Update valid options to include 'newer_older'

        // If the input is one of the valid options, return it. Otherwise, return the default option ('numeric').
        if ( in_array( $aerial_drone_input, $aerial_drone_valid_options, true ) ) {
            return $aerial_drone_input;
        } else {
            // Return 'numeric' as the fallback if the input is invalid.
            return 'numeric';
        }
    }

endif;

if( !function_exists( 'aerial_drone_sanitize_menu_transform' ) ) :

    // Sidebar Option Sanitize.
    function aerial_drone_sanitize_menu_transform( $aerial_drone_input ){

        $aerial_drone_metabox_options = array( 'capitalize','uppercase','lowercase');
        if( in_array( $aerial_drone_input,$aerial_drone_metabox_options ) ){

            return $aerial_drone_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'aerial_drone_sanitize_page_content_alignment' ) ) :

    // Sidebar Option Sanitize.
    function aerial_drone_sanitize_page_content_alignment( $aerial_drone_input ){

        $aerial_drone_metabox_options = array( 'left','center','right');
        if( in_array( $aerial_drone_input,$aerial_drone_metabox_options ) ){

            return $aerial_drone_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'aerial_drone_sanitize_footer_widget_title_alignment' ) ) :

    // Footer Option Sanitize.
    function aerial_drone_sanitize_footer_widget_title_alignment( $aerial_drone_input ){

        $aerial_drone_metabox_options = array( 'left','center','right');
        if( in_array( $aerial_drone_input,$aerial_drone_metabox_options ) ){

            return $aerial_drone_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'aerial_drone_sanitize_copyright_alignment_meta' ) ) :

    // Sidebar Option Sanitize.
    function aerial_drone_sanitize_copyright_alignment_meta( $aerial_drone_input ){

        $aerial_drone_metabox_options = array( 'Default','Reverse','Center');
        if( in_array( $aerial_drone_input,$aerial_drone_metabox_options ) ){

            return $aerial_drone_input;

        }else{

            return '';

        }
    }

endif;

/**
 * Sidebar Layout Function
 */
function aerial_drone_get_final_sidebar_layout() {
	$aerial_drone_defaults       = aerial_drone_get_default_theme_options();
	$aerial_drone_global_layout  = get_theme_mod('aerial_drone_global_sidebar_layout', $aerial_drone_defaults['aerial_drone_global_sidebar_layout']);
	$aerial_drone_page_layout    = get_theme_mod('aerial_drone_page_sidebar_layout', $aerial_drone_global_layout);
	$aerial_drone_post_layout    = get_theme_mod('aerial_drone_post_sidebar_layout', $aerial_drone_global_layout);
	$aerial_drone_meta_layout    = get_post_meta(get_the_ID(), 'aerial_drone_post_sidebar_option', true);

	if (!empty($aerial_drone_meta_layout) && $aerial_drone_meta_layout !== 'default') {
		return $aerial_drone_meta_layout;
	}
	if (is_page() || (function_exists('is_shop') && is_shop())) {
		return $aerial_drone_page_layout;
	}
	if (is_single()) {
		return $aerial_drone_post_layout;
	}
	return $aerial_drone_global_layout;
}