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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 6 years ago Admin.php 6 years ago Ajax.php 6 years ago Assets.php 6 years ago Course.php 6 years ago Course_Settings_Tabs.php 6 years ago Course_Widget.php 6 years ago Dashboard.php 6 years ago Email.php 6 years ago FormHandler.php 6 years ago Frontend.php 6 years ago Gutenberg.php 6 years ago Instructor.php 6 years ago Instructors_List.php 6 years ago Lesson.php 6 years ago Options.php 6 years ago Post_types.php 6 years ago Q_and_A.php 6 years ago Question_Answers_List.php 6 years ago Quiz.php 6 years ago Quiz_Attempts_List.php 6 years ago RestAPI.php 6 years ago Rewrite_Rules.php 6 years ago Shortcode.php 6 years ago Student.php 6 years ago Students_List.php 6 years ago Taxonomies.php 6 years ago Template.php 6 years ago Theme_Compatibility.php 6 years ago Tools.php 6 years ago Tutor.php 6 years ago TutorEDD.php 6 years ago Tutor_Base.php 6 years ago Tutor_List_Table.php 6 years ago Upgrader.php 6 years ago User.php 6 years ago Utils.php 6 years ago Video_Stream.php 6 years ago Withdraw.php 6 years ago Withdraw_Requests_List.php 6 years ago WooCommerce.php 6 years ago
Template.php
418 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'), 1 );
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 if ($query->is_main_query() && ! $query->is_feed() && ! is_admin() && is_page() ){
80 $queried_object = get_queried_object();
81 if ($queried_object instanceof \WP_Post){
82 $page_id = $queried_object->ID;
83 $selected_archive_page = (int) tutor_utils()->get_option('course_archive_page');
84
85 if ($page_id === $selected_archive_page){
86 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
87 query_posts(array('post_type' => $this->course_post_type, 'paged' => $paged ));
88 }
89 }
90 }
91
92 if ( $query->is_archive && $query->is_main_query() && ! $query->is_feed() && ! is_admin() ){
93 $post_type = get_query_var('post_type');
94 $course_category = get_query_var('course-category');
95 if ( ($post_type === $this->course_post_type || ! empty($course_category) )){
96 $courses_per_page = (int) tutor_utils()->get_option('courses_per_page', 10);
97 $query->set('posts_per_page', $courses_per_page);
98
99 $course_filter = 'newest_first';
100 if ( ! empty($_GET['tutor_course_filter'])){
101 $course_filter = sanitize_text_field($_GET['tutor_course_filter']);
102 }
103 switch ($course_filter){
104 case 'newest_first':
105 $query->set('orderby', 'ID');
106 $query->set('order', 'desc');
107 break;
108 case 'oldest_first':
109 $query->set('orderby', 'ID');
110 $query->set('order', 'asc');
111 break;
112 case 'course_title_az':
113 $query->set('orderby', 'post_title');
114 $query->set('order', 'asc');
115 break;
116 case 'course_title_za':
117 $query->set('orderby', 'post_title');
118 $query->set('order', 'desc');
119 break;
120 }
121
122 }
123 }
124 }
125
126 /**
127 * @param $template
128 *
129 * @return bool|string
130 *
131 * Load Single Course Template
132 *
133 * @since v.1.0.0
134 * @updated v.1.3.5
135 */
136 public function load_single_course_template($template){
137 global $wp_query;
138
139 if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === $this->course_post_type){
140 $student_must_login_to_view_course = tutor_utils()->get_option('student_must_login_to_view_course');
141 if ($student_must_login_to_view_course){
142 if ( ! is_user_logged_in() ) {
143 return tutor_get_template( 'login' );
144 }
145 }
146
147 wp_reset_query();
148 if (empty( $wp_query->query_vars['course_subpage'])) {
149 $template = tutor_get_template( 'single-course' );
150 if ( is_user_logged_in() ) {
151 if ( tutor_utils()->is_enrolled() ) {
152 $template = tutor_get_template( 'single-course-enrolled' );
153 }
154 }
155 }else{
156 //If Course Subpage Exists
157 if ( is_user_logged_in() ) {
158 $course_subpage = $wp_query->query_vars['course_subpage'];
159 $template = tutor_get_template_path( 'single-course-enrolled-' . $course_subpage );
160 if ( ! file_exists( $template ) ) {
161 $template = tutor_get_template( 'single-course-enrolled-subpage' );
162 }
163 }else{
164 $template = tutor_get_template('login');
165 }
166 }
167 return $template;
168 }
169 return $template;
170 }
171
172 /**
173 * @param $template
174 *
175 * @return bool|string
176 *
177 * Load lesson template
178 *
179 * @since v.1.0.0
180 */
181
182 public function load_single_lesson_template($template){
183 global $wp_query;
184
185 if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === $this->lesson_post_type){
186 $page_id = get_the_ID();
187
188 do_action('tutor_lesson_load_before', $template);
189
190 setup_postdata($page_id);
191
192 if (is_user_logged_in()){
193 $is_course_enrolled = tutor_utils()->is_course_enrolled_by_lesson();
194
195 if ($is_course_enrolled) {
196 $template = tutor_get_template( 'single-lesson' );
197 }else{
198 //You need to enroll first
199 $template = tutor_get_template( 'single.lesson.required-enroll' );
200
201 //Check Lesson edit access to support page builders
202 if(current_user_can(tutor()->instructor_role) && tutils()->has_lesson_edit_access()){
203 $template = tutor_get_template( 'single-lesson' );
204 }
205 }
206 }else{
207 $template = tutor_get_template('login');
208 }
209 wp_reset_postdata();
210
211 return apply_filters('tutor_lesson_template', $template);
212 }
213 return $template;
214 }
215
216 /**
217 * @param $template
218 *
219 * @return mixed
220 *
221 * Play the video in this url.
222 */
223 public function play_private_video($template){
224 global $wp_query;
225
226 if ($wp_query->is_single && ! empty($wp_query->query_vars['lesson_video']) && $wp_query->query_vars['lesson_video'] === 'true') {
227
228 $isPublicVideo = apply_filters('tutor_video_stream_is_public', false, get_the_ID());
229 if ($isPublicVideo){
230 $video_info = tutor_utils()->get_video_info();
231 if ( $video_info ) {
232 $stream = new Video_Stream( $video_info->path );
233 $stream->start();
234 }
235 exit();
236 }
237
238 if (tutor_utils()->is_course_enrolled_by_lesson()) {
239 $video_info = tutor_utils()->get_video_info();
240 if ( $video_info ) {
241 $stream = new Video_Stream( $video_info->path );
242 $stream->start();
243 }
244 }else{
245 _e('Permission denied', 'tutor');
246 }
247 exit();
248 }
249
250 return $template;
251 }
252
253 /**
254 * @param $content
255 *
256 * @return mixed
257 *
258 * Tutor Dashboard Page, Responsible to show dashboard stuffs
259 *
260 * @since v.1.0.0
261 */
262 public function convert_static_page_to_template($content){
263 //Dashboard Page
264 $student_dashboard_page_id = (int) tutor_utils()->get_option('tutor_dashboard_page_id');
265 if ($student_dashboard_page_id === get_the_ID()){
266 $shortcode = new Shortcode();
267 return $shortcode->tutor_dashboard();
268 }
269
270 //Instructor Registration Page
271 $instructor_register_page_page_id = (int) tutor_utils()->get_option('instructor_register_page');
272 if ($instructor_register_page_page_id === get_the_ID()){
273 $shortcode = new Shortcode();
274 return $shortcode->instructor_registration_form();
275 }
276
277 $student_register_page_id = (int) tutor_utils()->get_option('student_register_page');
278 if ($student_register_page_id === get_the_ID()){
279 $shortcode = new Shortcode();
280 return $shortcode->student_registration_form();
281 }
282
283 return $content;
284 }
285
286 public function tutor_dashboard($template){
287 global $wp_query;
288
289 if ($wp_query->is_page) {
290 $student_dashboard_page_id = (int) tutor_utils()->get_option('tutor_dashboard_page_id');
291 if ($student_dashboard_page_id === get_the_ID()) {
292 /**
293 * Handle if logout URL
294 * @since v.1.1.2
295 */
296 if (tutor_utils()->array_get('tutor_dashboard_page', $wp_query->query_vars) === 'logout'){
297 $redirect = get_permalink($student_dashboard_page_id);
298 wp_logout();
299 wp_redirect($redirect);
300 die();
301 }
302
303
304 $dashboard_page = tutor_utils()->array_get('tutor_dashboard_page', $wp_query->query_vars);
305 $get_dashboard_config = tutils()->tutor_dashboard_permalinks();
306 $target_dashboard_page = tutils()->array_get($dashboard_page, $get_dashboard_config);
307
308 if (isset($target_dashboard_page['login_require']) && $target_dashboard_page['login_require'] === false){
309 $template = tutor_load_template_part( "template-part.{$dashboard_page}" );
310 }else{
311
312 /**
313 * Load view page based on dashboard Endpoint
314 */
315 if (is_user_logged_in()) {
316 $template = tutor_get_template( 'dashboard' );
317 /**
318 * Check page page permission
319 *
320 * @since v.1.3.4
321 */
322 $query_var = tutor_utils()->array_get('tutor_dashboard_page', $wp_query->query_vars);
323 $dashboard_pages = tutor_utils()->tutor_dashboard_pages();
324 $dashboard_page_item = tutor_utils()->array_get($query_var, $dashboard_pages);
325 $auth_cap = tutor_utils()->array_get('auth_cap', $dashboard_page_item);
326 if ($auth_cap && ! current_user_can($auth_cap) ){
327 wp_die(__('Permission Denied', 'tutor'));
328 }
329
330 }else{
331 $template = tutor_get_template( 'login' );
332 }
333
334 }
335
336 }
337 }
338
339 return $template;
340 }
341
342 /**
343 * @param $template
344 *
345 * @return bool|string
346 *
347 * @since v.1.0.0
348 */
349 public function load_quiz_template($template){
350 global $wp_query;
351
352 if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === 'tutor_quiz'){
353 if (is_user_logged_in()){
354 $template = tutor_get_template( 'single-quiz' );
355 }else{
356 $template = tutor_get_template('login');
357 }
358 return $template;
359 }
360 return $template;
361 }
362
363 public function load_assignment_template($template){
364 global $wp_query;
365
366 if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === 'tutor_assignments'){
367 if (is_user_logged_in()){
368 $template = tutor_get_template( 'single-assignment' );
369 }else{
370 $template = tutor_get_template('login');
371 }
372 return $template;
373 }
374
375 return $template;
376 }
377
378 /**
379 * @param $template
380 *
381 * @return bool|string
382 *
383 * @since v.1.0.0
384 */
385 public function student_public_profile($template){
386 global $wp_query;
387
388 if ( ! empty($wp_query->query['tutor_student_username'])){
389 $template = tutor_get_template( 'student-public-profile' );
390 }
391
392 return $template;
393 }
394
395 /**
396 * @return string
397 * Show student Profile
398 *
399 * @since v.1.0.0
400 */
401 public function student_public_profile_title(){
402 global $wp_query;
403
404 if ( ! empty($wp_query->query['tutor_student_username'])){
405 global $wpdb;
406
407 $user_name = sanitize_text_field($wp_query->query['tutor_student_username']);
408 $user = $wpdb->get_row("select display_name from {$wpdb->users} WHERE user_login = '{$user_name}' limit 1; ");
409
410 if ( ! empty($user->display_name)){
411 return sprintf("%s's Profile page ", $user->display_name );
412 }
413 }
414 return '';
415 }
416
417
418 }