PluginProbe
Elementor Website Builder – more than just a page builder / 3.23.0-dev2
Elementor Website Builder – more than just a page builder v3.23.0-dev2
4.3.0-beta3 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 All 452 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.23.0-dev2, at modules/floating-buttons/classes/render/contact-buttons-render-base.php

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