PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.69
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.69
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 8.5.4 All 221 releases
wpvr / admin / class-wpvr-admin.php

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

782 lines 30.1 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 <support@rextheme.com>
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
122 $this->plugin_admin_ajax = new Wpvr_Ajax();
123 }
124
125 /**
126 * Register the stylesheets for the admin area.
127 *
128 * @since 8.0.0
129 */
130 public function enqueue_styles() {
131
132 /**
133 * This function is provided for demonstration purposes only.
134 *
135 * An instance of this class should be passed to the run() function
136 * defined in Wpvr_Loader as all of the hooks are defined
137 * in that particular class.
138 *
139 * The Wpvr_Loader will then create the relationship
140 * between the defined hooks and the functions defined in this
141 * class.
142 */
143 $screen = get_current_screen();
144
145
146 if ($screen->id == "toplevel_page_wpvr" || $screen->id == "wp-vr_page_wpvr-setting") {
147 wp_enqueue_style('materialize-css', plugin_dir_url(__FILE__) . 'css/materialize.min.css', array(), $this->version, 'all');
148 wp_enqueue_style('materialize-icons', plugin_dir_url(__FILE__) . 'lib/materializeicon.css', array(), $this->version, 'all');
149 wp_enqueue_style('owl-css', plugin_dir_url(__FILE__) . 'css/owl.carousel.css', array(), $this->version, 'all');
150 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin.css', array(), $this->version, 'all');
151 wp_enqueue_style('wpvr-rtl', plugin_dir_url(__FILE__) . 'css/wpvr-admin-rtl.css', array(), $this->version, 'all');
152 }
153
154 if ($screen->id == "edit-wpvr_item") {
155 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin-post-type.css', array(), $this->version, 'all');
156 }
157
158 if ($screen->id == "wpvr_item") {
159 wp_enqueue_style($this->plugin_name . 'fontawesome', plugin_dir_url(__FILE__) . 'lib/fontawesome/css/all.css', array(), $this->version, 'all');
160 wp_enqueue_style('icon-picker-css', plugin_dir_url(__FILE__) . 'css/jquery.fonticonpicker.min.css', array(), $this->version, 'all');
161 wp_enqueue_style('icon-picker-css-theme', plugin_dir_url(__FILE__) . 'css/jquery.fonticonpicker.grey.min.css', array(), $this->version, 'all');
162 wp_enqueue_style('owl-css', plugin_dir_url(__FILE__) . 'css/owl.carousel.css', array(), $this->version, 'all');
163 wp_enqueue_style('panellium-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/pannellum.css', array(), true);
164 wp_enqueue_style('videojs-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/video-js.css', array(), true);
165 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin.css', array(), $this->version, 'all');
166 wp_enqueue_style('wpvr-rtl', plugin_dir_url(__FILE__) . 'css/wpvr-admin-rtl.css', array(), $this->version, 'all');
167 wp_enqueue_style('summernote', plugin_dir_url(__FILE__) . 'lib/summernote/summernote-lite.min.css', array(), $this->version, 'all');
168
169 if (isset($_REQUEST['wpvr-guide-tour']) && $_REQUEST['wpvr-guide-tour'] == 1) {
170 wp_enqueue_style($this->plugin_name . '-shepherd-css', plugin_dir_url(__FILE__) . 'lib/shepherd/css/shepherd-theme-arrows-plain-buttons.css', false, $this->version);
171 wp_enqueue_style($this->plugin_name . '-tour-css', plugin_dir_url(__FILE__) . 'lib/shepherd/css/wpvr-tour-guide.min.css', false, $this->version);
172 }
173 }
174
175 if ($screen->id == "wp-vr_page_wpvr-setup-wizard") {
176 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin2.css', array(), $this->version, 'all');
177 wp_enqueue_style('wpvr-admin2-rtl', plugin_dir_url(__FILE__) . 'css/wpvr-admin2-rtl.css', array(), $this->version, 'all');
178 }
179
180 if ($screen->id == "dashboard_page_rex-wpvr-setup-wizard") {
181 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/style.css', array(), $this->version, 'all');
182 }
183 }
184
185
186 /**
187 * Register the JavaScript for the admin area.
188 *
189 * @since 8.0.0
190 */
191 public function enqueue_scripts() {
192
193 /**
194 * This function is provided for demonstration purposes only.
195 *
196 * An instance of this class should be passed to the run() function
197 * defined in Wpvr_Loader as all of the hooks are defined
198 * in that particular class.
199 *
200 * The Wpvr_Loader will then create the relationship
201 * between the defined hooks and the functions defined in this
202 * class.
203 */
204
205 $wpvr_list = array();
206 $wpvr_list[] = array('value' => 0, 'label' => 'None');
207 $args = array(
208 'numberposts' => -1,
209 'post_type' => 'wpvr_item'
210 );
211
212 $wpvr_posts = get_posts($args);
213 foreach ($wpvr_posts as $wpvr_post) {
214 $title = $wpvr_post->ID . ' : ' . $wpvr_post->post_title;
215 $wpvr_list[] = array( 'value'=>$wpvr_post->ID,'label'=> $title);
216 }
217
218 wp_enqueue_script('wp-api');
219 wp_enqueue_media();
220
221 $asset_url = apply_filters('change_asset_url', plugin_dir_url(__FILE__));
222
223 wp_enqueue_script('wp-api');
224 $adscreen = get_current_screen();
225 wp_enqueue_media();
226 if ($adscreen->id == "wpvr_item" || $adscreen->id == "toplevel_page_wpvr" || $adscreen->id == "wp-vr_page_wpvr-setting" || $adscreen->id == "edit-wpvr_item") {
227 wp_enqueue_script('summernote', $asset_url . 'lib/summernote/summernote-lite.min.js', array('jquery'), true);
228 wp_enqueue_script('wpvr-icon-picker', $asset_url . 'lib/jquery.fonticonpicker.min.js', array(), true);
229 wp_enqueue_script('panellium-js', $asset_url . 'lib/pannellum/src/js/pannellum.js', array(), true);
230 wp_enqueue_script('panelliumlib-js', $asset_url . 'lib/pannellum/src/js/libpannellum.js', array(), true);
231 wp_enqueue_script('videojs-js', $asset_url . 'js/video.js', array('jquery'), true);
232 wp_enqueue_script('panelliumvid-js', $asset_url . 'lib/pannellum/src/js/videojs-pannellum-plugin.js', array(), true);
233 wp_enqueue_script('jquery-repeater', $asset_url . 'js/jquery.repeater.min.js', array('jquery'), true);
234 wp_enqueue_script('icon-picker', $asset_url . 'lib/jquery.fonticonpicker.min.js', array(), true);
235 wp_enqueue_script('owl', $asset_url . 'js/owl.carousel.js', array('jquery'), false);
236 wp_enqueue_script($this->plugin_name, $asset_url . 'js/wpvr-admin.js', array('jquery'), $this->version, true);
237 wp_localize_script($this->plugin_name, 'wpvr_localize', array(
238 'WriteYourCssHere' => __('Write your css here', 'wpvr'),
239 'VideoTourNotice' => __('Turning On The Video Option Will Erase Your Virtual Tour Data. Are You Sure?', 'wpvr'),
240 'StreetViewNotice' => __('Turning On The StreetView Option Will Erase Your Virtual Tour Data. Are You Sure?', 'wpvr'),
241 'AddingHotspotsOnScene' => __('Adding Hotspots on Scene', 'wpvr'),
242 'WPVR_ASSET_PATH' => WPVR_ASSET_PATH,
243 ));
244 if (isset($_REQUEST['wpvr-guide-tour']) && $_REQUEST['wpvr-guide-tour'] == 1) {
245 wp_enqueue_script($this->plugin_name . '-tether-js', plugin_dir_url(__FILE__) . 'lib/shepherd/tether/tether.js', $this->version, true);
246 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);
247 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);
248 $tour_guide_translation = new Tour_Guide_Translation();
249
250 wp_localize_script($this->plugin_name . '-tour-guide', 'wpvr_tour_guide_obj', array(
251 'Tour_Guide_Translation' => $tour_guide_translation->get_translatable_string(),
252 'step1_bg_image' => plugins_url('admin/icon/first-step-bg.png', WPVR_FILE),
253 'next_button_arrow' => plugins_url('admin/icon/next-button-arrow.png', WPVR_FILE),
254 ));
255 }
256
257 wp_localize_script($this->plugin_name, 'wpvr_obj', array(
258 'ajaxurl' => admin_url('admin-ajax.php'),
259 'ajax_nonce' => wp_create_nonce('wpvr'),
260 'translated_languages' => $this->get_translated_languages(),
261 'site_language' => get_locale(),
262 'successfully_updated' => __('Successfully Updated', 'wpvr'),
263 'importing_text' => __('Importing...', 'wpvr'),
264 'import_text' => __('Import Now', 'wpvr'),
265 'admin_url' => admin_url(),
266 'is_wpvr_pro_active' => apply_filters('is_wpvr_pro_active', false),
267 'is_wpvr_license_valid' => get_option('wpvr_edd_license_status', '') === 'valid',
268 'published_text' => __('Published', 'wpvr'),
269 ));
270 }
271
272 if ($adscreen->id == "toplevel_page_wpvr" || $adscreen->id == "wp-vr_page_wpvr-setting") {
273 wp_enqueue_script('materialize-js', $asset_url . 'js/materialize.min.js', array('jquery'), $this->version, false);
274 }
275
276 if ($adscreen->id == "wpvr_item") {
277 wp_enqueue_script($this->plugin_name . '-shortcode', plugin_dir_url(__FILE__) . 'js/wpvr-shortcode.js', array('jquery'), $this->version, true);
278 }
279
280 wp_enqueue_script('owl-js', plugin_dir_url(__FILE__) . 'js/owl.carousel.js', array('jquery'), false);
281 wp_enqueue_script('wpvr-global', $asset_url . 'js/wpvr-global.js', array('jquery'), $this->version, false);
282
283 $admin_user = wp_get_current_user();
284 $admin_name = $admin_user->display_name ?? '';
285
286 wp_localize_script('wpvr-global', 'wpvr_global_obj', array(
287 'ajaxurl' => admin_url('admin-ajax.php'),
288 'site_url' => site_url() . '/wp-json/',
289 'ajax_nonce' => wp_create_nonce('wpvr'),
290 'user_information' => $this->get_logged_in_user_information(),
291 'is_wpvr_active' => is_plugin_active('wpvr-pro/wpvr-pro.php'),
292 'admin_name' => $admin_name,
293 'url_info' => array(
294 'admin_url' => admin_url(),
295 'screen' => $adscreen->action,
296 'url' => $_SERVER['PHP_SELF'],
297 'param' => $_GET,
298 ),
299 'active_tab_url' => admin_url('post-new.php?post_type=wpvr_item&active_tab=scene'),
300 'hotspot_warning_text' => __('Please upload a scene before proceeding to set hotspot!', 'wpvr'),
301 'negative_number_warning_text' =>__('Negative numbers are not allowed!', 'wpvr'),
302 ));
303
304 wp_localize_script('wpvr-global', 'wpvr_id_options', $wpvr_list);
305 }
306
307 /**
308 * Retrieve the currently logged-in user's email and name.
309 *
310 * @since 8.4.10
311 *
312 * @return array An associative array containing the logged-in user's email and name.
313 */
314 public function get_logged_in_user_information(): array
315 {
316 $admin_user = wp_get_current_user();
317 return array(
318 'email' => !empty( $admin_user->user_email ) ? $admin_user->user_email : '',
319 'name' => !empty( $admin_user->display_name ) ? $admin_user->display_name : '',
320 );
321 }
322
323
324 /**
325 * Set Preview and Setup custom metabox of this plugin
326 *
327 * @since 8.0.0
328 */
329 public function set_custom_meta_box() {
330 $this->setup_metabox = new WPVR_Setup_Meta_Box('setup', __('Setup', 'wpvr'), 'wpvr_item', 'normal', 'high');
331
332 $this->preview_metabox = new WPVR_Tour_Preview($this->post_type . '_builder__box', __('Tour Preview', 'wpvr'), $this->post_type, 'side', 'high');
333
334 $this->checklist_metabox = new WPVR_Tour_Checklist_Meta_Box($this->post_type . '_tour_checklist__box', __('Checklist', 'wpvr'), $this->post_type, 'side', 'high');
335
336 }
337
338
339 /**
340 * Plugin action links
341 *
342 * @param $actions || $links
343 * @return array
344 * @since 8.0.0
345 */
346 public function plugin_action_links_wpvr($actions)
347 {
348 $actions['get_started'] = sprintf(
349 '<a href="%s">%s</a>',
350 esc_url(admin_url('admin.php?page=wpvr')),
351 esc_html__('Get Started', 'wpvr')
352 );
353 $actions['documentation'] = sprintf(
354 '<a href="%s" target="_blank">%s</a>',
355 esc_url('https://rextheme.com/docs-category/wp-vr/'),
356 esc_html__('Documentation', 'wpvr')
357 );
358
359 if (!apply_filters('is_wpvr_pro_active', false)) {
360 $actions['go-pro'] = sprintf(
361 '<a href="%s" target="_blank" style="color: #201cfe; font-weight: bold;">%s</a>',
362 esc_url('https://rextheme.com/wpvr/wpvr-pricing/'),
363 esc_html__('Go Pro', 'wpvr')
364 );
365 }
366
367 return $actions;
368 }
369
370 /**
371 * Rollback execution
372 */
373 public function trigger_rollback()
374 {
375 if (!current_user_can('update_plugins') && !current_user_can('install_plugins')) {
376 return false;
377 }
378 $version = isset($_GET['wpvr_version']) ? sanitize_text_field(wp_unslash($_GET['wpvr_version'])) : '';
379 if ($version) {
380 check_admin_referer('wpvr_rollback', 'wpvr_rollback');
381 $plugin_slug = 'wpvr';
382 $rollback = new WPVR_Rollback(
383 [
384 'version' => $version,
385 'plugin_name' => 'wpvr',
386 'plugin_slug' => $plugin_slug,
387 'package_url' => sprintf('https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $version),
388 ]
389 );
390
391 $rollback->run();
392 }
393 }
394
395 /**
396 * Floor plan image Display
397 * Display Pro feature demo in free user
398 * @return void
399 */
400
401 public function floor_plan_image_show_for_free_user() {
402 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
403
404 ?>
405 <div class="rex-pano-tab floor-plan" id="floorPlan">
406
407 <img loading="lazy" src="<?= WPVR_PLUGIN_DIR_URL . 'images/floor-plan-demo.png' ?>" alt="icon" />
408 </div>
409 <?php
410 }
411 }
412
413 /**
414 * Background Tour image Display
415 * Display Pro feature demo in free user
416 * @return void
417 */
418 public function background_tour_image_show_for_free_user() {
419 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
420
421 ?>
422 <div class="rex-pano-tab background-tour" id="backgroundTour">
423
424 <!-- <img src="--><? //= WPVR_PLUGIN_DIR_URL . 'images/floor-plan-demo.png'
425 ?><!--" alt="icon" />-->
426 </div>
427 <?php
428 }
429 }
430 /**
431 * Street View image Display
432 * Display Pro feature demo in free user
433 * @return void
434 */
435
436 public function street_view_image_show_for_free_user() {
437 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
438
439 ?>
440 <div class="rex-pano-tab streetview" id="streetview">
441 <!-- <img src="--><? //= WPVR_PLUGIN_DIR_URL . 'images/floor-plan-demo.png'
442 ?><!--" alt="icon" />-->
443 </div>
444 <?php
445 }
446 }
447
448 public function scene_pro_image_show_for_free_user($pano_scene) {
449 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
450
451 ?>
452 <img loading="lazy" src="<?= WPVR_PLUGIN_DIR_URL . 'images/scene-pro-feature.png' ?>" alt="icon" />
453 <?php
454 }
455 }
456
457
458 public function empty_scene_pro_image_show_for_free_user() {
459 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
460 echo '<img loading="lazy" src="' . esc_url(WPVR_PLUGIN_DIR_URL . 'images/scene-pro-feature.png') . '" alt="WPVR Pro Feature" />';
461 }
462 }
463
464 public function show_review_request_markups() {
465 $show_review_request = get_option('wpvr_feed_review_request');
466 if (empty($show_review_request)) {
467 $data = array(
468 'show' => true,
469 'time' => '',
470 'frequency' => 'immediate',
471 );
472 update_option('wpvr_feed_review_request', $data);
473 }
474 }
475
476 public function wpvr_trigger_based_review_helper() {
477 $show_review_request = get_option('wpvr_feed_review_request');
478 $number_of_published_tours = $this->wpvr_get_total_published_tours();
479 if (!empty($show_review_request) && isset($show_review_request['show']) && $show_review_request['show']) {
480
481 if (isset($show_review_request['frequency']) && $number_of_published_tours > 1) {
482 if ($show_review_request['frequency'] == 'immediate') {
483 add_action('admin_notices', array($this, 'wpvr_generate_review_request_section'));
484 } elseif ($show_review_request['frequency'] == 'one_week') {
485 $last_shown_date = $show_review_request['time'];
486 $current_date = time();
487 $current_date = new DateTime(date('Y-m-d', $current_date));
488 $last_shown_date = new DateTime(date('Y-m-d', $last_shown_date));
489 $date_diff = $last_shown_date->diff($current_date);
490
491 if ($date_diff->d > 7) {
492 add_action('admin_notices', array($this, 'wpvr_generate_review_request_section'));
493 }
494 }
495 }
496 }
497 }
498
499 public function wpvr_generate_review_request_section() {
500 $screen = get_current_screen();
501
502 $promotional_notice_pages = [
503 'dashboard',
504 'plugins',
505 'wpvr_item',
506 'edit-wpvr_item',
507 'toplevel_page_wpvr',
508 'wp-vr_page_wpvr-setup-wizard'
509 ];
510
511 // Only proceed if the current screen ID matches the allowed pages.
512 if (!in_array($screen->id, $promotional_notice_pages)) {
513 return;
514 }
515
516 require_once plugin_dir_path(__FILE__) . 'partials/wpvr-review-request-body-content.php';
517 }
518
519 /**
520 * Get translated languages
521 *
522 * @return array
523 * @since 8.5.21
524 */
525 public function get_translated_languages(){
526 $language_mapping = [
527 'ar' => [ // Arabic
528 'Publish' => 'نشر', // nashr
529 'Update' => 'تحديث' // tahdith
530 ],
531 'pt_PT' => [ // Portuguese (Portugal)
532 'Publish' => 'Publicar',
533 'Update' => 'Atualizar'
534 ],
535 'es_ES' => [ // Spanish (Spain)
536 'Publish' => 'Publicar',
537 'Update' => 'Actualizar'
538 ],
539 'he_IL' => [ // Hebrew (Israel)
540 'Publish' => 'לפרסם', // lefarsem
541 'Update' => 'לעדכן' // le'adken
542 ],
543 'af' => [ // Afrikaans
544 'Publish' => 'Publiseer',
545 'Update' => 'Opdateer'
546 ],
547 'cs_CZ' => [ // Czech (Czech Republic)
548 'Publish' => 'Publikovat',
549 'Update' => 'Aktualizovat'
550 ],
551 'da_DK' => [ // Danish (Denmark)
552 'Publish' => 'Udgiv',
553 'Update' => 'Opdater'
554 ],
555 'de_DE' => [ // German (Germany)
556 'Publish' => 'Veröffentlichen',
557 'Update' => 'Aktualisieren'
558 ],
559 'fi' => [ // Finnish
560 'Publish' => 'Julkaise',
561 'Update' => 'Päivitä'
562 ],
563 'hr' => [ // Croatian
564 'Publish' => 'Objavi',
565 'Update' => 'Ažuriraj'
566 ],
567 'it_IT' => [ // Italian (Italy)
568 'Publish' => 'Pubblica',
569 'Update' => 'Aggiorna'
570 ],
571 'ja' => [ // Japanese
572 'Publish' => '�
573 �開',
574 'Update' => '更新'
575 ],
576 'nl_NL' => [ // Dutch (Netherlands)
577 'Publish' => 'Publiceren',
578 'Update' => 'Updaten'
579 ],
580 'pl_PL' => [ // Polish (Poland)
581 'Publish' => 'Opublikuj',
582 'Update' => 'Aktualizuj'
583 ],
584 'ru_RU' => [ // Russian (Russia)
585 'Publish' => 'Опубликовать',
586 'Update' => 'Обновить'
587 ],
588 'sv_SE' => [ // Swedish (Sweden)
589 'Publish' => 'Publicera',
590 'Update' => 'Uppdatera'
591 ],
592 'fr_FR' => [ // French (France)
593 'Publish' => 'Publier',
594 'Update' => 'Mettre à jour'
595 ],
596 'fr_CA' => [ // French (Canada)
597 'Publish' => 'Publier',
598 'Update' => 'Mettre à jour',
599 ],
600 'fr_BE' => [ // French (Belgium)
601 'Publish' => 'Publier',
602 'Update' => 'Mettre à jour',
603 ],
604 'fr_CH' => [ // Switzerland
605 'Publish' => 'Publier',
606 'Update' => 'Mettre à jour',
607 ],
608 'fr_LU' => [ // Luxembourg
609 'Publish' => 'Publier',
610 'Update' => 'Mettre à jour',
611 ],
612 'fr_MC' => [ // Monaco
613 'Publish' => 'Publier',
614 'Update' => 'Mettre à jour',
615 ],
616 'fr_CM' => [ // Cameroon
617 'Publish' => 'Publier',
618 'Update' => 'Mettre à jour',
619 ],
620 'fr_DZ' => [ // Algeria
621 'Publish' => 'Publier',
622 'Update' => 'Mettre à jour',
623 ],
624 'fr_MA' => [ // Morocco
625 'Publish' => 'Publier',
626 'Update' => 'Mettre à jour',
627 ],
628 'fr_TN' => [ // Tunisia
629 'Publish' => 'Publier',
630 'Update' => 'Mettre à jour',
631 ],
632 'fr_SN' => [ // Senegal
633 'Publish' => 'Publier',
634 'Update' => 'Mettre à jour',
635 ],
636 'fr_HT' => [ // Haiti
637 'Publish' => 'Publier',
638 'Update' => 'Mettre à jour',
639 ],
640 'fr_RW' => [ // Rwanda
641 'Publish' => 'Publier',
642 'Update' => 'Mettre à jour',
643 ],
644 'fr_CD' => [ // DR Congo
645 'Publish' => 'Publier',
646 'Update' => 'Mettre à jour',
647 ],
648 'fr_CI' => [ // Côte d’Ivoire
649 'Publish' => 'Publier',
650 'Update' => 'Mettre à jour',
651 ],
652 ];
653
654 return $language_mapping;
655 }
656
657
658 /**
659 * Add import button to the WPVR All Tours page
660 *
661 * @since 8.5.22
662 */
663 public function add_import_button() {
664 $screen = get_current_screen();
665 $status = get_option('wpvr_edd_license_status');
666
667 // Only add button on the WPVR Tours admin page
668 if ($screen && property_exists($screen, 'id') && ($screen->id === 'edit-wpvr_item')) {
669 ?>
670 <script type="text/javascript">
671 jQuery(document).ready(function($) {
672
673 // Check if user has WPVR Pro
674 var isProUser = <?php echo json_encode(defined('WPVR_PRO_VERSION')); ?>;
675
676 // Add the Import WPVR Tour button
677 var importButton = $('<a href="#" class="page-title-action wpvr-import-button"><?php _e("Import Tour", "wpvr"); ?></a>');
678 $('.wrap .page-title-action').after(importButton);
679
680 // If Free Version, add 'Pro' label
681 if (!isProUser || <?php echo json_encode($status !== 'valid'); ?>) {
682 importButton.append(" <span class='is-pro'>Pro</span>");
683 }
684
685 // If button wasn't added, try alternative placement
686 if ($('.wpvr-import-button').length === 0) {
687 $('.wrap h1.wp-heading-inline').after(importButton);
688 }
689
690 // Add the WPVR Import Form (hidden by default)
691 var importForm = `
692 <div id="wpvr-import-template-area">
693 <div id="wpvr-import-template-title">Choose a .zip archive of a WPVR tour and add it to your website.</div>
694 <form id="wpvr-import-template-form" method="post" action="<?php echo esc_url(admin_url('admin-ajax.php')); ?>" enctype="multipart/form-data">
695 <input type="hidden" name="action" value="wpvr_import_tour">
696 <fieldset id="wpvr-import-template-form-inputs">
697 <input type="file" name="wpvr_import_tour_file" accept=".zip" required>
698 <input id="wpvr-import-template-action" type="button" class="button button-primary" value="${wpvr_obj?.import_text}">
699 </fieldset>
700 </form>
701 </div>
702 `;
703
704 // Append the form after the Import button
705 $('.wpvr-import-button').after(importForm);
706
707 // Toggle form visibility on button click
708 $(document).on('click', '.wpvr-import-button', function(e) {
709 e.preventDefault();
710 if (!isProUser || <?php echo json_encode($status !== 'valid'); ?>) {
711 // Open CRO Modal (Pro Upgrade)
712 $("#wpvr_premium_feature_popup").show();
713 } else {
714 // Open WPVR Import Form
715 $('#wpvr-import-template-area').toggle();
716 }
717 });
718
719 // Close CRO Modal
720 $(document).on("click", "#wpvr_premium_feature_close", function () {
721 $("#wpvr_premium_feature_popup").hide();
722 });
723
724 var $importButton = $('#wpvr-import-template-action');
725 var $fileInput = $('input[name="wpvr_import_tour_file"]');
726
727 // Initially disable the import button
728 $importButton.prop('disabled', true);
729
730 // Enable button when a file is selected
731 $fileInput.on('change', function() {
732 if ($(this).val()) {
733 $importButton.prop('disabled', false);
734 } else {
735 $importButton.prop('disabled', true);
736 }
737 });
738 });
739 </script>
740 <?php
741 }
742 }
743
744 /**
745 * Enqueue deactivation sub-reason JS on plugins.php only, after SDK modal (priority 99).
746 *
747 * @return void
748 */
749 public function enqueue_deactivation_scripts() {
750 global $pagenow;
751 if ( 'plugins.php' !== $pagenow ) {
752 return;
753 }
754 wp_enqueue_script(
755 'wpvr-deactivation',
756 plugin_dir_url( __FILE__ ) . 'js/wpvr-deactivation.js',
757 array( 'jquery' ),
758 $this->version,
759 true
760 );
761 }
762
763 /**
764 * Get total published tours
765 *
766 * @return int
767 * @since 8.5.43
768 */
769 public function wpvr_get_total_published_tours(){
770 $args = array(
771 'post_type' => 'wpvr_item',
772 'post_status' => 'publish',
773 'posts_per_page' => -1,
774 'fields' => 'ids',
775 );
776
777 $query = new WP_Query( $args );
778 return $query->found_posts;
779 }
780
781 }
782