PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.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 All 34 releases
fluent-booking / app / Services / Integrations / Elementor / ElementorIntegration.php

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

173 lines 5.5 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 = [];
114
115 $events = $this->getCalendarEvents($calId);
116
117 wp_send_json_success($events);
118 }
119
120 public function ajaxGetEventHash() {
121 if (!isset($_POST['security']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['security'])), 'calendar_events_nonce')) {
122 wp_send_json_error(['message' => __('Nonce verification failed', 'fluent-booking')]);
123 exit;
124 }
125
126 if (!current_user_can('edit_posts')) {
127 wp_send_json_error(['message' => __('You do not have permission to perform this action', 'fluent-booking')]);
128 exit;
129 }
130
131 $eventId = isset($_POST['event_id']) ? intval($_POST['event_id']) : null;
132
133 $event = CalendarSlot::find($eventId);
134
135 if (!$event) {
136 wp_send_json_error(['message' => __('Event not found', 'fluent-booking')]);
137 exit;
138 }
139
140 $eventHash = $event->hash;
141
142 wp_send_json_success(['hash' => $eventHash]);
143 }
144
145 public function registerWidgets()
146 {
147 \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalCalendarEvent());
148 \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalBookings());
149 \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalCalendar());
150 }
151
152 /**
153 * @throws \Exception
154 */
155 private function loadFile($relativePath)
156 {
157 $filePath = __DIR__ . $relativePath;
158 if (file_exists($filePath)) {
159 require_once($filePath);
160 } else {
161 /* translators: %s: File path */
162 throw new \Exception(esc_html(sprintf(__('File not found: %s', 'fluent-booking'), $filePath)));
163 }
164 }
165
166 private function registerFluentBookingCustomGroupSelect($controls_manager)
167 {
168 $control = new \FluentBookingCustomGroupSelect();
169 \Elementor\Plugin::instance()->controls_manager->register($control, 'fcal_group_select');
170 }
171
172 }
173