PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.4
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.4
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.4, at admin/class-wpvr-admin.php

499 lines 19.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 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 /**
27 * The ID of this plugin.
28 *
29 * @since 8.0.0
30 * @access private
31 * @var string $plugin_name The ID of this plugin.
32 */
33 private $plugin_name;
34
35 /**
36 * The version of this plugin.
37 *
38 * @since 8.0.0
39 * @access private
40 * @var string $version The current version of this plugin.
41 */
42 private $version;
43
44 /**
45 * The post type of this plugin.
46 *
47 * @since 8.0.0
48 */
49 private $post_type;
50
51 /**
52 * Instance of WPVR_Admin_Page class
53 *
54 * @var object
55 * @since 8.0.0
56 */
57 private $plugin_admin_page;
58
59 /**
60 * Instance of WPVR_Setup_Meta_Box class
61 *
62 * @var object
63 * @since 8.0.0
64 */
65 private $setup_metabox;
66
67 /**
68 * Instacne of WPVR_Tour_Preview class
69 *
70 * @var object
71 * @since 8.0.0
72 */
73 private $preview_metabox;
74
75 /**
76 * Instance of Wpvr_Ajax class
77 *
78 * @var object
79 * @since 8.0.0
80 */
81 private $plugin_admin_ajax;
82
83 /**
84 * Instance of WPVR_Post_Type class
85 *
86 * @var object
87 * @since 8.0.0
88 */
89 private $wpvr_post_type;
90
91
92 /**
93 * Initialize the class and set its properties.
94 *
95 * @since 8.0.0
96 * @param string $plugin_name The name of this plugin.
97 * @param string $version The version of this plugin.
98 * @param string $post_type Post type of this plugin
99 */
100 public function __construct($plugin_name, $version, $post_type)
101 {
102
103 $this->plugin_name = $plugin_name;
104 $this->version = $version;
105 $this->post_type = $post_type;
106
107 $this->wpvr_post_type = new WPVR_Post_Type($this->plugin_name, $this->version, $this->post_type);
108 $this->plugin_admin_page = WPVR_Admin_Page::getInstance();
109
110 add_action('admin_init', array($this, 'set_custom_meta_box'));
111
112 $this->plugin_admin_ajax = new Wpvr_Ajax();
113 }
114
115 /**
116 * Register the stylesheets for the admin area.
117 *
118 * @since 8.0.0
119 */
120 public function enqueue_styles()
121 {
122
123 /**
124 * This function is provided for demonstration purposes only.
125 *
126 * An instance of this class should be passed to the run() function
127 * defined in Wpvr_Loader as all of the hooks are defined
128 * in that particular class.
129 *
130 * The Wpvr_Loader will then create the relationship
131 * between the defined hooks and the functions defined in this
132 * class.
133 */
134 $screen = get_current_screen();
135
136 if ($screen->id == "toplevel_page_wpvr" || $screen->id == "wp-vr_page_wpvr-setting") {
137 wp_enqueue_style('materialize-css', plugin_dir_url(__FILE__) . 'css/materialize.min.css', array(), $this->version, 'all');
138 wp_enqueue_style('materialize-icons', plugin_dir_url(__FILE__) . 'lib/materializeicon.css', array(), $this->version, 'all');
139 wp_enqueue_style('owl-css', plugin_dir_url(__FILE__) . 'css/owl.carousel.css', array(), $this->version, 'all');
140 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin.css', array(), $this->version, 'all');
141 wp_enqueue_style('wpvr-rtl', plugin_dir_url(__FILE__) . 'css/wpvr-admin-rtl.css', array(), $this->version, 'all');
142 }
143
144 if ($screen->id == "edit-wpvr_item") {
145 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin-post-type.css', array(), $this->version, 'all');
146 }
147
148 if ($screen->id == "wpvr_item") {
149 wp_enqueue_style($this->plugin_name . 'fontawesome', plugin_dir_url(__FILE__) . 'lib/fontawesome/css/all.css', array(), $this->version, 'all');
150 wp_enqueue_style('icon-picker-css', plugin_dir_url(__FILE__) . 'css/jquery.fonticonpicker.min.css', array(), $this->version, 'all');
151 wp_enqueue_style('icon-picker-css-theme', plugin_dir_url(__FILE__) . 'css/jquery.fonticonpicker.grey.min.css', array(), $this->version, 'all');
152 wp_enqueue_style('owl-css', plugin_dir_url(__FILE__) . 'css/owl.carousel.css', array(), $this->version, 'all');
153 wp_enqueue_style('panellium-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/pannellum.css', array(), true);
154 wp_enqueue_style('videojs-css', plugin_dir_url(__FILE__) . 'lib/pannellum/src/css/video-js.css', array(), true);
155 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin.css', array(), $this->version, 'all');
156 wp_enqueue_style('wpvr-rtl', plugin_dir_url(__FILE__) . 'css/wpvr-admin-rtl.css', array(), $this->version, 'all');
157 wp_enqueue_style('summernote', plugin_dir_url(__FILE__) . 'lib/summernote/summernote-lite.min.css', array(), $this->version, 'all');
158
159 if (isset($_REQUEST['wpvr-guide-tour']) && $_REQUEST['wpvr-guide-tour'] == 1) {
160 wp_enqueue_style($this->plugin_name . '-shepherd-css', plugin_dir_url(__FILE__) . 'lib/shepherd/css/shepherd-theme-arrows-plain-buttons.css', false, $this->version);
161 wp_enqueue_style($this->plugin_name . '-tour-css', plugin_dir_url(__FILE__) . 'lib/shepherd/css/wpvr-tour-guide.min.css', false, $this->version);
162 }
163 }
164
165 if ($screen->id == "wp-vr_page_wpvr-setup-wizard") {
166 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvr-admin2.css', array(), $this->version, 'all');
167 wp_enqueue_style('wpvr-admin2-rtl', plugin_dir_url(__FILE__) . 'css/wpvr-admin2-rtl.css', array(), $this->version, 'all');
168 }
169
170 if ($screen->id == "dashboard_page_rex-wpvr-setup-wizard") {
171 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/style.css', array(), $this->version, 'all');
172 }
173 }
174
175
176 /**
177 * Register the JavaScript for the admin area.
178 *
179 * @since 8.0.0
180 */
181 public function enqueue_scripts()
182 {
183
184 /**
185 * This function is provided for demonstration purposes only.
186 *
187 * An instance of this class should be passed to the run() function
188 * defined in Wpvr_Loader as all of the hooks are defined
189 * in that particular class.
190 *
191 * The Wpvr_Loader will then create the relationship
192 * between the defined hooks and the functions defined in this
193 * class.
194 */
195 $wpvr_list = array();
196 $wpvr_list[] = array('value' => 0, 'label' => 'None');
197 $args = array(
198 'numberposts' => -1,
199 'post_type' => 'wpvr_item'
200 );
201
202 $wpvr_posts = get_posts($args);
203 foreach ($wpvr_posts as $wpvr_post) {
204 $title = $wpvr_post->ID . ' : ' . $wpvr_post->post_title;
205 $wpvr_list[] = array( 'value'=>$wpvr_post->ID,'label'=> $title);
206 }
207
208 wp_enqueue_script('wp-api');
209 wp_enqueue_media();
210
211 $asset_url = apply_filters('change_asset_url', plugin_dir_url(__FILE__));
212
213 wp_enqueue_script('wp-api');
214 $adscreen = get_current_screen();
215 wp_enqueue_media();
216 if ($adscreen->id == "wpvr_item" || $adscreen->id == "toplevel_page_wpvr" || $adscreen->id == "wp-vr_page_wpvr-setting") {
217 wp_enqueue_script('summernote', $asset_url . 'lib/summernote/summernote-lite.min.js', array('jquery'), true);
218 wp_enqueue_script('wpvr-icon-picker', $asset_url . 'lib/jquery.fonticonpicker.min.js', array(), true);
219 wp_enqueue_script('panellium-js', $asset_url . 'lib/pannellum/src/js/pannellum.js', array(), true);
220 wp_enqueue_script('panelliumlib-js', $asset_url . 'lib/pannellum/src/js/libpannellum.js', array(), true);
221 wp_enqueue_script('videojs-js', $asset_url . 'js/video.js', array('jquery'), true);
222 wp_enqueue_script('panelliumvid-js', $asset_url . 'lib/pannellum/src/js/videojs-pannellum-plugin.js', array(), true);
223 wp_enqueue_script('jquery-repeater', $asset_url . 'js/jquery.repeater.min.js', array('jquery'), true);
224 wp_enqueue_script('icon-picker', $asset_url . 'lib/jquery.fonticonpicker.min.js', array(), true);
225 wp_enqueue_script('owl', $asset_url . 'js/owl.carousel.js', array('jquery'), false);
226 wp_enqueue_script($this->plugin_name, $asset_url . 'js/wpvr-admin.js', array('jquery'), $this->version, true);
227 wp_localize_script($this->plugin_name, 'wpvr_localize', array(
228 'WriteYourCssHere' => __('Write your css here', 'wpvr'),
229 'VideoTourNotice' => __('Turning On The Video Option Will Erase Your Virtual Tour Data. Are You Sure?', 'wpvr'),
230 'StreetViewNotice' => __('Turning On The StreetView Option Will Erase Your Virtual Tour Data. Are You Sure?', 'wpvr'),
231 'AddingHotspotsOnScene' => __('Adding Hotspots on Scene', 'wpvr'),
232 'WPVR_ASSET_PATH' => WPVR_ASSET_PATH,
233 ));
234 if (isset($_REQUEST['wpvr-guide-tour']) && $_REQUEST['wpvr-guide-tour'] == 1) {
235 wp_enqueue_script($this->plugin_name . '-tether-js', plugin_dir_url(__FILE__) . 'lib/shepherd/tether/tether.js', $this->version, true);
236 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);
237 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);
238 $tour_guide_translation = new Tour_Guide_Translation();
239
240 wp_localize_script($this->plugin_name . '-tour-guide', 'wpvr_tour_guide_obj', array(
241 'Tour_Guide_Translation' => $tour_guide_translation->get_translatable_string(),
242 ));
243 }
244
245 wp_localize_script($this->plugin_name, 'wpvr_obj', array(
246 'ajaxurl' => admin_url('admin-ajax.php'),
247 'ajax_nonce' => wp_create_nonce('wpvr')
248 ));
249 }
250
251 if ($adscreen->id == "toplevel_page_wpvr" || $adscreen->id == "wp-vr_page_wpvr-setting") {
252 wp_enqueue_script('materialize-js', $asset_url . 'js/materialize.min.js', array('jquery'), $this->version, false);
253 }
254 if ($adscreen->id == "wpvr_item") {
255 wp_enqueue_script($this->plugin_name . '-shortcode', plugin_dir_url(__FILE__) . 'js/wpvr-shortcode.js', array('jquery'), $this->version, true);
256 }
257
258 if ($adscreen->id == "dashboard_page_rex-wpvr-setup-wizard") {
259 wp_enqueue_script(
260 'wpvr-setup-wizard-manager',
261 WPVR_JS_PATH . 'library/setupwizard.bundle.js',
262 array('jquery'),
263 $this->version,
264 true
265 );
266 }
267
268
269 wp_enqueue_script('owl-js', plugin_dir_url(__FILE__) . 'js/owl.carousel.js', array('jquery'), false);
270 wp_enqueue_script('wpvr-global', $asset_url . 'js/wpvr-global.js', array('jquery'), $this->version, false);
271
272 $admin_user = wp_get_current_user();
273 $admin_name = $admin_user->display_name ?? '';
274
275 wp_localize_script('wpvr-global', 'wpvr_global_obj', array(
276 'ajaxurl' => admin_url('admin-ajax.php'),
277 'site_url' => site_url() . '/wp-json/',
278 'ajax_nonce' => wp_create_nonce('wpvr'),
279 'user_information' => $this->get_logged_in_user_information(),
280 'is_wpvr_active' => is_plugin_active('wpvr-pro/wpvr-pro.php'),
281 'admin_name' => $admin_name,
282 'url_info' => array(
283 'admin_url' => admin_url(),
284 'screen' => $adscreen->action,
285 'url' => $_SERVER['PHP_SELF'],
286 'param' => $_GET,
287 ),
288 ));
289 wp_localize_script('wpvr-global', 'wpvr_id_options', $wpvr_list);
290 }
291
292 /**
293 * Retrieve the currently logged-in user's email and name.
294 *
295 * @since 8.4.10
296 *
297 * @return array An associative array containing the logged-in user's email and name.
298 */
299 public function get_logged_in_user_information(): array
300 {
301 $admin_user = wp_get_current_user();
302 return array(
303 'email' => !empty( $admin_user->user_email ) ? $admin_user->user_email : '',
304 'name' => !empty( $admin_user->display_name ) ? $admin_user->display_name : '',
305 );
306 }
307
308
309 /**
310 * Set Preview and Setup custom metabox of this plugin
311 *
312 * @since 8.0.0
313 */
314 public function set_custom_meta_box()
315 {
316 $this->setup_metabox = new WPVR_Setup_Meta_Box('setup', __('Setup', 'wpvr'), 'wpvr_item', 'normal', 'high');
317
318 $this->preview_metabox = new WPVR_Tour_Preview($this->post_type . '_builder__box', __('Tour Preview', 'wpvr'), $this->post_type, 'side', 'high');
319 }
320
321
322 /**
323 * Plugin action links
324 *
325 * @param $actions || $links
326 * @return array
327 * @since 8.0.0
328 */
329 public function plugin_action_links_wpvr($actions)
330 {
331 $actions['get_started'] = sprintf(
332 '<a href="%s">%s</a>',
333 esc_url(admin_url('admin.php?page=wpvr')),
334 esc_html__('Get Started', 'wpvr')
335 );
336 $actions['documentation'] = sprintf(
337 '<a href="%s" target="_blank">%s</a>',
338 esc_url('https://rextheme.com/docs-category/wp-vr/'),
339 esc_html__('Documentation', 'wpvr')
340 );
341
342 if (!apply_filters('is_wpvr_pro_active', false)) {
343 $actions['go-pro'] = sprintf(
344 '<a href="%s" target="_blank" style="color: #201cfe; font-weight: bold;">%s</a>',
345 esc_url('https://rextheme.com/wpvr/wpvr-pricing/'),
346 esc_html__('Go Pro', 'wpvr')
347 );
348 }
349 return $actions;
350 }
351
352 /**
353 * Rollback execution
354 */
355 public function trigger_rollback()
356 {
357 if (!current_user_can('update_plugins') && !current_user_can('install_plugins')) {
358 return false;
359 }
360 $version = isset($_GET['wpvr_version']) ? sanitize_text_field(wp_unslash($_GET['wpvr_version'])) : '';
361 if ($version) {
362 check_admin_referer('wpvr_rollback', 'wpvr_rollback');
363 $plugin_slug = 'wpvr';
364 $rollback = new WPVR_Rollback(
365 [
366 'version' => $version,
367 'plugin_name' => 'wpvr',
368 'plugin_slug' => $plugin_slug,
369 'package_url' => sprintf('https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, $version),
370 ]
371 );
372
373 $rollback->run();
374 }
375 }
376
377 /**
378 * Floor plan image Display
379 * Display Pro feature demo in free user
380 * @return void
381 */
382
383 public function floor_plan_image_show_for_free_user()
384 {
385 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
386
387 ?>
388 <div class="rex-pano-tab floor-plan" id="floorPlan">
389
390 <img loading="lazy" src="<?= WPVR_PLUGIN_DIR_URL . 'images/floor-plan-demo.png' ?>" alt="icon" />
391 </div>
392 <?php
393 }
394 }
395 /**
396 * Background Tour image Display
397 * Display Pro feature demo in free user
398 * @return void
399 */
400 public function background_tour_image_show_for_free_user()
401 {
402 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
403
404 ?>
405 <div class="rex-pano-tab background-tour" id="backgroundTour">
406
407 <!-- <img src="--><? //= WPVR_PLUGIN_DIR_URL . 'images/floor-plan-demo.png'
408 ?><!--" alt="icon" />-->
409 </div>
410 <?php
411 }
412 }
413 /**
414 * Street View image Display
415 * Display Pro feature demo in free user
416 * @return void
417 */
418 public function street_view_image_show_for_free_user()
419 {
420 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
421
422 ?>
423 <div class="rex-pano-tab streetview" id="streetview">
424 <!-- <img src="--><? //= WPVR_PLUGIN_DIR_URL . 'images/floor-plan-demo.png'
425 ?><!--" alt="icon" />-->
426 </div>
427 <?php
428 }
429 }
430
431 public function scene_pro_image_show_for_free_user($pano_scene)
432 {
433 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
434
435 ?>
436 <img loading="lazy" src="<?= WPVR_PLUGIN_DIR_URL . 'images/scene-pro-feature.png' ?>" alt="icon" />
437 <?php
438 }
439 }
440
441 public function empty_scene_pro_image_show_for_free_user()
442 {
443 if (!is_plugin_active('wpvr-pro/wpvr-pro.php')) {
444
445 ?>
446 <img loading="lazy" src="<?= WPVR_PLUGIN_DIR_URL . 'images/scene-pro-feature.png' ?>" alt="icon" />
447 <?php
448 }
449 }
450
451 public function show_review_request_markups()
452 {
453 $show_review_request = get_option('wpvr_feed_review_request');
454
455 if (empty($show_review_request)) {
456 $data = array(
457 'show' => true,
458 'time' => '',
459 'frequency' => 'immediate',
460 );
461 update_option('wpvr_feed_review_request', $data);
462 }
463 }
464
465 public function wpvr_trigger_based_review_helper()
466 {
467 $show_review_request = get_option('wpvr_feed_review_request');
468
469 if (!empty($show_review_request) && isset($show_review_request['show']) && $show_review_request['show']) {
470
471 if (isset($show_review_request['frequency'])) {
472 if ($show_review_request['frequency'] == 'immediate') {
473 add_action('admin_notices', array($this, 'wpvr_generate_review_request_section'));
474 } elseif ($show_review_request['frequency'] == 'one_week') {
475 $last_shown_date = $show_review_request['time'];
476 $current_date = time();
477 $current_date = new DateTime(date('Y-m-d', $current_date));
478 $last_shown_date = new DateTime(date('Y-m-d', $last_shown_date));
479 $date_diff = $last_shown_date->diff($current_date);
480
481 if ($date_diff->d > 7) {
482 add_action('admin_notices', array($this, 'wpvr_generate_review_request_section'));
483 }
484 }
485 }
486 }
487 }
488 public function wpvr_generate_review_request_section()
489 {
490
491 $screen = get_current_screen();
492 $promotional_notice_pages = ['dashboard', 'plugins', 'wpvr_item', 'edit-wpvr_item', 'toplevel_page_wpvr', 'wp-vr_page_wpvr-setup-wizard'];
493 if (!in_array($screen->id, $promotional_notice_pages)) {
494 return;
495 }
496 require_once plugin_dir_path(__FILE__) . 'partials/wpvr-review-request-body-content.php';
497 }
498 }
499