PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.0-dev4
Elementor Website Builder – more than just a page builder v3.22.0-dev4
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 / conversion-center / classes / render / render-base.php

render-base.php in Elementor Website Builder – more than just a page builder 3.22.0-dev4, at modules/conversion-center/classes/render/render-base.php

490 lines 18.6 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\ConversionCenter\Classes\Render;
4
5 use Elementor\Icons_Manager;
6 use Elementor\Modules\ConversionCenter\Base\Widget_Link_In_Bio_Base;
7 use Elementor\Modules\ConversionCenter\Classes\Providers\Social_Network_Provider;
8 use Elementor\Modules\ConversionCenter\Traits\Conversion_Center_Controls_Trait;
9 use Elementor\Utils;
10
11 /**
12 * Class Render_Base.
13 *
14 * This is the base class that will hold shared functionality that will be needed by all the various widget versions.
15 *
16 * @since 3.23.0
17 */
18 abstract class Render_Base {
19
20 use Conversion_Center_Controls_Trait;
21
22 protected Widget_Link_In_Bio_Base $widget;
23
24 protected array $settings;
25
26 abstract public function render(): void;
27
28 public function __construct( Widget_Link_In_Bio_Base $widget ) {
29 $this->widget = $widget;
30 $this->settings = $widget->get_settings_for_display();
31 }
32
33 protected function render_ctas(): void {
34 $ctas_props_corners = $this->settings['cta_links_corners'] ?? 'rounded';
35 $ctas_props_show_border = $this->settings['cta_links_show_border'] ?? false;
36 $ctas_props_type = $this->settings['cta_links_type'] ?? 'button';
37 $ctas_value_initial = $this->settings['cta_link'] ?? [];
38
39 /**
40 * $this->settings['cta_link'] if empty returns a sub-array with all empty values
41 * Check for this here to avoid rendering container when empty
42 */
43 $ctas_value = array_filter( $ctas_value_initial, function( $sub_array ) {
44 // Use array_filter on the sub array
45 $filtered_sub_array = array_filter( $sub_array, function( $val ) {
46 // Filter out empty or null values
47 return ! is_null( $val ) && '' !== $val;
48 } );
49 // A non-empty result means the sub array contains some non-empty value(s)
50 return ! empty( $filtered_sub_array );
51 } );
52
53 $has_ctas = ! empty( $ctas_value );
54 if ( ! $has_ctas ) {
55 return;
56 }
57
58 $this->widget->add_render_attribute( 'ctas', [
59 'class' => 'e-link-in-bio__ctas has-type-' . $ctas_props_type,
60 ] );
61 ?>
62
63 <div <?php echo $this->widget->get_render_attribute_string( 'ctas' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
64 <?php
65 foreach ( $ctas_value as $key => $cta ) {
66 // Bail if no text
67 if ( empty( $cta['cta_link_text'] ) ) {
68 break;
69 }
70
71 $formatted_link = $this->get_formatted_link_based_on_type_for_cta( $cta );
72 $cta_image = $cta['cta_link_image'] ?? [];
73 $cta_has_image = ! empty( $cta_image ) &&
74 ( ! empty( $cta_image['url'] || ! empty( $cta_image['id'] ) ) ) &&
75 'button' === $ctas_props_type;
76
77 $ctas_classnames = 'e-link-in-bio__cta is-type-' . $ctas_props_type;
78
79 if ( 'button' === $ctas_props_type && $ctas_props_show_border ) {
80 $ctas_classnames .= ' has-border';
81 }
82
83 if ( $cta_has_image ) {
84 $ctas_classnames .= ' has-image';
85 }
86
87 if ( 'button' === $ctas_props_type ) {
88 $ctas_classnames .= ' has-corners-' . $ctas_props_corners;
89 }
90
91 $this->widget->add_render_attribute( 'cta-' . $key, [
92 'class' => $ctas_classnames,
93 'href' => esc_url( $formatted_link ),
94 ] );
95
96 if (
97 Social_Network_Provider::FILE_DOWNLOAD === $cta['cta_link_type'] ||
98 Social_Network_Provider::VCF === $cta['cta_link_type']
99 ) {
100 $this->widget->add_render_attribute( 'cta-' . $key, [
101 'download' => 'download',
102 ] );
103 }
104 ?>
105 <a <?php echo $this->widget->get_render_attribute_string( 'cta-' . $key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
106 <?php if ( $cta_has_image ) : ?>
107 <span class="e-link-in-bio__cta-image">
108 <?php if ( ! empty( $cta_image['id'] ) ) {
109 echo wp_get_attachment_image( $cta_image['id'], 'thumbnail', false, [
110 'class' => 'e-link-in-bio__cta-image-element',
111 ] );
112 } else {
113 $this->widget->add_render_attribute( 'cta-link-image' . $key, [
114 'alt' => '',
115 'class' => 'e-link-in-bio__cta-image-element',
116 'src' => esc_url( $cta_image['url'] ),
117 ] );
118 ?>
119 <img <?php echo $this->widget->get_render_attribute_string( 'cta-link-image' . $key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> />
120 <?php }; ?>
121 </span>
122 <?php endif; ?>
123 <span class="e-link-in-bio__cta-text">
124 <?php echo esc_html( $cta['cta_link_text'] ); ?>
125 </span>
126 </a>
127 <?php } ?>
128 </div>
129 <?php
130 }
131
132 protected function render_icons(): void {
133 $icons_props_show_border = $this->settings['icons_border_show_border'] ?? false;
134 $icons_props_size = $this->settings['icons_size'] ?? 'small';
135 $icons_value = $this->settings['icon'] ?? [];
136
137 $has_icons = ! empty( $icons_value );
138 if ( ! $has_icons ) {
139 return;
140 }
141
142 ?>
143 <div class="e-link-in-bio__icons">
144 <?php
145 foreach ( $icons_value as $key => $icon ) {
146
147 $formatted_link = $this->get_formatted_link_for_icon( $icon );
148
149 $icon_class_names = 'e-link-in-bio__icon has-size-' . $icons_props_size;
150
151 if ( $icons_props_show_border ) {
152 $icon_class_names .= ' has-border';
153 }
154
155 $this->widget->add_render_attribute( 'icon-' . $key, [
156 'class' => $icon_class_names,
157 ] );
158
159 $this->widget->add_render_attribute( 'icon-link-' . $key, [
160 'aria-label' => esc_attr( $icon['icon_platform'] ),
161 'class' => 'e-link-in-bio__icon-link',
162 'href' => esc_url( $formatted_link ),
163 'rel' => 'noopener noreferrer',
164 'target' => '_blank',
165 ] );
166
167 ?>
168 <div <?php echo $this->widget->get_render_attribute_string( 'icon-' . $key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
169 <a <?php echo $this->widget->get_render_attribute_string( 'icon-link-' . $key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
170 <span class="e-link-in-bio__icon-svg">
171 <?php
172 $mapping = Social_Network_Provider::get_icon_mapping( $icon['icon_platform'] );
173 $icon_lib = explode( ' ', $mapping )[0];
174 $library = 'fab' === $icon_lib ? 'fa-brands' : 'fa-solid';
175 Icons_Manager::render_icon(
176 [
177 'library' => $library,
178 'value' => $mapping,
179 ],
180 [ 'aria-hidden' => 'true' ]
181 );
182 ?>
183 </span>
184 <?php if ( ! empty( $icon['icon_text'] ) ) : ?>
185 <span class="e-link-in-bio__icon-label">
186 <?php echo esc_html( $icon['icon_text'] ); ?>
187 </span>
188 <?php endif; ?>
189 </a>
190 </div>
191 <?php } ?>
192 </div>
193 <?php
194 }
195
196 protected function render_bio(): void {
197 $bio_heading_props_tag = $this->settings['bio_heading_tag'] ?? 'h2';
198 $bio_heading_value = $this->settings['bio_heading'] ?? '';
199
200 $bio_title_props_tag = $this->settings['bio_title_tag'] ?? 'h2';
201 $bio_title_value = $this->settings['bio_title'] ?? '';
202
203 if ( 'top' === $this->widget->get_description_position() ) {
204 $bio_about_heading_props_tag = $this->settings['bio_about_tag'] ?? 'h3';
205 $bio_about_heading_value = $this->settings['bio_about'] ?? '';
206
207 $bio_description_value = $this->settings['bio_description'] ?? '';
208 }
209
210 $has_bio_about_heading = ! empty( $bio_about_heading_value );
211 $has_bio_description = ! empty( $bio_description_value );
212 $has_bio_heading = ! empty( $bio_heading_value );
213 $has_bio_title = ! empty( $bio_title_value );
214
215 if ( $has_bio_heading || $has_bio_title || $has_bio_about_heading || $has_bio_description ) {
216 ?>
217 <div class="e-link-in-bio__bio">
218 <?php if ( $has_bio_heading ) {
219 $this->widget->add_render_attribute( 'heading', 'class', 'e-link-in-bio__heading' );
220 $bio_heading_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $bio_heading_props_tag ), $this->widget->get_render_attribute_string( 'heading' ), esc_html( $bio_heading_value ) );
221 // Escaped above
222 Utils::print_unescaped_internal_string( $bio_heading_output );
223 } ?>
224 <?php if ( $has_bio_title ) {
225 $this->widget->add_render_attribute( 'title', 'class', 'e-link-in-bio__title' );
226 $bio_title_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $bio_title_props_tag ), $this->widget->get_render_attribute_string( 'title' ), esc_html( $bio_title_value ) );
227 // Escaped above
228 Utils::print_unescaped_internal_string( $bio_title_output );
229 } ?>
230 <?php if ( $has_bio_about_heading ) {
231 $this->widget->add_render_attribute( 'about-heading', 'class', 'e-link-in-bio__about-heading' );
232 $bio_about_heading_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $bio_about_heading_props_tag ), $this->widget->get_render_attribute_string( 'about-heading' ), esc_html( $bio_about_heading_value ) );
233 // Escaped above
234 Utils::print_unescaped_internal_string( $bio_about_heading_output );
235 } ?>
236 <?php if ( $has_bio_description ) {
237 $this->widget->add_render_attribute( 'description', 'class', 'e-link-in-bio__description' );
238 $bio_description_output = sprintf( '<p %1$s>%2$s</p>', $this->widget->get_render_attribute_string( 'description' ), esc_html( $bio_description_value ) );
239 // Escaped above
240 Utils::print_unescaped_internal_string( $bio_description_output );
241 } ?>
242 </div>
243 <?php
244 }
245 }
246
247 protected function render_footer_bio(): void {
248 if ( 'bottom' !== $this->widget->get_description_position() ) {
249 return;
250 }
251
252 $bio_about_heading_props_tag = $this->settings['bio_about_tag'] ?? 'h3';
253 $bio_about_heading_value = $this->settings['bio_about'] ?? '';
254
255 $bio_description_value = $this->settings['bio_description'] ?? '';
256
257 $has_bio_description = ! empty( $bio_description_value );
258 $has_bio_about_heading = ! empty( $bio_about_heading_value );
259
260 if ( $has_bio_about_heading || $has_bio_description ) {
261 ?>
262 <div class="e-link-in-bio__bio e-link-in-bio__bio--footer">
263 <?php if ( $has_bio_about_heading ) {
264 $this->widget->add_render_attribute( 'about-heading', 'class', 'e-link-in-bio__about-heading' );
265 $bio_about_heading_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $bio_about_heading_props_tag ), $this->widget->get_render_attribute_string( 'about-heading' ), esc_html( $bio_about_heading_value ) );
266 // Escaped above
267 Utils::print_unescaped_internal_string( $bio_about_heading_output );
268 } ?>
269 <?php if ( $has_bio_description ) {
270 $this->widget->add_render_attribute( 'description', 'class', 'e-link-in-bio__description' );
271 $bio_description_output = sprintf( '<p %1$s>%2$s</p>', $this->widget->get_render_attribute_string( 'description' ), esc_html( $bio_description_value ) );
272 // Escaped above
273 Utils::print_unescaped_internal_string( $bio_description_output );
274 } ?>
275 </div>
276 <?php
277 }
278 }
279
280 protected function render_identity_image(): void {
281 /**
282 * Get base data for potential images
283 * Note order is important - secondary must render before primary
284 */
285 $output_images = [
286 'secondary_image' => [
287 'props' => [],
288 'should_render' => false,
289 'value' => $this->settings['identity_image_cover'] ?? [],
290 ],
291 'primary_image' => [
292 'props' => [],
293 'should_render' => false,
294 'value' => $this->settings['identity_image'] ?? [],
295 ],
296 ];
297
298 $output_images['primary_image']['should_render'] = ! empty( $output_images['primary_image']['value'] ) && ( ! empty( $output_images['primary_image']['value']['url'] || ! empty( $output_images['primary_image']['value']['id'] ) ) );
299 $output_images['secondary_image']['should_render'] = ! empty( $output_images['secondary_image']['value'] ) && ( ! empty( $output_images['secondary_image']['value']['url'] || ! empty( $output_images['secondary_image']['value']['id'] ) ) );
300
301 if ( ! $output_images['primary_image']['should_render'] && ! $output_images['secondary_image']['should_render'] ) {
302 return;
303 }
304
305 $output_images = $this->set_primary_image_properties( $output_images );
306
307 $output_images = $this->set_secondary_image_properties( $output_images );
308 ?>
309 <div class="e-link-in-bio__identity">
310 <?php
311 foreach ( $output_images as $image_key => $image ) :
312 if ( $image['should_render'] ) :
313 $this->widget->add_render_attribute( 'identity_image_' . $image_key, [
314 'class' => $this->get_image_classnames( $image ),
315 ] );
316 ?>
317 <div <?php echo $this->widget->get_render_attribute_string( 'identity_image_' . $image_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
318 <?php if ( ! empty( $image['value']['id'] ) ) {
319 echo wp_get_attachment_image( $image['value']['id'], 'medium', false, [
320 'class' => 'e-link-in-bio__identity-image-element',
321 ] );
322 } else {
323 $this->widget->add_render_attribute( 'identity_image_src' . $image_key, [
324 'alt' => '',
325 'class' => 'e-link-in-bio__identity-image-element',
326 'src' => esc_url( $image['value']['url'] ),
327 ] );
328 ?>
329 <img <?php echo $this->widget->get_render_attribute_string( 'identity_image_src' . $image_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> />
330
331 <?php }; ?>
332 <?php
333 if ( ! empty( $image['props']['has_shape_divider'] ) ) {
334 $this->print_shape_divider();
335 }
336 ?>
337 </div>
338 <?php
339 endif;
340 endforeach;
341 ?>
342 </div>
343 <?php
344 }
345
346 protected function get_image_classnames( array $image ): string {
347 $image_classnames = 'e-link-in-bio__identity-image e-link-in-bio__identity-image-' . $image['props']['style'];
348 if ( ! empty( $image['props']['show_border'] ) || ! empty( $image['props']['show_bottom_border'] ) ) {
349 $image_classnames .= ' has-border';
350 }
351 if ( ! empty( $image['props']['shape'] ) && 'profile' === $image['props']['style'] ) {
352 $image_classnames .= ' has-style-' . $image['props']['shape'];
353 }
354 if ( ! empty( $image['props']['has_shape_divider'] ) ) {
355 $image_classnames .= ' has-shape-divider';
356 }
357 return $image_classnames;
358 }
359
360 protected function get_formatted_link_based_on_type_for_cta( array $cta ): string {
361 $formatted_link = $cta['cta_link_url']['url'] ?? '';
362
363 // Ensure we clear the default link value if the matching type value is empty
364 switch ( $cta['cta_link_type'] ) {
365 case Social_Network_Provider::EMAIL:
366 $formatted_link = Social_Network_Provider::build_email_link( $cta, 'cta_link' );
367 break;
368 case Social_Network_Provider::TELEPHONE:
369 $formatted_link = ! empty( $cta['cta_link_number'] ) ? 'tel:' . $cta['cta_link_number'] : '';
370 break;
371 case Social_Network_Provider::MESSENGER:
372 $formatted_link = ! empty( $icon['cta_link_username'] ) ?
373 'https://www.facebook.com/messages/t/' . $icon['icon_username'] :
374 '';
375 break;
376 case Social_Network_Provider::WAZE:
377 $formatted_link = ! empty( $cta['cta_link_location'] ) ? 'https://www.waze.com/ul?ll=' . $cta['cta_link_location'] . '&navigate=yes' : '';
378 break;
379 case Social_Network_Provider::WHATSAPP:
380 $formatted_link = ! empty( $cta['cta_link_number'] ) ? 'https://wa.me/' . $cta['cta_link_number'] : '';
381 break;
382 case Social_Network_Provider::FILE_DOWNLOAD:
383 $formatted_link = ! empty( $cta['cta_link_file']['url'] ) ? $cta['cta_link_file']['url'] : '';
384 break;
385 case Social_Network_Provider::VCF:
386 $formatted_link = ! empty( $cta['cta_link_file']['url'] ) ? $cta['cta_link_file']['url'] : '';
387 break;
388 default:
389 break;
390 }
391
392 return $formatted_link;
393 }
394
395 protected function get_formatted_link_for_icon( array $icon ): string {
396 $formatted_link = $icon['icon_url']['url'] ?? '';
397
398 // Ensure we clear the default link value if the matching type value is empty
399 switch ( $icon['icon_platform'] ) {
400 case Social_Network_Provider::EMAIL:
401 $formatted_link = Social_Network_Provider::build_email_link( $icon, 'icon' );
402 break;
403 case Social_Network_Provider::TELEPHONE:
404 $formatted_link = ! empty( $icon['icon_number'] ) ? 'tel:' . $icon['icon_number'] : '';
405 break;
406 case Social_Network_Provider::MESSENGER:
407 $formatted_link = ! empty( $icon['icon_username'] ) ?
408 'https://www.facebook.com/messages/t/' . $icon['icon_username'] :
409 '';
410 break;
411 case Social_Network_Provider::WAZE:
412 $formatted_link = ! empty( $icon['icon_location'] ) ? 'https://www.waze.com/ul?ll=' . $icon['icon_location'] . '&navigate=yes' : '';
413 break;
414 case Social_Network_Provider::WHATSAPP:
415 $formatted_link = ! empty( $icon['icon_number'] ) ? 'https://wa.me/' . $icon['icon_number'] : '';
416 break;
417 default:
418 break;
419 }
420
421 return $formatted_link;
422 }
423
424 protected function build_layout_render_attribute(): void {
425 $layout_props_full_height = $this->settings['advanced_layout_full_screen_height'] ?? '';
426 $layout_props_full_height_controls = $this->settings['advanced_layout_full_screen_height_controls'] ?? '';
427 $layout_props_full_width = $this->settings['advanced_layout_full_width_custom'] ?? '';
428 $layout_props_show_border = $this->settings['background_show_border'] ?? '';
429 $custom_classes = $this->settings['advanced_custom_css_classes'] ?? '';
430
431 $layout_classnames = 'e-link-in-bio e-' . $this->widget->get_name();
432
433 if ( 'yes' === $layout_props_show_border ) {
434 $layout_classnames .= ' has-border';
435 }
436
437 if ( 'yes' === $layout_props_full_height ) {
438 $layout_classnames .= ' is-full-height';
439 }
440
441 if ( 'yes' === $layout_props_full_width ) {
442 $layout_classnames .= ' is-full-width';
443 }
444
445 if ( ! empty( $layout_props_full_height_controls ) ) {
446 foreach ( $layout_props_full_height_controls as $breakpoint ) {
447 $layout_classnames .= ' is-full-height-' . $breakpoint;
448 }
449 }
450
451 if ( $custom_classes ) {
452 $layout_classnames .= ' ' . $custom_classes;
453 }
454
455 $this->widget->add_render_attribute( 'layout', [
456 'class' => $layout_classnames,
457 'id' => $this->settings['advanced_custom_css_id'],
458 ] );
459 }
460
461 private function set_primary_image_properties( array $output_images ): array {
462 if ( $output_images['primary_image']['should_render'] ) {
463 $output_images['primary_image']['props']['shape'] = $this->settings['identity_image_shape'] ?? 'circle';
464 $output_images['primary_image']['props']['style'] = $this->settings['identity_image_style'] ?? 'profile';
465 $output_images['primary_image']['props']['show_border'] = $this->settings['identity_image_show_border'] ?? false;
466 $output_images['primary_image']['props']['show_bottom_border'] = $this->settings['identity_image_show_bottom_border'] ?? false;
467 }
468
469 return $output_images;
470 }
471
472 private function set_secondary_image_properties( array $output_images ): array {
473 if ( $output_images['secondary_image']['should_render'] ) {
474 $output_images['secondary_image']['props']['style'] = 'cover';
475 $output_images['secondary_image']['props']['show_bottom_border'] = $this->settings['identity_image_show_bottom_border'] ?? false;
476
477 if ( ! empty( $this->settings['identity_section_style_cover_divider_bottom'] ) ) {
478 $output_images['secondary_image']['props']['has_shape_divider'] = true;
479
480 // Remove border if a shaped divider is applied
481 $output_images['secondary_image']['props']['show_bottom_border'] = false;
482 }
483
484 $output_images['primary_image']['props']['style'] = 'profile';
485 }
486
487 return $output_images;
488 }
489 }
490