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