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.0 3.6.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 / Ajax.php
tutor / classes Last commit date
Addons.php 6 years ago Admin.php 6 years ago Ajax.php 6 years ago Assets.php 6 years ago Course.php 6 years ago Course_Settings_Tabs.php 6 years ago Course_Widget.php 6 years ago Dashboard.php 6 years ago Gutenberg.php 6 years ago Instructor.php 6 years ago Instructors_List.php 6 years ago Lesson.php 6 years ago Options.php 6 years ago Post_types.php 6 years ago Q_and_A.php 6 years ago Question.php 6 years ago Question_Answers_List.php 6 years ago Quiz.php 6 years ago Quiz_Attempts_List.php 6 years ago Rewrite_Rules.php 6 years ago Shortcode.php 6 years ago Student.php 6 years ago Students_List.php 6 years ago Taxonomies.php 6 years ago Template.php 6 years ago Theme_Compatibility.php 6 years ago Tools.php 6 years ago Tutor.php 6 years ago TutorEDD.php 6 years ago Tutor_Base.php 6 years ago Tutor_List_Table.php 6 years ago Upgrader.php 6 years ago User.php 6 years ago Utils.php 6 years ago Video_Stream.php 6 years ago Withdraw.php 6 years ago Withdraw_Requests_List.php 6 years ago WooCommerce.php 6 years ago
Ajax.php
302 lines
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) )
5 exit;
6
7 class Ajax{
8 public function __construct() {
9 add_action('wp_ajax_sync_video_playback', array($this, 'sync_video_playback'));
10 add_action('wp_ajax_nopriv_sync_video_playback', array($this, 'sync_video_playback_noprev'));
11 add_action('wp_ajax_tutor_place_rating', array($this, 'tutor_place_rating'));
12
13 add_action('wp_ajax_tutor_ask_question', array($this, 'tutor_ask_question'));
14 add_action('wp_ajax_tutor_add_answer', array($this, 'tutor_add_answer'));
15
16 add_action('wp_ajax_tutor_course_add_to_wishlist', array($this, 'tutor_course_add_to_wishlist'));
17 add_action('wp_ajax_nopriv_tutor_course_add_to_wishlist', array($this, 'tutor_course_add_to_wishlist'));
18
19 /**
20 * Addon Enable Disable Control
21 */
22 add_action('wp_ajax_addon_enable_disable', array($this, 'addon_enable_disable'));
23
24 /**
25 * Update Rating/review
26 * @since v.1.4.0
27 */
28 add_action('wp_ajax_tutor_load_edit_review_modal', array($this, 'tutor_load_edit_review_modal'));
29 add_action('wp_ajax_tutor_update_review_modal', array($this, 'tutor_update_review_modal'));
30 }
31
32 /**
33 * Update video information and data when necessary
34 *
35 * @since v.1.0.0
36 */
37 public function sync_video_playback(){
38 tutor_utils()->checking_nonce();
39
40 $duration = sanitize_text_field($_POST['duration']);
41 $currentTime = sanitize_text_field($_POST['currentTime']);
42 $post_id = sanitize_text_field($_POST['post_id']);
43
44 /**
45 * Update posts attached video
46 */
47 $video = tutor_utils()->get_video($post_id);
48
49 if ($duration) {
50 $video['duration_sec'] = $duration; //secs
51 $video['playtime'] = tutor_utils()->playtime_string( $duration );
52 $video['runtime'] = tutor_utils()->playtime_array( $duration );
53 }
54 tutor_utils()->update_video($post_id, $video);
55
56 /**
57 * Sync Lesson Reading Info by Users
58 */
59
60 $user_id = get_current_user_id();
61
62 $best_watch_time = tutor_utils()->get_lesson_reading_info($post_id, $user_id, 'video_best_watched_time');
63 if ($best_watch_time < $currentTime){
64 tutor_utils()->update_lesson_reading_info($post_id, $user_id, 'video_best_watched_time', $currentTime);
65 }
66
67 if (tutor_utils()->avalue_dot('is_ended', $_POST)){
68 tutor_utils()->mark_lesson_complete($post_id);
69 }
70 exit();
71 }
72
73 public function sync_video_playback_noprev(){
74
75 }
76
77
78 public function tutor_place_rating(){
79 global $wpdb;
80
81 //TODO: Check nonce
82
83 $rating = sanitize_text_field(tutor_utils()->avalue_dot('rating', $_POST));
84 $course_id = sanitize_text_field(tutor_utils()->avalue_dot('course_id', $_POST));
85 $review = wp_kses_post(tutor_utils()->avalue_dot('review', $_POST));
86
87 $user_id = get_current_user_id();
88 $user = get_userdata($user_id);
89 $date = date("Y-m-d H:i:s");
90
91 do_action('tutor_before_rating_placed');
92
93 $previous_rating_id = $wpdb->get_var("select comment_ID from {$wpdb->comments} WHERE comment_post_ID={$course_id} AND user_id = {$user_id} AND comment_type = 'tutor_course_rating' LIMIT 1;");
94
95 $review_ID = $previous_rating_id;
96 if ( $previous_rating_id){
97 $wpdb->update( $wpdb->comments, array('comment_content' => $review),
98 array('comment_ID' => $previous_rating_id)
99 );
100 $wpdb->update( $wpdb->commentmeta, array('meta_value' => $rating),
101 array('comment_id' => $previous_rating_id, 'meta_key' => 'tutor_rating')
102 );
103 }else{
104 $data = array(
105 'comment_post_ID' => $course_id,
106 'comment_approved' => 'approved',
107 'comment_type' => 'tutor_course_rating',
108 'comment_date' => $date,
109 'comment_date_gmt' => get_gmt_from_date($date),
110 'user_id' => $user_id,
111 'comment_author' => $user->user_login,
112 'comment_agent' => 'TutorLMSPlugin',
113 );
114 if ($review){
115 $data['comment_content'] = $review;
116 }
117
118 $wpdb->insert($wpdb->comments, $data);
119 $comment_id = (int) $wpdb->insert_id;
120 $review_ID = $comment_id;
121
122 if ($comment_id && $rating){
123 $result = $wpdb->insert( $wpdb->commentmeta, array(
124 'comment_id' => $comment_id,
125 'meta_key' => 'tutor_rating',
126 'meta_value' => $rating
127 ) );
128
129 do_action('tutor_after_rating_placed', $comment_id);
130 }
131 }
132
133 $data = array('msg' => __('Rating placed success', 'tutor'), 'review_id' => $review_ID, 'review' => $review);
134 wp_send_json_success($data);
135 }
136
137 public function tutor_ask_question(){
138 tutor_utils()->checking_nonce();
139
140 global $wpdb;
141
142 $course_id = (int) sanitize_text_field($_POST['tutor_course_id']);
143 $question_title = sanitize_text_field($_POST['question_title']);
144 $question = wp_kses_post($_POST['question']);
145
146 if (empty($question) || empty($question_title)){
147 wp_send_json_error(__('Empty question title or body', 'tutor'));
148 }
149
150 $user_id = get_current_user_id();
151 $user = get_userdata($user_id);
152 $date = date("Y-m-d H:i:s");
153
154 do_action('tutor_before_add_question', $course_id);
155 $data = apply_filters('tutor_add_question_data', array(
156 'comment_post_ID' => $course_id,
157 'comment_author' => $user->user_login,
158 'comment_date' => $date,
159 'comment_date_gmt' => get_gmt_from_date($date),
160 'comment_content' => $question,
161 'comment_approved' => 'waiting_for_answer',
162 'comment_agent' => 'TutorLMSPlugin',
163 'comment_type' => 'tutor_q_and_a',
164 'user_id' => $user_id,
165 ));
166
167 $wpdb->insert($wpdb->comments, $data);
168 $comment_id = (int) $wpdb->insert_id;
169
170 if ($comment_id){
171 $result = $wpdb->insert( $wpdb->commentmeta, array(
172 'comment_id' => $comment_id,
173 'meta_key' => 'tutor_question_title',
174 'meta_value' => $question_title
175 ) );
176 }
177 do_action('tutor_after_add_question', $course_id, $comment_id);
178
179 wp_send_json_success(__('Question has been added successfully', 'tutor'));
180 }
181
182
183 public function tutor_add_answer(){
184 tutor_utils()->checking_nonce();
185 global $wpdb;
186
187 $answer = wp_kses_post($_POST['answer']);
188 if ( ! $answer){
189 wp_send_json_error(__('Please write answer', 'tutor'));
190 }
191
192 $question_id = (int) sanitize_text_field($_POST['question_id']);
193 $question = tutor_utils()->get_qa_question($question_id);
194
195 $user_id = get_current_user_id();
196 $user = get_userdata($user_id);
197 $date = date("Y-m-d H:i:s");
198
199 do_action('tutor_before_answer_to_question');
200 $data = apply_filters('tutor_add_answer_data', array(
201 'comment_post_ID' => $question->comment_post_ID,
202 'comment_author' => $user->user_login,
203 'comment_date' => $date,
204 'comment_date_gmt' => get_gmt_from_date($date),
205 'comment_content' => $answer,
206 'comment_approved' => 'approved',
207 'comment_agent' => 'TutorLMSPlugin',
208 'comment_type' => 'tutor_q_and_a',
209 'comment_parent' => $question_id,
210 'user_id' => $user_id,
211 ));
212
213 $wpdb->insert($wpdb->comments, $data);
214 $comment_id = (int) $wpdb->insert_id;
215 do_action('tutor_after_answer_to_question', $comment_id);
216
217 wp_send_json_success(__('Answer has been added successfully', 'tutor'));
218 }
219
220
221 public function tutor_course_add_to_wishlist(){
222 $course_id = (int) sanitize_text_field($_POST['course_id']);
223 if ( ! is_user_logged_in()){
224 wp_send_json_error(array('redirect_to' => wp_login_url( wp_get_referer() ) ) );
225 }
226 global $wpdb;
227
228 $user_id = get_current_user_id();
229 $if_added_to_list = $wpdb->get_row("select * from {$wpdb->usermeta} WHERE user_id = {$user_id} AND meta_key = '_tutor_course_wishlist' AND meta_value = {$course_id} ;");
230
231 if ( $if_added_to_list){
232 $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => '_tutor_course_wishlist', 'meta_value' => $course_id ));
233 wp_send_json_success(array('status' => 'removed', 'msg' => __('Course removed from wish list', 'tutor')));
234 }else{
235 add_user_meta($user_id, '_tutor_course_wishlist', $course_id);
236 wp_send_json_success(array('status' => 'added', 'msg' => __('Course added to wish list', 'tutor')));
237 }
238 }
239
240 /**
241 * Method for enable / disable addons
242 */
243 public function addon_enable_disable(){
244 $addonsConfig = maybe_unserialize(get_option('tutor_addons_config'));
245
246 $isEnable = (bool) sanitize_text_field(tutor_utils()->avalue_dot('isEnable', $_POST));
247 $addonFieldName = sanitize_text_field(tutor_utils()->avalue_dot('addonFieldName', $_POST));
248
249 if ($isEnable){
250 $addonsConfig[$addonFieldName]['is_enable'] = 1;
251 }else{
252 $addonsConfig[$addonFieldName]['is_enable'] = 0;
253 }
254
255 update_option('tutor_addons_config', $addonsConfig);
256
257 wp_send_json_success();
258 }
259
260
261 /**
262 * Load review edit form
263 * @since v.1.4.0
264 */
265 public function tutor_load_edit_review_modal(){
266 tutor_utils()->checking_nonce();
267
268 $review_id = (int) sanitize_text_field(tutils()->array_get('review_id', $_POST));
269 $rating = tutils()->get_rating_by_id($review_id);
270
271 ob_start();
272 tutor_load_template('dashboard.reviews.edit-review-form', array('rating' => $rating));
273 $output = ob_get_clean();
274
275 wp_send_json_success(array('output' => $output));
276 }
277
278 public function tutor_update_review_modal(){
279 global $wpdb;
280
281 tutor_utils()->checking_nonce();
282
283 $review_id = (int) sanitize_text_field(tutils()->array_get('review_id', $_POST));
284 $rating = sanitize_text_field(tutor_utils()->avalue_dot('rating', $_POST));
285 $review = wp_kses_post(tutor_utils()->avalue_dot('review', $_POST));
286
287 $is_exists = $wpdb->get_var("select comment_ID from {$wpdb->comments} WHERE comment_ID={$review_id} AND comment_type = 'tutor_course_rating' ;");
288
289 if ( $is_exists) {
290 $wpdb->update( $wpdb->comments, array( 'comment_content' => $review ),
291 array( 'comment_ID' => $review_id )
292 );
293 $wpdb->update( $wpdb->commentmeta, array( 'meta_value' => $rating ),
294 array( 'comment_id' => $review_id, 'meta_key' => 'tutor_rating' )
295 );
296
297 wp_send_json_success();
298 }
299 wp_send_json_error();
300 }
301
302 }