| 1 |
<?php |
| 2 |
/** |
| 3 |
* Step marker 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 |
|
| 18 |
if ( empty( $args['element'] ) ) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
$element = $args['element']; |
| 23 |
$data = $element['data']; |
| 24 |
|
| 25 |
$yaymail_op_max_steps = 5; |
| 26 |
$display_steps = array_slice( $steps, 0, $yaymail_op_max_steps ); |
| 27 |
$step_count = count( $display_steps ); |
| 28 |
|
| 29 |
if ( $step_count < 1 ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$active_index = min( max( 0, (int) $current_step_index ), max( 0, $step_count - 1 ) ); |
| 34 |
|
| 35 |
$bubble_pad = 6; |
| 36 |
$bubble_size = $icon_size + ( $bubble_pad * 2 ); |
| 37 |
$bubble_cell_size = max( 42, $bubble_size ); |
| 38 |
$bubble_row_height = max( $bubble_size, $bubble_cell_size ); |
| 39 |
$small_dot_px = 14; |
| 40 |
$ring_outer_px = 24; |
| 41 |
$inner_dot_px = 14; |
| 42 |
// First/last column inset: align marker center with teardrop bubble center (mirror getStepMarkerEdgeTrackPaddingPx). |
| 43 |
$edge_track_padding_px = max( 0, (int) round( $bubble_cell_size / 2 - $ring_outer_px / 2 ) ); |
| 44 |
// Connector bar: at least 1px (parent already clamps connector_height to 1–10). |
| 45 |
$bar_height = max( 1, (int) $connector_height ); |
| 46 |
$dot_ring_size = 3; |
| 47 |
|
| 48 |
$current_step_for_accent = isset( $display_steps[ $active_index ] ) ? $display_steps[ $active_index ] : []; |
| 49 |
$current_step_accent = OrderProgressVariantHelpers::resolve_step_marker_accent_color( |
| 50 |
is_array( $current_step_for_accent ) ? $current_step_for_accent : [], |
| 51 |
$connector_active_color |
| 52 |
); |
| 53 |
$yaymail_ring_border = OrderProgressVariantHelpers::blend_hex_with_white( $current_step_accent, 0.55 ); |
| 54 |
|
| 55 |
$yaymail_step_marker_presets = OrderProgressVariantHelpers::get_step_marker_presets(); |
| 56 |
|
| 57 |
$preset_key = min( 5, max( 1, $step_count ) ); |
| 58 |
$column_width_percents = $yaymail_step_marker_presets[ $preset_key ]['widths']; |
| 59 |
$yaymail_step_edge_aligns = $yaymail_step_marker_presets[ $preset_key ]['aligns']; |
| 60 |
|
| 61 |
$table_style = TemplateHelpers::get_style( |
| 62 |
[ |
| 63 |
'width' => '100%', |
| 64 |
'table-layout' => 'auto', |
| 65 |
'border-collapse' => 'collapse', |
| 66 |
'border-spacing' => '0', |
| 67 |
'mso-table-lspace' => '0pt', |
| 68 |
'mso-table-rspace' => '0pt', |
| 69 |
] |
| 70 |
); |
| 71 |
|
| 72 |
$step_marker_table_class = 'yaymail-element-order-progress yaymail-element-order-progress--step-marker'; |
| 73 |
?> |
| 74 |
<table class="<?php echo esc_attr( $step_marker_table_class ); ?>" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="<?php echo esc_attr( $table_style ); ?>"> |
| 75 |
<tbody> |
| 76 |
<tr class="yaymail-element-order-progress--step-marker-icon-row"> |
| 77 |
<?php foreach ( $display_steps as $index => $step ) : ?> |
| 78 |
<?php |
| 79 |
$is_step_active = $index <= $active_index; |
| 80 |
$is_current_step = $index === $active_index; |
| 81 |
|
| 82 |
$cell_align = isset( $yaymail_step_edge_aligns[ $index ] ) ? $yaymail_step_edge_aligns[ $index ] : 'center'; |
| 83 |
|
| 84 |
$image_url = $is_current_step && is_array( $step ) |
| 85 |
? OrderProgressVariantHelpers::get_step_image_url( $step ) |
| 86 |
: ''; |
| 87 |
|
| 88 |
$raw_image_bg_color = is_array( $step ) ? (string) ( $step['image_bg_color'] ?? '' ) : ''; |
| 89 |
$image_bg_color = $raw_image_bg_color ? $raw_image_bg_color : ( $is_step_active ? $connector_active_color : $connector_inactive_color ); |
| 90 |
|
| 91 |
$teardrop_style = TemplateHelpers::get_style( |
| 92 |
[ |
| 93 |
'width' => $bubble_cell_size . 'px', |
| 94 |
'height' => $bubble_cell_size . 'px', |
| 95 |
'background-color' => $image_bg_color ? $image_bg_color : 'transparent', |
| 96 |
'border-radius' => '35%', |
| 97 |
'mso-border-radius' => '35%', |
| 98 |
'text-align' => 'center', |
| 99 |
'vertical-align' => 'middle', |
| 100 |
'padding' => '0', |
| 101 |
] |
| 102 |
); |
| 103 |
|
| 104 |
$pointer_fill = $image_bg_color ? $image_bg_color : 'transparent'; |
| 105 |
$icon_pointer_style = TemplateHelpers::get_style( |
| 106 |
[ |
| 107 |
'width' => '0', |
| 108 |
'height' => '0', |
| 109 |
'border-left' => '10px solid transparent', |
| 110 |
'border-right' => '10px solid transparent', |
| 111 |
'border-top' => '12px solid ' . $pointer_fill, |
| 112 |
'margin-left' => 'auto !important', |
| 113 |
'margin-right' => 'auto !important', |
| 114 |
'font-size' => '0', |
| 115 |
'line-height' => '0', |
| 116 |
] |
| 117 |
); |
| 118 |
|
| 119 |
$icon_pct = isset( $column_width_percents[ $index ] ) ? (int) $column_width_percents[ $index ] : (int) floor( 100 / max( 1, $step_count ) ); |
| 120 |
?> |
| 121 |
<td width="<?php echo esc_attr( (string) $icon_pct ); ?>%" style=" |
| 122 |
<?php |
| 123 |
echo esc_attr( |
| 124 |
TemplateHelpers::get_style( |
| 125 |
[ |
| 126 |
'vertical-align' => 'top', |
| 127 |
'padding' => '0', |
| 128 |
'width' => $icon_pct . '%', |
| 129 |
'text-align' => $cell_align, |
| 130 |
'height' => $bubble_row_height . 'px', |
| 131 |
] |
| 132 |
) |
| 133 |
); |
| 134 |
?> |
| 135 |
"> |
| 136 |
<?php if ( $is_current_step && ! empty( $image_url ) ) : ?> |
| 137 |
<?php |
| 138 |
$icon_table_margin = '0'; |
| 139 |
if ( 'center' === $cell_align ) { |
| 140 |
$icon_table_margin = '0 auto'; |
| 141 |
} elseif ( 'right' === $cell_align ) { |
| 142 |
$icon_table_margin = '0 0 0 auto'; |
| 143 |
} |
| 144 |
?> |
| 145 |
<table width="<?php echo esc_attr( (string) $bubble_cell_size ); ?>" cellpadding="0" cellspacing="0" role="presentation" align="<?php echo esc_attr( $cell_align ); ?>" style=" |
| 146 |
<?php |
| 147 |
echo esc_attr( |
| 148 |
TemplateHelpers::get_style( |
| 149 |
[ |
| 150 |
'margin' => $icon_table_margin, |
| 151 |
'border-collapse' => 'collapse', |
| 152 |
] |
| 153 |
) |
| 154 |
); |
| 155 |
?> |
| 156 |
"> |
| 157 |
<tbody> |
| 158 |
<tr> |
| 159 |
<td width="<?php echo esc_attr( (string) $bubble_cell_size ); ?>" height="<?php echo esc_attr( (string) $bubble_cell_size ); ?>" align="center" valign="middle" style="<?php echo esc_attr( $teardrop_style ); ?>"> |
| 160 |
<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;object-fit:contain;"/> |
| 161 |
</td> |
| 162 |
</tr> |
| 163 |
<tr> |
| 164 |
<td width="<?php echo esc_attr( (string) $bubble_cell_size ); ?>" align="center" style=" |
| 165 |
<?php |
| 166 |
echo esc_attr( |
| 167 |
TemplateHelpers::get_style( |
| 168 |
[ |
| 169 |
'width' => $bubble_cell_size . 'px', |
| 170 |
'padding' => '0', |
| 171 |
'text-align' => 'center', |
| 172 |
'line-height' => '0', |
| 173 |
'font-size' => '0', |
| 174 |
] |
| 175 |
) |
| 176 |
); |
| 177 |
?> |
| 178 |
"> |
| 179 |
<div style="<?php echo esc_attr( $icon_pointer_style ); ?>"> </div> |
| 180 |
</td> |
| 181 |
</tr> |
| 182 |
</tbody> |
| 183 |
</table> |
| 184 |
<?php else : ?> |
| 185 |
<span style=" |
| 186 |
<?php |
| 187 |
echo esc_attr( |
| 188 |
TemplateHelpers::get_style( |
| 189 |
[ |
| 190 |
'display' => 'inline-block', |
| 191 |
'height' => $bubble_row_height . 'px', |
| 192 |
] |
| 193 |
) |
| 194 |
); |
| 195 |
?> |
| 196 |
"> </span> |
| 197 |
<?php endif; ?> |
| 198 |
</td> |
| 199 |
<?php endforeach; ?> |
| 200 |
</tr> |
| 201 |
|
| 202 |
<tr class="yaymail-element-order-progress--step-marker-track-row"> |
| 203 |
<td colspan="<?php echo esc_attr( (string) $step_count ); ?>" style="<?php echo esc_attr( TemplateHelpers::get_style( [ 'padding' => '0' ] ) ); ?>"> |
| 204 |
<table class="yaymail-element-order-progress--step-marker-track-inner" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="<?php echo esc_attr( $table_style ); ?>"> |
| 205 |
<tbody> |
| 206 |
<tr> |
| 207 |
<?php foreach ( $display_steps as $index => $step ) : ?> |
| 208 |
<?php |
| 209 |
$is_step_active = $index <= $active_index; |
| 210 |
$is_current_step = $index === $active_index; |
| 211 |
|
| 212 |
$col_pct = isset( $column_width_percents[ $index ] ) ? (int) $column_width_percents[ $index ] : (int) floor( 100 / max( 1, $step_count ) ); |
| 213 |
$dot_cell_w = $is_current_step ? $ring_outer_px : $small_dot_px; |
| 214 |
$plain_fill = $is_step_active ? $connector_active_color : $connector_inactive_color; |
| 215 |
|
| 216 |
$segment_colors = OrderProgressVariantHelpers::get_connector_segment_colors( |
| 217 |
$index, |
| 218 |
$active_index, |
| 219 |
$step_count, |
| 220 |
$connector_active_color, |
| 221 |
$connector_inactive_color |
| 222 |
); |
| 223 |
$left_color = $segment_colors['left']; |
| 224 |
$right_color = $segment_colors['right']; |
| 225 |
|
| 226 |
$cell_style = TemplateHelpers::get_style( |
| 227 |
[ |
| 228 |
'width' => $col_pct . '%', |
| 229 |
'vertical-align' => 'middle', |
| 230 |
'padding' => '0', |
| 231 |
'padding-left' => ( 0 === (int) $index ) ? $edge_track_padding_px . 'px' : '0', |
| 232 |
'padding-right' => ( (int) $index === $step_count - 1 ) ? $edge_track_padding_px . 'px' : '0', |
| 233 |
'text-align' => 'center', |
| 234 |
'line-height' => '0', |
| 235 |
'font-size' => '0', |
| 236 |
] |
| 237 |
); |
| 238 |
|
| 239 |
$bar_left_style = TemplateHelpers::get_style( |
| 240 |
[ |
| 241 |
'height' => $bar_height . 'px', |
| 242 |
'background' => $left_color, |
| 243 |
'width' => '100%', |
| 244 |
'font-size' => '0', |
| 245 |
'line-height' => '0', |
| 246 |
] |
| 247 |
); |
| 248 |
|
| 249 |
$bar_right_style = TemplateHelpers::get_style( |
| 250 |
[ |
| 251 |
'height' => $bar_height . 'px', |
| 252 |
'background' => $right_color, |
| 253 |
'width' => '100%', |
| 254 |
'font-size' => '0', |
| 255 |
'line-height' => '0', |
| 256 |
] |
| 257 |
); |
| 258 |
?> |
| 259 |
<td width="<?php echo esc_attr( (string) $col_pct ); ?>%" align="center" valign="middle" style="<?php echo esc_attr( $cell_style ); ?>"> |
| 260 |
<table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="<?php echo esc_attr( TemplateHelpers::get_style( [ 'border-collapse' => 'collapse' ] ) ); ?>"> |
| 261 |
<tbody> |
| 262 |
<tr> |
| 263 |
<?php if ( 0 !== (int) $index ) : ?> |
| 264 |
<td valign="middle" style=" |
| 265 |
<?php |
| 266 |
echo esc_attr( |
| 267 |
TemplateHelpers::get_style( |
| 268 |
[ |
| 269 |
'vertical-align' => 'middle', |
| 270 |
'padding' => '0', |
| 271 |
] |
| 272 |
) |
| 273 |
); |
| 274 |
?> |
| 275 |
"> |
| 276 |
<div style="<?php echo esc_attr( $bar_left_style ); ?>"> </div> |
| 277 |
</td> |
| 278 |
<?php endif; ?> |
| 279 |
|
| 280 |
<td width="<?php echo esc_attr( (string) $dot_cell_w ); ?>" align="center" valign="middle" style=" |
| 281 |
<?php |
| 282 |
echo esc_attr( |
| 283 |
TemplateHelpers::get_style( |
| 284 |
[ |
| 285 |
'width' => $dot_cell_w . 'px', |
| 286 |
'vertical-align' => 'middle', |
| 287 |
'padding' => '0', |
| 288 |
'text-align' => 'center', |
| 289 |
'line-height' => '0', |
| 290 |
'font-size' => '0', |
| 291 |
] |
| 292 |
) |
| 293 |
); |
| 294 |
?> |
| 295 |
"> |
| 296 |
<?php if ( $is_current_step ) : ?> |
| 297 |
<?php |
| 298 |
$inner_dot_margin_top = max( |
| 299 |
0, |
| 300 |
(int) floor( ( $ring_outer_px - ( 2 * $dot_ring_size ) - $inner_dot_px ) / 2 ) |
| 301 |
); |
| 302 |
$ring_outer_div_style = TemplateHelpers::get_style( |
| 303 |
[ |
| 304 |
'width' => $ring_outer_px . 'px', |
| 305 |
'height' => $ring_outer_px . 'px', |
| 306 |
'border-radius' => ( (int) ( $ring_outer_px ) ) . 'px', |
| 307 |
'border' => $dot_ring_size . 'px solid ' . $yaymail_ring_border, |
| 308 |
'background' => '#ffffff', |
| 309 |
'box-sizing' => 'border-box', |
| 310 |
'margin' => '0 auto', |
| 311 |
] |
| 312 |
); |
| 313 |
$inner_dot_style = TemplateHelpers::get_style( |
| 314 |
[ |
| 315 |
'width' => $inner_dot_px . 'px', |
| 316 |
'height' => $inner_dot_px . 'px', |
| 317 |
'border-radius' => ( (int) ( $inner_dot_px ) ) . 'px', |
| 318 |
'background' => $current_step_accent, |
| 319 |
'margin' => $inner_dot_margin_top + 3 . 'px auto 0', |
| 320 |
'font-size' => '0', |
| 321 |
'line-height' => '0', |
| 322 |
] |
| 323 |
); |
| 324 |
?> |
| 325 |
<table cellpadding="0" cellspacing="0" role="presentation" align="center" style=" |
| 326 |
<?php |
| 327 |
echo esc_attr( |
| 328 |
TemplateHelpers::get_style( |
| 329 |
[ |
| 330 |
'margin' => '0 auto', |
| 331 |
'border-collapse' => 'collapse', |
| 332 |
] |
| 333 |
) |
| 334 |
); |
| 335 |
?> |
| 336 |
"> |
| 337 |
<tr> |
| 338 |
<td width="<?php echo esc_attr( (string) $ring_outer_px ); ?>" height="<?php echo esc_attr( (string) $ring_outer_px ); ?>" align="center" valign="middle" style="<?php echo esc_attr( TemplateHelpers::get_style( [ 'padding' => '0' ] ) ); ?>"> |
| 339 |
<div style="<?php echo esc_attr( $ring_outer_div_style ); ?>"> |
| 340 |
<div style="<?php echo esc_attr( $inner_dot_style ); ?>"> </div> |
| 341 |
</div> |
| 342 |
</td> |
| 343 |
</tr> |
| 344 |
</table> |
| 345 |
<?php else : ?> |
| 346 |
<?php |
| 347 |
$plain_dot_style = TemplateHelpers::get_style( |
| 348 |
[ |
| 349 |
'width' => $small_dot_px . 'px', |
| 350 |
'height' => $small_dot_px . 'px', |
| 351 |
'border-radius' => ( (int) ( $small_dot_px / 2 ) ) . 'px', |
| 352 |
'background' => $plain_fill, |
| 353 |
'margin' => '0 3px', |
| 354 |
'font-size' => '0', |
| 355 |
'line-height' => '0', |
| 356 |
] |
| 357 |
); |
| 358 |
?> |
| 359 |
<div style="<?php echo esc_attr( $plain_dot_style ); ?>"> </div> |
| 360 |
<?php endif; ?> |
| 361 |
</td> |
| 362 |
|
| 363 |
<?php if ( (int) $index !== $step_count - 1 ) : ?> |
| 364 |
<td valign="middle" style=" |
| 365 |
<?php |
| 366 |
echo esc_attr( |
| 367 |
TemplateHelpers::get_style( |
| 368 |
[ |
| 369 |
'vertical-align' => 'middle', |
| 370 |
'padding' => '0', |
| 371 |
] |
| 372 |
) |
| 373 |
); |
| 374 |
?> |
| 375 |
"> |
| 376 |
<div style="<?php echo esc_attr( $bar_right_style ); ?>"> </div> |
| 377 |
</td> |
| 378 |
<?php endif; ?> |
| 379 |
</tr> |
| 380 |
</tbody> |
| 381 |
</table> |
| 382 |
</td> |
| 383 |
<?php endforeach; ?> |
| 384 |
</tr> |
| 385 |
</tbody> |
| 386 |
</table> |
| 387 |
</td> |
| 388 |
</tr> |
| 389 |
|
| 390 |
<tr class="yaymail-element-order-progress--step-marker-labels-row"> |
| 391 |
<td colspan="<?php echo esc_attr( (string) $step_count ); ?>" style="<?php echo esc_attr( TemplateHelpers::get_style( [ 'padding' => '10px 0 0' ] ) ); ?>"> |
| 392 |
<table class="yaymail-element-order-progress--step-marker-labels-inner" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="<?php echo esc_attr( $table_style ); ?>"> |
| 393 |
<tbody> |
| 394 |
<tr> |
| 395 |
<?php foreach ( $display_steps as $index => $step ) : ?> |
| 396 |
<?php |
| 397 |
$is_step_active = $index <= $active_index; |
| 398 |
|
| 399 |
$title = is_array( $step ) ? (string) ( $step['title'] ?? $step['label'] ?? '' ) : ''; |
| 400 |
|
| 401 |
$label_color = OrderProgressVariantHelpers::get_step_label_color( |
| 402 |
is_array( $step ) ? $step : [], |
| 403 |
$is_step_active, |
| 404 |
$legacy_label_active_color, |
| 405 |
$legacy_label_inactive_color |
| 406 |
); |
| 407 |
|
| 408 |
$label_align = isset( $yaymail_step_edge_aligns[ $index ] ) ? $yaymail_step_edge_aligns[ $index ] : 'center'; |
| 409 |
|
| 410 |
$label_col_pct = isset( $column_width_percents[ $index ] ) ? (int) $column_width_percents[ $index ] : (int) floor( 100 / max( 1, $step_count ) ); |
| 411 |
|
| 412 |
$label_style = TemplateHelpers::get_style( |
| 413 |
[ |
| 414 |
'margin' => '0', |
| 415 |
'padding' => '0', |
| 416 |
'font-size' => $label_font_size . 'px', |
| 417 |
'line-height' => '1.2', |
| 418 |
'color' => $label_color, |
| 419 |
'text-align' => $label_align, |
| 420 |
'font-family' => $label_font_family, |
| 421 |
] |
| 422 |
); |
| 423 |
?> |
| 424 |
<td width="<?php echo esc_attr( (string) $label_col_pct ); ?>%" align="<?php echo esc_attr( $label_align ); ?>" style=" |
| 425 |
<?php |
| 426 |
echo esc_attr( |
| 427 |
TemplateHelpers::get_style( |
| 428 |
[ |
| 429 |
'vertical-align' => 'top', |
| 430 |
'padding' => '0', |
| 431 |
'width' => $label_col_pct . '%', |
| 432 |
'text-align' => $label_align, |
| 433 |
] |
| 434 |
) |
| 435 |
); |
| 436 |
?> |
| 437 |
"> |
| 438 |
<?php if ( '' !== $title ) : ?> |
| 439 |
<p style="<?php echo esc_attr( $label_style ); ?>"><?php echo esc_html( $title ); ?></p> |
| 440 |
<?php endif; ?> |
| 441 |
</td> |
| 442 |
<?php endforeach; ?> |
| 443 |
</tr> |
| 444 |
</tbody> |
| 445 |
</table> |
| 446 |
</td> |
| 447 |
</tr> |
| 448 |
</tbody> |
| 449 |
</table> |
| 450 |
|