<?php 

$post_id = edumodo_get_id();
global $post; $post_id = $post->ID;
$course_id = $post_id;
$user_id   = get_current_user_id();
$current_id = $post->ID;

$enable_video = get_post_meta( $post->ID, '_learndash_course_grid_enable_video_preview', true );
$embed_code   = get_post_meta( $post->ID, '_learndash_course_grid_video_embed_code', true );
$button_text  = get_post_meta( $post->ID, '_learndash_course_grid_custom_button_text', true );

                            // Retrive oembed HTML if URL provided
if ( preg_match( '/^http/', $embed_code ) ) {
    $embed_code = wp_oembed_get( $embed_code, array( 'height' => 600, 'width' => 400 ) );
}

$button_text = isset( $button_text ) && ! empty( $button_text ) ? $button_text : __( 'See more...', 'edumodo' );

$button_text = apply_filters( 'learndash_course_grid_custom_button_text', $button_text, $post_id );

$options = get_option('sfwd_cpt_options');
$currency = null;

$course_options = get_post_meta($post_id, "_sfwd-courses", true);
$price = $course_options && isset($course_options['sfwd-courses_course_price']) ? $course_options['sfwd-courses_course_price'] : __( 'Free', 'edumodo' );
$short_description = @$course_options['sfwd-courses_course_short_description'];

$has_access   = sfwd_lms_has_access( $course_id, $user_id );
$is_completed = learndash_course_completed( $user_id, $course_id );

if( $price == '' )
    $price .= __( 'Free', 'edumodo' );

if ( is_numeric( $price ) ) {
    $price =  learndash_30_get_currency_symbol().' '.$price ;
}

$class       = '';
$ribbon_text = '';

if ( $has_access && ! $is_completed ) {
    $class = 'ld_course_grid_price ribbon-enrolled';
    $ribbon_text = __( 'Enrolled', 'edumodo' );
} elseif ( $has_access && $is_completed ) {
    $class = 'ld_course_grid_price';
    $ribbon_text = __( 'Completed', 'edumodo' );
} else {
     $class = ! empty( $course_options['sfwd-courses_course_price'] ) ? 'ld_course_grid_price price_' . learndash_30_get_currency_symbol() : 'ld_course_grid_price free';
        $ribbon_text = $price;
}

$edumodo_learndash_archive_column = edumodo_get_theme_mod('edumodo_archive_ld_course_grid_column', '4');
$edumodo_learndash_archive_course_content = edumodo_get_theme_mod('edumodo_learndash_archive_course_content', 'on');
$edumodo_learndash_archive_course_content_length = edumodo_get_theme_mod('edumodo_learndash_archive_course_content_length', 15);
$edumodo_learndash_archive_course_button_text = edumodo_get_theme_mod('edumodo_learndash_archive_course_button_text', 'See more');

?>
<div class="ld_course_grid col-md-<?php echo $edumodo_learndash_archive_column; ?> col-sm-6">
    <article <?php post_class(); ?>>
        <div class="ld_course_grid_price ribbon-enrolled">
            <?php echo $ribbon_text; ?>
        </div>

        <?php if (has_post_thumbnail()): ?>
        <figure class="post-thumbnail">
            <a href="<?php the_permalink(); ?>">
                <?php the_post_thumbnail();?>
            </a>
        </figure>
        <?php endif ?>

        <div class="caption">
            <a href="<?php the_permalink(); ?>">
                <h3 class="entry-title"><?php the_title(); ?></h3>
            </a>
            <?php if ($edumodo_learndash_archive_course_content == 'on'): ?>
                <p class="entry-content"><?php echo esc_html_e($short_description, 'edumodo'); ?></p>
            <?php endif ?>
            <p class="ld_course_grid_button">
                <a class="btn btn-primary" role="button" href="<?php the_permalink()?>" rel="bookmark">
                    <?php esc_html_e( $edumodo_learndash_archive_course_button_text, 'edumodo' ); ?>
                </a>
            </p>
        </div><!-- .entry-header -->
    </article><!-- #post-## -->
</div>