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