PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 All 140 releases
← All changes | inc/templates/class-lp-template-course.php +249 -359 4.1.7 → 4.4.9 View file →
@@ -1,6 +1,14 @@
1 1 <?php
2 2
3 +use LearnPress\Helpers\Template;
4 +use LearnPress\Models\CourseModel;
5 +use LearnPress\Models\UserItems\UserCourseModel;
6 +use LearnPress\Models\UserModel;
7 +use LearnPress\TemplateHooks\Course\SingleCourseModernLayout;
8 +use LearnPress\TemplateHooks\Course\SingleCourseTemplate;
9 +use LearnPress\TemplateHooks\UserItem\UserCourseTemplate;
10 +
3 11 /**
4 12 * Class LP_Course_Template
5 13 *
6 14 * Groups templates related course and items
@@ -7,9 +15,8 @@
7 15 *
8 16 * @since 3.x.x
9 17 */
10 18 class LP_Template_Course extends LP_Abstract_Template {
11 -
12 19 /**
13 20 * @var LP_Course
14 21 */
15 22 public $course = null;
@@ -19,9 +26,9 @@
19 26 */
20 27 public function __construct() {
21 28 parent::__construct();
22 29
23 - add_action( 'the_post', array( $this, 'get_course' ), 1000 );
30 + add_action( 'the_post', array( $this, 'get_course' ) );
24 31 }
25 32
26 33 public function get_course() {
27 34 // global $post;
@@ -33,8 +40,10 @@
33 40 learn_press_get_template( 'single-course/sidebar/preview' );
34 41 }
35 42
36 43 public function course_buttons() {
44 + global $lp_user;
45 + $lp_user = learn_press_get_current_user();
37 46 learn_press_get_template( 'single-course/buttons' );
38 47 }
39 48
40 49 public function course_graduation() {
@@ -58,12 +67,17 @@
58 67 * Show button retry course
59 68 *
60 69 * @throws Exception
61 70 */
62 - public function button_retry() {
63 - $user = learn_press_get_current_user();
64 - $course = learn_press_get_course();
71 + public function button_retry( $course = null ) {
72 + _deprecated_function( __METHOD__, '4.3.2.4', 'UserCourseTemplate::html_btn_retake' );
73 + return;
65 74
75 + $user = learn_press_get_current_user();
76 + if ( empty( $course ) ) {
77 + $course = learn_press_get_course();
78 + }
79 +
66 80 if ( ! $user || ! $course ) {
67 81 return;
68 82 }
69 83
@@ -92,20 +106,12 @@
92 106 * @param LP_Quiz $item
93 107 */
94 108 public function quiz_meta_questions( $item ) {
95 109 $count = $item->count_questions();
96 - echo '<span class="item-meta count-questions">' . sprintf(
97 - $count ? _n(
98 - '%d question',
99 - '%d questions',
100 - $count,
101 - 'learnpress'
102 - ) : __(
103 - '%d question',
104 - 'learnpress'
105 - ),
106 - $count
107 - ) . '</span>';
110 + printf(
111 + '<span class="item-meta count-questions">%s</span>',
112 + sprintf( _n( '%1$d question', '%1$d questions', $count, 'learnpress' ), $count )
113 + );
108 114 }
109 115
110 116 /**
111 117 * @param LP_Quiz|LP_Lesson $item
@@ -123,9 +129,10 @@
123 129 */
124 130 public function quiz_meta_final( $item ) {
125 131 $course = $item->get_course();
126 132
127 - if ( ! $course || ! $course->is_final_quiz( $item->get_id() ) ) {
133 + if ( ! $course || ! $course->is_final_quiz( $item->get_id() )
134 + || $course->get_evaluation_type() != 'evaluate_final_quiz' ) {
128 135 return;
129 136 }
130 137
131 138 echo '<span class="item-meta final-quiz">' . esc_html__( 'Final', 'learnpress' ) . '</span>';
@@ -142,30 +149,33 @@
142 149 public function courses_top_bar() {
143 150 learn_press_get_template( 'courses-top-bar' );
144 151 }
145 152
153 + /**
154 + * Display price or free of course, not button, it is label.
155 + *
156 + * @return void
157 + * @since 4.0.0
158 + * @version 1.0.3
159 + */
146 160 public function course_pricing() {
147 - $can_show = true;
148 - $course = learn_press_get_course();
149 - $user = learn_press_get_current_user();
150 - $price_html = '';
161 + $course = learn_press_get_course();
162 + $user = learn_press_get_current_user();
151 163
152 - try {
153 - if ( $user && $user->has_enrolled_course( get_the_ID() ) ) {
154 - throw new Exception( 'User has enrolled course' );
164 + $courseModel = CourseModel::find( $course->get_id(), true );
165 + $can_purchase = $courseModel->can_purchase( UserModel::find( $user->get_id(), true ) );
166 + $userCourseModel = UserCourseModel::find( $user->get_id(), $course->get_id(), true );
167 + if ( get_current_user_id() ) {
168 + if ( $userCourseModel ) {
169 + if ( $userCourseModel->has_enrolled() ) {
170 + return;
171 + } elseif ( $can_purchase instanceof WP_Error ) {
172 + return;
173 + }
155 174 }
156 -
157 - $price_html = $course->get_course_price_html();
158 - } catch ( Throwable $e ) {
159 - $can_show = false;
160 175 }
161 176
162 - $can_show = apply_filters( 'learnpress/course/template/price/can-show', $can_show, $user, $course );
163 -
164 - if ( ! $can_show ) {
165 - return;
166 - }
167 -
177 + $price_html = $course->get_course_price_html();
168 178 learn_press_get_template( 'single-course/price', compact( 'course', 'user', 'price_html' ) );
169 179 }
170 180
171 181 /**
@@ -172,51 +182,19 @@
172 182 * Template purchase course button
173 183 *
174 184 * @editor tungnx
175 185 * @modify 4.1.3.1
176 - * @version 4.0.1
177 186 * @throws Exception
187 + * @version 4.0.2
178 188 */
179 - public function course_purchase_button() {
180 - $can_show = true;
181 - $course = learn_press_get_course();
182 - $user = learn_press_get_current_user();
189 + public function course_purchase_button( $course = null ) {
190 + _deprecated_function( __METHOD__, '4.3.2', 'SingleCourseTemplate::html_btn_purchase_course' );
191 + return;
183 192
184 - try {
185 - if ( ! $user || ! $course ) {
186 - throw new Exception( 'User or Course is not exists' );
187 - }
188 -
189 - if ( ! $user->can_purchase_course( $course->get_id() ) ) {
190 - throw new Exception( 'You can not purchase course' );
191 - }
192 - } catch ( Throwable $e ) {
193 - $can_show = false;
194 - }
195 -
196 - $can_show = apply_filters( 'learnpress/course/template/button-purchase/can-show', $can_show, $user, $course );
197 -
198 - if ( ! $can_show ) {
199 - return;
200 - }
201 -
202 - $args_load_tmpl = array(
203 - 'template_name' => 'single-course/buttons/purchase.php',
204 - 'template_path' => '',
205 - 'default_path' => '',
206 - );
207 -
208 - $args_load_tmpl = apply_filters( 'learn-press/tmpl-button-purchase-course', $args_load_tmpl, $course );
209 -
210 - learn_press_get_template(
211 - $args_load_tmpl['template_name'],
212 - array(
213 - 'user' => $user,
214 - 'course' => $course,
215 - ),
216 - $args_load_tmpl['template_path'],
217 - $args_load_tmpl['default_path']
218 - );
193 + $singleCourseTemplate = SingleCourseTemplate::instance();
194 + $course = CourseModel::find( get_the_ID(), true );
195 + $user = UserModel::find( get_current_user_id(), true );
196 + echo $singleCourseTemplate->html_btn_purchase_course( $course, $user );
219 197 }
220 198
221 199 /**
222 200 * Show button enroll course
@@ -223,14 +201,26 @@
223 201 *
224 202 * @editor tungnx
225 203 * @modify 4.1.3.1
226 204 * @throws Exception
227 - * @version 4.0.2
205 + * @version 4.0.3
228 206 */
229 - public function course_enroll_button() {
207 + public function course_enroll_button( $course = null ) {
208 + _deprecated_function( __METHOD__, '4.3.2.4', 'SingleCourseTemplate::html_btn_enroll_course' );
209 + return;
210 +
211 + $singleCourseTemplate = SingleCourseTemplate::instance();
212 + $course = CourseModel::find( get_the_ID(), true );
213 + $user = UserModel::find( get_current_user_id(), true );
214 + echo $singleCourseTemplate->html_btn_enroll_course( $course, $user );
215 + return;
216 +
230 217 $can_show = true;
231 218 $user = learn_press_get_current_user();
232 - $course = learn_press_get_course();
219 + if ( empty( $course ) ) {
220 + $course = learn_press_get_course();
221 + }
222 + $error_code = '';
233 223
234 224 try {
235 225 if ( ! $course || ! $user ) {
236 226 throw new Exception( 'User or Course is not exists' );
@@ -236,22 +226,28 @@
236 226 throw new Exception( 'User or Course is not exists' );
237 227 }
238 228
239 229 // User can not enroll course.
240 - if ( ! $user->can_enroll_course( $course->get_id() ) ) {
241 - throw new Exception( 'You can not enroll course' );
230 + $can_enroll_course = $user->can_enroll_course( $course->get_id(), false );
231 + if ( ! $can_enroll_course->check ) {
232 + $error_code = $can_enroll_course->code;
233 + throw new Exception( $can_enroll_course->message );
242 234 }
243 235
244 236 if ( $user->has_finished_course( $course->get_id() ) ) {
245 - throw new Exception( 'Course is finished' );
246 -
237 + $error_code = 'course_is_finished';
238 + throw new Exception( __( 'Course is finished', 'learnpress' ) );
247 239 }
248 240 } catch ( Throwable $e ) {
241 + if ( ! in_array( $error_code, [ 'course_is_enrolled', 'course_can_retry' ] ) ) {
242 + if ( $course && $course->is_free() ) {
243 + Template::print_message( $e->getMessage(), 'warning' );
244 + }
245 + }
249 246 $can_show = false;
250 247 }
251 248
252 249 $can_show = apply_filters( 'learnpress/course/template/button-enroll/can-show', $can_show, $user, $course );
253 -
254 250 if ( ! $can_show ) {
255 251 return;
256 252 }
257 253
@@ -264,8 +260,11 @@
264 260 }
265 261
266 262 public function course_extra_requirements( $course_id ) {
267 263 $course = LP_Course::get_course( $course_id );
264 + if ( ! $course ) {
265 + return;
266 + }
268 267
269 268 $requirements = apply_filters(
270 269 'learn-press/course-extra-requirements',
271 270 $course->get_extra_info( 'requirements' ),
@@ -287,8 +286,11 @@
287 286 }
288 287
289 288 public function course_extra_key_features( $course_id ) {
290 289 $course = LP_Course::get_course( $course_id );
290 + if ( ! $course ) {
291 + return;
292 + }
291 293
292 294 $key_features = apply_filters(
293 295 'learn-press/course-extra-key-features',
294 296 $course->get_extra_info( 'key_features' ),
@@ -310,8 +312,11 @@
310 312 }
311 313
312 314 public function course_extra_target_audiences( $course_id ) {
313 315 $course = LP_Course::get_course( $course_id );
316 + if ( ! $course ) {
317 + return;
318 + }
314 319
315 320 $target_audiences = apply_filters(
316 321 'learn-press/course-extra-target-audiences',
317 322 $course->get_extra_info( 'target_audiences' ),
@@ -332,158 +337,69 @@
332 337 );
333 338 }
334 339
335 340 /**
336 - * Show button retake course
337 - *
338 - * @throws Exception
339 - * @deprecated 4.0.0
340 - */
341 - public function course_retake_button() {
342 - _deprecated_function( __FUNCTION__, '4.0.0', 'button_retry' );
343 - $user = learn_press_get_current_user();
344 -
345 - if ( ! $user ) {
346 - return;
347 - }
348 -
349 - if ( ! isset( $course ) ) {
350 - $course = learn_press_get_course();
351 - }
352 -
353 - if ( ! $user->has_enrolled_course( $course->get_id() ) && $course->get_external_link() ) {
354 - return;
355 - }
356 -
357 - // If user has not finished course
358 - if ( ! $user->has_finished_course( $course->get_id() ) ) {
359 - return;
360 - }
361 - learn_press_get_template( 'single-course/buttons/retake.php' );
362 - }
363 -
364 - /**
365 341 * Show template "continue" button con single course
366 342 *
367 343 * @throws Exception
368 - * @editor tungnx
369 344 * @modify 4.1.3.1
370 - * @version 4.0.2
345 + * @version 4.0.4
371 346 * @since 4.0.0
372 347 */
373 - public function course_continue_button() {
374 - $can_show = true;
375 - $user = learn_press_get_current_user();
376 - $course = learn_press_get_course();
348 + public static function course_continue_button( $args = [] ) {
349 + _deprecated_function( __METHOD__, '4.3.2.4', 'UserCourseTemplate::html_btn_continue' );
350 + return;
377 351
352 + $course_id_param = $args['course-id'] ?? 0;
353 + $course_id = ! empty( $course_id_param ) ? $course_id_param : get_the_ID();
354 + $courseModel = CourseModel::find( $course_id, true );
355 + $user_id = get_current_user_id();
356 +
378 357 try {
379 - if ( ! $user || ! $course ) {
358 + if ( ! $user_id || ! $courseModel ) {
380 359 throw new Exception( 'User or Course not exists!' );
381 360 }
382 361
383 - if ( ! $user->has_enrolled_course( $course->get_id() ) ) {
384 - throw new Exception( 'User has not enrolled course' );
362 + $userCourseModel = UserCourseModel::find( $user_id, $courseModel->get_id(), true );
363 + if ( ! $userCourseModel || ! $userCourseModel->has_enrolled() ) {
364 + throw new Exception( 'User not enrolled course' );
385 365 }
386 366
387 - if ( $user->has_finished_course( $course->get_id() ) ) {
367 + if ( $userCourseModel->has_finished() ) {
388 368 throw new Exception( 'User has finished course' );
389 369 }
390 370
391 371 // Course has no items
392 - if ( empty( $course->count_items() ) ) {
372 + if ( empty( $courseModel->get_total_items() ) ) {
393 373 throw new Exception( 'Course no any item' );
394 374 }
395 375
396 376 // Do not display continue button if course is block duration
397 - if ( $user->can_view_content_course( $course->get_id() )->key === LP_BLOCK_COURSE_DURATION_EXPIRE ) {
377 + if ( $userCourseModel->timestamp_remaining_duration() === 0 ) {
398 378 throw new Exception( 'Course is blocked' );
399 379 }
380 +
381 + $section = [
382 + 'start' => '<div>',
383 + 'link' => UserCourseTemplate::instance()->html_btn_continue( $userCourseModel ),
384 + 'end' => '</div>',
385 + ];
386 +
387 + echo Template::combine_components( $section );
400 388 } catch ( Throwable $e ) {
401 - $can_show = false;
402 - }
403 389
404 - $can_show = apply_filters( 'learnpress/course/template/button-continue/can-show', $can_show, $user, $course );
405 -
406 - if ( ! $can_show ) {
407 - return;
408 390 }
409 -
410 - $args = array(
411 - 'user' => $user,
412 - 'course' => $course,
413 - );
414 -
415 - learn_press_get_template( 'single-course/buttons/continue.php', $args );
416 391 }
417 392
418 - /**
419 - * Check can show button finish course
420 - *
421 - * @param LP_Course|false $course
422 - * @param LP_User|LP_User_Guest $user
423 - *
424 - * @return array
425 - * @editor tungnx
426 - * @modify 4.1.4.1 - comment - not use - replace on function can_show_finish_course_btn on LP_User
427 - */
428 - /*
429 - public function can_show_finish_course_btn( $course, $user ): array {
430 - $return = [
431 - 'flag' => false,
432 - 'message' => '',
433 - ];
393 + public function course_finish_button( $course = null ) {
394 + _deprecated_function( __METHOD__, '4.3.2.4', 'UserCourseTemplate::html_btn_finish' );
395 + return;
434 396
435 - try {
436 - if ( ! $course || ! $user ) {
437 - throw new Exception( esc_html__( 'Error: No Course or User available.', 'learnpress' ) );
438 - }
439 -
440 - $course_id = $course->get_id();
441 -
442 - if ( ! $user->has_enrolled_course( $course_id ) ) {
443 - throw new Exception( esc_html__( 'Course is not enroll.', 'learnpress' ) );
444 - }
445 -
446 - $course_data = $user->get_course_data( $course_id );
447 -
448 - if ( ! $user->is_course_in_progress( $course_id ) ) {
449 - throw new Exception( esc_html__( 'Error: Course is not in-progress.', 'learnpress' ) );
450 - }
451 -
452 - // Get option Allow show finish button when the student has completed all items but has not passed the course assessment.
453 - $has_finish = get_post_meta( $course_id, '_lp_has_finish', true ) ?? 'yes';
454 - $is_passed = $user->has_reached_passing_condition( $course_id );
455 -
456 - if ( ! $is_passed && $has_finish === 'no' ) {
457 - throw new Exception( esc_html__( 'Error: Course is not has finish.', 'learnpress' ) );
458 - }
459 -
460 - if ( $course_data ) {
461 - $course_result = $course_data->get_result();
462 -
463 - $is_all_completed = $user->is_completed_all_items( $course_id );
464 -
465 - if ( ! $is_all_completed && $has_finish === 'yes' && ! $course_result['pass'] ) {
466 - throw new Exception( esc_html__( 'Error: Cannot finish course.', 'learnpress' ) );
467 - }
468 - }
469 -
470 - if ( ! apply_filters( 'lp_can_finish_course', true ) ) {
471 - throw new Exception( esc_html__( 'Error: Filter disable finish course.', 'learnpress' ) );
472 - }
473 -
474 - $return['flag'] = true;
475 - } catch ( Exception $e ) {
476 - $return['message'] = $e->getMessage();
397 + $user = learn_press_get_current_user();
398 + if ( empty( $course ) ) {
399 + $course = learn_press_get_course();
477 400 }
478 401
479 - return $return;
480 - }*/
481 -
482 - public function course_finish_button() {
483 - $user = learn_press_get_current_user();
484 - $course = learn_press_get_course();
485 -
486 402 if ( ! $course ) {
487 403 return;
488 404 }
489 405
@@ -513,12 +429,18 @@
513 429 * @throws Exception
514 430 * @editor tungnx
515 431 * @modify 4.1.3
516 432 */
517 - public function course_external_button() {
518 - $course = learn_press_get_course();
519 - $user = learn_press_get_current_user();
433 + public function course_external_button( $course = null ) {
434 + _deprecated_function( __METHOD__, '4.3.2.4', 'SingleCourseTemplate::html_btn_external' );
435 + return;
520 436
437 + if ( empty( $course ) ) {
438 + $course = learn_press_get_course();
439 + }
440 +
441 + $user = learn_press_get_current_user();
442 +
521 443 if ( ! $course ) {
522 444 return;
523 445 }
524 446
@@ -530,10 +452,11 @@
530 452 $user = learn_press_get_current_user();
531 453
532 454 if ( $user && ! $user->has_enrolled_or_finished( $course->get_id() ) ) {
533 455 // Remove all another buttons
534 - learn_press_remove_course_buttons();
456 + // learn_press_remove_course_buttons();
535 457 learn_press_get_template( 'single-course/buttons/external-link.php' );
458 +
536 459 // Add back other buttons for other courses
537 460 add_action( 'learn-press/after-course-buttons', 'learn_press_add_course_buttons' );
538 461 }
539 462 }
@@ -550,9 +473,9 @@
550 473 $total_items = 0;
551 474 $completed_items = 0;
552 475 $course_data = $user->get_course_data( $course->get_id() );
553 476
554 - if ( $course_data && ! $course->is_no_required_enroll() ) {
477 + if ( $course_data && ! empty( $course_data->get_user_id() ) && ! $course->is_no_required_enroll() ) {
555 478 $course_results = $course_data->get_result();
556 479 $completed_items = $course_results['completed_items'];
557 480 $total_items = $course_results['count_items'];
558 481 $percentage = $course_results['count_items'] ? absint( $course_results['completed_items'] / $course_results['count_items'] * 100 ) : 0;
@@ -614,34 +537,62 @@
614 537 )
615 538 );
616 539 }
617 540
541 + /**
542 + * Display course curriculum.
543 + *
544 + * @since 4.1.6
545 + * @since 4.2.5.5 remove code load old template user for course curriculum load page instead of via AJAX.
546 + * @version 1.0.2
547 + * @depreacted 4.2.8.7.1
548 + */
618 549 public function course_curriculum() {
619 - if ( ! learn_press_override_templates() || ( learn_press_override_templates() && has_filter( 'lp/template-course/course_curriculum/skeleton' ) ) ) {
620 - $course_item = LP_Global::course_item();
550 + /**
551 + * @var CourseModel $lpCourseModel
552 + */
553 + global $lpCourseModel;
554 + $courseModel = CourseModel::find( get_the_ID(), true );
555 + if ( $lpCourseModel instanceof CourseModel ) {
556 + $courseModel = $lpCourseModel;
557 + }
621 558
622 - if ( $course_item ) { // Check if current item is viewable
623 - $item_id = $course_item->get_id();
624 - $section_id = LP_Section_DB::getInstance()->get_section_id_by_item_id( absint( $item_id ) );
559 + $course_item = LP_Global::course_item();
560 + $userModel = UserModel::find( get_current_user_id(), true );
561 +
562 + $singleCourseTemplate = SingleCourseTemplate::instance();
563 + echo $singleCourseTemplate->html_curriculum( $courseModel, $userModel );
564 + }
565 +
566 + /**
567 + * Display course curriculum.
568 + *
569 + * @since 4.1.6
570 + * @since 4.2.5.5 remove code load old template user for course curriculum load page instead of via AJAX.
571 + * @version 1.0.2
572 + */
573 + public function course_curriculum_bk() {
574 + /**
575 + * @var CourseModel $lpCourseModel
576 + */
577 + global $lpCourseModel;
578 + $course_item = LP_Global::course_item();
579 +
580 + if ( $course_item ) { // Check if current item is viewable
581 + $course_id = 0;
582 + if ( $lpCourseModel ) {
583 + $course_id = $lpCourseModel->get_id();
625 584 }
626 - ?>
627 - <div class="learnpress-course-curriculum" data-section="<?php echo esc_attr( $section_id ?? '' ); ?>" data-id="<?php echo esc_attr( $item_id ?? '' ); ?>">
628 - <ul class="lp-skeleton-animation">
629 - <li style="width: 100%; height: 50px"></li>
630 - <li style="width: 100%; height: 20px"></li>
631 - <li style="width: 100%; height: 20px"></li>
632 - <li style="width: 100%; height: 20px"></li>
633 585
634 - <li style="width: 100%; height: 50px; margin-top: 40px;"></li>
635 - <li style="width: 100%; height: 20px"></li>
636 - <li style="width: 100%; height: 20px"></li>
637 - <li style="width: 100%; height: 20px"></li>
638 - </ul>
639 - </div>
640 - <?php
641 - } else {
642 - learn_press_get_template( 'single-course/tabs/curriculum' );
586 + $item_id = (int) $course_item->get_id();
587 + $section_id = LP_Section_DB::getInstance()->get_section_id_by_item_id( $item_id, $course_id );
643 588 }
589 + ?>
590 + <div class="learnpress-course-curriculum" data-section="<?php echo esc_attr( $section_id ?? '' ); ?>"
591 + data-id="<?php echo esc_attr( $item_id ?? '' ); ?>">
592 + <?php lp_skeleton_animation_html( 10 ); ?>
593 + </div>
594 + <?php
644 595 }
645 596
646 597 /**
647 598 * Get template content item's course
@@ -681,15 +632,13 @@
681 632 }
682 633
683 634 public function course_item_content() {
684 635 $course = learn_press_get_course();
685 - $item = LP_Global::course_item();
636 + if ( ! $course ) {
637 + return;
638 + }
686 639
687 - // if ( $item->is_blocked() ) {
688 - // learn_press_get_template( 'global/block-content.php' );
689 - //
690 - // return;
691 - // }
640 + $item = LP_Global::course_item();
692 641
693 642 /**
694 643 * Fix only for WPBakery load style inline
695 644 * custom CSS is provided, load inline style.
@@ -700,22 +649,15 @@
700 649 $shortcodes_custom_css = get_post_meta( $item->get_id(), '_wpb_shortcodes_custom_css', true );
701 650
702 651 if ( ! empty( $shortcodes_custom_css ) ) {
703 652 $shortcodes_custom_css = strip_tags( $shortcodes_custom_css );
704 - echo '<style type="text/css" data-type="vc_shortcodes-custom-css">';
653 + echo '<style data-type="vc_shortcodes-custom-css">';
705 654 echo wp_kses_post( $shortcodes_custom_css );
706 655 echo '</style>';
707 656 }
708 657 // End
709 658
710 - // Get timestamp remaining duration of course
711 - /*$course_item = $item->get_course();
712 - if ( ! $course_item ) {
713 - return;
714 - }*/
715 -
716 659 $timestamp_remaining = $course->timestamp_remaining_duration();
717 -
718 660 if ( $timestamp_remaining > 0 ) {
719 661 echo '<input type="hidden" name="lp-course-timestamp-remaining" value="' . esc_attr( $timestamp_remaining ) . '">';
720 662 }
721 663 // End
@@ -728,36 +670,8 @@
728 670 echo esc_html( sprintf( 'File %s not exists', $item_template_name ) );
729 671 }
730 672 }
731 673
732 - /**
733 - * @editor tungnx
734 - * @reason comment - not use
735 - * @since 4.1.2
736 - */
737 - /*
738 - public function remaining_time() {
739 -
740 - if ( ! $course = learn_press_get_course() ) {
741 - return;
742 - }
743 -
744 - if ( ! $user = learn_press_get_current_user() ) {
745 - return;
746 - }
747 -
748 - if ( false === ( $remain = $user->get_course_remaining_time( $course->get_id() ) ) ) {
749 -
750 - return;
751 - }
752 -
753 - if ( $user->has_finished_course( $course->get_id() ) ) {
754 - return;
755 - }
756 -
757 - learn_press_get_template( 'single-course/remaining-time.php', array( 'remaining_time' => $remain ) );
758 - }*/
759 -
760 674 public function item_lesson_title() {
761 675 $item = LP_Global::course_item();
762 676 $format = $item->get_format();
763 677 $format_template = learn_press_locate_template( "content-lesson/{$format}/title.php" );
@@ -781,23 +695,11 @@
781 695 return;
782 696 }
783 697 do_action( 'learn-press/lesson-start', $item );
784 698
785 - learn_press_get_template( 'content-lesson/content.php', array( 'lesson' => $item ) );
699 + Template::instance()->get_frontend_template( 'content-lesson/content.php', array( 'lesson' => $item ) );
786 700 }
787 701
788 - public function item_quiz_content() {
789 - $item = LP_Global::course_item();
790 -
791 - learn_press_get_template( 'content-quiz/js.php' );
792 - }
793 -
794 - public function item_lesson_content_blocked() {
795 - $item = LP_Global::course_item();
796 -
797 - learn_press_get_template( 'global/block-content.php' );
798 - }
799 -
800 702 /**
801 703 * Get template button complete lesson
802 704 */
803 705 public function item_lesson_complete_button() {
@@ -802,64 +704,53 @@
802 704 */
803 705 public function item_lesson_complete_button() {
804 706 $user = learn_press_get_current_user();
805 707 $course = learn_press_get_course();
806 - $item = LP_Global::course_item();
807 -
808 - if ( ! $user || ! $course || ! $user->is_course_in_progress( $course->get_id() ) ) {
708 + if ( ! $course ) {
809 709 return;
810 710 }
811 711
812 - // The complete button is not displayed when the course is locked --hungkv--
813 - if ( $user->can_view_content_course( $course->get_id() )->key === LP_BLOCK_COURSE_DURATION_EXPIRE ) {
814 - return;
815 - }
712 + try {
713 + $item = LP_Global::course_item();
714 + if ( ! $user || ! $user->is_course_in_progress( $course->get_id() ) ) {
715 + return;
716 + }
816 717
817 - learn_press_get_template(
818 - 'content-lesson/button-complete.php',
819 - array(
820 - 'user' => $user,
821 - 'course' => $course,
822 - 'item' => $item,
823 - )
824 - );
825 - }
718 + // The complete button is not displayed when the course is locked --hungkv--
719 + if ( $user->can_view_content_course( $course->get_id() )->key === LP_BLOCK_COURSE_DURATION_EXPIRE ) {
720 + return;
721 + }
826 722
827 - /**
828 - * @depecated 4.1.6.9
829 - */
830 - /*public function lesson_comment_form() {
831 - $course = learn_press_get_course();
832 - if ( ! $course ) {
833 - return;
723 + learn_press_get_template(
724 + 'content-lesson/button-complete.php',
725 + array(
726 + 'user' => $user,
727 + 'course' => $course,
728 + 'item' => $item,
729 + )
730 + );
731 + } catch ( Throwable $e ) {
732 + error_log( $e->getMessage() );
834 733 }
734 + }
835 735
836 - $lesson = LP_Global::course_item();
837 - if ( ! $lesson ) {
838 - return;
736 + public function item_lesson_material() {
737 + try {
738 + do_action( 'learn-press/course-material/layout', [] );
739 + } catch ( Throwable $e ) {
740 + error_log( $e->getMessage() );
839 741 }
742 + }
840 743
841 - if ( $lesson->setup_postdata() ) {
842 -
843 - if ( comments_open() || get_comments_number() ) {
844 - add_filter( 'deprecated_file_trigger_error', '__return_false' );
845 - comments_template();
846 - remove_filter( 'deprecated_file_trigger_error', '__return_false' );
847 - }
848 - $lesson->reset_postdata();
849 - }
850 - }*/
851 -
852 744 /**
853 745 * Template show count items
854 746 *
855 747 * @since 4.0.0
856 - * @version 1.0.1
748 + * @version 1.0.2
857 749 * @editor tungnx
858 750 */
859 751 public function count_object() {
860 - $course = learn_press_get_course();
861 -
752 + $course = CourseModel::find( get_the_ID(), true );
862 753 if ( ! $course ) {
863 754 return;
864 755 }
865 756
@@ -898,9 +789,13 @@
898 789 }
899 790
900 791 public function course_extra_boxes() {
901 792 $course = LP_Course::get_course( get_the_ID() );
902 - $boxes = apply_filters(
793 + if ( ! $course ) {
794 + return;
795 + }
796 +
797 + $boxes = apply_filters(
903 798 'learn-press/course-extra-boxes-data',
904 799 array(
905 800 array(
906 801 'title' => __( 'Requirements', 'learnpress' ),
@@ -930,10 +825,13 @@
930 825 }
931 826
932 827 learn_press_get_template( 'single-course/extra-info', $box );
933 828 }
829 + }
934 830
935 - }
831 + /*public function metarials() {
832 + echo wp_kses_post( do_shortcode( '[learn_press_course_materials]' ) );
833 + }*/
936 834
937 835 public function faqs() {
938 836 $course = LP_Course::get_course( get_the_ID() );
939 837 $faqs = $course->get_faqs();
@@ -974,17 +872,8 @@
974 872 )
975 873 );
976 874 }
977 875
978 - public function instructor_socials() {
979 - $instructor = $this->course->get_instructor();
980 - $socials = $instructor->get_profile_socials( $instructor->get_id() );
981 -
982 - foreach ( $socials as $social ) {
983 - echo wp_kses_post( $social );
984 - }
985 - }
986 -
987 876 public function has_sidebar() {
988 877 $actions = array(
989 878 'learn-press/before-course-summary-sidebar',
990 879 'learn-press/course-summary-sidebar',
@@ -1020,14 +909,15 @@
1020 909 if ( ! $item ) {
1021 910 return;
1022 911 }
1023 912
1024 - $user = learn_press_get_current_user();
913 + $user = learn_press_get_current_user();
914 + $user_can_view_course = $user->can_view_content_course( $course->get_id() );
915 + $user_can_view_item = $user->can_view_item( $item->get_id(), $user_can_view_course );
916 + if ( ! $user_can_view_item->flag ) {
917 + return;
918 + }
1025 919
1026 - // if ( ! $user->is_admin() && ! $user->has_course_status( $course->get_id(), array( 'enrolled', 'finished' ) ) ) {
1027 - // return;
1028 - // }
1029 -
1030 920 if ( $item->setup_postdata() ) {
1031 921
1032 922 if ( comments_open() || get_comments_number() ) {
1033 923 learn_press_get_template( 'single-course/item-comments' );
@@ -1035,11 +925,10 @@
1035 925 $item->reset_postdata();
1036 926 }
1037 927 }
1038 928
929 +
1039 930 public function course_comment_template() {
1040 - global $post;
1041 -
1042 931 if ( comments_open() || get_comments_number() ) {
1043 932 add_filter( 'deprecated_file_trigger_error', '__return_false' );
1044 933 comments_template();
1045 934 remove_filter( 'deprecated_file_trigger_error', '__return_false' );
@@ -1049,10 +938,13 @@
1049 938 /**
1050 939 * Show info time handle of user
1051 940 *
1052 941 * @throws Exception
942 + * @deprecated 4.4.0
1053 943 */
1054 944 public function user_time() {
945 + _deprecated_function( __METHOD__, '4.4.0' );
946 + return;
1055 947 $user = learn_press_get_current_user();
1056 948
1057 949 if ( ! $user ) {
1058 950 return;
@@ -1074,12 +966,18 @@
1074 966 $status = $user_course->get_status();
1075 967 $start_time = $user_course->get_start_time();
1076 968 $end_time = $user_course->get_end_time();
1077 969 $expiration_time = $user_course->get_expiration_time();
970 + $data = [
971 + 'status' => $status,
972 + 'start_time' => $start_time,
973 + 'end_time' => $end_time,
974 + 'expiration_time' => $expiration_time,
975 + ];
1078 976
1079 977 learn_press_get_template(
1080 978 'single-course/sidebar/user-time',
1081 - compact( 'status', 'start_time', 'end_time', 'expiration_time' )
979 + compact( 'data' )
1082 980 );
1083 981 }
1084 982
1085 983 /**
@@ -1090,26 +988,19 @@
1090 988 * @throws Exception
1091 989 * @author Nhamdv.
1092 990 */
1093 991 public function user_progress() {
1094 - if ( ! is_user_logged_in() ) {
992 + $courseModel = CourseModel::find( get_the_ID(), true );
993 + if ( ! $courseModel ) {
1095 994 return;
1096 995 }
1097 996
1098 - $course = learn_press_get_course();
1099 - $user = learn_press_get_current_user();
997 + $userModel = UserModel::find( get_current_user_id(), true );
998 + echo SingleCourseModernLayout::instance()->html_info_learning( $courseModel, $userModel );
1100 999
1101 - if ( ! $course ) {
1102 - return;
1103 - }
1104 -
1105 - if ( ! $user->has_enrolled_or_finished( $course->get_id() ) ) {
1106 - return;
1107 - }
1108 -
1109 - if ( LP_LAZY_LOAD_ANIMATION ) {
1000 + /*if ( LP_LAZY_LOAD_ANIMATION ) {
1110 1001 echo '<div class="lp-course-progress-wrapper">';
1111 - echo lp_skeleton_animation_html( 3 );
1002 + lp_skeleton_animation_html();
1112 1003 echo '</div>';
1113 1004 } else {
1114 1005 $course_data = $user->get_course_data( $course->get_id() );
1115 1006 if ( ! $course_data ) {
@@ -1121,15 +1012,14 @@
1121 1012 learn_press_get_template(
1122 1013 'single-course/sidebar/user-progress',
1123 1014 compact( 'user', 'course', 'course_data', 'course_results' )
1124 1015 );
1125 - }
1016 + }*/
1126 1017 }
1127 1018
1128 1019 public function course_extra_boxes_position_control() {
1129 1020 $course = LP_Course::get_course( get_the_ID() );
1130 1021 $user = learn_press_get_current_user();
1131 -
1132 1022 if ( ! $user || ! $course ) {
1133 1023 return;
1134 1024 }
1135 1025
@@ -1136,15 +1026,15 @@
1136 1026 $enrolled = $user->has_enrolled_course( $course->get_id() );
1137 1027 if ( $enrolled ) {
1138 1028 remove_action(
1139 1029 'learn-press/course-content-summary',
1140 - LP()->template( 'course' )->func( 'course_extra_boxes' ),
1030 + LearnPress::instance()->template( 'course' )->func( 'course_extra_boxes' ),
1141 1031 40
1142 1032 );
1143 1033 } else {
1144 1034 remove_action(
1145 1035 'learn-press/course-content-summary',
1146 - LP()->template( 'course' )->func( 'course_extra_boxes' ),
1036 + LearnPress::instance()->template( 'course' )->func( 'course_extra_boxes' ),
1147 1037 70
1148 1038 );
1149 1039 }
1150 1040 }