Addons.php
4 years ago
Admin.php
4 years ago
Ajax.php
4 years ago
Announcements.php
4 years ago
Assets.php
3 years ago
Backend_Page_Trait.php
4 years ago
Course.php
3 years ago
Course_Filter.php
4 years ago
Course_List.php
3 years ago
Course_Settings_Tabs.php
4 years ago
Course_Widget.php
4 years ago
Custom_Validation.php
4 years ago
Dashboard.php
3 years ago
FormHandler.php
4 years ago
Frontend.php
3 years ago
Gutenberg.php
4 years ago
Input.php
3 years ago
Instructor.php
4 years ago
Instructors_List.php
3 years ago
Lesson.php
4 years ago
Options_V2.php
3 years ago
Post_types.php
4 years ago
Private_Course_Access.php
4 years ago
Q_and_A.php
4 years ago
Question_Answers_List.php
4 years ago
Quiz.php
4 years ago
Quiz_Attempts_List.php
4 years ago
RestAPI.php
4 years ago
Reviews.php
4 years ago
Rewrite_Rules.php
4 years ago
Shortcode.php
4 years ago
Student.php
4 years ago
Students_List.php
4 years ago
Taxonomies.php
4 years ago
Template.php
3 years ago
Theme_Compatibility.php
5 years ago
Tools.php
3 years ago
Tools_V2.php
4 years ago
Tutor.php
3 years ago
TutorEDD.php
4 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
4 years ago
Tutor_Setup.php
4 years ago
Upgrader.php
4 years ago
User.php
4 years ago
Utils.php
3 years ago
Video_Stream.php
4 years ago
Withdraw.php
3 years ago
Withdraw_Requests_List.php
4 years ago
WooCommerce.php
3 years ago
Template.php
447 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Template Class |
| 4 | * |
| 5 | * @since: v.1.0.0 |
| 6 | * |
| 7 | * @package Tutor\Template |
| 8 | */ |
| 9 | |
| 10 | namespace TUTOR; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Handle template before include |
| 18 | */ |
| 19 | class Template extends Tutor_Base { |
| 20 | |
| 21 | /** |
| 22 | * Register Hooks |
| 23 | */ |
| 24 | public function __construct() { |
| 25 | parent::__construct(); |
| 26 | |
| 27 | /** |
| 28 | * Should Load Template Override |
| 29 | * Integration for specially oxygen builder |
| 30 | * If we found false of below filter, then we will not use this file |
| 31 | */ |
| 32 | |
| 33 | $template_override = apply_filters( 'tutor_lms_should_template_override', true ); |
| 34 | if ( ! $template_override ) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | add_filter( 'template_include', array( $this, 'load_course_archive_template' ), 99 ); |
| 39 | add_filter( 'template_include', array( $this, 'load_single_course_template' ), 99 ); |
| 40 | add_filter( 'template_include', array( $this, 'load_single_lesson_template' ), 99 ); |
| 41 | add_filter( 'template_include', array( $this, 'play_private_video' ), 99 ); |
| 42 | add_filter( 'template_include', array( $this, 'load_quiz_template' ), 99 ); |
| 43 | add_filter( 'template_include', array( $this, 'load_assignment_template' ), 99 ); |
| 44 | |
| 45 | add_filter( 'template_include', array( $this, 'student_public_profile' ), 99 ); |
| 46 | add_filter( 'template_include', array( $this, 'tutor_dashboard' ), 99 ); |
| 47 | add_filter( 'pre_get_document_title', array( $this, 'student_public_profile_title' ) ); |
| 48 | |
| 49 | add_filter( 'the_content', array( $this, 'convert_static_page_to_template' ) ); |
| 50 | add_action( 'pre_get_posts', array( $this, 'limit_course_query_archive' ), 99 ); |
| 51 | |
| 52 | /** |
| 53 | * Dummy template for Spotlight mode design. It will be removed once we adopt the design to core. |
| 54 | */ |
| 55 | add_action( |
| 56 | 'wp_loaded', |
| 57 | function() { |
| 58 | if ( ! is_admin() && isset( $_GET['course-spotlight-v2'] ) && $_GET['course-spotlight-v2'] == 1 ) { |
| 59 | tutor_utils()->tutor_custom_header(); |
| 60 | include tutor()->path . '/views/course-spotlight-v2-static.php'; |
| 61 | tutor_utils()->tutor_custom_footer(); |
| 62 | exit; |
| 63 | } |
| 64 | } |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @param $template |
| 70 | * |
| 71 | * @return bool|string |
| 72 | * |
| 73 | * Load default template for course |
| 74 | * |
| 75 | * @since v.1.0.0 |
| 76 | */ |
| 77 | public function load_course_archive_template( $template ) { |
| 78 | global $wp_query; |
| 79 | |
| 80 | $post_type = get_query_var( 'post_type' ); |
| 81 | $course_category = get_query_var( 'course-category' ); |
| 82 | |
| 83 | if ( ( $post_type === $this->course_post_type || ! empty( $course_category ) ) && $wp_query->is_archive ) { |
| 84 | $template = tutor_get_template( 'archive-course' ); |
| 85 | return $template; |
| 86 | } |
| 87 | |
| 88 | return $template; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @param $query |
| 93 | * |
| 94 | * limit for course archive listing |
| 95 | * |
| 96 | * Make a page to archive listing for courses |
| 97 | */ |
| 98 | public function limit_course_query_archive( $query ) { |
| 99 | $courses_per_page = (int) tutor_utils()->get_option( 'courses_per_page', 12 ); |
| 100 | |
| 101 | if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && is_page() ) { |
| 102 | $queried_object = get_queried_object(); |
| 103 | if ( $queried_object instanceof \WP_Post ) { |
| 104 | $page_id = $queried_object->ID; |
| 105 | $selected_archive_page = (int) tutor_utils()->get_option( 'course_archive_page' ); |
| 106 | |
| 107 | if ( $page_id === $selected_archive_page ) { |
| 108 | $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; |
| 109 | $search_query = get_search_query(); |
| 110 | query_posts( |
| 111 | array( |
| 112 | 'post_type' => $this->course_post_type, |
| 113 | 'paged' => $paged, |
| 114 | 's' => $search_query, |
| 115 | 'posts_per_page' => $courses_per_page, |
| 116 | ) |
| 117 | ); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if ( $query->is_archive && $query->is_main_query() && ! $query->is_feed() && ! is_admin() ) { |
| 123 | $post_type = get_query_var( 'post_type' ); |
| 124 | $course_category = get_query_var( 'course-category' ); |
| 125 | if ( ( $post_type === $this->course_post_type || ! empty( $course_category ) ) ) { |
| 126 | $query->set( 'posts_per_page', $courses_per_page ); |
| 127 | |
| 128 | $course_filter = 'newest_first'; |
| 129 | if ( ! empty( $_GET['tutor_course_filter'] ) ) { |
| 130 | $course_filter = sanitize_text_field( $_GET['tutor_course_filter'] ); |
| 131 | } |
| 132 | switch ( $course_filter ) { |
| 133 | case 'newest_first': |
| 134 | $query->set( 'orderby', 'ID' ); |
| 135 | $query->set( 'order', 'desc' ); |
| 136 | break; |
| 137 | case 'oldest_first': |
| 138 | $query->set( 'orderby', 'ID' ); |
| 139 | $query->set( 'order', 'asc' ); |
| 140 | break; |
| 141 | case 'course_title_az': |
| 142 | $query->set( 'orderby', 'post_title' ); |
| 143 | $query->set( 'order', 'asc' ); |
| 144 | break; |
| 145 | case 'course_title_za': |
| 146 | $query->set( 'orderby', 'post_title' ); |
| 147 | $query->set( 'order', 'desc' ); |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * @param $template |
| 156 | * |
| 157 | * @return bool|string |
| 158 | * |
| 159 | * Load Single Course Template |
| 160 | * |
| 161 | * @since v.1.0.0 |
| 162 | * @updated v.1.3.5 |
| 163 | */ |
| 164 | public function load_single_course_template( $template ) { |
| 165 | global $wp_query; |
| 166 | |
| 167 | if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] === $this->course_post_type ) { |
| 168 | do_action( 'single_course_template_before_load', get_the_ID() ); |
| 169 | wp_reset_query(); |
| 170 | return tutor_get_template( 'single-course' ); |
| 171 | } |
| 172 | |
| 173 | return $template; |
| 174 | } |
| 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 | * @param $template |
| 185 | * |
| 186 | * @return bool|string |
| 187 | * |
| 188 | * Load lesson template |
| 189 | * |
| 190 | * @since v.1.0.0 |
| 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 ( get_post_meta( $course_id, '_tutor_is_public_course', true ) == 'yes' && ! 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 | * @param $template |
| 226 | * |
| 227 | * @return mixed |
| 228 | * |
| 229 | * Play the video in this url. |
| 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'] ) && $wp_query->query_vars['lesson_video'] === 'true' ) { |
| 235 | |
| 236 | $isPublicVideo = apply_filters( 'tutor_video_stream_is_public', false, get_the_ID() ); |
| 237 | if ( $isPublicVideo ) { |
| 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 | _e( 'Permission denied', 'tutor' ); |
| 254 | } |
| 255 | exit(); |
| 256 | } |
| 257 | |
| 258 | return $template; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * @param $content |
| 263 | * |
| 264 | * @return mixed |
| 265 | * |
| 266 | * Tutor Dashboard Page, Responsible to show dashboard stuffs |
| 267 | * |
| 268 | * @since v.1.0.0 |
| 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 ( $student_dashboard_page_id === get_the_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 ( $instructor_register_page_page_id === get_the_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 ( $student_register_page_id === get_the_ID() ) { |
| 287 | $shortcode = new Shortcode(); |
| 288 | return $shortcode->student_registration_form(); |
| 289 | } |
| 290 | |
| 291 | return $content; |
| 292 | } |
| 293 | |
| 294 | public function tutor_dashboard( $template ) { |
| 295 | global $wp_query; |
| 296 | if ( $wp_query->is_page ) { |
| 297 | $student_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' ); |
| 298 | $student_dashboard_page_id = apply_filters( 'tutor_dashboard_page_id_filter', $student_dashboard_page_id ); |
| 299 | |
| 300 | if ( $student_dashboard_page_id == get_the_ID() ) { |
| 301 | /** |
| 302 | * Handle if logout URL |
| 303 | * |
| 304 | * @since v.1.1.2 |
| 305 | */ |
| 306 | if ( tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars ) === 'logout' ) { |
| 307 | $redirect = apply_filters( 'tutor_dashboard_logout_redirect_url', get_permalink( $student_dashboard_page_id ) ); |
| 308 | wp_logout(); |
| 309 | wp_redirect( $redirect ); |
| 310 | die(); |
| 311 | } |
| 312 | |
| 313 | $dashboard_page = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars ); |
| 314 | |
| 315 | $get_dashboard_config = tutor_utils()->tutor_dashboard_permalinks(); |
| 316 | $target_dashboard_page = tutor_utils()->array_get( $dashboard_page, $get_dashboard_config ); |
| 317 | |
| 318 | if ( isset( $target_dashboard_page['login_require'] ) && $target_dashboard_page['login_require'] === false ) { |
| 319 | $template = tutor_load_template_part( "template-part.{$dashboard_page}" ); |
| 320 | } else { |
| 321 | |
| 322 | /** |
| 323 | * Load view page based on dashboard Endpoint |
| 324 | */ |
| 325 | if ( is_user_logged_in() ) { |
| 326 | |
| 327 | global $wp; |
| 328 | $full_path = explode( '/', trim( str_replace( get_home_url(), '', home_url( $wp->request ) ), '/' ) ); |
| 329 | |
| 330 | // $template = tutor_get_template( end( $full_path ) == 'create-course' ? implode( '/', $full_path ) : 'dashboard' ); |
| 331 | $template = tutor_get_template( end( $full_path ) == 'create-course' ? 'dashboard.create-course' : 'dashboard' ); |
| 332 | |
| 333 | /** |
| 334 | * Check page page permission |
| 335 | * |
| 336 | * @since v.1.3.4 |
| 337 | */ |
| 338 | $query_var = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars ); |
| 339 | $dashboard_pages = tutor_utils()->tutor_dashboard_pages(); |
| 340 | $dashboard_page_item = tutor_utils()->array_get( $query_var, $dashboard_pages ); |
| 341 | $auth_cap = tutor_utils()->array_get( 'auth_cap', $dashboard_page_item ); |
| 342 | if ( $auth_cap && ! current_user_can( $auth_cap ) ) { |
| 343 | $template = tutor_get_template( 'permission-denied' ); |
| 344 | } |
| 345 | } else { |
| 346 | $template = tutor_get_template( 'login' ); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | return $template; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * @param $template |
| 356 | * |
| 357 | * @return bool|string |
| 358 | * |
| 359 | * @since v.1.0.0 |
| 360 | * |
| 361 | * If course public then enrolment not required |
| 362 | * |
| 363 | * @since v2.0.2 |
| 364 | */ |
| 365 | public function load_quiz_template( $template ) { |
| 366 | global $wp_query, $post; |
| 367 | |
| 368 | if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] === 'tutor_quiz' ) { |
| 369 | if ( is_user_logged_in() ) { |
| 370 | $has_content_access = tutor_utils()->has_enrolled_content_access( 'quiz' ); |
| 371 | $course_id = tutor_utils()->get_course_id_by_content( $post ); |
| 372 | $is_public = Course_List::is_public( $course_id ); |
| 373 | |
| 374 | // if public course don't need to be enrolled. |
| 375 | if ( $has_content_access || $is_public ) { |
| 376 | $template = tutor_get_template( 'single-quiz' ); |
| 377 | } else { |
| 378 | $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first |
| 379 | } |
| 380 | } else { |
| 381 | $template = tutor_get_template( 'login' ); |
| 382 | } |
| 383 | return $template; |
| 384 | } |
| 385 | return $template; |
| 386 | } |
| 387 | |
| 388 | public function load_assignment_template( $template ) { |
| 389 | global $wp_query; |
| 390 | |
| 391 | if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] === 'tutor_assignments' ) { |
| 392 | if ( is_user_logged_in() ) { |
| 393 | $has_content_access = tutor_utils()->has_enrolled_content_access( 'assignment' ); |
| 394 | if ( $has_content_access ) { |
| 395 | $template = tutor_get_template( 'single-assignment' ); |
| 396 | } else { |
| 397 | $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first |
| 398 | } |
| 399 | } else { |
| 400 | $template = tutor_get_template( 'login' ); |
| 401 | } |
| 402 | return $template; |
| 403 | } |
| 404 | |
| 405 | return $template; |
| 406 | } |
| 407 | |
| 408 | /** |
| 409 | * @param $template |
| 410 | * |
| 411 | * @return bool|string |
| 412 | * |
| 413 | * @since v.1.0.0 |
| 414 | */ |
| 415 | public function student_public_profile( $template ) { |
| 416 | global $wp_query; |
| 417 | $query_var = $wp_query->query_vars; |
| 418 | if ( ! empty( $wp_query->query['tutor_profile_username'] ) ) { |
| 419 | $template = tutor_get_template( 'public-profile' ); |
| 420 | } |
| 421 | |
| 422 | return $template; |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * @return string |
| 427 | * Show student Profile |
| 428 | * |
| 429 | * @since v.1.0.0 |
| 430 | */ |
| 431 | public function student_public_profile_title() { |
| 432 | global $wp_query; |
| 433 | |
| 434 | if ( ! empty( $wp_query->query['tutor_profile_username'] ) ) { |
| 435 | global $wpdb; |
| 436 | |
| 437 | $user_name = sanitize_text_field( $wp_query->query['tutor_profile_username'] ); |
| 438 | $user = $wpdb->get_row( $wpdb->prepare( "SELECT display_name from {$wpdb->users} WHERE user_login = %s limit 1; ", $user_name ) ); |
| 439 | |
| 440 | if ( ! empty( $user->display_name ) ) { |
| 441 | return sprintf( "%s's Profile page ", $user->display_name ); |
| 442 | } |
| 443 | } |
| 444 | return ''; |
| 445 | } |
| 446 | } |
| 447 |