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