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

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

312 lines 15.3 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 <support@rextheme.com>
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 wp_enqueue_style('videojs-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/video-js.css', array(), $this->version);
110 wp_enqueue_style('videojs-vr-css', plugin_dir_url(__FILE__) . 'lib/videojs-vr/videojs-vr.css', array(), $this->version);
111 wp_enqueue_style('panellium-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/pannellum.css', array(), $this->version);
112 wp_enqueue_style('owl-css', plugin_dir_url(__FILE__) . 'css/owl.carousel.css', array(), $this->version, 'all');
113 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-public.css', array(), $this->version, 'all');
114 }
115 }
116
117 /**
118 * Register the JavaScript for the public-facing side of the site.
119 *
120 * @since 8.0.0
121 */
122 public function enqueue_scripts() {
123 global $wp;
124 $wpvr_script_control = get_option('wpvr_script_control');
125
126 if ( $wpvr_script_control == 'true' ) {
127 $wpvr_frontend_notice = get_option('wpvr_frontend_notice');
128 $notice = $wpvr_frontend_notice ? sanitize_text_field( get_option('wpvr_frontend_notice_area') ) : '';
129 $wpvr_script_list = get_option('wpvr_script_list');
130 $allowed_pages = isset($wpvr_script_list) && !empty($wpvr_script_list) ? array_map('sanitize_text_field', explode(",", $wpvr_script_list)) : array();
131 $allowed_pages_modified = array();
132 foreach ($allowed_pages as $value) {
133 $allowed_pages_modified[] = untrailingslashit($value);
134 }
135 $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) : ''));
136
137 foreach ($allowed_pages_modified as $value) {
138 if ($value && strpos($current_url, $value) !== false) {
139 wp_enqueue_script('videojs-js', plugin_dir_url(__FILE__) . 'js/video.js', array(), $this->version, true);
140 wp_enqueue_script('videojsvr-js', plugin_dir_url(__FILE__) . 'lib/videojs-vr/videojs-vr.js', array('videojs-js'), $this->version, true);
141 wp_enqueue_script('panellium-js', plugin_dir_url(__FILE__) . 'lib/pannellum/src/js/pannellum.js', array(), $this->version, true);
142 wp_enqueue_script('panelliumlib-js', plugin_dir_url(__FILE__) . 'lib/pannellum/src/js/libpannellum.js', array('panellium-js'), $this->version, true);
143 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);
144 wp_enqueue_script('owl-js', plugin_dir_url(__FILE__) . 'js/owl.carousel.js', array('jquery'), $this->version, true);
145 wp_enqueue_script('jquery_cookie', plugin_dir_url(__FILE__) . 'js/jquery.cookie.js', array('jquery'), $this->version, true);
146 wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/wpvr-public.js', array('jquery', 'jquery_cookie'), $this->version, true);
147 wp_localize_script('wpvr', 'wpvr_public', array(
148 'notice_active' => $wpvr_frontend_notice,
149 'notice' => $notice,
150 'is_pro_active' => is_plugin_active('wpvr-pro/wpvr-pro.php'),
151 'is_license_active' => get_option('wpvr_edd_license_status') == 'valid' ? true : false,
152 'dis_on_hover' => get_option('dis_on_hover') === 'true' ? true : false,
153 'mobile_hotspot_tip' => get_option('wpvr_mobile_hotspot_tip') === 'true' ? true : false,
154 ));
155 break;
156 }
157 }
158 }
159 // In auto mode, scripts are enqueued from render functions via wpvr_enqueue_frontend_scripts().
160 }
161
162 /**
163 * Ensure the Video.js Pannellum adapter loads after its runtime dependencies.
164 */
165 public function fix_script_deps() {
166 $scripts = wp_scripts();
167
168 if (
169 isset($scripts->registered['panelliumvid-js'])
170 && !wp_script_is('panelliumvid-js', 'done')
171 ) {
172 $registered = $scripts->registered['panelliumvid-js'];
173 $required_dependencies = array('videojs-js', 'videojsvr-js', 'panellium-js', 'panelliumlib-js');
174
175 if (array_diff($required_dependencies, $registered->deps) || !$scripts->get_data('panelliumvid-js', 'group')) {
176 $src = $registered->src;
177 $ver = $registered->ver;
178 wp_deregister_script('panelliumvid-js');
179 wp_enqueue_script('panelliumvid-js', $src, $required_dependencies, $ver, true);
180 }
181 }
182 }
183
184 /**
185 * Init the edit screen of the plugin post type item
186 *
187 * @since 8.0.0
188 */
189 public function public_init()
190 {
191 add_shortcode($this->plugin_name, array( $this->shortcode , 'wpvr_shortcode'));
192
193 }
194
195 }
196
197 if ( ! function_exists( 'wpvr_accessibility_labels' ) ) {
198 function wpvr_accessibility_labels() {
199 return array(
200 'tour' => __( 'Virtual tour', 'wpvr' ),
201 'instructions' => __( 'Use the arrow keys or W, A, S, and D to look around. Use Tab to reach tour controls and hotspots.', 'wpvr' ),
202 'load' => __( 'Load virtual tour', 'wpvr' ),
203 'hotspot' => __( 'Tour hotspot', 'wpvr' ),
204 'scene' => __( 'View scene', 'wpvr' ),
205 'scene_menu' => __( 'Scene menu', 'wpvr' ),
206 'previous_scene' => __( 'Previous scene', 'wpvr' ),
207 'next_scene' => __( 'Next scene', 'wpvr' ),
208 'pan_up' => __( 'Look up', 'wpvr' ),
209 'pan_down' => __( 'Look down', 'wpvr' ),
210 'pan_left' => __( 'Look left', 'wpvr' ),
211 'pan_right' => __( 'Look right', 'wpvr' ),
212 'zoom_in' => __( 'Zoom in', 'wpvr' ),
213 'zoom_out' => __( 'Zoom out', 'wpvr' ),
214 'fullscreen' => __( 'Toggle fullscreen', 'wpvr' ),
215 'home' => __( 'Return to starting scene', 'wpvr' ),
216 'orientation' => __( 'Toggle device orientation', 'wpvr' ),
217 'audio' => __( 'Toggle tour audio', 'wpvr' ),
218 'gallery' => __( 'Toggle scene gallery', 'wpvr' ),
219 'explainer' => __( 'Open tour video', 'wpvr' ),
220 'form' => __( 'Open form', 'wpvr' ),
221 'floor_plan' => __( 'Open floor plan', 'wpvr' ),
222 'floor_plan_point' => __( 'View scene from floor plan', 'wpvr' ),
223 'company_info' => __( 'Company information', 'wpvr' ),
224 'close' => __( 'Close dialog', 'wpvr' ),
225 'dialog' => __( 'Tour dialog', 'wpvr' ),
226 );
227 }
228 }
229
230 if ( ! function_exists( 'wpvr_enqueue_accessibility_script' ) ) {
231 function wpvr_enqueue_accessibility_script() {
232 $base = plugin_dir_url( __FILE__ );
233 $ver = defined( 'WPVR_VERSION' ) ? WPVR_VERSION : '1.0.0';
234
235 wp_enqueue_script(
236 'wpvr-accessibility',
237 $base . 'js/wpvr-accessibility.js',
238 array( 'jquery', 'wpvr' ),
239 $ver,
240 true
241 );
242 wp_localize_script( 'wpvr-accessibility', 'wpvrAccessibility', wpvr_accessibility_labels() );
243 }
244 }
245
246 if ( ! function_exists( 'wpvr_maybe_enqueue_accessibility_script' ) ) {
247 function wpvr_maybe_enqueue_accessibility_script() {
248 if ( wp_script_is( 'wpvr', 'enqueued' ) || wp_script_is( 'panellium-js', 'enqueued' ) ) {
249 wpvr_enqueue_accessibility_script();
250 }
251 }
252 }
253 add_action( 'wp_enqueue_scripts', 'wpvr_maybe_enqueue_accessibility_script', 100 );
254
255 if ( ! function_exists( 'wpvr_enqueue_frontend_scripts' ) ) {
256 function wpvr_enqueue_frontend_scripts( $type = 'scene' ) {
257 $base = plugin_dir_url( __FILE__ );
258 $ver = defined( 'WPVR_VERSION' ) ? WPVR_VERSION : '1.0.0';
259
260 /**
261 * Allow add-ons to replace or extend frontend dependencies before the
262 * free handles are registered. WP VR Pro uses this for page builders
263 * that render their content before wp_head(), including Breakdance.
264 */
265 do_action( 'wpvr_enqueue_frontend_scripts', $type );
266
267 if ( ! wp_style_is( 'panellium-css', 'enqueued' ) ) {
268 $fontawesome_disable = get_option( 'wpvr_fontawesome_disable' );
269 if ( $fontawesome_disable != 'true' ) {
270 wp_enqueue_style( 'wpvrfontawesome', $base . 'css/fontawesome/css/all.css', array(), $ver, 'all' );
271 wp_enqueue_style(
272 'wpvr-icons-fix',
273 $base . 'css/fontawesome/css/icons-fix.css',
274 array( 'wpvrfontawesome' ),
275 $ver
276 );
277 }
278 wp_enqueue_style( 'panellium-css', $base . 'lib/pannellum/src/css/pannellum.css', array(), $ver );
279 wp_enqueue_style( 'owl-css', $base . 'css/owl.carousel.css', array(), $ver, 'all' );
280 wp_enqueue_style( 'wpvr', $base . 'css/wpvr-public.css', array(), $ver, 'all' );
281 }
282
283 if ( $type === 'video' && ! wp_style_is( 'videojs-vr-css', 'enqueued' ) ) {
284 wp_enqueue_style( 'videojs-css', $base . 'lib/pannellum/src/css/video-js.css', array(), $ver );
285 wp_enqueue_style( 'videojs-vr-css', $base . 'lib/videojs-vr/videojs-vr.css', array(), $ver );
286 }
287
288 wp_enqueue_script( 'panellium-js', $base . 'lib/pannellum/src/js/pannellum.js', array(), $ver, true );
289 wp_enqueue_script( 'panelliumlib-js', $base . 'lib/pannellum/src/js/libpannellum.js', array('panellium-js'), $ver, true );
290 wp_enqueue_script( 'owl-js', $base . 'js/owl.carousel.js', array('jquery'), $ver, true );
291 wp_enqueue_script( 'jquery_cookie', $base . 'js/jquery.cookie.js', array('jquery'), $ver, true );
292 wp_enqueue_script( 'wpvr', $base . 'js/wpvr-public.js', array('jquery', 'jquery_cookie'), $ver, true );
293
294 if ( $type === 'video' ) {
295 wp_enqueue_script( 'videojs-js', $base . 'js/video.js', array(), $ver, true );
296 wp_enqueue_script( 'videojsvr-js', $base . 'lib/videojs-vr/videojs-vr.js', array('videojs-js'), $ver, true );
297 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 );
298 }
299
300 wp_localize_script( 'wpvr', 'wpvr_public', array(
301 'notice_active' => get_option('wpvr_frontend_notice'),
302 'notice' => get_option('wpvr_frontend_notice') ? sanitize_text_field( get_option('wpvr_frontend_notice_area') ) : '',
303 'is_pro_active' => function_exists('is_plugin_active') ? is_plugin_active('wpvr-pro/wpvr-pro.php') : false,
304 'is_license_active' => get_option('wpvr_edd_license_status') == 'valid',
305 'dis_on_hover' => get_option('dis_on_hover') === 'true',
306 'mobile_hotspot_tip' => get_option('wpvr_mobile_hotspot_tip') === 'true',
307 ) );
308
309 wpvr_enqueue_accessibility_script();
310 }
311 }
312