PluginProbe
Booking Calendar / 10.15.6
Booking Calendar v10.15.6
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
booking / includes / elementor-booking-form / elementor-widget-booking.php

elementor-widget-booking.php in Booking Calendar 10.15.6, at includes/elementor-booking-form/elementor-widget-booking.php

390 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * includes/elementor-booking-form/elementor-widget-booking.php
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor Booking Calendar Widget.
12 *
13 * Elementor widget for Booking Calendar plugin.
14 *
15 * @since 1.0.0
16 */
17 class WPBC_Elementor_WPBC_Booking_Form_1 extends \Elementor\Widget_Base {
18
19 /**
20 * Get widget name.
21 *
22 * Retrieve list widget name.
23 *
24 * @since 1.0.0
25 * @access public
26 * @return string Widget name.
27 */
28 public function get_name(): string {
29 return 'wpbc_widget_booking_form_1';
30 }
31
32 /**
33 * Get widget title.
34 *
35 * Retrieve list widget title.
36 *
37 * @since 1.0.0
38 * @access public
39 * @return string Widget title.
40 */
41 public function get_title(): string {
42 return 'Booking Calendar'; // . ' - ' . esc_html__( 'Booking Form', 'booking' ); //.
43 }
44
45 /**
46 * Get widget icon.
47 *
48 * Retrieve list widget icon.
49 *
50 * @since 1.0.0
51 * @access public
52 * @return string Widget icon.
53 */
54 public function get_icon(): string {
55 return 'wpbc_logo_in_elementor';
56 }
57
58 /**
59 * Get widget categories.
60 *
61 * Retrieve the list of categories the list widget belongs to.
62 *
63 * @since 1.0.0
64 * @access public
65 * @return array Widget categories.
66 */
67 public function get_categories(): array {
68 return [ 'basic', 'wpbc' ];
69 }
70
71 /**
72 * Get widget keywords.
73 *
74 * Retrieve the list of keywords the list widget belongs to.
75 *
76 * @since 1.0.0
77 * @access public
78 * @return array Widget keywords.
79 */
80 public function get_keywords(): array {
81 return [ 'Booking Calendar', 'booking', 'calendar', 'bookings', 'events', 'appointments', 'booking plugin', 'wpbc' ];
82 }
83
84 /**
85 * Get custom help URL.
86 *
87 * Retrieve a URL where the user can get more information about the widget.
88 *
89 * @since 1.0.0
90 * @access public
91 * @return string Widget help URL.
92 */
93 public function get_custom_help_url(): string {
94 return 'https://wpbookingcalendar.com/contact/';
95 }
96
97 /**
98 * Get widget promotion data.
99 *
100 * Retrieve the widget promotion data.
101 *
102 * @since 1.0.0
103 * @access protected
104 * @return array Widget promotion data.
105 */
106 protected function get_upsale_data(): array {
107 return array(
108 'image' => esc_url( ELEMENTOR_ASSETS_URL . 'images/go-pro.svg' ),
109 'image_alt' => esc_attr__( 'Upgrade', 'booking' ),
110 'title' => esc_html__( 'Booking Calendar Pro', 'booking' ),
111 'description' => esc_html__( 'Get the premium version of the plugin with additional features.', 'booking' ),
112 'upgrade_url' => esc_url( 'https://wpbookingcalendar.com/prices/' ),
113 'upgrade_text' => esc_html__( 'Upgrade Now', 'booking' ),
114 'condition' => ! class_exists('wpdev_bk_personal'),
115 );
116 }
117
118 /**
119 * Whether the widget requires inner wrapper.
120 *
121 * Determine whether to optimize the DOM size.
122 *
123 * @since 1.0.0
124 * @access public
125 * @return bool Whether to optimize the DOM size.
126 */
127 public function has_widget_inner_wrapper(): bool {
128 return true;
129 }
130
131 /**
132 * Whether the element returns dynamic content.
133 *
134 * Determine whether to cache the element output or not.
135 *
136 * @since 1.0.0
137 * @access protected
138 * @return bool Whether to cache the element output.
139 */
140 protected function is_dynamic_content(): bool {
141 return true;
142 }
143
144 /**
145 * Register list widget controls.
146 *
147 * Add input fields to allow the user to customize the widget settings.
148 *
149 * @since 1.0.0
150 * @access protected
151 */
152 protected function register_controls(): void {
153
154 $this->start_controls_section(
155 'wpbc_booking_interface_section',
156 [
157 'label' => esc_html__( 'Booking Interface', 'booking' ),
158 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
159 ]
160 );
161
162 $this->add_control(
163 'wpbc_booking_shortcode',
164 [
165 'type' => \Elementor\Controls_Manager::SELECT,
166 'label' => esc_html__( 'Display Mode', 'booking' ),
167 'options' => [
168 'booking' => esc_html__( 'Booking Form', 'booking' ) . ' + ' . esc_html__( 'Calendar', 'booking' ),
169 'bookingcalendar' => esc_html__( 'Availability Calendar Only', 'booking' ),
170 ],
171 'default' => 'booking',
172 'label_block' => true,
173 ]
174 );
175
176 if ( class_exists( 'wpdev_bk_personal' ) ) {
177 $this->add_control(
178 'wpbc_booking_resource_id',
179 [
180 'label' => esc_html__( 'Select Booking Resource', 'booking' ),
181 'type' => 'wpbc_resource_selection',
182 ]
183 );
184 }
185
186 $this->add_control(
187 'wpbc_booking_months_number',
188 [
189 'type' => \Elementor\Controls_Manager::SELECT,
190 'label' => esc_html__( 'Number of Visible Months', 'booking' ),
191 'options' => [
192 '1' => '1 ' . esc_html__( 'month', 'booking' ),
193 '2' => '2 ' . esc_html__( 'months', 'booking' ),
194 '3' => '3 ' . esc_html__( 'months', 'booking' ),
195 '4' => '4 ' . esc_html__( 'months', 'booking' ),
196 '5' => '5 ' . esc_html__( 'months', 'booking' ),
197 '6' => '6 ' . esc_html__( 'months', 'booking' ),
198 '7' => '7 ' . esc_html__( 'months', 'booking' ),
199 '8' => '8 ' . esc_html__( 'months', 'booking' ),
200 '9' => '9 ' . esc_html__( 'months', 'booking' ),
201 '10' => '10 ' . esc_html__( 'months', 'booking' ),
202 '11' => '11 ' . esc_html__( 'months', 'booking' ),
203 '12' => '12 ' . esc_html__( 'months', 'booking' ),
204 ],
205 'default' => '1',
206 ]
207 );
208
209
210 if ( wpbc_is_custom_forms_enabled() ) {
211 $this->add_control(
212 'wpbc_custom_form_id',
213 [
214 'label' => esc_html__( 'Use Custom Form', 'booking' ),
215 'type' => 'wpbc_custom_form_selection',
216 'condition' => [
217 'wpbc_booking_shortcode' => 'booking',
218 ],
219 ]
220 );
221 }
222
223 $this->add_control(
224 'wpbc_go_button__form_fields',
225 [
226 'type' => 'wpbc_go_button',
227 'text' => esc_html__( 'Go to Form Fields Configuration', 'booking' ),
228 'icon' => 'eicon-share-arrow',
229 'css_class' => 'e-btn-txt e-btn-txt-border',
230 'url' => esc_url( wpbc_get_settings_url() . '&tab=form' ),
231 'condition' => [
232 'wpbc_booking_shortcode' => 'booking',
233 ],
234 ]
235 );
236
237 $this->end_controls_section();
238
239 $this->start_controls_section(
240 'wpbc_booking_advanced_section',
241 [
242 'label' => esc_html__( 'Advanced', 'booking' ),
243 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
244 ]
245 );
246
247 $this->add_control(
248 'wpbc_booking_calendar_dates_start',
249 [
250 'type' => \Elementor\Controls_Manager::DATE_TIME,
251 'label' => esc_html__( 'Earliest date visible/selectable in the calendar.', 'booking' ),
252 'default' => '',
253 'label_block' => true,
254 'description' => '<strong>' . esc_html__('Optional', 'booking') . '!</strong> ' . esc_html__( 'Format: YYYY-MM-DD (e.g. 2025-07-26)', 'booking' ),
255 'picker_options' => [
256 'enableTime' => false,
257 'dateFormat' => 'Y-m-d', // '2025-07-26' format
258 ],
259 ]
260 );
261
262 $this->add_control(
263 'wpbc_booking_calendar_dates_end',
264 [
265 'type' => \Elementor\Controls_Manager::DATE_TIME,
266 'label' => esc_html__( 'Latest date visible/selectable in the calendar.', 'booking' ),
267 'default' => '',
268 'label_block' => true,
269 'description' => '<strong>' . esc_html__('Optional', 'booking') . '!</strong> ' . esc_html__( 'Format: YYYY-MM-DD (e.g. 2025-12-31)', 'booking' ),
270 'picker_options' => [
271 'enableTime' => false,
272 'dateFormat' => 'Y-m-d', // '2025-07-26' format
273 ],
274 ]
275 );
276
277 $this->add_control(
278 'wpbc_booking_calendar_startmonth',
279 [
280 'type' => \Elementor\Controls_Manager::DATE_TIME,
281 'label' => esc_html__( 'Select start month of calendar after loading.', 'booking' ),
282 'default' => '',
283 'label_block' => true,
284 'description' => '<strong>' . esc_html__('Optional', 'booking') . '!</strong> ' . esc_html__( 'Format: YYYY-MM (e.g. 2025-3)', 'booking' ),
285 'picker_options' => [
286 'enableTime' => false,
287 'dateFormat' => 'Y-m', // '2025-07-26' format
288 ],
289 ]
290 );
291 $this->add_control(
292 'wpbc_booking_calendar_dates_reset_button',
293 [
294 'type' => \Elementor\Controls_Manager::RAW_HTML,
295 'raw' => '<button type="button" class="elementor-button wpbc-reset-dates-button" style="margin-top:10px;">'.esc_html__('Reset Dates','booking').'</button>',
296 'content_classes' => 'wpbc-calendar-dates-reset-wrapper',
297 ]
298 );
299
300 $this->end_controls_section();
301
302
303 $this->start_controls_section(
304 'wpbc_theme_section',
305 [
306 'label' => esc_html__( 'Appearance & Color Themes', 'booking' ),
307 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
308 ]
309 );
310
311 $this->add_control(
312 'wpbc_calendar_skin_control',
313 [
314 'label' => esc_html__( 'Calendar Theme (Skin)', 'booking' ),
315 'type' => 'wpbc_calendar_skin_selection',
316 'frontend_available' => false,
317 'render_type' => 'none',
318 'label_block' => true,
319 ]
320 );
321
322 $this->end_controls_section();
323 }
324
325
326 /**
327 * Render list widget output on the frontend.
328 *
329 * Written in PHP and used to generate the final HTML.
330 *
331 * @since 1.0.0
332 * @access protected
333 */
334 protected function render(): void {
335
336 $shortcode_params = array();
337 $settings = $this->get_settings_for_display();
338
339 // Shortcode type.
340 $allowed_shortcodes = array( 'booking', 'bookingcalendar' );
341 $shortcode_type = in_array( $settings['wpbc_booking_shortcode'], $allowed_shortcodes, true ) ? $settings['wpbc_booking_shortcode'] : 'booking';
342
343 // Number of months.
344 $months_number = isset( $settings['wpbc_booking_months_number'] ) ? intval( $settings['wpbc_booking_months_number'] ) : 1;
345 if ( $months_number > 1 ) {
346 $shortcode_params[] = "nummonths={$months_number}";
347 }
348
349 // Booking resource (if personal version is active).
350 if ( class_exists( 'wpdev_bk_personal' ) && ! empty( $settings['wpbc_booking_resource_id'] ) && intval( $settings['wpbc_booking_resource_id'] ) > 1 ) {
351 $resource_id = intval( $settings['wpbc_booking_resource_id'] );
352 $shortcode_params[] = "resource_id={$resource_id}";
353 }
354
355 // Is custom use form ?
356 if ( ( class_exists( 'wpdev_bk_biz_m' ) ) && ! empty( $settings['wpbc_custom_form_id'] ) ) {
357 $wpbc_custom_form_id = sanitize_text_field( $settings['wpbc_custom_form_id'] );
358 if ( 'standard' !== $wpbc_custom_form_id ) {
359 $shortcode_params[] = "form_type='{$wpbc_custom_form_id}'";
360 }
361 }
362
363 // wpbc_booking_calendar_dates_start / calendar_dates_end / startmonth .
364 if ( ! empty( $settings['wpbc_booking_calendar_dates_start'] ) ) {
365 $shortcode_params[] = "calendar_dates_start='" . $settings['wpbc_booking_calendar_dates_start'] . "'";
366 }
367 if ( ! empty( $settings['wpbc_booking_calendar_dates_end'] ) ) {
368 $shortcode_params[] = "calendar_dates_end='" . $settings['wpbc_booking_calendar_dates_end'] . "'";
369 }
370 if ( ! empty( $settings['wpbc_booking_calendar_startmonth'] ) ) {
371 $shortcode_params[] = "startmonth='" . $settings['wpbc_booking_calendar_startmonth'] . "'";
372 }
373
374
375
376 // Final parameters string.
377 $shortcode_params_str = implode( ' ', $shortcode_params );
378
379 echo do_shortcode( '[' . $shortcode_type . ' ' . $shortcode_params_str . ']' );
380 }
381
382 public function get_script_depends(): array {
383 return array( 'wpbc-elementor-frontend-bridge' );
384 }
385
386 public function get_style_depends(): array {
387 return array( 'wpbc-elementor-frontend-bridge' );
388 }
389
390 }