| 1 |
<?php |
| 2 |
/** |
| 3 |
* Partial: Savings summary card (top-right). |
| 4 |
*/ |
| 5 |
|
| 6 |
if (!defined('ABSPATH')) die('No direct access allowed'); |
| 7 |
|
| 8 |
$total_human = $savings['total_human'] ?? '0 B'; |
| 9 |
$has_savings = ($savings['total_bytes'] ?? 0) > 0; |
| 10 |
|
| 11 |
$image_bytes = (int) ($savings['image_bytes'] ?? 0); |
| 12 |
$db_bytes = (int) ($savings['database_bytes'] ?? 0); |
| 13 |
$cache_bytes = (int) ($savings['cache_bytes'] ?? 0); |
| 14 |
$files_bytes = (int) ($savings['files_bytes'] ?? 0); |
| 15 |
|
| 16 |
$image_pct = (int) ($savings['image_pct'] ?? 0); |
| 17 |
$db_pct = (int) ($savings['database_pct'] ?? 0); |
| 18 |
$cache_pct = (int) ($savings['cache_pct'] ?? 0); |
| 19 |
$files_pct = (int) ($savings['files_pct'] ?? 0); |
| 20 |
|
| 21 |
$image_human = $savings['image_human'] ?? '0 B'; |
| 22 |
$db_human = $savings['database_human'] ?? '0 B'; |
| 23 |
$cache_human = $savings['cache_human'] ?? '0 B'; |
| 24 |
$files_human = $savings['files_human'] ?? '0 B'; |
| 25 |
|
| 26 |
// Bar widths: zero-byte segments get a 1% sliver so all 4 colours always show. |
| 27 |
$image_bar = $has_savings ? ($image_bytes > 0 ? max(2, $image_pct) : 1) : 0; |
| 28 |
$db_bar = $has_savings ? ($db_bytes > 0 ? max(2, $db_pct) : 1) : 0; |
| 29 |
$cache_bar = $has_savings ? ($cache_bytes > 0 ? max(2, $cache_pct) : 1) : 0; |
| 30 |
$files_bar = $has_savings ? ($files_bytes > 0 ? max(2, $files_pct) : 1) : 0; |
| 31 |
?> |
| 32 |
|
| 33 |
<div class="wpo-card"> |
| 34 |
<div class="wpo-card-saving-bar"> |
| 35 |
|
| 36 |
<?php if ($has_savings) : ?> |
| 37 |
<div class="wpo-big-num wpo-big-num--green"><?php echo wp_kses($total_human, array('span' => array('class' => true))); ?></div> |
| 38 |
<p class="wpo-savings-sub"> |
| 39 |
<?php esc_html_e('Freed so far across all optimisations', 'wp-optimize'); ?> |
| 40 |
</p> |
| 41 |
<?php else : ?> |
| 42 |
<div class="wpo-big-num wpo-big-num--zero grey-out"><b>0</b> <span>MB</span></div> |
| 43 |
<p class="wpo-savings-sub"> |
| 44 |
<?php esc_html_e('No savings yet — we\'ll track them here.', 'wp-optimize'); ?> |
| 45 |
<?php esc_html_e('Typical sites free up 50–200 MB', 'wp-optimize'); ?> |
| 46 |
</p> |
| 47 |
<?php endif; ?> |
| 48 |
|
| 49 |
<div class="wpo-savings-bar-label"> |
| 50 |
<?php esc_html_e('Where savings come from', 'wp-optimize'); ?> |
| 51 |
</div> |
| 52 |
|
| 53 |
<?php if ($has_savings) : ?> |
| 54 |
<div class="wpo-bar-wrap"> |
| 55 |
<div class="wpo-bar-seg" style="width:<?php echo esc_attr($image_bar); ?>%;background:#1A80BB"></div> |
| 56 |
<div class="wpo-bar-seg" style="width:<?php echo esc_attr($db_bar); ?>%;background:#EAC11C"></div> |
| 57 |
<div class="wpo-bar-seg" style="width:<?php echo esc_attr($cache_bar); ?>%;background:#B8B8B8"></div> |
| 58 |
<div class="wpo-bar-seg" style="width:<?php echo esc_attr($files_bar); ?>%;background:#605F69"></div> |
| 59 |
</div> |
| 60 |
<?php else : ?> |
| 61 |
<div class="wpo-bar-wrap wpo-bar-wrap--empty"> |
| 62 |
<div class="wpo-bar-seg"></div> |
| 63 |
</div> |
| 64 |
<?php endif; ?> |
| 65 |
|
| 66 |
<div class="wpo-bar-legend"> |
| 67 |
<div class="wpo-legend-item"> |
| 68 |
<div class="wpo-legend-square" style="background:#1A80BB"></div> |
| 69 |
<?php |
| 70 |
/* translators: %s = human size e.g. "31.6 MB" */ |
| 71 |
printf(esc_html__('Media: %s', 'wp-optimize'), esc_html($image_human)); |
| 72 |
?> |
| 73 |
</div> |
| 74 |
<div class="wpo-legend-item"> |
| 75 |
<div class="wpo-legend-square" style="background:#EAC11C"></div> |
| 76 |
<?php |
| 77 |
/* translators: %s = human size */ |
| 78 |
printf(esc_html__('Database: %s', 'wp-optimize'), esc_html($db_human)); |
| 79 |
?> |
| 80 |
</div> |
| 81 |
<div class="wpo-legend-item"> |
| 82 |
<div class="wpo-legend-square" style="background:#B8B8B8"></div> |
| 83 |
<?php |
| 84 |
/* translators: %s = human size */ |
| 85 |
printf(esc_html__('Cache: %s', 'wp-optimize'), esc_html($cache_human)); |
| 86 |
?> |
| 87 |
</div> |
| 88 |
<div class="wpo-legend-item"> |
| 89 |
<div class="wpo-legend-square" style="background:#605F69"></div> |
| 90 |
<?php |
| 91 |
/* translators: %s = human size */ |
| 92 |
printf(esc_html__('Files: %s', 'wp-optimize'), esc_html($files_human)); |
| 93 |
?> |
| 94 |
</div> |
| 95 |
</div> |
| 96 |
|
| 97 |
</div> |
| 98 |
</div> |
| 99 |
|