?> " name='meta_preview_page[<?php echo $unit->ID . '_' . $i; ?> ]' <?php if (isset($preview_page[$unit->ID . '_' . $i]) || isset($preview_unit[$unit->ID])) { echo $preview_page[$unit->ID . '_' . $i] == 'on' || $preview_unit[$unit->ID] == 'on' ? 'checked' : ''; } ?> <?php echo $unit->post_status == 'publish' ? 'enabled' : 'disabled'; ?> /> <span><?php echo $unit_class->get_unit_page_time_estimation($unit->ID, $i); ?> </span> </div> </label> <input type="checkbox" id="page_<?php echo $unit->ID . '_' . $i; ?> " class="hidden_checkbox"/> <ol class="course_structure_elements_ol"> <?php /* foreach ($modules as $mod) { $class_name = $mod->module_type;
/** * Shows the course structure. * * @since 1.0.0 */ function course_structure($atts) { extract(shortcode_atts(array('course_id' => in_the_loop() ? get_the_ID() : '', 'course' => false, 'free_text' => __('Free', 'cp'), 'free_show' => 'true', 'show_title' => 'no', 'show_label' => 'no', 'label_delimeter' => ': ', 'label_tag' => 'h2', 'show_divider' => 'yes', 'label' => __('Course Structure', 'cp'), 'class' => ''), $atts, 'course_structure')); $course_id = (int) $course_id; $free_text = sanitize_text_field($free_text); $free_show = sanitize_text_field($free_show); $free_show = 'true' == $free_show ? true : false; $show_title = sanitize_html_class($show_title); $show_label = sanitize_html_class($show_label); $label_delimeter = sanitize_html_class($label_delimeter); $label_tag = sanitize_html_class($label_tag); $show_divider = sanitize_html_class($show_divider); $label = sanitize_text_field($label); $class = sanitize_html_class($class); // Saves some overhead by not loading the post again if we don't need to. $course = empty($course) ? new Course($course_id) : object_decode($course, 'Course'); $class = sanitize_html_class($class); $label_tag = sanitize_html_class($label_tag); $label_delimeter = sanitize_html_class($label_delimeter); if ($course->details->course_structure_options == 'on') { $content = ''; $student = new Student(get_current_user_id()); $existing_student = $student->has_access_to_course($course_id); $show_unit = $course->details->show_unit_boxes; $preview_unit = $course->details->preview_unit_boxes; $show_page = $course->details->show_page_boxes; $preview_page = $course->details->preview_page_boxes; $current_time = date('Y-m-d', current_time('timestamp', 0)); $course_start_date = $course->details->course_start_date; $enable_links = false; if ($current_time >= $course_start_date) { $enable_links = true; } $units = $course->get_units(); $content .= '<div class="course-structure-block course-structure-block-' . $course_id . '">'; if (!empty($label)) { $content .= '<' . $label_tag . ' class="label">' . $label . $label_delimeter . '</' . $label_tag . '>'; } $content .= 'yes' == $show_title ? '<label>' . $this->details->post_title . '</label>' : ''; if ($units) { ob_start(); ?> <ul class="tree"> <li> <ul> <?php foreach ($units as $unit) { $unit_class = new Unit($unit->ID); $unit_pagination = cp_unit_uses_new_pagination($unit->ID); if ($unit_pagination) { $unit_pages = coursepress_unit_pages($unit->ID, $unit_pagination); } else { $unit_pages = coursepress_unit_pages($unit->ID); } //$unit_pages = $unit_class->get_number_of_unit_pages(); // $modules = Unit_Module::get_modules( $unit->ID ); $unit_permalink = Unit::get_permalink($unit->ID); if (isset($show_unit[$unit->ID]) && $show_unit[$unit->ID] == 'on' && $unit->post_status == 'publish') { ?> <li> <label for="unit_<?php echo $unit->ID; ?> " class="course_structure_unit_label <?php echo $existing_student ? 'single_column' : ''; ?> "> <?php $title = ''; if ($existing_student && $enable_links) { $title = '<a href="' . $unit_permalink . '">' . $unit->post_title . '</a>'; } else { $title = $unit->post_title; } ?> <div class="tree-unit-left"><?php echo $title; ?> </div> <div class="tree-unit-right"> <?php if ($course->details->course_structure_time_display == 'on') { ?> <span><?php echo $unit_class->get_unit_time_estimation($unit->ID); ?> </span> <?php } ?> <?php if (isset($preview_unit[$unit->ID]) && $preview_unit[$unit->ID] == 'on' && $unit_permalink && !$existing_student) { ?> <a href="<?php echo $unit_permalink; ?> ?try" class="preview_option"><?php echo $free_text; ?> </a> <?php } ?> </div> </label> <ul> <?php for ($i = 1; $i <= $unit_pages; $i++) { if (isset($show_page[$unit->ID . '_' . $i]) && $show_page[$unit->ID . '_' . $i] == 'on') { ?> <li class="course_structure_page_li <?php echo $existing_student ? 'single_column' : ''; ?> "> <?php $pages_num = 1; $page_title = $unit_class->get_unit_page_name($i); ?> <label for="page_<?php echo $unit->ID . '_' . $i; ?> "> <?php $title = ''; if ($existing_student && $enable_links) { $p_title = isset($page_title) && $page_title !== '' ? $page_title : __('Untitled Page', 'cp'); $title = '<a href="' . trailingslashit($unit_permalink) . trailingslashit('page') . trailingslashit($i) . '">' . $p_title . '</a>'; } else { $title = isset($page_title) && $page_title !== '' ? $page_title : __('Untitled Page', 'cp'); } ?> <div class="tree-page-left"> <?php echo $title; ?> </div> <div class="tree-page-right"> <?php if ($course->details->course_structure_time_display == 'on') { ?> <span><?php echo $unit_class->get_unit_page_time_estimation($unit->ID, $i); ?> </span> <?php } ?> <?php if (isset($preview_page[$unit->ID . '_' . $i]) && $preview_page[$unit->ID . '_' . $i] == 'on' && $unit_permalink && !$existing_student) { ?> <a href="<?php echo $unit_permalink; ?> page/<?php echo $i; ?> ?try" class="preview_option"><?php echo $free_text; ?> </a> <?php } ?> </div> </label> <?php ?> </li> <?php } } //page visible ?> </ul> </li> <?php } //unit visible } // foreach ?> </ul> </li> </ul> <?php if ($show_divider == 'yes') { ?> <div class="divider"></div> <?php } ?> <?php $content .= trim(ob_get_clean()); } else { } $content .= '</div>'; return $content; } }
/** * Renders the course structure. * * Used in shortcodes on the front end to render the course hierarchy. * * @param string $try_title * @param bool $show_try * @param bool $hide_title * @param bool $echo */ function course_structure_front($try_title = '', $show_try = true, $hide_title = false, $echo = true) { $show_unit = $this->details->show_unit_boxes; $preview_unit = $this->details->preview_unit_boxes; $show_page = $this->details->show_page_boxes; $preview_page = $this->details->preview_page_boxes; $units = $this->get_units(); $content = ''; if (!$echo) { ob_start(); } echo $hide_title ? '' : '<label>' . $this->details->post_title . '</label>'; ?> <ul class="tree"> <li> <ul> <?php foreach ($units as $unit) { $unit_class = new Unit($unit->ID); $unit_pages = $unit_class->get_number_of_unit_pages(); // $modules = Unit_Module::get_modules( $unit->ID ); if (isset($show_unit[$unit->ID]) && $show_unit[$unit->ID] == 'on' && $unit->post_status == 'publish') { ?> <li> <label for="unit_<?php echo $unit->ID; ?> " class="course_structure_unit_label"> <div class="tree-unit-left"><?php echo $unit->post_title; ?> </div> <div class="tree-unit-right"> <?php if ($this->details->course_structure_time_display == 'on') { ?> <span><?php echo $unit_class->get_unit_time_estimation($unit->ID); ?> </span> <?php } ?> <?php if (isset($preview_unit[$unit->ID]) && $preview_unit[$unit->ID] == 'on') { ?> <a href="<?php echo Unit::get_permalink($unit->ID); ?> ?try" class="preview_option"><?php if ($try_title == '') { _e('Try Now', 'cp'); } else { echo $try_title; } ?> </a> <?php } ?> </div> </label> <ul> <?php for ($i = 1; $i <= $unit_pages; $i++) { if (isset($show_page[$unit->ID . '_' . $i]) && $show_page[$unit->ID . '_' . $i] == 'on') { ?> <li class="course_structure_page_li"> <?php $pages_num = 1; $page_title = $unit_class->get_unit_page_name($i); ?> <label for="page_<?php echo $unit->ID . '_' . $i; ?> "> <div class="tree-page-left"> <?php echo isset($page_title) && $page_title !== '' ? $page_title : __('Untitled Page', 'cp'); ?> </div> <div class="tree-page-right"> <?php if ($this->details->course_structure_time_display == 'on') { ?> <span><?php echo $unit_class->get_unit_page_time_estimation($unit->ID, $i); ?> </span> <?php } ?> <?php if (isset($preview_page[$unit->ID . '_' . $i]) && $preview_page[$unit->ID . '_' . $i] == 'on') { ?> <a href="<?php echo Unit::get_permalink($unit->ID); ?> page/<?php echo $i; ?> ?try" class="preview_option"><?php if ($try_title == '') { _e('Try Now', 'cp'); } else { echo $try_title; } ?> </a> <?php } ?> </div> </label> <?php ?> </li> <?php } } //page visible ?> </ul> </li> <?php } //unit visible if (!$echo) { trim(ob_get_clean()); } } ?> </ul> <?php }