overview.php
284 lines
| 1 | <?php |
| 2 | /** |
| 3 | * User: shahnuralam |
| 4 | * Date: 5/7/17 |
| 5 | * Time: 2:19 AM |
| 6 | */ |
| 7 | global $wpdb; |
| 8 | if(!defined('ABSPATH')) die('!'); |
| 9 | |
| 10 | // Cache key based on current hour (refreshes every hour) |
| 11 | $cache_key = 'wpdm_overview_' . wp_date('Y-m-d-H'); |
| 12 | $overview_data = get_transient($cache_key); |
| 13 | |
| 14 | if (!$overview_data) { |
| 15 | // Gather stats with single optimized query where possible |
| 16 | $packs = wp_count_posts('wpdmpro'); |
| 17 | $total_packages = $packs->publish; |
| 18 | $total_downloads = (int) $wpdb->get_var("SELECT SUM(meta_value) FROM {$wpdb->prefix}postmeta WHERE meta_key='__wpdm_download_count'"); |
| 19 | $total_categories = wp_count_terms('wpdmcategory'); |
| 20 | $total_subscribers = (int) $wpdb->get_var("SELECT COUNT(DISTINCT email) FROM {$wpdb->prefix}ahm_emails"); |
| 21 | |
| 22 | $today_start = strtotime(wp_date("Y-m-d 0:0:0")); |
| 23 | $today_end = time(); |
| 24 | $subscribed_today = (int) $wpdb->get_var($wpdb->prepare( |
| 25 | "SELECT COUNT(DISTINCT email) FROM {$wpdb->prefix}ahm_emails WHERE date > %d AND date < %d", |
| 26 | $today_start, |
| 27 | $today_end |
| 28 | )); |
| 29 | |
| 30 | // Use year, month, day columns (same as download-trends.php) |
| 31 | $downloads_today = (int) $wpdb->get_var($wpdb->prepare( |
| 32 | "SELECT COUNT(*) FROM {$wpdb->prefix}ahm_download_stats WHERE year = %d AND month = %d AND day = %d", |
| 33 | wp_date('Y'), |
| 34 | wp_date('n'), // 'n' returns month without leading zero (1-12) |
| 35 | wp_date('j') // 'j' returns day without leading zero (1-31) |
| 36 | )); |
| 37 | |
| 38 | $overview_data = [ |
| 39 | 'total_packages' => $total_packages, |
| 40 | 'total_downloads' => $total_downloads, |
| 41 | 'total_categories' => $total_categories, |
| 42 | 'total_subscribers' => $total_subscribers, |
| 43 | 'subscribed_today' => $subscribed_today, |
| 44 | 'downloads_today' => $downloads_today, |
| 45 | ]; |
| 46 | |
| 47 | // Cache for 30 minutes |
| 48 | set_transient($cache_key, $overview_data, 30 * MINUTE_IN_SECONDS); |
| 49 | } |
| 50 | |
| 51 | extract($overview_data); |
| 52 | ?> |
| 53 | <style> |
| 54 | .wpdm-overview-widget { |
| 55 | --wpdm-primary: #6366f1; |
| 56 | --wpdm-primary-light: #eef2ff; |
| 57 | --wpdm-success: #10b981; |
| 58 | --wpdm-success-light: #ecfdf5; |
| 59 | --wpdm-warning: #f59e0b; |
| 60 | --wpdm-warning-light: #fffbeb; |
| 61 | --wpdm-info: #0ea5e9; |
| 62 | --wpdm-info-light: #f0f9ff; |
| 63 | --wpdm-purple: #8b5cf6; |
| 64 | --wpdm-purple-light: #f5f3ff; |
| 65 | --wpdm-text: #1e293b; |
| 66 | --wpdm-text-muted: #64748b; |
| 67 | --wpdm-border: #e2e8f0; |
| 68 | --wpdm-bg: #f8fafc; |
| 69 | --wpdm-radius: 10px; |
| 70 | --wpdm-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.08); |
| 71 | margin: -12px; |
| 72 | } |
| 73 | |
| 74 | .wpdm-overview-grid { |
| 75 | display: grid; |
| 76 | grid-template-columns: repeat(2, 1fr); |
| 77 | gap: 12px; |
| 78 | padding: 16px; |
| 79 | background: var(--wpdm-bg); |
| 80 | } |
| 81 | |
| 82 | .wpdm-stat-card { |
| 83 | background: #fff; |
| 84 | border-radius: var(--wpdm-radius); |
| 85 | padding: 16px; |
| 86 | display: flex; |
| 87 | align-items: flex-start; |
| 88 | gap: 12px; |
| 89 | box-shadow: var(--wpdm-shadow); |
| 90 | border: 1px solid var(--wpdm-border); |
| 91 | transition: transform 150ms ease, box-shadow 150ms ease; |
| 92 | } |
| 93 | |
| 94 | .wpdm-stat-card:hover { |
| 95 | transform: translateY(-2px); |
| 96 | box-shadow: 0 4px 12px rgb(0 0 0 / 0.1); |
| 97 | } |
| 98 | |
| 99 | .wpdm-stat-icon { |
| 100 | width: 44px; |
| 101 | height: 44px; |
| 102 | border-radius: 10px; |
| 103 | display: flex; |
| 104 | align-items: center; |
| 105 | justify-content: center; |
| 106 | flex-shrink: 0; |
| 107 | } |
| 108 | |
| 109 | .wpdm-stat-icon svg { |
| 110 | width: 22px; |
| 111 | height: 22px; |
| 112 | } |
| 113 | |
| 114 | .wpdm-stat-icon--primary { |
| 115 | background: var(--wpdm-primary-light); |
| 116 | color: var(--wpdm-primary); |
| 117 | } |
| 118 | |
| 119 | .wpdm-stat-icon--success { |
| 120 | background: var(--wpdm-success-light); |
| 121 | color: var(--wpdm-success); |
| 122 | } |
| 123 | |
| 124 | .wpdm-stat-icon--warning { |
| 125 | background: var(--wpdm-warning-light); |
| 126 | color: var(--wpdm-warning); |
| 127 | } |
| 128 | |
| 129 | .wpdm-stat-icon--info { |
| 130 | background: var(--wpdm-info-light); |
| 131 | color: var(--wpdm-info); |
| 132 | } |
| 133 | |
| 134 | .wpdm-stat-icon--purple { |
| 135 | background: var(--wpdm-purple-light); |
| 136 | color: var(--wpdm-purple); |
| 137 | } |
| 138 | |
| 139 | .wpdm-stat-content { |
| 140 | flex: 1; |
| 141 | min-width: 0; |
| 142 | } |
| 143 | |
| 144 | .wpdm-stat-value { |
| 145 | font-size: 24px; |
| 146 | font-weight: 700; |
| 147 | color: var(--wpdm-text); |
| 148 | line-height: 1.2; |
| 149 | margin-bottom: 2px; |
| 150 | } |
| 151 | |
| 152 | .wpdm-stat-label { |
| 153 | font-size: 12px; |
| 154 | color: var(--wpdm-text-muted); |
| 155 | font-weight: 500; |
| 156 | text-transform: uppercase; |
| 157 | letter-spacing: 0.5px; |
| 158 | } |
| 159 | |
| 160 | .wpdm-stat-badge { |
| 161 | display: inline-flex; |
| 162 | align-items: center; |
| 163 | gap: 4px; |
| 164 | font-size: 11px; |
| 165 | font-weight: 600; |
| 166 | padding: 3px 8px; |
| 167 | border-radius: 12px; |
| 168 | margin-top: 6px; |
| 169 | } |
| 170 | |
| 171 | .wpdm-stat-badge--success { |
| 172 | background: var(--wpdm-success-light); |
| 173 | color: var(--wpdm-success); |
| 174 | } |
| 175 | |
| 176 | @media (max-width: 782px) { |
| 177 | .wpdm-overview-grid { |
| 178 | grid-template-columns: 1fr; |
| 179 | } |
| 180 | } |
| 181 | </style> |
| 182 | |
| 183 | <div class="wpdm-overview-widget"> |
| 184 | <div class="wpdm-overview-grid"> |
| 185 | |
| 186 | <!-- Total Packages --> |
| 187 | <div class="wpdm-stat-card"> |
| 188 | <div class="wpdm-stat-icon wpdm-stat-icon--primary"> |
| 189 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 190 | <path stroke-linecap="round" stroke-linejoin="round" d="m20.25 7.5-.625 10.632a2.25 2.25 0 0 1-2.247 2.118H6.622a2.25 2.25 0 0 1-2.247-2.118L3.75 7.5M10 11.25h4M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125Z" /> |
| 191 | </svg> |
| 192 | </div> |
| 193 | <div class="wpdm-stat-content"> |
| 194 | <div class="wpdm-stat-value"><?php echo number_format($total_packages); ?></div> |
| 195 | <div class="wpdm-stat-label"><?php _e("Packages", "download-manager"); ?></div> |
| 196 | </div> |
| 197 | </div> |
| 198 | |
| 199 | <!-- Total Downloads --> |
| 200 | <div class="wpdm-stat-card"> |
| 201 | <div class="wpdm-stat-icon wpdm-stat-icon--success"> |
| 202 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 203 | <path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" /> |
| 204 | </svg> |
| 205 | </div> |
| 206 | <div class="wpdm-stat-content"> |
| 207 | <div class="wpdm-stat-value"><?php echo number_format($total_downloads); ?></div> |
| 208 | <div class="wpdm-stat-label"><?php _e("Downloads", "download-manager"); ?></div> |
| 209 | </div> |
| 210 | </div> |
| 211 | |
| 212 | <!-- Total Categories --> |
| 213 | <div class="wpdm-stat-card"> |
| 214 | <div class="wpdm-stat-icon wpdm-stat-icon--warning"> |
| 215 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 216 | <path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12.75V12A2.25 2.25 0 0 1 4.5 9.75h15A2.25 2.25 0 0 1 21.75 12v.75m-8.69-6.44-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z" /> |
| 217 | </svg> |
| 218 | </div> |
| 219 | <div class="wpdm-stat-content"> |
| 220 | <div class="wpdm-stat-value"><?php echo number_format($total_categories); ?></div> |
| 221 | <div class="wpdm-stat-label"><?php _e("Categories", "download-manager"); ?></div> |
| 222 | </div> |
| 223 | </div> |
| 224 | |
| 225 | <!-- Total Subscribers --> |
| 226 | <div class="wpdm-stat-card"> |
| 227 | <div class="wpdm-stat-icon wpdm-stat-icon--info"> |
| 228 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 229 | <path stroke-linecap="round" stroke-linejoin="round" d="M15 19.128a9.38 9.38 0 0 0 2.625.372 9.337 9.337 0 0 0 4.121-.952 4.125 4.125 0 0 0-7.533-2.493M15 19.128v-.003c0-1.113-.285-2.16-.786-3.07M15 19.128v.106A12.318 12.318 0 0 1 8.624 21c-2.331 0-4.512-.645-6.374-1.766l-.001-.109a6.375 6.375 0 0 1 11.964-3.07M12 6.375a3.375 3.375 0 1 1-6.75 0 3.375 3.375 0 0 1 6.75 0Zm8.25 2.25a2.625 2.625 0 1 1-5.25 0 2.625 2.625 0 0 1 5.25 0Z" /> |
| 230 | </svg> |
| 231 | </div> |
| 232 | <div class="wpdm-stat-content"> |
| 233 | <div class="wpdm-stat-value"><?php echo number_format($total_subscribers); ?></div> |
| 234 | <div class="wpdm-stat-label"><?php _e("Subscribers", "download-manager"); ?></div> |
| 235 | </div> |
| 236 | </div> |
| 237 | |
| 238 | <!-- Downloads Today --> |
| 239 | <div class="wpdm-stat-card"> |
| 240 | <div class="wpdm-stat-icon wpdm-stat-icon--success"> |
| 241 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 242 | <path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" /> |
| 243 | </svg> |
| 244 | </div> |
| 245 | <div class="wpdm-stat-content"> |
| 246 | <div class="wpdm-stat-value"><?php echo number_format($downloads_today); ?></div> |
| 247 | <div class="wpdm-stat-label"><?php _e("Downloads Today", "download-manager"); ?></div> |
| 248 | <?php if ($downloads_today > 0): ?> |
| 249 | <div class="wpdm-stat-badge wpdm-stat-badge--success"> |
| 250 | <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"> |
| 251 | <polyline points="23 6 13.5 15.5 8.5 10.5 1 18"></polyline> |
| 252 | <polyline points="17 6 23 6 23 12"></polyline> |
| 253 | </svg> |
| 254 | <?php _e("Active", "download-manager"); ?> |
| 255 | </div> |
| 256 | <?php endif; ?> |
| 257 | </div> |
| 258 | </div> |
| 259 | |
| 260 | <!-- Subscribed Today --> |
| 261 | <div class="wpdm-stat-card"> |
| 262 | <div class="wpdm-stat-icon wpdm-stat-icon--purple"> |
| 263 | <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"> |
| 264 | <path stroke-linecap="round" stroke-linejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" /> |
| 265 | </svg> |
| 266 | </div> |
| 267 | <div class="wpdm-stat-content"> |
| 268 | <div class="wpdm-stat-value"><?php echo number_format($subscribed_today); ?></div> |
| 269 | <div class="wpdm-stat-label"><?php _e("Subscribed Today", "download-manager"); ?></div> |
| 270 | <?php if ($subscribed_today > 0): ?> |
| 271 | <div class="wpdm-stat-badge wpdm-stat-badge--success"> |
| 272 | <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"> |
| 273 | <polyline points="23 6 13.5 15.5 8.5 10.5 1 18"></polyline> |
| 274 | <polyline points="17 6 23 6 23 12"></polyline> |
| 275 | </svg> |
| 276 | <?php _e("Active", "download-manager"); ?> |
| 277 | </div> |
| 278 | <?php endif; ?> |
| 279 | </div> |
| 280 | </div> |
| 281 | |
| 282 | </div> |
| 283 | </div> |
| 284 |