PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 9.2.0
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v9.2.0
9.2.0 9.1.4 9.1.3 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 All 224 releases
wpvr / src / Api / Transformers / TourTransformer.php

TourTransformer.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 9.2.0, at src/Api/Transformers/TourTransformer.php

1,103 lines 75.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RexTheme\WPVR\Api\Transformers;
4
5 use RexTheme\WPVR\Api\Contracts\TransformerInterface;
6 use RexTheme\WPVR\Content\TextOverlayContent;
7
8 class TourTransformer implements TransformerInterface {
9
10 protected bool $is_pro;
11
12 public function __construct( bool $is_pro = false ) {
13 $this->is_pro = $is_pro;
14 }
15
16 /**
17 * Convert raw panodata PHP array → normalized API JSON shape.
18 */
19 public function toApi( array $raw ): array {
20 if ( ! $this->is_pro ) {
21 $raw = wpvr_get_effective_panodata( $raw );
22 }
23
24 $scenes = $this->scenes_to_api( $raw['panodata']['scene-list'] ?? [] );
25 // Enabled: check new key first, then fall back to legacy `autoRotate` speed (truthy = enabled).
26 $auto_rotate_enabled = ( $raw['autorotate-enabled'] ?? '' ) === 'on' || ! empty( $raw['autoRotate'] );
27 // Speed: new key first, then legacy `autoRotate` (which doubles as speed in old tours).
28 $auto_rotate_speed = isset( $raw['autorotate-speed'] )
29 ? (float) $raw['autorotate-speed']
30 : ( isset( $raw['autoRotate'] ) ? (float) $raw['autoRotate'] : -5 );
31 // Delay: new key first, then legacy `autoRotateInactivityDelay`.
32 $auto_rotate_delay = isset( $raw['autorotate-delay'] )
33 ? (int) $raw['autorotate-delay']
34 : ( isset( $raw['autoRotateInactivityDelay'] ) ? (int) $raw['autoRotateInactivityDelay'] : 2000 );
35 $auto_rotate = [
36 'enabled' => $auto_rotate_enabled,
37 'speed' => $auto_rotate_speed,
38 'delay' => $auto_rotate_delay,
39 'stopDelay' => isset( $raw['autorotationstopdelay'] ) && $raw['autorotationstopdelay'] !== ''
40 ? (int) $raw['autorotationstopdelay']
41 : ( isset( $raw['autoRotateStopDelay'] ) && $raw['autoRotateStopDelay'] !== '' ? (int) $raw['autoRotateStopDelay'] : null ),
42 ];
43
44 $default_scene_id = ! empty( $raw['defaultscene'] ) ? $raw['defaultscene'] : null;
45 $has_explicit_default_scene = ( $raw['defaultscene-auto'] ?? 'off' ) !== 'on';
46
47 return [
48 'defaultSceneId' => $has_explicit_default_scene ? $default_scene_id : null,
49 'tourType' => $this->detect_tour_type( $raw ),
50 'settings' => [
51 'autoLoad' => ! empty( $raw['autoLoad'] ),
52 'showControls' => isset( $raw['showControls'] ) ? (bool) $raw['showControls'] : true,
53 'previewText' => $raw['previewtext'] ?? '',
54 'previewImage' => $raw['preview'] ?? '',
55 'sceneFadeDuration' => isset( $raw['scenefadeduration'] ) ? (int) $raw['scenefadeduration'] : 0,
56 'showSceneInfo' => ( $raw['scene-info-enabled'] ?? 'on' ) !== 'off',
57 'autoRotate' => $auto_rotate,
58 'socialShare' => ( $raw['wpvr_social_share'] ?? 'off' ) === 'on',
59 ],
60 'floorPlan' => $this->floor_plan_to_api( $raw ),
61 'backgroundTour' => [
62 'enabled' => ( $raw['bg_tour_enabler'] ?? 'off' ) === 'on',
63 'title' => $raw['bg_tour_title'] ?? '',
64 'subtitle' => $raw['bg_tour_subtitle'] ?? '',
65 ],
66 'videoData' => [
67 'url' => $raw['vidurl'] ?? '',
68 'autoplay' => ( $raw['video-autoplay'] ?? $raw['autoplay'] ?? 'off' ) === 'on',
69 'loop' => ( $raw['video-loop'] ?? $raw['loop'] ?? 'off' ) === 'on',
70 ],
71 'streetViewData' => [
72 'embedUrl' => $raw['streetviewurl'] ?? '',
73 ],
74 'scenes' => $scenes,
75 'advancedSettings' => $this->advanced_settings_to_api( $raw ),
76 ];
77 }
78
79 /**
80 * Convert normalized API JSON → raw panodata PHP array.
81 */
82 public function fromApi( array $data ): array {
83 $settings = $data['settings'] ?? [];
84 $floor_plan = $data['floorPlan'] ?? [];
85 $bg_tour = $data['backgroundTour'] ?? [];
86 $auto_rotate = $settings['autoRotate'] ?? [];
87
88 $video_data = $data['videoData'] ?? [];
89 $street_view_data = $data['streetViewData'] ?? [];
90 $advanced_control = is_array( $data['advancedControl'] ?? null )
91 ? $data['advancedControl']
92 : ( is_array( $data['proData'] ?? null ) ? $data['proData'] : [] );
93 $tour_type = in_array( $data['tourType'] ?? 'image', [ 'image', 'video', 'street-view' ], true )
94 ? $data['tourType']
95 : 'image';
96 if ( ! $this->is_pro && $tour_type === 'street-view' ) {
97 $tour_type = 'image';
98 $street_view_data = [];
99 }
100
101 $scenes = is_array( $data['scenes'] ?? null ) ? $data['scenes'] : [];
102 $requested_default_scene_id = (string) ( $data['defaultSceneId'] ?? '' );
103 $has_explicit_default_scene = $requested_default_scene_id !== ''
104 && ! empty( array_filter(
105 $scenes,
106 static function ( $scene ) use ( $requested_default_scene_id ) {
107 return is_array( $scene ) && ( $scene['id'] ?? '' ) === $requested_default_scene_id;
108 }
109 ) );
110 $default_scene_id = $has_explicit_default_scene
111 ? $requested_default_scene_id
112 : ( $scenes[0]['id'] ?? '' );
113
114 $raw = [
115 'autoLoad' => ! empty( $settings['autoLoad'] ) && $settings['autoLoad'] !== 'off' && $settings['autoLoad'] !== 'false',
116 'showControls' => ! empty( $settings['showControls'] ),
117 'draggable' => ( isset( $advanced_control['draggable'] ) && ( $advanced_control['draggable'] === 'off' || $advanced_control['draggable'] === false ) ) ? 'off' : 'on',
118 'mouseZoom' => ( isset( $advanced_control['mouseZoom'] ) && ( $advanced_control['mouseZoom'] === 'off' || $advanced_control['mouseZoom'] === false ) ) ? 'off' : 'on',
119 'diskeyboard' => ( isset( $advanced_control['diskeyboard'] ) && ( $advanced_control['diskeyboard'] === 'off' || $advanced_control['diskeyboard'] === false ) ) ? 'on' : 'off',
120 'keyboardzoom' => ( isset( $advanced_control['keyboardzoom'] ) && ( $advanced_control['keyboardzoom'] === 'off' || $advanced_control['keyboardzoom'] === false ) ) ? false : true,
121 'previewtext' => $settings['previewText'] ?? '',
122 'scenefadeduration' => isset( $settings['sceneFadeDuration'] ) ? (string) $settings['sceneFadeDuration'] : '0',
123 'scene-info-enabled' => array_key_exists( 'showSceneInfo', $settings ) && ! $settings['showSceneInfo'] ? 'off' : 'on',
124 'defaultscene' => $default_scene_id,
125 'defaultscene-auto' => $has_explicit_default_scene ? 'off' : 'on',
126 'autorotate-enabled' => ! empty( $auto_rotate['enabled'] ) ? 'on' : 'off',
127 'autorotate-speed' => $auto_rotate['speed'] ?? -5,
128 'autorotate-delay' => $auto_rotate['delay'] ?? 2000,
129 'autorotationstopdelay' => $auto_rotate['stopDelay'] ?? '',
130 // Legacy keys for PRO plugin / shortcode compatibility.
131 'autoRotate' => ! empty( $auto_rotate['enabled'] ) ? ( $auto_rotate['speed'] ?? -5 ) : '',
132 'autoRotateInactivityDelay' => $auto_rotate['delay'] ?? 2000,
133 'autoRotateStopDelay' => $auto_rotate['stopDelay'] ?? '',
134 'floorplan-enabled' => ! empty( $floor_plan['enabled'] ) ? 'on' : 'off',
135 'floorplan-image' => $floor_plan['imageUrl'] ?? '',
136 'floorplan-compass' => ! empty( $floor_plan['directionIndicator']['enabled'] ) ? 'on' : 'off',
137 'floorplan-compass-color' => $floor_plan['directionIndicator']['color'] ?? '#6D28D9',
138 // Legacy keys — used by legacy rendering and pro plugin.
139 'floor_plan_tour_enabler' => ! empty( $floor_plan['enabled'] ) ? 'on' : 'off',
140 'floor_plan_attachment_url' => $floor_plan['imageUrl'] ?? '',
141 'floor_plan_custom_color' => ! empty( $floor_plan['pointerColor'] ) ? $floor_plan['pointerColor'] : '#cca92c',
142 'floor_plan_direction_indicator' => ! empty( $floor_plan['directionIndicator']['enabled'] ) ? 'on' : 'off',
143 'floor_plan_pointer_position' => $this->pointer_positions_from_api( $floor_plan ),
144 'floor_plan_data_list' => $this->pointer_data_list_from_api( $floor_plan ),
145 'bg_tour_enabler' => ! empty( $bg_tour['enabled'] ) ? 'on' : 'off',
146 'bg_tour_title' => $bg_tour['title'] ?? '',
147 'bg_tour_subtitle' => $bg_tour['subtitle'] ?? '',
148 'genericform' => ! empty( $advanced_control['genericform'] ) && $advanced_control['genericform'] !== 'off' ? 'on' : 'off',
149 'genericformshortcode' => sanitize_text_field( (string) ( $advanced_control['genericformshortcode'] ?? '' ) ),
150 'genericformicon' => sanitize_text_field( (string) ( $advanced_control['genericformicon'] ?? 'fab fa-wpforms' ) ),
151 'genericformiconcolor' => sanitize_hex_color( $advanced_control['genericformiconcolor'] ?? '' ) ?: '#f7fffb',
152 'calltoaction' => ! empty( $advanced_control['calltoaction'] ) && $advanced_control['calltoaction'] !== 'off' ? 'on' : 'off',
153 'buttontext' => sanitize_text_field( (string) ( $advanced_control['buttontext'] ?? 'Click Here' ) ),
154 'buttonurl' => esc_url_raw( (string) ( $advanced_control['buttonurl'] ?? '' ) ),
155 'button_configuration' => $this->button_configuration_to_api( $advanced_control['button_configuration'] ?? [] ),
156 'preview' => esc_url_raw( $settings['previewImage'] ?? '' ),
157 'panoid' => '',
158 'customcontrol' => $this->customcontrol_to_api(
159 is_array( $advanced_control['customcontrol'] ?? null )
160 ? $advanced_control['customcontrol']
161 : []
162 ),
163 'tour-type' => $tour_type,
164 'vidurl' => esc_url_raw( $video_data['url'] ?? '' ),
165 'video-autoplay' => ! empty( $video_data['autoplay'] ) ? 'on' : 'off',
166 'video-loop' => ! empty( $video_data['loop'] ) ? 'on' : 'off',
167 'autoplay' => ! empty( $video_data['autoplay'] ) ? 'on' : 'off',
168 'loop' => ! empty( $video_data['loop'] ) ? 'on' : 'off',
169 'streetviewurl' => esc_url_raw( $street_view_data['embedUrl'] ?? '' ),
170 'streetview' => ! empty( $street_view_data['embedUrl'] ) ? 'on' : 'off',
171 'panodata' => [
172 'scene-list' => $this->scenes_from_api(
173 $scenes,
174 $default_scene_id,
175 ( $settings['showSceneInfo'] ?? true ) !== false
176 ),
177 ],
178 'wpvr_social_share' => ! empty( $settings['socialShare'] ) ? 'on' : 'off',
179 ];
180
181 if ( $tour_type === 'video' && ! empty( $video_data['url'] ) ) {
182 $raw['vidid'] = 'vid' . ( $data['tourId'] ?? $data['id'] ?? wp_rand( 1000, 99999 ) );
183 }
184
185 return $raw;
186 }
187
188 // -------------------------------------------------------------------------
189
190 private function floor_plan_to_api( array $raw ): array {
191 // Merge pointer positions and scene assignments into a unified array.
192 $positions = $raw['floor_plan_pointer_position'] ?? [];
193 $data_list = $raw['floor_plan_data_list'] ?? [];
194
195 // Build id → sceneId map from data_list ({id:'1', name:'plan1', value:'scene-id'}).
196 $scene_map = [];
197 foreach ( $data_list as $item ) {
198 $item = is_object( $item ) ? $item : (object) $item;
199 $scene_map[ $item->id ?? '' ] = $item->value ?? '';
200 }
201
202 $pointers = [];
203 foreach ( $positions as $pos ) {
204 $pos = is_object( $pos ) ? $pos : (object) $pos;
205 $pos_id = $pos->id ?? '';
206 // Extract numeric suffix from 'pointer-N'.
207 preg_match( '/(\d+)$/', $pos_id, $m );
208 $num = $m[1] ?? '';
209 $scene_id = $scene_map[ $num ] ?? $scene_map[ $pos_id ] ?? '';
210
211 $pointers[] = [
212 'id' => $pos_id,
213 'top' => $pos->data_top ?? '0%',
214 'left' => $pos->data_left ?? '0%',
215 'sceneId' => $scene_id,
216 ];
217 }
218
219 return [
220 // Read from new key first, fall back to legacy key.
221 'enabled' => ( $raw['floorplan-enabled'] ?? 'off' ) === 'on' || ( $raw['floor_plan_tour_enabler'] ?? 'off' ) === 'on',
222 'imageUrl' => $raw['floorplan-image'] ?? $raw['floor_plan_attachment_url'] ?? '',
223 'pointerColor' => ! empty( $raw['floor_plan_custom_color'] ) ? $raw['floor_plan_custom_color'] : '#cca92c',
224 'pointers' => $pointers,
225 'directionIndicator' => [
226 'enabled' => ( $raw['floorplan-compass'] ?? 'off' ) === 'on' || ( $raw['floor_plan_direction_indicator'] ?? 'off' ) === 'on',
227 'color' => $raw['floorplan-compass-color'] ?? '#6D28D9',
228 ],
229 ];
230 }
231
232 private function pointer_positions_from_api( array $floor_plan ): array {
233 $pointers = $floor_plan['pointers'] ?? [];
234 $color = $floor_plan['pointerColor'] ?? '#cca92c';
235 $result = [];
236 $index = 1;
237 foreach ( $pointers as $pointer ) {
238 $top = $pointer['top'] ?? '0%';
239 $left = $pointer['left'] ?? '0%';
240 $result[] = (object) [
241 'id' => 'pointer-' . $index,
242 'text' => (string) $index,
243 'data_top' => $top,
244 'data_left' => $left,
245 'style' => "background:{$color};top:{$top};left:{$left};",
246 ];
247 $index++;
248 }
249 return $result;
250 }
251
252 private function pointer_data_list_from_api( array $floor_plan ): array {
253 $pointers = $floor_plan['pointers'] ?? [];
254 $result = [];
255 $index = 1;
256 foreach ( $pointers as $pointer ) {
257 $result[] = (object) [
258 'id' => (string) $index,
259 'name' => 'plan' . $index,
260 'value' => $pointer['sceneId'] ?? '',
261 ];
262 $index++;
263 }
264 return $result;
265 }
266
267 /**
268 * Detect tour type supporting both new-UI ('tour-type' key) and legacy
269 * ('streetviewdata'/'vidid' keys) save formats.
270 */
271 private function detect_tour_type( array $raw ): string {
272 if ( ! empty( $raw['tour-type'] ) ) {
273 $allowed = [ 'image', 'video', 'street-view' ];
274 return in_array( $raw['tour-type'], $allowed, true ) ? $raw['tour-type'] : 'image';
275 }
276 if ( isset( $raw['streetviewdata'] ) || ! empty( $raw['streetviewurl'] ) ) {
277 return 'street-view';
278 }
279 if ( ! empty( $raw['vidid'] ) || ! empty( $raw['vidurl'] ) ) {
280 return 'video';
281 }
282 return 'image';
283 }
284
285 /**
286 * Extract pro advanced-control fields from raw panodata for the API response.
287 * tourLayout is stored as an array by pro but the React store uses a plain string.
288 */
289 protected function advanced_settings_to_api( array $raw ): array {
290 $b = static function ( $val, $default ) {
291 if ( is_bool( $val ) ) return $val;
292 return filter_var( $val ?? $default, FILTER_VALIDATE_BOOLEAN );
293 };
294
295 $tour_layout_raw = $raw['tourLayout'] ?? 'default';
296 $tour_layout = is_array( $tour_layout_raw )
297 ? ( $tour_layout_raw['layout'] ?? 'default' )
298 : (string) $tour_layout_raw;
299
300 // globalzoom is on when any of hfov/maxHfov/minHfov is set.
301 $globalzoom = ( ! empty( $raw['hfov'] ) || ! empty( $raw['maxHfov'] ) || ! empty( $raw['minHfov'] ) );
302
303 return [
304 'tourLayout' => $tour_layout,
305 'layout_icon_bg_color' => (string) ( $raw['layout_icon_bg_color'] ?? '#5a536e' ),
306 'layout_icon_color' => (string) ( $raw['layout_icon_color'] ?? '#ffffff' ),
307 'diskeyboard' => ! in_array( $raw['diskeyboard'] ?? 'off', [ 'on', 'true', true ], true ),
308 'keyboardzoom' => $b( $raw['keyboardzoom'] ?? null, true ),
309 'draggable' => $b( $raw['draggable'] ?? null, true ),
310 'mouseZoom' => $b( $raw['mouseZoom'] ?? null, true ),
311 'gyro' => $b( $raw['gyro'] ?? null, false ),
312 'deviceorientationcontrol' => $b( $raw['deviceorientationcontrol']?? null, false ),
313 'compass' => $b( $raw['compass'] ?? null, false ),
314 'vrgallery' => $b( $raw['vrgallery'] ?? null, false ),
315 'vrgallery_title' => $b( $raw['vrgallery_title'] ?? null, false ),
316 'vrgallery_icon_size' => $b( $raw['vrgallery_icon_size'] ?? null, false ),
317 'vrgallery_display' => $b( $raw['vrgallery_display'] ?? null, false ),
318 'scene_navigation' => $b( $raw['scene_navigation'] ?? null, false ),
319 'scene_navigation_content_type' => (string) ( $raw['scene_navigation_content_type'] ?? 'scene_id' ),
320 'sceneAnimation' => $b( $raw['sceneAnimation'] ?? null, false ),
321 'sceneAnimationName' => (string) ( $raw['sceneAnimationName'] ?? 'none' ),
322 'sceneAnimationTransitionDuration'=> (string) ( $raw['sceneAnimationTransitionDuration'] ?? '500' ),
323 'sceneAnimationTransitionDelay' => (string) ( $raw['sceneAnimationTransitionDelay'] ?? '0' ),
324 'bg_music' => $b( $raw['bg_music'] ?? null, false ),
325 'bg_music_url' => (string) ( $raw['bg_music_url'] ?? '' ),
326 'autoplay_bg_music' => $b( $raw['autoplay_bg_music'] ?? null, false ),
327 'loop_bg_music' => $b( $raw['loop_bg_music'] ?? null, false ),
328 'explainerSwitch' => $b( $raw['explainerSwitch'] ?? null, false ),
329 'explainerContent' => (string) ( $raw['explainerContent'] ?? '' ),
330 'cpLogoSwitch' => $b( $raw['cpLogoSwitch'] ?? null, false ),
331 'cpLogoImg' => (string) ( $raw['cpLogoImg'] ?? '' ),
332 'cpLogoContent' => (string) ( $raw['cpLogoContent'] ?? '' ),
333 'globalzoom' => $globalzoom,
334 'hfov' => isset( $raw['hfov'] ) && $raw['hfov'] !== '' ? (int) $raw['hfov'] : null,
335 'maxHfov' => isset( $raw['maxHfov'] ) && $raw['maxHfov'] !== '' ? (int) $raw['maxHfov'] : null,
336 'minHfov' => isset( $raw['minHfov'] ) && $raw['minHfov'] !== '' ? (int) $raw['minHfov'] : null,
337 'genericform' => ( ( $raw['genericform'] ?? 'off' ) === 'on' ),
338 'genericformshortcode' => (string) ( $raw['genericformshortcode'] ?? '' ),
339 'genericformicon' => (string) ( $raw['genericformicon'] ?? 'fab fa-wpforms' ),
340 'genericformiconcolor' => (string) ( $raw['genericformiconcolor'] ?? '#f7fffb' ),
341 'calltoaction' => ( ( $raw['calltoaction'] ?? 'off' ) === 'on' ),
342 'buttontext' => (string) ( $raw['buttontext'] ?? 'Click Here' ),
343 'buttonurl' => (string) ( $raw['buttonurl'] ?? '' ),
344 'button_configuration' => $this->button_configuration_to_api( $raw['button_configuration'] ?? [] ),
345 'customcss_enable' => ( ( $raw['customcss_enable'] ?? 'off' ) === 'on' ),
346 'customcss' => (string) ( $raw['customcss'] ?? '' ),
347 'customcontrol' => $this->customcontrol_to_api( $raw['customcontrol'] ?? [] ),
348 ];
349 }
350
351 private function customcontrol_to_api( $raw_ctrl ): array {
352 if ( ! is_array( $raw_ctrl ) ) {
353 $raw_ctrl = [];
354 }
355 $defaults = [
356 'panupSwitch' => 'off', 'panupColor' => '#f7fffb', 'panupIcon' => 'fas fa-angle-up',
357 'panDownSwitch' => 'off', 'panDownColor' => '#f7fffb', 'panDownIcon' => 'fas fa-angle-down',
358 'panLeftSwitch' => 'off', 'panLeftColor' => '#f7fffb', 'panLeftIcon' => 'fas fa-angle-left',
359 'panRightSwitch' => 'off', 'panRightColor' => '#f7fffb', 'panRightIcon' => 'fas fa-angle-right',
360 'panZoomInSwitch' => 'off', 'panZoomInColor' => '#f7fffb', 'panZoomInIcon' => 'fas fa-plus-circle',
361 'panZoomOutSwitch' => 'off', 'panZoomOutColor' => '#f7fffb', 'panZoomOutIcon' => 'fas fa-minus-circle',
362 'panFullscreenSwitch' => 'off', 'panFullscreenColor' => '#f7fffb', 'panFullscreenIcon' => 'fas fa-expand',
363 'gyroscopeSwitch' => 'off', 'gyroscopeColor' => '#f7fffb', 'gyroscopeIcon' => 'fas fa-dot-circle',
364 'backToHomeSwitch' => 'off', 'backToHomeColor' => '#f7fffb', 'backToHomeIcon' => 'fas fa-home',
365 'explainerColor' => '#f7fffb', 'explainerIcon' => 'fas fa-video',
366 ];
367 return array_merge( $defaults, array_intersect_key( $raw_ctrl, $defaults ) );
368 }
369
370 private function button_configuration_to_api( $raw_config ): array {
371 if ( ! is_array( $raw_config ) ) {
372 $raw_config = [];
373 }
374
375 $defaults = [
376 'button_open_new_tab' => 'off',
377 'button_background_color' => '#201cfe',
378 'button_font_color' => '#ffffff',
379 'button_font_size' => '14',
380 'button_font_weight' => '400',
381 'button_line_height' => '1',
382 'button_text_decoration' => 'none',
383 'button_transform' => 'none',
384 'button_alignment' => 'left',
385 'button_text_style' => 'normal',
386 'button_letter_spacing' => '1',
387 'button_word_spacing' => '0',
388 'button_border_width' => '1',
389 'button_border_style' => 'solid',
390 'button_border_color' => '#201cfe',
391 'button_border_radius' => '6',
392 'button_pt' => '10',
393 'button_pr' => '15',
394 'button_pb' => '10',
395 'button_pl' => '15',
396 ];
397 $config = array_merge( $defaults, array_intersect_key( $raw_config, $defaults ) );
398
399 $config['button_open_new_tab'] = in_array(
400 $config['button_open_new_tab'],
401 [ true, 1, '1', 'on' ],
402 true
403 ) ? 'on' : 'off';
404
405 $allowed_values = [
406 'button_font_weight' => [ '400', '500', '600', '700', '800', '900' ],
407 'button_text_decoration' => [ 'none', 'underline', 'overline', 'line-through' ],
408 'button_transform' => [ 'none', 'uppercase', 'lowercase', 'capitalize' ],
409 'button_alignment' => [ 'left', 'right', 'center', 'justified' ],
410 'button_text_style' => [ 'normal', 'italic', 'oblique' ],
411 'button_border_style' => [ 'solid', 'dashed', 'dotted', 'double', 'none' ],
412 ];
413 foreach ( $allowed_values as $key => $allowed ) {
414 $value = (string) $config[ $key ];
415 $config[ $key ] = in_array( $value, $allowed, true ) ? $value : $defaults[ $key ];
416 }
417
418 foreach ( [ 'button_background_color', 'button_font_color', 'button_border_color' ] as $key ) {
419 $value = (string) $config[ $key ];
420 $config[ $key ] = preg_match( '/^#[0-9a-fA-F]{6}$/', $value ) ? strtolower( $value ) : $defaults[ $key ];
421 }
422
423 foreach ( [
424 'button_font_size', 'button_line_height', 'button_letter_spacing',
425 'button_word_spacing', 'button_border_width', 'button_border_radius',
426 'button_pt', 'button_pr', 'button_pb', 'button_pl',
427 ] as $key ) {
428 $value = $config[ $key ];
429 $config[ $key ] = is_numeric( $value ) && (float) $value >= 0
430 ? (string) $value
431 : $defaults[ $key ];
432 }
433
434 return $config;
435 }
436
437 protected function scenes_to_api( array $scene_list ): array {
438 $n = static function ( $val, $cast ) {
439 if ( ! isset( $val ) || $val === '' ) return null;
440 return $cast === 'int' ? (int) $val : (float) $val;
441 };
442
443 $scenes = [];
444 foreach ( $scene_list as $scene ) {
445 $scenes[] = [
446 // Free fields
447 'id' => $scene['scene-id'] ?? '',
448 'name' => $scene['scene-ititle'] ?? '',
449 'type' => $scene['scene-type'] ?? 'equirectangular',
450 'imageUrl' => $scene['scene-attachment-url'] ?? '',
451 'isDefault' => ( $scene['dscene'] ?? 'off' ) === 'on',
452 'hotspots' => $this->hotspots_to_api( $scene['hotspot-list'] ?? [] ),
453 // Pro: metadata
454 'author' => $scene['scene-author'] ?? '',
455 'authorUrl' => $scene['scene-author-url'] ?? '',
456 'vaov' => $n( $scene['scene-vaov'] ?? null, 'int' ),
457 'haov' => $n( $scene['scene-haov'] ?? null, 'int' ),
458 'verticalOffset' => $n( $scene['scene-vertical-offset'] ?? null, 'float' ),
459 // Pro: default face orientation
460 'defaultFace' => $scene['ptyscene'] ?? 'off',
461 'pitch' => $n( $scene['scene-pitch'] ?? null, 'float' ),
462 'yaw' => $n( $scene['scene-yaw'] ?? null, 'float' ),
463 // Pro: vertical drag limits
464 'limitVertical' => $scene['cvgscene'] ?? 'off',
465 'maxPitch' => $n( $scene['scene-maxpitch'] ?? null, 'float' ),
466 'minPitch' => $n( $scene['scene-minpitch'] ?? null, 'float' ),
467 // Pro: horizontal drag limits
468 'limitHorizontal' => $scene['chgscene'] ?? 'off',
469 'maxYaw' => $n( $scene['scene-maxyaw'] ?? null, 'float' ),
470 'minYaw' => $n( $scene['scene-minyaw'] ?? null, 'float' ),
471 // Pro: per-scene zoom override
472 'customZoom' => $scene['czscene'] ?? 'off',
473 'zoom' => $n( $scene['scene-zoom'] ?? null, 'int' ),
474 'maxZoom' => $n( $scene['scene-maxzoom'] ?? null, 'int' ),
475 'minZoom' => $n( $scene['scene-minzoom'] ?? null, 'int' ),
476 // Pro: cubemap faces (6-element array, null when not set)
477 'cubemapFaces' => [
478 $scene['scene-attachment-url-face0'] ?? null,
479 $scene['scene-attachment-url-face1'] ?? null,
480 $scene['scene-attachment-url-face2'] ?? null,
481 $scene['scene-attachment-url-face3'] ?? null,
482 $scene['scene-attachment-url-face4'] ?? null,
483 $scene['scene-attachment-url-face5'] ?? null,
484 ],
485 'textOverlays' => $this->text_overlays_to_api( $scene['text-overlays'] ?? [] ),
486 'showLayerToggle' => ( $scene['scene-show-layer-toggle'] ?? 'on' ) === 'on',
487 ];
488 }
489 // Older tours did not store whether a hotspot entry point inherited
490 // the target scene face or was edited manually. Keep those links in
491 // inherit mode: only edits made through the new Navigation Entry Point
492 // controls explicitly record the custom mode.
493 foreach ( $scenes as &$scene ) {
494 foreach ( $scene['hotspots'] as &$hotspot ) {
495 if ( in_array( $hotspot['sceneEntryPointMode'] ?? '', [ 'inherit', 'custom' ], true ) ) {
496 continue;
497 }
498 $hotspot['sceneEntryPointMode'] = 'inherit';
499 }
500 unset( $hotspot );
501 }
502 unset( $scene );
503
504 return $scenes;
505 }
506
507 protected function scenes_from_api( array $scenes, string $default_scene_id = '', bool $show_scene_info = true ): array {
508 $scene_list = [];
509 $index = 1;
510 foreach ( $scenes as $scene ) {
511 $scene_id = $scene['id'] ?? '';
512 $faces = $scene['cubemapFaces'] ?? [];
513 $scene_data = [
514 // Free fields
515 'scene-id' => $scene_id,
516 'scene-ititle' => $scene['name'] ?? '',
517 'scene-type' => $this->is_pro && ( $scene['type'] ?? '' ) === 'cubemap' ? 'cubemap' : 'equirectangular',
518 'scene-attachment-url' => $scene['imageUrl'] ?? '',
519 'scene-show-info' => $show_scene_info ? 'on' : 'off',
520 'hotspot-list' => $this->hotspots_from_api( $scene['hotspots'] ?? [] ),
521 'dscene' => ( $default_scene_id !== '' && $scene_id === $default_scene_id ) ? 'on' : 'off',
522 'text-overlays' => $this->text_overlays_from_api( $scene['textOverlays'] ?? [] ),
523 'scene-show-layer-toggle' => ( ! isset( $scene['showLayerToggle'] ) || ! empty( $scene['showLayerToggle'] ) ) ? 'on' : 'off',
524 'showLayerToggle' => ( ! isset( $scene['showLayerToggle'] ) || ! empty( $scene['showLayerToggle'] ) ),
525 ];
526
527 if ( $this->is_pro ) {
528 $scene_data = array_merge( $scene_data, [
529 // Pro: metadata
530 'scene-author' => $scene['author'] ?? '',
531 'scene-author-url' => $scene['authorUrl'] ?? '',
532 'scene-vaov' => $scene['vaov'] ?? '',
533 'scene-haov' => $scene['haov'] ?? '',
534 'scene-vertical-offset' => $scene['verticalOffset'] ?? '',
535 // Pro: default face orientation
536 'ptyscene' => $scene['defaultFace'] ?? 'off',
537 'scene-pitch' => $scene['pitch'] ?? '',
538 'scene-yaw' => $scene['yaw'] ?? '',
539 // Pro: vertical drag limits
540 'cvgscene' => $scene['limitVertical'] ?? 'off',
541 'scene-maxpitch' => $scene['maxPitch'] ?? '',
542 'scene-minpitch' => $scene['minPitch'] ?? '',
543 // Pro: horizontal drag limits
544 'chgscene' => $scene['limitHorizontal'] ?? 'off',
545 'scene-maxyaw' => $scene['maxYaw'] ?? '',
546 'scene-minyaw' => $scene['minYaw'] ?? '',
547 // Pro: per-scene zoom override
548 'czscene' => $scene['customZoom'] ?? 'off',
549 'scene-zoom' => $scene['zoom'] ?? '',
550 'scene-maxzoom' => $scene['maxZoom'] ?? '',
551 'scene-minzoom' => $scene['minZoom'] ?? '',
552 // Pro: cubemap faces
553 'scene-attachment-url-face0' => $faces[0] ?? '',
554 'scene-attachment-url-face1' => $faces[1] ?? '',
555 'scene-attachment-url-face2' => $faces[2] ?? '',
556 'scene-attachment-url-face3' => $faces[3] ?? '',
557 'scene-attachment-url-face4' => $faces[4] ?? '',
558 'scene-attachment-url-face5' => $faces[5] ?? '',
559 'text-overlays' => $this->text_overlays_from_api( $scene['textOverlays'] ?? [] ),
560 ] );
561 }
562
563 $scene_list[ $index ] = $scene_data;
564 $index++;
565 }
566 return $scene_list;
567 }
568
569 protected function hotspots_to_api( array $hotspot_list ): array {
570 $hotspots = [];
571 foreach ( $hotspot_list as $hotspot ) {
572 if ( empty( $hotspot['hotspot-title'] ) && empty( $hotspot['hotspot-type'] ) ) {
573 continue;
574 }
575 $scene_pitch = isset( $hotspot['hotspot-scene-pitch'] ) && $hotspot['hotspot-scene-pitch'] !== ''
576 ? (float) $hotspot['hotspot-scene-pitch']
577 : null;
578 $scene_yaw = isset( $hotspot['hotspot-scene-yaw'] ) && $hotspot['hotspot-scene-yaw'] !== ''
579 ? (float) $hotspot['hotspot-scene-yaw']
580 : null;
581 $product_id = isset( $hotspot['hotspot-product-id'] ) ? (string) $hotspot['hotspot-product-id'] : '';
582 $product_name = '';
583 if ( ! empty( $product_id ) && function_exists( 'wc_get_product' ) ) {
584 $product_obj = wc_get_product( $product_id );
585 if ( is_object( $product_obj ) ) {
586 $product_name = $product_obj->get_formatted_name();
587 }
588 }
589
590 $template_val = $hotspot['hotspot-sticker-template'] ?? '';
591 $is_separate_icon = $template_val === 'button_with_separate_icon';
592 $is_add_to_cart = $template_val === 'add_to_cart';
593 $is_social_share = $template_val === 'social_share';
594 $default_card_radius = $is_separate_icon ? 135 : ( ( $is_add_to_cart || $is_social_share ) ? 15 : 20 );
595
596 $hotspots[] = [
597 'id' => $hotspot['hotspot-id'] ?? wp_generate_uuid4(),
598 'type' => $hotspot['hotspot-type'] ?? 'info',
599 'pitch' => isset( $hotspot['hotspot-pitch'] ) ? (float) $hotspot['hotspot-pitch'] : 0,
600 'yaw' => isset( $hotspot['hotspot-yaw'] ) ? (float) $hotspot['hotspot-yaw'] : 0,
601 'text' => $hotspot['hotspot-title'] ?? '',
602 'content' => $hotspot['hotspot-content'] ?? '',
603 'url' => $hotspot['hotspot-url'] ?? '',
604 'urlOpen' => $hotspot['hotspot-url-open'] ?? 'off',
605 'hover' => $hotspot['hotspot-hover'] ?? '',
606 'targetSceneId' => $hotspot['hotspot-scene'] ?? '',
607 'customClass' => $hotspot['hotspot-customclass'] ?? '',
608 'fluentFormId' => isset( $hotspot['fluent-form-id'] ) ? (string) $hotspot['fluent-form-id'] : '',
609 'productId' => $product_id,
610 'productName' => $product_name,
611 // Sticker fields
612 'stickerTemplate' => $template_val ?: 'social_proof',
613 'stickerReviewText' => $hotspot['hotspot-sticker-review-text'] ?? 'The support is super responsive and responds without worries to our requests and needs! Big up to the entire RexTheme team!',
614 'stickerClientName' => $hotspot['hotspot-sticker-client-name'] ?? 'Elena R.',
615 'stickerClientAvatar' => $hotspot['hotspot-sticker-client-avatar'] ?? '',
616 'stickerRating' => isset( $hotspot['hotspot-sticker-rating'] ) ? (int) $hotspot['hotspot-sticker-rating'] : 5,
617 'stickerBgColor' => $hotspot['hotspot-sticker-bg-color'] ?? '#201b2c',
618 'stickerBgOpacity' => isset( $hotspot['hotspot-sticker-bg-opacity'] ) ? (float) $hotspot['hotspot-sticker-bg-opacity'] : ( ( $is_separate_icon || $is_add_to_cart || $is_social_share ) ? 75 : 95 ),
619 'stickerBlur' => isset( $hotspot['hotspot-sticker-blur'] ) ? (float) $hotspot['hotspot-sticker-blur'] : 12,
620 'stickerBrightness' => isset( $hotspot['hotspot-sticker-brightness'] ) ? (float) $hotspot['hotspot-sticker-brightness'] : 100,
621 'stickerTextColor' => $hotspot['hotspot-sticker-text-color'] ?? '#ffffff',
622 'stickerBorderColor' => $hotspot['hotspot-sticker-border-color'] ?? ( ( $is_separate_icon || $is_add_to_cart || $is_social_share ) ? '#40355a' : '#3a3051' ),
623 'stickerBorderRadius' => isset( $hotspot['hotspot-sticker-border-radius'] ) && is_array( $hotspot['hotspot-sticker-border-radius'] ) ? [
624 'topLeft' => isset( $hotspot['hotspot-sticker-border-radius']['topLeft'] ) ? (float) $hotspot['hotspot-sticker-border-radius']['topLeft'] : $default_card_radius,
625 'topRight' => isset( $hotspot['hotspot-sticker-border-radius']['topRight'] ) ? (float) $hotspot['hotspot-sticker-border-radius']['topRight'] : $default_card_radius,
626 'bottomRight' => isset( $hotspot['hotspot-sticker-border-radius']['bottomRight'] ) ? (float) $hotspot['hotspot-sticker-border-radius']['bottomRight'] : $default_card_radius,
627 'bottomLeft' => isset( $hotspot['hotspot-sticker-border-radius']['bottomLeft'] ) ? (float) $hotspot['hotspot-sticker-border-radius']['bottomLeft'] : $default_card_radius,
628 ] : ( isset( $hotspot['hotspot-sticker-border-radius'] ) && is_numeric( $hotspot['hotspot-sticker-border-radius'] ) ? [
629 'topLeft' => (float) $hotspot['hotspot-sticker-border-radius'],
630 'topRight' => (float) $hotspot['hotspot-sticker-border-radius'],
631 'bottomRight' => (float) $hotspot['hotspot-sticker-border-radius'],
632 'bottomLeft' => (float) $hotspot['hotspot-sticker-border-radius'],
633 ] : [
634 'topLeft' => $default_card_radius,
635 'topRight' => $default_card_radius,
636 'bottomRight' => $default_card_radius,
637 'bottomLeft' => $default_card_radius,
638 ] ),
639 'stickerPadding' => isset( $hotspot['hotspot-sticker-padding'] ) && is_array( $hotspot['hotspot-sticker-padding'] ) ? [
640 'top' => isset( $hotspot['hotspot-sticker-padding']['top'] ) ? (float) $hotspot['hotspot-sticker-padding']['top'] : 21,
641 'right' => isset( $hotspot['hotspot-sticker-padding']['right'] ) ? (float) $hotspot['hotspot-sticker-padding']['right'] : 21,
642 'bottom' => isset( $hotspot['hotspot-sticker-padding']['bottom'] ) ? (float) $hotspot['hotspot-sticker-padding']['bottom'] : 21,
643 'left' => isset( $hotspot['hotspot-sticker-padding']['left'] ) ? (float) $hotspot['hotspot-sticker-padding']['left'] : 21,
644 ] : ( isset( $hotspot['hotspot-sticker-padding'] ) && is_numeric( $hotspot['hotspot-sticker-padding'] ) ? [
645 'top' => (float) $hotspot['hotspot-sticker-padding'],
646 'right' => (float) $hotspot['hotspot-sticker-padding'],
647 'bottom' => (float) $hotspot['hotspot-sticker-padding'],
648 'left' => (float) $hotspot['hotspot-sticker-padding'],
649 ] : [
650 'top' => 21,
651 'right' => 21,
652 'bottom' => 21,
653 'left' => 21,
654 ] ),
655 'stickerStarColor' => $hotspot['hotspot-sticker-star-color'] ?? '#EF991F',
656 // Text before button (for add_to_cart)
657 'stickerPrefixText' => $hotspot['hotspot-sticker-prefix-text'] ?? '$1,090 -',
658 'stickerSubText' => $hotspot['hotspot-sticker-sub-text'] ?? 'Ready to ship',
659 // Discount button, add to cart & social share sticker fields
660 'stickerBtnText' => $hotspot['hotspot-sticker-btn-text'] ?? ( $is_social_share ? 'SHARE EXPERIENCE' : ( $is_add_to_cart ? 'ADD TO CART' : ( $is_separate_icon ? 'Limited “Midnight Horizon” Edition' : 'GET 20% OFF NOW' ) ) ),
661 'stickerBtnColor' => $hotspot['hotspot-sticker-btn-color'] ?? ( $is_social_share ? '#201a2b' : ( $is_add_to_cart ? '#3f04fe' : ( $is_separate_icon ? '#ffffff' : '#EF991F' ) ) ),
662 'stickerBtnTextColor' => $hotspot['hotspot-sticker-btn-text-color'] ?? ( ( $is_add_to_cart || $is_social_share ) ? '#ffffff' : '#000000' ),
663 'stickerBtnIconColor' => $hotspot['hotspot-sticker-btn-icon-color'] ?? '#000000',
664 'stickerBtnUrl' => $hotspot['hotspot-sticker-btn-url'] ?? '',
665 'stickerBtnNewTab' => $hotspot['hotspot-sticker-btn-new-tab'] ?? 'off',
666 'stickerMainBg' => $hotspot['hotspot-sticker-main-bg'] ?? ( $hotspot['hotspot-sticker-card-bg'] ?? 'on' ),
667 'stickerCardBg' => $hotspot['hotspot-sticker-card-bg'] ?? ( $hotspot['hotspot-sticker-main-bg'] ?? 'on' ),
668 'stickerBtnBg' => $hotspot['hotspot-sticker-btn-bg'] ?? 'on',
669 'stickerBtnWidth' => isset( $hotspot['hotspot-sticker-btn-width'] ) && $hotspot['hotspot-sticker-btn-width'] !== '' ? (float) $hotspot['hotspot-sticker-btn-width'] : ( $is_social_share ? 222 : ( $is_add_to_cart ? 163 : ( $is_separate_icon ? 356 : '' ) ) ),
670 'stickerBtnHeight' => isset( $hotspot['hotspot-sticker-btn-height'] ) && $hotspot['hotspot-sticker-btn-height'] !== '' ? (float) $hotspot['hotspot-sticker-btn-height'] : ( ( $is_social_share || $is_add_to_cart || $is_separate_icon ) ? 60 : '' ),
671 'stickerBtnRadius' => isset( $hotspot['hotspot-sticker-btn-radius'] ) && $hotspot['hotspot-sticker-btn-radius'] !== '' ? (float) $hotspot['hotspot-sticker-btn-radius'] : ( $is_separate_icon ? 30 : 10 ),
672 'stickerBtnBorder' => isset( $hotspot['hotspot-sticker-btn-border'] ) && $hotspot['hotspot-sticker-btn-border'] !== '' ? (float) $hotspot['hotspot-sticker-btn-border'] : ( $is_social_share ? 1 : 0 ),
673 'stickerBtnBorderColor' => $hotspot['hotspot-sticker-btn-border-color'] ?? ( $is_social_share ? '#3a3051' : ( ( $is_add_to_cart || $is_separate_icon ) ? '#ffffff' : '#EF991F' ) ),
674 'stickerBtnTextSize' => isset( $hotspot['hotspot-sticker-btn-text-size'] ) && $hotspot['hotspot-sticker-btn-text-size'] !== '' ? (float) $hotspot['hotspot-sticker-btn-text-size'] : 18,
675 'stickerBtnTextWeight' => $hotspot['hotspot-sticker-btn-text-weight'] ?? ( ( $is_social_share || $is_add_to_cart || $is_separate_icon ) ? '600' : '700' ),
676 'stickerBtnIcon' => ( $is_add_to_cart || $is_social_share ) ? 'none' : ( $hotspot['hotspot-sticker-btn-icon'] ?? 'fas fa-tag' ),
677 // Button with separate icon fields
678 'stickerIconBoxBgColor' => $hotspot['hotspot-sticker-icon-box-bg-color'] ?? '#ffffff',
679 'stickerIconBoxRadius' => isset( $hotspot['hotspot-sticker-icon-box-radius'] ) && $hotspot['hotspot-sticker-icon-box-radius'] !== '' ? (float) $hotspot['hotspot-sticker-icon-box-radius'] : 30,
680 'stickerIconBoxBorder' => isset( $hotspot['hotspot-sticker-icon-box-border'] ) && $hotspot['hotspot-sticker-icon-box-border'] !== '' ? (float) $hotspot['hotspot-sticker-icon-box-border'] : 0,
681 'stickerIconBoxBorderColor' => $hotspot['hotspot-sticker-icon-box-border-color'] ?? '#ffffff',
682 'stickerIconBoxSize' => isset( $hotspot['hotspot-sticker-icon-box-size'] ) && $hotspot['hotspot-sticker-icon-box-size'] !== '' ? (float) $hotspot['hotspot-sticker-icon-box-size'] : 60,
683 // Social share sticker fields
684 'stickerSocialColor' => $hotspot['hotspot-sticker-social-color'] ?? '#ffffff',
685 'stickerSocialSize' => isset( $hotspot['hotspot-sticker-social-size'] ) && $hotspot['hotspot-sticker-social-size'] !== '' ? (float) $hotspot['hotspot-sticker-social-size'] : 20,
686 'stickerSocialGap' => isset( $hotspot['hotspot-sticker-social-gap'] ) && $hotspot['hotspot-sticker-social-gap'] !== '' ? (float) $hotspot['hotspot-sticker-social-gap'] : 16,
687 'stickerSocialLinks' => isset( $hotspot['hotspot-sticker-social-links'] ) ? ( is_array( $hotspot['hotspot-sticker-social-links'] ) ? $hotspot['hotspot-sticker-social-links'] : json_decode( (string) $hotspot['hotspot-sticker-social-links'], true ) ) : [
688 [ 'id' => '1', 'icon' => 'fab fa-linkedin-in', 'customSvg' => '', 'url' => 'https://linkedin.com', 'openNewTab' => 'on' ],
689 [ 'id' => '2', 'icon' => 'fab fa-facebook-f', 'customSvg' => '', 'url' => 'https://facebook.com', 'openNewTab' => 'on' ],
690 [ 'id' => '3', 'icon' => 'fab fa-instagram', 'customSvg' => '', 'url' => 'https://instagram.com', 'openNewTab' => 'on' ],
691 [ 'id' => '4', 'icon' => 'fab fa-dribbble', 'customSvg' => '', 'url' => 'https://dribbble.com', 'openNewTab' => 'on' ],
692 ],
693 'stickerShowPlaceholderText' => $hotspot['hotspot-sticker-show-placeholder-text'] ?? 'on',
694 'scale' => isset( $hotspot['hotspot-scale'] ) ? ( $hotspot['hotspot-scale'] === 'on' || $hotspot['hotspot-scale'] === true ) : ( ( $hotspot['hotspot-type'] ?? '' ) === 'sticker' ),
695 // Pro styling fields
696 'iconClass' => ( ( $hotspot['hotspot-customclass-pro'] ?? '' ) === 'none' || ( $hotspot['hotspot-customclass-pro'] ?? '' ) === '' ) ? '' : $hotspot['hotspot-customclass-pro'],
697 'iconBgColor' => $hotspot['hotspot-customclass-color-icon-value'] ?? '#00b4ff',
698 'iconColor' => $hotspot['hotspot-custom-icon-color-value'] ?? '#ffffff',
699 'blink' => $hotspot['hotspot-blink'] ?? 'on',
700 'shape' => $hotspot['hotspot-shape'] ?? 'round',
701 'border' => $hotspot['hotspot-border'] ?? 'off',
702 'borderWidth' => $hotspot['hotspot-border-width'] ?? '1',
703 'borderStyle' => $hotspot['hotspot-border-style'] ?? 'none',
704 'borderColor' => $hotspot['hotspot-border-color'] ?? '#00b4ff',
705 // Pro navigation entry point fields
706 'scenePitch' => $scene_pitch,
707 'sceneYaw' => $scene_yaw,
708 'sceneEntryPointMode' => $hotspot['hotspot-scene-entry-point-mode'] ?? null,
709 ];
710 }
711 return $hotspots;
712 }
713
714 protected function hotspots_from_api( array $hotspots ): array {
715 $hotspot_list = [];
716 foreach ( $hotspots as $hotspot ) {
717 $hotspot_type = sanitize_key( $hotspot['type'] ?? 'info' );
718 $is_fluent_form = $hotspot_type === 'fluent_form';
719 $raw_content = (string) ( $hotspot['content'] ?? '' );
720 $raw_hover = (string) ( $hotspot['hover'] ?? '' );
721
722 // For fluent_form hotspots, content is dynamically rendered server-side from fluent-form-id.
723 // User-supplied content is never used and must not be saved, completely eliminating stored XSS.
724 if ( $is_fluent_form ) {
725 $content = '';
726 } else {
727 $content = function_exists( 'sanitize_content_preserve_styles' )
728 ? sanitize_content_preserve_styles( $raw_content, false )
729 : wp_kses_post( $raw_content );
730 }
731 $hover = function_exists( 'sanitize_content_preserve_styles' )
732 ? sanitize_content_preserve_styles( $raw_hover, false )
733 : wp_kses_post( $raw_hover );
734
735 $hs = [
736 'hotspot-id' => $hotspot['id'] ?? wp_generate_uuid4(),
737 'hotspot-type' => $hotspot_type,
738 'hotspot-pitch' => (string) ( $hotspot['pitch'] ?? 0 ),
739 'hotspot-yaw' => (string) ( $hotspot['yaw'] ?? 0 ),
740 'hotspot-title' => sanitize_text_field( $hotspot['text'] ?? '' ),
741 'hotspot-content' => $content,
742 'hotspot-url' => sanitize_text_field( $hotspot['url'] ?? '' ),
743 'hotspot-url-open' => ( $hotspot['urlOpen'] ?? 'off' ) === 'on' ? 'on' : 'off',
744 'hotspot-hover' => $hover,
745 'hotspot-scene' => sanitize_text_field( $hotspot['targetSceneId'] ?? '' ),
746 'hotspot-customclass' => sanitize_text_field( $hotspot['customClass'] ?? '' ),
747 'hotspot-scene-list' => 'none',
748 ];
749
750 if ( isset( $hotspot['fluentFormId'] ) ) {
751 $hs['fluent-form-id'] = (string) absint( $hotspot['fluentFormId'] );
752 } elseif ( isset( $hotspot['fluent-form-id'] ) ) {
753 $hs['fluent-form-id'] = (string) absint( $hotspot['fluent-form-id'] );
754 }
755
756 if ( isset( $hotspot['productId'] ) ) {
757 $hs['hotspot-product-id'] = sanitize_text_field( $hotspot['productId'] );
758 } elseif ( isset( $hotspot['hotspot-product-id'] ) ) {
759 $hs['hotspot-product-id'] = sanitize_text_field( $hotspot['hotspot-product-id'] );
760 }
761
762 // Sticker fields
763 if ( isset( $hotspot['stickerTemplate'] ) || isset( $hotspot['hotspot-sticker-template'] ) ) {
764 $hs['hotspot-sticker-template'] = sanitize_text_field( $hotspot['stickerTemplate'] ?? $hotspot['hotspot-sticker-template'] );
765 }
766 if ( isset( $hotspot['stickerReviewText'] ) || isset( $hotspot['hotspot-sticker-review-text'] ) ) {
767 $hs['hotspot-sticker-review-text'] = sanitize_textarea_field( $hotspot['stickerReviewText'] ?? $hotspot['hotspot-sticker-review-text'] );
768 }
769 if ( isset( $hotspot['stickerClientName'] ) || isset( $hotspot['hotspot-sticker-client-name'] ) ) {
770 $hs['hotspot-sticker-client-name'] = sanitize_text_field( $hotspot['stickerClientName'] ?? $hotspot['hotspot-sticker-client-name'] );
771 }
772 if ( isset( $hotspot['stickerClientAvatar'] ) || isset( $hotspot['hotspot-sticker-client-avatar'] ) ) {
773 $hs['hotspot-sticker-client-avatar'] = esc_url_raw( $hotspot['stickerClientAvatar'] ?? $hotspot['hotspot-sticker-client-avatar'] );
774 }
775 if ( isset( $hotspot['stickerRating'] ) || isset( $hotspot['hotspot-sticker-rating'] ) ) {
776 $hs['hotspot-sticker-rating'] = (string) max( 1, min( 5, (int) ( $hotspot['stickerRating'] ?? $hotspot['hotspot-sticker-rating'] ) ) );
777 }
778 if ( isset( $hotspot['stickerBgColor'] ) || isset( $hotspot['hotspot-sticker-bg-color'] ) ) {
779 $hs['hotspot-sticker-bg-color'] = sanitize_text_field( $hotspot['stickerBgColor'] ?? $hotspot['hotspot-sticker-bg-color'] );
780 }
781 if ( isset( $hotspot['stickerBgOpacity'] ) || isset( $hotspot['hotspot-sticker-bg-opacity'] ) ) {
782 $hs['hotspot-sticker-bg-opacity'] = max( 0, min( 100, (float) ( $hotspot['stickerBgOpacity'] ?? $hotspot['hotspot-sticker-bg-opacity'] ) ) );
783 }
784 if ( isset( $hotspot['stickerBlur'] ) || isset( $hotspot['hotspot-sticker-blur'] ) ) {
785 $hs['hotspot-sticker-blur'] = max( 0, min( 40, (float) ( $hotspot['stickerBlur'] ?? $hotspot['hotspot-sticker-blur'] ) ) );
786 }
787 if ( isset( $hotspot['stickerBrightness'] ) || isset( $hotspot['hotspot-sticker-brightness'] ) ) {
788 $hs['hotspot-sticker-brightness'] = max( 0, min( 200, (float) ( $hotspot['stickerBrightness'] ?? $hotspot['hotspot-sticker-brightness'] ) ) );
789 }
790 if ( isset( $hotspot['stickerTextColor'] ) || isset( $hotspot['hotspot-sticker-text-color'] ) ) {
791 $hs['hotspot-sticker-text-color'] = sanitize_hex_color( $hotspot['stickerTextColor'] ?? $hotspot['hotspot-sticker-text-color'] ) ?: '#ffffff';
792 }
793 if ( isset( $hotspot['stickerBorderColor'] ) || isset( $hotspot['hotspot-sticker-border-color'] ) ) {
794 $raw_border_color = strtolower( trim( (string) ( $hotspot['stickerBorderColor'] ?? $hotspot['hotspot-sticker-border-color'] ) ) );
795 if ( $raw_border_color === 'none' || $raw_border_color === 'transparent' ) {
796 $hs['hotspot-sticker-border-color'] = $raw_border_color;
797 } else {
798 $hs['hotspot-sticker-border-color'] = sanitize_hex_color( $raw_border_color ) ?: '#3a3051';
799 }
800 }
801 if ( isset( $hotspot['stickerBorderRadius'] ) || isset( $hotspot['hotspot-sticker-border-radius'] ) ) {
802 $raw_radius = $hotspot['stickerBorderRadius'] ?? $hotspot['hotspot-sticker-border-radius'];
803 if ( is_array( $raw_radius ) ) {
804 $hs['hotspot-sticker-border-radius'] = [
805 'topLeft' => max( 0, min( 500, (float) ( $raw_radius['topLeft'] ?? 20 ) ) ),
806 'topRight' => max( 0, min( 500, (float) ( $raw_radius['topRight'] ?? 20 ) ) ),
807 'bottomRight' => max( 0, min( 500, (float) ( $raw_radius['bottomRight'] ?? 20 ) ) ),
808 'bottomLeft' => max( 0, min( 500, (float) ( $raw_radius['bottomLeft'] ?? 20 ) ) ),
809 ];
810 } else {
811 $val = max( 0, min( 500, (float) $raw_radius ) );
812 $hs['hotspot-sticker-border-radius'] = [
813 'topLeft' => $val,
814 'topRight' => $val,
815 'bottomRight' => $val,
816 'bottomLeft' => $val,
817 ];
818 }
819 }
820 if ( isset( $hotspot['stickerPadding'] ) || isset( $hotspot['hotspot-sticker-padding'] ) ) {
821 $raw_pad = $hotspot['stickerPadding'] ?? $hotspot['hotspot-sticker-padding'];
822 if ( is_array( $raw_pad ) ) {
823 $hs['hotspot-sticker-padding'] = [
824 'top' => max( 0, min( 200, (float) ( $raw_pad['top'] ?? 21 ) ) ),
825 'right' => max( 0, min( 200, (float) ( $raw_pad['right'] ?? 21 ) ) ),
826 'bottom' => max( 0, min( 200, (float) ( $raw_pad['bottom'] ?? 21 ) ) ),
827 'left' => max( 0, min( 200, (float) ( $raw_pad['left'] ?? 21 ) ) ),
828 ];
829 } else {
830 $val = max( 0, min( 200, (float) $raw_pad ) );
831 $hs['hotspot-sticker-padding'] = [
832 'top' => $val,
833 'right' => $val,
834 'bottom' => $val,
835 'left' => $val,
836 ];
837 }
838 }
839 if ( isset( $hotspot['stickerStarColor'] ) || isset( $hotspot['hotspot-sticker-star-color'] ) ) {
840 $hs['hotspot-sticker-star-color'] = sanitize_hex_color( $hotspot['stickerStarColor'] ?? $hotspot['hotspot-sticker-star-color'] ) ?: '#EF991F';
841 }
842 // Discount button sticker fields
843 if ( isset( $hotspot['stickerBtnText'] ) || isset( $hotspot['hotspot-sticker-btn-text'] ) ) {
844 $hs['hotspot-sticker-btn-text'] = sanitize_text_field( $hotspot['stickerBtnText'] ?? $hotspot['hotspot-sticker-btn-text'] );
845 }
846 if ( isset( $hotspot['stickerBtnColor'] ) || isset( $hotspot['hotspot-sticker-btn-color'] ) ) {
847 $hs['hotspot-sticker-btn-color'] = sanitize_hex_color( $hotspot['stickerBtnColor'] ?? $hotspot['hotspot-sticker-btn-color'] ) ?: '#EF991F';
848 }
849 if ( isset( $hotspot['stickerBtnTextColor'] ) || isset( $hotspot['hotspot-sticker-btn-text-color'] ) ) {
850 $hs['hotspot-sticker-btn-text-color'] = sanitize_hex_color( $hotspot['stickerBtnTextColor'] ?? $hotspot['hotspot-sticker-btn-text-color'] ) ?: '#000000';
851 }
852 if ( isset( $hotspot['stickerBtnIconColor'] ) || isset( $hotspot['hotspot-sticker-btn-icon-color'] ) ) {
853 $hs['hotspot-sticker-btn-icon-color'] = sanitize_hex_color( $hotspot['stickerBtnIconColor'] ?? $hotspot['hotspot-sticker-btn-icon-color'] ) ?: '#000000';
854 }
855 if ( isset( $hotspot['stickerBtnUrl'] ) || isset( $hotspot['hotspot-sticker-btn-url'] ) ) {
856 $hs['hotspot-sticker-btn-url'] = esc_url_raw( $hotspot['stickerBtnUrl'] ?? $hotspot['hotspot-sticker-btn-url'] );
857 }
858 if ( isset( $hotspot['stickerBtnNewTab'] ) || isset( $hotspot['hotspot-sticker-btn-new-tab'] ) ) {
859 $raw_new_tab = $hotspot['stickerBtnNewTab'] ?? $hotspot['hotspot-sticker-btn-new-tab'];
860 $hs['hotspot-sticker-btn-new-tab'] = ( $raw_new_tab === 'on' || $raw_new_tab === true || $raw_new_tab === 'true' ) ? 'on' : 'off';
861 }
862 if ( isset( $hotspot['stickerMainBg'] ) || isset( $hotspot['hotspot-sticker-main-bg'] ) || isset( $hotspot['stickerCardBg'] ) || isset( $hotspot['hotspot-sticker-card-bg'] ) ) {
863 $raw_main_bg = $hotspot['stickerMainBg'] ?? ( $hotspot['stickerCardBg'] ?? ( $hotspot['hotspot-sticker-main-bg'] ?? $hotspot['hotspot-sticker-card-bg'] ) );
864 $val = ( $raw_main_bg === 'off' || $raw_main_bg === false || $raw_main_bg === 'false' ) ? 'off' : 'on';
865 $hs['hotspot-sticker-main-bg'] = $val;
866 $hs['hotspot-sticker-card-bg'] = $val;
867 }
868 if ( isset( $hotspot['stickerBtnBg'] ) || isset( $hotspot['hotspot-sticker-btn-bg'] ) ) {
869 $raw_bg = $hotspot['stickerBtnBg'] ?? $hotspot['hotspot-sticker-btn-bg'];
870 $hs['hotspot-sticker-btn-bg'] = ( $raw_bg === 'off' || $raw_bg === false || $raw_bg === 'false' ) ? 'off' : 'on';
871 }
872 if ( isset( $hotspot['stickerBtnWidth'] ) || isset( $hotspot['hotspot-sticker-btn-width'] ) ) {
873 $raw_w = $hotspot['stickerBtnWidth'] ?? $hotspot['hotspot-sticker-btn-width'];
874 $hs['hotspot-sticker-btn-width'] = ( $raw_w !== '' && $raw_w !== null ) ? sanitize_text_field( (string) $raw_w ) : '';
875 }
876 if ( isset( $hotspot['stickerBtnHeight'] ) || isset( $hotspot['hotspot-sticker-btn-height'] ) ) {
877 $raw_h = $hotspot['stickerBtnHeight'] ?? $hotspot['hotspot-sticker-btn-height'];
878 $hs['hotspot-sticker-btn-height'] = ( $raw_h !== '' && $raw_h !== null ) ? sanitize_text_field( (string) $raw_h ) : '';
879 }
880 if ( isset( $hotspot['stickerBtnRadius'] ) || isset( $hotspot['hotspot-sticker-btn-radius'] ) ) {
881 $hs['hotspot-sticker-btn-radius'] = (float) ( $hotspot['stickerBtnRadius'] ?? $hotspot['hotspot-sticker-btn-radius'] );
882 }
883 if ( isset( $hotspot['stickerBtnBorder'] ) || isset( $hotspot['hotspot-sticker-btn-border'] ) ) {
884 $hs['hotspot-sticker-btn-border'] = (float) ( $hotspot['stickerBtnBorder'] ?? $hotspot['hotspot-sticker-btn-border'] );
885 }
886 if ( isset( $hotspot['stickerBtnBorderColor'] ) || isset( $hotspot['hotspot-sticker-btn-border-color'] ) ) {
887 $hs['hotspot-sticker-btn-border-color'] = sanitize_hex_color( $hotspot['stickerBtnBorderColor'] ?? $hotspot['hotspot-sticker-btn-border-color'] ) ?: '#EF991F';
888 }
889 if ( isset( $hotspot['stickerBtnTextSize'] ) || isset( $hotspot['hotspot-sticker-btn-text-size'] ) ) {
890 $hs['hotspot-sticker-btn-text-size'] = (float) ( $hotspot['stickerBtnTextSize'] ?? $hotspot['hotspot-sticker-btn-text-size'] );
891 }
892 if ( isset( $hotspot['stickerBtnTextWeight'] ) || isset( $hotspot['hotspot-sticker-btn-text-weight'] ) ) {
893 $hs['hotspot-sticker-btn-text-weight'] = sanitize_text_field( (string) ( $hotspot['stickerBtnTextWeight'] ?? $hotspot['hotspot-sticker-btn-text-weight'] ) );
894 }
895 if ( ( $hs['hotspot-sticker-template'] ?? '' ) === 'add_to_cart' || ( $hs['hotspot-sticker-template'] ?? '' ) === 'social_share' ) {
896 $hs['hotspot-sticker-btn-icon'] = 'none';
897 } elseif ( isset( $hotspot['stickerBtnIcon'] ) || isset( $hotspot['hotspot-sticker-btn-icon'] ) ) {
898 $hs['hotspot-sticker-btn-icon'] = sanitize_text_field( $hotspot['stickerBtnIcon'] ?? $hotspot['hotspot-sticker-btn-icon'] );
899 }
900 // Add to cart text fields
901 if ( isset( $hotspot['stickerPrefixText'] ) || isset( $hotspot['hotspot-sticker-prefix-text'] ) ) {
902 $hs['hotspot-sticker-prefix-text'] = sanitize_text_field( $hotspot['stickerPrefixText'] ?? $hotspot['hotspot-sticker-prefix-text'] );
903 }
904 if ( isset( $hotspot['stickerSubText'] ) || isset( $hotspot['hotspot-sticker-sub-text'] ) ) {
905 $hs['hotspot-sticker-sub-text'] = sanitize_text_field( $hotspot['stickerSubText'] ?? $hotspot['hotspot-sticker-sub-text'] );
906 }
907 // Button with separate icon fields
908 if ( isset( $hotspot['stickerIconBoxBgColor'] ) || isset( $hotspot['hotspot-sticker-icon-box-bg-color'] ) ) {
909 $hs['hotspot-sticker-icon-box-bg-color'] = sanitize_hex_color( $hotspot['stickerIconBoxBgColor'] ?? $hotspot['hotspot-sticker-icon-box-bg-color'] ) ?: '#ffffff';
910 }
911 if ( isset( $hotspot['stickerIconBoxRadius'] ) || isset( $hotspot['hotspot-sticker-icon-box-radius'] ) ) {
912 $hs['hotspot-sticker-icon-box-radius'] = (float) ( $hotspot['stickerIconBoxRadius'] ?? $hotspot['hotspot-sticker-icon-box-radius'] );
913 }
914 if ( isset( $hotspot['stickerIconBoxBorder'] ) || isset( $hotspot['hotspot-sticker-icon-box-border'] ) ) {
915 $hs['hotspot-sticker-icon-box-border'] = (float) ( $hotspot['stickerIconBoxBorder'] ?? $hotspot['hotspot-sticker-icon-box-border'] );
916 }
917 if ( isset( $hotspot['stickerIconBoxBorderColor'] ) || isset( $hotspot['hotspot-sticker-icon-box-border-color'] ) ) {
918 $hs['hotspot-sticker-icon-box-border-color'] = sanitize_hex_color( $hotspot['stickerIconBoxBorderColor'] ?? $hotspot['hotspot-sticker-icon-box-border-color'] ) ?: '#ffffff';
919 }
920 if ( isset( $hotspot['stickerIconBoxSize'] ) || isset( $hotspot['hotspot-sticker-icon-box-size'] ) ) {
921 $hs['hotspot-sticker-icon-box-size'] = (float) ( $hotspot['stickerIconBoxSize'] ?? $hotspot['hotspot-sticker-icon-box-size'] );
922 }
923 // Social share sticker fields
924 if ( isset( $hotspot['stickerSocialColor'] ) || isset( $hotspot['hotspot-sticker-social-color'] ) ) {
925 $hs['hotspot-sticker-social-color'] = sanitize_hex_color( $hotspot['stickerSocialColor'] ?? $hotspot['hotspot-sticker-social-color'] ) ?: '#ffffff';
926 }
927 if ( isset( $hotspot['stickerSocialSize'] ) || isset( $hotspot['hotspot-sticker-social-size'] ) ) {
928 $hs['hotspot-sticker-social-size'] = (float) ( $hotspot['stickerSocialSize'] ?? $hotspot['hotspot-sticker-social-size'] );
929 }
930 if ( isset( $hotspot['stickerSocialGap'] ) || isset( $hotspot['hotspot-sticker-social-gap'] ) ) {
931 $hs['hotspot-sticker-social-gap'] = (float) ( $hotspot['stickerSocialGap'] ?? $hotspot['hotspot-sticker-social-gap'] );
932 }
933 if ( isset( $hotspot['stickerSocialLinks'] ) || isset( $hotspot['hotspot-sticker-social-links'] ) ) {
934 $raw_links = $hotspot['stickerSocialLinks'] ?? $hotspot['hotspot-sticker-social-links'];
935 if ( is_string( $raw_links ) ) {
936 $raw_links = json_decode( $raw_links, true );
937 }
938 $clean_links = [];
939 if ( is_array( $raw_links ) ) {
940 foreach ( $raw_links as $item ) {
941 if ( ! is_array( $item ) ) continue;
942 $clean_links[] = [
943 'id' => sanitize_text_field( (string) ( $item['id'] ?? wp_generate_uuid4() ) ),
944 'icon' => sanitize_text_field( (string) ( $item['icon'] ?? '' ) ),
945 'customSvg' => function_exists( 'wp_kses' ) ? wp_kses( (string) ( $item['customSvg'] ?? '' ), [
946 'svg' => [ 'class' => true, 'xmlns' => true, 'viewbox' => true, 'viewBox' => true, 'width' => true, 'height' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, 'style' => true ],
947 'path' => [ 'd' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, 'style' => true ],
948 'g' => [ 'fill' => true, 'stroke' => true, 'style' => true ],
949 'circle' => [ 'cx' => true, 'cy' => true, 'r' => true, 'fill' => true, 'stroke' => true, 'style' => true ],
950 'rect' => [ 'x' => true, 'y' => true, 'width' => true, 'height' => true, 'rx' => true, 'ry' => true, 'fill' => true, 'stroke' => true, 'style' => true ],
951 ] ) : (string) ( $item['customSvg'] ?? '' ),
952 'url' => esc_url_raw( (string) ( $item['url'] ?? '' ) ),
953 'openNewTab' => ( ( $item['openNewTab'] ?? 'on' ) === 'off' || ( $item['openNewTab'] ?? 'on' ) === false ) ? 'off' : 'on',
954 ];
955 }
956 }
957 $hs['hotspot-sticker-social-links'] = $clean_links;
958 }
959 if ( isset( $hotspot['stickerShowPlaceholderText'] ) || isset( $hotspot['hotspot-sticker-show-placeholder-text'] ) ) {
960 $hs['hotspot-sticker-show-placeholder-text'] = sanitize_text_field( $hotspot['stickerShowPlaceholderText'] ?? $hotspot['hotspot-sticker-show-placeholder-text'] );
961 }
962 if ( isset( $hotspot['scale'] ) ) {
963 $hs['hotspot-scale'] = $hotspot['scale'] ? 'on' : 'off';
964 } elseif ( ( $hotspot['type'] ?? '' ) === 'sticker' ) {
965 $hs['hotspot-scale'] = 'on';
966 }
967
968 if ( $this->is_pro ) {
969 $hs = array_merge( $hs, [
970 // Pro styling fields
971 'hotspot-customclass-pro' => !empty( $hotspot['iconClass'] ) ? $hotspot['iconClass'] : 'none',
972 'hotspot-customclass-color-icon-value' => $hotspot['iconBgColor'] ?? '#00b4ff',
973 'hotspot-custom-icon-color-value' => $hotspot['iconColor'] ?? '#ffffff',
974 'hotspot-blink' => $hotspot['blink'] ?? 'on',
975 'hotspot-shape' => $hotspot['shape'] ?? 'round',
976 'hotspot-border' => $hotspot['border'] ?? 'off',
977 'hotspot-border-width' => $hotspot['borderWidth'] ?? '1',
978 'hotspot-border-style' => $hotspot['borderStyle'] ?? 'none',
979 'hotspot-border-color' => $hotspot['borderColor'] ?? '#00b4ff',
980 'hotspot-scene-pitch' => ( isset( $hotspot['scenePitch'] ) && $hotspot['scenePitch'] !== null ) ? (string) $hotspot['scenePitch'] : '',
981 'hotspot-scene-yaw' => ( isset( $hotspot['sceneYaw'] ) && $hotspot['sceneYaw'] !== null ) ? (string) $hotspot['sceneYaw'] : '',
982 'hotspot-scene-entry-point-mode' => in_array( $hotspot['sceneEntryPointMode'] ?? '', [ 'inherit', 'custom' ], true )
983 ? $hotspot['sceneEntryPointMode']
984 : 'inherit',
985 ] );
986 }
987
988 $hotspot_list[] = $hs;
989 }
990 return $hotspot_list;
991 }
992
993 protected function text_overlays_to_api( array $list ): array {
994 $overlays = [];
995 foreach ( $list as $item ) {
996 if ( ! is_array( $item ) ) {
997 continue;
998 }
999 $overlays[] = [
1000 'id' => (string) ( $item['id'] ?? ( 'overlay_' . wp_generate_uuid4() ) ),
1001 'name' => sanitize_text_field( (string) ( $item['name'] ?? 'Text Overlay Layer' ) ),
1002 'enabled' => ! isset( $item['enabled'] ) || ! empty( $item['enabled'] ),
1003 'template' => in_array( $item['template'] ?? '', [ 'left', 'right', 'top', 'bottom', 'custom' ], true ) ? $item['template'] : '',
1004 'bgColor' => sanitize_hex_color( $item['bgColor'] ?? '' ) ?: '#281E19',
1005 'bgOpacity' => isset( $item['bgOpacity'] ) ? (float) $item['bgOpacity'] : 55,
1006 'blur' => isset( $item['blur'] ) ? (float) $item['blur'] : 14,
1007 'brightness' => isset( $item['brightness'] ) ? (float) $item['brightness'] : 85,
1008 'text' => TextOverlayContent::sanitize( (string) ( $item['text'] ?? '' ) ),
1009 'showClose' => ! isset( $item['showClose'] ) || ! empty( $item['showClose'] ),
1010 'color' => sanitize_hex_color( $item['color'] ?? '' ) ?: '#ffffff',
1011 'fontSize' => isset( $item['fontSize'] ) ? (int) $item['fontSize'] : 18,
1012 'fontWeight' => in_array( $item['fontWeight'] ?? '', [ 'normal', 'bold' ], true ) ? $item['fontWeight'] : 'normal',
1013 'fontStyle' => in_array( $item['fontStyle'] ?? '', [ 'normal', 'italic' ], true ) ? $item['fontStyle'] : 'normal',
1014 'textAlign' => in_array( $item['textAlign'] ?? '', [ 'left', 'center', 'right' ], true ) ? $item['textAlign'] : 'left',
1015 'width' => isset( $item['width'] ) ? (float) $item['width'] : ( isset( $item['position']['width'] ) ? (float) $item['position']['width'] : 75 ),
1016 'position' => [
1017 'x' => isset( $item['position']['x'] ) ? (float) $item['position']['x'] : 10,
1018 'y' => isset( $item['position']['y'] ) ? (float) $item['position']['y'] : 15,
1019 'width' => isset( $item['position']['width'] ) ? (float) $item['position']['width'] : ( isset( $item['width'] ) ? (float) $item['width'] : 75 ),
1020 ],
1021 'containerRect' => isset( $item['containerRect'] ) && is_array( $item['containerRect'] ) ? [
1022 'top' => isset( $item['containerRect']['top'] ) ? (float) $item['containerRect']['top'] : 20,
1023 'left' => isset( $item['containerRect']['left'] ) ? (float) $item['containerRect']['left'] : 20,
1024 'width' => isset( $item['containerRect']['width'] ) ? (float) $item['containerRect']['width'] : 60,
1025 'height' => isset( $item['containerRect']['height'] ) ? (float) $item['containerRect']['height'] : 60,
1026 ] : null,
1027 'borderRadius' => isset( $item['borderRadius'] ) && is_array( $item['borderRadius'] ) ? [
1028 'topLeft' => isset( $item['borderRadius']['topLeft'] ) ? (float) $item['borderRadius']['topLeft'] : 0,
1029 'topRight' => isset( $item['borderRadius']['topRight'] ) ? (float) $item['borderRadius']['topRight'] : 0,
1030 'bottomRight' => isset( $item['borderRadius']['bottomRight'] ) ? (float) $item['borderRadius']['bottomRight'] : 0,
1031 'bottomLeft' => isset( $item['borderRadius']['bottomLeft'] ) ? (float) $item['borderRadius']['bottomLeft'] : 0,
1032 ] : ( isset( $item['borderRadius'] ) && is_numeric( $item['borderRadius'] ) ? [
1033 'topLeft' => (float) $item['borderRadius'],
1034 'topRight' => (float) $item['borderRadius'],
1035 'bottomRight' => (float) $item['borderRadius'],
1036 'bottomLeft' => (float) $item['borderRadius'],
1037 ] : [
1038 'topLeft' => 0,
1039 'topRight' => 0,
1040 'bottomRight' => 0,
1041 'bottomLeft' => 0,
1042 ] ),
1043 ];
1044 }
1045 return array_slice( $overlays, 0, 5 );
1046 }
1047
1048 protected function text_overlays_from_api( array $list ): array {
1049 $overlays = [];
1050 foreach ( $list as $item ) {
1051 if ( ! is_array( $item ) ) {
1052 continue;
1053 }
1054 $overlays[] = [
1055 'id' => sanitize_text_field( (string) ( $item['id'] ?? '' ) ),
1056 'name' => sanitize_text_field( (string) ( $item['name'] ?? 'Text Overlay Layer' ) ),
1057 'enabled' => ! isset( $item['enabled'] ) || ! empty( $item['enabled'] ),
1058 'template' => in_array( $item['template'] ?? '', [ 'left', 'right', 'top', 'bottom', 'custom' ], true ) ? $item['template'] : '',
1059 'bgColor' => sanitize_hex_color( $item['bgColor'] ?? '' ) ?: '#281E19',
1060 'bgOpacity' => isset( $item['bgOpacity'] ) ? (float) $item['bgOpacity'] : 55,
1061 'blur' => isset( $item['blur'] ) ? (float) $item['blur'] : 14,
1062 'brightness' => isset( $item['brightness'] ) ? (float) $item['brightness'] : 85,
1063 'text' => TextOverlayContent::sanitize( (string) ( $item['text'] ?? '' ) ),
1064 'showClose' => ! isset( $item['showClose'] ) || ! empty( $item['showClose'] ),
1065 'color' => sanitize_hex_color( $item['color'] ?? '' ) ?: '#ffffff',
1066 'fontSize' => isset( $item['fontSize'] ) ? (int) $item['fontSize'] : 18,
1067 'fontWeight' => in_array( $item['fontWeight'] ?? '', [ 'normal', 'bold' ], true ) ? $item['fontWeight'] : 'normal',
1068 'fontStyle' => in_array( $item['fontStyle'] ?? '', [ 'normal', 'italic' ], true ) ? $item['fontStyle'] : 'normal',
1069 'textAlign' => in_array( $item['textAlign'] ?? '', [ 'left', 'center', 'right' ], true ) ? $item['textAlign'] : 'left',
1070 'width' => isset( $item['width'] ) ? (float) $item['width'] : ( isset( $item['position']['width'] ) ? (float) $item['position']['width'] : 75 ),
1071 'position' => [
1072 'x' => isset( $item['position']['x'] ) ? (float) $item['position']['x'] : 10,
1073 'y' => isset( $item['position']['y'] ) ? (float) $item['position']['y'] : 15,
1074 'width' => isset( $item['position']['width'] ) ? (float) $item['position']['width'] : ( isset( $item['width'] ) ? (float) $item['width'] : 75 ),
1075 ],
1076 'containerRect' => isset( $item['containerRect'] ) && is_array( $item['containerRect'] ) ? [
1077 'top' => isset( $item['containerRect']['top'] ) ? (float) $item['containerRect']['top'] : 20,
1078 'left' => isset( $item['containerRect']['left'] ) ? (float) $item['containerRect']['left'] : 20,
1079 'width' => isset( $item['containerRect']['width'] ) ? (float) $item['containerRect']['width'] : 60,
1080 'height' => isset( $item['containerRect']['height'] ) ? (float) $item['containerRect']['height'] : 60,
1081 ] : null,
1082 'borderRadius' => isset( $item['borderRadius'] ) && is_array( $item['borderRadius'] ) ? [
1083 'topLeft' => isset( $item['borderRadius']['topLeft'] ) ? (float) $item['borderRadius']['topLeft'] : 0,
1084 'topRight' => isset( $item['borderRadius']['topRight'] ) ? (float) $item['borderRadius']['topRight'] : 0,
1085 'bottomRight' => isset( $item['borderRadius']['bottomRight'] ) ? (float) $item['borderRadius']['bottomRight'] : 0,
1086 'bottomLeft' => isset( $item['borderRadius']['bottomLeft'] ) ? (float) $item['borderRadius']['bottomLeft'] : 0,
1087 ] : ( isset( $item['borderRadius'] ) && is_numeric( $item['borderRadius'] ) ? [
1088 'topLeft' => (float) $item['borderRadius'],
1089 'topRight' => (float) $item['borderRadius'],
1090 'bottomRight' => (float) $item['borderRadius'],
1091 'bottomLeft' => (float) $item['borderRadius'],
1092 ] : [
1093 'topLeft' => 0,
1094 'topRight' => 0,
1095 'bottomRight' => 0,
1096 'bottomLeft' => 0,
1097 ] ),
1098 ];
1099 }
1100 return array_slice( $overlays, 0, 5 );
1101 }
1102 }
1103