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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 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 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
406 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_path( 'single-course-enrolled-' . $course_subpage );
148 if ( ! file_exists( $template ) ) {
149 $template = tutor_get_template( 'single-course-enrolled-subpage' );
150 }
151 }else{
152 $template = tutor_get_template('login');
153 }
154 }
155 return $template;
156 }
157 return $template;
158 }
159
160 /**
161 * @param $template
162 *
163 * @return bool|string
164 *
165 * Load lesson template
166 *
167 * @since v.1.0.0
168 */
169
170 public function load_single_lesson_template($template){
171 global $wp_query;
172
173 if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === $this->lesson_post_type){
174 $page_id = get_the_ID();
175
176 do_action('tutor_lesson_load_before', $template);
177
178 setup_postdata($page_id);
179
180 if (is_user_logged_in()){
181 $is_course_enrolled = tutor_utils()->is_course_enrolled_by_lesson();
182
183 if ($is_course_enrolled) {
184 $template = tutor_get_template( 'single-lesson' );
185 }else{
186 //You need to enroll first
187 $template = tutor_get_template( 'single.lesson.required-enroll' );
188
189 //Check Lesson edit access to support page builders
190 if(current_user_can(tutor()->instructor_role) && tutils()->has_lesson_edit_access()){
191 $template = tutor_get_template( 'single-lesson' );
192 }
193 }
194 }else{
195 $template = tutor_get_template('login');
196 }
197 wp_reset_postdata();
198
199 return apply_filters('tutor_lesson_template', $template);
200 }
201 return $template;
202 }
203
204 /**
205 * @param $template
206 *
207 * @return mixed
208 *
209 * Play the video in this url.
210 */
211 public function play_private_video($template){
212 global $wp_query;
213
214 if ($wp_query->is_single && ! empty($wp_query->query_vars['lesson_video']) && $wp_query->query_vars['lesson_video'] === 'true') {
215
216 $isPublicVideo = apply_filters('tutor_video_stream_is_public', false, get_the_ID());
217 if ($isPublicVideo){
218 $video_info = tutor_utils()->get_video_info();
219 if ( $video_info ) {
220 $stream = new Video_Stream( $video_info->path );
221 $stream->start();
222 }
223 exit();
224 }
225
226 if (tutor_utils()->is_course_enrolled_by_lesson()) {
227 $video_info = tutor_utils()->get_video_info();
228 if ( $video_info ) {
229 $stream = new Video_Stream( $video_info->path );
230 $stream->start();
231 }
232 }else{
233 _e('Permission denied', 'tutor');
234 }
235 exit();
236 }
237
238 return $template;
239 }
240
241 /**
242 * @param $content
243 *
244 * @return mixed
245 *
246 * Tutor Dashboard Page, Responsible to show dashboard stuffs
247 *
248 * @since v.1.0.0
249 */
250 public function convert_static_page_to_template($content){
251 //Student Registration Page
252 $student_dashboard_page_id = (int) tutor_utils()->get_option('tutor_dashboard_page_id');
253 if ($student_dashboard_page_id === get_the_ID()){
254 $shortcode = new Shortcode();
255 return $shortcode->tutor_dashboard();
256 }
257
258 //Instructor Registration Page
259 $instructor_register_page_page_id = (int) tutor_utils()->get_option('instructor_register_page');
260 if ($instructor_register_page_page_id === get_the_ID()){
261 $shortcode = new Shortcode();
262 return $shortcode->instructor_registration_form();
263 }
264
265 $student_register_page_id = (int) tutor_utils()->get_option('student_register_page');
266 if ($student_register_page_id === get_the_ID()){
267 $shortcode = new Shortcode();
268 return $shortcode->student_registration_form();
269 }
270
271 return $content;
272 }
273
274 public function tutor_dashboard($template){
275 global $wp_query;
276
277 if ($wp_query->is_page) {
278 $student_dashboard_page_id = (int) tutor_utils()->get_option('tutor_dashboard_page_id');
279 if ($student_dashboard_page_id === get_the_ID()) {
280 /**
281 * Handle if logout URL
282 * @since v.1.1.2
283 */
284 if (tutor_utils()->array_get('tutor_dashboard_page', $wp_query->query_vars) === 'logout'){
285 $redirect = get_permalink($student_dashboard_page_id);
286 wp_logout();
287 wp_redirect($redirect);
288 die();
289 }
290
291
292 $dashboard_page = tutor_utils()->array_get('tutor_dashboard_page', $wp_query->query_vars);
293 $get_dashboard_config = tutils()->tutor_dashboard_permalinks();
294 $target_dashboard_page = tutils()->array_get($dashboard_page, $get_dashboard_config);
295
296 if (isset($target_dashboard_page['login_require']) && $target_dashboard_page['login_require'] === false){
297 $template = tutor_load_template_part( "template-part.{$dashboard_page}" );
298 }else{
299
300 /**
301 * Load view page based on dashboard Endpoint
302 */
303 if (is_user_logged_in()) {
304 $template = tutor_get_template( 'dashboard' );
305 /**
306 * Check page page permission
307 *
308 * @since v.1.3.4
309 */
310 $query_var = tutor_utils()->array_get('tutor_dashboard_page', $wp_query->query_vars);
311 $dashboard_pages = tutor_utils()->tutor_dashboard_pages();
312 $dashboard_page_item = tutor_utils()->array_get($query_var, $dashboard_pages);
313 $auth_cap = tutor_utils()->array_get('auth_cap', $dashboard_page_item);
314 if ($auth_cap && ! current_user_can($auth_cap) ){
315 wp_die(__('Permission Denied', 'tutor'));
316 }
317
318 }else{
319 $template = tutor_get_template( 'login' );
320 }
321
322 }
323
324 }
325 }
326
327 return $template;
328 }
329
330 /**
331 * @param $template
332 *
333 * @return bool|string
334 *
335 * @since v.1.0.0
336 */
337 public function load_quiz_template($template){
338 global $wp_query;
339
340 if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === 'tutor_quiz'){
341 if (is_user_logged_in()){
342 $template = tutor_get_template( 'single-quiz' );
343 }else{
344 $template = tutor_get_template('login');
345 }
346 return $template;
347 }
348 return $template;
349 }
350
351 public function load_assignment_template($template){
352 global $wp_query;
353
354 if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === 'tutor_assignments'){
355 if (is_user_logged_in()){
356 $template = tutor_get_template( 'single-assignment' );
357 }else{
358 $template = tutor_get_template('login');
359 }
360 return $template;
361 }
362
363 return $template;
364 }
365
366 /**
367 * @param $template
368 *
369 * @return bool|string
370 *
371 * @since v.1.0.0
372 */
373 public function student_public_profile($template){
374 global $wp_query;
375
376 if ( ! empty($wp_query->query['tutor_student_username'])){
377 $template = tutor_get_template( 'student-public-profile' );
378 }
379
380 return $template;
381 }
382
383 /**
384 * @return string
385 * Show student Profile
386 *
387 * @since v.1.0.0
388 */
389 public function student_public_profile_title(){
390 global $wp_query;
391
392 if ( ! empty($wp_query->query['tutor_student_username'])){
393 global $wpdb;
394
395 $user_name = sanitize_text_field($wp_query->query['tutor_student_username']);
396 $user = $wpdb->get_row("select display_name from {$wpdb->users} WHERE user_login = '{$user_name}' limit 1; ");
397
398 if ( ! empty($user->display_name)){
399 return sprintf("%s's Profile page ", $user->display_name );
400 }
401 }
402 return '';
403 }
404
405
406 }