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.2 3.5.0 3.6.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 / tutor-droip / backend / Ajax.php
tutor / tutor-droip / backend Last commit date
ElementGenerator 1 year ago Ajax.php 1 year ago Backend.php 1 year ago Editor.php 1 year ago Frontend.php 1 year ago Helper.php 1 year ago Iframe.php 1 year ago Pages.php 1 year ago
Ajax.php
150 lines
1 <?php
2 /**
3 * Preview script for html markup generator
4 *
5 * @package tutor-droip-elements
6 */
7
8 namespace TutorLMSDroip;
9
10 use stdClass;
11 use Tutor\Models\CourseModel;
12 use TutorLMSDroip\ElementGenerator\Preview;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Class Ajax
20 * This class is used to define all ajax functions.
21 *
22 * @package TutorLMSDroip
23 * @since 1.0.0
24 */
25 class Ajax {
26
27 /**
28 * Class constructor
29 */
30 public function __construct() {
31 add_action( 'wp_ajax_tutor_handle_api_calls', array( $this, 'tutor_handle_api_calls' ) );
32 }
33
34 /**
35 * Handle api calls
36 *
37 * @since 1.0.0
38 */
39 public function tutor_handle_api_calls() {
40 // Helper::verify_nonce( 'wp_rest' );
41 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
42 $request_method = sanitize_text_field( isset( $_REQUEST['method'] ) ? $_REQUEST['method'] : null );
43 if ( 'enroll_course' === $request_method ) {
44 tutor_utils()->checking_nonce();
45 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
46 $course_id = sanitize_text_field( isset( $_REQUEST['course_id'] ) ? $_REQUEST['course_id'] : null );
47 $res = tutor_utils()->do_enroll( $course_id );
48 wp_send_json_success( $res );
49 }
50
51 if ( 'complete_course' === $request_method ) {
52 tutor_utils()->checking_nonce();
53
54 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
55 $course_id = sanitize_text_field( isset( $_REQUEST['course_id'] ) ? $_REQUEST['course_id'] : null );
56 $user_id = get_current_user_id();
57 if ( ! $user_id ) {
58 wp_send_json_error( 'Please Sign-In' );
59 }
60 CourseModel::mark_course_as_completed( $course_id, $user_id );
61
62 wp_send_json_success( true );
63 }
64
65 if ( 'add_qna' === $request_method ) {
66 tutor_utils()->checking_nonce();
67
68 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
69 $course_id = sanitize_text_field( isset( $_REQUEST['course_id'] ) ? $_REQUEST['course_id'] : null );
70 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
71 $comment_parent_id = sanitize_text_field( isset( $_REQUEST['comment_parent_id'] ) ? $_REQUEST['comment_parent_id'] : null );
72 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
73 $content = sanitize_text_field( isset( $_REQUEST['content'] ) ? $_REQUEST['content'] : null );
74 $user = wp_get_current_user();
75 $date = gmdate( 'Y-m-d H:i:s', tutor_time() );
76
77 //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
78 $collection_data = json_decode( stripslashes( isset( $_REQUEST['collection_data'] ) ? $_REQUEST['collection_data'] : null ), true );
79
80 if ( ! $content ) {
81 wp_send_json_error( 'Invalid request' );
82 }
83
84 $data = apply_filters(
85 'tutor_qna_insert_data',
86 array(
87 'comment_post_ID' => $course_id,
88 'comment_author' => $user->user_login,
89 'comment_date' => $date,
90 'comment_date_gmt' => get_gmt_from_date( $date ),
91 'comment_content' => $content,
92 'comment_approved' => 'approved',
93 'comment_agent' => 'TutorLMSPlugin',
94 'comment_type' => 'tutor_q_and_a',
95 'comment_parent' => $comment_parent_id,
96 'user_id' => $user->ID,
97 )
98 );
99
100 global $wpdb;
101
102 $response = $wpdb->insert( $wpdb->comments, $data );
103
104 if ( false === $response ) {
105 wp_send_json_error( 'Request failed!' );
106 }
107
108 $thread = $this->get_comment( $wpdb->insert_id );
109
110 // comment-item.// -qna-reply.
111 $new_element_name = 0 === $comment_parent_id ? 'comment-item' : TDE_APP_PREFIX . '-qna-reply';
112
113 $new_element = Preview::generateQnAElement( $thread, $new_element_name, $collection_data );
114
115 wp_send_json_success(
116 array(
117 'html' => $new_element,
118 'inserted_comment_id' => $wpdb->insert_id,
119 )
120 );
121 }
122
123 wp_send_json_error( 'Invalid request' );
124 }
125
126 /**
127 * Get comment
128 *
129 * @param int $id comment id.
130 * @return object
131 * @since 1.0.0
132 */
133 private function get_comment( $id ) {
134 $comment = (object) (array) get_comment( $id );
135
136 if ( $comment instanceof stdClass ) {
137 $author_posts_page_link = $comment->comment_author_url;
138
139 if ( ! $author_posts_page_link ) {
140 $author_posts_page_link = \get_author_posts_url( $comment->user_id );
141 }
142
143 $comment->author_profile_picture = get_avatar_url( $comment->user_id );
144 $comment->author_posts_page_link = $author_posts_page_link;
145 }
146
147 return $comment;
148 }
149 }
150