PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / extensions / divi_5_amelia / server / AmeliaEventsListBookingButtonModule.php
ameliabooking / extensions / divi_5_amelia / server Last commit date
AmeliaBookingButtonRendererTrait.php 3 months ago AmeliaBookingModule.php 1 day ago AmeliaCatalogBookingModule.php 1 day ago AmeliaCatalogModule.php 1 day ago AmeliaCatalogShortcodeHelper.php 1 day ago AmeliaCustomerPanelModule.php 1 day ago AmeliaEmployeePanelModule.php 1 day ago AmeliaEventsCalendarModule.php 1 day ago AmeliaEventsListBookingButtonModule.php 1 day ago AmeliaEventsListModule.php 1 day ago AmeliaEventsModule.php 1 day ago AmeliaSearchModule.php 1 day ago AmeliaStepBookingButtonModule.php 1 day ago AmeliaStepBookingModule.php 1 day ago ModuleMetadata.php 2 months ago SharedShortcodeModule.php 2 months ago index.php 1 day ago
AmeliaEventsListBookingButtonModule.php
185 lines
1 <?php
2
3 namespace Divi5Amelia;
4
5 use AmeliaBooking\Infrastructure\WP\ShortcodeService\ShortcodeAliasService;
6 use ET\Builder\Framework\DependencyManagement\Interfaces\DependencyInterface;
7 use ET\Builder\FrontEnd\Module\Style;
8 use ET\Builder\Packages\Module\Layout\Components\ModuleElements\ModuleElements;
9 use ET\Builder\Packages\Module\Options\Element\ElementClassnames;
10 use ET\Builder\Packages\ModuleLibrary\ModuleRegistration;
11 use AmeliaBooking\Infrastructure\WP\Translations\LiteBackendStrings;
12 use WP_Block;
13
14 /**
15 * Class that handles "Amelia Events List Booking Button" module output in frontend.
16 */
17 class AmeliaEventsListBookingButtonModule implements DependencyInterface
18 {
19 use AmeliaBookingButtonRendererTrait;
20
21 private const BUTTON_BASE_CLASS = 'amelia-eventslist-booking-button';
22
23 /**
24 * Register module.
25 */
26 public function load()
27 {
28 add_action('init', [AmeliaEventsListBookingButtonModule::class, 'registerModule']);
29 }
30
31 public static function registerModule()
32 {
33 $module_json_folder_path = dirname(__DIR__, 1) . '/visual-builder/src/modules/EventsListBookingButton';
34
35 ModuleRegistration::register_module(
36 $module_json_folder_path,
37 [
38 'render_callback' => [AmeliaEventsListBookingButtonModule::class, 'renderCallback'],
39 ]
40 );
41 }
42
43 /**
44 * Generate classnames for the module.
45 */
46 public static function module_classnames(array $args): void
47 {
48 $classnames_instance = $args['classnamesInstance'];
49 $attrs = $args['attrs'];
50
51 $classnames_instance->add(
52 ElementClassnames::classnames([
53 'attrs' => $attrs['module']['decoration'] ?? [],
54 ])
55 );
56 }
57
58 /**
59 * Module script data.
60 */
61 public static function module_script_data(array $args): void
62 {
63 $elements = $args['elements'];
64
65 $elements->script_data([
66 'attrName' => 'module',
67 ]);
68 }
69
70 /**
71 * Module styles.
72 */
73 public static function module_styles(array $args): void
74 {
75 $attrs = $args['attrs'] ?? [];
76 $elements = $args['elements'];
77 $settings = $args['settings'] ?? [];
78
79 Style::add([
80 'id' => $args['id'],
81 'name' => $args['name'],
82 'orderIndex' => $args['orderIndex'],
83 'storeInstance' => $args['storeInstance'],
84 'styles' => [
85 // Module styles.
86 $elements->style([
87 'attrName' => 'module',
88 'styleProps' => [
89 'disabledOn' => [
90 'disabledModuleVisibility' => $settings['disabledModuleVisibility'] ?? null,
91 ],
92 ],
93 ]),
94 // Button styles.
95 $elements->style([
96 'attrName' => 'button',
97 ]),
98 ],
99 ]);
100 }
101
102 /**
103 * Render module HTML output.
104 */
105 public static function renderCallback(array $attrs, string $content, WP_Block $block, ModuleElements $elements): string
106 {
107 $auto_trigger = wp_unique_id('amelia-eventslist-booking-btn-');
108
109 $shortcode = '[' . ShortcodeAliasService::activeShortcodeTag('eventslistbooking', 'ameliaeventslistbooking');
110 $shortcode .= ' trigger=' . sanitize_html_class($auto_trigger);
111 $shortcode .= ' trigger_type=id';
112 $shortcode .= ' in_dialog=1';
113
114 // Preselect/filter parameters
115 $booking_params = $attrs['booking_params']['innerContent']['desktop']['value'] ?? false;
116 if ($booking_params === 'on') {
117 $event = $attrs['events']['innerContent']['desktop']['value'] ?? [];
118 if ($event && count($event) > 0) {
119 $shortcode .= ' event=' . implode(',', array_filter(array_map('absint', $event)));
120 }
121
122 $event_to_show = $attrs['event_to_show']['innerContent']['desktop']['value'] ?? 'all';
123 if (count($event) === 0 && $event_to_show !== 'all') {
124 if ($event_to_show === 'custom') {
125 $start_date = $attrs['start_date']['innerContent']['desktop']['value'] ?? '';
126 $end_date = $attrs['end_date']['innerContent']['desktop']['value'] ?? '';
127
128 $has_valid_start = $start_date && preg_match('/^\d{4}-\d{2}-\d{2}$/', $start_date);
129 $has_valid_end = $end_date && preg_match('/^\d{4}-\d{2}-\d{2}$/', $end_date);
130
131 if (!$has_valid_start || !$has_valid_end) {
132 // Fallback: render without date range filter, or log warning
133 // For now, skip the range parameter rather than hiding the button
134 $event_to_show = 'all';
135 } else {
136 $shortcode .= ' range="' . esc_attr($start_date) . ' - ' . esc_attr($end_date) . '"';
137 }
138 } else {
139 $shortcode .= ' range="' . esc_attr($event_to_show) . '"';
140 }
141 }
142
143 $tag = $attrs['tags']['innerContent']['desktop']['value'] ?? [];
144 if ($tag && count($tag) > 0) {
145 $shortcode .= ' tag="' . implode(',', array_map(function ($t) {
146 return '{' . sanitize_text_field($t) . '}';
147 }, $tag)) . '"';
148 }
149
150 $recurring = $attrs['recurring']['innerContent']['desktop']['value'] ?? false;
151 if ($recurring === 'on') {
152 $shortcode .= ' recurring=1';
153 }
154
155 $locations = $attrs['locations']['innerContent']['desktop']['value'] ?? [];
156 if ($locations && count($locations) > 0) {
157 $shortcode .= ' location=' . implode(',', array_filter(array_map('absint', $locations)));
158 }
159 }
160
161 $shortcode .= ']';
162
163 // Render shortcode now to preserve quoted attributes (e.g., custom range) reliably.
164 $shortcode_output = do_shortcode($shortcode);
165
166 $button_html = self::renderTriggerButtonHtml(
167 $attrs,
168 $block,
169 $elements,
170 $auto_trigger,
171 self::BUTTON_BASE_CLASS,
172 LiteBackendStrings::get('event_book_event')
173 );
174
175 return self::renderBookingButtonModuleShell(
176 $attrs,
177 $block,
178 $elements,
179 $button_html,
180 'amelia-eventslist-booking-button_wrapper',
181 $shortcode_output
182 );
183 }
184 }
185