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.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 / includes / kirki / backend / Ajax.php
tutor / includes / kirki / backend Last commit date
ElementGenerator 2 months ago Ajax.php 1 week ago Backend.php 2 months ago Editor.php 2 months ago Frontend.php 2 months ago Helper.php 2 months ago Hooks.php 2 months ago Iframe.php 2 months ago Pages.php 2 months ago VisibilityCondition.php 1 month ago
Ajax.php
217 lines
1 <?php
2 /**
3 * Preview script for html markup generator
4 *
5 * @package tutor-kirki-elements
6 */
7
8 namespace TutorLMSKirki;
9
10 use Kirki\HelperFunctions;
11 use stdClass;
12 use TutorLMSKirki\ElementGenerator\Preview;
13 use TUTOR\Input;
14 use Tutor\Models\CourseModel;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly.
18 }
19
20 /**
21 * Class Ajax
22 * This class is used to define all ajax functions.
23 *
24 * @package TutorLMSKirki
25 * @since 1.0.0
26 */
27 class Ajax {
28
29
30 /**
31 * Class constructor
32 */
33 public function __construct() {
34 add_action( 'wp_ajax_tutor_handle_api_calls', array( $this, 'tutor_handle_api_calls' ) );
35 add_action( 'wp_ajax_nopriv_tutor_handle_api_calls', array( $this, 'tutor_handle_api_calls' ) );
36 }
37
38 /**
39 * Handle api calls
40 *
41 * @since 1.0.0
42 */
43 public function tutor_handle_api_calls() {
44 $request_method = Input::post( 'method' );
45 $is_user_logged_in = is_user_logged_in();
46
47 tutor_utils()->checking_nonce();
48
49 if ( 'generate_html' === $request_method ) {
50
51 $course_id = Input::post( 'course_id' );
52 $kirki_data = isset( $_REQUEST['kirki_data'] ) ? wp_unslash( $_REQUEST['kirki_data'] ) : null; //phpcs:ignore
53 $kirki_data = json_decode( $kirki_data, true );
54
55 $blocks = $kirki_data['blocks'];
56 $styles = $kirki_data['styles'];
57 $root = Input::sanitize( $kirki_data['root'] );
58
59 $params = array(
60 'blocks' => $blocks,
61 'style_blocks' => $styles,
62 'root' => $root,
63 'get_variable' => false,
64 'get_fonts' => false,
65 'options' => array( 'post' => get_post( $course_id ) ),
66 );
67
68 $collection_wrapper_html_string = HelperFunctions::get_html_using_preview_script( $params );
69 wp_send_json_success( $collection_wrapper_html_string );
70 }
71
72 if ( 'enroll_course' === $request_method && $is_user_logged_in ) {
73 $course_id = Input::post( 'course_id' );
74
75 $course = get_post( $course_id );
76
77 if ( ! $course || ! is_object( $course ) || $course->post_status !== 'publish' ) {
78 wp_send_json_error( 'Course not found!' );
79 }
80
81 if ( tutor_utils()->is_course_purchasable( $course_id ) ) {
82 wp_send_json_error( 'You cannot enroll in this course without purchasing it first.' );
83 }
84
85 $res = tutor_utils()->do_enroll( $course_id );
86
87 wp_send_json_success( $res );
88 }
89
90 if ( 'add_to_cart_course' === $request_method ) {
91 $course_id = Input::post( 'course_id' );
92 $res = tutor_add_to_cart( $course_id );
93
94 // check is user logged in or not
95 if (! is_user_logged_in() ) {
96 $res['redirect'] = true;
97 $res['data'] = wp_login_url( wp_get_referer() );
98 }
99
100 wp_send_json_success( $res );
101 }
102
103 if ('remove_from_cart_course' === $request_method) {
104 $res = tutor_remove_cart_item(Input::post('course_id'));
105 wp_send_json_success($res);
106 }
107
108 if('get_user_cart_item_count' === $request_method) {
109 $cart_items = tutor_get_cart_items();
110 $count = count($cart_items);
111 wp_send_json_success($count);
112 }
113
114 if ( 'complete_course' === $request_method && $is_user_logged_in ) {
115 $course_id = Input::post( 'course_id' );
116
117 $is_enrolled = tutor_utils()->is_enrolled($course_id);
118
119 if ( ! $is_enrolled ) {
120 wp_send_json_error( 'You are not allowed to complete this course.' );
121 }
122
123 $user_id = get_current_user_id();
124
125 CourseModel::mark_course_as_completed( $course_id, $user_id );
126
127 wp_send_json_success( true );
128 }
129
130 if ( 'add_qna' === $request_method && $is_user_logged_in ) {
131 $course_id = Input::post( 'course_id' );
132
133 $is_enrolled = tutor_utils()->is_enrolled($course_id);
134
135 if ( ! $is_enrolled ) {
136 wp_send_json_error( 'You are not allowed to add Q&A to this course.' );
137 }
138
139 $comment_parent_id = Input::post( 'comment_parent_id' );
140 $content = Input::post( 'content' );
141
142 $user = wp_get_current_user();
143 $date = gmdate( 'Y-m-d H:i:s', tutor_time() );
144
145 $collection_data = isset($_REQUEST['collection_data']) ? json_decode(wp_unslash($_REQUEST['collection_data']), true) : null; //phpcs:ignore
146
147 if ( ! $content ) {
148 wp_send_json_error( 'Invalid request' );
149 }
150
151 $data = apply_filters(
152 'tutor_qna_insert_data',
153 array(
154 'comment_post_ID' => $course_id,
155 'comment_author' => $user->user_login,
156 'comment_date' => $date,
157 'comment_date_gmt' => get_gmt_from_date( $date ),
158 'comment_content' => $content,
159 'comment_approved' => 'approved',
160 'comment_agent' => 'TutorLMSPlugin',
161 'comment_type' => 'tutor_q_and_a',
162 'comment_parent' => $comment_parent_id,
163 'user_id' => $user->ID,
164 )
165 );
166
167 global $wpdb;
168
169 $response = $wpdb->insert( $wpdb->comments, $data );
170
171 if ( false === $response ) {
172 wp_send_json_error( 'Request failed!' );
173 }
174
175 $thread = $this->get_comment( $wpdb->insert_id );
176
177 // comment-item.// -qna-reply.
178 $new_element_name = 0 === $comment_parent_id ? 'comment-item' : TDE_APP_PREFIX . '-qna-reply';
179
180 $new_element = Preview::generateQnAElement( $thread, $new_element_name, $collection_data );
181
182 wp_send_json_success(
183 array(
184 'html' => $new_element,
185 'inserted_comment_id' => $wpdb->insert_id,
186 )
187 );
188 }
189
190 wp_send_json_error( 'Invalid request' );
191 }
192
193 /**
194 * Get comment
195 *
196 * @param int $id comment id.
197 * @return object
198 * @since 1.0.0
199 */
200 private function get_comment( $id ) {
201 $comment = (object) (array) get_comment( $id );
202
203 if ( $comment instanceof stdClass ) {
204 $author_posts_page_link = $comment->comment_author_url;
205
206 if ( ! $author_posts_page_link ) {
207 $author_posts_page_link = \get_author_posts_url( $comment->user_id );
208 }
209
210 $comment->author_profile_picture = get_avatar_url( $comment->user_id );
211 $comment->author_posts_page_link = $author_posts_page_link;
212 }
213
214 return $comment;
215 }
216 }
217