PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.76
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.76
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-import-sample-tour.php

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

264 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 /**
4 * Responsible for managing Tour Import feature
5 *
6 * @link http://rextheme.com/
7 * @since 8.5.21
8 *
9 * @package Wpvr
10 * @subpackage Wpvr/admin/classes
11 */
12
13 class WPVR_Sample_Tour_Import {
14
15 /**
16 * Prepare tour import feature, if tour has preview file
17 *
18 * @param mixed $file_save_url
19 * @param mixed $new_post_id
20 * @param mixed $new_data
21 *
22 * @return void
23 * @since 8.5.21
24 */
25 public static function prepare_preview_file_to_import($file_save_url, $new_post_id, $new_data)
26 {
27 $preview_file_path = WPVR_PLUGIN_DIR_PATH . 'sample-data/scene_preview.jpg';
28 if (!file_exists($preview_file_path)) {
29 return $new_data['preview']; // Return original if file doesn't exist
30 }
31 $media_get = self::wpvr_handle_media_import_from_path($preview_file_path, $new_post_id);
32 if ($media_get['status'] == 'error') {
33 wp_delete_post($new_post_id, true);
34 wp_send_json_error($media_get['message']);
35 } elseif ($media_get['status'] == 'success') {
36 return $new_data['preview'] = $media_get['message'];
37 } else {
38 wp_delete_post($new_post_id, true);
39 wp_send_json_error('Media transfer process failed');
40 }
41 }
42
43
44 /**
45 * Prepare tour import feature, if tour has company logo
46 *
47 * @param mixed $logo
48 * @param mixed $file_save_url
49 * @param mixed $new_post_id
50 * @param mixed $new_data
51 *
52 * @return void
53 * @since 8.5.21
54 */
55 public static function prepare_company_log_image_to_import($logo, $file_save_url, $new_post_id, $new_data)
56 {
57 $get_logo_format = explode(".", $logo);
58 $logo_format = end($get_logo_format);
59 $logo_file_path = WPVR_PLUGIN_DIR_PATH . 'sample-data/logo_img.' . $logo_format;
60 if (!file_exists($logo_file_path)) {
61 return $new_data['cpLogoImg']; // Return original if file doesn't exist
62 }
63 $media_get = self::wpvr_handle_media_import_from_path($logo_file_path, $new_post_id);
64 if ($media_get['status'] == 'error') {
65 wp_delete_post($new_post_id, true);
66 wp_send_json_error($media_get['message']);
67 } elseif ($media_get['status'] == 'success') {
68 return $new_data['cpLogoImg'] = $media_get['message'];
69 } else {
70 wp_delete_post($new_post_id, true);
71 wp_send_json_error('Media transfer process failed');
72 }
73 }
74
75
76 /**
77 * Prepare tour import feature, if tour has background music url
78 *
79 * @param mixed $new_data
80 * @param mixed $file_save_url
81 * @param mixed $new_post_id
82 *
83 * @return array
84 * @since 8.5.21
85 */
86 public static function prepare_bg_music_url_to_import($new_data, $file_save_url, $new_post_id)
87 {
88 $music_url = $new_data['bg_music_url'];
89 $get_music_format = explode(".", $music_url);
90 $music_format = end($get_music_format);
91 $music_file_path = WPVR_PLUGIN_DIR_PATH . 'sample-data/bg_music.' . $music_format;
92 if (!file_exists($music_file_path)) {
93 return $new_data['bg_music_url']; // Return original if file doesn't exist
94 }
95 $media_get = self::wpvr_handle_media_import_from_path($music_file_path, $new_post_id);
96 if ($media_get['status'] == 'error') {
97 wp_delete_post($new_post_id, true);
98 wp_send_json_error($media_get['message']);
99 } elseif ($media_get['status'] == 'success') {
100 return $new_data['bg_music_url'] = $media_get['message'];
101 } else {
102 wp_delete_post($new_post_id, true);
103 wp_send_json_error('Media transfer process failed');
104 }
105 }
106
107
108 /**
109 * Prepare scene attachment url to import
110 *
111 * @param mixed $panoscenes
112 * @param mixed $cube_name
113 * @param mixed $file_save_url
114 * @param mixed $new_post_id
115 * @param mixed $key
116 *
117 * @return array
118 * @since 8.5.21
119 */
120 public static function prepare_scene_attachment_url_to_import($panoscenes, $cube_name, $file_save_url, $new_post_id, $key)
121 {
122 $scene_id = $panoscenes['scene-id'];
123 $scene_file_path = WPVR_PLUGIN_DIR_PATH . 'sample-data/' . $scene_id . $cube_name;
124 if (!file_exists($scene_file_path)) {
125 return null; // Return null if file doesn't exist
126 }
127 $media_get = self::wpvr_handle_media_import_from_path($scene_file_path, $new_post_id);
128 if ($media_get['status'] == 'error') {
129 wp_delete_post($new_post_id, true);
130 wp_send_json_error($media_get['message']);
131 } elseif ($media_get['status'] == 'success') {
132 return $media_get['message'];
133 } else {
134 wp_delete_post($new_post_id, true);
135 wp_send_json_error('Media transfer process failed');
136 }
137 }
138
139
140 /**
141 * Handle media importing from local file path
142 *
143 * @param string $file_path Local file path
144 * @param int $post_id Post ID
145 *
146 * @return array
147 * @since 8.5.21
148 */
149 public static function wpvr_handle_media_import_from_path($file_path, $post_id)
150 {
151 if (!file_exists($file_path) || !is_readable($file_path)) {
152 return array(
153 'status' => 'error',
154 'message' => 'File does not exist or is not readable: ' . $file_path
155 );
156 }
157
158 // Include required WordPress files
159 if (!function_exists('wp_handle_upload')) {
160 require_once ABSPATH . 'wp-admin/includes/file.php';
161 }
162 if (!function_exists('wp_generate_attachment_metadata')) {
163 require_once ABSPATH . 'wp-admin/includes/image.php';
164 }
165 if (!function_exists('media_handle_sideload')) {
166 require_once ABSPATH . 'wp-admin/includes/media.php';
167 }
168
169 // Create a temporary copy for WordPress to handle
170 $temp_file = wp_tempnam(basename($file_path));
171 if (!copy($file_path, $temp_file)) {
172 return array(
173 'status' => 'error',
174 'message' => 'Failed to create temporary file copy'
175 );
176 }
177
178 $file_array = array(
179 'name' => basename($file_path),
180 'tmp_name' => $temp_file
181 );
182
183 $id = media_handle_sideload($file_array, $post_id);
184
185 if (is_wp_error($id)) {
186 wp_delete_file($temp_file);
187 return array(
188 'status' => 'error',
189 'message' => $id->get_error_message()
190 );
191 }
192
193 $value = wp_get_attachment_url($id);
194 return array(
195 'status' => 'success',
196 'message' => $value
197 );
198 }
199
200 /**
201 * Handle media importing
202 *
203 * @param mixed $url
204 * @param mixed $post_id
205 *
206 * @return array
207 * @since 8.5.21
208 */
209 public static function wpvr_handle_media_import($url, $post_id)
210 {
211 add_filter('https_ssl_verify', '__return_false');
212 add_filter('https_local_ssl_verify', '__return_false');
213
214 $tmp = download_url($url);
215 $file_array = array(
216 'name' => basename($url),
217 'tmp_name' => $tmp
218 );
219
220 if (is_wp_error($tmp)) {
221 wp_delete_file($file_array['tmp_name']);
222 return (array(
223 'status' => 'error',
224 'message' => $tmp->get_error_message()
225 ));
226 }
227
228 $id = media_handle_sideload($file_array, $post_id);
229
230 if (is_wp_error($id)) {
231 wp_delete_file($file_array['tmp_name']);
232 return (array(
233 'status' => 'error',
234 'message' => $tmp->get_error_message()
235 ));
236 }
237 remove_filter('https_ssl_verify', '__return_false');
238 remove_filter('https_local_ssl_verify', '__return_false');
239
240 $value = wp_get_attachment_url($id);
241 return (array(
242 'status' => 'success',
243 'message' => $value
244 ));
245 }
246
247
248 /**
249 * Delete temporary files (deprecated - no longer needed with direct file loading)
250 *
251 * @return void
252 * @since 8.5.21
253 * @deprecated No longer needed with direct file loading approach
254 */
255 public static function wpvr_delete_temp_file()
256 {
257 // This method is deprecated and no longer needed since we load files directly
258 // from the sample-data directory instead of extracting from ZIP files.
259 // Keeping for backward compatibility but it does nothing.
260 return;
261 }
262
263 }
264