<?php
/**
 * Custom Functions.
 *
 * @package Online Learning LMS
 */

if( !function_exists( 'online_learning_lms_fonts_url' ) ) :

    //Google Fonts URL
    function online_learning_lms_fonts_url(){

        $online_learning_lms_font_families = array(
            'Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
            'Playfair+Display:ital,wght@0,400..900;1,400..900',
        );

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

        return esc_url_raw($online_learning_lms_fonts_url);
    }

endif;

if ( ! function_exists( 'online_learning_lms_sub_menu_toggle_button' ) ) :

    function online_learning_lms_sub_menu_toggle_button( $online_learning_lms_args, $online_learning_lms_item, $depth ) {

        // Add sub menu toggles to the main menu with toggles
        if ( $online_learning_lms_args->theme_location == 'online-learning-lms-primary-menu' && isset( $online_learning_lms_args->show_toggles ) ) {
            
            // Wrap the menu item link contents in a div, used for positioning
            $online_learning_lms_args->before = '<div class="submenu-wrapper">';
            $online_learning_lms_args->after  = '';

            // Add a toggle to items with children
            if ( in_array( 'menu-item-has-children', $online_learning_lms_item->classes ) ) {

                $online_learning_lms_toggle_target_string = '.menu-item.menu-item-' . $online_learning_lms_item->ID . ' > .sub-menu';

                // Add the sub menu toggle
                $online_learning_lms_args->after .= '<button type="button" class="theme-aria-button submenu-toggle" data-toggle-target="' . $online_learning_lms_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', 'online-learning-lms' ) . '</span>' . online_learning_lms_get_theme_svg( 'chevron-down' ) . '</span></button>';

            }

            // Close the wrapper
            $online_learning_lms_args->after .= '</div><!-- .submenu-wrapper -->';
            // Add sub menu icons to the main menu without toggles (the fallback menu)

        }elseif( $online_learning_lms_args->theme_location == 'online-learning-lms-primary-menu' ) {

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

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

            } else {

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

            }

        }

        return $online_learning_lms_args;

    }

endif;

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

if ( ! function_exists( 'online_learning_lms_the_theme_svg' ) ):
    
    function online_learning_lms_the_theme_svg( $online_learning_lms_svg_name, $online_learning_lms_return = false ) {

        if( $online_learning_lms_return ){

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

        }else{

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

        }
    }

endif;

if ( ! function_exists( 'online_learning_lms_get_theme_svg' ) ):

    function online_learning_lms_get_theme_svg( $online_learning_lms_svg_name ) {

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

    }

endif;

if( !function_exists( 'online_learning_lms_post_category_list' ) ) :

    // Post Category List.
    function online_learning_lms_post_category_list( $online_learning_lms_select_cat = true ){

        $online_learning_lms_post_cat_lists = get_categories(
            array(
                'hide_empty' => '0',
                'exclude' => '1',
            )
        );

        $online_learning_lms_post_cat_cat_array = array();
        if( $online_learning_lms_select_cat ){

            $online_learning_lms_post_cat_cat_array[''] = esc_html__( '-- Select Category --','online-learning-lms' );

        }

        foreach ( $online_learning_lms_post_cat_lists as $online_learning_lms_post_cat_list ) {

            $online_learning_lms_post_cat_cat_array[$online_learning_lms_post_cat_list->slug] = $online_learning_lms_post_cat_list->name;

        }

        return $online_learning_lms_post_cat_cat_array;
    }

endif;

if( !function_exists('online_learning_lms_single_post_navigation') ):

    function online_learning_lms_single_post_navigation(){

        $online_learning_lms_footer_column_layout = online_learning_lms_get_default_theme_options();
        $online_learning_lms_twp_navigation_type = esc_attr( get_post_meta( get_the_ID(), 'online_learning_lms_twp_disable_ajax_load_next_post', true ) );
        $online_learning_lms_current_id = '';
        $article_wrap_class = '';
        global $post;
        $online_learning_lms_current_id = $post->ID;
        if( $online_learning_lms_twp_navigation_type == '' || $online_learning_lms_twp_navigation_type == 'global-layout' ){
            $online_learning_lms_twp_navigation_type = get_theme_mod('online_learning_lms_twp_navigation_type', $online_learning_lms_footer_column_layout['online_learning_lms_twp_navigation_type']);
        }

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

            if( $online_learning_lms_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">' . online_learning_lms_the_theme_svg('arrow-left',$online_learning_lms_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Previous post:', 'online-learning-lms') . '</span><span class="post-title">%title</span>',
                        'next_text' => '<span class="arrow" aria-hidden="true">' . online_learning_lms_the_theme_svg('arrow-right',$online_learning_lms_return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Next post:', 'online-learning-lms') . '</span><span class="post-title">%title</span>',
                    )); ?>
                </div>
                <?php

            }else{

                $online_learning_lms_next_post = get_next_post();
                if( isset( $online_learning_lms_next_post->ID ) ){

                    $online_learning_lms_next_post_id = $online_learning_lms_next_post->ID;
                    echo '<div loop-count="1" next-post="' . absint( $online_learning_lms_next_post_id ) . '" class="twp-single-infinity"></div>';

                }
            }

        }

    }

endif;

add_action( 'online_learning_lms_navigation_action','online_learning_lms_single_post_navigation',30 );

if( !function_exists('online_learning_lms_content_offcanvas') ):

    // Offcanvas Contents
    function online_learning_lms_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', 'online-learning-lms'); ?>
                            </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', 'online-learning-lms'); ?>" role="navigation">
                        <ul class="primary-menu theme-menu">
                            <?php
                            if (has_nav_menu('online-learning-lms-primary-menu')) {
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'online-learning-lms-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 Online_Learning_LMS_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( 'online_learning_lms_before_footer_content_action','online_learning_lms_content_offcanvas',30 );

if( !function_exists('online_learning_lms_footer_content_widget') ):

    function online_learning_lms_footer_content_widget(){
        
        $online_learning_lms_default = online_learning_lms_get_default_theme_options();
        
        $online_learning_lms_footer_column_layout = absint(get_theme_mod('online_learning_lms_footer_column_layout', $online_learning_lms_default['online_learning_lms_footer_column_layout']));
        $online_learning_lms_footer_sidebar_class = 12;
        
        if($online_learning_lms_footer_column_layout == 2) {
            $online_learning_lms_footer_sidebar_class = 6;
        }
        
        if($online_learning_lms_footer_column_layout == 3) {
            $online_learning_lms_footer_sidebar_class = 4;
        }
        ?>
        
        <?php if ( get_theme_mod('online_learning_lms_display_footer', true) == true ) : ?>
            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                    
                        <?php for ($i = 0; $i < $online_learning_lms_footer_column_layout; $i++) : ?>
                            
                            <div class="column <?php echo 'column-' . absint($online_learning_lms_footer_sidebar_class); ?> column-sm-12">
                                
                                <?php 
                                // If no widgets are assigned, display default widgets
                                if ( ! is_active_sidebar( 'online-learning-lms-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', 'online-learning-lms' ); ?>" 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('In a fast-paced digital world, education is no longer confined to classrooms. An Online Learning LMS (Learning Management System) theme is the perfect solution for educators, trainers, and institutions looking to deliver courses online efficiently.', 'online-learning-lms'); ?>
                                                </p>
                                            </div>
                                        </div>

                                    <?php elseif ($i === 1) : ?>
                                        <div id="pages-2" class="widget widget_pages">
                                            <h2 class="widget-title"><?php esc_html_e('Calendar', 'online-learning-lms'); ?></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', 'online-learning-lms'); ?></h2>
                                            <?php get_search_form(); ?>
                                        </div>
                                    <?php endif; 
                                    
                                else :
                                    // Display dynamic sidebar widget if assigned
                                    dynamic_sidebar('online-learning-lms-footer-widget-' . $i);
                                endif;
                                ?>
                                
                            </div>
                            
                        <?php endfor; ?>

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

    <?php
    }

endif;

add_action( 'online_learning_lms_footer_content_action', 'online_learning_lms_footer_content_widget', 10 );

if( !function_exists('online_learning_lms_footer_content_info') ):

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

        $online_learning_lms_footer_column_layout = online_learning_lms_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
                                $online_learning_lms_footer_copyright_text = wp_kses_post( get_theme_mod( 'online_learning_lms_footer_copyright_text', $online_learning_lms_footer_column_layout['online_learning_lms_footer_copyright_text'] ) );
                                    echo esc_html( $online_learning_lms_footer_copyright_text );
                                    echo '<br>';
                                    echo esc_html__('Theme: ', 'online-learning-lms') . '<a href="' . esc_url('https://www.omegathemes.com/products/online-learning-lms') . '" title="' . esc_attr__('Online Learning LMS ', 'online-learning-lms') . '" target="_blank"><span>' . esc_html__('Online Learning LMS  ', 'online-learning-lms') . '</span></a>' . esc_html__(' By ', 'online-learning-lms') . '  <span>' . esc_html__('OMEGA ', 'online-learning-lms') . '</span>';
                                    echo esc_html__('Powered by ', 'online-learning-lms') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'online-learning-lms') . '" target="_blank"><span>' . esc_html__('WordPress.', 'online-learning-lms') . '</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('online_learning_lms_enable_to_the_top', true) == true ) : ?>
                                    <?php
                                    $online_learning_lms_to_the_top_text = get_theme_mod( 'online_learning_lms_to_the_top_text', __( 'To the Top', 'online-learning-lms' ) );
                                    printf( 
                                        wp_kses( 
                                            /* translators: %s is the arrow icon markup */
                                            '%s %s', 
                                            array( 'span' => array( 'class' => array(), 'aria-hidden' => array() ) ) 
                                        ), 
                                        esc_html( $online_learning_lms_to_the_top_text ),
                                        '<span class="arrow" aria-hidden="true">&uarr;</span>' 
                                    );
                                    ?>
                                <?php endif; ?>
                            </span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    <?php
    }

endif;

add_action( 'online_learning_lms_footer_content_action','online_learning_lms_footer_content_info',20 );


if( !function_exists( 'online_learning_lms_main_slider' ) ) :

    function online_learning_lms_main_slider(){

        $online_learning_lms_defaults = online_learning_lms_get_default_theme_options();
        $online_learning_lms_header_slider = get_theme_mod( 'online_learning_lms_header_slider', $online_learning_lms_defaults['online_learning_lms_header_slider'] );

        $online_learning_lms_banner_background_image = get_theme_mod( 'online_learning_lms_banner_background_image', 
        $online_learning_lms_defaults['online_learning_lms_banner_background_image'] );

        $online_learning_lms_header_banner_cat = get_theme_mod( 'online_learning_lms_header_banner_cat','uncategorized' );

        if( $online_learning_lms_header_slider ){ $online_learning_lms_rtl = '';
            if( is_rtl() ){
                $online_learning_lms_rtl = 'dir="rtl"';
            }

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

            if( $online_learning_lms_banner_query->have_posts() ): ?>

                <div id="site-content" class="main-banner">
                    <div class="slider-box" style="background: url(<?php echo esc_url( $online_learning_lms_banner_background_image ); ?>);">
                        <div class="wrapper">
                            <div class="main-slider">
                                <div class="swiper-container theme-main-carousel swiper-container" <?php echo $online_learning_lms_rtl; ?>>
                                    <div class="swiper-wrapper">
                                        <?php
                                        while( $online_learning_lms_banner_query->have_posts() ):
                                        $online_learning_lms_banner_query->the_post();
                                        $online_learning_lms_featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
                                        $online_learning_lms_default_image = get_template_directory_uri() . '/inc/homepage-setup/assets/homepage-setup-images/banner.png';
                                        $online_learning_lms_featured_image = isset( $online_learning_lms_featured_image[0] ) ? $online_learning_lms_featured_image[0] : $online_learning_lms_default_image;?>
                                            <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">
                                                                    <header class="entry-header">
                                                                        <h2 class="slider-heading">
                                                                            <a href="<?php the_permalink(); ?>" rel="bookmark"><span><?php the_title(); ?></span></a>
                                                                        </h2>
                                                                    </header>
                                                                    <div class="entry-content">
                                                                        <?php
                                                                        if (has_excerpt()) {
                                                                            the_excerpt();
                                                                        } else {
                                                                            echo esc_html(wp_trim_words(get_the_content(), 25, '...'));
                                                                        } ?>
                                                                    </div>
                                                                    <a href="<?php the_permalink(); ?>" class="btn-fancy btn-fancy-primary" tabindex="0">
                                                                        <?php echo esc_html__('get started', 'online-learning-lms'); ?>
                                                                    </a>
                                                                </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($online_learning_lms_featured_image); ?>">
                                                            </div>
                                                            <?php online_learning_lms_post_format_icon(); ?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php endwhile; ?>
                                    </div>
                                    <div class="custom-navigation">
                                        <div class="swiper-button-prev custom-prev">
                                            <span class="arrow">
                                                <!-- Left Arrow SVG -->
                                                <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 320 512"><!--!Font Awesome Free v5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z"/></svg>
                                            </span>
                                        </div>

                                        <!-- Swiper Pagination Container -->
                                        <div class="swiper-pagination custom-pagination"></div>

                                        <div class="swiper-button-next custom-next">
                                            <span class="arrow">
                                                <!-- Right Arrow SVG -->
                                                <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 320 512"><!--!Font Awesome Free v5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"/></svg>
                                            </span>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            <?php
            wp_reset_postdata();
            endif;
        }
    }

endif;

    if( !function_exists( 'online_learning_lms_services_section' ) ) :

    function online_learning_lms_services_section(){

        $online_learning_lms_footer_column_layout = online_learning_lms_get_default_theme_options();
        $online_learning_lms_services = get_theme_mod( 'online_learning_lms_services', $online_learning_lms_footer_column_layout['online_learning_lms_services'] );
        $online_learning_lms_services_sec_cat = get_theme_mod( 'online_learning_lms_services_sec_cat','Second' );

        $online_learning_lms_our_team_section_title = get_theme_mod( 'online_learning_lms_our_team_section_title', 
        $online_learning_lms_footer_column_layout['online_learning_lms_our_team_section_title'] );

        $online_learning_lms_our_team_section_short_title = get_theme_mod( 'online_learning_lms_our_team_section_short_title', 
        $online_learning_lms_footer_column_layout['online_learning_lms_our_team_section_short_title'] );

        if( $online_learning_lms_services ){
            if( $online_learning_lms_services_sec_cat ){ ?>
                <div class="service-box">
                    <div class="wrapper">
                        <div class="team-left-content">
                            <?php if( $online_learning_lms_our_team_section_short_title ){ ?>
                                <h6><?php echo esc_html( $online_learning_lms_our_team_section_short_title ); ?></h6>
                            <?php } ?>
                            <?php if( $online_learning_lms_our_team_section_title ){ ?>
                                <h2><?php echo esc_html( $online_learning_lms_our_team_section_title ); ?></h2>
                            <?php } ?>
                        </div>
                        <div class="service-right-box">
                                <?php
                                $online_learning_lms_rtl = '';
                                if( is_rtl() ){
                                    $online_learning_lms_rtl = 'dir="rtl"';
                                }
                                $online_learning_lms_banner_query = new WP_Query( array('post_type' => 'courses', 'posts_per_page' => 8 ) );
                                if( $online_learning_lms_banner_query->have_posts() ): ?>
                                    <div class="theme-custom-block theme-banner-block">
                                        <div class="swiper-container theme-services-carousel swiper-container" <?php echo $online_learning_lms_rtl; ?>>
                                        <div class="swiper-wrapper">
                                            <?php
                                            $s = 1;
                                            while( $online_learning_lms_banner_query->have_posts() ):
                                                $online_learning_lms_banner_query->the_post();
                                                
                                                // Get the featured image for the post
                                                $online_learning_lms_featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
                                                $online_learning_lms_featured_image = isset( $online_learning_lms_featured_image[0] ) ? $online_learning_lms_featured_image[0] : ''; 

                                                $online_learning_lms_default_services_images = get_template_directory_uri() . '/assets/images/service-img.png';
                                                
                                                // Use the customizer icon if set, otherwise fallback to the default icon
                                                $online_learning_lms_featured_image = !empty( $online_learning_lms_featured_image ) ? esc_url( $online_learning_lms_featured_image ) : esc_url( $online_learning_lms_default_services_images );
                                                
                                                // Get the services icon from theme mod or set default icon
                                                $online_learning_lms_services_icon = get_theme_mod( 'online_learning_lms_services_icon' .$s, '' );
                                                $default_services_icon = get_template_directory_uri() . '/assets/images/icon.png';
                                                
                                                // Use the customizer icon if set, otherwise fallback to the default icon
                                                $online_learning_lms_services_icon = !empty( $online_learning_lms_services_icon ) ? esc_url( $online_learning_lms_services_icon ) : esc_url( $default_services_icon );
                                                $course_id = get_the_ID();

                                                $_course_duration = get_post_meta($course_id,'_course_duration',true);

                                              $online_learning_lms_student_enrolled = tutor_utils()->count_enrolled_users_by_course();

                                              $hours = '0h';$minutes = '0min';
                                              if ($_course_duration != '') {
                                                $hours = $_course_duration['hours'] . 'h';
                                                $minutes = $_course_duration['minutes'] . 'min';
                                              }

                                            ?>
                                                <div class="swiper-slide main-carousel-item">                                 
                                                    <div class="theme-article-post">
                                                        <div class="main-carousel-caption">
                                                            <div class="service-content">
                                                                <div class="entry-thumbnail">
                                                                    <div class="data-bg data-bg-large featured-image" data-background="<?php echo esc_url($online_learning_lms_featured_image); ?>">
                                                                        <a href="<?php the_permalink(); ?>" class="theme-image-responsive" tabindex="0"></a>
                                                                    </div>
                                                                </div>
                                                                <header class="entry-header">
                                                                    <?php if ( function_exists('tutor_utils') ) {
                                                                     /* ============ Review Rating ============ */
                                                                        if ( tutor_utils()->get_option( 'enable_course_review', true, true ) ) {
                                                                            $rating = tutor_utils()->get_course_rating( $course_id );
                                                                            if ( ! empty( $rating->rating_avg ) ) {
                                                                                ?>
                                                                                <div class="tutor-course-meta-item tutor-course-rating">
                                                                                    <?php tutor_utils()->star_rating_generator( $rating->rating_avg ); ?>
                                                                                    <span class="rating-value">
                                                                                        <?php echo number_format( $rating->rating_avg, 1 ); ?>/5.0
                                                                                    </span>
                                                                                </div>
                                                                                <?php
                                                                            }
                                                                        }
                                                                    }?>
                                                                    <!-- Post Title -->
                                                                    <h2 class="entry-title">
                                                                        <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
                                                                    </h2>
                                                                    <div class="courses-meta">
                                                                        <div class="class-count">
                                                                            <div class="tutor-course-meta-item tutor-course-enrolled">
                                                                                    <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 448 512"><!--!Font Awesome Free v5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M224 256c70.7 0 128-57.3 128-128S294.7 0 224 0 96 57.3 96 128s57.3 128 128 128zm89.6 32h-16.7c-22.2 10.2-46.9 16-72.9 16s-50.6-5.8-72.9-16h-16.7C60.2 288 0 348.2 0 422.4V464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48v-41.6c0-74.2-60.2-134.4-134.4-134.4z"/></svg><span class="value"><?php echo esc_html($online_learning_lms_student_enrolled);?></span>
                                                                                </div>
                                                                            
                                                                        </div>
                                                                        <div class="class-time">
                                                                            <?php if ( function_exists('tutor_utils') ) {
                                                                                    /* ============ Duration ============ */
                                                                                if ( get_tutor_option( 'enable_course_duration' ) ) {
                                                                                    $duration = get_tutor_course_duration_context( $course_id );
                                                                                    if ( ! empty( $duration ) ) {
                                                                                        $duration_html = str_replace(
                                                                                            ['hours', 'hour', 'minutes', 'minute'],
                                                                                            [
                                                                                                '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">h</span>',
                                                                                                '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">h</span>',
                                                                                                '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">min</span>',
                                                                                                '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">min</span>'
                                                                                            ],
                                                                                            '<span class="tutor-meta-level">' . $duration
                                                                                        );

                                                                                        echo '<div class="tutor-course-meta-item tutor-course-duration"><span class="tutor-icon-clock-line"></span> ' . $duration_html . '</div>';
                                                                                    }
                                                                                }
                                                                            }?>
                                                                        </div>
                                                                    </div>
                                                                    <div class="course-btn">
                                                                        <div class="button-1">
                                                                            <a href="<?php the_permalink(); ?>"><?php echo esc_html('Enroll Now','online-learning-lms'); ?></a>
                                                                        </div>
                                                                        <div class="button-2">
                                                                            <?php if ( function_exists('tutor_utils') ) {
                                                                                /* ============ Difficulty Level ============ */
                                                                                if ( tutor_utils()->get_option( 'enable_course_level', true, true ) ) {
                                                                                    $course_level = get_tutor_course_level( $course_id );
                                                                                    if ( ! empty( $course_level ) ) {
                                                                                        ?>
                                                                                        <div class="tutor-course-meta-item tutor-course-level">
                                                                                            <span class="value"><?php echo esc_html( $course_level ); ?></span>
                                                                                        </div>
                                                                                        <?php
                                                                                    }
                                                                                }
                                                                            }
                                                                            ?>
                                                                        </div>
                                                                    </div>
                                                                        

                                                                </header>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php $s++; endwhile; ?>
                                        </div>
                                            <div class="swiper-pagination"></div>
                                        </div>
                                    </div>
                                <?php
                                wp_reset_postdata();
                                endif; ?>
                        </div>
                    </div>
                </div>
            <?php }
        }
    }

endif;

if (!function_exists('online_learning_lms_post_format_icon')):

    // Post Format Icon.
    function online_learning_lms_post_format_icon() {

        $online_learning_lms_format = get_post_format(get_the_ID()) ?: 'standard';
        $online_learning_lms_icon = '';
        $online_learning_lms_title = '';
        if( $online_learning_lms_format == 'video' ){
            $online_learning_lms_icon = online_learning_lms_get_theme_svg( 'video' );
            $online_learning_lms_title = esc_html__('Video','online-learning-lms');
        }elseif( $online_learning_lms_format == 'audio' ){
            $online_learning_lms_icon = online_learning_lms_get_theme_svg( 'audio' );
            $online_learning_lms_title = esc_html__('Audio','online-learning-lms');
        }elseif( $online_learning_lms_format == 'gallery' ){
            $online_learning_lms_icon = online_learning_lms_get_theme_svg( 'gallery' );
            $online_learning_lms_title = esc_html__('Gallery','online-learning-lms');
        }elseif( $online_learning_lms_format == 'quote' ){
            $online_learning_lms_icon = online_learning_lms_get_theme_svg( 'quote' );
            $online_learning_lms_title = esc_html__('Quote','online-learning-lms');
        }elseif( $online_learning_lms_format == 'image' ){
            $online_learning_lms_icon = online_learning_lms_get_theme_svg( 'image' );
            $online_learning_lms_title = esc_html__('Image','online-learning-lms');
        } elseif( $online_learning_lms_format == 'link' ){
            $online_learning_lms_icon = online_learning_lms_get_theme_svg( 'link' );
            $online_learning_lms_title = esc_html__('Link','online-learning-lms');
        } elseif( $online_learning_lms_format == 'status' ){
            $online_learning_lms_icon = online_learning_lms_get_theme_svg( 'status' );
            $online_learning_lms_title = esc_html__('Status','online-learning-lms');
        } elseif( $online_learning_lms_format == 'aside' ){
            $online_learning_lms_icon = online_learning_lms_get_theme_svg( 'aside' );
            $online_learning_lms_title = esc_html__('Aside','online-learning-lms');
        } elseif( $online_learning_lms_format == 'chat' ){
            $online_learning_lms_icon = online_learning_lms_get_theme_svg( 'chat' );
            $online_learning_lms_title = esc_html__('Chat','online-learning-lms');
        }
        
        if (!empty($online_learning_lms_icon)) { ?>
            <div class="theme-post-format">
                <span class="post-format-icom"><?php echo online_learning_lms_svg_escape($online_learning_lms_icon); ?></span>
                <?php if( $online_learning_lms_title ){ echo '<span class="post-format-label">'.esc_html( $online_learning_lms_title ).'</span>'; } ?>
            </div>
        <?php }
    }

endif;

if ( ! function_exists( 'online_learning_lms_svg_escape' ) ):

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

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

        return $online_learning_lms_svg;

    }

endif;

if( !function_exists( 'online_learning_lms_sanitize_sidebar_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function online_learning_lms_sanitize_sidebar_option_meta( $online_learning_lms_input ){

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

            return $online_learning_lms_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'online_learning_lms_sanitize_pagination_meta' ) ) :

    // Sidebar Option Sanitize.
    function online_learning_lms_sanitize_pagination_meta( $online_learning_lms_input ){

        $online_learning_lms_metabox_options = array( 'Center','Right','Left');
        if( in_array( $online_learning_lms_input,$online_learning_lms_metabox_options ) ){

            return $online_learning_lms_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'online_learning_lms_sanitize_menu_transform' ) ) :

    // Sidebar Option Sanitize.
    function online_learning_lms_sanitize_menu_transform( $online_learning_lms_input ){

        $online_learning_lms_metabox_options = array( 'capitalize','uppercase','lowercase');
        if( in_array( $online_learning_lms_input,$online_learning_lms_metabox_options ) ){

            return $online_learning_lms_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'online_learning_lms_sanitize_page_content_alignment' ) ) :

    // Sidebar Option Sanitize.
    function online_learning_lms_sanitize_page_content_alignment( $online_learning_lms_input ){

        $online_learning_lms_metabox_options = array( 'left','center','right');
        if( in_array( $online_learning_lms_input,$online_learning_lms_metabox_options ) ){

            return $online_learning_lms_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'online_learning_lms_sanitize_copyright_alignment_meta' ) ) :

    // Sidebar Option Sanitize.
    function online_learning_lms_sanitize_copyright_alignment_meta( $online_learning_lms_input ){

        $online_learning_lms_metabox_options = array( 'Default','Reverse','Center');
        if( in_array( $online_learning_lms_input,$online_learning_lms_metabox_options ) ){

            return $online_learning_lms_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'online_learning_lms_sanitize_footer_widget_title_alignment' ) ) :

    // Footer Option Sanitize.
    function online_learning_lms_sanitize_footer_widget_title_alignment( $online_learning_lms_input ){

        $online_learning_lms_metabox_options = array( 'left','center','right');
        if( in_array( $online_learning_lms_input,$online_learning_lms_metabox_options ) ){

            return $online_learning_lms_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'online_learning_lms_sanitize_pagination_type' ) ) :

    /**
     * Sanitize the pagination type setting.
     *
     * @param string $online_learning_lms_input The input value from the Customizer.
     * @return string The sanitized value.
     */
    function online_learning_lms_sanitize_pagination_type( $online_learning_lms_input ) {
        // Define valid options for the pagination type.
        $online_learning_lms_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( $online_learning_lms_input, $online_learning_lms_valid_options, true ) ) {
            return $online_learning_lms_input;
        } else {
            // Return 'numeric' as the fallback if the input is invalid.
            return 'numeric';
        }
    }

endif;


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

/**
 * Sidebar Layout Function
 */
function online_learning_lms_get_final_sidebar_layout() {
	$online_learning_lms_defaults       = online_learning_lms_get_default_theme_options();
	$online_learning_lms_global_layout  = get_theme_mod('online_learning_lms_global_sidebar_layout', $online_learning_lms_defaults['online_learning_lms_global_sidebar_layout']);
	$online_learning_lms_page_layout    = get_theme_mod('online_learning_lms_page_sidebar_layout', $online_learning_lms_global_layout);
	$online_learning_lms_post_layout    = get_theme_mod('online_learning_lms_post_sidebar_layout', $online_learning_lms_global_layout);
	$online_learning_lms_meta_layout    = get_post_meta(get_the_ID(), 'online_learning_lms_post_sidebar_option', true);

	if (!empty($online_learning_lms_meta_layout) && $online_learning_lms_meta_layout !== 'default') {
		return $online_learning_lms_meta_layout;
	}
	if (is_page() || (function_exists('is_shop') && is_shop())) {
		return $online_learning_lms_page_layout;
	}
	if (is_single()) {
		return $online_learning_lms_post_layout;
	}
	return $online_learning_lms_global_layout;
}