PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.11
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.11
5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / shortcodes_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 3 months ago agent_helper.php 3 months ago analytics_helper.php 4 months ago auth_helper.php 3 months ago blocks_helper.php 3 months ago booking_helper.php 3 months ago bricks_helper.php 3 months ago bundles_helper.php 3 months ago calendar_helper.php 3 months ago carts_helper.php 3 months ago connector_helper.php 3 months ago csv_helper.php 3 months ago customer_helper.php 3 months ago customer_import_helper.php 3 months ago database_helper.php 3 months ago debug_helper.php 3 months ago defaults_helper.php 3 months ago elementor_helper.php 3 months ago email_helper.php 3 months ago encrypt_helper.php 3 months ago events_helper.php 3 months ago form_helper.php 3 months ago icalendar_helper.php 3 months ago image_helper.php 3 months ago invoices_helper.php 3 months ago license_helper.php 3 months ago location_helper.php 3 months ago marketing_systems_helper.php 3 months ago meeting_systems_helper.php 3 months ago menu_helper.php 3 months ago meta_helper.php 3 months ago migrations_helper.php 3 months ago money_helper.php 3 months ago notifications_helper.php 3 months ago nps_survey_helper.php 3 months ago order_intent_helper.php 3 months ago orders_helper.php 3 months ago otp_helper.php 3 months ago pages_helper.php 3 months ago params_helper.php 3 months ago payments_helper.php 3 months ago price_breakdown_helper.php 3 months ago process_jobs_helper.php 3 months ago processes_helper.php 3 months ago replacer_helper.php 3 months ago resource_helper.php 3 months ago roles_helper.php 3 months ago router_helper.php 3 months ago service_helper.php 3 months ago sessions_helper.php 3 months ago settings_helper.php 3 months ago short_links_systems_helper.php 3 months ago shortcodes_helper.php 3 months ago sms_helper.php 3 months ago steps_helper.php 3 months ago stripe_connect_helper.php 3 months ago styles_helper.php 3 months ago support_topics_helper.php 3 months ago time_helper.php 3 months ago timeline_helper.php 3 months ago transaction_helper.php 3 months ago transaction_intent_helper.php 3 months ago util_helper.php 3 months ago version_specific_updates_helper.php 3 months ago whatsapp_helper.php 3 months ago work_periods_helper.php 3 months ago wp_datetime.php 3 months ago wp_user_helper.php 3 months ago
shortcodes_helper.php
461 lines
1 <?php
2
3 class OsShortcodesHelper {
4
5 // [latepoint_calendar]
6 public static function shortcode_latepoint_calendar( array $atts = [] ): string {
7 $atts = shortcode_atts(
8 [
9 'date' => 'now',
10 'show_services' => false,
11 'show_agents' => false,
12 'show_locations' => false,
13 'view' => 'month',
14 ],
15 $atts
16 );
17 $output = '';
18 try {
19 $target_date = new OsWpDateTime( $atts['date'] );
20 } catch ( Exception $e ) {
21 $target_date = new OsWpDateTime( 'now' );
22 }
23
24 $restrictions = [];
25 if ( $atts['show_services'] ) {
26 $restrictions['show_services'] = $atts['show_services'];
27 }
28 if ( $atts['show_agents'] ) {
29 $restrictions['show_agents'] = $atts['show_agents'];
30 }
31 if ( $atts['show_locations'] ) {
32 $restrictions['show_locations'] = $atts['show_locations'];
33 }
34 $output .= OsEventsHelper::events_grid( $target_date, [], $atts['view'], $restrictions );
35
36 return $output;
37 }
38
39 // [latepoint_resources]
40 public static function shortcode_latepoint_resources( $atts ) {
41 $atts = shortcode_atts(
42 array(
43 'id' => false,
44 'button_caption' => esc_html__( 'Book Now', 'latepoint' ),
45 'items' => 'services', // services, agents, locations, bundles
46 'item_ids' => '',
47 'group_ids' => '',
48 'columns' => 4,
49 'limit' => false,
50 'button_border_radius' => false,
51 'button_bg_color' => false,
52 'button_text_color' => false,
53 'button_font_size' => false,
54 'show_locations' => false,
55 'show_agents' => false,
56 'show_services' => false,
57 'show_service_categories' => false,
58 'selected_location' => false,
59 'selected_bundle' => false,
60 'selected_agent' => false,
61 'selected_service' => false,
62 'selected_duration' => false,
63 'selected_total_attendees' => false,
64 'selected_service_category' => false,
65 'calendar_start_date' => false,
66 'selected_start_date' => false,
67 'selected_start_time' => false,
68 'hide_side_panel' => false,
69 'hide_summary' => false,
70 'hide_image' => false,
71 'hide_price' => false,
72 'hide_description' => false,
73 'source_id' => false,
74 'classname' => false,
75 'btn_classes' => false,
76 'btn_wrapper_classes' => false,
77 ),
78 $atts
79 );
80
81 if ( $atts['items'] == 'bundles' && $atts['selected_service'] ) {
82 $atts['selected_service'] = false;
83 }
84 if ( $atts['items'] == 'services' && $atts['selected_bundle'] ) {
85 $atts['selected_bundle'] = false;
86 }
87
88 // Data attributes setup
89 $data_atts = '';
90 if ( ( $atts['items'] != 'locations' ) && $atts['show_locations'] ) {
91 $data_atts .= 'data-show-locations="' . esc_attr( $atts['show_locations'] ) . '" ';
92 }
93 if ( ( $atts['items'] != 'agents' ) && $atts['show_agents'] ) {
94 $data_atts .= 'data-show-agents="' . esc_attr( $atts['show_agents'] ) . '" ';
95 }
96 if ( ( $atts['items'] != 'services' ) && $atts['show_services'] ) {
97 $data_atts .= 'data-show-services="' . esc_attr( $atts['show_services'] ) . '" ';
98 }
99 if ( ( $atts['items'] != 'services' ) && $atts['show_service_categories'] ) {
100 $data_atts .= 'data-show-service-categories="' . esc_attr( $atts['show_service_categories'] ) . '" ';
101 }
102 if ( ( $atts['items'] != 'locations' ) && $atts['selected_location'] ) {
103 $data_atts .= 'data-selected-location="' . esc_attr( $atts['selected_location'] ) . '" ';
104 }
105 if ( ( $atts['items'] != 'agents' ) && $atts['selected_agent'] ) {
106 $data_atts .= 'data-selected-agent="' . esc_attr( $atts['selected_agent'] ) . '" ';
107 }
108 if ( ( $atts['items'] != 'bundles' ) && $atts['selected_bundle'] ) {
109 $data_atts .= 'data-selected-bundle="' . esc_attr( $atts['selected_bundle'] ) . '" ';
110 }
111 if ( ( $atts['items'] != 'services' ) && $atts['selected_service'] ) {
112 $data_atts .= 'data-selected-service="' . esc_attr( $atts['selected_service'] ) . '" ';
113 }
114 if ( $atts['selected_duration'] ) {
115 $data_atts .= 'data-selected-duration="' . esc_attr( $atts['selected_duration'] ) . '" ';
116 }
117 if ( $atts['selected_total_attendees'] ) {
118 $data_atts .= 'data-selected-total-attendees="' . esc_attr( $atts['selected_total_attendees'] ) . '" ';
119 }
120 if ( ( $atts['items'] != 'services' ) && $atts['selected_service_category'] ) {
121 $data_atts .= 'data-selected-service-category="' . esc_attr( $atts['selected_service_category'] ) . '" ';
122 }
123 if ( $atts['calendar_start_date'] ) {
124 $data_atts .= 'data-calendar-start-date="' . esc_attr( $atts['calendar_start_date'] ) . '" ';
125 }
126 if ( $atts['selected_start_date'] ) {
127 $data_atts .= 'data-selected-start-date="' . esc_attr( $atts['selected_start_date'] ) . '" ';
128 }
129 if ( $atts['selected_start_time'] ) {
130 $data_atts .= 'data-selected-start-time="' . esc_attr( $atts['selected_start_time'] ) . '" ';
131 }
132 if ( $atts['hide_side_panel'] == 'yes' ) {
133 $data_atts .= 'data-hide-side-panel="yes" ';
134 }
135 if ( $atts['hide_summary'] == 'yes' ) {
136 $data_atts .= 'data-hide-summary="yes" ';
137 }
138 if ( $atts['source_id'] ) {
139 $data_atts .= 'data-source-id="' . esc_attr( $atts['source_id'] ) . '" ';
140 }
141
142 $block_classes = $atts['classname'] ? ' ' . $atts['classname'] : '';
143 $resource_item_classes = $atts['id'] ? ' resource-item-' . $atts['id'] : '';
144
145 $btn_wrapper_classes = $atts['btn_wrapper_classes'] ?: ' wp-block-button';
146 $btn_classes = $atts['btn_classes'] ?: ' wp-block-button__link';
147
148 $output = '<div class="latepoint-resources-items-w resources-columns-' . esc_attr( $atts['columns'] ) . esc_attr( $block_classes ) . '">';
149
150 if ( $atts['item_ids'] ) {
151 $ids = OsUtilHelper::explode_and_trim( $atts['item_ids'] );
152 $clean_item_ids = OsUtilHelper::clean_numeric_ids( $ids );
153 } else {
154 $clean_item_ids = [];
155 }
156 if ( $atts['group_ids'] ) {
157 $ids = OsUtilHelper::explode_and_trim( $atts['group_ids'] );
158 $clean_group_ids = OsUtilHelper::clean_numeric_ids( $ids );
159 } else {
160 $clean_group_ids = [];
161 }
162 switch ( $atts['items'] ) {
163 case 'services':
164 $services = new OsServiceModel();
165 if ( $atts['limit'] && is_numeric( $atts['limit'] ) ) {
166 $services->set_limit( $atts['limit'] );
167 }
168 if ( $clean_item_ids ) {
169 $services->where( [ 'id' => $clean_item_ids ] );
170 }
171 if ( $clean_group_ids ) {
172 $services->where( [ 'category_id' => $clean_group_ids ] );
173 }
174 $services = $services->should_be_active()->should_not_be_hidden()->order_by( 'order_number asc' )->get_results_as_models();
175 foreach ( $services as $service ) {
176 $output .= '<div class="resource-item ' . esc_attr( $resource_item_classes ) . '">';
177 if ( $atts['hide_image'] !== 'yes' && ! empty( $service->description_image_id ) ) {
178 $output .= '<div class="ri-media" style="background-image: url(' . $service->get_description_image_url() . ')"></div>';
179 }
180 $output .= '<div class="ri-name"><h3>' . esc_html( $service->name ) . '</h3></div>';
181
182 if ( $atts['hide_price'] !== 'yes' && $service->price_min > 0 ) {
183 $service_price_formatted = ( $service->price_min != $service->price_max ) ? __( 'Starts at', 'latepoint' ) . ' ' . $service->price_min_formatted : $service->price_min_formatted;
184 $output .= '<div class="ri-price">' . $service_price_formatted . '</div>';
185 }
186 if ( $atts['hide_description'] !== 'yes' && ! empty( $service->short_description ) ) {
187 $output .= '<div class="ri-description">' . wp_kses_post( $service->short_description ) . '</div>';
188 }
189 $output .= '<div class="ri-buttons ' . esc_attr( $btn_wrapper_classes ) . '">
190 <a href="#" ' . $data_atts . ' class="latepoint-book-button os_trigger_booking ' . esc_attr( $btn_classes ) . '" data-selected-service="' . esc_attr( $service->id ) . '">' . wp_kses_post( $atts['button_caption'] ) . '</a>
191 </div>';
192 $output .= '</div>';
193 }
194 break;
195 case 'agents':
196 $agents = new OsAgentModel();
197 if ( $atts['limit'] && is_numeric( $atts['limit'] ) ) {
198 $agents->set_limit( $atts['limit'] );
199 }
200 if ( $atts['item_ids'] ) {
201 $ids = OsUtilHelper::explode_and_trim( $atts['item_ids'] );
202 $ids = OsUtilHelper::clean_numeric_ids( $ids );
203 if ( $ids ) {
204 $agents->where( [ 'id' => $ids ] );
205 }
206 }
207 if ( $clean_item_ids ) {
208 $agents->where( [ 'id' => $clean_item_ids ] );
209 }
210 $agents = $agents->should_be_active()->get_results_as_models();
211 foreach ( $agents as $agent ) {
212 $output .= '<div class="resource-item ' . esc_attr( $resource_item_classes ) . ' ri-centered">';
213 $output .= ! empty( $agent->avatar_image_id ) ? '<div class="ri-avatar" style="background-image: url(' . $agent->get_avatar_url() . ')"></div>' : '';
214 $output .= '<div class="ri-name"><h3>' . esc_html( $agent->full_name ) . '</h3></div>';
215 $output .= ! empty( $agent->title ) ? '<div class="ri-title">' . esc_html( $agent->title ) . '</div>' : '';
216 $output .= ! empty( $agent->short_description ) ? '<div class="ri-description">' . wp_kses_post( $agent->short_description ) . '</div>' : '';
217 $output .= '<div class="ri-buttons ' . esc_attr( $btn_wrapper_classes ) . '">
218 <a href="#" ' . $data_atts . ' class="latepoint-book-button os_trigger_booking latepoint-btn-block ' . esc_attr( $btn_classes ) . '" data-selected-agent="' . esc_attr( $agent->id ) . '">' . wp_kses_post( $atts['button_caption'] ) . '</a>
219 </div>';
220 $output .= '</div>';
221 }
222 break;
223 case 'locations':
224 $locations = new OsLocationModel();
225 if ( $atts['limit'] && is_numeric( $atts['limit'] ) ) {
226 $locations->set_limit( $atts['limit'] );
227 }
228 if ( $clean_item_ids ) {
229 $locations->where( [ 'id' => $clean_item_ids ] );
230 }
231 if ( $clean_group_ids ) {
232 $locations->where( [ 'category_id' => $clean_group_ids ] );
233 }
234 $locations = $locations->should_be_active()->order_by( 'order_number asc' )->get_results_as_models();
235 foreach ( $locations as $location ) {
236 $output .= '<div class="resource-item ' . esc_attr( $resource_item_classes ) . '">';
237 $output .= ! empty( $location->full_address ) ? '<div class="ri-map">' . $location->get_google_maps_iframe( 200 ) . '</div>' : '';
238 $output .= '<div class="ri-name"><h3>' . esc_html( $location->name ) . '</h3></div>';
239 $output .= ! empty( $location->full_address ) ? '<div class="ri-description">' . $location->full_address . '<a href="' . $location->get_google_maps_link() . '" target="_blank" class="ri-external-link"><i class="latepoint-icon latepoint-icon-external-link"></i></a></div>' : '';
240 $output .= '<div class="ri-buttons ' . $btn_wrapper_classes . '">
241 <a href="#" ' . $data_atts . ' class="latepoint-book-button os_trigger_booking ' . esc_attr( $btn_classes ) . '" data-selected-location="' . esc_attr( $location->id ) . '">' . wp_kses_post( $atts['button_caption'] ) . '</a>
242 </div>';
243 $output .= '</div>';
244 }
245 break;
246 case 'bundles':
247 $bundles = new OsBundleModel();
248
249 if ( $clean_item_ids ) {
250 $bundles->where( [ 'id' => $clean_item_ids ] );
251 }
252
253 if ( $atts['limit'] && is_numeric( $atts['limit'] ) ) {
254 $bundles->set_limit( $atts['limit'] );
255 }
256
257 $bundles = $bundles->should_be_active()->should_not_be_hidden()->order_by( 'order_number asc' )->get_results_as_models();
258 $bundles = is_array( $bundles ) ? $bundles : [ $bundles ];
259
260 ob_start();
261 foreach ( $bundles as $bundle ) {
262 ?>
263 <div class="resource-item <?php echo esc_attr( $resource_item_classes ); ?>">
264 <div class="ri-name">
265 <h3><?php echo esc_html( $bundle->name ); ?></h3>
266 </div>
267 <?php if ( $atts['hide_price'] !== 'yes' && $price = $bundle->get_formatted_charge_amount() ) { ?>
268 <div class="ri-price"><?php echo $price; ?></div>
269 <?php } ?>
270
271 <?php if ( $atts['hide_description'] !== 'yes' && $description = $bundle->short_description ) { ?>
272 <div class="ri-description"><?php echo $description; ?></div>
273 <?php } ?>
274 <div class="ri-buttons <?php echo esc_attr( $btn_wrapper_classes ) ?>">
275 <a href="#" <?php echo $data_atts ?>
276 class="latepoint-book-button os_trigger_booking latepoint-btn-block <?php echo esc_attr( $btn_classes ); ?>"
277 data-selected-bundle="<?php echo $bundle->id; ?>" >
278 <?php echo $atts['button_caption']; ?>
279 </a>
280 </div>
281 </div>
282 <?php }
283
284 $output .= ob_get_clean();
285 break;
286 }
287 $output .= '</div>';
288
289 return $output;
290 }
291
292 // [latepoint_book_form]
293 public static function shortcode_latepoint_book_form( $atts, $content = '' ) {
294
295 $atts = shortcode_atts( self::get_default_booking_atts(), $atts );
296 $element_classes = [ 'latepoint-inline-form' ];
297 $element_classes[] = ( empty( $atts['hide_side_panel'] ) || $atts['hide_side_panel'] == 'no' ) ? 'latepoint-show-side-panel' : 'latepoint-hide-side-panel';
298 $output = '<div class="latepoint-book-form-wrapper os-loading os_init_booking_form" id="latepointBookForm_' . esc_attr( uniqid() ) . '" ' . self::generate_data_atts_string_from_atts( $atts ) . '>
299 <div class="latepoint-w ' . esc_attr( implode( ' ', $element_classes ) ) . '">
300 <div class="latepoint-booking-form-element">
301 <div class="latepoint-side-panel"></div>
302 <div class="latepoint-form-w"></div>
303 </div>
304 </div>
305 </div>';
306
307 return $output;
308 }
309
310
311 // [latepoint_book_button]
312 public static function shortcode_latepoint_book_button( $atts, $content = '' ) {
313 $atts = shortcode_atts(
314 array_merge(
315 self::get_default_booking_atts(),
316 [
317 'id' => false,
318 'caption' => __( 'Book Appointment', 'latepoint' ),
319 'is_inherit' => false,
320 'align' => false,
321 'bg_color' => false,
322 'text_color' => false,
323 'font_size' => false,
324 'border' => false,
325 'border_radius' => false,
326 'margin' => false,
327 'padding' => false,
328 'css' => false,
329 'classname' => false,
330 'btn_classes' => false,
331 'btn_wrapper_classes' => false,
332 ]
333 ),
334 $atts
335 );
336
337 $btn_wrapper_classes = [];
338 $btn_wrapper_classes[] = $atts['btn_wrapper_classes'] ?: 'wp-block-button';
339 if ( $atts['align'] ) {
340 $btn_wrapper_classes[] = "latepoint-book-button-align-{$atts['align']}";
341 }
342 if ( $atts['classname'] ) {
343 $btn_wrapper_classes[] = $atts['classname'];
344 }
345
346 $btn_classes = [];
347 $btn_classes[] = $atts['btn_classes'] ?: 'wp-block-button__link';
348 if ( $atts['id'] ) {
349 $btn_classes[] = 'latepoint-book-button-' . $atts['id'];
350 }
351
352 $data_atts = self::generate_data_atts_string_from_atts( $atts );
353
354 $styles = [];
355 # if not inherit - show button styles
356 if ( ! $atts['is_inherit'] ) {
357 if ( $atts['bg_color'] ) {
358 $styles[] = 'background-color: ' . esc_attr( $atts['bg_color'] );
359 }
360 if ( $atts['text_color'] ) {
361 $styles[] = 'color: ' . esc_attr( $atts['text_color'] );
362 }
363 if ( $atts['font_size'] ) {
364 $styles[] = 'font-size: ' . esc_attr( $atts['font_size'] );
365 }
366 if ( $atts['border'] ) {
367 $styles[] = 'border: ' . esc_attr( $atts['border'] );
368 }
369 if ( $atts['border_radius'] ) {
370 $styles[] = 'border-radius: ' . esc_attr( $atts['border_radius'] );
371 }
372 if ( $atts['margin'] ) {
373 $styles[] = 'margin: ' . esc_attr( $atts['margin'] );
374 }
375 if ( $atts['padding'] ) {
376 $styles[] = 'padding: ' . esc_attr( $atts['padding'] );
377 }
378 if ( $atts['css'] ) {
379 $styles[] = $atts['css'];
380 }
381 }
382 $style_attr = ! empty( $styles ) ? ' style="' . esc_attr( implode( '; ', $styles ) ) . '"' : '';
383
384 $before_html = '<div class="latepoint-book-button-wrapper ' . esc_attr( implode( ' ', $btn_wrapper_classes ) ) . '">';
385 $after_html = '</div>';
386
387 return $before_html . '<a href="#" class="latepoint-book-button os_trigger_booking ' .
388 esc_attr( implode( ' ', $btn_classes ) ) . '"' . $style_attr . ' ' . $data_atts . '>' .
389 esc_html( $atts['caption'] ) . '</a>' . $after_html;
390 }
391
392 // [latepoint_customer_dashboard]
393 public static function shortcode_latepoint_customer_dashboard( $atts ) {
394 $atts = shortcode_atts(
395 array(
396 'caption' => __( 'Book Appointment', 'latepoint' ),
397 'hide_new_appointment_ui' => false,
398 ),
399 $atts
400 );
401 $atts['hide_new_appointment_ui'] = $atts['hide_new_appointment_ui'] == 'yes' ?? false;
402
403 $customerCabinetController = new OsCustomerCabinetController();
404 $output = $customerCabinetController->dashboard( $atts );
405
406 return $output;
407 }
408
409 // [latepoint_customer_login]
410 public static function shortcode_latepoint_customer_login( $atts ) {
411 $atts = shortcode_atts(
412 array(
413 'caption' => __( 'Book Appointment', 'latepoint' ),
414 ),
415 $atts
416 );
417
418 $customerCabinetController = new OsCustomerCabinetController();
419 $output = $customerCabinetController->login();
420
421 return $output;
422 }
423
424 /**
425 * List of default booking attributes for booking button and form shortcodes
426 *
427 * @return false[]
428 */
429 private static function get_default_booking_atts(): array {
430 return [
431 'show_locations' => false,
432 'show_agents' => false,
433 'show_services' => false,
434 'show_service_categories' => false,
435 'selected_location' => false,
436 'selected_agent' => false,
437 'selected_service' => false,
438 'selected_duration' => false,
439 'selected_total_attendees' => false,
440 'selected_service_category' => false,
441 'selected_bundle' => false,
442 'calendar_start_date' => false,
443 'selected_start_date' => false,
444 'selected_start_time' => false,
445 'hide_side_panel' => false,
446 'hide_summary' => false,
447 'source_id' => false,
448 ];
449 }
450
451 private static function generate_data_atts_string_from_atts( array $atts ): string {
452 $data_atts = '';
453 $defaults = self::get_default_booking_atts();
454 foreach ( $defaults as $key => $value ) {
455 if ( ! empty( $atts[ $key ] ) ) {
456 $data_atts .= 'data-' . esc_html( str_replace( '_', '-', $key ) ) . '="' . esc_attr( $atts[ $key ] ) . '" ';
457 }
458 }
459 return $data_atts;
460 }
461 }