PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.4
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.4
9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 8.5.4 All 221 releases
wpvr / admin / classes / class-wpvr-ajax.php

class-wpvr-ajax.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.4, at admin/classes/class-wpvr-ajax.php

488 lines 14.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit; // Exit if accessed directly
4 /**
5 * The admin-specific Ajax files.
6 *
7 * @link http://rextheme.com/
8 * @since 8.0.0
9 *
10 * @package Wpvr
11 * @subpackage Wpvr/admin
12 */
13
14 class Wpvr_Ajax
15 {
16
17 /**
18 * Instance of WPVR_Format class
19 *
20 * @var object
21 * @since 8.0.0
22 */
23 protected $format;
24
25
26 /**
27 * Instance of WPVR_StreetView class
28 *
29 * @var object
30 * @since 8.0.0
31 */
32 protected $streetview;
33
34
35 /**
36 * Instance of WPVR_Video class
37 *
38 * @var object
39 * @since 8.0.0
40 */
41 protected $video;
42
43
44 /**
45 * Instance of WPVR_Scene class
46 *
47 * @var object
48 * @since 8.0.0
49 */
50 protected $scene;
51
52
53 /**
54 * Instance of WPVR_Validator class
55 *
56 * @var object
57 * @since 8.0.0
58 */
59 protected $validator;
60
61
62 function __construct()
63 {
64 $this->format = new WPVR_Format();
65 $this->streetview = new WPVR_StreetView();
66 $this->video = new WPVR_Video();
67 $this->scene = new WPVR_Scene();
68 $this->validator = new WPVR_Validator();
69
70 add_action('wp_ajax_wpvr_save', array($this, 'wpvr_save_data'));
71 add_action('wp_ajax_wpvr_preview', array($this, 'wpvr_show_preview'));
72 add_action('wp_ajax_wpvrstreetview_preview', array($this, 'wpvrstreetview_preview'));
73 add_action('wp_ajax_wpvr_file_import', array($this, 'wpvr_file_import'));
74 add_action('wp_ajax_wpvr_role_management', array($this, 'wpvr_role_management'));
75 add_action('wp_ajax_wpvr_notice', array($this, 'wpvr_notice'));
76 add_action('wp_ajax_wpvr_halloween_offer_notice_dismiss', array($this, 'wpvr_halloween_offer_notice_dismiss'));
77 add_action('wp_ajax_wpvr_dismiss_black_friday_notice', array($this, 'dismiss_black_friday_notice'));
78 add_action('wp_ajax_wpvr_review_request', array($this, 'wpvr_review_request'));
79
80 //setup wizard ajax
81 add_action( 'wp_ajax_wpvr_create_contact', array($this, 'wpvr_create_contact' ) );
82 add_action( 'wp_ajax_wpvr_nopriv_create_contact', array($this, 'wpvr_create_contact' ) );
83
84 //general setting ajax
85 add_action( 'wp_ajax_wpvr_save_general_settings', array($this, 'wpvr_save_general_settings' ) );
86 add_action( 'wp_ajax_wpvr_save_general_settings', array($this, 'wpvr_save_general_settings' ) );
87 }
88
89 public function wpvr_review_request()
90 {
91 $nonce = sanitize_text_field($_POST['nonce']);
92 if (!wp_verify_nonce($nonce, 'wpvr-dismiss-notice-five-star-review')) {
93 $response = array(
94 'success' => false,
95 'data' => 'Permission denied.'
96 );
97 wp_send_json($response);
98 }
99 $payload = !empty($_POST['payload']) ? $_POST['payload'] : array();
100 $data = array(
101 'show' => !empty($payload['show']) ? $payload['show'] : '',
102 'time' => !empty($payload['frequency']) && 'never' !== $payload['frequency'] ? time() : '',
103 'frequency' => !empty($payload['frequency']) ? $payload['frequency'] : '',
104 );
105 update_option('wpvr_feed_review_request', $data);
106 $response = array(
107 'success' => true,
108 'data' => 'Review request updated successfully.'
109 );
110 wp_send_json($response);
111 die();
112 }
113
114 /**
115 * Responsible for Tour Preview
116 *
117 * @return void
118 * @since 8.0.0
119 */
120 public function wpvr_show_preview()
121 {
122 //===Current user capabilities check===//
123 if (!current_user_can('edit_posts')) {
124 $response = array(
125 'success' => false,
126 'data' => 'Contact admin.'
127 );
128 wp_send_json($response);
129 }
130 //===Current user capabilities check===//
131 //===Nonce check===//
132 $nonce = sanitize_text_field($_POST['nonce']);
133 if (!wp_verify_nonce($nonce, 'wpvr')) {
134 $response = array(
135 'success' => false,
136 'data' => 'Permission denied.'
137 );
138 wp_send_json($response);
139 }
140 //===Nonce check===//
141
142 $panoid = '';
143 $postid = sanitize_text_field($_POST['postid']);
144 $panoid = 'pano' . $postid;
145 if (isset($_POST['panovideo'])) {
146 $panovideo = sanitize_text_field($_POST['panovideo']);
147 }
148
149 $post_type = get_post_type($postid);
150 if ($post_type != 'wpvr_item') {
151 die();
152 }
153
154 do_action('wpvr_pro_street_view_preview', $postid, $panoid);
155
156 if ($panovideo == 'off') {
157 $this->scene->wpvr_scene_preview($panoid, $panovideo); // Preapre preview based on Scene data //
158 } else {
159 $this->video->wpvr_video_preview($panoid); // Prepare preview based on Video data //
160 }
161 }
162
163
164 /**
165 * Responsible for saving WPVR data
166 *
167 * @return void
168 * @since 8.0.0
169 */
170 public function wpvr_save_data()
171 {
172
173 //===Current user capabilities check===//
174 if (!current_user_can('edit_posts')) {
175 $response = array(
176 'success' => false,
177 'data' => 'Permission denied.'
178 );
179 wp_send_json($response);
180 }
181 //===Current user capabilities check===//
182 //===Nonce check===//
183 $nonce = sanitize_text_field($_POST['nonce']);
184 if (!wp_verify_nonce($nonce, 'wpvr')) {
185 $response = array(
186 'success' => false,
187 'data' => 'Permission denied.'
188 );
189 wp_send_json($response);
190 }
191 //===Nonce check===//
192 $panoid = '';
193 $postid = sanitize_text_field($_POST['postid']);
194 $post_type = get_post_type($postid);
195 if ($post_type != 'wpvr_item') {
196 die();
197 }
198 $panoid = 'pano' . $postid;
199
200 $post_status = get_post_status($postid);
201 if ($post_status != 'publish') {
202 wp_update_post(array(
203 'ID' => $postid,
204 'post_status' => 'publish'
205 ));
206 }
207
208 $post_array = [];
209 if (isset($_POST['post_status'])) {
210 $post_status = sanitize_text_field($_POST['post_status']);
211 $post_array['post_status'] = $post_status;
212 }
213 if (isset($_POST['post_password'])) {
214 $visibility = sanitize_text_field($_POST['post_password']);
215 $post_array['post_password'] = $visibility;
216 }
217 if (isset($_POST['visibility'])) {
218 $visibility = sanitize_text_field($_POST['visibility']);
219 $post_array['visibility'] = $visibility;
220 if ($visibility == 'public' || $visibility == 'private') {
221 $post_array['post_password'] = '';
222 }
223 }
224 if (isset($_POST['post_value'])) {
225 $post_value = sanitize_text_field($_POST['post_value']);
226 if ($post_array['visibility'] == 'private') {
227 $post_array['post_status'] = 'private';
228 } elseif ($post_value === 'Publish') {
229 $post_array['post_status'] = 'publish';
230 }
231 }
232 $post_title = sanitize_text_field($_POST['post_title']);
233 wp_update_post(array(
234 'ID' => $postid,
235 'post_status' => $post_array['post_status'],
236 'post_password' => $post_array['post_password'],
237 'visibility' => $post_array['visibility'],
238 'post_title' => $post_title,
239
240 ));
241
242 do_action('wpvr_pro_update_street_view', $postid, $panoid);
243
244 if ($_POST['panovideo'] == "on") {
245 $this->video->wpvr_update_meta_box($postid, $panoid);
246 } else {
247 $this->scene->wpvr_update_meta_box($postid, $panoid);
248 }
249 }
250
251
252 /**
253 * Responsible for importing tour
254 *
255 * @return void
256 * @since 8.0.0
257 */
258 public function wpvr_file_import()
259 {
260 //===Current user capabilities check===//
261 if (!current_user_can('edit_posts')) {
262 $response = array(
263 'success' => false,
264 'data' => 'Permission denied.'
265 );
266 wp_send_json($response);
267 }
268 //===Current user capabilities check===//
269 //===Nonce check===//
270 $nonce = sanitize_text_field($_POST['nonce']);
271 if (!wp_verify_nonce($nonce, 'wpvr')) {
272 $response = array(
273 'success' => false,
274 'data' => 'Permission denied.'
275 );
276 wp_send_json($response);
277 }
278 //===Nonce check===//
279 WPVR_Import::prepare_tour_import_feature();
280 }
281
282
283
284 /**
285 * WPVR Role Management
286 *
287 * @return void
288 * @since 8.0.0
289 */
290 function wpvr_role_management()
291 {
292
293 //===Current user capabilities check===//
294 if (!current_user_can('edit_posts')) {
295 $response = array(
296 'success' => false,
297 'data' => 'Permission denied.'
298 );
299 wp_send_json($response);
300 }
301 //===Current user capabilities check===//
302 //===Nonce check===//
303 $nonce = sanitize_text_field($_POST['nonce']);
304 if (!wp_verify_nonce($nonce, 'wpvr')) {
305 $response = array(
306 'success' => false,
307 'data' => 'Permission denied.'
308 );
309 wp_send_json($response);
310 }
311 //===Nonce check===//
312
313 $editor = sanitize_text_field($_POST['editor']);
314 $author = sanitize_text_field($_POST['author']);
315 $fontawesome = sanitize_text_field($_POST['fontawesome']);
316
317
318 $cardboard = !empty($_POST['wpvr_cardboard_disable']) ? sanitize_text_field($_POST['wpvr_cardboard_disable']) : 'no'; //
319
320 $wpvr_webp_conversion = !empty($_POST['wpvr_webp_conversion']) ? sanitize_text_field($_POST['wpvr_webp_conversion']) : 'no';
321
322 $mobile_media_resize = sanitize_text_field($_POST['mobile_media_resize']);
323 $high_res_image = sanitize_text_field($_POST['high_res_image']);
324 $dis_on_hover = sanitize_text_field($_POST['dis_on_hover']);
325 $wpvr_frontend_notice = sanitize_text_field($_POST['wpvr_frontend_notice']);
326 $wpvr_frontend_notice_area = sanitize_text_field($_POST['wpvr_frontend_notice_area']);
327 $wpvr_script_control = sanitize_text_field($_POST['wpvr_script_control']);
328 $wpvr_script_list = sanitize_text_field($_POST['wpvr_script_list']);
329
330 $wpvr_video_script_control = sanitize_text_field($_POST['wpvr_video_script_control']);
331 $wpvr_video_script_list = sanitize_text_field($_POST['wpvr_video_script_list']);
332
333 // $enable_woocommerce = sanitize_text_field($_POST['woocommerce']);
334
335 $wpvr_script_list = str_replace(' ', '', $wpvr_script_list);
336
337 update_option('wpvr_editor_active', $editor);
338 update_option('wpvr_author_active', $author);
339 update_option('wpvr_fontawesome_disable', $fontawesome);
340 update_option('wpvr_cardboard_disable', $cardboard);
341 update_option('wpvr_webp_conversion', $wpvr_webp_conversion);
342 update_option('mobile_media_resize', $mobile_media_resize);
343 update_option('high_res_image', $high_res_image);
344 update_option('dis_on_hover', $dis_on_hover);
345 update_option('wpvr_frontend_notice', $wpvr_frontend_notice);
346 update_option('wpvr_frontend_notice_area', $wpvr_frontend_notice_area);
347 update_option('wpvr_script_control', $wpvr_script_control);
348 update_option('wpvr_script_list', $wpvr_script_list);
349
350 update_option('wpvr_video_script_control', $wpvr_video_script_control);
351 update_option('wpvr_video_script_list', $wpvr_video_script_list);
352
353 // update_option('wpvr_enable_woocommerce', $enable_woocommerce);
354
355 $response = array(
356 'status' => 'success',
357 'message' => 'Successfully saved',
358 );
359 wp_send_json($response);
360 }
361
362
363 /**
364 * WPVR Notice
365 *
366 * @return void
367 * @since 8.0.0
368 */
369 function wpvr_notice()
370 {
371 //===Current user capabilities check===//
372 if (!current_user_can('edit_posts')) {
373 $response = array(
374 'success' => false,
375 'data' => 'Permission denied.'
376 );
377 wp_send_json($response);
378 }
379 //===Current user capabilities check===//
380 //===Nonce check===//
381 $nonce = sanitize_text_field($_POST['nonce']);
382 if (!wp_verify_nonce($nonce, 'wpvr')) {
383 $response = array(
384 'success' => false,
385 'data' => 'Permission denied.'
386 );
387 wp_send_json($response);
388 }
389 //===Nonce check===//
390 update_option('wpvr_black_friday_notice', '1');
391 }
392
393 /**
394 * WPVR Halloween Notice
395 *
396 * @return void
397 */
398 function wpvr_halloween_offer_notice_dismiss()
399 {
400 update_option('_is_wpvr_promotion', 'no');
401 wp_send_json([
402 'success' => true,
403 ]);
404 }
405
406
407 /**
408 * Dismiss black friday notice
409 */
410 function dismiss_black_friday_notice()
411 {
412 if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'wpvr')) {
413 wp_die(__('Permission check failed', 'wpvr'));
414 }
415 update_option('_wpvr_eid_al_adha_2024', 'yes');
416 echo json_encode(['success' => true,]);
417 wp_die();
418 }
419
420 /**
421 * Handles the creation of a contact via a webhook.
422 *
423 * This function validates the nonce, sanitizes and validates the input fields,
424 * and then creates a new contact using the WPVR_Create_Contact class.
425 *
426 * @since 8.4.10
427 */
428 function wpvr_create_contact(){
429 $nonce = filter_input(INPUT_POST, 'security', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
430 $nonce = !empty( $nonce ) ? $nonce : null;
431 if ( !wp_verify_nonce( $nonce, 'wpvr' ) ) {
432 wp_send_json_error( array( 'message' => 'Invalid nonce' ), 400 );
433 return;
434 }
435
436 $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
437 $industry = filter_input(INPUT_POST, 'industry', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
438 $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
439
440 $name = !empty($name) ? $name: '';
441 $industry = !empty($industry ) ? $industry : '';
442 $email = !empty( $email ) ? $email : '';
443
444 if ( empty( $email ) ) {
445 wp_send_json_error( array( 'message' => __('Email is required', 'rex-product-feed') ), 400 );
446 }elseif( !is_email( $email ) ){
447 wp_send_json_error( array( 'message' => __('Email is invalid', 'rex-product-feed') ), 400 );
448 }
449
450 $create_contact_instance = new WPVR_Create_Contact( $email, $name, $industry );
451 $response = $create_contact_instance->create_contact_via_webhook();
452
453 if ( $response ) {
454 wp_send_json_success( array( 'message' => __('Contact created successfully', 'wpvr') ), 200 );
455 } else {
456 wp_send_json_error( array( 'message' => __('Failed to create contact', 'wpvr') ), 500 );
457 }
458 }
459
460 /**
461 * Saves the general settings for the WPVR plugin.
462 *
463 * This function handles the nonce verification, sanitizes the input fields,
464 * and updates the options in the database. It responds with a JSON success or error message.
465 *
466 * @since 8.4.10
467 */
468 function wpvr_save_general_settings(){
469 $nonce = filter_input(INPUT_POST, 'security', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
470 $nonce = !empty( $nonce ) ? $nonce : null; // phpcs:ignore
471 if ( !wp_verify_nonce( $nonce, 'wpvr' ) ) {
472 wp_send_json_error( array( 'message' => 'Invalid nonce' ), 400 );
473 return;
474 }
475
476 $is_mobile_media_resize = filter_input(INPUT_POST, 'media_resizer', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
477 $convert_to_webp = filter_input(INPUT_POST, 'convert_to_webp', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
478 $vr_glass_support = filter_input(INPUT_POST, 'vr_glass_support', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
479
480 update_option('mobile_media_resize', $is_mobile_media_resize);
481 update_option('wpvr_webp_conversion', $convert_to_webp);
482 update_option('wpvr_cardboard_disable', $vr_glass_support);
483
484 wp_send_json_success( array( 'message' => __('General setting data successfully saved.', 'wpvr') ), 200 );
485 }
486
487 }
488