Addons.php
3 years ago
Admin.php
3 years ago
Ajax.php
3 years ago
Announcements.php
3 years ago
Assets.php
3 years ago
Backend_Page_Trait.php
3 years ago
Course.php
3 years ago
Course_Embed.php
3 years ago
Course_Filter.php
3 years ago
Course_List.php
3 years ago
Course_Settings_Tabs.php
3 years ago
Course_Widget.php
3 years ago
Custom_Validation.php
3 years ago
Dashboard.php
3 years ago
FormHandler.php
3 years ago
Frontend.php
3 years ago
Gutenberg.php
3 years ago
Input.php
3 years ago
Instructor.php
3 years ago
Instructors_List.php
3 years ago
Lesson.php
3 years ago
Options_V2.php
3 years ago
Post_types.php
3 years ago
Private_Course_Access.php
3 years ago
Q_and_A.php
3 years ago
Question_Answers_List.php
3 years ago
Quiz.php
3 years ago
Quiz_Attempts_List.php
3 years ago
RestAPI.php
3 years ago
Reviews.php
3 years ago
Rewrite_Rules.php
3 years ago
Shortcode.php
3 years ago
Student.php
3 years ago
Students_List.php
3 years ago
Taxonomies.php
3 years ago
Template.php
3 years ago
Theme_Compatibility.php
3 years ago
Tools.php
3 years ago
Tools_V2.php
3 years ago
Tutor.php
3 years ago
TutorEDD.php
3 years ago
Tutor_Base.php
3 years ago
Tutor_Setup.php
3 years ago
Upgrader.php
3 years ago
User.php
3 years ago
Utils.php
3 years ago
Video_Stream.php
3 years ago
Withdraw.php
3 years ago
Withdraw_Requests_List.php
3 years ago
WooCommerce.php
3 years ago
Template.php
471 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Template Class |
| 4 | * |
| 5 | * @package Tutor\Template |
| 6 | * @author Themeum <support@themeum.com> |
| 7 | * @link https://themeum.com |
| 8 | * @since 1.0.0 |
| 9 | */ |
| 10 | |
| 11 | namespace TUTOR; |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Handle template before include |
| 19 | * |
| 20 | * @since 1.0.0 |
| 21 | */ |
| 22 | class Template extends Tutor_Base { |
| 23 | |
| 24 | /** |
| 25 | * Register Hooks |
| 26 | * |
| 27 | * @since 1.0.0 |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | parent::__construct(); |
| 31 | |
| 32 | /** |
| 33 | * Should Load Template Override |
| 34 | * Integration for specially oxygen builder |
| 35 | * If we found false of below filter, then we will not use this file |
| 36 | */ |
| 37 | |
| 38 | $template_override = apply_filters( 'tutor_lms_should_template_override', true ); |
| 39 | if ( ! $template_override ) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | add_filter( 'template_include', array( $this, 'load_course_archive_template' ), 99 ); |
| 44 | add_filter( 'template_include', array( $this, 'load_single_course_template' ), 99 ); |
| 45 | add_filter( 'template_include', array( $this, 'load_single_lesson_template' ), 99 ); |
| 46 | add_filter( 'template_include', array( $this, 'play_private_video' ), 99 ); |
| 47 | add_filter( 'template_include', array( $this, 'load_quiz_template' ), 99 ); |
| 48 | add_filter( 'template_include', array( $this, 'load_assignment_template' ), 99 ); |
| 49 | |
| 50 | add_filter( 'template_include', array( $this, 'student_public_profile' ), 99 ); |
| 51 | add_filter( 'template_include', array( $this, 'tutor_dashboard' ), 99 ); |
| 52 | add_filter( 'pre_get_document_title', array( $this, 'student_public_profile_title' ) ); |
| 53 | |
| 54 | add_filter( 'the_content', array( $this, 'convert_static_page_to_template' ) ); |
| 55 | add_action( 'pre_get_posts', array( $this, 'limit_course_query_archive' ), 99 ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Load default template for course |
| 60 | * |
| 61 | * @since v.1.0.0 |
| 62 | * |
| 63 | * @param sting $template template name. |
| 64 | * |
| 65 | * @return bool|string |
| 66 | */ |
| 67 | public function load_course_archive_template( $template ) { |
| 68 | global $wp_query; |
| 69 | |
| 70 | $post_type = get_query_var( 'post_type' ); |
| 71 | $course_category = get_query_var( 'course-category' ); |
| 72 | |
| 73 | if ( ( $post_type === $this->course_post_type || ! empty( $course_category ) ) && $wp_query->is_archive ) { |
| 74 | $template = tutor_get_template( 'archive-course' ); |
| 75 | return $template; |
| 76 | } |
| 77 | |
| 78 | return $template; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Limit for course archive listing |
| 83 | * |
| 84 | * Make a page to archive listing for courses |
| 85 | * |
| 86 | * @since 1.0.0 |
| 87 | * |
| 88 | * @param mixed $query query argument. |
| 89 | * |
| 90 | * @return void |
| 91 | */ |
| 92 | public function limit_course_query_archive( $query ) { |
| 93 | $courses_per_page = (int) tutor_utils()->get_option( 'courses_per_page', 12 ); |
| 94 | |
| 95 | if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && is_page() ) { |
| 96 | $queried_object = get_queried_object(); |
| 97 | if ( $queried_object instanceof \WP_Post ) { |
| 98 | $page_id = $queried_object->ID; |
| 99 | $selected_archive_page = (int) tutor_utils()->get_option( 'course_archive_page' ); |
| 100 | |
| 101 | if ( $page_id === $selected_archive_page ) { |
| 102 | $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; |
| 103 | $search_query = get_search_query(); |
| 104 | query_posts( |
| 105 | array( |
| 106 | 'post_type' => $this->course_post_type, |
| 107 | 'paged' => $paged, |
| 108 | 's' => $search_query, |
| 109 | 'posts_per_page' => $courses_per_page, |
| 110 | ) |
| 111 | ); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if ( $query->is_archive && $query->is_main_query() && ! $query->is_feed() && ! is_admin() ) { |
| 117 | $post_type = get_query_var( 'post_type' ); |
| 118 | $course_category = get_query_var( 'course-category' ); |
| 119 | if ( ( $post_type === $this->course_post_type || ! empty( $course_category ) ) ) { |
| 120 | $query->set( 'posts_per_page', $courses_per_page ); |
| 121 | |
| 122 | $course_filter = 'newest_first'; |
| 123 | if ( ! empty( Input::get( 'tutor_course_filter', '' ) ) ) { |
| 124 | $course_filter = Input::get( 'tutor_course_filter' ); |
| 125 | } |
| 126 | switch ( $course_filter ) { |
| 127 | case 'newest_first': |
| 128 | $query->set( 'orderby', 'ID' ); |
| 129 | $query->set( 'order', 'desc' ); |
| 130 | break; |
| 131 | case 'oldest_first': |
| 132 | $query->set( 'orderby', 'ID' ); |
| 133 | $query->set( 'order', 'asc' ); |
| 134 | break; |
| 135 | case 'course_title_az': |
| 136 | $query->set( 'orderby', 'post_title' ); |
| 137 | $query->set( 'order', 'asc' ); |
| 138 | break; |
| 139 | case 'course_title_za': |
| 140 | $query->set( 'orderby', 'post_title' ); |
| 141 | $query->set( 'order', 'desc' ); |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Load Single Course Template |
| 150 | * |
| 151 | * @since v.1.0.0 |
| 152 | * |
| 153 | * @param string $template template name to load. |
| 154 | * |
| 155 | * @return bool|string |
| 156 | */ |
| 157 | public function load_single_course_template( $template ) { |
| 158 | global $wp_query; |
| 159 | |
| 160 | if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] === $this->course_post_type ) { |
| 161 | do_action( 'single_course_template_before_load', get_the_ID() ); |
| 162 | wp_reset_query(); |
| 163 | return tutor_get_template( 'single-course' ); |
| 164 | } |
| 165 | |
| 166 | return $template; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Get root post parent id |
| 171 | * |
| 172 | * @param int $id post id. |
| 173 | * |
| 174 | * @return int root post id |
| 175 | */ |
| 176 | private function get_root_post_parent_id( $id ) { |
| 177 | $ancestors = get_post_ancestors( $id ); |
| 178 | $root = is_array( $ancestors ) ? end( $ancestors ) : null; |
| 179 | |
| 180 | return is_numeric( $root ) ? $root : $id; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Load lesson template |
| 185 | * |
| 186 | * @since v.1.0.0 |
| 187 | * |
| 188 | * @param string $template template name to load. |
| 189 | * |
| 190 | * @return bool|string |
| 191 | */ |
| 192 | public function load_single_lesson_template( $template ) { |
| 193 | global $wp_query; |
| 194 | |
| 195 | if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] === $this->lesson_post_type ) { |
| 196 | $page_id = get_the_ID(); |
| 197 | |
| 198 | do_action( 'tutor_lesson_load_before', $template ); |
| 199 | setup_postdata( $page_id ); |
| 200 | |
| 201 | if ( is_user_logged_in() ) { |
| 202 | $has_content_access = tutor_utils()->has_enrolled_content_access( 'lesson' ); |
| 203 | if ( $has_content_access ) { |
| 204 | $template = tutor_get_template( 'single-lesson' ); |
| 205 | } else { |
| 206 | $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first |
| 207 | } |
| 208 | } else { |
| 209 | $template = tutor_get_template( 'login' ); |
| 210 | } |
| 211 | wp_reset_postdata(); |
| 212 | |
| 213 | // Forcefully show lessons if it is public and not paid. |
| 214 | $course_id = $this->get_root_post_parent_id( $page_id ); |
| 215 | if ( 'yes' === get_post_meta( $course_id, '_tutor_is_public_course', true ) && ! tutor_utils()->is_course_purchasable( $course_id ) ) { |
| 216 | $template = tutor_get_template( 'single-lesson' ); |
| 217 | } |
| 218 | |
| 219 | return apply_filters( 'tutor_lesson_template', $template ); |
| 220 | } |
| 221 | return $template; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Play the video in this url. |
| 226 | * |
| 227 | * @param string $template template to load. |
| 228 | * |
| 229 | * @return mixed |
| 230 | */ |
| 231 | public function play_private_video( $template ) { |
| 232 | global $wp_query; |
| 233 | |
| 234 | if ( $wp_query->is_single && ! empty( $wp_query->query_vars['lesson_video'] ) && 'true' === $wp_query->query_vars['lesson_video'] ) { |
| 235 | |
| 236 | $is_public_video = apply_filters( 'tutor_video_stream_is_public', false, get_the_ID() ); |
| 237 | if ( $is_public_video ) { |
| 238 | $video_info = tutor_utils()->get_video_info(); |
| 239 | if ( $video_info ) { |
| 240 | $stream = new Video_Stream( $video_info->path ); |
| 241 | $stream->start(); |
| 242 | } |
| 243 | exit(); |
| 244 | } |
| 245 | |
| 246 | if ( tutor_utils()->is_course_enrolled_by_lesson() ) { |
| 247 | $video_info = tutor_utils()->get_video_info(); |
| 248 | if ( $video_info ) { |
| 249 | $stream = new Video_Stream( $video_info->path ); |
| 250 | $stream->start(); |
| 251 | } |
| 252 | } else { |
| 253 | esc_html_e( 'Permission denied', 'tutor' ); |
| 254 | } |
| 255 | exit(); |
| 256 | } |
| 257 | |
| 258 | return $template; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Tutor Dashboard Page, Responsible to show dashboard stuffs |
| 263 | * |
| 264 | * @since v.1.0.0 |
| 265 | * |
| 266 | * @param string $content page content. |
| 267 | * |
| 268 | * @return mixed |
| 269 | */ |
| 270 | public function convert_static_page_to_template( $content ) { |
| 271 | // Dashboard Page. |
| 272 | $student_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' ); |
| 273 | if ( get_the_ID() === $student_dashboard_page_id ) { |
| 274 | $shortcode = new Shortcode(); |
| 275 | return $shortcode->tutor_dashboard(); |
| 276 | } |
| 277 | |
| 278 | // Instructor Registration Page. |
| 279 | $instructor_register_page_page_id = (int) tutor_utils()->get_option( 'instructor_register_page' ); |
| 280 | if ( get_the_ID() === $instructor_register_page_page_id ) { |
| 281 | $shortcode = new Shortcode(); |
| 282 | return $shortcode->instructor_registration_form(); |
| 283 | } |
| 284 | |
| 285 | $student_register_page_id = (int) tutor_utils()->get_option( 'student_register_page' ); |
| 286 | if ( get_the_ID() === $student_register_page_id ) { |
| 287 | $shortcode = new Shortcode(); |
| 288 | return $shortcode->student_registration_form(); |
| 289 | } |
| 290 | |
| 291 | return $content; |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Tutor dashboard |
| 296 | * |
| 297 | * @since 1.0.0 |
| 298 | * |
| 299 | * @param string $template template name. |
| 300 | * |
| 301 | * @return string |
| 302 | */ |
| 303 | public function tutor_dashboard( $template ) { |
| 304 | global $wp_query; |
| 305 | $is_page = apply_filters( 'tutor_determine_is_page', $wp_query->is_page, $template ); |
| 306 | if ( $is_page ) { |
| 307 | $student_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' ); |
| 308 | $student_dashboard_page_id = apply_filters( 'tutor_dashboard_page_id_filter', $student_dashboard_page_id ); |
| 309 | $is_dashboard_page = apply_filters( 'tutor_determine_is_dashboard_page', get_the_ID() == $student_dashboard_page_id ); |
| 310 | |
| 311 | if ( $is_dashboard_page ) { |
| 312 | /** |
| 313 | * Handle if logout URL |
| 314 | * |
| 315 | * @since v.1.1.2 |
| 316 | */ |
| 317 | if ( tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars ) === 'logout' ) { |
| 318 | $redirect = apply_filters( 'tutor_dashboard_logout_redirect_url', get_permalink( $student_dashboard_page_id ) ); |
| 319 | wp_logout(); |
| 320 | wp_safe_redirect( $redirect ); |
| 321 | die(); |
| 322 | } |
| 323 | |
| 324 | $dashboard_page = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars ); |
| 325 | |
| 326 | $get_dashboard_config = tutor_utils()->tutor_dashboard_permalinks(); |
| 327 | $target_dashboard_page = tutor_utils()->array_get( $dashboard_page, $get_dashboard_config ); |
| 328 | |
| 329 | if ( isset( $target_dashboard_page['login_require'] ) && false === $target_dashboard_page['login_require'] ) { |
| 330 | $template = tutor_load_template_part( "template-part.{$dashboard_page}" ); |
| 331 | } else { |
| 332 | |
| 333 | /** |
| 334 | * Load view page based on dashboard Endpoint |
| 335 | */ |
| 336 | if ( is_user_logged_in() ) { |
| 337 | |
| 338 | global $wp; |
| 339 | $full_path = explode( '/', trim( str_replace( get_home_url(), '', home_url( $wp->request ) ), '/' ) ); |
| 340 | |
| 341 | $template = tutor_get_template( 'create-course' === end( $full_path ) ? 'dashboard.create-course' : 'dashboard' ); |
| 342 | |
| 343 | /** |
| 344 | * Check page page permission |
| 345 | * |
| 346 | * @since 1.3.4 |
| 347 | */ |
| 348 | $query_var = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars ); |
| 349 | $dashboard_pages = tutor_utils()->tutor_dashboard_pages(); |
| 350 | $dashboard_page_item = tutor_utils()->array_get( $query_var, $dashboard_pages ); |
| 351 | $auth_cap = tutor_utils()->array_get( 'auth_cap', $dashboard_page_item ); |
| 352 | if ( $auth_cap && ! current_user_can( $auth_cap ) ) { |
| 353 | $template = tutor_get_template( 'permission-denied' ); |
| 354 | } |
| 355 | } else { |
| 356 | $template = tutor_get_template( 'login' ); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | return $template; |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Load quiz template |
| 366 | * |
| 367 | * @since 1.0.0 |
| 368 | * |
| 369 | * If course public then enrollment not required |
| 370 | * |
| 371 | * @since 2.0.2 |
| 372 | * |
| 373 | * @param string $template template to load. |
| 374 | * |
| 375 | * @return bool|string |
| 376 | */ |
| 377 | public function load_quiz_template( $template ) { |
| 378 | global $wp_query, $post; |
| 379 | |
| 380 | if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && 'tutor_quiz' === $wp_query->query_vars['post_type'] ) { |
| 381 | if ( is_user_logged_in() ) { |
| 382 | $has_content_access = tutor_utils()->has_enrolled_content_access( 'quiz' ); |
| 383 | $course_id = tutor_utils()->get_course_id_by_content( $post ); |
| 384 | $is_public = Course_List::is_public( $course_id ); |
| 385 | |
| 386 | // if public course don't need to be enrolled. |
| 387 | if ( $has_content_access || $is_public ) { |
| 388 | $template = tutor_get_template( 'single-quiz' ); |
| 389 | } else { |
| 390 | $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first. |
| 391 | } |
| 392 | } else { |
| 393 | $template = tutor_get_template( 'login' ); |
| 394 | } |
| 395 | return $template; |
| 396 | } |
| 397 | return $template; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Load assignment template |
| 402 | * |
| 403 | * @since 1.0.0 |
| 404 | * |
| 405 | * @param string $template template file to load. |
| 406 | * |
| 407 | * @return string template path |
| 408 | */ |
| 409 | public function load_assignment_template( $template ) { |
| 410 | global $wp_query; |
| 411 | |
| 412 | if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && 'tutor_assignments' === $wp_query->query_vars['post_type'] ) { |
| 413 | if ( is_user_logged_in() ) { |
| 414 | $has_content_access = tutor_utils()->has_enrolled_content_access( 'assignment' ); |
| 415 | if ( $has_content_access ) { |
| 416 | $template = tutor_get_template( 'single-assignment' ); |
| 417 | } else { |
| 418 | $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first |
| 419 | } |
| 420 | } else { |
| 421 | $template = tutor_get_template( 'login' ); |
| 422 | } |
| 423 | return $template; |
| 424 | } |
| 425 | |
| 426 | return $template; |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Student public profile |
| 431 | * |
| 432 | * @since 1.0.0 |
| 433 | * |
| 434 | * @param string $template profile template. |
| 435 | * |
| 436 | * @return bool|string |
| 437 | */ |
| 438 | public function student_public_profile( $template ) { |
| 439 | global $wp_query; |
| 440 | $query_var = $wp_query->query_vars; |
| 441 | if ( ! empty( $wp_query->query['tutor_profile_username'] ) ) { |
| 442 | $template = tutor_get_template( 'public-profile' ); |
| 443 | } |
| 444 | |
| 445 | return $template; |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * Show student Profile |
| 450 | * |
| 451 | * @since 1.0.0 |
| 452 | * |
| 453 | * @return string |
| 454 | */ |
| 455 | public function student_public_profile_title() { |
| 456 | global $wp_query; |
| 457 | |
| 458 | if ( ! empty( $wp_query->query['tutor_profile_username'] ) ) { |
| 459 | global $wpdb; |
| 460 | |
| 461 | $user_name = sanitize_text_field( $wp_query->query['tutor_profile_username'] ); |
| 462 | $user = $wpdb->get_row( $wpdb->prepare( "SELECT display_name from {$wpdb->users} WHERE user_login = %s limit 1; ", $user_name ) ); |
| 463 | |
| 464 | if ( ! empty( $user->display_name ) ) { |
| 465 | return sprintf( "%s's Profile page ", $user->display_name ); |
| 466 | } |
| 467 | } |
| 468 | return ''; |
| 469 | } |
| 470 | } |
| 471 |