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