PluginProbe
Tutor LMS – eLearning and online course solution / 1.0.7
Tutor LMS – eLearning and online course solution v1.0.7
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
tutor / classes / Admin.php

Admin.php in Tutor LMS – eLearning and online course solution 1.0.7, at classes/Admin.php

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