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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 / init.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 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 WooCommerce.php 7 years ago init.php 7 years ago
init.php
435 lines
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) )
5 exit;
6
7 class init{
8 public $version = TUTOR_VERSION;
9 public $path;
10 public $url;
11 public $basename;
12
13 //Components
14 public $utils;
15 public $admin;
16 public $ajax;
17 public $options;
18 public $shortcode;
19
20 private $post_types;
21 private $assets;
22 private $course;
23 private $lesson;
24 private $rewrite_rules;
25 private $template;
26 private $instructor;
27 private $student;
28 private $q_and_a;
29 private $quiz;
30 private $question;
31 private $tools;
32 private $user;
33 private $theme_compatibility;
34 private $gutenberg;
35
36 private $woocommerce;
37 private $edd;
38
39 function __construct() {
40
41 $this->path = plugin_dir_path(TUTOR_FILE);
42 $this->url = plugin_dir_url(TUTOR_FILE);
43 $this->basename = plugin_basename(TUTOR_FILE);
44
45 /**
46 * Include Files
47 */
48 add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
49
50 /**
51 * Loading Autoloader
52 */
53
54 spl_autoload_register(array($this, 'loader'));
55
56 do_action('tutor_before_load');
57
58 $this->post_types = new Post_types();
59 $this->assets = new Assets();
60 $this->admin = new Admin();
61 $this->ajax = new Ajax();
62 $this->options = new Options();
63 $this->shortcode = new Shortcode();
64 $this->course = new Course();
65 $this->lesson = new Lesson();
66 $this->rewrite_rules = new Rewrite_Rules();
67 $this->template = new Template();
68 $this->instructor = new Instructor();
69 $this->student = new Student();
70 $this->q_and_a = new Q_and_A();
71 $this->quiz = new Quiz();
72 $this->question = new Question();
73 $this->tools = new Tools();
74 $this->user = new User();
75 $this->theme_compatibility = new Theme_Compatibility();
76 $this->gutenberg = new Gutenberg();
77 $this->woocommerce = new WooCommerce();
78 $this->edd = new TutorEDD();
79
80 do_action('tutor_loaded');
81 }
82 /**
83 * @param $className
84 *
85 * Auto Load class and the files
86 */
87 private function loader($className) {
88 if ( ! class_exists($className)){
89 $className = preg_replace(
90 array('/([a-z])([A-Z])/', '/\\\/'),
91 array('$1$2', DIRECTORY_SEPARATOR),
92 $className
93 );
94
95 $className = str_replace('TUTOR/', 'classes/', $className);
96 $file_name = $this->path.$className.'.php';
97
98 if (file_exists($file_name) ) {
99 require_once $file_name;
100 }
101 }
102 }
103
104 public function include_template_functions(){
105 include tutor()->path.'includes/tutor-template-functions.php';
106 include tutor()->path.'includes/tutor-template-hook.php';
107 }
108
109 //Run the TUTOR right now
110 public function run(){
111 do_action('tutor_before_run');
112
113 register_activation_hook( TUTOR_FILE, array( $this, 'tutor_activate' ) );
114 register_deactivation_hook(TUTOR_FILE, array($this, 'tutor_deactivation'));
115
116 do_action('tutor_after_run');
117 }
118
119 /**
120 * Do some task during plugin activation
121 */
122 public function tutor_activate(){
123 $version = get_option('tutor_version');
124 //Save Option
125 if ( ! $version){
126 //Create Database
127 $this->create_database();
128
129 $options = self::default_options();
130 update_option('tutor_option', $options);
131
132 //Rewrite Flush
133 update_option('required_rewrite_flush', time());
134 self::manage_tutor_roles_and_permissions();
135
136 self::save_data();//Save initial Page
137 update_option('tutor_version', TUTOR_VERSION);
138 }
139
140 //Set Schedule
141 if (! wp_next_scheduled ( 'tutor_once_in_day_run_schedule' )) {
142 wp_schedule_event(time(), 'twicedaily', 'tutor_once_in_day_run_schedule');
143 }
144
145 /**
146 * backward / Alpha version compatibility
147 * todo: should remove in version 1.1.0
148 */
149 if (version_compare(get_option('TUTOR_VERSION'), '1.0.0', '<')){
150 //Create Database
151 $this->create_database();
152 update_option('tutor_version', '1.0.0');
153 }
154 /**
155 * backward / v.1.0.0 compatibility
156 * todo: should remove in version 1.1.0
157 */
158 if (get_option('TUTOR_VERSION') == '1.0.0' && version_compare(get_option('TUTOR_VERSION'), '1.0.1', '<')){
159 //Adding column course_id in prefix_tutor_quiz_attempts
160 $this->upgrading_db_1_0_1();
161 update_option('tutor_version', '1.0.1');
162 }
163
164 }
165
166 //Run task on deactivation
167 public function tutor_deactivation() {
168 wp_clear_scheduled_hook('tutor_once_in_day_run_schedule');
169 }
170
171 public function create_database(){
172 global $wpdb;
173
174 $charset_collate = $wpdb->get_charset_collate();
175
176 /**
177 * Table SQL
178 *
179 * {$wpdb->prefix}tutor_quiz_attempts
180 * {$wpdb->prefix}tutor_quiz_attempt_answers
181 * {$wpdb->prefix}tutor_quiz_questions
182 * {$wpdb->prefix}tutor_quiz_question_answers
183 *
184 * @since v.1.0.0
185 */
186 $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts (
187 attempt_id int(11) NOT NULL AUTO_INCREMENT,
188 course_id int(11) DEFAULT NULL,
189 quiz_id int(11) DEFAULT NULL,
190 user_id int(11) DEFAULT NULL,
191 total_questions int(11) DEFAULT NULL,
192 total_answered_questions int(11) DEFAULT NULL,
193 total_marks decimal(9,2) DEFAULT NULL,
194 earned_marks decimal(9,2) DEFAULT NULL,
195 attempt_info text,
196 attempt_status varchar(50) DEFAULT NULL,
197 attempt_ip varchar(250) DEFAULT NULL,
198 attempt_started_at datetime DEFAULT NULL,
199 attempt_ended_at datetime DEFAULT NULL,
200 is_manually_reviewed int(1) DEFAULT NULL,
201 manually_reviewed_at datetime DEFAULT NULL,
202 PRIMARY KEY (attempt_id)
203 ) $charset_collate;";
204
205 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
206 attempt_answer_id int(11) NOT NULL AUTO_INCREMENT,
207 user_id int(11) DEFAULT NULL,
208 quiz_id int(11) DEFAULT NULL,
209 question_id int(11) DEFAULT NULL,
210 quiz_attempt_id int(11) DEFAULT NULL,
211 given_answer longtext,
212 question_mark decimal(8,2) DEFAULT NULL,
213 achieved_mark decimal(8,2) DEFAULT NULL,
214 minus_mark decimal(8,2) DEFAULT NULL,
215 is_correct tinyint(4) DEFAULT NULL,
216 PRIMARY KEY (attempt_answer_id)
217 ) $charset_collate;";
218
219 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
220 question_id int(11) NOT NULL AUTO_INCREMENT,
221 quiz_id int(11) DEFAULT NULL,
222 question_title text,
223 question_description longtext,
224 question_type varchar(50) DEFAULT NULL,
225 question_mark decimal(9,2) DEFAULT NULL,
226 question_settings longtext,
227 question_order int(11) DEFAULT NULL,
228 PRIMARY KEY (question_id)
229 ) $charset_collate;";
230
231 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
232 answer_id int(11) NOT NULL AUTO_INCREMENT,
233 belongs_question_id int(11) DEFAULT NULL,
234 belongs_question_type varchar(250) DEFAULT NULL,
235 answer_title text,
236 is_correct tinyint(4) DEFAULT NULL,
237 image_id int(11) DEFAULT NULL,
238 answer_two_gap_match text,
239 answer_view_format varchar(250) DEFAULT NULL,
240 answer_settings text,
241 answer_order int(11) DEFAULT '0',
242 PRIMARY KEY (answer_id)
243 ) $charset_collate;";
244
245 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
246 dbDelta( $quiz_attempts_sql );
247 dbDelta( $quiz_attempt_answers );
248 dbDelta( $tutor_quiz_questions );
249 dbDelta( $tutor_quiz_question_answers );
250 }
251
252 /**
253 * upgrading quiz_attempts_database adding course_id
254 * @since v.1.0.1
255 */
256 public function upgrading_db_1_0_1(){
257 global $wpdb;
258 /**
259 * Adding course_id column in tutor_quiz_attempts table
260 */
261 $sql = "ALTER TABLE {$wpdb->prefix}tutor_quiz_attempts ADD course_id INT NULL DEFAULT NULL AFTER attempt_id;";
262 $wpdb->query($sql);
263 /**
264 * Setting Course_id column data;
265 */
266 $attempts = $wpdb->get_results("SELECT * from {$wpdb->prefix}tutor_quiz_attempts;");
267 if (is_array($attempts) && count($attempts)){
268 foreach ($attempts as $attempt){
269 $course = tutor_utils()->get_course_by_quiz($attempt->quiz_id);
270 $wpdb->update($wpdb->prefix."tutor_quiz_attempts", array('course_id' => $course->ID), array('attempt_id' => $attempt->attempt_id));
271 }
272 }
273 }
274
275 public static function manage_tutor_roles_and_permissions(){
276 /**
277 * Add role for instructor
278 */
279 $instructor_role = tutor()->instructor_role;
280
281 remove_role($instructor_role);
282 add_role( $instructor_role, __('Tutor Instructor', 'tutor'), array() );
283
284 $custom_post_type_permission = array(
285 //Manage Instructor
286 'manage_tutor_instructor',
287
288 //Tutor Posts Type Permission
289 'edit_tutor_course',
290 'read_tutor_course',
291 'delete_tutor_course',
292 'delete_tutor_courses',
293 'edit_tutor_courses',
294 'edit_others_tutor_courses',
295 'read_private_tutor_courses',
296 'edit_tutor_courses',
297
298 'edit_tutor_lesson',
299 'read_tutor_lesson',
300 'delete_tutor_lesson',
301 'delete_tutor_lessons',
302 'edit_tutor_lessons',
303 'edit_others_tutor_lessons',
304 'read_private_tutor_lessons',
305 'edit_tutor_lessons',
306 'publish_tutor_lessons',
307
308 'edit_tutor_quiz',
309 'read_tutor_quiz',
310 'delete_tutor_quiz',
311 'delete_tutor_quizzes',
312 'edit_tutor_quizzes',
313 'edit_others_tutor_quizzes',
314 'read_private_tutor_quizzes',
315 'edit_tutor_quizzes',
316 'publish_tutor_quizzes',
317
318 'edit_tutor_question',
319 'read_tutor_question',
320 'delete_tutor_question',
321 'delete_tutor_questions',
322 'edit_tutor_questions',
323 'edit_others_tutor_questions',
324 'publish_tutor_questions',
325 'read_private_tutor_questions',
326 'edit_tutor_questions',
327 );
328
329 $instructor = get_role( $instructor_role );
330 if ( $instructor ) {
331 $instructor_cap = array (
332 'edit_posts',
333 'read',
334 'upload_files',
335 );
336
337 $instructor_cap = array_merge($instructor_cap, $custom_post_type_permission);
338
339 $can_publish_course = (bool) tutor_utils()->get_option('instructor_can_publish_course');
340 if ($can_publish_course){
341 $instructor_cap[] = 'publish_tutor_courses';
342 }
343
344 foreach ($instructor_cap as $cap){
345 $instructor->add_cap( $cap );
346 }
347 }
348
349 $administrator = get_role( 'administrator' );
350 if ( $administrator ) {
351 $administrator_cap = array (
352 'manage_tutor',
353 );
354 $administrator_cap = array_merge($administrator_cap, $custom_post_type_permission);
355 $administrator_cap[] = 'publish_tutor_courses';
356
357 foreach ($administrator_cap as $cap){
358 $administrator->add_cap( $cap );
359 }
360 }
361 }
362
363 /**
364 * Save data like page
365 */
366 public static function save_data(){
367 $student_dashboard_args = array(
368 'post_title' => __('Student Dashboard', 'tutor'),
369 'post_content' => '[tutor_student_dashboard]',
370 'post_type' => 'page',
371 'post_status' => 'publish',
372 );
373 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
374 tutor_utils()->update_option('student_dashboard', $student_dashboard_page_id);
375
376 $student_registration_args = array(
377 'post_title' => __('Student Registration', 'tutor'),
378 'post_content' => '[tutor_student_registration_form]',
379 'post_type' => 'page',
380 'post_status' => 'publish',
381 );
382 $student_register_page_id = wp_insert_post( $student_registration_args );
383 tutor_utils()->update_option('student_register_page', $student_register_page_id);
384
385 $instructor_registration_args = array(
386 'post_title' => __('Instructor Registration', 'tutor'),
387 'post_content' => '[tutor_instructor_registration_form]',
388 'post_type' => 'page',
389 'post_status' => 'publish',
390 );
391 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
392 tutor_utils()->update_option('instructor_register_page', $instructor_registration_id);
393 }
394
395 public static function default_options(){
396 $options = array (
397 'load_tutor_css' => '1',
398 'load_tutor_js' => '1',
399 'course_allow_upload_private_files' => '1',
400 'display_course_instructors' => '1',
401 'enable_q_and_a_on_course' => '1',
402 'courses_col_per_row' => '3',
403 'courses_per_page' => '3',
404 'lesson_permalink_base' => 'lesson',
405 'quiz_time_limit' =>
406 array (
407 'value' => '0',
408 'time' => 'minutes',
409 ),
410 'quiz_when_time_expires' => 'autosubmit',
411 'quiz_attempts_allowed' => '10',
412 'quiz_grade_method' => 'highest_grade',
413 'enable_public_profile' => '1',
414 'email_to_students' =>
415 array (
416 'quiz_completed' => '1',
417 'completed_course' => '1',
418 ),
419 'email_to_instructors' =>
420 array (
421 'a_student_enrolled_in_course' => '1',
422 'a_student_completed_course' => '1',
423 'a_student_completed_lesson' => '1',
424 'a_student_placed_question' => '1',
425 ),
426 'email_from_name' => get_option('blogname'),
427 'email_from_address' => get_option('admin_email'),
428 'email_footer_text' => '',
429 'enable_course_sell_by_woocommerce' => '1',
430 );
431 return $options;
432 }
433
434
435 }