| 1 |
<?php |
| 2 |
/** |
| 3 |
* Filled bar variant for Order Progress. |
| 4 |
* |
| 5 |
* Variables expected from parent template: |
| 6 |
* - $steps, $current_step_index, $align, $table_style |
| 7 |
* - $connector_height, $connector_active_color, $connector_inactive_color |
| 8 |
* - $icon_size, $label_font_size, $label_font_family |
| 9 |
* - $legacy_label_active_color, $legacy_label_inactive_color |
| 10 |
*/ |
| 11 |
|
| 12 |
defined( 'ABSPATH' ) || exit; |
| 13 |
|
| 14 |
use YayMail\Utils\OrderProgressVariantHelpers; |
| 15 |
use YayMail\Utils\TemplateHelpers; |
| 16 |
|
| 17 |
if ( empty( $args['element'] ) ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
$element = $args['element']; |
| 22 |
$data = $element['data']; |
| 23 |
|
| 24 |
$yaymail_op_max_steps = 5; |
| 25 |
$display_steps = array_slice( $steps, 0, $yaymail_op_max_steps ); |
| 26 |
$step_count = count( $display_steps ); |
| 27 |
|
| 28 |
if ( $step_count < 1 ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
$active_index = min( max( 0, (int) $current_step_index ), max( 0, $step_count - 1 ) ); |
| 33 |
|
| 34 |
$bubble_pad = 6; |
| 35 |
$bubble_size = $icon_size + ( $bubble_pad * 2 ); |
| 36 |
$bubble_cell_size = max( 44, $bubble_size ); |
| 37 |
|
| 38 |
// Connector bar: at least 1px (customizer clamps connector_height to 1–10). |
| 39 |
$bar_height = max( 1, (int) $connector_height ); |
| 40 |
|
| 41 |
$yaymail_step_marker_presets = OrderProgressVariantHelpers::get_step_marker_presets(); |
| 42 |
|
| 43 |
$preset_key = min( 5, max( 1, $step_count ) ); |
| 44 |
$column_width_percents = $yaymail_step_marker_presets[ $preset_key ]['widths']; |
| 45 |
?> |
| 46 |
<table class="yaymail-element-order-progress yaymail-element-order-progress--filled-bar" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="<?php echo esc_attr( $table_style ); ?>"> |
| 47 |
<tbody> |
| 48 |
<tr class="yaymail-element-order-progress--filled-bar-track-row"> |
| 49 |
<td colspan="<?php echo esc_attr( (string) $step_count ); ?>" style="<?php echo esc_attr( TemplateHelpers::get_style( [ 'padding' => '0' ] ) ); ?>"> |
| 50 |
<table class="yaymail-element-order-progress--step-marker-track-inner yaymail-element-order-progress--filled-bar-track-inner" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="<?php echo esc_attr( $table_style ); ?>"> |
| 51 |
<tbody> |
| 52 |
<tr> |
| 53 |
<?php foreach ( $display_steps as $index => $step ) : ?> |
| 54 |
<?php |
| 55 |
$is_step_active = $index <= $active_index; |
| 56 |
|
| 57 |
$image_active_url = is_array( $step ) ? (string) ( $step['image_active_url'] ?? '' ) : ''; |
| 58 |
$image_inactive_url = is_array( $step ) ? (string) ( $step['image_inactive_url'] ?? '' ) : ''; |
| 59 |
|
| 60 |
$image_url = OrderProgressVariantHelpers::resolve_step_image_url( $is_step_active, $image_active_url, $image_inactive_url ); |
| 61 |
|
| 62 |
$raw_image_bg_color = is_array( $step ) ? (string) ( $step['image_bg_color'] ?? '' ) : ''; |
| 63 |
$image_bg_color = OrderProgressVariantHelpers::resolve_filled_bar_icon_background( |
| 64 |
$is_step_active, |
| 65 |
$raw_image_bg_color, |
| 66 |
$connector_active_color |
| 67 |
); |
| 68 |
|
| 69 |
$raw_global_border_radius = is_array( $data ) ? (string) ( $data['filled_bar_icon_border_radius'] ?? '' ) : ''; |
| 70 |
$raw_border_active = is_array( $step ) ? (string) ( $step['filled_bar_icon_border_color_active'] ?? '' ) : ''; |
| 71 |
$raw_border_inactive = is_array( $step ) ? (string) ( $step['filled_bar_icon_border_color_inactive'] ?? '' ) : ''; |
| 72 |
$icon_border_radius = trim( (string) $raw_global_border_radius ) === '' |
| 73 |
? 50 |
| 74 |
: max( 0, (int) $raw_global_border_radius ); |
| 75 |
|
| 76 |
$icon_border_color = OrderProgressVariantHelpers::resolve_filled_bar_icon_border_color( |
| 77 |
$is_step_active, |
| 78 |
$raw_border_active, |
| 79 |
$raw_border_inactive |
| 80 |
); |
| 81 |
|
| 82 |
$pct = isset( $column_width_percents[ $index ] ) ? (int) $column_width_percents[ $index ] : (int) floor( 100 / max( 1, $step_count ) ); |
| 83 |
|
| 84 |
$segment_colors = OrderProgressVariantHelpers::get_connector_segment_colors( |
| 85 |
$index, |
| 86 |
$active_index, |
| 87 |
$step_count, |
| 88 |
$connector_active_color, |
| 89 |
$connector_inactive_color |
| 90 |
); |
| 91 |
$left_color = $segment_colors['left']; |
| 92 |
$right_color = $segment_colors['right']; |
| 93 |
|
| 94 |
$icon_wrap_style = TemplateHelpers::get_style( |
| 95 |
[ |
| 96 |
'display' => 'inline-block', |
| 97 |
'background-color' => $image_bg_color ? $image_bg_color : 'transparent', |
| 98 |
'border-radius' => $icon_border_radius . 'px', |
| 99 |
'padding' => '10px', |
| 100 |
'vertical-align' => 'middle', |
| 101 |
'border-width' => '2px', |
| 102 |
'border-style' => 'solid', |
| 103 |
'border-color' => $icon_border_color, |
| 104 |
] |
| 105 |
); |
| 106 |
|
| 107 |
$icon_middle_td_style = TemplateHelpers::get_style( |
| 108 |
[ |
| 109 |
'vertical-align' => 'middle', |
| 110 |
'padding' => '0', |
| 111 |
'text-align' => 'center', |
| 112 |
'line-height' => '0 !important', |
| 113 |
] |
| 114 |
); |
| 115 |
?> |
| 116 |
<td width="<?php echo esc_attr( (string) $pct ); ?>%" align="center" valign="middle" style=" |
| 117 |
<?php |
| 118 |
echo esc_attr( |
| 119 |
TemplateHelpers::get_style( |
| 120 |
[ |
| 121 |
'width' => $pct . '%', |
| 122 |
'vertical-align' => 'middle', |
| 123 |
'padding' => '0', |
| 124 |
'padding-left' => '0', |
| 125 |
'padding-right' => '0', |
| 126 |
'text-align' => 'center', |
| 127 |
'line-height' => '0', |
| 128 |
'font-size' => '0', |
| 129 |
] |
| 130 |
) |
| 131 |
); |
| 132 |
?> |
| 133 |
"> |
| 134 |
<table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="<?php echo esc_attr( TemplateHelpers::get_style( [ 'border-collapse' => 'collapse' ] ) ); ?>"> |
| 135 |
<tbody> |
| 136 |
<tr> |
| 137 |
<?php if ( 0 !== (int) $index ) : ?> |
| 138 |
<td valign="middle" style=" |
| 139 |
<?php |
| 140 |
echo esc_attr( |
| 141 |
TemplateHelpers::get_style( |
| 142 |
[ |
| 143 |
'vertical-align' => 'middle', |
| 144 |
'padding' => '0', |
| 145 |
] |
| 146 |
) |
| 147 |
); |
| 148 |
?> |
| 149 |
"> |
| 150 |
<div style=" |
| 151 |
<?php |
| 152 |
echo esc_attr( |
| 153 |
TemplateHelpers::get_style( |
| 154 |
[ |
| 155 |
'height' => $bar_height . 'px', |
| 156 |
'background-color' => $left_color, |
| 157 |
'width' => '100%', |
| 158 |
'font-size' => '0', |
| 159 |
'line-height' => '0', |
| 160 |
] |
| 161 |
) |
| 162 |
); |
| 163 |
?> |
| 164 |
"> </div> |
| 165 |
</td> |
| 166 |
<?php endif; ?> |
| 167 |
|
| 168 |
<td width="50" align="center" valign="middle" style="<?php echo esc_attr( $icon_middle_td_style ); ?>"> |
| 169 |
<?php if ( ! empty( $image_url ) ) : ?> |
| 170 |
<span style="<?php echo esc_attr( $icon_wrap_style ); ?>"> |
| 171 |
<img src="<?php echo esc_url( $image_url ); ?>" alt="" width="<?php echo esc_attr( (string) $icon_size ); ?>" height="<?php echo esc_attr( (string) $icon_size ); ?>" style="display:block;margin:0 auto;border:0;outline:none;text-decoration:none;width:<?php echo esc_attr( (string) $icon_size ); ?>px;height:<?php echo esc_attr( (string) $icon_size ); ?>px;"/> |
| 172 |
</span> |
| 173 |
<?php else : ?> |
| 174 |
<span style=" |
| 175 |
<?php |
| 176 |
echo esc_attr( |
| 177 |
TemplateHelpers::get_style( |
| 178 |
[ |
| 179 |
'display' => 'inline-block', |
| 180 |
'width' => $bubble_cell_size . 'px', |
| 181 |
'min-height' => $bubble_cell_size . 'px', |
| 182 |
] |
| 183 |
) |
| 184 |
); |
| 185 |
?> |
| 186 |
"> </span> |
| 187 |
<?php endif; ?> |
| 188 |
</td> |
| 189 |
|
| 190 |
<?php if ( (int) $index !== $step_count - 1 ) : ?> |
| 191 |
<td valign="middle" style=" |
| 192 |
<?php |
| 193 |
echo esc_attr( |
| 194 |
TemplateHelpers::get_style( |
| 195 |
[ |
| 196 |
'vertical-align' => 'middle', |
| 197 |
'padding' => '0', |
| 198 |
] |
| 199 |
) |
| 200 |
); |
| 201 |
?> |
| 202 |
"> |
| 203 |
<div style=" |
| 204 |
<?php |
| 205 |
echo esc_attr( |
| 206 |
TemplateHelpers::get_style( |
| 207 |
[ |
| 208 |
'height' => $bar_height . 'px', |
| 209 |
'background-color' => $right_color, |
| 210 |
'width' => '100%', |
| 211 |
'font-size' => '0', |
| 212 |
'line-height' => '0', |
| 213 |
] |
| 214 |
) |
| 215 |
); |
| 216 |
?> |
| 217 |
"> </div> |
| 218 |
</td> |
| 219 |
<?php endif; ?> |
| 220 |
</tr> |
| 221 |
</tbody> |
| 222 |
</table> |
| 223 |
</td> |
| 224 |
<?php endforeach; ?> |
| 225 |
</tr> |
| 226 |
</tbody> |
| 227 |
</table> |
| 228 |
</td> |
| 229 |
</tr> |
| 230 |
|
| 231 |
<tr class="yaymail-element-order-progress--filled-bar-labels-row"> |
| 232 |
<td colspan="<?php echo esc_attr( (string) $step_count ); ?>" style="<?php echo esc_attr( TemplateHelpers::get_style( [ 'padding' => '0' ] ) ); ?>"> |
| 233 |
<table class="yaymail-element-order-progress--filled-bar-labels-inner" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="<?php echo esc_attr( $table_style ); ?>"> |
| 234 |
<tbody> |
| 235 |
<tr> |
| 236 |
<?php foreach ( $display_steps as $index => $step ) : ?> |
| 237 |
<?php |
| 238 |
$is_step_active = $index <= $active_index; |
| 239 |
|
| 240 |
$title = is_array( $step ) ? (string) ( $step['title'] ?? $step['label'] ?? '' ) : ''; |
| 241 |
|
| 242 |
$step_label_color = is_array( $step ) ? (string) ( $step['label_color'] ?? '' ) : ''; |
| 243 |
$step_label_active_color = is_array( $step ) ? (string) ( $step['label_active_color'] ?? '' ) : ''; |
| 244 |
$step_label_inactive_color = is_array( $step ) ? (string) ( $step['label_inactive_color'] ?? '' ) : ''; |
| 245 |
|
| 246 |
// Mirror filled-bar.tsx: first column left, last right, else center. |
| 247 |
$label_td_align = ( 0 === (int) $index ) |
| 248 |
? 'left' |
| 249 |
: ( (int) $index === $step_count - 1 ? 'right' : 'center' ); |
| 250 |
|
| 251 |
$label_color = OrderProgressVariantHelpers::resolve_filled_bar_label_color( |
| 252 |
$step_label_color, |
| 253 |
$is_step_active, |
| 254 |
$step_label_active_color, |
| 255 |
$step_label_inactive_color, |
| 256 |
$legacy_label_active_color, |
| 257 |
$legacy_label_inactive_color |
| 258 |
); |
| 259 |
|
| 260 |
$label_pct = isset( $column_width_percents[ $index ] ) ? (int) $column_width_percents[ $index ] : (int) floor( 100 / max( 1, $step_count ) ); |
| 261 |
|
| 262 |
$label_style = TemplateHelpers::get_style( |
| 263 |
[ |
| 264 |
'margin' => '8px 0 0', |
| 265 |
'padding' => '0', |
| 266 |
'font-size' => $label_font_size . 'px', |
| 267 |
'line-height' => '1.2', |
| 268 |
'color' => $label_color, |
| 269 |
'font-family' => $label_font_family, |
| 270 |
] |
| 271 |
); |
| 272 |
?> |
| 273 |
<td width="<?php echo esc_attr( (string) $label_pct ); ?>%" align="center" style=" |
| 274 |
<?php |
| 275 |
echo esc_attr( |
| 276 |
TemplateHelpers::get_style( |
| 277 |
[ |
| 278 |
'width' => $label_pct . '%', |
| 279 |
'vertical-align' => 'top', |
| 280 |
'padding' => '0', |
| 281 |
'text-align' => $label_td_align, |
| 282 |
] |
| 283 |
) |
| 284 |
); |
| 285 |
?> |
| 286 |
"> |
| 287 |
<?php if ( '' !== $title ) : ?> |
| 288 |
<p style="<?php echo esc_attr( $label_style ); ?>"><?php echo esc_html( $title ); ?></p> |
| 289 |
<?php endif; ?> |
| 290 |
</td> |
| 291 |
<?php endforeach; ?> |
| 292 |
</tr> |
| 293 |
</tbody> |
| 294 |
</table> |
| 295 |
</td> |
| 296 |
</tr> |
| 297 |
</tbody> |
| 298 |
</table> |
| 299 |
|
| 300 |
|