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 / public / class-wpvr-public.php

class-wpvr-public.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 9.2.0, at legacy/public/class-wpvr-public.php

326 lines 17.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The public-facing functionality of the plugin.
5 *
6 * @link http://rextheme.com/
7 * @since 8.0.0
8 *
9 * @package Wpvr
10 * @subpackage Wpvr/public
11 */
12
13 use WPVR\Builder\DIVI\WPVR_Divi_modules;
14
15 /**
16 * The public-facing functionality of the plugin.
17 *
18 * Defines the plugin name, version, and two examples hooks for how to
19 * enqueue the public-facing stylesheet and JavaScript.
20 *
21 * @package Wpvr
22 * @subpackage Wpvr/public
23 * @author Rextheme <[email protected]>
24 */
25 class Wpvr_Public {
26
27 /**
28 * The ID of this plugin.
29 *
30 * @since 8.0.0
31 * @access private
32 * @var string $plugin_name The ID of this plugin.
33 */
34 private $plugin_name;
35
36 /**
37 * The version of this plugin.
38 *
39 * @since 8.0.0
40 * @access private
41 * @var string $version The current version of this plugin.
42 */
43 private $version;
44
45
46 /**
47 * Instance of WPVR_Shortcode class
48 *
49 * @var object
50 * @since 8.0.0
51 */
52 private $shortcode;
53
54 /**
55 * Initialize the class and set its properties.
56 *
57 * @since 8.0.0
58 * @param string $plugin_name The name of the plugin.
59 * @param string $version The version of this plugin.
60 */
61 public function __construct( $plugin_name, $version ) {
62
63 $this->plugin_name = $plugin_name;
64 $this->version = $version;
65 $this->shortcode = new WPVR_Shortcode($this->plugin_name);
66
67 }
68
69 /**
70 * Register the stylesheets for the public-facing side of the site.
71 *
72 * @since 8.0.0
73 */
74 public function enqueue_styles() {
75 global $wp;
76 $wpvr_script_control = get_option('wpvr_script_control');
77
78 $should_load = false;
79
80 if ( $wpvr_script_control == 'true' ) {
81 $wpvr_script_list = get_option('wpvr_script_list');
82 $allowed_pages = isset($wpvr_script_list) && !empty($wpvr_script_list) ? array_map('sanitize_text_field', explode(",", $wpvr_script_list)) : array();
83 $allowed_pages_modified = array();
84 foreach ($allowed_pages as $value) {
85 $allowed_pages_modified[] = untrailingslashit($value);
86 }
87 $current_url = home_url(add_query_arg(isset($_GET) ? array_map('sanitize_text_field', wp_unslash($_GET)) : array(), isset($wp->request) ? sanitize_text_field($wp->request) : ''));
88 foreach ($allowed_pages_modified as $value) {
89 if ($value && strpos($current_url, $value) !== false) {
90 $should_load = true;
91 break;
92 }
93 }
94 } else {
95 $should_load = true;
96 }
97
98 if ( $should_load ) {
99 $fontawesome_disable = get_option('wpvr_fontawesome_disable');
100 if ($fontawesome_disable != 'true') {
101 wp_enqueue_style($this->plugin_name . 'fontawesome', plugin_dir_url(__FILE__) . 'css/fontawesome/css/all.css', array(), $this->version, 'all');
102 wp_enqueue_style(
103 $this->plugin_name . '-icons-fix',
104 plugin_dir_url(__FILE__) . 'css/fontawesome/css/icons-fix.css',
105 array($this->plugin_name . 'fontawesome'),
106 $this->version
107 );
108 }
109 $inter_font_path = plugin_dir_path(__FILE__) . 'css/inter.css';
110 $inter_font_ver = file_exists($inter_font_path) ? filemtime($inter_font_path) : $this->version;
111 wp_enqueue_style('wpvr-inter-font', plugin_dir_url(__FILE__) . 'css/inter.css', array(), $inter_font_ver, 'all');
112 wp_enqueue_style('videojs-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/video-js.css', array(), $this->version);
113 wp_enqueue_style('videojs-vr-css', plugin_dir_url(__FILE__) . 'lib/videojs-vr/videojs-vr.css', array(), $this->version);
114 wp_enqueue_style('panellium-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/pannellum.css', array(), $this->version);
115 wp_enqueue_style('owl-css', plugin_dir_url(__FILE__) . 'css/owl.carousel.css', array(), $this->version, 'all');
116 $public_css_path = plugin_dir_path(__FILE__) . 'css/wpvr-public.css';
117 $public_css_ver = file_exists($public_css_path) ? filemtime($public_css_path) : $this->version;
118 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-public.css', array('wpvr-inter-font'), $public_css_ver, 'all');
119 wp_enqueue_style('wpvr-stickers', plugin_dir_url(__FILE__) . 'css/wpvr-stickers.css', array($this->plugin_name), filemtime(plugin_dir_path(__FILE__) . 'css/wpvr-stickers.css'));
120 }
121 }
122
123 /**
124 * Register the JavaScript for the public-facing side of the site.
125 *
126 * @since 8.0.0
127 */
128 public function enqueue_scripts() {
129 global $wp;
130 $wpvr_script_control = get_option('wpvr_script_control');
131
132 if ( $wpvr_script_control == 'true' ) {
133 $wpvr_frontend_notice = get_option('wpvr_frontend_notice');
134 $notice = $wpvr_frontend_notice ? sanitize_text_field( get_option('wpvr_frontend_notice_area') ) : '';
135 $wpvr_script_list = get_option('wpvr_script_list');
136 $allowed_pages = isset($wpvr_script_list) && !empty($wpvr_script_list) ? array_map('sanitize_text_field', explode(",", $wpvr_script_list)) : array();
137 $allowed_pages_modified = array();
138 foreach ($allowed_pages as $value) {
139 $allowed_pages_modified[] = untrailingslashit($value);
140 }
141 $current_url = home_url(add_query_arg(isset($_GET) ? array_map('sanitize_text_field', wp_unslash($_GET)) : array(), isset($wp->request) ? sanitize_text_field($wp->request) : ''));
142
143 foreach ($allowed_pages_modified as $value) {
144 if ($value && strpos($current_url, $value) !== false) {
145 wp_enqueue_script('videojs-js', plugin_dir_url(__FILE__) . 'js/video.js', array(), $this->version, true);
146 wp_enqueue_script('videojsvr-js', plugin_dir_url(__FILE__) . 'lib/videojs-vr/videojs-vr.js', array('videojs-js'), $this->version, true);
147 wp_enqueue_script('panellium-js', plugin_dir_url(__FILE__) . 'lib/pannellum/src/js/pannellum.js', array(), $this->version, true);
148 wp_enqueue_script('panelliumlib-js', plugin_dir_url(__FILE__) . 'lib/pannellum/src/js/libpannellum.js', array('panellium-js'), $this->version, true);
149 wp_enqueue_script('panelliumvid-js', plugin_dir_url(__FILE__) . 'lib/pannellum/src/js/videojs-pannellum-plugin.js', array('videojs-js', 'videojsvr-js', 'panellium-js', 'panelliumlib-js'), $this->version, true);
150 wp_enqueue_script('owl-js', plugin_dir_url(__FILE__) . 'js/owl.carousel.js', array('jquery'), $this->version, true);
151 wp_enqueue_script('jquery_cookie', plugin_dir_url(__FILE__) . 'js/jquery.cookie.js', array('jquery'), $this->version, true);
152 wp_enqueue_script('wpvr-stickers', plugin_dir_url(__FILE__) . 'js/wpvr-stickers.js', array(), filemtime(plugin_dir_path(__FILE__) . 'js/wpvr-stickers.js'), true);
153 wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/wpvr-public.js', array('jquery', 'jquery_cookie', 'wpvr-stickers'), $this->version, true);
154 wp_localize_script('wpvr', 'wpvr_public', array(
155 'notice_active' => $wpvr_frontend_notice,
156 'notice' => $notice,
157 'is_pro_active' => is_plugin_active('wpvr-pro/wpvr-pro.php'),
158 'is_license_active' => get_option('wpvr_edd_license_status') == 'valid' ? true : false,
159 'dis_on_hover' => get_option('dis_on_hover') === 'true' ? true : false,
160 'mobile_hotspot_tip' => get_option('wpvr_mobile_hotspot_tip') === 'true' ? true : false,
161 ));
162 break;
163 }
164 }
165 }
166 // In auto mode, scripts are enqueued from render functions via wpvr_enqueue_frontend_scripts().
167 }
168
169 /**
170 * Ensure the Video.js Pannellum adapter loads after its runtime dependencies.
171 */
172 public function fix_script_deps() {
173 $scripts = wp_scripts();
174
175 if (
176 isset($scripts->registered['panelliumvid-js'])
177 && !wp_script_is('panelliumvid-js', 'done')
178 ) {
179 $registered = $scripts->registered['panelliumvid-js'];
180 $required_dependencies = array('videojs-js', 'videojsvr-js', 'panellium-js', 'panelliumlib-js');
181
182 if (array_diff($required_dependencies, $registered->deps) || !$scripts->get_data('panelliumvid-js', 'group')) {
183 $src = $registered->src;
184 $ver = $registered->ver;
185 wp_deregister_script('panelliumvid-js');
186 wp_enqueue_script('panelliumvid-js', $src, $required_dependencies, $ver, true);
187 }
188 }
189 }
190
191 /**
192 * Init the edit screen of the plugin post type item
193 *
194 * @since 8.0.0
195 */
196 public function public_init()
197 {
198 add_shortcode($this->plugin_name, array( $this->shortcode , 'wpvr_shortcode'));
199
200 }
201
202 }
203
204 if ( ! function_exists( 'wpvr_accessibility_labels' ) ) {
205 function wpvr_accessibility_labels() {
206 return array(
207 'tour' => __( 'Virtual tour', 'wpvr' ),
208 'instructions' => __( 'Use the arrow keys or W, A, S, and D to look around. Use Tab to reach tour controls and hotspots.', 'wpvr' ),
209 'load' => __( 'Load virtual tour', 'wpvr' ),
210 'hotspot' => __( 'Tour hotspot', 'wpvr' ),
211 'scene' => __( 'View scene', 'wpvr' ),
212 'scene_menu' => __( 'Scene menu', 'wpvr' ),
213 'previous_scene' => __( 'Previous scene', 'wpvr' ),
214 'next_scene' => __( 'Next scene', 'wpvr' ),
215 'pan_up' => __( 'Look up', 'wpvr' ),
216 'pan_down' => __( 'Look down', 'wpvr' ),
217 'pan_left' => __( 'Look left', 'wpvr' ),
218 'pan_right' => __( 'Look right', 'wpvr' ),
219 'zoom_in' => __( 'Zoom in', 'wpvr' ),
220 'zoom_out' => __( 'Zoom out', 'wpvr' ),
221 'fullscreen' => __( 'Toggle fullscreen', 'wpvr' ),
222 'home' => __( 'Return to starting scene', 'wpvr' ),
223 'orientation' => __( 'Toggle device orientation', 'wpvr' ),
224 'audio' => __( 'Toggle tour audio', 'wpvr' ),
225 'gallery' => __( 'Toggle scene gallery', 'wpvr' ),
226 'explainer' => __( 'Open tour video', 'wpvr' ),
227 'form' => __( 'Open form', 'wpvr' ),
228 'floor_plan' => __( 'Open floor plan', 'wpvr' ),
229 'floor_plan_point' => __( 'View scene from floor plan', 'wpvr' ),
230 'company_info' => __( 'Company information', 'wpvr' ),
231 'close' => __( 'Close dialog', 'wpvr' ),
232 'dialog' => __( 'Tour dialog', 'wpvr' ),
233 );
234 }
235 }
236
237 if ( ! function_exists( 'wpvr_enqueue_accessibility_script' ) ) {
238 function wpvr_enqueue_accessibility_script() {
239 $base = plugin_dir_url( __FILE__ );
240 $ver = defined( 'WPVR_VERSION' ) ? WPVR_VERSION : '1.0.0';
241
242 wp_enqueue_script(
243 'wpvr-accessibility',
244 $base . 'js/wpvr-accessibility.js',
245 array( 'jquery', 'wpvr' ),
246 $ver,
247 true
248 );
249 wp_localize_script( 'wpvr-accessibility', 'wpvrAccessibility', wpvr_accessibility_labels() );
250 }
251 }
252
253 if ( ! function_exists( 'wpvr_maybe_enqueue_accessibility_script' ) ) {
254 function wpvr_maybe_enqueue_accessibility_script() {
255 if ( wp_script_is( 'wpvr', 'enqueued' ) || wp_script_is( 'panellium-js', 'enqueued' ) ) {
256 wpvr_enqueue_accessibility_script();
257 }
258 }
259 }
260 add_action( 'wp_enqueue_scripts', 'wpvr_maybe_enqueue_accessibility_script', 100 );
261
262 if ( ! function_exists( 'wpvr_enqueue_frontend_scripts' ) ) {
263 function wpvr_enqueue_frontend_scripts( $type = 'scene' ) {
264 $base = plugin_dir_url( __FILE__ );
265 $ver = defined( 'WPVR_VERSION' ) ? WPVR_VERSION : '1.0.0';
266
267 /**
268 * Allow add-ons to replace or extend frontend dependencies before the
269 * free handles are registered. WP VR Pro uses this for page builders
270 * that render their content before wp_head(), including Breakdance.
271 */
272 do_action( 'wpvr_enqueue_frontend_scripts', $type );
273
274 if ( ! wp_style_is( 'panellium-css', 'enqueued' ) ) {
275 $fontawesome_disable = get_option( 'wpvr_fontawesome_disable' );
276 if ( $fontawesome_disable != 'true' ) {
277 wp_enqueue_style( 'wpvrfontawesome', $base . 'css/fontawesome/css/all.css', array(), $ver, 'all' );
278 wp_enqueue_style(
279 'wpvr-icons-fix',
280 $base . 'css/fontawesome/css/icons-fix.css',
281 array( 'wpvrfontawesome' ),
282 $ver
283 );
284 }
285 $inter_font_path = plugin_dir_path( __FILE__ ) . 'css/inter.css';
286 $inter_font_ver = file_exists( $inter_font_path ) ? filemtime( $inter_font_path ) : $ver;
287 wp_enqueue_style( 'wpvr-inter-font', $base . 'css/inter.css', array(), $inter_font_ver, 'all' );
288 wp_enqueue_style( 'panellium-css', $base . 'lib/pannellum/src/css/pannellum.css', array(), $ver );
289 wp_enqueue_style( 'owl-css', $base . 'css/owl.carousel.css', array(), $ver, 'all' );
290 $public_css_path = plugin_dir_path( __FILE__ ) . 'css/wpvr-public.css';
291 $public_css_ver = file_exists( $public_css_path ) ? filemtime( $public_css_path ) : $ver;
292 wp_enqueue_style( 'wpvr', $base . 'css/wpvr-public.css', array( 'wpvr-inter-font' ), $public_css_ver, 'all' );
293 wp_enqueue_style('wpvr-stickers', $base . 'css/wpvr-stickers.css', array('wpvr'), filemtime(plugin_dir_path(__FILE__) . 'css/wpvr-stickers.css'));
294 }
295
296 if ( $type === 'video' && ! wp_style_is( 'videojs-vr-css', 'enqueued' ) ) {
297 wp_enqueue_style( 'videojs-css', $base . 'lib/pannellum/src/css/video-js.css', array(), $ver );
298 wp_enqueue_style( 'videojs-vr-css', $base . 'lib/videojs-vr/videojs-vr.css', array(), $ver );
299 }
300
301 wp_enqueue_script( 'panellium-js', $base . 'lib/pannellum/src/js/pannellum.js', array(), $ver, true );
302 wp_enqueue_script( 'panelliumlib-js', $base . 'lib/pannellum/src/js/libpannellum.js', array('panellium-js'), $ver, true );
303 wp_enqueue_script( 'owl-js', $base . 'js/owl.carousel.js', array('jquery'), $ver, true );
304 wp_enqueue_script( 'jquery_cookie', $base . 'js/jquery.cookie.js', array('jquery'), $ver, true );
305 wp_enqueue_script('wpvr-stickers', $base . 'js/wpvr-stickers.js', array(), filemtime(plugin_dir_path(__FILE__) . 'js/wpvr-stickers.js'), true);
306 wp_enqueue_script( 'wpvr', $base . 'js/wpvr-public.js', array('jquery', 'jquery_cookie', 'wpvr-stickers'), $ver, true );
307
308 if ( $type === 'video' ) {
309 wp_enqueue_script( 'videojs-js', $base . 'js/video.js', array(), $ver, true );
310 wp_enqueue_script( 'videojsvr-js', $base . 'lib/videojs-vr/videojs-vr.js', array('videojs-js'), $ver, true );
311 wp_enqueue_script( 'panelliumvid-js', $base . 'lib/pannellum/src/js/videojs-pannellum-plugin.js', array('videojs-js', 'videojsvr-js', 'panellium-js', 'panelliumlib-js'), $ver, true );
312 }
313
314 wp_localize_script( 'wpvr', 'wpvr_public', array(
315 'notice_active' => get_option('wpvr_frontend_notice'),
316 'notice' => get_option('wpvr_frontend_notice') ? sanitize_text_field( get_option('wpvr_frontend_notice_area') ) : '',
317 'is_pro_active' => function_exists('is_plugin_active') ? is_plugin_active('wpvr-pro/wpvr-pro.php') : false,
318 'is_license_active' => get_option('wpvr_edd_license_status') == 'valid',
319 'dis_on_hover' => get_option('dis_on_hover') === 'true',
320 'mobile_hotspot_tip' => get_option('wpvr_mobile_hotspot_tip') === 'true',
321 ) );
322
323 wpvr_enqueue_accessibility_script();
324 }
325 }
326