PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 9.1.3
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v9.1.3
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 8.5.38 8.5.39 All 222 releases
wpvr / legacy / breakdance / elements / Wpvr / element.php

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

224 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/fontawesome/css/all.css',
82 $public_url . 'css/fontawesome/css/icons-fix.css',
83 $public_url . 'lib/pannellum/src/css/pannellum.css',
84 $public_url . 'css/owl.carousel.css',
85 $public_url . 'css/wpvr-public.css',
86 ],
87 'inlineScripts' => [
88 'window.wpvr_public = window.wpvr_public || ' . wp_json_encode( $runtime_config ) . ';',
89 ],
90 'builderCondition' => 'return true;',
91 'frontendCondition' => 'return false;',
92 ],
93 ];
94 }
95
96 private static function builderPreviewScript() {
97 return <<<'JS'
98 (function () {
99 const element = document.querySelector('%%SELECTOR%%');
100 let attempts = 0;
101
102 function initializeWpvrPreview() {
103 if (!element || attempts > 40) return;
104
105 if (
106 typeof window.jQuery === 'undefined' ||
107 typeof window.pannellum === 'undefined' ||
108 typeof window.wpvrhotspot === 'undefined'
109 ) {
110 attempts += 1;
111 window.setTimeout(initializeWpvrPreview, 50);
112 return;
113 }
114
115 element
116 .querySelectorAll('script[type="application/wpvr-breakdance-preview"]')
117 .forEach(function (previewScript) {
118 if (previewScript.dataset.wpvrInitialized === 'true') return;
119
120 previewScript.dataset.wpvrInitialized = 'true';
121
122 const executableScript = document.createElement('script');
123 executableScript.textContent = previewScript.textContent;
124 document.body.appendChild(executableScript);
125 executableScript.remove();
126 });
127 }
128
129 initializeWpvrPreview();
130 }());
131 JS;
132 }
133
134 public static function actions() {
135 $preview_script = self::builderPreviewScript();
136
137 return [
138 'onMountedElement' => [
139 [ 'script' => $preview_script ],
140 ],
141 'onPropertyChange' => [
142 [ 'script' => $preview_script ],
143 ],
144 ];
145 }
146
147 public static function defaultProperties() {
148 return [
149 'content' => [
150 'wpvr' => [
151 'tour' => null,
152 'width' => 600,
153 'height' => 400,
154 'mobile_height' => 300,
155 'radius' => 0,
156 ],
157 ],
158 ];
159 }
160
161 public static function contentControls() {
162 $number_options = [
163 'type' => 'number',
164 'layout' => 'inline',
165 'rangeOptions' => [
166 'min' => 0,
167 'max' => 2000,
168 'step' => 1,
169 ],
170 ];
171
172 return [
173 c(
174 'wpvr',
175 'WP VR',
176 [
177 c(
178 'tour',
179 __( 'Select Tour', 'wpvr' ),
180 [],
181 [
182 'type' => 'post_chooser',
183 'layout' => 'vertical',
184 'postChooserOptions' => [
185 'multiple' => false,
186 'showThumbnails' => true,
187 'postType' => 'wpvr_item',
188 ],
189 ],
190 false,
191 false,
192 []
193 ),
194 c( 'width', __( 'Width (px)', 'wpvr' ), [], $number_options, false, false, [] ),
195 c( 'height', __( 'Height (px)', 'wpvr' ), [], $number_options, false, false, [] ),
196 c( 'mobile_height', __( 'Mobile Height (px)', 'wpvr' ), [], $number_options, false, false, [] ),
197 c( 'radius', __( 'Border Radius (px)', 'wpvr' ), [], $number_options, false, false, [] ),
198 ],
199 [
200 'type' => 'section',
201 'layout' => 'vertical',
202 ],
203 false,
204 false,
205 []
206 ),
207 ];
208 }
209
210 public static function nestingRule() {
211 return [ 'type' => 'final' ];
212 }
213
214 public static function propertyPathsToSsrElementWhenValueChanges() {
215 return [
216 'content.wpvr.tour',
217 'content.wpvr.width',
218 'content.wpvr.height',
219 'content.wpvr.mobile_height',
220 'content.wpvr.radius',
221 ];
222 }
223 }
224