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 / legacy / breakdance / elements / Wpvr / element.php

element.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 9.2.0, at legacy/breakdance/elements/Wpvr/element.php

225 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WpvrElement\Breakdance;
4
5 use function Breakdance\Elements\c;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 \Breakdance\ElementStudio\registerElementForEditing(
12 __NAMESPACE__ . '\\Wpvr',
13 \Breakdance\Util\getDirectoryPathRelativeToPluginFolder( __DIR__ )
14 );
15
16 /**
17 * WP VR element for Breakdance Builder.
18 */
19 class Wpvr extends \Breakdance\Elements\Element {
20
21 public static function uiIcon() {
22 return 'ImageIcon';
23 }
24
25 public static function tag() {
26 return 'div';
27 }
28
29 public static function name() {
30 return 'WP VR';
31 }
32
33 public static function className() {
34 return 'bde-wpvr';
35 }
36
37 public static function category() {
38 return 'basic';
39 }
40
41 public static function slug() {
42 return __CLASS__;
43 }
44
45 public static function template() {
46 return '%%SSR%%';
47 }
48
49 public static function defaultCSS() {
50 return '.breakdance .bde-wpvr { max-width: 100%; width: 100%; }';
51 }
52
53 public static function dependencies() {
54 $public_url = trailingslashit( WPVR_PLUGIN_PUBLIC_DIR_URL );
55 $main_script = $public_url . 'js/wpvr-public.js';
56
57 if ( defined( 'WPVR_PRO_PLUGIN_DIR_URL' ) ) {
58 $main_script = trailingslashit( WPVR_PRO_PLUGIN_DIR_URL ) . 'admin/js/wpvr-public.js';
59 }
60
61 $runtime_config = [
62 'notice_active' => get_option( 'wpvr_frontend_notice' ),
63 'notice' => get_option( 'wpvr_frontend_notice' ) ? sanitize_text_field( get_option( 'wpvr_frontend_notice_area' ) ) : '',
64 'is_pro_active' => defined( 'WPVR_PRO_PLUGIN_DIR_URL' ),
65 'is_license_active' => 'valid' === get_option( 'wpvr_edd_license_status' ),
66 'dis_on_hover' => 'true' === get_option( 'dis_on_hover' ),
67 'mobile_hotspot_tip' => 'true' === get_option( 'wpvr_mobile_hotspot_tip' ),
68 ];
69
70 return [
71 [
72 'title' => 'WP VR builder preview',
73 'scripts' => [
74 $public_url . 'lib/pannellum/src/js/pannellum.js',
75 $public_url . 'lib/pannellum/src/js/libpannellum.js',
76 $public_url . 'js/owl.carousel.js',
77 $public_url . 'js/jquery.cookie.js',
78 $main_script,
79 ],
80 'styles' => [
81 $public_url . 'css/inter.css',
82 $public_url . 'css/fontawesome/css/all.css',
83 $public_url . 'css/fontawesome/css/icons-fix.css',
84 $public_url . 'lib/pannellum/src/css/pannellum.css',
85 $public_url . 'css/owl.carousel.css',
86 $public_url . 'css/wpvr-public.css',
87 ],
88 'inlineScripts' => [
89 'window.wpvr_public = window.wpvr_public || ' . wp_json_encode( $runtime_config ) . ';',
90 ],
91 'builderCondition' => 'return true;',
92 'frontendCondition' => 'return false;',
93 ],
94 ];
95 }
96
97 private static function builderPreviewScript() {
98 return <<<'JS'
99 (function () {
100 const element = document.querySelector('%%SELECTOR%%');
101 let attempts = 0;
102
103 function initializeWpvrPreview() {
104 if (!element || attempts > 40) return;
105
106 if (
107 typeof window.jQuery === 'undefined' ||
108 typeof window.pannellum === 'undefined' ||
109 typeof window.wpvrhotspot === 'undefined'
110 ) {
111 attempts += 1;
112 window.setTimeout(initializeWpvrPreview, 50);
113 return;
114 }
115
116 element
117 .querySelectorAll('script[type="application/wpvr-breakdance-preview"]')
118 .forEach(function (previewScript) {
119 if (previewScript.dataset.wpvrInitialized === 'true') return;
120
121 previewScript.dataset.wpvrInitialized = 'true';
122
123 const executableScript = document.createElement('script');
124 executableScript.textContent = previewScript.textContent;
125 document.body.appendChild(executableScript);
126 executableScript.remove();
127 });
128 }
129
130 initializeWpvrPreview();
131 }());
132 JS;
133 }
134
135 public static function actions() {
136 $preview_script = self::builderPreviewScript();
137
138 return [
139 'onMountedElement' => [
140 [ 'script' => $preview_script ],
141 ],
142 'onPropertyChange' => [
143 [ 'script' => $preview_script ],
144 ],
145 ];
146 }
147
148 public static function defaultProperties() {
149 return [
150 'content' => [
151 'wpvr' => [
152 'tour' => null,
153 'width' => 600,
154 'height' => 400,
155 'mobile_height' => 300,
156 'radius' => 0,
157 ],
158 ],
159 ];
160 }
161
162 public static function contentControls() {
163 $number_options = [
164 'type' => 'number',
165 'layout' => 'inline',
166 'rangeOptions' => [
167 'min' => 0,
168 'max' => 2000,
169 'step' => 1,
170 ],
171 ];
172
173 return [
174 c(
175 'wpvr',
176 'WP VR',
177 [
178 c(
179 'tour',
180 __( 'Select Tour', 'wpvr' ),
181 [],
182 [
183 'type' => 'post_chooser',
184 'layout' => 'vertical',
185 'postChooserOptions' => [
186 'multiple' => false,
187 'showThumbnails' => true,
188 'postType' => 'wpvr_item',
189 ],
190 ],
191 false,
192 false,
193 []
194 ),
195 c( 'width', __( 'Width (px)', 'wpvr' ), [], $number_options, false, false, [] ),
196 c( 'height', __( 'Height (px)', 'wpvr' ), [], $number_options, false, false, [] ),
197 c( 'mobile_height', __( 'Mobile Height (px)', 'wpvr' ), [], $number_options, false, false, [] ),
198 c( 'radius', __( 'Border Radius (px)', 'wpvr' ), [], $number_options, false, false, [] ),
199 ],
200 [
201 'type' => 'section',
202 'layout' => 'vertical',
203 ],
204 false,
205 false,
206 []
207 ),
208 ];
209 }
210
211 public static function nestingRule() {
212 return [ 'type' => 'final' ];
213 }
214
215 public static function propertyPathsToSsrElementWhenValueChanges() {
216 return [
217 'content.wpvr.tour',
218 'content.wpvr.width',
219 'content.wpvr.height',
220 'content.wpvr.mobile_height',
221 'content.wpvr.radius',
222 ];
223 }
224 }
225