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