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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Template.php
tutor / classes Last commit date
Addons.php 11 months ago Admin.php 8 months ago Ajax.php 9 months ago Announcements.php 1 year ago Assets.php 7 months ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 11 months ago Container.php 11 months ago Course.php 5 months ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 5 months ago Course_Settings_Tabs.php 1 year ago Course_Widget.php 1 year ago Custom_Validation.php 3 years ago Dashboard.php 1 year ago Earnings.php 9 months ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Icon.php 8 months ago Input.php 1 year ago Instructor.php 1 year ago Instructors_List.php 11 months ago Lesson.php 8 months ago Options_V2.php 7 months ago Permalink.php 2 years ago Post_types.php 1 year ago Private_Course_Access.php 1 year ago Q_And_A.php 10 months ago Question_Answers_List.php 11 months ago Quiz.php 5 months ago QuizBuilder.php 11 months ago Quiz_Attempts_List.php 9 months ago RestAPI.php 2 years ago Reviews.php 9 months ago Rewrite_Rules.php 2 years ago Shortcode.php 9 months ago Singleton.php 1 year ago Student.php 1 year ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 9 months ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 1 year ago Tutor.php 7 months ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 8 months ago Upgrader.php 9 months ago User.php 4 months ago Utils.php 5 months ago Video_Stream.php 3 years ago WhatsNew.php 9 months ago Withdraw.php 1 year ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 7 months ago
Template.php
497 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 if ( ! is_array( $post_type ) ) {
72 $post_type = array( $post_type );
73 }
74
75 $course_category = get_query_var( 'course-category' );
76
77 if ( ( in_array( $this->course_post_type, $post_type, true ) || ! empty( $course_category ) ) && $wp_query->is_archive ) {
78 $template = tutor_get_template( 'archive-course' );
79 return $template;
80 }
81
82 return $template;
83 }
84
85 /**
86 * Limit for course archive listing
87 *
88 * Make a page to archive listing for courses
89 *
90 * @since 1.0.0
91 *
92 * @param mixed $query query argument.
93 *
94 * @return void
95 */
96 public function limit_course_query_archive( $query ) {
97 $courses_per_page = (int) tutor_utils()->get_option( 'courses_per_page', 12 );
98
99 if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && is_page() ) {
100 $queried_object = get_queried_object();
101 if ( $queried_object instanceof \WP_Post ) {
102 $page_id = $queried_object->ID;
103 $selected_archive_page = (int) apply_filters( 'tutor_filter_course_archive_page', tutor_utils()->get_option( 'course_archive_page' ) );
104
105 if ( $page_id === $selected_archive_page ) {
106 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
107 $search_query = get_search_query();
108 query_posts(
109 array(
110 'post_type' => $this->course_post_type,
111 'paged' => $paged,
112 's' => $search_query,
113 'posts_per_page' => $courses_per_page,
114 )
115 );
116 }
117 }
118 }
119
120 if ( $query->is_archive && $query->is_main_query() && ! $query->is_feed() && ! is_admin() ) {
121 $post_type = get_query_var( 'post_type' );
122 $course_category = get_query_var( 'course-category' );
123 if ( ( $post_type === $this->course_post_type || ! empty( $course_category ) ) ) {
124 $query->set( 'posts_per_page', $courses_per_page );
125 $query->set( 'post_type', apply_filters( 'tutor_course_archive_post_types', array( $this->course_post_type ) ) );
126 $query = apply_filters( 'tutor_limit_course_archive_list_filter', $query );
127
128 $course_filter = 'newest_first';
129 if ( ! empty( Input::get( 'tutor_course_filter', '' ) ) ) {
130 $course_filter = Input::get( 'tutor_course_filter' );
131 }
132 switch ( $course_filter ) {
133 case 'newest_first':
134 $query->set( 'orderby', 'post_date' );
135 $query->set( 'order', 'desc' );
136 break;
137 case 'oldest_first':
138 $query->set( 'orderby', 'post_date' );
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 * Load Single Course Template
156 *
157 * @since v.1.0.0
158 *
159 * @param string $template template name to load.
160 *
161 * @return bool|string
162 */
163 public function load_single_course_template( $template ) {
164 global $wp_query;
165
166 if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] === $this->course_post_type ) {
167 do_action( 'single_course_template_before_load', get_the_ID() );
168 wp_reset_query();
169 return tutor_get_template( 'single-course' );
170 }
171
172 return $template;
173 }
174
175 /**
176 * Get root post parent id
177 *
178 * @param int $id post id.
179 *
180 * @return int root post id
181 */
182 private function get_root_post_parent_id( $id ) {
183 $ancestors = get_post_ancestors( $id );
184 $root = is_array( $ancestors ) ? end( $ancestors ) : null;
185
186 return is_numeric( $root ) ? $root : $id;
187 }
188
189 /**
190 * Load lesson template
191 *
192 * @since v.1.0.0
193 *
194 * @param string $template template name to load.
195 *
196 * @return bool|string
197 */
198 public function load_single_lesson_template( $template ) {
199 global $wp_query;
200
201 $post_type = get_query_var( 'post_type' );
202
203 $is_lesson_post_type = apply_filters( 'tutor_is_lesson_post_type', $wp_query->query_vars['post_type'] === $this->lesson_post_type, $post_type );
204
205 if ( $wp_query->is_single && ! empty( $post_type ) && $is_lesson_post_type ) {
206 $page_id = get_the_ID();
207
208 do_action( 'tutor_lesson_load_before', $template );
209 setup_postdata( $page_id );
210
211 if ( is_user_logged_in() ) {
212 $has_content_access = tutor_utils()->has_enrolled_content_access( 'lesson' );
213 if ( $has_content_access ) {
214 $template = tutor_get_template( 'single-lesson' );
215 } else {
216 $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
217 }
218 } else {
219 $template = tutor_get_template( 'login' );
220 }
221 wp_reset_postdata();
222
223 // Forcefully show lessons if it is public and not paid.
224 $course_id = $this->get_root_post_parent_id( $page_id );
225 if ( 'yes' === get_post_meta( $course_id, '_tutor_is_public_course', true ) && ! tutor_utils()->is_course_purchasable( $course_id ) ) {
226 $template = tutor_get_template( 'single-lesson' );
227 }
228
229 return apply_filters( 'tutor_lesson_template', $template );
230 }
231 return $template;
232 }
233
234 /**
235 * Play the video in this url.
236 *
237 * @param string $template template to load.
238 *
239 * @return mixed
240 */
241 public function play_private_video( $template ) {
242 global $wp_query;
243
244 if ( $wp_query->is_single && ! empty( $wp_query->query_vars['lesson_video'] ) && 'true' === $wp_query->query_vars['lesson_video'] ) {
245
246 $is_public_video = apply_filters( 'tutor_video_stream_is_public', false, get_the_ID() );
247 if ( $is_public_video ) {
248 $video_info = tutor_utils()->get_video_info();
249 if ( $video_info ) {
250 $stream = new Video_Stream( $video_info->path );
251 $stream->start();
252 }
253 exit();
254 }
255
256 if ( tutor_utils()->is_course_enrolled_by_lesson() ) {
257 $video_info = tutor_utils()->get_video_info();
258 if ( $video_info ) {
259 $stream = new Video_Stream( $video_info->path );
260 $stream->start();
261 }
262 } else {
263 esc_html_e( 'Permission denied', 'tutor' );
264 }
265 exit();
266 }
267
268 return $template;
269 }
270
271 /**
272 * Tutor Dashboard Page, Responsible to show dashboard stuffs
273 *
274 * @since v.1.0.0
275 *
276 * @param string $content page content.
277 *
278 * @return mixed
279 */
280 public function convert_static_page_to_template( $content ) {
281 // Dashboard Page.
282 $student_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
283 if ( get_the_ID() === $student_dashboard_page_id ) {
284 $shortcode = new Shortcode( false );
285 return $shortcode->tutor_dashboard();
286 }
287
288 // Instructor Registration Page.
289 $instructor_register_page_page_id = (int) tutor_utils()->get_option( 'instructor_register_page' );
290 if ( get_the_ID() === $instructor_register_page_page_id ) {
291 $shortcode = new Shortcode( false );
292 return $shortcode->instructor_registration_form();
293 }
294
295 $student_register_page_id = (int) tutor_utils()->get_option( 'student_register_page' );
296 if ( get_the_ID() === $student_register_page_id ) {
297 $shortcode = new Shortcode( false );
298 return $shortcode->student_registration_form();
299 }
300
301 $tutor_cart_page_id = (int) tutor_utils()->get_option( 'tutor_cart_page_id' );
302 if ( get_the_ID() === $tutor_cart_page_id ) {
303 $shortcode = new Shortcode( false );
304 return $shortcode->tutor_cart_page();
305 }
306
307 $tutor_checkout_page_id = (int) tutor_utils()->get_option( 'tutor_checkout_page_id' );
308 if ( get_the_ID() === $tutor_checkout_page_id ) {
309 if ( ! apply_filters( 'tutor_should_load_checkout_page', true ) ) {
310 return;
311 }
312
313 $shortcode = new Shortcode( false );
314 return $shortcode->tutor_checkout_page();
315 }
316
317 return $content;
318 }
319
320 /**
321 * Tutor dashboard
322 *
323 * @since 1.0.0
324 *
325 * @param string $template template name.
326 *
327 * @return string
328 */
329 public function tutor_dashboard( $template ) {
330 global $wp_query;
331 $is_page = apply_filters( 'tutor_determine_is_page', $wp_query->is_page, $template );
332 if ( $is_page ) {
333 $student_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
334 $student_dashboard_page_id = apply_filters( 'tutor_dashboard_page_id_filter', $student_dashboard_page_id );
335 $is_dashboard_page = apply_filters( 'tutor_determine_is_dashboard_page', get_the_ID() == $student_dashboard_page_id );
336
337 if ( $is_dashboard_page ) {
338 /**
339 * Handle if logout URL
340 *
341 * @since v.1.1.2
342 */
343 if ( tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars ) === 'logout' ) {
344 $redirect = apply_filters( 'tutor_dashboard_logout_redirect_url', get_permalink( $student_dashboard_page_id ) );
345 wp_logout();
346 wp_safe_redirect( $redirect );
347 die();
348 }
349
350 $dashboard_page = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars );
351
352 $get_dashboard_config = tutor_utils()->tutor_dashboard_permalinks();
353 $target_dashboard_page = tutor_utils()->array_get( $dashboard_page, $get_dashboard_config );
354
355 if ( isset( $target_dashboard_page['login_require'] ) && false === $target_dashboard_page['login_require'] ) {
356 $template = tutor_load_template_part( "template-part.{$dashboard_page}" );
357 } else {
358
359 /**
360 * Load view page based on dashboard Endpoint
361 */
362 if ( is_user_logged_in() ) {
363
364 global $wp;
365 $full_path = explode( '/', trim( str_replace( get_home_url(), '', home_url( $wp->request ) ), '/' ) );
366
367 $template = tutor_get_template( 'create-course' === end( $full_path ) ? 'dashboard.create-course' : 'dashboard' );
368
369 /**
370 * Check page page permission
371 *
372 * @since 1.3.4
373 */
374 $query_var = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars );
375 $dashboard_pages = tutor_utils()->tutor_dashboard_pages();
376 $dashboard_page_item = tutor_utils()->array_get( $query_var, $dashboard_pages );
377 $auth_cap = tutor_utils()->array_get( 'auth_cap', $dashboard_page_item );
378 if ( $auth_cap && ! current_user_can( $auth_cap ) ) {
379 $template = tutor_get_template( 'permission-denied' );
380 }
381 } else {
382 $template = tutor_get_template( 'login' );
383 }
384 }
385 }
386 }
387 return $template;
388 }
389
390 /**
391 * Load quiz template
392 *
393 * @since 1.0.0
394 *
395 * If course public then enrollment not required
396 *
397 * @since 2.0.2
398 *
399 * @param string $template template to load.
400 *
401 * @return bool|string
402 */
403 public function load_quiz_template( $template ) {
404 global $wp_query, $post;
405
406 if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && 'tutor_quiz' === $wp_query->query_vars['post_type'] ) {
407 if ( is_user_logged_in() ) {
408 $has_content_access = tutor_utils()->has_enrolled_content_access( 'quiz' );
409 $course_id = tutor_utils()->get_course_id_by_content( $post );
410 $is_public = Course_List::is_public( $course_id );
411
412 // if public course don't need to be enrolled.
413 if ( $has_content_access || $is_public ) {
414 $template = tutor_get_template( 'single-quiz' );
415 } else {
416 $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
417 }
418 } else {
419 $template = tutor_get_template( 'login' );
420 }
421 return $template;
422 }
423 return $template;
424 }
425
426 /**
427 * Load assignment template
428 *
429 * @since 1.0.0
430 *
431 * @param string $template template file to load.
432 *
433 * @return string template path
434 */
435 public function load_assignment_template( $template ) {
436 global $wp_query;
437
438 if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && 'tutor_assignments' === $wp_query->query_vars['post_type'] ) {
439 if ( is_user_logged_in() ) {
440 $has_content_access = tutor_utils()->has_enrolled_content_access( 'assignment' );
441 if ( $has_content_access ) {
442 $template = tutor_get_template( 'single-assignment' );
443 } else {
444 $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
445 }
446 } else {
447 $template = tutor_get_template( 'login' );
448 }
449 return $template;
450 }
451
452 return $template;
453 }
454
455 /**
456 * Student public profile
457 *
458 * @since 1.0.0
459 *
460 * @param string $template profile template.
461 *
462 * @return bool|string
463 */
464 public function student_public_profile( $template ) {
465 global $wp_query;
466 $query_var = $wp_query->query_vars;
467 if ( ! empty( $wp_query->query['tutor_profile_username'] ) ) {
468 $template = tutor_get_template( 'public-profile' );
469 }
470
471 return $template;
472 }
473
474 /**
475 * Show student Profile
476 *
477 * @since 1.0.0
478 *
479 * @return string
480 */
481 public function student_public_profile_title() {
482 global $wp_query;
483
484 if ( ! empty( $wp_query->query['tutor_profile_username'] ) ) {
485 global $wpdb;
486
487 $user_name = sanitize_text_field( $wp_query->query['tutor_profile_username'] );
488 $user = $wpdb->get_row( $wpdb->prepare( "SELECT display_name from {$wpdb->users} WHERE user_login = %s limit 1; ", $user_name ) );
489
490 if ( ! empty( $user->display_name ) ) {
491 return sprintf( "%s's %s", $user->display_name, __( 'Profile Page', 'tutor' ) );
492 }
493 }
494 return '';
495 }
496 }
497