PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.3.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.3.0
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 / Hooks / Handlers / DataImporter.php

DataImporter.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.3.0, at app/Hooks/Handlers/DataImporter.php

79 lines 2.3 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\Hooks\Handlers;
4
5 use FluentBooking\App\App;
6 use FluentBooking\App\Services\CalendarService;
7 use FluentBooking\App\Services\PermissionManager;
8
9 class DataImporter
10 {
11 public function importCalendar()
12 {
13 if (!$this->verifyNonce()) {
14 wp_send_json_error([
15 'message' => __('Security check failed. Please refresh and try again.', 'fluent-booking'),
16 ]);
17 }
18
19 if (!PermissionManager::userCan(['invite_team_members', 'manage_all_data', 'manage_other_calendars'])) {
20 wp_send_json_error([
21 'message' => __('You are not authorized to import calendar', 'fluent-booking'),
22 ]);
23 }
24
25 $app = App::getInstance();
26
27 $data = $app->request->all();
28
29 if (empty($data['type']) || empty($data['user_id']) || empty($data['author_timezone'])) {
30 wp_send_json_error([
31 'message' => __('Please provide all required data', 'fluent-booking'),
32 ]);
33 }
34
35 $file = $app->request->file('file');
36
37 if (empty($file) || $file->getClientOriginalExtension() != 'json') {
38 wp_send_json_error([
39 'message' => __('Invalid file. Please provide a valid JSON file', 'fluent-booking'),
40 ]);
41 }
42
43 $fileContent = $file->getContents();
44
45 $calendarData = wp_parse_args($data, json_decode($fileContent, true));
46
47 if (empty($calendarData)) {
48 wp_send_json_error([
49 'message' => __('Invalid file. Please provide a valid JSON file', 'fluent-booking'),
50 ]);
51 }
52
53 $calendar = CalendarService::createCalendar($calendarData, false, true);
54
55 if (is_wp_error($calendar)) {
56 wp_send_json_error([
57 'message' => $calendar->get_error_message(),
58 ]);
59 }
60
61 wp_send_json([
62 'success' => true,
63 'message' => __('Calendar imported successfully', 'fluent-booking'),
64 ]);
65 }
66
67 /**
68 * Verify the request nonce for AJAX actions.
69 *
70 * @return bool
71 */
72 private function verifyNonce()
73 {
74 $nonce = isset($_REQUEST['nonce']) ? sanitize_text_field(wp_unslash($_REQUEST['nonce'])) : '';
75
76 return !empty($nonce) && wp_verify_nonce($nonce, 'fluent-booking');
77 }
78 }
79