PluginProbe
Elementor Website Builder – more than just a page builder / 3.29.2
Elementor Website Builder – more than just a page builder v3.29.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / floating-buttons / classes / render / contact-buttons-render-base.php

contact-buttons-render-base.php in Elementor Website Builder – more than just a page builder 3.29.2, at modules/floating-buttons/classes/render/contact-buttons-render-base.php

488 lines 16.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\FloatingButtons\Classes\Render;
4
5 use Elementor\Core\Base\Providers\Social_Network_Provider;
6 use Elementor\Icons_Manager;
7 use Elementor\Modules\FloatingButtons\Base\Widget_Contact_Button_Base;
8 use Elementor\Utils;
9
10 /**
11 * Class Contact_Buttons_Render_Base.
12 *
13 * This is the base class that will hold shared functionality that will be needed by all the various widget versions.
14 *
15 * @since 3.23.0
16 */
17 abstract class Contact_Buttons_Render_Base {
18
19 protected Widget_Contact_Button_Base $widget;
20
21 protected array $settings;
22
23
24 abstract public function render(): void;
25
26 public function __construct( Widget_Contact_Button_Base $widget ) {
27 $this->widget = $widget;
28 $this->settings = $widget->get_settings_for_display();
29 }
30
31 protected function render_chat_button_icon(): void {
32 $platform = $this->settings['chat_button_platform'] ?? '';
33
34 $mapping = Social_Network_Provider::get_icon_mapping( $platform );
35 $icon_lib = explode( ' ', $mapping )[0];
36 $library = 'fab' === $icon_lib ? 'fa-brands' : 'fa-solid';
37 Icons_Manager::render_icon(
38 [
39 'library' => $library,
40 'value' => $mapping,
41 ],
42 [ 'aria-hidden' => 'true' ]
43 );
44 }
45
46 protected function render_chat_button(): void {
47 $platform = $this->settings['chat_button_platform'] ?? '';
48 $display_dot = $this->settings['chat_button_show_dot'] ?? '';
49 $button_size = $this->settings['style_chat_button_size'];
50 $hover_animation = $this->settings['style_button_color_hover_animation'];
51 $entrance_animation = $this->settings['style_chat_button_animation'];
52 $entrance_animation_duration = $this->settings['style_chat_button_animation_duration'];
53 $entrance_animation_delay = $this->settings['style_chat_button_animation_delay'];
54 $accessible_name = $this->settings['chat_aria_label'];
55
56 $button_classnames = 'e-contact-buttons__chat-button e-contact-buttons__chat-button-shadow';
57
58 if ( ! empty( $button_size ) ) {
59 $button_classnames .= ' has-size-' . $button_size;
60 }
61
62 if ( ! empty( $hover_animation ) ) {
63 $button_classnames .= ' elementor-animation-' . $hover_animation;
64 }
65
66 if ( ! empty( $entrance_animation ) && 'none' != $entrance_animation ) {
67 $button_classnames .= ' has-entrance-animation';
68 }
69
70 if ( ! empty( $entrance_animation_delay ) ) {
71 $button_classnames .= ' has-entrance-animation-delay';
72 }
73
74 if ( ! empty( $entrance_animation_duration ) ) {
75 $button_classnames .= ' has-entrance-animation-duration-' . $entrance_animation_duration;
76 }
77
78 if ( 'yes' === $display_dot ) {
79 $button_classnames .= ' has-dot';
80 }
81
82 $this->widget->add_render_attribute( 'button', [
83 'class' => $button_classnames,
84 'aria-controls' => 'e-contact-buttons__content-wrapper',
85 'aria-label' => sprintf(
86 /* translators: 1: Accessible name. */
87 esc_html__( 'Toggle %1$s', 'elementor' ),
88 $accessible_name,
89 ),
90 'type' => 'button',
91 ] );
92
93 ?>
94 <div class="e-contact-buttons__chat-button-container">
95 <button <?php echo $this->widget->get_render_attribute_string( 'button' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
96 <?php
97 $this->render_chat_button_icon();
98 ?>
99 </button>
100 </div>
101 <?php
102 }
103
104 protected function render_close_button(): void {
105 $accessible_name = $this->settings['chat_aria_label'];
106
107 $this->widget->add_render_attribute( 'close-button', [
108 'class' => 'e-contact-buttons__close-button',
109 'aria-controls' => 'e-contact-buttons__content-wrapper',
110 'aria-label' => sprintf(
111 /* translators: 1: Accessible name. */
112 esc_html__( 'Close %1$s', 'elementor' ),
113 $accessible_name,
114 ),
115 'type' => 'button',
116 ] );
117
118 ?>
119 <button <?php echo $this->widget->get_render_attribute_string( 'close-button' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
120 <i class="eicon-close"></i>
121 </button>
122 <?php
123 }
124
125 protected function render_top_bar(): void {
126 $profile_image_value = $this->settings['top_bar_image'] ?? [];
127 $has_profile_image = ! empty( $profile_image_value ) && ( ! empty( $profile_image_value['url'] || ! empty( $profile_image_value['id'] ) ) );
128 $profile_image_size = $this->settings['style_top_bar_image_size'];
129 $display_profile_dot = $this->settings['top_bar_show_dot'];
130
131 $profile_image_classnames = 'e-contact-buttons__profile-image';
132
133 if ( ! empty( $profile_image_size ) ) {
134 $profile_image_classnames .= ' has-size-' . $profile_image_size;
135 }
136
137 if ( 'yes' === $display_profile_dot ) {
138 $profile_image_classnames .= ' has-dot';
139 }
140
141 $top_bar_title = $this->settings['top_bar_title'] ?? '';
142 $top_bar_subtitle = $this->settings['top_bar_subtitle'] ?? '';
143
144 $has_top_bar_title = ! empty( $top_bar_title );
145 $has_top_bar_subtitle = ! empty( $top_bar_subtitle );
146
147 $this->widget->add_render_attribute( 'profile-image', [
148 'class' => $profile_image_classnames,
149 ] );
150 ?>
151 <div class="e-contact-buttons__top-bar">
152 <?php $this->render_close_button(); ?>
153 <div <?php echo $this->widget->get_render_attribute_string( 'profile-image' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
154 <?php if ( ! empty( $profile_image_value['id'] ) ) {
155 echo wp_get_attachment_image( $profile_image_value['id'], 'medium', false, [
156 'class' => 'e-contact-buttons__profile-image-el',
157 ] );
158 } else {
159 $this->widget->add_render_attribute( 'profile-image-src', [
160 'alt' => '',
161 'class' => 'e-contact-buttons__profile-image-el',
162 'src' => esc_url( $profile_image_value['url'] ),
163 ] );
164 ?>
165 <img <?php echo $this->widget->get_render_attribute_string( 'profile-image-src' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> />
166 <?php }; ?>
167 </div>
168
169 <div class="e-contact-buttons__top-bar-details">
170 <?php if ( $has_top_bar_title ) { ?>
171 <p class="e-contact-buttons__top-bar-title"><?php echo esc_html( $top_bar_title ); ?></p>
172 <?php } ?>
173 <?php if ( $has_top_bar_subtitle ) { ?>
174 <p class="e-contact-buttons__top-bar-subtitle"><?php echo esc_html( $top_bar_subtitle ); ?></p>
175 <?php } ?>
176 </div>
177 </div>
178 <?php
179 }
180
181 protected function render_message_bubble_typing_animation(): void {
182 $has_typing_animation = 'yes' === $this->settings['chat_button_show_animation'];
183 ?>
184 <?php if ( $has_typing_animation ) { ?>
185 <div class="e-contact-buttons__dots-container">
186 <span class="e-contact-buttons__dot e-contact-buttons__dot-1"></span>
187 <span class="e-contact-buttons__dot e-contact-buttons__dot-2"></span>
188 <span class="e-contact-buttons__dot e-contact-buttons__dot-3"></span>
189 </div>
190 <?php } ?>
191 <?php
192 }
193
194 protected function render_message_bubble_container(): void {
195 $message_bubble_name = $this->settings['message_bubble_name'] ?? '';
196 $message_bubble_body = $this->settings['message_bubble_body'] ?? '';
197 $has_message_bubble_name = ! empty( $message_bubble_name );
198 $has_message_bubble_body = ! empty( $message_bubble_body );
199 $time_format = $this->settings['chat_button_time_format'];
200 ?>
201 <div class="e-contact-buttons__bubble-container">
202 <div class="e-contact-buttons__bubble">
203 <?php if ( $has_message_bubble_name ) { ?>
204 <p class="e-contact-buttons__message-bubble-name"><?php echo esc_html( $message_bubble_name ); ?></p>
205 <?php } ?>
206 <?php if ( $has_message_bubble_body ) { ?>
207 <p class="e-contact-buttons__message-bubble-body"><?php echo esc_html( $message_bubble_body ); ?></p>
208 <?php } ?>
209 <p class="e-contact-buttons__message-bubble-time" data-time-format="<?php echo esc_attr( $time_format ); ?>"></p>
210 </div>
211 </div>
212 <?php
213 }
214
215 protected function render_message_bubble_powered_by(): void {
216 if ( Utils::has_pro() ) {
217 return;
218 }
219 ?>
220 <div class="e-contact-buttons__powered-container">
221 <p class="e-contact-buttons__powered-text">
222 <?php echo esc_attr__( 'Powered by Elementor', 'elementor' ); ?>
223 </p>
224 </div>
225 <?php
226 }
227
228 protected function render_message_bubble(): void {
229 $message_bubble_classnames = 'e-contact-buttons__message-bubble';
230 $show_animation = $this->settings['chat_button_show_animation'] ?? false;
231 $has_typing_animation = $show_animation && 'yes' === $show_animation;
232
233 if ( $has_typing_animation ) {
234 $message_bubble_classnames .= ' has-typing-animation';
235 }
236
237 $this->widget->add_render_attribute( 'message-bubble', [
238 'class' => $message_bubble_classnames,
239 ] );
240 ?>
241 <div <?php echo $this->widget->get_render_attribute_string( 'message-bubble' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
242 <?php
243 $this->render_message_bubble_typing_animation();
244 $this->render_message_bubble_container();
245 ?>
246 </div>
247 <?php
248 }
249
250 protected function render_contact_text(): void {
251 $contact_cta_text = $this->settings['contact_cta_text'] ?? '';
252 ?>
253 <?php if ( ! empty( $contact_cta_text ) ) { ?>
254 <p class="e-contact-buttons__contact-text"><?php echo esc_html( $contact_cta_text ); ?></p>
255 <?php } ?>
256 <?php
257 }
258
259 protected function render_contact_links(): void {
260 $contact_icons = $this->settings['contact_repeater'] ?? [];
261 $icons_size = $this->settings['style_contact_button_size'] ?? 'small';
262 $hover_animation = $this->settings['style_contact_button_hover_animation'];
263 ?>
264 <div class="e-contact-buttons__contact-links">
265 <?php
266 foreach ( $contact_icons as $key => $icon ) {
267 $icon_text_mapping = Social_Network_Provider::get_text_mapping( $icon['contact_icon_platform'] );
268 $aria_label = sprintf(
269 /* translators: 1: Platform name. */
270 esc_html__( 'Open %1$s', 'elementor' ),
271 $icon_text_mapping,
272 );
273
274 $link = [
275 'platform' => $icon['contact_icon_platform'],
276 'number' => $icon['contact_icon_number'] ?? '',
277 'username' => $icon['contact_icon_username'] ?? '',
278 'email_data' => [
279 'contact_icon_mail' => $icon['contact_icon_mail'] ?? '',
280 'contact_icon_mail_subject' => $icon['contact_icon_mail_subject'] ?? '',
281 'contact_icon_mail_body' => $icon['contact_icon_mail_body'] ?? '',
282 ],
283 'viber_action' => $icon['contact_icon_viber_action'] ?? '',
284 ];
285
286 $formatted_link = $this->get_formatted_link( $link, 'contact_icon' );
287
288 $icon_classnames = 'e-contact-buttons__contact-icon-link has-size-' . $icons_size;
289
290 if ( ! empty( $hover_animation ) ) {
291 $icon_classnames .= ' elementor-animation-' . $hover_animation;
292 }
293
294 $this->widget->add_render_attribute( 'icon-link-' . $key, [
295 'aria-label' => $aria_label,
296 'class' => $icon_classnames,
297 'href' => $formatted_link,
298 'rel' => 'noopener noreferrer',
299 'target' => '_blank',
300 ] );
301
302 ?>
303
304 <a <?php echo $this->widget->get_render_attribute_string( 'icon-link-' . $key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
305 <?php
306 $mapping = Social_Network_Provider::get_icon_mapping( $icon['contact_icon_platform'] );
307 $icon_lib = explode( ' ', $mapping )[0];
308 $library = 'fab' === $icon_lib ? 'fa-brands' : 'fa-solid';
309 Icons_Manager::render_icon(
310 [
311 'library' => $library,
312 'value' => $mapping,
313 ],
314 [ 'aria-hidden' => 'true' ]
315 );
316 ?>
317 </a>
318 <?php } ?>
319 </div>
320 <?php
321 }
322
323 protected function render_contact_section(): void {
324 ?>
325 <div class="e-contact-buttons__contact">
326 <?php
327 $this->render_contact_text();
328 $this->render_contact_links();
329 ?>
330 </div>
331 <?php
332 }
333
334 protected function render_send_button(): void {
335 $platform = $this->settings['chat_button_platform'] ?? '';
336 $send_button_text = $this->settings['send_button_text'];
337 $hover_animation = $this->settings['style_send_hover_animation'];
338 $cta_classnames = 'e-contact-buttons__send-cta';
339
340 $link = [
341 'platform' => $platform,
342 'number' => $this->settings['chat_button_number'] ?? '',
343 'username' => $this->settings['chat_button_username'] ?? '',
344 'email_data' => [
345 'chat_button_mail' => $this->settings['chat_button_mail'],
346 'chat_button_mail_subject' => $this->settings['chat_button_mail_subject'] ?? '',
347 'chat_button_mail_body' => $this->settings['chat_button_mail_body'] ?? '',
348 ],
349 'viber_action' => $this->settings['chat_button_viber_action'],
350 ];
351
352 $formatted_link = $this->get_formatted_link( $link, 'chat_button' );
353
354 if ( ! empty( $hover_animation ) ) {
355 $cta_classnames .= ' elementor-animation-' . $hover_animation;
356 }
357
358 $this->widget->add_render_attribute( 'formatted-cta', [
359 'class' => $cta_classnames,
360 'href' => $formatted_link,
361 'rel' => 'noopener noreferrer',
362 'target' => '_blank',
363 ] );
364
365 ?>
366 <div class="e-contact-buttons__send-button">
367 <?php $this->render_message_bubble_powered_by(); ?>
368 <div class="e-contact-buttons__send-button-container">
369 <?php if ( $send_button_text ) { ?>
370 <a <?php echo $this->widget->get_render_attribute_string( 'formatted-cta' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
371 <?php
372 $mapping = Social_Network_Provider::get_icon_mapping( $platform );
373 $icon_lib = explode( ' ', $mapping )[0];
374 $library = 'fab' === $icon_lib ? 'fa-brands' : 'fa-solid';
375 Icons_Manager::render_icon(
376 [
377 'library' => $library,
378 'value' => $mapping,
379 ],
380 [ 'aria-hidden' => 'true' ]
381 );
382 ?>
383 <?php echo esc_html( $send_button_text ); ?>
384 </a>
385 <?php } ?>
386 </div>
387 </div>
388 <?php
389 }
390
391 protected function get_formatted_link( array $link, string $prefix ): string {
392
393 // Ensure we clear the default link value if the matching type value is empty
394 switch ( $link['platform'] ) {
395 case Social_Network_Provider::EMAIL:
396 $formatted_link = Social_Network_Provider::build_email_link( $link['email_data'], $prefix );
397 break;
398 case Social_Network_Provider::SMS:
399 $formatted_link = ! empty( $link['number'] ) ? 'sms:' . $link['number'] : '';
400 break;
401 case Social_Network_Provider::MESSENGER:
402 $formatted_link = ! empty( $link['username'] ) ?
403 Social_Network_Provider::build_messenger_link( $link['username'] ) :
404 '';
405 break;
406 case Social_Network_Provider::WHATSAPP:
407 $formatted_link = ! empty( $link['number'] ) ? 'https://wa.me/' . $link['number'] : '';
408 break;
409 case Social_Network_Provider::VIBER:
410 $formatted_link = Social_Network_Provider::build_viber_link( $link['viber_action'], $link['number'] );
411 break;
412 case Social_Network_Provider::SKYPE:
413 $formatted_link = ! empty( $link['username'] ) ? 'skype:' . $link['username'] . '?chat' : '';
414 break;
415 case Social_Network_Provider::TELEPHONE:
416 $formatted_link = ! empty( $link['number'] ) ? 'tel:' . $link['number'] : '';
417 break;
418 default:
419 break;
420 }
421
422 return esc_html( $formatted_link );
423 }
424
425 protected function is_url_link( string $platform ): bool {
426 return Social_Network_Provider::URL === $platform || Social_Network_Provider::WAZE === $platform;
427 }
428
429 protected function render_link_attributes( array $link, string $key ) {
430 switch ( $link['platform'] ) {
431 case Social_Network_Provider::WAZE:
432 if ( empty( $link['location']['url'] ) ) {
433 $link['location']['url'] = '#';
434 }
435
436 $this->widget->add_link_attributes( $key, $link['location'] );
437 break;
438 case Social_Network_Provider::URL:
439 if ( empty( $link['url']['url'] ) ) {
440 $link['url']['url'] = '#';
441 }
442
443 $this->widget->add_link_attributes( $key, $link['url'] );
444 break;
445 default:
446 break;
447 }
448 }
449
450 protected function build_layout_render_attribute(): void {
451 $layout_classnames = 'e-contact-buttons e-' . $this->widget->get_name();
452 $platform = $this->settings['chat_button_platform'] ?? '';
453 $border_radius = $this->settings['style_chat_box_corners'];
454 $alignment_position_horizontal = $this->settings['advanced_horizontal_position'];
455 $alignment_position_vertical = $this->settings['advanced_vertical_position'];
456 $has_animations = ! empty( $this->settings['style_chat_box_exit_animation'] ) || ! empty( $this->settings['style_chat_box_entrance_animation'] );
457 $custom_classes = $this->settings['advanced_custom_css_classes'] ?? '';
458
459 $icon_name_mapping = Social_Network_Provider::get_name_mapping( $platform );
460
461 if ( ! empty( $platform ) ) {
462 $layout_classnames .= ' has-platform-' . $icon_name_mapping;
463 }
464
465 if ( ! empty( $border_radius ) ) {
466 $layout_classnames .= ' has-corners-' . $border_radius;
467 }
468
469 if ( ! empty( $alignment_position_horizontal ) ) {
470 $layout_classnames .= ' has-h-alignment-' . $alignment_position_horizontal;
471 }
472
473 if ( ! empty( $alignment_position_vertical ) ) {
474 $layout_classnames .= ' has-v-alignment-' . $alignment_position_vertical;
475 }
476
477 if ( $has_animations ) {
478 $layout_classnames .= ' has-animations';
479 }
480
481 if ( $custom_classes ) {
482 $layout_classnames .= ' ' . $custom_classes;
483 }
484
485 $this->add_layout_render_attribute( $layout_classnames );
486 }
487 }
488