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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 / Tutor.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 Taxonomies.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
Tutor.php
565 lines
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) )
5 exit;
6
7 final class Tutor{
8 public $version = TUTOR_VERSION;
9 public $path;
10 public $url;
11 public $basename;
12
13 /**
14 * The single instance of the class.
15 *
16 * @since v.1.2.0
17 */
18 protected static $_instance = null;
19
20 //Components
21 public $utils;
22 public $admin;
23 public $ajax;
24 public $options;
25 public $shortcode;
26
27 private $addons;
28 private $post_types;
29 private $taxonomies;
30 private $assets;
31 private $course;
32 private $lesson;
33 private $rewrite_rules;
34 private $template;
35 private $instructor;
36 private $student;
37 private $q_and_a;
38 private $quiz;
39 private $question;
40 private $tools;
41 private $user;
42 private $theme_compatibility;
43 private $gutenberg;
44
45 private $woocommerce;
46 private $edd;
47 private $withdraw;
48
49 /**
50 * @return null|Tutor
51 *
52 * Run the TUTOR
53 *
54 * @since 1.2.0
55 */
56 public static function instance() {
57 if ( is_null( self::$_instance ) ) {
58 self::$_instance = new self();
59 }
60 return self::$_instance;
61 }
62
63 function __construct() {
64
65 $this->path = plugin_dir_path(TUTOR_FILE);
66 $this->url = plugin_dir_url(TUTOR_FILE);
67 $this->basename = plugin_basename(TUTOR_FILE);
68
69 /**
70 * Include Files
71 */
72 //add_action( 'init', array( $this, 'includes' ), 11 );
73 $this->includes();
74
75 /**
76 * Loading Autoloader
77 */
78
79 if ( function_exists( '__autoload' ) ) {
80 spl_autoload_register( '__autoload' );
81 }
82 spl_autoload_register(array($this, 'loader'));
83
84 do_action('tutor_before_load');
85
86 $this->addons = new Addons();
87 $this->post_types = new Post_types();
88 $this->taxonomies = new Taxonomies();
89 $this->assets = new Assets();
90 $this->admin = new Admin();
91 $this->ajax = new Ajax();
92 $this->options = new Options();
93 $this->shortcode = new Shortcode();
94 $this->course = new Course();
95 $this->lesson = new Lesson();
96 $this->rewrite_rules = new Rewrite_Rules();
97 $this->template = new Template();
98 $this->instructor = new Instructor();
99 $this->student = new Student();
100 $this->q_and_a = new Q_and_A();
101 $this->quiz = new Quiz();
102 $this->question = new Question();
103 $this->tools = new Tools();
104 $this->user = new User();
105 $this->theme_compatibility = new Theme_Compatibility();
106 $this->gutenberg = new Gutenberg();
107 $this->woocommerce = new WooCommerce();
108 $this->edd = new TutorEDD();
109 $this->withdraw = new Withdraw();
110
111 /**
112 * Run Method
113 * @since v.1.2.0
114 */
115 $this->run();
116
117 do_action('tutor_loaded');
118
119
120 add_action( 'init', array( $this, 'init_action' ) );
121 }
122 /**
123 * @param $className
124 *
125 * Auto Load class and the files
126 */
127 private function loader($className) {
128 if ( ! class_exists($className)){
129 $className = preg_replace(
130 array('/([a-z])([A-Z])/', '/\\\/'),
131 array('$1$2', DIRECTORY_SEPARATOR),
132 $className
133 );
134
135 $className = str_replace('TUTOR'.DIRECTORY_SEPARATOR, 'classes'.DIRECTORY_SEPARATOR, $className);
136 $file_name = $this->path.$className.'.php';
137
138 if (file_exists($file_name) ) {
139 require_once $file_name;
140 }
141 }
142 }
143
144 public function includes(){
145 include tutor()->path.'includes/tutor-general-functions.php';
146 include tutor()->path.'includes/tutor-template-functions.php';
147 include tutor()->path.'includes/tutor-template-hook.php';
148 }
149
150 //Run the TUTOR right now
151 public function run(){
152 do_action('tutor_before_run');
153
154 register_activation_hook( TUTOR_FILE, array($this, 'tutor_activate' ) );
155 register_deactivation_hook(TUTOR_FILE, array($this, 'tutor_deactivation'));
156
157 do_action('tutor_after_run');
158 }
159
160 /**
161 * Tutor Action Via do_action
162 * @since 1.2.14
163 */
164 public function init_action(){
165 if (isset($_REQUEST['tutor_action'])){
166 do_action('tutor_action_'.$_REQUEST['tutor_action']);
167 }
168 }
169
170 /**
171 * Do some task during plugin activation
172 */
173 public function tutor_activate(){
174 $version = get_option('tutor_version');
175 //Save Option
176 if ( ! $version){
177 //Create Database
178 $this->create_database();
179
180 $options = self::default_options();
181 update_option('tutor_option', $options);
182
183 //Rewrite Flush
184 update_option('required_rewrite_flush', time());
185 self::manage_tutor_roles_and_permissions();
186
187 self::save_data();//Save initial Page
188 update_option('tutor_version', TUTOR_VERSION);
189 }
190
191 //Set Schedule
192 if (! wp_next_scheduled ( 'tutor_once_in_day_run_schedule' )) {
193 wp_schedule_event(time(), 'twicedaily', 'tutor_once_in_day_run_schedule');
194 }
195
196 /**
197 * Backward Compatibility for version < 1.2.0
198 */
199 if (version_compare(get_option('TUTOR_VERSION'), '1.2.0', '<')){
200 /**
201 * Creating New Database
202 */
203 $this->create_withdraw_database();
204 //Update the tutor version
205 update_option('tutor_version', '1.2.0');
206 //Rewrite Flush
207 update_option('required_rewrite_flush', time());
208 }
209
210 }
211
212 //Run task on deactivation
213 public function tutor_deactivation() {
214 wp_clear_scheduled_hook('tutor_once_in_day_run_schedule');
215 }
216
217 public function create_database(){
218 global $wpdb;
219
220 $charset_collate = $wpdb->get_charset_collate();
221
222 /**
223 * Table SQL
224 *
225 * {$wpdb->prefix}tutor_quiz_attempts
226 * {$wpdb->prefix}tutor_quiz_attempt_answers
227 * {$wpdb->prefix}tutor_quiz_questions
228 * {$wpdb->prefix}tutor_quiz_question_answers
229 * {$wpdb->prefix}tutor_earnings
230 * {$wpdb->prefix}tutor_withdraws
231 *
232 * @since v.1.0.0
233 */
234 $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts (
235 attempt_id int(11) NOT NULL AUTO_INCREMENT,
236 course_id int(11) DEFAULT NULL,
237 quiz_id int(11) DEFAULT NULL,
238 user_id int(11) DEFAULT NULL,
239 total_questions int(11) DEFAULT NULL,
240 total_answered_questions int(11) DEFAULT NULL,
241 total_marks decimal(9,2) DEFAULT NULL,
242 earned_marks decimal(9,2) DEFAULT NULL,
243 attempt_info text,
244 attempt_status varchar(50) DEFAULT NULL,
245 attempt_ip varchar(250) DEFAULT NULL,
246 attempt_started_at datetime DEFAULT NULL,
247 attempt_ended_at datetime DEFAULT NULL,
248 is_manually_reviewed int(1) DEFAULT NULL,
249 manually_reviewed_at datetime DEFAULT NULL,
250 PRIMARY KEY (attempt_id)
251 ) $charset_collate;";
252
253 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
254 attempt_answer_id int(11) NOT NULL AUTO_INCREMENT,
255 user_id int(11) DEFAULT NULL,
256 quiz_id int(11) DEFAULT NULL,
257 question_id int(11) DEFAULT NULL,
258 quiz_attempt_id int(11) DEFAULT NULL,
259 given_answer longtext,
260 question_mark decimal(8,2) DEFAULT NULL,
261 achieved_mark decimal(8,2) DEFAULT NULL,
262 minus_mark decimal(8,2) DEFAULT NULL,
263 is_correct tinyint(4) DEFAULT NULL,
264 PRIMARY KEY (attempt_answer_id)
265 ) $charset_collate;";
266
267 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
268 question_id int(11) NOT NULL AUTO_INCREMENT,
269 quiz_id int(11) DEFAULT NULL,
270 question_title text,
271 question_description longtext,
272 question_type varchar(50) DEFAULT NULL,
273 question_mark decimal(9,2) DEFAULT NULL,
274 question_settings longtext,
275 question_order int(11) DEFAULT NULL,
276 PRIMARY KEY (question_id)
277 ) $charset_collate;";
278
279 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
280 answer_id int(11) NOT NULL AUTO_INCREMENT,
281 belongs_question_id int(11) DEFAULT NULL,
282 belongs_question_type varchar(250) DEFAULT NULL,
283 answer_title text,
284 is_correct tinyint(4) DEFAULT NULL,
285 image_id int(11) DEFAULT NULL,
286 answer_two_gap_match text,
287 answer_view_format varchar(250) DEFAULT NULL,
288 answer_settings text,
289 answer_order int(11) DEFAULT '0',
290 PRIMARY KEY (answer_id)
291 ) $charset_collate;";
292
293 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
294 earning_id int(11) NOT NULL AUTO_INCREMENT,
295 user_id int(11) DEFAULT NULL,
296 course_id int(11) DEFAULT NULL,
297 order_id int(11) DEFAULT NULL,
298 order_status varchar(50) DEFAULT NULL,
299 course_price_total decimal(16,2) DEFAULT NULL,
300 course_price_grand_total decimal(16,2) DEFAULT NULL,
301 instructor_amount decimal(16,2) DEFAULT NULL,
302 instructor_rate decimal(16,2) DEFAULT NULL,
303 admin_amount decimal(16,2) DEFAULT NULL,
304 admin_rate decimal(16,2) DEFAULT NULL,
305 commission_type varchar(20) DEFAULT NULL,
306 deduct_fees_amount decimal(16,2) DEFAULT NULL,
307 deduct_fees_name varchar(250) DEFAULT NULL,
308 deduct_fees_type varchar(20) DEFAULT NULL,
309 process_by varchar(20) DEFAULT NULL,
310 created_at datetime DEFAULT NULL,
311 PRIMARY KEY (earning_id)
312 ) $charset_collate;";
313
314 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
315 withdraw_id int(11) NOT NULL AUTO_INCREMENT,
316 user_id int(11) DEFAULT NULL,
317 amount decimal(16,2) DEFAULT NULL,
318 method_data text DEFAULT NULL,
319 status varchar(50) DEFAULT NULL,
320 updated_at datetime DEFAULT NULL,
321 created_at datetime DEFAULT NULL,
322 PRIMARY KEY (withdraw_id)
323 ) $charset_collate;";
324
325 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
326 dbDelta( $quiz_attempts_sql );
327 dbDelta( $quiz_attempt_answers );
328 dbDelta( $tutor_quiz_questions );
329 dbDelta( $tutor_quiz_question_answers );
330 dbDelta( $earning_table );
331 dbDelta( $withdraw_table );
332 }
333
334 public static function manage_tutor_roles_and_permissions(){
335 /**
336 * Add role for instructor
337 */
338 $instructor_role = tutor()->instructor_role;
339
340 remove_role($instructor_role);
341 add_role( $instructor_role, __('Tutor Instructor', 'tutor'), array() );
342
343 $custom_post_type_permission = array(
344 //Manage Instructor
345 'manage_tutor_instructor',
346
347 //Tutor Posts Type Permission
348 'edit_tutor_course',
349 'read_tutor_course',
350 'delete_tutor_course',
351 'delete_tutor_courses',
352 'edit_tutor_courses',
353 'edit_others_tutor_courses',
354 'read_private_tutor_courses',
355 'edit_tutor_courses',
356
357 'edit_tutor_lesson',
358 'read_tutor_lesson',
359 'delete_tutor_lesson',
360 'delete_tutor_lessons',
361 'edit_tutor_lessons',
362 'edit_others_tutor_lessons',
363 'read_private_tutor_lessons',
364 'edit_tutor_lessons',
365 'publish_tutor_lessons',
366
367 'edit_tutor_quiz',
368 'read_tutor_quiz',
369 'delete_tutor_quiz',
370 'delete_tutor_quizzes',
371 'edit_tutor_quizzes',
372 'edit_others_tutor_quizzes',
373 'read_private_tutor_quizzes',
374 'edit_tutor_quizzes',
375 'publish_tutor_quizzes',
376
377 'edit_tutor_question',
378 'read_tutor_question',
379 'delete_tutor_question',
380 'delete_tutor_questions',
381 'edit_tutor_questions',
382 'edit_others_tutor_questions',
383 'publish_tutor_questions',
384 'read_private_tutor_questions',
385 'edit_tutor_questions',
386 );
387
388 $instructor = get_role( $instructor_role );
389 if ( $instructor ) {
390 $instructor_cap = array (
391 'edit_posts',
392 'read',
393 'upload_files',
394 );
395
396 $instructor_cap = array_merge($instructor_cap, $custom_post_type_permission);
397
398 $can_publish_course = (bool) tutor_utils()->get_option('instructor_can_publish_course');
399 if ($can_publish_course){
400 $instructor_cap[] = 'publish_tutor_courses';
401 }
402
403 foreach ($instructor_cap as $cap){
404 $instructor->add_cap( $cap );
405 }
406 }
407
408 $administrator = get_role( 'administrator' );
409 if ( $administrator ) {
410
411 $administrator_cap = array (
412 'manage_tutor',
413 );
414 $administrator_cap = array_merge($administrator_cap, $custom_post_type_permission);
415 $administrator_cap[] = 'publish_tutor_courses';
416
417 foreach ($administrator_cap as $cap){
418 $administrator->add_cap( $cap );
419 }
420 }
421
422 /**
423 * Add Instructor role to administrator
424 */
425 if (current_user_can('administrator')){
426 tutor_utils()->add_instructor_role(get_current_user_id());
427 }
428
429 }
430
431 /**
432 * Save data like page
433 */
434 public static function save_data(){
435 $student_dashboard_args = array(
436 'post_title' => __('Dashboard', 'tutor'),
437 'post_content' => '',
438 'post_type' => 'page',
439 'post_status' => 'publish',
440 );
441 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
442 tutor_utils()->update_option('tutor_dashboard_page_id', $student_dashboard_page_id);
443
444 $student_registration_args = array(
445 'post_title' => __('Student Registration', 'tutor'),
446 'post_content' => '[tutor_student_registration_form]',
447 'post_type' => 'page',
448 'post_status' => 'publish',
449 );
450 $student_register_page_id = wp_insert_post( $student_registration_args );
451 tutor_utils()->update_option('student_register_page', $student_register_page_id);
452
453 $instructor_registration_args = array(
454 'post_title' => __('Instructor Registration', 'tutor'),
455 'post_content' => '[tutor_instructor_registration_form]',
456 'post_type' => 'page',
457 'post_status' => 'publish',
458 );
459 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
460 tutor_utils()->update_option('instructor_register_page', $instructor_registration_id);
461 }
462
463 public static function default_options(){
464 $options = array (
465 'load_tutor_css' => '1',
466 'load_tutor_js' => '1',
467 'course_allow_upload_private_files' => '1',
468 'display_course_instructors' => '1',
469 'enable_q_and_a_on_course' => '1',
470 'courses_col_per_row' => '3',
471 'courses_per_page' => '3',
472 'lesson_permalink_base' => 'lesson',
473 'quiz_time_limit' =>
474 array (
475 'value' => '0',
476 'time' => 'minutes',
477 ),
478 'quiz_when_time_expires' => 'autosubmit',
479 'quiz_attempts_allowed' => '10',
480 'quiz_grade_method' => 'highest_grade',
481 'enable_public_profile' => '1',
482 'email_to_students' =>
483 array (
484 'quiz_completed' => '1',
485 'completed_course' => '1',
486 ),
487 'email_to_instructors' =>
488 array (
489 'a_student_enrolled_in_course' => '1',
490 'a_student_completed_course' => '1',
491 'a_student_completed_lesson' => '1',
492 'a_student_placed_question' => '1',
493 ),
494 'email_from_name' => get_option('blogname'),
495 'email_from_address' => get_option('admin_email'),
496 'email_footer_text' => '',
497 );
498 return $options;
499 }
500
501
502 /**
503 * Create withdraw database
504 *
505 * @since v.1.2.0
506 */
507 public function create_withdraw_database(){
508 global $wpdb;
509
510 $charset_collate = $wpdb->get_charset_collate();
511
512 /**
513 * Table SQL
514 *
515 * {$wpdb->prefix}tutor_earnings
516 * {$wpdb->prefix}tutor_withdraws
517 *
518 * @since v.1.2.0
519 */
520
521 $earning_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_earnings (
522 earning_id int(11) NOT NULL AUTO_INCREMENT,
523 user_id int(11) DEFAULT NULL,
524 course_id int(11) DEFAULT NULL,
525 order_id int(11) DEFAULT NULL,
526 order_status varchar(50) DEFAULT NULL,
527 course_price_total decimal(16,2) DEFAULT NULL,
528 course_price_grand_total decimal(16,2) DEFAULT NULL,
529 instructor_amount decimal(16,2) DEFAULT NULL,
530 instructor_rate decimal(16,2) DEFAULT NULL,
531 admin_amount decimal(16,2) DEFAULT NULL,
532 admin_rate decimal(16,2) DEFAULT NULL,
533 commission_type varchar(20) DEFAULT NULL,
534 deduct_fees_amount decimal(16,2) DEFAULT NULL,
535 deduct_fees_name varchar(250) DEFAULT NULL,
536 deduct_fees_type varchar(20) DEFAULT NULL,
537 process_by varchar(20) DEFAULT NULL,
538 created_at datetime DEFAULT NULL,
539 PRIMARY KEY (earning_id)
540 ) $charset_collate;";
541
542 $withdraw_table = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tutor_withdraws (
543 withdraw_id int(11) NOT NULL AUTO_INCREMENT,
544 user_id int(11) DEFAULT NULL,
545 amount decimal(16,2) DEFAULT NULL,
546 method_data text DEFAULT NULL,
547 status varchar(50) DEFAULT NULL,
548 updated_at datetime DEFAULT NULL,
549 created_at datetime DEFAULT NULL,
550 PRIMARY KEY (withdraw_id)
551 ) $charset_collate;";
552
553 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
554 dbDelta( $earning_table );
555 dbDelta( $withdraw_table );
556
557 /**
558 * Setting previous dashboard to new dashboard
559 */
560 $previous_dashboard_page_id = (int) tutor_utils()->get_option('student_dashboard');
561 tutor_utils()->update_option('tutor_dashboard_page_id', $previous_dashboard_page_id);
562 }
563
564
565 }