| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
use YayMail\SocialIcons\SocialIconEndpoint; |
| 6 |
use YayMail\Utils\TemplateHelpers; |
| 7 |
|
| 8 |
if ( empty( $args['element'] ) ) { |
| 9 |
return; |
| 10 |
} |
| 11 |
|
| 12 |
$element = $args['element']; |
| 13 |
$data = $element['data']; |
| 14 |
|
| 15 |
if ( empty( $data['icon_list'] ) ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
$direction_rtl = yaymail_get_email_direction(); |
| 20 |
|
| 21 |
$wrapper_style = TemplateHelpers::get_style( |
| 22 |
[ |
| 23 |
'word-break' => 'break-word', |
| 24 |
'background-color' => $data['background_color'], |
| 25 |
'padding' => TemplateHelpers::get_spacing_value( isset( $data['padding'] ) ? $data['padding'] : [] ), |
| 26 |
] |
| 27 |
); |
| 28 |
|
| 29 |
$theme = [ |
| 30 |
'Colorful' => 'colorful', |
| 31 |
'LineDark' => 'line-dark', |
| 32 |
'LineLight' => 'line-light', |
| 33 |
'SolidDark' => 'solid-dark', |
| 34 |
'SolidLight' => 'solid-light', |
| 35 |
]; |
| 36 |
|
| 37 |
$is_custom_theme = isset( $data['theme'] ) && 'Custom' === $data['theme']; |
| 38 |
$icon_color = isset( $data['icon_color'] ) ? $data['icon_color'] : '#333333'; |
| 39 |
// Resolve global preset paths (presets/...) to hex BEFORE building the image URL. |
| 40 |
// Otherwise TemplateRenderer's post-pass replaces the path with "#rrggbb" inside the |
| 41 |
// query string, and the "#" truncates the URL as a fragment. |
| 42 |
$icon_color = TemplateHelpers::replace_color_paths( $icon_color ); |
| 43 |
$icon_size = isset( $data['width_icon'] ) ? absint( $data['width_icon'] ) : 24; |
| 44 |
$render_size = max( 32, min( 256, $icon_size * 2 ) ); |
| 45 |
|
| 46 |
// Handle table alignment |
| 47 |
$table_margin = '0 auto'; |
| 48 |
if ( isset( $data['align'] ) ) { |
| 49 |
switch ( $data['align'] ) { |
| 50 |
case 'center': |
| 51 |
$table_margin = '0 auto'; |
| 52 |
break; |
| 53 |
case 'right': |
| 54 |
$table_margin = '0 0 0 auto'; |
| 55 |
break; |
| 56 |
case 'left': |
| 57 |
default: |
| 58 |
$table_margin = '0'; |
| 59 |
break; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
$item_style = TemplateHelpers::get_style( |
| 64 |
[ |
| 65 |
'display' => 'inline-block', |
| 66 |
'vertical-align' => 'top', |
| 67 |
'text-align' => 'center', |
| 68 |
'margin' => '5px 0', |
| 69 |
'padding-left' => TemplateHelpers::get_dimension_value( max( ( $data['spacing'] ?? 0 ) - 5, 0 ) / 2 ), |
| 70 |
'padding-right' => TemplateHelpers::get_dimension_value( max( ( $data['spacing'] ?? 0 ) - 5, 0 ) / 2 ), |
| 71 |
'padding-top' => 0, |
| 72 |
'padding-bottom' => 0, |
| 73 |
] |
| 74 |
); |
| 75 |
|
| 76 |
$a_style = TemplateHelpers::get_style( |
| 77 |
[ |
| 78 |
'display' => 'inline-block', |
| 79 |
'border' => 'none', |
| 80 |
'text-decoration' => 'none', |
| 81 |
] |
| 82 |
); |
| 83 |
|
| 84 |
ob_start(); |
| 85 |
?> |
| 86 |
<table class="yaymail-customizer-element-social" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse: collapse; margin: <?php echo esc_attr( $table_margin ); ?>; width: 100%;"> |
| 87 |
<tr> |
| 88 |
<td style="text-align: <?php echo esc_attr( $data['align'] ?? 'center' ); ?>;"> |
| 89 |
<?php foreach ( $data['icon_list'] as $key => $el ) : ?> |
| 90 |
<?php |
| 91 |
if ( $is_custom_theme ) { |
| 92 |
$img_url = SocialIconEndpoint::get_url( $el['icon'], $icon_color, $render_size ); |
| 93 |
} else { |
| 94 |
$theme_slug = $theme[ $data['theme'] ] ?? 'colorful'; |
| 95 |
$img_url = YAYMAIL_PLUGIN_URL . 'assets/images/social-icons/' . $el['icon'] . '/' . $theme_slug . '.png'; |
| 96 |
} |
| 97 |
$first_index = ( 'rtl' === $direction_rtl ) ? count( $data['icon_list'] ) - 1 : 0; |
| 98 |
$spacing = ( $first_index === $key ) ? '0px' : $data['spacing'] . 'px'; |
| 99 |
$text_align = isset( $data['align'] ) ? $data['align'] : 'center'; |
| 100 |
?> |
| 101 |
<span class="yaymail-social-icon-item" style="<?php echo esc_attr( $item_style ); ?>"> |
| 102 |
<a href="<?php echo esc_attr( do_shortcode( $el['url'] ) ); ?>" target="_blank" style="<?php echo esc_attr( $a_style ); ?>"> |
| 103 |
<img border="0" tabindex="0" src="<?php echo esc_url( $img_url ); ?>" height="<?php echo esc_attr( $data['width_icon'] ); ?>" width="<?php echo esc_attr( $data['width_icon'] ); ?>" style="display: block; border: 0; margin: 0; padding: 0; outline: none;" /> |
| 104 |
</a> |
| 105 |
</span> |
| 106 |
<?php endforeach; ?> |
| 107 |
</td> |
| 108 |
</tr> |
| 109 |
</table> |
| 110 |
<?php |
| 111 |
$element_content = ob_get_clean(); |
| 112 |
|
| 113 |
TemplateHelpers::wrap_element_content( $element_content, $element, $wrapper_style ); |
| 114 |
|