/** * load_user_courses_content generates HTML for user's active & completed courses * @since 1.4.0 * @param object $user Queried user object * @param boolean $manage Whether the user has permission to manage the courses * @return string HTML displayng course data */ public function load_user_courses_content($user = false, $manage = false) { global $woothemes_sensei, $post, $wp_query, $course, $my_courses_page, $my_courses_section; // Build Output HTML $complete_html = $active_html = ''; if ($user) { $my_courses_page = true; // Allow action to be run before My Courses content has loaded do_action('sensei_before_my_courses', $user->ID); // Logic for Active and Completed Courses $per_page = 20; if (isset($woothemes_sensei->settings->settings['my_course_amount']) && 0 < absint($woothemes_sensei->settings->settings['my_course_amount'])) { $per_page = absint($woothemes_sensei->settings->settings['my_course_amount']); } $course_statuses = WooThemes_Sensei_Utils::sensei_check_for_activity(array('user_id' => $user->ID, 'type' => 'sensei_course_status'), true); // User may only be on 1 Course if (!is_array($course_statuses)) { $course_statuses = array($course_statuses); } $completed_ids = $active_ids = array(); foreach ($course_statuses as $course_status) { if (WooThemes_Sensei_Utils::user_completed_course($course_status, $user->ID)) { $completed_ids[] = $course_status->comment_post_ID; } else { $active_ids[] = $course_status->comment_post_ID; } } $active_count = $completed_count = 0; $active_courses = array(); if (0 < intval(count($active_ids))) { $my_courses_section = 'active'; $active_courses = $woothemes_sensei->post_types->course->course_query($per_page, 'usercourses', $active_ids); $active_count = count($active_ids); } // End If Statement $completed_courses = array(); if (0 < intval(count($completed_ids))) { $my_courses_section = 'completed'; $completed_courses = $woothemes_sensei->post_types->course->course_query($per_page, 'usercourses', $completed_ids); $completed_count = count($completed_ids); } // End If Statement $lesson_count = 1; $active_page = 1; if (isset($_GET['active_page']) && 0 < intval($_GET['active_page'])) { $active_page = $_GET['active_page']; } $completed_page = 1; if (isset($_GET['completed_page']) && 0 < intval($_GET['completed_page'])) { $completed_page = $_GET['completed_page']; } foreach ($active_courses as $course_item) { $course_lessons = $woothemes_sensei->post_types->course->course_lessons($course_item->ID); $lessons_completed = 0; foreach ($course_lessons as $lesson) { if (WooThemes_Sensei_Utils::user_completed_lesson($lesson->ID, $user->ID)) { ++$lessons_completed; } } // Get Course Categories $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', ''); $active_html .= '<article class="' . esc_attr(join(' ', get_post_class(array('course', 'post'), $course_item->ID))) . '">'; // Image $active_html .= $woothemes_sensei->post_types->course->course_image(absint($course_item->ID)); // Title $active_html .= '<header>'; $active_html .= '<h2><a href="' . esc_url(get_permalink(absint($course_item->ID))) . '" title="' . esc_attr($course_item->post_title) . '">' . esc_html($course_item->post_title) . '</a></h2>'; $active_html .= '</header>'; $active_html .= '<section class="entry">'; $active_html .= '<p class="sensei-course-meta">'; // Author $user_info = get_userdata(absint($course_item->post_author)); if (isset($woothemes_sensei->settings->settings['course_author']) && $woothemes_sensei->settings->settings['course_author']) { $active_html .= '<span class="course-author">' . __('by ', 'woothemes-sensei') . '<a href="' . esc_url(get_author_posts_url(absint($course_item->post_author))) . '" title="' . esc_attr($user_info->display_name) . '">' . esc_html($user_info->display_name) . '</a></span>'; } // End If Statement // Lesson count for this author $lesson_count = $woothemes_sensei->post_types->course->course_lesson_count(absint($course_item->ID)); // Handle Division by Zero if (0 == $lesson_count) { $lesson_count = 1; } // End If Statement $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . apply_filters('sensei_lessons_text', __('Lessons', 'woothemes-sensei')) . '</span>'; // Course Categories if ('' != $category_output) { $active_html .= '<span class="course-category">' . sprintf(__('in %s', 'woothemes-sensei'), $category_output) . '</span>'; } // End If Statement $active_html .= '<span class="course-lesson-progress">' . sprintf(__('%1$d of %2$d lessons completed', 'woothemes-sensei'), $lessons_completed, $lesson_count) . '</span>'; $active_html .= '</p>'; $active_html .= '<p class="course-excerpt">' . sensei_get_excerpt($course_item) . '</p>'; $progress_percentage = abs(round(doubleval($lessons_completed) * 100 / $lesson_count, 0)); $active_html .= $this->get_progress_meter($progress_percentage); $active_html .= '</section>'; if (is_user_logged_in()) { $active_html .= '<section class="entry-actions">'; $active_html .= '<form method="POST" action="' . esc_url(remove_query_arg(array('active_page', 'completed_page'))) . '">'; $active_html .= '<input type="hidden" name="' . esc_attr('woothemes_sensei_complete_course_noonce') . '" id="' . esc_attr('woothemes_sensei_complete_course_noonce') . '" value="' . esc_attr(wp_create_nonce('woothemes_sensei_complete_course_noonce')) . '" />'; $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr(absint($course_item->ID)) . '" />'; if (0 < absint(count($course_lessons)) && $woothemes_sensei->settings->settings['course_completion'] == 'complete') { $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' . apply_filters('sensei_mark_as_complete_text', __('Mark as Complete', 'woothemes-sensei')) . '"/></span>'; } // End If Statement $course_purchased = false; if (WooThemes_Sensei_Utils::sensei_is_woocommerce_activated()) { // Get the product ID $wc_post_id = get_post_meta(absint($course_item->ID), '_course_woocommerce_product', true); if (0 < $wc_post_id) { $course_purchased = WooThemes_Sensei_Utils::sensei_customer_bought_product($user->user_email, $user->ID, $wc_post_id); } // End If Statement } // End If Statement if (!$course_purchased) { $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' . apply_filters('sensei_delete_course_text', __('Delete Course', 'woothemes-sensei')) . '"/></span>'; } // End If Statement $active_html .= '</form>'; $active_html .= '</section>'; } $active_html .= '</article>'; } // Active pagination if ($active_count > $per_page) { $current_page = 1; if (isset($_GET['active_page']) && 0 < intval($_GET['active_page'])) { $current_page = $_GET['active_page']; } $active_html .= '<nav class="pagination woo-pagination">'; $total_pages = ceil($active_count / $per_page); $link = ''; if ($current_page > 1) { $prev_link = add_query_arg('active_page', $current_page - 1); $active_html .= '<a class="prev page-numbers" href="' . esc_url($prev_link) . '">' . __('Previous', 'woothemes-sensei') . '</a> '; } for ($i = 1; $i <= $total_pages; $i++) { $link = add_query_arg('active_page', $i); if ($i == $current_page) { $active_html .= '<span class="page-numbers current">' . $i . '</span> '; } else { $active_html .= '<a class="page-numbers" href="' . esc_url($link) . '">' . $i . '</a> '; } } if ($current_page < $total_pages) { $next_link = add_query_arg('active_page', $current_page + 1); $active_html .= '<a class="next page-numbers" href="' . esc_url($next_link) . '">' . __('Next', 'woothemes-sensei') . '</a> '; } $active_html .= '</nav>'; } foreach ($completed_courses as $course_item) { $course = $course_item; // Get Course Categories $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', ''); $complete_html .= '<article class="' . join(' ', get_post_class(array('course', 'post'), $course_item->ID)) . '">'; // Image $complete_html .= $woothemes_sensei->post_types->course->course_image(absint($course_item->ID)); // Title $complete_html .= '<header>'; $complete_html .= '<h2><a href="' . esc_url(get_permalink(absint($course_item->ID))) . '" title="' . esc_attr($course_item->post_title) . '">' . esc_html($course_item->post_title) . '</a></h2>'; $complete_html .= '</header>'; $complete_html .= '<section class="entry">'; $complete_html .= '<p class="sensei-course-meta">'; // Author $user_info = get_userdata(absint($course_item->post_author)); if (isset($woothemes_sensei->settings->settings['course_author']) && $woothemes_sensei->settings->settings['course_author']) { $complete_html .= '<span class="course-author">' . __('by ', 'woothemes-sensei') . '<a href="' . esc_url(get_author_posts_url(absint($course_item->post_author))) . '" title="' . esc_attr($user_info->display_name) . '">' . esc_html($user_info->display_name) . '</a></span>'; } // End If Statement // Lesson count for this author $complete_html .= '<span class="course-lesson-count">' . $woothemes_sensei->post_types->course->course_lesson_count(absint($course_item->ID)) . ' ' . apply_filters('sensei_lessons_text', __('Lessons', 'woothemes-sensei')) . '</span>'; // Course Categories if ('' != $category_output) { $complete_html .= '<span class="course-category">' . sprintf(__('in %s', 'woothemes-sensei'), $category_output) . '</span>'; } // End If Statement $complete_html .= '</p>'; $complete_html .= '<p class="course-excerpt">' . sensei_get_excerpt($course_item) . '</p>'; $complete_html .= $this->get_progress_meter(100); if ($manage) { $has_quizzes = $woothemes_sensei->post_types->course->course_quizzes($course_item->ID, true); // Output only if there is content to display if (has_filter('sensei_results_links') || $has_quizzes) { $complete_html .= '<p class="sensei-results-links">'; $results_link = ''; if ($has_quizzes) { $results_link = '<a class="button view-results" href="' . $woothemes_sensei->course_results->get_permalink($course_item->ID) . '">' . apply_filters('sensei_view_results_text', __('View results', 'woothemes-sensei')) . '</a>'; } $complete_html .= apply_filters('sensei_results_links', $results_link); $complete_html .= '</p>'; } } $complete_html .= '</section>'; $complete_html .= '</article>'; } // Active pagination if ($completed_count > $per_page) { $current_page = 1; if (isset($_GET['completed_page']) && 0 < intval($_GET['completed_page'])) { $current_page = $_GET['completed_page']; } $complete_html .= '<nav class="pagination woo-pagination">'; $total_pages = ceil($completed_count / $per_page); $link = ''; if ($current_page > 1) { $prev_link = add_query_arg('completed_page', $current_page - 1); $complete_html .= '<a class="prev page-numbers" href="' . esc_url($prev_link) . '">' . __('Previous', 'woothemes-sensei') . '</a> '; } for ($i = 1; $i <= $total_pages; $i++) { $link = add_query_arg('completed_page', $i); if ($i == $current_page) { $complete_html .= '<span class="page-numbers current">' . $i . '</span> '; } else { $complete_html .= '<a class="page-numbers" href="' . esc_url($link) . '">' . $i . '</a> '; } } if ($current_page < $total_pages) { $next_link = add_query_arg('completed_page', $current_page + 1); $complete_html .= '<a class="next page-numbers" href="' . esc_url($next_link) . '">' . __('Next', 'woothemes-sensei') . '</a> '; } $complete_html .= '</nav>'; } } // End If Statement if ($manage) { $no_active_message = apply_filters('sensei_no_active_courses_user_text', __('You have no active courses.', 'woothemes-sensei')); $no_complete_message = apply_filters('sensei_no_complete_courses_user_text', __('You have not completed any courses yet.', 'woothemes-sensei')); } else { $no_active_message = apply_filters('sensei_no_active_courses_learner_text', __('This learner has no active courses.', 'woothemes-sensei')); $no_complete_message = apply_filters('sensei_no_complete_courses_learner_text', __('This learner has not completed any courses yet.', 'woothemes-sensei')); } ob_start(); ?> <?php do_action('sensei_before_user_courses'); ?> <?php if ($manage && (!isset($woothemes_sensei->settings->settings['messages_disable']) || !$woothemes_sensei->settings->settings['messages_disable'])) { ?> <p class="my-messages-link-container"><a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?> " title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?> "><?php _e('My Messages', 'woothemes-sensei'); ?> </a></p> <?php } ?> <div id="my-courses"> <ul> <li><a href="#active-courses"><?php echo apply_filters('sensei_active_courses_text', __('Active Courses', 'woothemes-sensei')); ?> </a></li> <li><a href="#completed-courses"><?php echo apply_filters('sensei_completed_courses_text', __('Completed Courses', 'woothemes-sensei')); ?> </a></li> </ul> <?php do_action('sensei_before_active_user_courses'); ?> <?php $course_page_id = intval($woothemes_sensei->settings->settings['course_page']); if (0 < $course_page_id) { $course_page_url = get_permalink($course_page_id); } elseif (0 == $course_page_id) { $course_page_url = get_post_type_archive_link('course'); } ?> <div id="active-courses"> <?php if ('' != $active_html) { echo $active_html; } else { ?> <div class="sensei-message info"><?php echo $no_active_message; ?> <a href="<?php echo $course_page_url; ?> "><?php apply_filters('sensei_start_a_course_text', _e('Start a Course!', 'woothemes-sensei')); ?> </a></div> <?php } // End If Statement ?> </div> <?php do_action('sensei_after_active_user_courses'); ?> <?php do_action('sensei_before_completed_user_courses'); ?> <div id="completed-courses"> <?php if ('' != $complete_html) { echo $complete_html; } else { ?> <div class="sensei-message info"><?php echo $no_complete_message; ?> </div> <?php } // End If Statement ?> </div> <?php do_action('sensei_after_completed_user_courses'); ?> </div> <?php do_action('sensei_after_user_courses'); ?> <?php return ob_get_clean(); }
/** * Only show excerpts for lessons and courses in search results * @param string $content Original content * @return string Modified content */ public function sensei_search_results_excerpt($content) { global $post; if (is_search() && in_array($post->post_type, array('course', 'lesson'))) { $content = '<p class="course-excerpt">' . sensei_get_excerpt($post) . '</p>'; } return $content; }
echo $woothemes_sensei->permissions_message['title']; ?> </h1> </header> <section class="entry fix"> <div class="sensei-message alert"><?php echo $woothemes_sensei->permissions_message['message']; ?> </div> <?php if ('full' == $woothemes_sensei->settings->settings['course_single_content_display']) { the_content(); } else { echo '<p class="course-excerpt">' . sensei_get_excerpt($post) . '</p>'; } ?> </section> <?php course_single_meta(); ?> <?php do_action('sensei_course_single_lessons'); ?> </article><!-- .post --> <?php } else { ?>
<div class="sensei-message alert"><?php echo $woothemes_sensei->permissions_message['message']; ?> </div> <?php } ?> <?php if ($access_permission || is_user_logged_in() && $user_taking_course || $is_preview) { if (apply_filters('sensei_video_position', 'top', $post->ID) == 'top') { do_action('sensei_lesson_video', $post->ID); } the_content(); } else { echo '<p>' . sensei_get_excerpt($post) . '</p>'; } ?> </section> <?php if ($access_permission || is_user_logged_in() && $user_taking_course || $is_preview) { do_action('sensei_lesson_single_meta'); } else { do_action('sensei_lesson_course_signup', $lesson_course_id); } ?> <?php } else { if ($lesson_prerequisite > 0) {
?> <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?> </span> <?php } // End If Statement ?> <?php sensei_simple_course_price($post_id); ?> </p> <p class="course-excerpt"><?php echo sensei_get_excerpt($post); ?> </p> <?php if (0 < $preview_lesson_count && !$is_user_taking_course) { $preview_lessons = sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?> <p class="sensei-free-lessons"><a href="<?php echo get_permalink($post_id); ?> "><?php _e('Preview this course', 'woothemes-sensei'); ?> </a> - <?php echo $preview_lessons; ?>
/** * Handles the output of the lesson excerpt. * * @access public * @return string */ public static function lesson_excerpt($lesson = null) { $html = ''; if (is_a($lesson, 'WP_Post') && 'lesson' == $lesson->post_type) { $html = wpautop(sensei_get_excerpt($lesson)); } return apply_filters('sensei_lesson_excerpt', $html); }