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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
395 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', TUTOR_VERSION);
147 }
148 }
149
150 //Run task on deactivation
151 public function tutor_deactivation() {
152 wp_clear_scheduled_hook('tutor_once_in_day_run_schedule');
153 }
154
155 public function create_database(){
156 global $wpdb;
157
158 $charset_collate = $wpdb->get_charset_collate();
159
160 /**
161 * Table SQL
162 *
163 * {$wpdb->prefix}tutor_quiz_attempts
164 * {$wpdb->prefix}tutor_quiz_attempt_answers
165 * {$wpdb->prefix}tutor_quiz_questions
166 * {$wpdb->prefix}tutor_quiz_question_answers
167 *
168 * @since v.1.0.0
169 */
170 $quiz_attempts_sql = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempts (
171 attempt_id int(11) NOT NULL AUTO_INCREMENT,
172 quiz_id int(11) DEFAULT NULL,
173 user_id int(11) DEFAULT NULL,
174 total_questions int(11) DEFAULT NULL,
175 total_answered_questions int(11) DEFAULT NULL,
176 total_marks decimal(9,2) DEFAULT NULL,
177 earned_marks decimal(9,2) DEFAULT NULL,
178 attempt_info text,
179 attempt_status varchar(50) DEFAULT NULL,
180 attempt_ip varchar(250) DEFAULT NULL,
181 attempt_started_at datetime DEFAULT NULL,
182 attempt_ended_at datetime DEFAULT NULL,
183 is_manually_reviewed int(1) DEFAULT NULL,
184 manually_reviewed_at datetime DEFAULT NULL,
185 PRIMARY KEY (attempt_id)
186 ) $charset_collate;";
187
188 $quiz_attempt_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_attempt_answers (
189 attempt_answer_id int(11) NOT NULL AUTO_INCREMENT,
190 user_id int(11) DEFAULT NULL,
191 quiz_id int(11) DEFAULT NULL,
192 question_id int(11) DEFAULT NULL,
193 quiz_attempt_id int(11) DEFAULT NULL,
194 given_answer longtext,
195 question_mark decimal(8,2) DEFAULT NULL,
196 achieved_mark decimal(8,2) DEFAULT NULL,
197 minus_mark decimal(8,2) DEFAULT NULL,
198 is_correct tinyint(4) DEFAULT NULL,
199 PRIMARY KEY (attempt_answer_id)
200 ) $charset_collate;";
201
202 $tutor_quiz_questions = "CREATE TABLE {$wpdb->prefix}tutor_quiz_questions (
203 question_id int(11) NOT NULL AUTO_INCREMENT,
204 quiz_id int(11) DEFAULT NULL,
205 question_title text,
206 question_description longtext,
207 question_type varchar(50) DEFAULT NULL,
208 question_mark decimal(9,2) DEFAULT NULL,
209 question_settings longtext,
210 question_order int(11) DEFAULT NULL,
211 PRIMARY KEY (question_id)
212 ) $charset_collate;";
213
214 $tutor_quiz_question_answers = "CREATE TABLE {$wpdb->prefix}tutor_quiz_question_answers (
215 answer_id int(11) NOT NULL AUTO_INCREMENT,
216 belongs_question_id int(11) DEFAULT NULL,
217 belongs_question_type varchar(250) DEFAULT NULL,
218 answer_title text,
219 is_correct tinyint(4) DEFAULT NULL,
220 image_id int(11) DEFAULT NULL,
221 answer_two_gap_match text,
222 answer_view_format varchar(250) DEFAULT NULL,
223 answer_settings text,
224 answer_order int(11) DEFAULT '0',
225 PRIMARY KEY (answer_id)
226 ) $charset_collate;";
227
228 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
229 dbDelta( $quiz_attempts_sql );
230 dbDelta( $quiz_attempt_answers );
231 dbDelta( $tutor_quiz_questions );
232 dbDelta( $tutor_quiz_question_answers );
233 }
234
235 public static function manage_tutor_roles_and_permissions(){
236 /**
237 * Add role for instructor
238 */
239 $instructor_role = tutor()->instructor_role;
240
241 remove_role($instructor_role);
242 add_role( $instructor_role, __('Tutor Instructor', 'tutor'), array() );
243
244 $custom_post_type_permission = array(
245 //Manage Instructor
246 'manage_tutor_instructor',
247
248 //Tutor Posts Type Permission
249 'edit_tutor_course',
250 'read_tutor_course',
251 'delete_tutor_course',
252 'delete_tutor_courses',
253 'edit_tutor_courses',
254 'edit_others_tutor_courses',
255 'read_private_tutor_courses',
256 'edit_tutor_courses',
257
258 'edit_tutor_lesson',
259 'read_tutor_lesson',
260 'delete_tutor_lesson',
261 'delete_tutor_lessons',
262 'edit_tutor_lessons',
263 'edit_others_tutor_lessons',
264 'read_private_tutor_lessons',
265 'edit_tutor_lessons',
266 'publish_tutor_lessons',
267
268 'edit_tutor_quiz',
269 'read_tutor_quiz',
270 'delete_tutor_quiz',
271 'delete_tutor_quizzes',
272 'edit_tutor_quizzes',
273 'edit_others_tutor_quizzes',
274 'read_private_tutor_quizzes',
275 'edit_tutor_quizzes',
276 'publish_tutor_quizzes',
277
278 'edit_tutor_question',
279 'read_tutor_question',
280 'delete_tutor_question',
281 'delete_tutor_questions',
282 'edit_tutor_questions',
283 'edit_others_tutor_questions',
284 'publish_tutor_questions',
285 'read_private_tutor_questions',
286 'edit_tutor_questions',
287 );
288
289 $instructor = get_role( $instructor_role );
290 if ( $instructor ) {
291 $instructor_cap = array (
292 'edit_posts',
293 'read',
294 'upload_files',
295 );
296
297 $instructor_cap = array_merge($instructor_cap, $custom_post_type_permission);
298
299 $can_publish_course = (bool) tutor_utils()->get_option('instructor_can_publish_course');
300 if ($can_publish_course){
301 $instructor_cap[] = 'publish_tutor_courses';
302 }
303
304 foreach ($instructor_cap as $cap){
305 $instructor->add_cap( $cap );
306 }
307 }
308
309 $administrator = get_role( 'administrator' );
310 if ( $administrator ) {
311 $administrator_cap = array (
312 'manage_tutor',
313 );
314 $administrator_cap = array_merge($administrator_cap, $custom_post_type_permission);
315 $administrator_cap[] = 'publish_tutor_courses';
316
317 foreach ($administrator_cap as $cap){
318 $administrator->add_cap( $cap );
319 }
320 }
321 }
322
323 /**
324 * Save data like page
325 */
326 public static function save_data(){
327 $student_dashboard_args = array(
328 'post_title' => __('Student Dashboard', 'tutor'),
329 'post_content' => '[tutor_student_dashboard]',
330 'post_type' => 'page',
331 'post_status' => 'publish',
332 );
333 $student_dashboard_page_id = wp_insert_post( $student_dashboard_args );
334 tutor_utils()->update_option('student_dashboard', $student_dashboard_page_id);
335
336 $student_registration_args = array(
337 'post_title' => __('Student Registration', 'tutor'),
338 'post_content' => '[tutor_student_registration_form]',
339 'post_type' => 'page',
340 'post_status' => 'publish',
341 );
342 $student_register_page_id = wp_insert_post( $student_registration_args );
343 tutor_utils()->update_option('student_register_page', $student_register_page_id);
344
345 $instructor_registration_args = array(
346 'post_title' => __('Instructor Registration', 'tutor'),
347 'post_content' => '[tutor_instructor_registration_form]',
348 'post_type' => 'page',
349 'post_status' => 'publish',
350 );
351 $instructor_registration_id = wp_insert_post( $instructor_registration_args );
352 tutor_utils()->update_option('instructor_register_page', $instructor_registration_id);
353 }
354
355 public static function default_options(){
356 $options = array (
357 'load_tutor_css' => '1',
358 'load_tutor_js' => '1',
359 'course_allow_upload_private_files' => '1',
360 'display_course_instructors' => '1',
361 'enable_q_and_a_on_course' => '1',
362 'courses_col_per_row' => '3',
363 'courses_per_page' => '3',
364 'lesson_permalink_base' => 'lesson',
365 'quiz_time_limit' =>
366 array (
367 'value' => '0',
368 'time' => 'minutes',
369 ),
370 'quiz_when_time_expires' => 'autosubmit',
371 'quiz_attempts_allowed' => '10',
372 'quiz_grade_method' => 'highest_grade',
373 'enable_public_profile' => '1',
374 'email_to_students' =>
375 array (
376 'quiz_completed' => '1',
377 'completed_course' => '1',
378 ),
379 'email_to_instructors' =>
380 array (
381 'a_student_enrolled_in_course' => '1',
382 'a_student_completed_course' => '1',
383 'a_student_completed_lesson' => '1',
384 'a_student_placed_question' => '1',
385 ),
386 'email_from_name' => get_option('blogname'),
387 'email_from_address' => get_option('admin_email'),
388 'email_footer_text' => '',
389 'enable_course_sell_by_woocommerce' => '1',
390 );
391 return $options;
392 }
393
394
395 }