PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.37
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.37
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 / classes / class-wpvr-sample-tour.php

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

191 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPVR Sample Tour Class
4 *
5 * This class handles the creation of a sample virtual tour for the WPVR plugin.
6 * It includes methods to copy necessary images to the WordPress uploads folder
7 * and generate a sample tour post with predefined panorama data.
8 *
9 * @since 8.5.21
10 */
11
12 class WPVR_Sample_Tour {
13
14
15 /**
16 * Check if running in WordPress Playground.
17 *
18 * @return bool True if in Playground, false otherwise.
19 * @since 8.5.22
20 */
21 public function wpvr_is_playground() {
22
23 if (get_option('wpvr_is_playground') === '1') {
24 return true;
25 }
26
27 // Check if HTTP_HOST is set
28 $host = $_SERVER['HTTP_HOST'] ?? '';
29
30 // Check for Playground domains
31 $playground_domains = [
32 'playground.wordpress.net', // Online Playground
33 '.wordpress.net', // Any WordPress.net subdomain
34 'localhost:5400', // Local Playground default port
35 ];
36
37 foreach ($playground_domains as $domain) {
38 if (strpos($host, $domain) !== false) {
39 return true;
40 }
41 }
42
43 // Check for specific environment variables that might be set in Playground
44 if (defined('IS_WORDPRESS_PLAYGROUND') && IS_WORDPRESS_PLAYGROUND) {
45 return true;
46 }
47
48 // Check for specific file structures that might indicate Playground
49 if (file_exists('/wordpress-playground') || file_exists('/wp-playground')) {
50 return true;
51 }
52
53 return false;
54 }
55
56 /**
57 * Create a sample virtual tour for the WPVR plugin.
58 *
59 * This method copies the necessary images to the WordPress uploads folder
60 * and generates a sample tour post with predefined panorama data.
61 *
62 * @since 8.5.21
63 */
64 public function create_sample_tour() {
65
66 if (!function_exists('WP_Filesystem')) {
67 require_once ABSPATH . 'wp-admin/includes/file.php';
68 }
69
70 // Initialize the Filesystem API
71 global $wp_filesystem;
72 if (!isset($wp_filesystem)) {
73 $filesystem_initialized = WP_Filesystem();
74 if (!$filesystem_initialized) {
75 wp_send_json_error(__('Failed to initialize WP_Filesystem', 'wpvr'));
76 return;
77 }
78 }
79
80 $file_save_url = wp_upload_dir();
81 $zip_file_path = WPVR_PLUGIN_DIR_PATH . 'sample_tour/wpvr_sample_tour.zip';
82 $unzipfile = unzip_file($zip_file_path, $file_save_url['basedir'] . '/wpvr/temp/');
83
84 if (is_wp_error($unzipfile)) {
85 WPVR_Sample_Tour_Import::wpvr_delete_temp_file();
86 wp_send_json_error(__('Failed to unzip file', 'wpvr'));
87 }
88
89 $result = glob($file_save_url["basedir"] . '/wpvr/temp/*.json');
90 if (!$result) {
91 WPVR_Sample_Tour_Import::wpvr_delete_temp_file();
92 wp_send_json_error(__('Tour json file not found', 'wpvr'));
93 }
94
95 $tour_json = $result[0];
96 $arrContextOptions = array(
97 "ssl" => array(
98 "verify_peer" => false,
99 "verify_peer_name" => false,
100 ),
101 );
102 $getfile = file_get_contents($tour_json, false, stream_context_create($arrContextOptions));
103
104 $file_content = json_decode($getfile, true);
105
106 $new_title = $file_content['title'];
107 $new_data = $file_content['data'];
108
109 if(empty($new_data)){
110 return;
111 }
112
113 $new_post_id = wp_insert_post(array(
114 'post_title' => $new_title,
115 'post_type' => 'wpvr_item',
116 'post_status' => 'publish',
117 ));
118 if ($new_post_id) {
119 if ($new_data['panoid']) {
120 $new_data['panoid'] = 'pano' . $new_post_id;
121 }
122 if ($new_data['preview']) {
123 $new_data['preview'] = WPVR_Sample_Tour_Import::prepare_preview_file_to_import($file_save_url, $new_post_id, $new_data);
124 }
125
126 if ($new_data['cpLogoImg']) {
127 $new_data['cpLogoImg'] = WPVR_Sample_Tour_Import::prepare_company_log_image_to_import($new_data['cpLogoImg'], $file_save_url, $new_post_id, $new_data);
128 }
129
130 if ($new_data['bg_music_url']) {
131 $new_data['bg_music_url'] = WPVR_Sample_Tour_Import::prepare_bg_music_url_to_import($new_data, $file_save_url, $new_post_id);
132 }
133 if ($new_data['panodata']) {
134
135 if ($new_data['panodata']["scene-list"]) {
136
137 foreach ($new_data['panodata']["scene-list"] as $key => $panoscenes) {
138
139 if ($panoscenes['scene-type'] == 'cubemap') {
140
141 // face 0
142 if ($panoscenes["scene-attachment-url-face0"]) {
143 $cube_name = '_face0.jpg';
144 $new_data['panodata']["scene-list"][$key]['scene-attachment-url'] = WPVR_Sample_Tour_Import::prepare_scene_attachment_url_to_import($panoscenes, $cube_name, $file_save_url, $new_post_id, $key);
145 }
146
147 // face 1
148 if ($panoscenes["scene-attachment-url-face1"]) {
149 $cube_name = '_face1.jpg';
150 $new_data['panodata']["scene-list"][$key]['scene-attachment-url'] = WPVR_Sample_Tour_Import::prepare_scene_attachment_url_to_import($panoscenes, $cube_name, $file_save_url, $new_post_id, $key);
151 }
152
153 // face 2
154 if ($panoscenes["scene-attachment-url-face2"]) {
155 $cube_name = '_face2.jpg';
156 $new_data['panodata']["scene-list"][$key]['scene-attachment-url'] = WPVR_Sample_Tour_Import::prepare_scene_attachment_url_to_import($panoscenes, $cube_name, $file_save_url, $new_post_id, $key);
157 }
158
159 // face 3
160 if ($panoscenes["scene-attachment-url-face0"]) {
161 $cube_name = '_face3.jpg';
162 $new_data['panodata']["scene-list"][$key]['scene-attachment-url'] = WPVR_Sample_Tour_Import::prepare_scene_attachment_url_to_import($panoscenes, $cube_name, $file_save_url, $new_post_id, $key);
163 }
164
165 // face 4
166 if ($panoscenes["scene-attachment-url-face4"]) {
167 $cube_name = '_face4.jpg';
168 $new_data['panodata']["scene-list"][$key]['scene-attachment-url'] = WPVR_Sample_Tour_Import::prepare_scene_attachment_url_to_import($panoscenes, $cube_name, $file_save_url, $new_post_id, $key);
169 }
170
171 // face 5
172 if ($panoscenes["scene-attachment-url-face5"]) {
173 $cube_name = '_face5.jpg';
174 $new_data['panodata']["scene-list"][$key]['scene-attachment-url'] = WPVR_Sample_Tour_Import::prepare_scene_attachment_url_to_import($panoscenes, $cube_name, $file_save_url, $new_post_id, $key);
175 }
176 } else {
177 if ($panoscenes["scene-attachment-url"]) {
178 $cube_name = '.jpg';
179 $new_data['panodata']["scene-list"][$key]['scene-attachment-url'] = WPVR_Sample_Tour_Import::prepare_scene_attachment_url_to_import($panoscenes, $cube_name, $file_save_url, $new_post_id, $key);
180 }
181 }
182 }
183 }
184 update_post_meta($new_post_id, 'panodata', $new_data);
185 WPVR_Sample_Tour_Import::wpvr_delete_temp_file();
186 }
187 }
188 }
189
190 }
191