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