PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.77
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.77
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 / helpers / class-wpvr-validator.php

class-wpvr-validator.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.77, at admin/helpers/class-wpvr-validator.php

606 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit; // Exit if accessed directly
3 /**
4 * Manage all validation requirements and messages
5 *
6 * @link http://rextheme.com/
7 * @since 8.0.0
8 *
9 * @package Wpvr
10 * @subpackage Wpvr/admin/classes
11 */
12
13 class WPVR_Validator {
14
15 /**
16 * Get all error messages
17 *
18 * @var array
19 * @since 8.0.0
20 */
21 public $errors = array();
22
23
24 /**
25 * Auto-rotation data error control and validation
26 *
27 * @param number $autorotationinactivedelay
28 * @param number $autorotationstopdelay
29 *
30 * @return void
31 * @since 8.0.0
32 */
33 public function basic_setting_validation($autorotationinactivedelay, $autorotationstopdelay)
34 {
35 if (!empty($autorotationinactivedelay) && !empty($autorotationstopdelay)) {
36 $this->add_error('autorotation_dual_action', '<span class="pano-error-title">Dual Action Error for Auto-Rotation</span><p> You can not use both Resume Auto-rotation & Stop Auto-rotation on the same tour. You can use only one of them.</p>');
37 }
38 }
39
40
41 /**
42 * Preview Image Message error control and validation
43 *
44 * @param string $text
45 *
46 * @return string
47 * @since 8.0.0
48 */
49 public function preview_text_validation($text)
50 {
51 $prevtext = sanitize_text_field($text);
52 if (strlen($prevtext) > 50) {
53 $this->add_error('preview_text', '<p><span>Warning:</span> Don\'t add more than 50 characters in Preview Image Message</p>');
54 }
55 return $prevtext;
56 }
57
58
59 /**
60 * Scene content error control and validation
61 * @param array $panodata
62 *
63 * @return void
64 * @since 8.0.0
65 */
66 public function scene_validation($panodata)
67 {
68 if ($panodata["scene-list"] != "") {
69 foreach ($panodata["scene-list"] as $scenes_val) {
70 $scene_id_validate = $scenes_val["scene-id"];
71
72 if (!empty($scene_id_validate)) {
73
74 $scene_id_validated = preg_replace('/[^0-9a-zA-Z_]/', "", $scene_id_validate ?? '');
75 if ($scene_id_validated != $scene_id_validate) {
76 $this->add_error('invalid_scene_id', '<span class="pano-error-title">Invalid Scene ID</span> <p>Scene ID can\'t contain spaces and special characters. <br/>Please assign a unique Scene ID with letters and numbers where Scene ID is : ' . $scene_id_validate . '</p>');
77 }
78
79 $this->scene_attachment_validation($scenes_val, $scene_id_validate); // Attachment error control and validation //
80
81 $this->scene_pitch_yaw_validation($scenes_val, $scene_id_validate); // Pitch and yaw error controll and validation //
82
83 $this->scene_default_zoom_validation($scenes_val, $scene_id_validate); // Default zoom error controll and validation //
84
85 $this->scene_max_zoom_validation($scenes_val, $scene_id_validate); // Max zoom error controll and validation //
86
87 $this->scene_min_zoom_validation($scenes_val, $scene_id_validate); // Min zoom error controll and validation //
88
89 $this->scene_hotspot_validation($scenes_val, $scene_id_validate); // Hotspot error controll and validation //
90 }
91 }
92 }
93 }
94
95
96 /**
97 * Empty image, Scene ID, and duplicate scene
98 * Error control and validation
99 *
100 * @param array $panodata
101 *
102 * @return void
103 * @since 8.0.0
104 */
105 public function empty_scene_validation($panodata)
106 {
107 $allsceneids = array();
108
109 foreach ($panodata["scene-list"] as $panoscenes) {
110 if (empty($panoscenes['scene-id']) && !empty($panoscenes['scene-attachment-url'])) {
111 $this->add_error('missing_scene_id', '<span class="pano-error-title">Missing Scene ID</span> <p>Please assign a unique Scene ID to your uploaded scene.</p>');
112 }
113 if (!empty($panoscenes['scene-id'])) {
114 array_push($allsceneids, $panoscenes['scene-id']);
115 }
116 }
117
118 foreach ($panodata["scene-list"] as $panoscenes) {
119
120 if ($panoscenes['dscene'] == 'on') {
121 $default_scene = $panoscenes['scene-id'];
122 }
123 }
124 if (empty($default_scene)) {
125 if ($allsceneids) {
126 $default_scene = $allsceneids[0];
127 } else {
128 $this->add_error('missing_image_scene', '<span class="pano-error-title">Missing Image & Scene ID</span> <p>Please Upload An Image and Set A Scene ID To See The Preview</p>');
129 }
130 }
131
132 $allsceneids_count = array_count_values($allsceneids);
133 foreach ($allsceneids_count as $key => $value) {
134 if ($value > 1) {
135 $this->add_error('duplicate_scene', '<span class="pano-error-title">Duplicate Scene ID</span> <p>You\'ve assigned a duplicate Scene ID. <br/>Please assign unique Scene IDs to each scene. </p>');
136 }
137 }
138 }
139
140
141 /**
142 * Scene attachment error controll and validation
143 *
144 * @param array $scenes_val
145 * @param string $scene_id_validate
146 *
147 * @return void
148 * @since 8.0.0
149 */
150 private function scene_attachment_validation($scenes_val, $scene_id_validate)
151 {
152 if ($scenes_val['scene-type'] == 'cubemap') {
153 if (empty($scenes_val["scene-attachment-url-face0"])) {
154 $this->add_error('cubemap_0', '<span class="pano-error-title">Missing Cubemap Scene Face 0</span><p> Please upload a 360 Degree image where Scene ID is: ' . $scene_id_validate . '</p>');
155 }
156
157 if (empty($scenes_val["scene-attachment-url-face1"])) {
158 $this->add_error('cubemap_1', '<span class="pano-error-title">Missing Cubemap Scene Face 1</span><p> Please upload a 360 Degree image where Scene ID is: ' . $scene_id_validate . '</p>');
159 }
160
161 if (empty($scenes_val["scene-attachment-url-face2"])) {
162 $this->add_error('cubemap_2', '<span class="pano-error-title">Missing Cubemap Scene Face 2</span><p> Please upload a 360 Degree image where Scene ID is: ' . $scene_id_validate . '</p>');
163 }
164
165 if (empty($scenes_val["scene-attachment-url-face3"])) {
166 $this->add_error('cubemap_3', '<span class="pano-error-title">Missing Cubemap Scene Face 3</span><p> Please upload a 360 Degree image where Scene ID is: ' . $scene_id_validate . '</p>');
167 }
168
169 if (empty($scenes_val["scene-attachment-url-face4"])) {
170 $this->add_error('cubemap_4', '<span class="pano-error-title">Missing Cubemap Scene Face 4</span><p> Please upload a 360 Degree image where Scene ID is: ' . $scene_id_validate . '</p>');
171 }
172
173 if (empty($scenes_val["scene-attachment-url-face5"])) {
174 $this->add_error('cubemap_5', '<span class="pano-error-title">Missing Cubemap Scene Face 5</span><p> Please upload a 360 Degree image where Scene ID is: ' . $scene_id_validate . '</p>');
175 }
176 } else {
177 if (empty($scenes_val["scene-attachment-url"])) {
178 $this->add_error('missing_scene', '<span class="pano-error-title">Missing Scene Image</span><p> Please upload a 360 Degree image where Scene ID is: ' . $scene_id_validate . '</p>');
179 }
180 }
181 }
182
183
184
185 /**
186 * Scene default zoom error control and validation
187 *
188 * @param array $scenes_val
189 * @param string $scene_id_validate
190 *
191 * @return void
192 * @since 8.0.0
193 */
194 private function scene_default_zoom_validation($scenes_val, $scene_id_validate)
195 {
196 if (!empty($scenes_val["scene-zoom"])) {
197 $validate_default_zoom = $scenes_val["scene-zoom"];
198 $validated_default_zoom = preg_replace('/[^0-9-]/', '', $validate_default_zoom ?? '');
199 if ($validated_default_zoom != $validate_default_zoom) {
200 $this->add_error('invalid_default_zoom', '<span class="pano-error-title">Invalid Default Zoom Value</span><p> You can only set Default Zoom in Degree values from 50 to 120 where Scene ID: ' . $scene_id_validate . '</p>');
201 }
202 $default_zoom_value = (int)$scenes_val["scene-zoom"];
203 if ($default_zoom_value > 120 || $default_zoom_value < 50) {
204 $this->add_error('invalid_default_zoom', '<span class="pano-error-title">Invalid Default Zoom Value</span><p> You can only set Default Zoom in Degree values from 50 to 120 where Scene ID: ' . $scene_id_validate . '</p>');
205 }
206 }
207 }
208
209
210 /**
211 * Scene max zoom error control and validation
212 *
213 * @param array $scenes_val
214 * @param string $scene_id_validate
215 *
216 * @return void
217 * @since 8.0.0
218 */
219 private function scene_max_zoom_validation($scenes_val, $scene_id_validate)
220 {
221 if (!empty($scenes_val["scene-maxzoom"])) {
222 $validate_max_zoom = $scenes_val["scene-maxzoom"];
223 $validated_max_zoom = preg_replace('/[^0-9-]/', '', $validate_max_zoom ?? '');
224 if ($validated_max_zoom != $validate_max_zoom) {
225 $this->add_error('invalid_max_zoom', '<span class="pano-error-title">Invalid Max-zoom Value:</span><p> You can only set Max-zoom in degree values (50-120) where Scene ID: ' . $scene_id_validate . '</p>');
226 }
227 $max_zoom_value = (int)$scenes_val["scene-maxzoom"];
228 if ($max_zoom_value > 120) {
229 $this->add_error('limit_max_zoom', '<span class="pano-error-title">Max-zoom Value Limit Exceeded</span><p> You can set the Max-zoom Value up to 120 degrees.</p>');
230 }
231
232 if ($max_zoom_value < 50) {
233 $this->add_error('limit_max_zoom', '<span class="pano-error-title">Max-zoom Value Limit Exceeded</span><p> You can not set the Max-zoom Value lower than 50 degrees.</p>');
234 }
235 }
236 }
237
238
239 /**
240 * Scene min zoom error control and validation
241 *
242 * @param array $scenes_val
243 * @param string $scene_id_validate
244 *
245 * @return void
246 * @since 8.0.0
247 */
248 private function scene_min_zoom_validation($scenes_val, $scene_id_validate)
249 {
250 if (!empty($scenes_val["scene-minzoom"])) {
251 $validate_min_zoom = $scenes_val["scene-minzoom"];
252 $validated_min_zoom = preg_replace('/[^0-9-]/', '', $validate_min_zoom ?? '');
253 if ($validated_min_zoom != $validate_min_zoom) {
254 $this->add_error('invalid_min_zomm', '<span class="pano-error-title">Invalid Min-zoom Value</span><p> You can only set Min-zoom in degree values (50-120) where Scene ID: ' . $scene_id_validate . '</p>');
255 }
256 $min_zoom_value = (int)$scenes_val["scene-minzoom"];
257 if ($min_zoom_value < 50) {
258 $this->add_error('low_min_zoom', '<span class="pano-error-title">Low Min-Zoom Value</span><p> The Min-zoom value must be more than 50 in degree values where Scene ID: ' . $scene_id_validate . '</p>');
259 }
260
261 if ($min_zoom_value > 120) {
262 $this->add_error('low_min_zoom', '<span class="pano-error-title">Hight Min-Zoom Value</span><p> The Min-zoom value must be less than 120 in degree values where Scene ID: ' . $scene_id_validate . '</p>');
263 }
264 }
265 }
266
267
268 /**
269 * Scene hotspot error control and validation
270 *
271 * @param array $scenes_val
272 * @param string $scene_id_validate
273 *
274 * @return void
275 * @since 8.0.0
276 */
277 private function scene_hotspot_validation($scenes_val, $scene_id_validate)
278 {
279 if ($scenes_val["hotspot-list"] != "") {
280 foreach ($scenes_val["hotspot-list"] as $hotspot_val) {
281
282 $hotspot_title_validate = $hotspot_val["hotspot-title"];
283
284 if (!empty($hotspot_title_validate)) {
285 $this->hotspot_id_validation($scene_id_validate, $hotspot_title_validate); // ID error control and validation //
286
287 $this->hotspot_pitch_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate); // Pitch error control and validation //
288
289 $this->hotspot_yaw_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate); // Yaw error control and validation //
290
291 $this->hotspot_custom_icon_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate); // Custom icon error control and validation //
292
293 $this->hotspot_url_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate); // URL error control and validation //
294
295 $this->info_hotspot_type_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate); // Info type error control and validation //
296
297 $this->hotspot_shortcode_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate); // Shortcode error control and validation //
298
299 $this->scene_type_hotspot_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate); // Scene type error control and validation //
300 }
301 }
302 }
303 }
304
305
306 /**
307 * Scene pitch and yaw error control and validation
308 *
309 * @param array $scenes_val
310 * @param string $scene_id_validate
311 *
312 * @return void
313 * @since 8.0.0
314 */
315 private function scene_pitch_yaw_validation($scenes_val, $scene_id_validate)
316 {
317 if (!empty($scenes_val["scene-pitch"])) {
318 $validate_scene_pitch = $scenes_val["scene-pitch"];
319 $validated_scene_pitch = preg_replace('/[^0-9.-]/', '', $validate_scene_pitch ?? '');
320 if ($validated_scene_pitch != $validate_scene_pitch) {
321 $this->add_error('invalid_pitch', '<span class="pano-error-title">Invalid Pitch Value</span><p> The Pitch Value can only contain float numbers where Scene ID: ' . $scene_id_validate . '</p>');
322 }
323 }
324
325 if (!empty($scenes_val["scene-yaw"])) {
326 $validate_scene_yaw = $scenes_val["scene-yaw"];
327 $validated_scene_yaw = preg_replace('/[^0-9.-]/', '', $validate_scene_yaw ?? '');
328 if ($validated_scene_yaw != $validate_scene_yaw) {
329 $this->add_error('invalid_yaw', '<span class="pano-error-title">Invalid Yaw Value</span><p> The Yaw Value can only contain float numbers where Scene ID: ' . $scene_id_validate . '</p>');
330 }
331 }
332 }
333
334
335 /**
336 * Hotspot pitch error control and validation
337 *
338 * @param array $hotspot_val
339 * @param string $scene_id_validate
340 * @param string $hotspot_title_validate
341 *
342 * @return void
343 * @since 8.0.0
344 */
345 private function hotspot_pitch_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate)
346 {
347 $hotspot_pitch_validate = $hotspot_val["hotspot-pitch"];
348 if (empty($hotspot_pitch_validate)) {
349 $this->add_error('pitch_required', '<p><span>Warning:</span> Hotspot pitch is required for every hotspot where scene id: ' . $scene_id_validate . ' and hotspot id : ' . $hotspot_title_validate . '</p>');
350 }
351 if (!empty($hotspot_pitch_validate)) {
352 $hotspot_pitch_normalized = trim($hotspot_pitch_validate ?? '');
353 $hotspot_pitch_validated = preg_replace('/[^0-9.-]/', '', $hotspot_pitch_normalized);
354 if ($hotspot_pitch_validated != $hotspot_pitch_normalized) {
355 $this->add_error('invalid_pitch', '<span class="pano-error-title">Invalid Pitch Value</span> <p>The Pitch Value can only contain float numbers where Scene ID: ' . $scene_id_validate . ' Hotspot ID is: ' . $hotspot_title_validate . '</p>');
356 }
357 }
358 }
359
360
361 /**
362 * Hotspot yaw error control and validation
363 *
364 * @param array $hotspot_val
365 * @param string $scene_id_validate
366 * @param string $hotspot_title_validate
367 *
368 * @return void
369 * @since 8.0.0
370 */
371 private function hotspot_yaw_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate)
372 {
373 $hotspot_yaw_validate = $hotspot_val["hotspot-yaw"];
374 if (empty($hotspot_yaw_validate)) {
375 $this->add_error('yaw_required', '<p><span>Warning:</span> Hotspot yaw is required for every hotspot where scene id: ' . $scene_id_validate . ' and hotspot id : ' . $hotspot_title_validate . '</p>');
376 }
377 if (!empty($hotspot_yaw_validate)) {
378 $hotspot_yaw_normalized = trim($hotspot_yaw_validate ?? '');
379 $hotspot_yaw_validated = preg_replace('/[^0-9.-]/', '', $hotspot_yaw_normalized);
380 if ($hotspot_yaw_validated != $hotspot_yaw_normalized) {
381 $this->add_error('invalid_yaw', '<span class="pano-error-title">Invalid Yaw Value</span> <p>The Yaw Value can only contain float numbers where Scene ID: ' . $scene_id_validate . ' Hotspot ID is: ' . $hotspot_title_validate . '</p>');
382 }
383 }
384 }
385
386
387 /**
388 * Info type hotspot error control and validation
389 *
390 * @param array $hotspot_val
391 * @param string $scene_id_validate
392 * @param string $hotspot_title_validate
393 *
394 * @return void
395 * @since 8.0.0
396 */
397 private function info_hotspot_type_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate)
398 {
399 if ($hotspot_val["hotspot-type"] == "info") {
400 if (!empty($hotspot_val["hotspot-scene"])) {
401 $this->add_error('target_scene_info_type', '<p><span>Warning:</span> Don\'t add Target Scene ID on info type hotspot where scene id: ' . $scene_id_validate . ' and hotspot id : ' . $hotspot_title_validate . '</p>');
402 }
403 if (!empty($hotspot_val["hotspot-url"]) && !empty($hotspot_val["hotspot-content"])) {
404 $this->add_error('both_click_content_url', '<span class="pano-error-title">Warning!</span> <p>You can not set both On Click Content and URL on a hotspot where scene id: ' . $scene_id_validate . ' and hotspot id : ' . $hotspot_title_validate . '</p>');
405 }
406 }
407 }
408
409 /**
410 * Scene type hotspot error control and validation
411 *
412 * @param array $hotspot_val
413 * @param string $scene_id_validate
414 * @param string $hotspot_title_validate
415 *
416 * @return void
417 * @since 8.0.0
418 */
419 private function scene_type_hotspot_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate)
420 {
421 if ($hotspot_val["hotspot-type"] == "scene") {
422 if (empty($hotspot_val["hotspot-scene"])) {
423 $this->add_error('target_scene_missing', '<span class="pano-error-title">Target Scene Missing</span> <p>Assign a Target Scene to the Scene-type Hotspot where Scene ID: ' . $scene_id_validate . ' and Hotspot ID : ' . $hotspot_title_validate . '</p>');
424 }
425 if (!empty($hotspot_val["hotspot-url"]) || !empty($hotspot_val["hotspot-content"])) {
426 $this->add_error('both_url_click_content', '<p><span>Warning:</span> Don\'t add Url or On click content on scene type hotspot where scene id: ' . $scene_id_validate . ' and hotspot id : ' . $hotspot_title_validate . '</p>');
427 }
428 }
429 }
430
431
432 /**
433 * Hotspot URL error control and validation
434 *
435 * @param array $hotspot_val
436 * @param string $scene_id_validate
437 * @param string $hotspot_title_validate
438 *
439 * @return void
440 * @since 8.0.0
441 */
442 private function hotspot_url_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate)
443 {
444 $hotspot_url_validate = $hotspot_val["hotspot-url"];
445 if (!empty($hotspot_url_validate)) {
446 $hotspot_url_validated = esc_url($hotspot_url_validate);
447 if ($hotspot_url_validated != $hotspot_url_validate) {
448 $this->add_error('invalid_hotspot_url', '<p><span>Warning:</span> Hotspot Url is invalid where scene id: ' . $scene_id_validate . ' and hotspot id : ' . $hotspot_title_validate . '</p>');
449 }
450 }
451 }
452
453
454 /**
455 * Hotspot Shortcode error control and validation
456 *
457 * @param array $hotspot_val
458 * @param string $scene_id_validate
459 * @param string $hotspot_title_validate
460 *
461 * @return void
462 * @since 8.0.0
463 */
464 private function hotspot_shortcode_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate)
465 {
466 if ($hotspot_val["hotspot-type"] == "shortcode_editor") {
467 if (substr($hotspot_val['hotspot-shortcode'], 0, 1) === '[') {
468 $pattern = get_shortcode_regex();
469 preg_match('/' . $pattern . '/s', $hotspot_val['hotspot-shortcode'], $matches);
470 if (is_array($matches) && !isset($matches[2])) {
471 $this->add_error('invalid_shortcode', '<p><span>Warning:</span> This is not a valid shortcode where scene id: ' . $scene_id_validate . ' and hotspot id : ' . $hotspot_title_validate . '</p>');
472 }
473 }
474 }
475 }
476
477 /**
478 * Hotspot custom icon error control and validation
479 *
480 * @param array $hotspot_val
481 * @param string $scene_id_validate
482 * @param string $hotspot_title_validate
483 *
484 * @return void
485 * @since 8.0.0
486 */
487 private function hotspot_custom_icon_validation($hotspot_val, $scene_id_validate, $hotspot_title_validate)
488 {
489 if (is_plugin_active('wpvr-pro/wpvr-pro.php')) {
490 $status = get_option('wpvr_edd_license_status');
491 if ($status !== false && $status == 'valid') {
492 if ($hotspot_val["hotspot-customclass-pro"] != 'none' && !empty($hotspot_val["hotspot-customclass"])) {
493 $this->add_error('both_custom_icon', '<span class="pano-error-title">Warning!</span> <p>You can not use both Custom Icon and Custom Icon Class for a hotspot where scene id: ' . $scene_id_validate . ' and hotspot id : ' . $hotspot_title_validate . '</p>');
494 }
495 }
496 }
497 }
498
499
500 /**
501 * Hotspot ID error control and validation
502 *
503 * @param string $scene_id_validate
504 * @param string $hotspot_title_validate
505 *
506 * @return void
507 */
508 private function hotspot_id_validation($scene_id_validate, $hotspot_title_validate)
509 {
510 $hotspot_title_validated = preg_replace('/[^0-9a-zA-Z_]/', "", $hotspot_title_validate ?? '');
511 if ($hotspot_title_validated != $hotspot_title_validate) {
512 $this->add_error('invalid_hotspot_id', '<span class="pano-error-title">Invalid Hotspot ID</span> <p>Hotspot ID can\'t contain spaces and special characters.<br/> Please assign a unique Hotspot ID with letters and numbers where Scene id: ' . $scene_id_validate . ' and hotspot id : ' . $hotspot_title_validate . '</p>');
513 }
514 }
515
516
517 /**
518 * Duplicate hotspot error control and validation
519 *
520 * @param array $panodata
521 *
522 * @return void
523 * @since 8.0.0
524 */
525 public function duplicate_hotspot_validation($panodata)
526 {
527 foreach ($panodata["scene-list"] as $panoscenes) {
528 if (!empty($panoscenes['scene-id'])) {
529 $allhotspot = array();
530 foreach ($panoscenes["hotspot-list"] as $hotspot_val) {
531 if (!empty($hotspot_val["hotspot-title"])) {
532 array_push($allhotspot, $hotspot_val["hotspot-title"]);
533 }
534 }
535 $allhotspotcount = array_count_values($allhotspot);
536 foreach ($allhotspotcount as $key => $value) {
537 if ($value > 1) {
538 $this->add_error('duplicate_hotspot', '<span class="pano-error-title">Duplicate Hotspot ID</span> <p>You\'ve assigned a duplicate Hotspot ID. <br/>Please assign unique Hotspot IDs to each Hotspot.</p>');
539 }
540 }
541 }
542 }
543 }
544
545
546 /**
547 * Empty or no video url error control and validation
548 *
549 * @param string $videourl
550 *
551 * @return void
552 * @since 8.0.0
553 */
554 public function empty_video_validation($videourl)
555 {
556 if($videourl == ''){
557 $this->add_error('no_video', '<span class="pano-error-title">No Video Found!</span> <p>You haven\'t uploaded or set the link to a 360 degree video. Please Upload or Set a video to see the Preview.</p>');
558 }
559 }
560
561 /**
562 * Empty or no video url error control and validation
563 *
564 * @param string $videourl
565 *
566 * @return void
567 * @since 8.0.0
568 */
569 public function empty_floor_plan_image_validation($floor_plan)
570 {
571 if($floor_plan == ''){
572 $this->add_error('no_floor_plan_image', '<span class="pano-error-title">No Image Found!</span> <p>Please provide floor plan image</p>');
573 }
574 }
575
576
577 /**
578 * Add validation messages to errors array
579 *
580 * @param string $key
581 * @param string $value
582 *
583 * @return void
584 * @since 8.0.0
585 */
586 public function add_error($key, $value)
587 {
588 $this->errors[$key] = $value;
589 $this->display_errors();
590 }
591
592
593 /**
594 * Display validation message or sending back responses
595 *
596 * @return wp_send_json_error
597 * @since 8.0.0
598 */
599 private function display_errors()
600 {
601 foreach($this->errors as $error){
602 wp_send_json_error($error);
603 die();
604 }
605 }
606 }