| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || exit; |
| 3 |
use YayMail\Utils\TemplateHelpers; |
| 4 |
|
| 5 |
if ( empty( $args['element'] ) ) { |
| 6 |
return; |
| 7 |
} |
| 8 |
|
| 9 |
$element = $args['element']; |
| 10 |
$data = $element['data']; |
| 11 |
|
| 12 |
$data_column_1 = [ |
| 13 |
'align' => 'center', |
| 14 |
'full_width' => false, |
| 15 |
'width' => '100', |
| 16 |
'url' => '#', |
| 17 |
'image' => YAYMAIL_PLUGIN_URL . 'assets/images/woocommerce-logo.png', |
| 18 |
'padding' => [ |
| 19 |
'top' => '10', |
| 20 |
'right' => '10', |
| 21 |
'bottom' => '10', |
| 22 |
'left' => '50', |
| 23 |
], |
| 24 |
]; |
| 25 |
|
| 26 |
if ( is_array( $data['image_list']['column_1'] ) && ! empty( $data['image_list']['column_1'] ) ) { |
| 27 |
$_data_column_1 = $data['image_list']['column_1']; |
| 28 |
foreach ( $_data_column_1 as $key => $value ) { |
| 29 |
if ( $key === 'full_width' ) { |
| 30 |
$data_column_1['full_width'] = filter_var( $value['value'], FILTER_VALIDATE_BOOLEAN ); |
| 31 |
} else { |
| 32 |
$data_column_1[ $key ] = $value['value']; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
$data_column_2 = [ |
| 38 |
'align' => 'center', |
| 39 |
'full_width' => false, |
| 40 |
'width' => '100', |
| 41 |
'url' => '#', |
| 42 |
'image' => YAYMAIL_PLUGIN_URL . 'assets/images/woocommerce-logo.png', |
| 43 |
'padding' => [ |
| 44 |
'top' => '10', |
| 45 |
'right' => '30', |
| 46 |
'bottom' => '10', |
| 47 |
'left' => '30', |
| 48 |
], |
| 49 |
]; |
| 50 |
|
| 51 |
if ( is_array( $data['image_list']['column_2'] ) && ! empty( $data['image_list']['column_2'] ) ) { |
| 52 |
$_data_column_2 = $data['image_list']['column_2']; |
| 53 |
foreach ( $_data_column_2 as $key => $value ) { |
| 54 |
if ( $key === 'full_width' ) { |
| 55 |
$data_column_2['full_width'] = filter_var( $value['value'], FILTER_VALIDATE_BOOLEAN ); |
| 56 |
} else { |
| 57 |
$data_column_2[ $key ] = $value['value']; |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
$data_column_3 = [ |
| 63 |
'align' => 'center', |
| 64 |
'full_width' => false, |
| 65 |
'width' => '100', |
| 66 |
'url' => '#', |
| 67 |
'image' => YAYMAIL_PLUGIN_URL . 'assets/images/woocommerce-logo.png', |
| 68 |
'padding' => [ |
| 69 |
'top' => '10', |
| 70 |
'right' => '50', |
| 71 |
'bottom' => '10', |
| 72 |
'left' => '10', |
| 73 |
], |
| 74 |
]; |
| 75 |
|
| 76 |
if ( is_array( $data['image_list']['column_3'] ) && ! empty( $data['image_list']['column_3'] ) ) { |
| 77 |
$_data_column_3 = $data['image_list']['column_3']; |
| 78 |
foreach ( $_data_column_3 as $key => $value ) { |
| 79 |
if ( $key === 'full_width' ) { |
| 80 |
$data_column_3['full_width'] = filter_var( $value['value'], FILTER_VALIDATE_BOOLEAN ); |
| 81 |
} else { |
| 82 |
$data_column_3[ $key ] = $value['value']; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
$wrapper_style = TemplateHelpers::get_style( |
| 88 |
[ |
| 89 |
'word-break' => 'break-word', |
| 90 |
'background-color' => $data['background_color'], |
| 91 |
] |
| 92 |
); |
| 93 |
|
| 94 |
$column_1_style = TemplateHelpers::get_style( |
| 95 |
[ |
| 96 |
'padding' => TemplateHelpers::get_spacing_value( isset( $data_column_1['padding'] ) ? $data_column_1['padding'] : [] ), |
| 97 |
'text-align' => isset( $data_column_1['align'] ) ? $data_column_1['align'] : 'center', |
| 98 |
'width' => '100%', |
| 99 |
] |
| 100 |
); |
| 101 |
|
| 102 |
$column_2_style = TemplateHelpers::get_style( |
| 103 |
[ |
| 104 |
'padding' => TemplateHelpers::get_spacing_value( isset( $data_column_2['padding'] ) ? $data_column_2['padding'] : [] ), |
| 105 |
'text-align' => isset( $data_column_2['align'] ) ? $data_column_2['align'] : 'center', |
| 106 |
'width' => '100%', |
| 107 |
] |
| 108 |
); |
| 109 |
|
| 110 |
$column_3_style = TemplateHelpers::get_style( |
| 111 |
[ |
| 112 |
'padding' => TemplateHelpers::get_spacing_value( isset( $data_column_3['padding'] ) ? $data_column_3['padding'] : [] ), |
| 113 |
'text-align' => isset( $data_column_3['align'] ) ? $data_column_3['align'] : 'center', |
| 114 |
'width' => '100%', |
| 115 |
] |
| 116 |
); |
| 117 |
|
| 118 |
$column_style = TemplateHelpers::get_style( |
| 119 |
[ |
| 120 |
'width' => TemplateHelpers::get_dimension_value( 100 / $data['number_column'], '%' ), |
| 121 |
'box-sizing' => 'border-box', |
| 122 |
] |
| 123 |
); |
| 124 |
|
| 125 |
ob_start(); |
| 126 |
?> |
| 127 |
|
| 128 |
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="width: 100%; table-layout: fixed;"> |
| 129 |
<tbody> |
| 130 |
<tr> |
| 131 |
<!-- Column 1 --> |
| 132 |
<td valign="top" style="<?php echo esc_attr( $column_style ); ?>"> |
| 133 |
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="width: 100%; table-layout: fixed;"> |
| 134 |
<tbody> |
| 135 |
<tr> |
| 136 |
<td style="<?php echo esc_attr( $column_1_style ); ?>"> |
| 137 |
<a href="<?php echo esc_url( do_shortcode( $data_column_1['url'] ) ); ?>" target="_blank" rel="noreferrer" style="display: inline-block;"> |
| 138 |
<img alt="<?php echo esc_attr( $data_column_1['alt'] ?? '' ); ?>" src="<?php echo esc_url( $data_column_1['image'] ); ?>" style="width: <?php echo esc_attr( isset( $data_column_1['full_width'] ) && $data_column_1['full_width'] ? '100%' : TemplateHelpers::get_dimension_value( $data_column_1['width'] ) ); ?>; display: block; max-width: 100%; height: auto;"/> |
| 139 |
</a> |
| 140 |
</td> |
| 141 |
</tr> |
| 142 |
</tbody> |
| 143 |
</table> |
| 144 |
</td> |
| 145 |
<!-- Column 2 --> |
| 146 |
<?php if ( 2 <= (int) $data['number_column'] ) : ?> |
| 147 |
<td valign="top" style="<?php echo esc_attr( $column_style ); ?>"> |
| 148 |
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="width: 100%; table-layout: fixed;"> |
| 149 |
<tbody> |
| 150 |
<tr> |
| 151 |
<td style="<?php echo esc_attr( $column_2_style ); ?>"> |
| 152 |
<a href="<?php echo esc_url( do_shortcode( $data_column_2['url'] ) ); ?>" target="_blank" rel="noreferrer" style="display: inline-block;"> |
| 153 |
<img alt="<?php echo esc_attr( $data_column_2['alt'] ?? '' ); ?>" src="<?php echo esc_url( $data_column_2['image'] ); ?>" style="width: <?php echo esc_attr( isset( $data_column_2['full_width'] ) && $data_column_2['full_width'] ? '100%' : TemplateHelpers::get_dimension_value( $data_column_2['width'] ) ); ?>; display: block; max-width: 100%; height: auto;"/> |
| 154 |
</a> |
| 155 |
</td> |
| 156 |
</tr> |
| 157 |
</tbody> |
| 158 |
</table> |
| 159 |
</td> |
| 160 |
<?php endif; ?> |
| 161 |
<!-- Column 3 --> |
| 162 |
<?php if ( 3 <= (int) $data['number_column'] ) : ?> |
| 163 |
<td valign="top" style="<?php echo esc_attr( $column_style ); ?>"> |
| 164 |
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="width: 100%; table-layout: fixed;"> |
| 165 |
<tbody> |
| 166 |
<tr> |
| 167 |
<td style="<?php echo esc_attr( $column_3_style ); ?>"> |
| 168 |
<a href="<?php echo esc_url( do_shortcode( $data_column_3['url'] ) ); ?>" target="_blank" rel="noreferrer" style="display: inline-block;"> |
| 169 |
<img alt="<?php echo esc_attr( $data_column_3['alt'] ?? '' ); ?>" src="<?php echo esc_url( $data_column_3['image'] ); ?>" style="width: <?php echo esc_attr( isset( $data_column_3['full_width'] ) && $data_column_3['full_width'] ? '100%' : TemplateHelpers::get_dimension_value( $data_column_3['width'] ) ); ?>; display: block; max-width: 100%; height: auto;"/> |
| 170 |
</a> |
| 171 |
</td> |
| 172 |
</tr> |
| 173 |
</tbody> |
| 174 |
</table> |
| 175 |
</td> |
| 176 |
<?php endif; ?> |
| 177 |
</tr> |
| 178 |
</tbody> |
| 179 |
</table> |
| 180 |
<?php |
| 181 |
$element_content = ob_get_clean(); |
| 182 |
|
| 183 |
TemplateHelpers::wrap_element_content( $element_content, $element, $wrapper_style ); |
| 184 |
|