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