| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || exit; |
| 3 |
|
| 4 |
$stats = QDBP_Analytics_Table::get_stat_counts(); |
| 5 |
$top_files = QDBP_Analytics_Table::get_top_files( 5 ); |
| 6 |
$max_count = ! empty( $top_files ) ? (int) $top_files[0]->total : 1; |
| 7 |
?> |
| 8 |
<div class="wrap qdbp-wrap"> |
| 9 |
|
| 10 |
<div class="qdbp-page-header"> |
| 11 |
<h1><?php esc_html_e( 'Download Analytics', 'quick-download-button' ); ?></h1> |
| 12 |
</div> |
| 13 |
|
| 14 |
<?php QDBP_Admin::analytics_nav( 'overview' ); ?> |
| 15 |
|
| 16 |
<!-- ── Stat cards ──────────────────────────────────────────────────── --> |
| 17 |
<div class="qdbp-stat-grid"> |
| 18 |
|
| 19 |
<div class="qdbp-stat-card qdbp-stat-card--indigo"> |
| 20 |
<div class="qdbp-stat-card__inner"> |
| 21 |
<div class="qdbp-stat-card__body"> |
| 22 |
<span class="qdbp-stat-card__value"><?php echo number_format_i18n( $stats['total'] ); ?></span> |
| 23 |
<span class="qdbp-stat-card__label"><?php esc_html_e( 'All Time', 'quick-download-button' ); ?></span> |
| 24 |
</div> |
| 25 |
<div class="qdbp-stat-card__icon-wrap qdbp-stat-card__icon-wrap--indigo"> |
| 26 |
<span class="dashicons dashicons-download"></span> |
| 27 |
</div> |
| 28 |
</div> |
| 29 |
</div> |
| 30 |
|
| 31 |
<div class="qdbp-stat-card qdbp-stat-card--amber"> |
| 32 |
<div class="qdbp-stat-card__inner"> |
| 33 |
<div class="qdbp-stat-card__body"> |
| 34 |
<span class="qdbp-stat-card__value"><?php echo number_format_i18n( $stats['today'] ); ?></span> |
| 35 |
<span class="qdbp-stat-card__label"><?php esc_html_e( 'Today', 'quick-download-button' ); ?></span> |
| 36 |
<span class="qdbp-stat-card__sub"><?php echo esc_html( current_time( 'F j, Y' ) ); ?></span> |
| 37 |
</div> |
| 38 |
<div class="qdbp-stat-card__icon-wrap qdbp-stat-card__icon-wrap--amber"> |
| 39 |
<span class="dashicons dashicons-calendar-alt"></span> |
| 40 |
</div> |
| 41 |
</div> |
| 42 |
</div> |
| 43 |
|
| 44 |
<div class="qdbp-stat-card qdbp-stat-card--emerald"> |
| 45 |
<div class="qdbp-stat-card__inner"> |
| 46 |
<div class="qdbp-stat-card__body"> |
| 47 |
<span class="qdbp-stat-card__value"><?php echo number_format_i18n( $stats['week'] ); ?></span> |
| 48 |
<span class="qdbp-stat-card__label"><?php esc_html_e( 'Last 7 Days', 'quick-download-button' ); ?></span> |
| 49 |
</div> |
| 50 |
<div class="qdbp-stat-card__icon-wrap qdbp-stat-card__icon-wrap--emerald"> |
| 51 |
<span class="dashicons dashicons-chart-line"></span> |
| 52 |
</div> |
| 53 |
</div> |
| 54 |
</div> |
| 55 |
|
| 56 |
<div class="qdbp-stat-card qdbp-stat-card--blue"> |
| 57 |
<div class="qdbp-stat-card__inner"> |
| 58 |
<div class="qdbp-stat-card__body"> |
| 59 |
<span class="qdbp-stat-card__value"><?php echo number_format_i18n( $stats['month'] ); ?></span> |
| 60 |
<span class="qdbp-stat-card__label"><?php esc_html_e( 'Last 30 Days', 'quick-download-button' ); ?></span> |
| 61 |
</div> |
| 62 |
<div class="qdbp-stat-card__icon-wrap qdbp-stat-card__icon-wrap--blue"> |
| 63 |
<span class="dashicons dashicons-chart-bar"></span> |
| 64 |
</div> |
| 65 |
</div> |
| 66 |
</div> |
| 67 |
|
| 68 |
</div> |
| 69 |
|
| 70 |
<!-- ── Top downloaded files ────────────────────────────────────────── --> |
| 71 |
<?php if ( ! empty( $top_files ) ) : ?> |
| 72 |
<div class="qdbp-panel"> |
| 73 |
<div class="qdbp-panel__header"> |
| 74 |
<span class="dashicons dashicons-awards qdbp-panel__header-icon"></span> |
| 75 |
<h2 class="qdbp-panel__title"><?php esc_html_e( 'Top Downloaded Files', 'quick-download-button' ); ?></h2> |
| 76 |
<a href="<?php echo esc_url( admin_url( 'admin.php?page=qdbp-log' ) ); ?>" class="qdbp-panel__link"> |
| 77 |
<?php esc_html_e( 'View full log', 'quick-download-button' ); ?> → |
| 78 |
</a> |
| 79 |
</div> |
| 80 |
<div class="qdbp-panel__body"> |
| 81 |
<?php foreach ( $top_files as $rank => $file ) : |
| 82 |
// Resolve file label |
| 83 |
$label = ''; |
| 84 |
$href = ''; |
| 85 |
if ( $file->attachment_id ) { |
| 86 |
$title = get_the_title( $file->attachment_id ); |
| 87 |
$url = wp_get_attachment_url( $file->attachment_id ); |
| 88 |
$label = $title ?: ( $url ? basename( $url ) : '' ); |
| 89 |
$href = $url ?: ''; |
| 90 |
} elseif ( $file->external_url ) { |
| 91 |
$label = $file->external_url; |
| 92 |
$href = $file->external_url; |
| 93 |
} |
| 94 |
if ( ! $label ) $label = 'btn:' . $file->btn_id; |
| 95 |
|
| 96 |
$pct = $max_count > 0 ? round( ( $file->total / $max_count ) * 100 ) : 0; |
| 97 |
?> |
| 98 |
<div class="qdbp-top-file"> |
| 99 |
<span class="qdbp-top-file__rank qdbp-top-file__rank--<?php echo $rank + 1; ?>"><?php echo $rank + 1; ?></span> |
| 100 |
<div class="qdbp-top-file__info"> |
| 101 |
<?php if ( $href ) : ?> |
| 102 |
<a href="<?php echo esc_url( $href ); ?>" class="qdbp-top-file__name" target="_blank" title="<?php echo esc_attr( $label ); ?>"><?php echo esc_html( $label ); ?></a> |
| 103 |
<?php else : ?> |
| 104 |
<span class="qdbp-top-file__name" title="<?php echo esc_attr( $label ); ?>"><?php echo esc_html( $label ); ?></span> |
| 105 |
<?php endif; ?> |
| 106 |
<div class="qdbp-top-file__bar"> |
| 107 |
<div class="qdbp-top-file__fill" style="width:<?php echo absint( $pct ); ?>%"></div> |
| 108 |
</div> |
| 109 |
</div> |
| 110 |
<span class="qdbp-top-file__count"> |
| 111 |
<?php echo number_format_i18n( $file->total ); ?> |
| 112 |
<span class="qdbp-top-file__count-label"><?php esc_html_e( 'downloads', 'quick-download-button' ); ?></span> |
| 113 |
</span> |
| 114 |
</div> |
| 115 |
<?php endforeach; ?> |
| 116 |
</div> |
| 117 |
</div> |
| 118 |
<?php else : ?> |
| 119 |
<div class="qdbp-empty-state"> |
| 120 |
<span class="dashicons dashicons-download qdbp-empty-state__icon"></span> |
| 121 |
<p><?php esc_html_e( 'No downloads recorded yet. Download data will appear here once visitors start downloading files.', 'quick-download-button' ); ?></p> |
| 122 |
</div> |
| 123 |
<?php endif; ?> |
| 124 |
|
| 125 |
</div> |
| 126 |
|