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
← All changes | app/Hooks/Handlers/BlockEditorHandler.php +84 -52 1.10.0 → 2.5.0 View file →
@@ -2,12 +2,14 @@
2 2
3 3 namespace FluentBooking\App\Hooks\Handlers;
4 4
5 5 use FluentBooking\App\App;
6 +use FluentBooking\App\Vite;
6 7 use FluentBooking\App\Models\Calendar;
7 8 use FluentBooking\App\Models\CalendarSlot;
8 9 use FluentBooking\App\Services\CalendarEventService;
9 10 use FluentBooking\App\Services\Helper;
11 +use FluentBooking\App\Services\LocationService;
10 12 use FluentBooking\Framework\Support\Arr;
11 13
12 14 class BlockEditorHandler
13 15 {
@@ -13,48 +15,25 @@
13 15 {
14 16 public function init()
15 17 {
16 18 add_action('enqueue_block_editor_assets', function () {
17 - $app = App::getInstance();
18 - $assets = $app['url.assets'];
19 + $blockDeps = array('wp-blocks', 'wp-components', 'wp-block-editor', 'wp-element');
19 20
20 - wp_enqueue_script(
21 - 'fluent-booking/calendar',
22 - $assets . 'admin/fluent-booking-index.js',
23 - array('wp-blocks', 'wp-components', 'wp-block-editor', 'wp-element'),
24 - FLUENT_BOOKING_ASSETS_VERSION,
25 - true
26 - );
21 + $assetsVersion = Vite::isDev() ? time() : FLUENT_BOOKING_ASSETS_VERSION;
27 22
23 + Vite::enqueueScript('fluent-booking/calendar', 'fb_index', $blockDeps, $assetsVersion);
24 +
28 25 wp_localize_script('fluent-booking/calendar', 'fluentCalendarGutenbergVars', [
29 26 'ajaxurl' => admin_url('admin-ajax.php'),
30 27 ]);
31 28
32 - wp_enqueue_script(
33 - 'fluent-booking/team-management',
34 - $assets . 'admin/fluent-booking-team-management-index.js',
35 - array('wp-blocks', 'wp-components', 'wp-block-editor', 'wp-element'),
36 - FLUENT_BOOKING_ASSETS_VERSION,
37 - true
38 - );
29 + Vite::enqueueScript('fluent-booking/team-management', 'fb_team', $blockDeps, $assetsVersion);
39 30
40 - wp_enqueue_script(
41 - 'fluent-booking/calendar-management',
42 - $assets . 'admin/fluent-booking-calendar-management-index.js',
43 - array('wp-blocks', 'wp-components', 'wp-block-editor', 'wp-element'),
44 - FLUENT_BOOKING_ASSETS_VERSION,
45 - true
46 - );
31 + Vite::enqueueScript('fluent-booking/calendar-management', 'fb_calendar', $blockDeps, $assetsVersion);
47 32
48 - wp_enqueue_script(
49 - 'fluent-booking/booking-management',
50 - $assets . 'admin/fluent-booking-booking-management-index.js',
51 - array('wp-blocks', 'wp-components', 'wp-block-editor', 'wp-element'),
52 - FLUENT_BOOKING_ASSETS_VERSION,
53 - true
54 - );
33 + Vite::enqueueScript('fluent-booking/booking-management', 'fb_booking', $blockDeps, $assetsVersion);
55 34
56 - $calendars = Calendar::with(['events' => function ($query) {
35 + $calendars = Calendar::with(['metas', 'events' => function ($query) {
57 36 $query->where('status', 'active');
58 37 }])->where('status', 'active')->get();
59 38
60 39 $formattedCalendars = [];
@@ -72,9 +51,9 @@
72 51 'color_schema' => $event->color_schema,
73 52 'durations' => $event->getAvailableDurations(),
74 53 'locations' => $event->defaultLocationHtml(),
75 54 'payment_html' => $event->getPaymentHtml(),
76 - 'loc_settings' => $event->location_settings,
55 + 'loc_settings' => LocationService::sanitizePublicLocationSettings($event->location_settings),
77 56 'description' => $event->short_description
78 57 ];
79 58 }
80 59
@@ -81,9 +60,9 @@
81 60 $formattedCalendars[$calendar->id] = [
82 61 'id' => (string)$calendar->id,
83 62 'title' => $calendar->title,
84 63 'description' => wpautop(Helper::excerpt($calendar->description, 200)),
85 - 'author' => $calendar->getAuthorProfile(),
64 + 'author' => Arr::only($calendar->getAuthorProfile(), ['name', 'avatar']),
86 65 'event_order' => $calendar->getMeta('event_order'),
87 66 'events' => $formattedEvents
88 67 ];
89 68 }
@@ -88,13 +67,26 @@
88 67 ];
89 68 }
90 69
91 70 wp_localize_script('fluent-booking/calendar', 'fluent_booking_block', [
92 - 'assets_url' => $assets,
71 + 'assets_url' => App::getInstance()['url.assets'] ?? '',
93 72 'hosts' => $formattedCalendars
94 73 ]);
95 74 });
96 75
76 + add_action('enqueue_block_assets', function () {
77 + if (!is_admin()) {
78 + return;
79 + }
80 +
81 + $assetsVersion = Vite::isDev() ? time() : FLUENT_BOOKING_ASSETS_VERSION;
82 +
83 + Vite::enqueueStyle('fluent-booking/calendar-style', 'fb_index_css', [], $assetsVersion);
84 + Vite::enqueueStyle('fluent-booking/team-management-style', 'fb_team_css', [], $assetsVersion);
85 + Vite::enqueueStyle('fluent-booking/calendar-management-style', 'fb_calendar_css', [], $assetsVersion);
86 + Vite::enqueueStyle('fluent-booking/booking-management-style', 'fb_booking_css', [], $assetsVersion);
87 + });
88 +
97 89 register_block_type('fluent-booking/calendar', array(
98 90 'editor_script' => 'fluent-booking/calendar',
99 91 'render_callback' => array($this, 'fcalRenderBlock'),
100 92 'attributes' => [
@@ -239,9 +231,9 @@
239 231
240 232 $hostItems = [];
241 233
242 234 foreach ($hosts as $config) {
243 - $calendar = Calendar::find($config['id']);
235 + $calendar = Calendar::with('metas')->find($config['id']);
244 236 if (!$calendar) {
245 237 continue;
246 238 }
247 239
@@ -320,13 +312,19 @@
320 312 }
321 313
322 314 public function fcalRenderBookingManagementBlock($attributes)
323 315 {
324 - $calendarIds = Arr::get($attributes, 'calendarIds', []);
316 + $calendarIds = (array) Arr::get($attributes, 'calendarIds', []);
325 317
318 + if (!$calendarIds || in_array('all', $calendarIds, true)) {
319 + $calendarIds = 'all';
320 + } else {
321 + $calendarIds = implode(',', array_map('intval', $calendarIds));
322 + }
323 +
326 324 $title = sanitize_text_field(Arr::get($attributes, 'title'));
327 325
328 - $period = sanitize_text_field(Arr::get($attributes, 'period', 'all'));
326 + $period = sanitize_key(Arr::get($attributes, 'period', 'all'));
329 327
330 328 $perPage = intval(Arr::get($attributes, 'perPage', 10));
331 329
332 330 $showFilter = Arr::isTrue($attributes, 'showFilter', true) ? 'show' : 'hide';
@@ -334,26 +332,46 @@
334 332 $showPagination = Arr::isTrue($attributes, 'showPagination', true) ? 'show' : 'hide';
335 333
336 334 $noBookingsMessage = sanitize_text_field(Arr::get($attributes, 'noBookingsMessage'));
337 335
338 - return do_shortcode("[fluent_booking_lists title=\"$title\" period=$period per_page=$perPage filter=$showFilter pagination=$showPagination no_bookings=\"$noBookingsMessage\" calendar_ids=" . implode(',', $calendarIds) . "]");
336 + $shortcode = sprintf(
337 + '[fluent_booking_lists title="%s" period=%s per_page=%d filter=%s pagination=%s no_bookings="%s" calendar_ids=%s]',
338 + esc_attr($title),
339 + $period,
340 + $perPage,
341 + $showFilter,
342 + $showPagination,
343 + esc_attr($noBookingsMessage),
344 + $calendarIds
345 + );
346 +
347 + return do_shortcode($shortcode);
339 348 }
340 349
341 350 public function fcalRenderBlock($attributes)
342 351 {
343 - $output = '<style>
344 - :root {
345 - --fcal_primary_color: ' . esc_attr($attributes['primary_color']) . ' !important;
346 - --fcal_date_radius: ' . esc_attr($attributes['date_round']) . ' !important;
347 - --fcal_avatar_radius: ' . esc_attr($attributes['avatarStyle']) . ' !important;
348 - }
349 - </style>';
352 + $primaryColor = sanitize_hex_color(Arr::get($attributes, 'primary_color', ''));
353 + $dateRadius = self::sanitizeCssLength(Arr::get($attributes, 'date_round', ''));
354 + $avatarRadius = self::sanitizeCssLength(Arr::get($attributes, 'avatarStyle', ''));
350 355
351 - $slotId = (int) $attributes['slotId'];
352 - $disableHost = $attributes['hideHostInfo'];
353 - $theme = Arr::get($attributes, 'theme', 'light');
354 - $eventHash = Arr::get($attributes, 'eventHash');
356 + $output = '<style>:root {';
357 + if ($primaryColor) {
358 + $output .= '--fcal_primary_color: ' . $primaryColor . ' !important;';
359 + }
360 + if ($dateRadius) {
361 + $output .= '--fcal_date_radius: ' . $dateRadius . ' !important;';
362 + }
363 + if ($avatarRadius) {
364 + $output .= '--fcal_avatar_radius: ' . $avatarRadius . ' !important;';
365 + }
366 + $output .= '}</style>';
355 367
368 + $slotId = (int) Arr::get($attributes, 'slotId');
369 + $disableHost = Arr::isTrue($attributes, 'hideHostInfo') ? 'yes' : 'no';
370 + $theme = sanitize_key(Arr::get($attributes, 'theme', 'light'));
371 + $eventHash = sanitize_text_field(Arr::get($attributes, 'eventHash', ''));
372 + $align = sanitize_html_class(Arr::get($attributes, 'align', ''));
373 +
356 374 $slot = CalendarSlot::find($slotId);
357 375
358 376 if (!$slot) {
359 377 $slot = CalendarSlot::where('hash', $eventHash)->first();
@@ -359,15 +377,29 @@
359 377 $slot = CalendarSlot::where('hash', $eventHash)->first();
360 378 if (!$slot) {
361 379 return '';
362 380 }
363 - $slotId = $slot->id;
381 + $slotId = (int) $slot->id;
382 + $eventHash = (string) $slot->hash;
364 383 }
365 384
366 - $output .= '<div class="fluent-booking-calendar-block align' . Arr::get($attributes, 'align') . '">';
385 + $output .= '<div class="fluent-booking-calendar-block align' . esc_attr($align) . '">';
367 386
368 - $output .= do_shortcode("[fluent_booking id=$slotId disable_author=$disableHost theme=$theme hash=$eventHash]");
387 + $output .= do_shortcode(sprintf(
388 + '[fluent_booking id=%d disable_author=%s theme=%s hash=%s]',
389 + $slotId,
390 + $disableHost,
391 + $theme,
392 + esc_attr($eventHash)
393 + ));
369 394
370 395 $output .= '</div>';
371 396 return $output;
397 + }
398 +
399 + private static function sanitizeCssLength($value)
400 + {
401 + $value = trim((string) $value);
402 +
403 + return preg_match('/^\d{1,3}(\.\d+)?(px|%|em|rem)$/', $value) ? $value : '';
372 404 }
373 405 }