PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.7.1
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.7.1
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / app / Services / ImportService.php

ImportService.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.7.1, at app/Services/ImportService.php

67 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Services;
4
5 use FluentBooking\Framework\Support\Arr;
6
7 class ImportService
8 {
9 /*
10 * Import host data from JSON
11 * @param array|string $data JSON data or array
12 * @param bool $useCurrentUser If true, the current user will be used as the host
13 * @return \FluentBooking\App\Models\Calendar|\WP_Error
14 */
15 public function importHostJson($data, $useCurrentUser = true)
16 {
17 if (is_string($data)) {
18 $data = json_decode($data, true);
19 }
20
21 if (!$data || !is_array($data) || empty($data['data_type']) || $data['data_type'] !== 'host') {
22 return new \WP_Error('invalid_data', 'Invalid data provided');
23 }
24
25 if (empty($data['title']) || empty($data['slug'])) {
26 return new \WP_Error('invalid_data', 'Invalid data provided');
27 }
28
29 $createdCalendar = CalendarService::createCalendar($data, $useCurrentUser);
30
31 if (is_wp_error($createdCalendar)) {
32 return new \WP_Error($createdCalendar->get_error_code(), $createdCalendar->get_error_message());
33 }
34
35 return $createdCalendar;
36 }
37
38 /*
39 * Import host data from JSON URL
40 * @param string $jsonUrl JSON URL
41 * @param bool $useCurrentUser If true, the current user will be used as the host
42 * @return \FluentBooking\App\Models\Calendar|\WP_Error
43 */
44 public function importHostByJSONUrl($jsonUrl, $useCurrentUser = true)
45 {
46 $response = wp_safe_remote_get($jsonUrl, [
47 'timeout' => 30,
48 'headers' => [
49 'Accept' => 'application/json'
50 ]
51 ]);
52
53 if (is_wp_error($response)) {
54 return $response;
55 }
56
57 // check if the status code is not 200
58 if (wp_remote_retrieve_response_code($response) !== 200) {
59 return new \WP_Error('invalid_response', 'Invalid response from the server');
60 }
61
62 $body = json_decode(wp_remote_retrieve_body($response), true);
63
64 return $this->importHostJson($body, $useCurrentUser);
65 }
66 }
67