PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.1
YayMail – WooCommerce Email Customizer v4.4.1
4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 All 57 releases
yaymail / templates / elements / order-progress / variants / step-marker.php

step-marker.php in YayMail – WooCommerce Email Customizer 4.4.1, at templates/elements/order-progress/variants/step-marker.php

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