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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 / Admin.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
Admin.php
400 lines
1 <?php
2 namespace TUTOR;
3
4 /**
5 * Class Admin
6 * @package TUTOR
7 *
8 * @since v.1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) )
12 exit;
13
14 class Admin{
15 public function __construct() {
16 add_action('admin_menu', array($this, 'register_menu'));
17 //Force activate menu for necessary
18 add_filter('parent_file', array($this, 'parent_menu_active'));
19 add_filter('submenu_file', array($this, 'submenu_file_active'), 10, 2);
20
21 add_action('admin_init', array($this, 'filter_posts_for_instructors'));
22 add_action('load-post.php', array($this, 'check_if_current_users_post') );
23
24 add_action('admin_action_uninstall_tutor_and_erase', array($this, 'erase_tutor_data'));
25 add_filter('plugin_action_links_' . plugin_basename(TUTOR_FILE), array( $this, 'plugin_action_links' ) );
26 }
27
28 public function register_menu(){
29 $hasPro = tutor()->has_pro;
30
31 $unanswered_questions = tutor_utils()->unanswered_question_count();
32 $unanswered_bubble = '';
33 if ($unanswered_questions){
34 $unanswered_bubble = '<span class="update-plugins count-'.$unanswered_questions.'"><span class="plugin-count">'.$unanswered_questions.'</span></span>';
35 }
36
37 $course_post_type = tutor()->course_post_type;
38
39 add_menu_page(__('Tutor LMS', 'tutor'), __('Tutor LMS', 'tutor'), 'manage_tutor_instructor', 'tutor', null, 'dashicons-welcome-learn-more', 2);
40
41 add_submenu_page('tutor', __('Categories', 'tutor'), __('Categories', 'tutor'), 'manage_tutor', 'edit-tags.php?taxonomy=course-category&post_type='.$course_post_type, null );
42
43 add_submenu_page('tutor', __('Tags', 'tutor'), __('Tags', 'tutor'), 'manage_tutor', 'edit-tags.php?taxonomy=course-tag&post_type='.$course_post_type, null );
44
45 add_submenu_page('tutor', __('Students', 'tutor'), __('Students', 'tutor'), 'manage_tutor', 'tutor-students', array($this, 'tutor_students') );
46
47 add_submenu_page('tutor', __('Instructors', 'tutor'), __('Instructors', 'tutor'), 'manage_tutor', 'tutor-instructors', array($this, 'tutor_instructors') );
48
49 add_submenu_page('tutor', __('Q & A', 'tutor'), __('Q & A '.$unanswered_bubble, 'tutor'), 'manage_tutor_instructor', 'question_answer', array($this, 'question_answer') );
50
51 add_submenu_page('tutor', __('Quiz Attempts', 'tutor'), __('Quiz Attempts', 'tutor'), 'manage_tutor_instructor', 'tutor_quiz_attempts',array($this, 'quiz_attempts') );
52
53 //add_submenu_page('tutor', __('Add-ons', 'tutor'), __('Add-ons', 'tutor'), 'manage_tutor', 'tutor-addons', array(new Addons(),'addons_page') );
54
55 if (defined('TUTOR_PRO_VERSION')) {
56 add_submenu_page( 'tutor', __( 'Add-ons', 'tutor' ), __( 'Add-ons', 'tutor' ), 'manage_tutor', 'tutor-addons', array( $this, 'enable_disable_addons' ) );
57 }
58
59 add_submenu_page('tutor', __('Status', 'tutor'), __('Status', 'tutor'), 'manage_tutor', 'tutor-status', array($this, 'tutor_status') );
60
61 do_action('tutor_admin_register');
62
63 add_submenu_page('tutor', __('Settings', 'tutor'), __('Settings', 'tutor'), 'manage_tutor', 'tutor_settings', array($this, 'tutor_page') );
64
65 add_submenu_page('tutor',__('Uninstall Tutor LMS', 'tutor'), null, 'deactivate_plugin', 'tutor-uninstall', array($this, 'tutor_uninstall'));
66 /*
67 if ( ! $hasPro){
68 add_submenu_page( 'tutor', __( 'Get Pro', 'tutor' ), __( '<span class="dashicons dashicons-awards tutor-get-pro-text"></span> Get Pro', 'tutor' ), 'manage_options', 'tutor-get-pro', array($this, 'tutor_get_pro') );
69 }*/
70
71 }
72
73 public function tutor_page(){
74 $tutor_option = new Options();
75 echo apply_filters('tutor/options/generated-html', $tutor_option->generate());
76 }
77
78 public function tutor_students(){
79 include tutor()->path.'views/pages/students.php';
80 }
81
82 public function tutor_instructors(){
83 include tutor()->path.'views/pages/instructors.php';
84 }
85
86 public function question_answer(){
87 include tutor()->path.'views/pages/question_answer.php';
88 }
89
90 public function quiz_attempts(){
91 include tutor()->path.'views/pages/quiz_attempts.php';
92 }
93
94 public function enable_disable_addons(){
95 include tutor()->path.'views/pages/enable_disable_addons.php';
96 }
97
98 public function tutor_status(){
99 include tutor()->path.'views/pages/status.php';
100 }
101
102 public function tutor_uninstall(){
103 include tutor()->path.'views/pages/uninstall.php';
104 }
105
106 public function tutor_get_pro(){
107 include tutor()->path.'views/pages/get-pro.php';
108 }
109
110 public function parent_menu_active( $parent_file ){
111 $taxonomy = tutor_utils()->avalue_dot('taxonomy', $_GET);
112 if ($taxonomy === 'course-category' || $taxonomy === 'course-tag'){
113 return 'tutor';
114 }
115
116 return $parent_file;
117 }
118
119 public function submenu_file_active($submenu_file, $parent_file){
120 $taxonomy = tutor_utils()->avalue_dot('taxonomy', $_GET);
121 $course_post_type = tutor()->course_post_type;
122
123 if ($taxonomy === 'course-category'){
124 return 'edit-tags.php?taxonomy=course-category&post_type='.$course_post_type;
125 }
126 if ($taxonomy === 'course-tag'){
127 return 'edit-tags.php?taxonomy=course-tag&post_type='.$course_post_type;
128 }
129
130
131 return $submenu_file;
132 }
133
134 /**
135 * Filter posts for instructor
136 */
137 public function filter_posts_for_instructors(){
138 if ( ! current_user_can('administrator') && current_user_can(tutor()->instructor_role)){
139 remove_menu_page( 'edit-comments.php' ); //Comments
140 add_filter( 'posts_clauses_request', array($this, 'posts_clauses_request') );
141 }
142 }
143
144 public function posts_clauses_request($clauses){
145 global $wpdb;
146
147 $user_id = get_current_user_id();
148
149 $get_assigned_courses_ids = $wpdb->get_col("SELECT meta_value from {$wpdb->usermeta} WHERE meta_key = '_tutor_instructor_course_id' AND user_id = {$user_id} ");
150
151 $custom_author_query = "AND {$wpdb->posts}.post_author = {$user_id}";
152 if (is_array($get_assigned_courses_ids) && count($get_assigned_courses_ids)){
153 $in_query_pre = implode(',', $get_assigned_courses_ids);
154 $custom_author_query = " AND ( {$wpdb->posts}.post_author = {$user_id} OR {$wpdb->posts}.ID IN({$in_query_pre}) ) ";
155 }
156
157 $clauses['where'] .= $custom_author_query;
158
159 return $clauses;
160 }
161
162 /**
163 * Prevent unauthorised post edit page by direct URL
164 *
165 * @since v.1.0.0
166 */
167 public function check_if_current_users_post(){
168 if (! current_user_can(tutor()->instructor_role)) {
169 return;
170 }
171
172 if (! empty($_GET['post']) ) {
173 $get_post_id = (int) sanitize_text_field($_GET['post']);
174 $get_post = get_post($get_post_id);
175 $current_user = get_current_user_id();
176
177 if ($get_post->post_author != $current_user){
178 global $wpdb;
179
180 $get_assigned_courses_ids = (int) $wpdb->get_var("SELECT user_id from {$wpdb->usermeta} WHERE user_id = {$current_user} AND meta_key = '_tutor_instructor_course_id' AND meta_value = {$get_post_id} ");
181
182 if ( ! $get_assigned_courses_ids){
183 wp_die(__('Permission Denied', 'tutor'));
184 }
185
186 }
187 }
188 }
189
190 /**
191 * Status
192 */
193
194 public static function scan_template_files( $template_path = null ) {
195 if ( ! $template_path){
196 $template_path = tutor()->path.'templates/';
197 }
198
199
200 $files = @scandir( $template_path ); // @codingStandardsIgnoreLine.
201 $result = array();
202
203 if ( ! empty( $files ) ) {
204 foreach ( $files as $key => $value ) {
205 if ( ! in_array( $value, array( '.', '..', '.DS_Store' ), true ) ) {
206 if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
207 $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
208 foreach ( $sub_files as $sub_file ) {
209 $result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
210 }
211 } else {
212 $result[] = $value;
213 }
214 }
215 }
216 }
217 return $result;
218 }
219
220 /**
221 * @return array
222 *
223 *
224 */
225 public static function template_overridden_files(){
226 $template_files = self::scan_template_files();
227
228 $override_files = array();
229 foreach ($template_files as $file){
230 $file_path = null;
231 if (file_exists(trailingslashit(get_stylesheet_directory()).tutor()->template_path.$file)){
232 $file_path = $file;
233 }elseif (file_exists(trailingslashit(get_template_directory()).tutor()->template_path.$file)){
234 $file_path = $file;
235 }
236
237 if ($file_path){
238 $override_files[] = str_replace( WP_CONTENT_DIR.'/themes/', '', $file_path );
239 }
240 }
241
242 return $override_files;
243 }
244
245 public static function get_environment_info(){
246
247 // Figure out cURL version, if installed.
248 $curl_version = '';
249 if ( function_exists( 'curl_version' ) ) {
250 $curl_version = curl_version();
251 $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
252 }
253
254
255 // WP memory limit.
256 $wp_memory_limit = tutor_utils()->let_to_num(WP_MEMORY_LIMIT);
257 if ( function_exists( 'memory_get_usage' ) ) {
258 $wp_memory_limit = max( $wp_memory_limit, tutor_utils()->let_to_num( @ini_get( 'memory_limit' ) ) );
259 }
260
261 $database_version = tutor_utils()->get_db_version();
262
263 return array(
264 'home_url' => get_option( 'home' ),
265 'site_url' => get_option( 'siteurl' ),
266 'version' => tutor()->version,
267 'wp_version' => get_bloginfo( 'version' ),
268 'wp_multisite' => is_multisite(),
269 'wp_memory_limit' => $wp_memory_limit,
270 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
271 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
272 'language' => get_locale(),
273 'external_object_cache' => wp_using_ext_object_cache(),
274 'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) : '',
275 'php_version' => phpversion(),
276 'php_post_max_size' => tutor_utils()->let_to_num( ini_get( 'post_max_size' ) ),
277 'php_max_execution_time' => ini_get( 'max_execution_time' ),
278 'php_max_input_vars' => ini_get( 'max_input_vars' ),
279 'curl_version' => $curl_version,
280 'suhosin_installed' => extension_loaded( 'suhosin' ),
281 'max_upload_size' => wp_max_upload_size(),
282 'mysql_version' => $database_version['number'],
283 'mysql_version_string' => $database_version['string'],
284 'default_timezone' => date_default_timezone_get(),
285 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ),
286 'soapclient_enabled' => class_exists( 'SoapClient' ),
287 'domdocument_enabled' => class_exists( 'DOMDocument' ),
288 'gzip_enabled' => is_callable( 'gzopen' ),
289 'mbstring_enabled' => extension_loaded( 'mbstring' ),
290 );
291
292 }
293
294
295 public function erase_tutor_data(){
296 global $wpdb;
297
298 $is_erase_data = tutor_utils()->get_option('delete_on_uninstall');
299 /**D*/ //=> Deleting Data
300
301 $plugin_file = tutor()->basename;
302 if ($is_erase_data && current_user_can( 'deactivate_plugin', $plugin_file )) {
303 /**
304 * Deleting Post Type, Meta Data, taxonomy
305 */
306 $course_post_type = tutor()->course_post_type;
307 $lesson_post_type = tutor()->lesson_post_type;
308
309 $post_types = array(
310 $course_post_type,
311 $lesson_post_type,
312 'tutor_quiz',
313 'tutor_question',
314 'tutor_enrolled',
315 'topics',
316 'tutor_enrolled',
317 'tutor_announcements',
318 );
319
320 $post_type_strings = "'".implode("','", $post_types)."'";
321 $tutor_posts = $wpdb->get_col("SELECT ID from {$wpdb->posts} WHERE post_type in({$post_type_strings}) ;");
322
323 if (is_array($tutor_posts) && count($tutor_posts)){
324 foreach ($tutor_posts as $post_id){
325 //Delete categories
326 $terms = wp_get_object_terms( $post_id, 'course-category' );
327 foreach( $terms as $term ){
328 /**D*/ wp_remove_object_terms( $post_id, array( $term->term_id ), 'course-category' );
329 }
330
331 //Delete tags if available
332 $terms = wp_get_object_terms( $post_id, 'course-tag' );
333 foreach( $terms as $term ){
334 /**D*/ wp_remove_object_terms( $post_id, array( $term->term_id ), 'course-tag' );
335 }
336
337 //Delete All Meta
338 /**D*/ $wpdb->delete($wpdb->postmeta, array('post_id' => $post_id) );
339 /**D*/ $wpdb->delete($wpdb->posts, array('ID' => $post_id) );
340 }
341 }
342
343 /**
344 * Deleting Comments (reviews, questions, quiz_answers, etc)
345 */
346 $tutor_comments = $wpdb->get_col("SELECT comment_ID from {$wpdb->comments} WHERE comment_agent = 'comment_agent' ;");
347 $comments_ids_strings = "'".implode("','", $tutor_comments)."'";
348 if (is_array($tutor_comments) && count($tutor_comments)){
349 /**D*/ $wpdb->query("DELETE from {$wpdb->commentmeta} WHERE comment_ID in({$comments_ids_strings}) ");
350 }
351 /**D*/ $wpdb->delete($wpdb->comments, array('comment_agent' => 'comment_agent'));
352
353 /**
354 * Delete Options
355 */
356
357 /**D*/ delete_option('tutor_option');
358 /**D*/ $wpdb->delete($wpdb->usermeta, array('meta_key' => '_is_tutor_student'));
359 /**D*/ $wpdb->delete($wpdb->usermeta, array('meta_key' => '_tutor_instructor_approved'));
360 /**D*/ $wpdb->delete($wpdb->usermeta, array('meta_key' => '_tutor_instructor_status'));
361 /**D*/ $wpdb->delete($wpdb->usermeta, array('meta_key' => '_is_tutor_instructor'));
362 /**D*/ $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_tutor_completed_lesson_id_%' ");
363
364 //Deleting Table
365 $prefix = $wpdb->prefix;
366 /**D*/ $wpdb->query("DROP TABLE IF EXISTS {$prefix}tutor_quiz_attempts, {$prefix}tutor_quiz_attempt_answers, {$prefix}tutor_quiz_questions, {$prefix}tutor_quiz_question_answers ");
367
368 deactivate_plugins($plugin_file);
369 }
370
371 wp_redirect('plugins.php');
372 die();
373 }
374
375 public function plugin_action_links($actions){
376 /*$hasPro = tutor()->has_pro;
377
378 if(!$hasPro){
379 $actions['tutor_pro_link'] = '<a href="https://www.themeum.com/product/tutor-lms/#pricing?utm_source=tutor_plugin_action_link&utm_medium=wordpress_dashboard&utm_campaign=go_premium" target="_blank"><span
380 style="color: #39a700eb; font-weight: bold;">'.__('Upgrade to Pro', 'wp-megamenu').'</span></a>';
381 }*/
382
383 $is_erase_data = tutor_utils()->get_option('delete_on_uninstall');
384
385 if ($is_erase_data) {
386 $plugin_file = tutor()->basename;
387 if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) {
388 if ( isset( $actions['deactivate'] ) ) {
389 $actions['deactivate'] = '<a href="admin.php?page=tutor-uninstall">' . __('Uninstall', 'tutor') . '</a>';
390 }
391 }
392 }
393
394 $actions['settings'] = '<a href="admin.php?page=tutor_settings">' . __('Settings', 'tutor') . '</a>';
395 return $actions;
396 }
397
398
399
400 }