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 / Services / Integrations / Elementor / ElementorIntegration.php

ElementorIntegration.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.3.0, at app/Services/Integrations/Elementor/ElementorIntegration.php

174 lines 5.6 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\Integrations\Elementor;
4
5
6 use FluentBooking\App\Models\Calendar;
7 use FluentBooking\App\Models\CalendarSlot;
8 use FluentBooking\App\App;
9
10 class ElementorIntegration
11 {
12 public function register()
13 {
14 add_action('elementor/init', [$this, 'addElementorCategory']);
15
16 add_action('elementor/widgets/widgets_registered', [$this, 'registerWidget']);
17 add_action('elementor/controls/controls_registered', [$this, 'registerControl']);
18
19 add_action('elementor/editor/before_enqueue_scripts', [$this, 'editorScripts']);
20 add_action('elementor/editor/after_enqueue_scripts', [$this, 'editorScripts']);
21
22 add_action('wp_ajax_get_calendar_events', [$this, 'ajaxGetCalendarEvents']);
23
24 add_action('wp_ajax_get_event_hash', [$this, 'ajaxGetEventHash']);
25 }
26
27 public function editorScripts()
28 {
29 wp_enqueue_script('fcal-custom-elementor', plugin_dir_url(__FILE__) . 'fcal-custom-elementor.js', ['jquery'], time(), true);
30
31 wp_localize_script('fcal-custom-elementor', 'fcal_elementor_ajax_object', array(
32 'nonce' => wp_create_nonce('calendar_events_nonce'),
33 'ajaxurl' => admin_url('admin-ajax.php'),
34 'svgIcon' => App::getInstance('url.assets') . 'images/fluentbooking.svg'
35 ));
36 }
37
38
39 private function getCalendarEvents($selectedCalId = '')
40 {
41 if (empty($selectedCalId)) {
42 return [];
43 }
44
45 $calendar = Calendar::with(['events' => function ($query) {
46 $query->where('status', 'active');
47 }])->find($selectedCalId);
48
49 if (!$calendar) {
50 return [];
51 }
52
53 $formattedData = [];
54
55 foreach ($calendar->events as $event) {
56 $formattedData[$event->id] = $event->title;
57 }
58
59 return $formattedData;
60 }
61
62 public function addElementorCategory()
63 {
64 \Elementor\Plugin::instance()->elements_manager->add_category('fluentbooking', [
65 'title' => __('FluentBooking', 'fluent-booking'),
66 ], 1);
67 }
68
69 /**
70 * @throws \Exception
71 */
72 public function registerWidget()
73 {
74 $this->includeWidgets();
75 $this->registerWidgets();
76 }
77
78 /**
79 * @throws \Exception
80 */
81 public function includeWidgets()
82 {
83 $this->loadFile('/Widgets/FcalCalendarEvent.php');
84 $this->loadFile('/Widgets/FcalBookings.php');
85 $this->loadFile('/Widgets/FcalCalendar.php');
86 }
87
88 /**
89 * @throws \Exception
90 */
91 public function registerControl($controls_manager)
92 {
93 $this->loadFile('/Controls/FluentBookingCustomGroupSelect.php');
94 $this->registerFluentBookingCustomGroupSelect($controls_manager);
95 }
96
97 public function ajaxGetCalendarEvents() {
98 if (!isset($_POST['security']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['security'])), 'calendar_events_nonce')) {
99 wp_send_json_error(['message' => __('Nonce verification failed', 'fluent-booking')]);
100 exit;
101 }
102
103 if (!current_user_can('edit_posts')) {
104 wp_send_json_error(['message' => __('You do not have permission to perform this action', 'fluent-booking')]);
105 exit;
106 }
107
108 if (!isset($_POST['cal_id'])) {
109 wp_send_json_error(['message' => __('No calendar ID provided', 'fluent-booking')]);
110 }
111
112 $calId = intval($_POST['cal_id']);
113 $events = []; // Fetch events using your getCalendarEvents method or similar
114
115 // Example of fetching events (you need to replace this with your actual method)
116 $events = $this->getCalendarEvents($calId);
117
118 wp_send_json_success($events);
119 }
120
121 public function ajaxGetEventHash() {
122 if (!isset($_POST['security']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['security'])), 'calendar_events_nonce')) {
123 wp_send_json_error(['message' => __('Nonce verification failed', 'fluent-booking')]);
124 exit;
125 }
126
127 if (!current_user_can('edit_posts')) {
128 wp_send_json_error(['message' => __('You do not have permission to perform this action', 'fluent-booking')]);
129 exit;
130 }
131
132 $eventId = isset($_POST['event_id']) ? intval($_POST['event_id']) : null;
133
134 $event = CalendarSlot::find($eventId);
135
136 if (!$event) {
137 wp_send_json_error(['message' => __('Event not found', 'fluent-booking')]);
138 exit;
139 }
140
141 $eventHash = $event->hash;
142
143 wp_send_json_success(['hash' => $eventHash]);
144 }
145
146 public function registerWidgets()
147 {
148 \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalCalendarEvent());
149 \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalBookings());
150 \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalCalendar());
151 }
152
153 /**
154 * @throws \Exception
155 */
156 private function loadFile($relativePath)
157 {
158 $filePath = __DIR__ . $relativePath;
159 if (file_exists($filePath)) {
160 require_once($filePath);
161 } else {
162 /* translators: %s: File path */
163 throw new \Exception(esc_html(sprintf(__('File not found: %s', 'fluent-booking'), $filePath)));
164 }
165 }
166
167 private function registerFluentBookingCustomGroupSelect($controls_manager)
168 {
169 $control = new \FluentBookingCustomGroupSelect();
170 \Elementor\Plugin::instance()->controls_manager->register($control, 'fcal_group_select');
171 }
172
173 }
174