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

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

877 lines 35.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @link http://rextheme.com/
7 * @since 8.0.0
8 *
9 * @package Wpvr
10 * @subpackage Wpvr/admin
11 */
12
13 /**
14 * The admin-specific functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the admin-specific stylesheet and JavaScript.
18 *
19 * @package Wpvr
20 * @subpackage Wpvr/admin
21 * @author Rextheme <[email protected]>
22 */
23 class Wpvr_Admin {
24
25 /**
26 * The ID of this plugin.
27 *
28 * @since 8.0.0
29 * @access private
30 * @var string $plugin_name The ID of this plugin.
31 */
32 private $plugin_name;
33
34 /**
35 * The version of this plugin.
36 *
37 * @since 8.0.0
38 * @access private
39 * @var string $version The current version of this plugin.
40 */
41 private $version;
42
43 /**
44 * The post type of this plugin.
45 *
46 * @since 8.0.0
47 */
48 private $post_type;
49
50 /**
51 * Instance of WPVR_Admin_Page class
52 *
53 * @var object
54 * @since 8.0.0
55 */
56 private $plugin_admin_page;
57
58 /**
59 * Instance of WPVR_Setup_Meta_Box class
60 *
61 * @var object
62 * @since 8.0.0
63 */
64 private $setup_metabox;
65
66 /**
67 * Instacne of WPVR_Tour_Preview class
68 *
69 * @var object
70 * @since 8.0.0
71 */
72 private $preview_metabox;
73
74 /**
75 * Instance of Wpvr_Ajax class
76 *
77 * @var object
78 * @since 8.0.0
79 */
80 private $plugin_admin_ajax;
81
82 /**
83 * Instance of WPVR_Post_Type class
84 *
85 * @var object
86 * @since 8.0.0
87 */
88 private $wpvr_post_type;
89
90 /**
91 * Instacne of WPVR_Tour_Preview class
92 *
93 * @var object
94 * @since 8.5.24
95 */
96 private $checklist_metabox;
97
98
99 /**
100 * Initialize the class and set its properties.
101 *
102 * @since 8.0.0
103 * @param string $plugin_name The name of this plugin.
104 * @param string $version The version of this plugin.
105 * @param string $post_type Post type of this plugin
106 */
107 public function __construct($plugin_name, $version, $post_type) {
108
109 $this->plugin_name = $plugin_name;
110 $this->version = $version;
111 $this->post_type = $post_type;
112
113 $this->wpvr_post_type = new WPVR_Post_Type($this->plugin_name, $this->version, $this->post_type);
114 $this->plugin_admin_page = WPVR_Admin_Page::getInstance();
115
116 add_action('admin_init', array($this, 'set_custom_meta_box'));
117
118 // // Add the import button to the All Tours page
119 add_action('admin_footer', array($this, 'add_import_button'));
120 add_action('admin_footer', array($this, 'enqueue_deactivation_scripts'), 99);
121 add_filter('post_states_html', array($this, 'add_imported_tour_badge'), 10, 3);
122 add_action('post_updated', array($this, 'remove_imported_tour_badge'), 10, 2);
123
124 $this->plugin_admin_ajax = new Wpvr_Ajax();
125 }
126
127
128 /**
129 * Add an Imported badge to imported tours in the admin list.
130 *
131 * @param string $post_states_html Post states markup.
132 * @param array $post_states Post states.
133 * @param WP_Post $post Current post.
134 *
135 * @return string
136 */
137 public function add_imported_tour_badge($post_states_html, $post_states, $post)
138 {
139 if ('wpvr_item' !== $post->post_type || 'yes' !== get_post_meta($post->ID, '_wpvr_imported_tour', true)) {
140 return $post_states_html;
141 }
142
143 $imported_at = (int) get_post_meta($post->ID, '_wpvr_imported_at', true);
144 if (!$imported_at) {
145 $imported_at = (int) get_post_time('U', true, $post);
146 }
147
148 if (time() >= $imported_at + (7 * DAY_IN_SECONDS)) {
149 return $post_states_html;
150 }
151
152 return '<span class="wpvr-imported-tour-badge">' . esc_html__('Imported', 'wpvr') . '</span>' . $post_states_html;
153 }
154
155 /**
156 * Remove the Imported badge after an imported tour is updated.
157 *
158 * @param int $post_id Post ID.
159 * @param WP_Post $post Updated post.
160 *
161 * @return void
162 */
163 public function remove_imported_tour_badge($post_id, $post)
164 {
165 if ('wpvr_item' !== $post->post_type) {
166 return;
167 }
168
169 delete_post_meta($post_id, '_wpvr_imported_tour');
170 delete_post_meta($post_id, '_wpvr_imported_at');
171 }
172
173 /**
174 * Register the stylesheets for the admin area.
175 *
176 * @since 8.0.0
177 */
178 public function enqueue_styles() {
179
180 /**
181 * This function is provided for demonstration purposes only.
182 *
183 * An instance of this class should be passed to the run() function
184 * defined in Wpvr_Loader as all of the hooks are defined
185 * in that particular class.
186 *
187 * The Wpvr_Loader will then create the relationship
188 * between the defined hooks and the functions defined in this
189 * class.
190 */
191 $screen = get_current_screen();
192
193
194 if ($screen->id == "toplevel_page_wpvr" || $screen->id == "wp-vr_page_wpvr-setting") {
195 wp_enqueue_style('materialize-css', plugin_dir_url(__FILE__) . 'css/materialize.min.css', array(), $this->version, 'all');
196 wp_enqueue_style('materialize-icons', plugin_dir_url(__FILE__) . 'lib/materializeicon.css', array(), $this->version, 'all');
197 wp_enqueue_style('owl-css', plugin_dir_url(__FILE__) . 'css/owl.carousel.css', array(), $this->version, 'all');
198 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin.css', array(), $this->version, 'all');
199 wp_enqueue_style('wpvr-rtl', plugin_dir_url(__FILE__) . 'css/wpvr-admin-rtl.css', array(), $this->version, 'all');
200 }
201
202 if ($screen->id == "edit-wpvr_item") {
203 $listing_style_path = plugin_dir_path(__FILE__) . 'css/wpvr-admin-post-type.css';
204 $listing_style_version = file_exists($listing_style_path) ? filemtime($listing_style_path) : $this->version;
205 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin-post-type.css', array(), $listing_style_version, 'all');
206 }
207
208 if ($screen->id == "wpvr_item") {
209 wp_enqueue_style($this->plugin_name . 'fontawesome', plugin_dir_url(__FILE__) . 'lib/fontawesome/css/all.css', array(), $this->version, 'all');
210 wp_enqueue_style('icon-picker-css', plugin_dir_url(__FILE__) . 'css/jquery.fonticonpicker.min.css', array(), $this->version, 'all');
211 wp_enqueue_style('icon-picker-css-theme', plugin_dir_url(__FILE__) . 'css/jquery.fonticonpicker.grey.min.css', array(), $this->version, 'all');
212 wp_enqueue_style('owl-css', plugin_dir_url(__FILE__) . 'css/owl.carousel.css', array(), $this->version, 'all');
213 wp_enqueue_style('panellium-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/pannellum.css', array(), true);
214 wp_enqueue_style('videojs-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/video-js.css', array(), true);
215 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin.css', array(), $this->version, 'all');
216 wp_enqueue_style('wpvr-inter-font', plugin_dir_url(__FILE__) . '../public/css/inter.css', array(), filemtime(plugin_dir_path(__FILE__) . '../public/css/inter.css'));
217 wp_enqueue_style('wpvr-stickers', plugin_dir_url(__FILE__) . '../public/css/wpvr-stickers.css', array('panellium-css', 'wpvr-inter-font'), filemtime(plugin_dir_path(__FILE__) . '../public/css/wpvr-stickers.css'));
218 wp_enqueue_style('wpvr-sticker-fields', plugin_dir_url(__FILE__) . 'css/wpvr-sticker-fields.css', array($this->plugin_name), filemtime(plugin_dir_path(__FILE__) . 'css/wpvr-sticker-fields.css'));
219 wp_enqueue_style('wpvr-image-resize-warning', plugin_dir_url(__FILE__) . 'css/wpvr-image-resize-warning.css', array(), filemtime(plugin_dir_path(__FILE__) . 'css/wpvr-image-resize-warning.css'), 'all');
220 wp_enqueue_style('wpvr-rtl', plugin_dir_url(__FILE__) . 'css/wpvr-admin-rtl.css', array(), $this->version, 'all');
221 wp_enqueue_style('summernote', plugin_dir_url(__FILE__) . 'lib/summernote/summernote-lite.min.css', array(), $this->version, 'all');
222
223 if (isset($_REQUEST['wpvr-guide-tour']) && $_REQUEST['wpvr-guide-tour'] == 1) {
224 wp_enqueue_style($this->plugin_name . '-shepherd-css', plugin_dir_url(__FILE__) . 'lib/shepherd/css/shepherd-theme-arrows-plain-buttons.css', false, $this->version);
225 wp_enqueue_style($this->plugin_name . '-tour-css', plugin_dir_url(__FILE__) . 'lib/shepherd/css/wpvr-tour-guide.min.css', false, $this->version);
226 }
227 }
228
229 if ($screen->id == "wp-vr_page_wpvr-setup-wizard") {
230 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin2.css', array(), $this->version, 'all');
231 wp_enqueue_style('wpvr-admin2-rtl', plugin_dir_url(__FILE__) . 'css/wpvr-admin2-rtl.css', array(), $this->version, 'all');
232 }
233
234 if ($screen->id == "dashboard_page_rex-wpvr-setup-wizard") {
235 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/style.css', array(), $this->version, 'all');
236 }
237 }
238
239
240 /**
241 * Register the JavaScript for the admin area.
242 *
243 * @since 8.0.0
244 */
245 public function enqueue_scripts() {
246
247 /**
248 * This function is provided for demonstration purposes only.
249 *
250 * An instance of this class should be passed to the run() function
251 * defined in Wpvr_Loader as all of the hooks are defined
252 * in that particular class.
253 *
254 * The Wpvr_Loader will then create the relationship
255 * between the defined hooks and the functions defined in this
256 * class.
257 */
258
259 $wpvr_list = array();
260 $wpvr_list[] = array('value' => 0, 'label' => 'None');
261 $args = array(
262 'numberposts' => -1,
263 'post_type' => 'wpvr_item'
264 );
265
266 $wpvr_posts = get_posts($args);
267 foreach ($wpvr_posts as $wpvr_post) {
268 $title = $wpvr_post->ID . ' : ' . $wpvr_post->post_title;
269 $wpvr_list[] = array( 'value'=>$wpvr_post->ID,'label'=> $title);
270 }
271
272 wp_enqueue_script('wp-api');
273 wp_enqueue_media();
274
275 $asset_url = apply_filters('change_asset_url', plugin_dir_url(__FILE__));
276 $admin_script_path = plugin_dir_path(__FILE__) . 'js/wpvr-admin.js';
277
278 if (defined('WPVR_PRO_PLUGIN_DIR_URL') && defined('WPVR_PRO_PLUGIN_DIR_PATH') && $asset_url === WPVR_PRO_PLUGIN_DIR_URL . 'admin/') {
279 $admin_script_path = WPVR_PRO_PLUGIN_DIR_PATH . 'admin/js/wpvr-admin.js';
280 }
281
282 wp_enqueue_script('wp-api');
283 $adscreen = get_current_screen();
284 wp_enqueue_media();
285 if ($adscreen->id == "wpvr_item" || $adscreen->id == "toplevel_page_wpvr" || $adscreen->id == "wp-vr_page_wpvr-setting" || $adscreen->id == "edit-wpvr_item") {
286 wp_enqueue_script('summernote', $asset_url . 'lib/summernote/summernote-lite.min.js', array('jquery'), true);
287 wp_enqueue_script('wpvr-icon-picker', $asset_url . 'lib/jquery.fonticonpicker.min.js', array(), true);
288 wp_enqueue_script('panellium-js', $asset_url . 'lib/pannellum/src/js/pannellum.js', array(), true);
289 wp_enqueue_script('panelliumlib-js', $asset_url . 'lib/pannellum/src/js/libpannellum.js', array(), true);
290 wp_enqueue_script('videojs-js', $asset_url . 'js/video.js', array('jquery'), true);
291 wp_enqueue_script('panelliumvid-js', $asset_url . 'lib/pannellum/src/js/videojs-pannellum-plugin.js', array(), true);
292 wp_enqueue_script('jquery-repeater', $asset_url . 'js/jquery.repeater.min.js', array('jquery'), true);
293 wp_enqueue_script('icon-picker', $asset_url . 'lib/jquery.fonticonpicker.min.js', array(), true);
294 wp_enqueue_script('owl', $asset_url . 'js/owl.carousel.js', array('jquery'), false);
295 wp_enqueue_script('wpvr-image-resize-warning', plugin_dir_url(__FILE__) . 'js/wpvr-image-resize-warning.js', array('jquery'), filemtime(plugin_dir_path(__FILE__) . 'js/wpvr-image-resize-warning.js'), true);
296 wp_enqueue_script('wpvr-stickers', plugin_dir_url(__FILE__) . '../public/js/wpvr-stickers.js', array(), filemtime(plugin_dir_path(__FILE__) . '../public/js/wpvr-stickers.js'), true);
297 wp_enqueue_script($this->plugin_name, $asset_url . 'js/wpvr-admin.js', array('jquery', 'wpvr-image-resize-warning', 'wpvr-stickers'), filemtime($admin_script_path), true);
298 wp_enqueue_script('wpvr-sticker-fields', plugin_dir_url(__FILE__) . 'js/wpvr-sticker-fields.js', array('jquery', $this->plugin_name), filemtime(plugin_dir_path(__FILE__) . 'js/wpvr-sticker-fields.js'), true);
299 wp_localize_script($this->plugin_name, 'wpvr_localize', array(
300 'WriteYourCssHere' => __('Write your css here', 'wpvr'),
301 'VideoTourNotice' => __('Turning On The Video Option Will Erase Your Virtual Tour Data. Are You Sure?', 'wpvr'),
302 'StreetViewNotice' => __('Turning On The StreetView Option Will Erase Your Virtual Tour Data. Are You Sure?', 'wpvr'),
303 'AddingHotspotsOnScene' => __('Adding Hotspots on Scene', 'wpvr'),
304 'WPVR_ASSET_PATH' => WPVR_ASSET_PATH,
305 ));
306 if (isset($_REQUEST['wpvr-guide-tour']) && $_REQUEST['wpvr-guide-tour'] == 1) {
307 wp_enqueue_script($this->plugin_name . '-tether-js', plugin_dir_url(__FILE__) . 'lib/shepherd/tether/tether.js', $this->version, true);
308 wp_enqueue_script($this->plugin_name . '-shepherd-js', plugin_dir_url(__FILE__) . 'lib/shepherd/tether-shepherd/shepherd.js', array($this->plugin_name . '-tether-js'), $this->version, true);
309 wp_enqueue_script($this->plugin_name . '-tour-guide', plugin_dir_url(__FILE__) . 'js/wpvr-tour-guide.js', array('jquery', $this->plugin_name . '-tether-js'), $this->version, true);
310 $tour_guide_translation = new WPVR_Tour_Guide_Translation();
311
312 wp_localize_script($this->plugin_name . '-tour-guide', 'wpvr_tour_guide_obj', array(
313 'Tour_Guide_Translation' => $tour_guide_translation->get_translatable_string(),
314 'step1_bg_image' => plugins_url('admin/icon/first-step-bg.png', WPVR_FILE),
315 'next_button_arrow' => plugins_url('admin/icon/next-button-arrow.png', WPVR_FILE),
316 ));
317 }
318
319 wp_localize_script($this->plugin_name, 'wpvr_obj', array(
320 'ajaxurl' => admin_url('admin-ajax.php'),
321 'ajax_nonce' => wp_create_nonce('wpvr'),
322 'translated_languages' => $this->get_translated_languages(),
323 'site_language' => get_locale(),
324 'successfully_updated' => __('Successfully Updated', 'wpvr'),
325 'importing_text' => __('Importing...', 'wpvr'),
326 'import_text' => __('Import Now', 'wpvr'),
327 'admin_url' => admin_url(),
328 'is_wpvr_pro_active' => apply_filters('is_wpvr_pro_active', false),
329 'is_wpvr_license_valid' => get_option('wpvr_edd_license_status', '') === 'valid',
330 'published_text' => __('Published', 'wpvr'),
331 'dis_on_hover' => get_option('dis_on_hover') === 'true' ? true : false,
332 'mobile_hotspot_tip' => get_option('wpvr_mobile_hotspot_tip') === 'true' ? true : false,
333 'image_resize_warning' => array(
334 'heading' => __('Keep this panorama in High Resolution', 'wpvr'),
335 'scaled_message' => __('By default, a resized version is created while the original image is still available.', 'wpvr'),
336 'disable_handler' => __('Disable WordPress Large Image Handler on WP VR for future uploads', 'wpvr'),
337 'high_resolution_note' => __('*Note: Turn this on to use the high-resolution image.', 'wpvr'),
338 'close' => __('Close', 'wpvr'),
339 'can_manage_settings' => current_user_can('manage_options'),
340 'setting_enabled' => get_option('high_res_image') === 'true',
341 ),
342 ));
343 }
344
345 if ($adscreen->id == "toplevel_page_wpvr" || $adscreen->id == "wp-vr_page_wpvr-setting") {
346 wp_enqueue_script('materialize-js', $asset_url . 'js/materialize.min.js', array('jquery'), $this->version, false);
347 }
348
349 if ($adscreen->id == "wpvr_item") {
350 wp_enqueue_script($this->plugin_name . '-shortcode', plugin_dir_url(__FILE__) . 'js/wpvr-shortcode.js', array('jquery'), $this->version, true);
351 }
352
353 $is_wpvr_screen = false;
354 if ( isset( $adscreen->id ) ) {
355 $is_wpvr_screen = (
356 $adscreen->id === 'wpvr_item' ||
357 $adscreen->id === 'edit-wpvr_item' ||
358 $adscreen->id === 'toplevel_page_wpvr' ||
359 $adscreen->id === 'wp-vr_page_wpvr-setting' ||
360 false !== strpos( $adscreen->id, 'wpvr' ) ||
361 false !== strpos( $adscreen->id, 'wp-vr' ) ||
362 ( isset( $adscreen->post_type ) && 'wpvr_item' === $adscreen->post_type )
363 );
364 }
365
366 if ( $is_wpvr_screen ) {
367 wp_enqueue_script('owl-js', plugin_dir_url(__FILE__) . 'js/owl.carousel.js', array('jquery'), false);
368 wp_enqueue_script('wpvr-global', $asset_url . 'js/wpvr-global.js', array('jquery'), $this->version, false);
369
370 $admin_user = wp_get_current_user();
371 $admin_name = $admin_user->display_name ?? '';
372
373 wp_localize_script('wpvr-global', 'wpvr_global_obj', array(
374 'ajaxurl' => admin_url('admin-ajax.php'),
375 'site_url' => site_url() . '/wp-json/',
376 'ajax_nonce' => wp_create_nonce('wpvr'),
377 'user_information' => $this->get_logged_in_user_information(),
378 'is_wpvr_active' => is_plugin_active('wpvr-pro/wpvr-pro.php'),
379 'admin_name' => $admin_name,
380 'url_info' => array(
381 'admin_url' => admin_url(),
382 'screen' => $adscreen->action,
383 'url' => isset( $_SERVER['PHP_SELF'] ) ? sanitize_text_field( wp_unslash( $_SERVER['PHP_SELF'] ) ) : '',
384 'param' => $_GET,
385 ),
386 'active_tab_url' => admin_url('post-new.php?post_type=wpvr_item&active_tab=scene'),
387 'hotspot_warning_text' => __('Please upload a scene before proceeding to set hotspot!', 'wpvr'),
388 'negative_number_warning_text' =>__('Negative numbers are not allowed!', 'wpvr'),
389 ));
390
391 wp_localize_script('wpvr-global', 'wpvr_id_options', $wpvr_list);
392 }
393 }
394
395 /**
396 * Retrieve the currently logged-in user's email and name.
397 *
398 * @since 8.4.10
399 *
400 * @return array An associative array containing the logged-in user's email and name.
401 */
402 public function get_logged_in_user_information(): array
403 {
404 $admin_user = wp_get_current_user();
405 return array(
406 'email' => !empty( $admin_user->user_email ) ? $admin_user->user_email : '',
407 'name' => !empty( $admin_user->display_name ) ? $admin_user->display_name : '',
408 );
409 }
410
411
412 /**
413 * Set Preview and Setup custom metabox of this plugin
414 *
415 * @since 8.0.0
416 */
417 public function set_custom_meta_box() {
418 $this->setup_metabox = new WPVR_Setup_Meta_Box('setup', __('Setup', 'wpvr'), 'wpvr_item', 'normal', 'high');
419
420 $this->preview_metabox = new WPVR_Tour_Preview($this->post_type . '_builder__box', __('Tour Preview', 'wpvr'), $this->post_type, 'side', 'high');
421
422 $this->checklist_metabox = new WPVR_Tour_Checklist_Meta_Box($this->post_type . '_tour_checklist__box', __('Checklist', 'wpvr'), $this->post_type, 'side', 'high');
423
424 }
425
426
427 /**
428 * Plugin action links
429 *
430 * @param $actions || $links
431 * @return array
432 * @since 8.0.0
433 */
434 public function plugin_action_links_wpvr($actions)
435 {
436 $actions['get_started'] = sprintf(
437 '<a href="%s">%s</a>',
438 esc_url(admin_url('admin.php?page=wpvr')),
439 esc_html__('Get Started', 'wpvr')
440 );
441 $actions['documentation'] = sprintf(
442 '<a href="%s" target="_blank">%s</a>',
443 esc_url('https://rextheme.com/docs-category/wp-vr/'),
444 esc_html__('Documentation', 'wpvr')
445 );
446
447 if (!apply_filters('is_wpvr_pro_active', false)) {
448 $actions['go-pro'] = sprintf(
449 '<a href="%s" target="_blank" style="color: #201cfe; font-weight: bold;">%s</a>',
450 esc_url('https://rextheme.com/wpvr/wpvr-pricing/'),
451 esc_html__('Go Pro', 'wpvr')
452 );
453 }
454
455 return $actions;
456 }
457
458 /**
459 * Rollback execution
460 */
461 public function trigger_rollback()
462 {
463 if (!current_user_can('update_plugins') && !current_user_can('install_plugins')) {
464 return false;
465 }
466 $version = isset($_GET['wpvr_version']) ? sanitize_text_field(wp_unslash($_GET['wpvr_version'])) : '';
467 if ($version) {
468 check_admin_referer('wpvr_rollback', 'wpvr_rollback');
469 $plugin_slug = 'wpvr';
470 $rollback = new WPVR_Rollback(
471 [
472 'version' => $version,
473 'plugin_name' => 'wpvr',
474 'plugin_slug' => $plugin_slug,
475 'package_url' => sprintf('https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $version),
476 ]
477 );
478
479 $rollback->run();
480 }
481 }
482
483 /**
484 * Floor plan image Display
485 * Display Pro feature demo in free user
486 * @return void
487 */
488
489 public function floor_plan_image_show_for_free_user() {
490 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
491
492 ?>
493 <div class="rex-pano-tab floor-plan" id="floorPlan">
494
495 <img loading="lazy" src="<?php echo esc_url( WPVR_PLUGIN_DIR_URL . 'images/floor-plan-demo.png' ); ?>" alt="icon" />
496 </div>
497 <?php
498 }
499 }
500
501 /**
502 * Background Tour image Display
503 * Display Pro feature demo in free user
504 * @return void
505 */
506 public function background_tour_image_show_for_free_user() {
507 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
508
509 ?>
510 <div class="rex-pano-tab background-tour" id="backgroundTour">
511
512 <!-- <img src="--><?php //= WPVR_PLUGIN_DIR_URL . 'images/floor-plan-demo.png'
513 ?><!--" alt="icon" />-->
514 </div>
515 <?php
516 }
517 }
518 /**
519 * Street View image Display
520 * Display Pro feature demo in free user
521 * @return void
522 */
523
524 public function street_view_image_show_for_free_user() {
525 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
526
527 ?>
528 <div class="rex-pano-tab streetview" id="streetview">
529 <!-- <img src="--><?php //= WPVR_PLUGIN_DIR_URL . 'images/floor-plan-demo.png'
530 ?><!--" alt="icon" />-->
531 </div>
532 <?php
533 }
534 }
535
536 public function scene_pro_image_show_for_free_user($pano_scene) {
537 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
538
539 ?>
540 <img loading="lazy" src="<?php echo esc_url( WPVR_PLUGIN_DIR_URL . 'images/scene-pro-feature.png' ); ?>" alt="icon" />
541 <?php
542 }
543 }
544
545
546 public function empty_scene_pro_image_show_for_free_user() {
547 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
548 echo '<img loading="lazy" src="' . esc_url(WPVR_PLUGIN_DIR_URL . 'images/scene-pro-feature.png') . '" alt="WPVR Pro Feature" />';
549 }
550 }
551
552 public function show_review_request_markups() {
553 $show_review_request = get_option('wpvr_feed_review_request');
554 if (empty($show_review_request)) {
555 $data = array(
556 'show' => true,
557 'time' => '',
558 'frequency' => 'immediate',
559 );
560 update_option('wpvr_feed_review_request', $data);
561 }
562 }
563
564 public function wpvr_trigger_based_review_helper() {
565 $show_review_request = get_option('wpvr_feed_review_request');
566 $number_of_published_tours = $this->wpvr_get_total_published_tours();
567 if (!empty($show_review_request) && isset($show_review_request['show']) && $show_review_request['show']) {
568
569 if (isset($show_review_request['frequency']) && $number_of_published_tours > 1) {
570 if ($show_review_request['frequency'] == 'immediate') {
571 add_action('admin_notices', array($this, 'wpvr_generate_review_request_section'));
572 } elseif ($show_review_request['frequency'] == 'one_week') {
573 $last_shown_date = $show_review_request['time'];
574 $current_date = time();
575 $current_date = new DateTime(gmdate('Y-m-d', $current_date));
576 $last_shown_date = new DateTime(gmdate('Y-m-d', $last_shown_date));
577 $date_diff = $last_shown_date->diff($current_date);
578
579 if ($date_diff->d > 7) {
580 add_action('admin_notices', array($this, 'wpvr_generate_review_request_section'));
581 }
582 }
583 }
584 }
585 }
586
587 public function wpvr_generate_review_request_section() {
588 $screen = get_current_screen();
589
590 $promotional_notice_pages = [
591 'dashboard',
592 'plugins',
593 'wpvr_item',
594 'edit-wpvr_item',
595 'toplevel_page_wpvr',
596 'wp-vr_page_wpvr-setup-wizard'
597 ];
598
599 // Only proceed if the current screen ID matches the allowed pages.
600 if (!in_array($screen->id, $promotional_notice_pages)) {
601 return;
602 }
603
604 require_once plugin_dir_path(__FILE__) . 'partials/wpvr-review-request-body-content.php';
605 }
606
607 /**
608 * Get translated languages
609 *
610 * @return array
611 * @since 8.5.21
612 */
613 public function get_translated_languages(){
614 $language_mapping = [
615 'ar' => [ // Arabic
616 'Publish' => 'نشر', // nashr
617 'Update' => 'تحديث' // tahdith
618 ],
619 'pt_PT' => [ // Portuguese (Portugal)
620 'Publish' => 'Publicar',
621 'Update' => 'Atualizar'
622 ],
623 'es_ES' => [ // Spanish (Spain)
624 'Publish' => 'Publicar',
625 'Update' => 'Actualizar'
626 ],
627 'he_IL' => [ // Hebrew (Israel)
628 'Publish' => 'לפרסם', // lefarsem
629 'Update' => 'לעדכן' // le'adken
630 ],
631 'af' => [ // Afrikaans
632 'Publish' => 'Publiseer',
633 'Update' => 'Opdateer'
634 ],
635 'cs_CZ' => [ // Czech (Czech Republic)
636 'Publish' => 'Publikovat',
637 'Update' => 'Aktualizovat'
638 ],
639 'da_DK' => [ // Danish (Denmark)
640 'Publish' => 'Udgiv',
641 'Update' => 'Opdater'
642 ],
643 'de_DE' => [ // German (Germany)
644 'Publish' => 'Veröffentlichen',
645 'Update' => 'Aktualisieren'
646 ],
647 'fi' => [ // Finnish
648 'Publish' => 'Julkaise',
649 'Update' => 'Päivitä'
650 ],
651 'hr' => [ // Croatian
652 'Publish' => 'Objavi',
653 'Update' => 'Ažuriraj'
654 ],
655 'it_IT' => [ // Italian (Italy)
656 'Publish' => 'Pubblica',
657 'Update' => 'Aggiorna'
658 ],
659 'ja' => [ // Japanese
660 'Publish' => '�
661 �開',
662 'Update' => '更新'
663 ],
664 'nl_NL' => [ // Dutch (Netherlands)
665 'Publish' => 'Publiceren',
666 'Update' => 'Updaten'
667 ],
668 'pl_PL' => [ // Polish (Poland)
669 'Publish' => 'Opublikuj',
670 'Update' => 'Aktualizuj'
671 ],
672 'ru_RU' => [ // Russian (Russia)
673 'Publish' => 'Опубликовать',
674 'Update' => 'Обновить'
675 ],
676 'sv_SE' => [ // Swedish (Sweden)
677 'Publish' => 'Publicera',
678 'Update' => 'Uppdatera'
679 ],
680 'fr_FR' => [ // French (France)
681 'Publish' => 'Publier',
682 'Update' => 'Mettre à jour'
683 ],
684 'fr_CA' => [ // French (Canada)
685 'Publish' => 'Publier',
686 'Update' => 'Mettre à jour',
687 ],
688 'fr_BE' => [ // French (Belgium)
689 'Publish' => 'Publier',
690 'Update' => 'Mettre à jour',
691 ],
692 'fr_CH' => [ // Switzerland
693 'Publish' => 'Publier',
694 'Update' => 'Mettre à jour',
695 ],
696 'fr_LU' => [ // Luxembourg
697 'Publish' => 'Publier',
698 'Update' => 'Mettre à jour',
699 ],
700 'fr_MC' => [ // Monaco
701 'Publish' => 'Publier',
702 'Update' => 'Mettre à jour',
703 ],
704 'fr_CM' => [ // Cameroon
705 'Publish' => 'Publier',
706 'Update' => 'Mettre à jour',
707 ],
708 'fr_DZ' => [ // Algeria
709 'Publish' => 'Publier',
710 'Update' => 'Mettre à jour',
711 ],
712 'fr_MA' => [ // Morocco
713 'Publish' => 'Publier',
714 'Update' => 'Mettre à jour',
715 ],
716 'fr_TN' => [ // Tunisia
717 'Publish' => 'Publier',
718 'Update' => 'Mettre à jour',
719 ],
720 'fr_SN' => [ // Senegal
721 'Publish' => 'Publier',
722 'Update' => 'Mettre à jour',
723 ],
724 'fr_HT' => [ // Haiti
725 'Publish' => 'Publier',
726 'Update' => 'Mettre à jour',
727 ],
728 'fr_RW' => [ // Rwanda
729 'Publish' => 'Publier',
730 'Update' => 'Mettre à jour',
731 ],
732 'fr_CD' => [ // DR Congo
733 'Publish' => 'Publier',
734 'Update' => 'Mettre à jour',
735 ],
736 'fr_CI' => [ // Côte d’Ivoire
737 'Publish' => 'Publier',
738 'Update' => 'Mettre à jour',
739 ],
740 ];
741
742 return $language_mapping;
743 }
744
745
746 /**
747 * Add import button to the WPVR All Tours page
748 *
749 * @since 8.5.22
750 */
751 public function add_import_button() {
752 $screen = get_current_screen();
753 $status = get_option('wpvr_edd_license_status');
754 $is_pro_available = apply_filters('is_wpvr_pro_active', false) && $status === 'valid';
755
756 // Only add button on the WPVR Tours admin page
757 if ($screen && property_exists($screen, 'id') && ($screen->id === 'edit-wpvr_item')) {
758 ?>
759 <script type="text/javascript">
760 jQuery(document).ready(function($) {
761
762 // Check if user has WPVR Pro
763 var isProUser = <?php echo wp_json_encode($is_pro_available); ?>;
764
765 // Add the Import WPVR Tour button
766 var importButton = $('<a href="#" class="page-title-action wpvr-import-button"><?php echo esc_js( esc_html__( 'Import Tour', 'wpvr' ) ); ?></a>');
767 $('.wrap .page-title-action').after(importButton);
768
769 // If Free Version, add 'Pro' label
770 if (!isProUser) {
771 importButton
772 .addClass('wpvr-import-button--locked')
773 .attr({
774 'aria-disabled': 'true',
775 'aria-haspopup': 'dialog'
776 })
777 .append("<span class='is-pro' aria-hidden='true'>Pro</span>");
778 }
779
780 // If button wasn't added, try alternative placement
781 if ($('.wpvr-import-button').length === 0) {
782 $('.wrap h1.wp-heading-inline').after(importButton);
783 }
784
785 // Add the WPVR Import Form (hidden by default)
786 var importForm = `
787 <div id="wpvr-import-template-area">
788 <div id="wpvr-import-template-title">Choose a .zip archive of a WPVR tour and add it to your website.</div>
789 <form id="wpvr-import-template-form" method="post" action="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" enctype="multipart/form-data">
790 <input type="hidden" name="action" value="wpvr_import_tour">
791 <fieldset id="wpvr-import-template-form-inputs">
792 <input type="file" name="wpvr_import_tour_file" accept=".zip" required>
793 <input id="wpvr-import-template-action" type="button" class="button button-primary" value="${wpvr_obj?.import_text}">
794 </fieldset>
795 </form>
796 </div>
797 `;
798
799 // Append the form after the Import button
800 $('.wpvr-import-button').after(importForm);
801
802 // Toggle form visibility on button click
803 $(document).on('click', '.wpvr-import-button', function(e) {
804 e.preventDefault();
805 if (!isProUser) {
806 // Open CRO Modal (Pro Upgrade)
807 $("#wpvr_premium_feature_popup").show();
808 } else {
809 // Open WPVR Import Form
810 $('#wpvr-import-template-area').toggle();
811 }
812 });
813
814 // Close CRO Modal
815 $(document).on("click", "#wpvr_premium_feature_close", function () {
816 $("#wpvr_premium_feature_popup").hide();
817 });
818
819 var $importButton = $('#wpvr-import-template-action');
820 var $fileInput = $('input[name="wpvr_import_tour_file"]');
821
822 // Initially disable the import button
823 $importButton.prop('disabled', true);
824
825 // Enable button when a file is selected
826 $fileInput.on('change', function() {
827 if ($(this).val()) {
828 $importButton.prop('disabled', false);
829 } else {
830 $importButton.prop('disabled', true);
831 }
832 });
833 });
834 </script>
835 <?php
836 }
837 }
838
839 /**
840 * Enqueue deactivation sub-reason JS on plugins.php only, after SDK modal (priority 99).
841 *
842 * @return void
843 */
844 public function enqueue_deactivation_scripts() {
845 global $pagenow;
846 if ( 'plugins.php' !== $pagenow ) {
847 return;
848 }
849 wp_enqueue_script(
850 'wpvr-deactivation',
851 plugin_dir_url( __FILE__ ) . 'js/wpvr-deactivation.js',
852 array( 'jquery' ),
853 $this->version,
854 true
855 );
856 }
857
858 /**
859 * Get total published tours
860 *
861 * @return int
862 * @since 8.5.43
863 */
864 public function wpvr_get_total_published_tours(){
865 $args = array(
866 'post_type' => 'wpvr_item',
867 'post_status' => 'publish',
868 'posts_per_page' => -1,
869 'fields' => 'ids',
870 );
871
872 $query = new WP_Query( $args );
873 return $query->found_posts;
874 }
875
876 }
877