dashboard.php
5 months ago
download-history.php
5 months ago
edit-profile.php
5 months ago
profile.php
5 months ago
profile.php
231 lines
| 1 | <?php |
| 2 | /** |
| 3 | * User Dashboard - Profile/Home |
| 4 | * Enterprise-grade design |
| 5 | */ |
| 6 | |
| 7 | global $current_user, $wpdb; |
| 8 | |
| 9 | $total_downloads = (int) $wpdb->get_var($wpdb->prepare( |
| 10 | "SELECT COUNT(*) FROM {$wpdb->prefix}ahm_download_stats WHERE uid = %d", |
| 11 | $current_user->ID |
| 12 | )); |
| 13 | |
| 14 | $today_downloads = (int) $wpdb->get_var($wpdb->prepare( |
| 15 | "SELECT COUNT(*) FROM {$wpdb->prefix}ahm_download_stats WHERE uid = %d AND `year` = YEAR(CURDATE()) AND `month` = MONTH(CURDATE()) AND `day` = DAY(CURDATE())", |
| 16 | $current_user->ID |
| 17 | )); |
| 18 | |
| 19 | $this_month_downloads = (int) $wpdb->get_var($wpdb->prepare( |
| 20 | "SELECT COUNT(*) FROM {$wpdb->prefix}ahm_download_stats WHERE uid = %d AND `year` = YEAR(CURDATE()) AND `month` = MONTH(CURDATE())", |
| 21 | $current_user->ID |
| 22 | )); |
| 23 | ?> |
| 24 | |
| 25 | <?php do_action("wpdm_before_user_dashboard_summery"); ?> |
| 26 | |
| 27 | <!-- Stats Grid --> |
| 28 | <div class="wpdm-stats-grid"> |
| 29 | <div class="wpdm-stat-card"> |
| 30 | <div class="wpdm-stat-icon wpdm-stat-icon--success"> |
| 31 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg> |
| 32 | </div> |
| 33 | <div class="wpdm-stat-content"> |
| 34 | <span class="wpdm-stat-label"><?php esc_html_e('Total Downloads', 'download-manager'); ?></span> |
| 35 | <span class="wpdm-stat-value"><?php echo number_format($total_downloads); ?></span> |
| 36 | </div> |
| 37 | </div> |
| 38 | |
| 39 | <div class="wpdm-stat-card"> |
| 40 | <div class="wpdm-stat-icon wpdm-stat-icon--info"> |
| 41 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line></svg> |
| 42 | </div> |
| 43 | <div class="wpdm-stat-content"> |
| 44 | <span class="wpdm-stat-label"><?php esc_html_e('This Month', 'download-manager'); ?></span> |
| 45 | <span class="wpdm-stat-value"><?php echo number_format($this_month_downloads); ?></span> |
| 46 | </div> |
| 47 | </div> |
| 48 | |
| 49 | <div class="wpdm-stat-card"> |
| 50 | <div class="wpdm-stat-icon wpdm-stat-icon--warning"> |
| 51 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg> |
| 52 | </div> |
| 53 | <div class="wpdm-stat-content"> |
| 54 | <span class="wpdm-stat-label"><?php esc_html_e('Today', 'download-manager'); ?></span> |
| 55 | <span class="wpdm-stat-value"><?php echo number_format($today_downloads); ?></span> |
| 56 | </div> |
| 57 | </div> |
| 58 | </div> |
| 59 | |
| 60 | <?php do_action("wpdm_after_user_dashboard_summery"); ?> |
| 61 | |
| 62 | <?php |
| 63 | // Recommended Downloads |
| 64 | if (isset($params['recommended']) && (term_exists($params['recommended'], 'wpdmcategory') || $params['recommended'] == 'recent')) { |
| 65 | $qparams = [ |
| 66 | 'post_type' => 'wpdmpro', |
| 67 | 'posts_per_page' => 6, |
| 68 | 'orderby' => 'rand' |
| 69 | ]; |
| 70 | |
| 71 | if ($params['recommended'] != 'recent') { |
| 72 | $qparams['tax_query'] = [['taxonomy' => 'wpdmcategory', 'field' => 'slug', 'terms' => explode(",", $params['recommended'])]]; |
| 73 | } else { |
| 74 | $qparams['orderby'] = 'date'; |
| 75 | } |
| 76 | |
| 77 | $q = new WP_Query($qparams); |
| 78 | if ($q->have_posts()) { |
| 79 | ?> |
| 80 | <div class="wpdm-card" style="margin-top: 1.5rem;"> |
| 81 | <div class="wpdm-card-header"> |
| 82 | <h3> |
| 83 | <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"></polygon></svg> |
| 84 | <?php esc_html_e('Recommended Downloads', 'download-manager'); ?> |
| 85 | </h3> |
| 86 | </div> |
| 87 | <div class="wpdm-card-body"> |
| 88 | <div class="wpdm-recommended-grid"> |
| 89 | <?php |
| 90 | while ($q->have_posts()) { |
| 91 | $q->the_post(); |
| 92 | if (WPDM()->package->userCanAccess(get_the_ID())) { |
| 93 | ?> |
| 94 | <a href="<?php the_permalink(); ?>" class="wpdm-recommended-item"> |
| 95 | <div class="wpdm-recommended-thumb"> |
| 96 | <?php |
| 97 | $thumb = wpdm_thumb(get_the_ID(), [300, 225], 'url'); |
| 98 | if ($thumb) { |
| 99 | echo '<img src="' . esc_url($thumb) . '" alt="' . esc_attr(get_the_title()) . '" class="wpdm-recommended-img">'; |
| 100 | } |
| 101 | ?> |
| 102 | </div> |
| 103 | <span class="wpdm-recommended-title"><?php the_title(); ?></span> |
| 104 | </a> |
| 105 | <?php |
| 106 | } |
| 107 | } |
| 108 | wp_reset_postdata(); |
| 109 | ?> |
| 110 | </div> |
| 111 | </div> |
| 112 | </div> |
| 113 | <?php |
| 114 | } |
| 115 | } |
| 116 | ?> |
| 117 | |
| 118 | <?php |
| 119 | // Favourites |
| 120 | if (isset($params['fav']) && (int)$params['fav'] == 1) { |
| 121 | $myfavs = maybe_unserialize(get_user_meta(get_current_user_id(), '__wpdm_favs', true)); |
| 122 | if (!empty($myfavs)) { |
| 123 | ?> |
| 124 | <div class="wpdm-card" style="margin-top: 1.5rem;"> |
| 125 | <div class="wpdm-card-header"> |
| 126 | <h3> |
| 127 | <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path></svg> |
| 128 | <?php esc_html_e('My Favourites', 'download-manager'); ?> |
| 129 | </h3> |
| 130 | </div> |
| 131 | <div class="wpdm-table-wrap"> |
| 132 | <table class="wpdm-table"> |
| 133 | <thead> |
| 134 | <tr> |
| 135 | <th><?php esc_html_e('Package Name', 'download-manager'); ?></th> |
| 136 | <th style="width: 100px; text-align: right;"><?php esc_html_e('Action', 'download-manager'); ?></th> |
| 137 | </tr> |
| 138 | </thead> |
| 139 | <tbody> |
| 140 | <?php |
| 141 | foreach ($myfavs as $fav) { |
| 142 | $fav_post = get_post($fav); |
| 143 | if (is_object($fav_post) && $fav_post->post_type == 'wpdmpro') { |
| 144 | ?> |
| 145 | <tr id="fav_<?php echo esc_attr($fav); ?>"> |
| 146 | <td> |
| 147 | <a class="wpdm-table-link" href="<?php echo esc_url(get_permalink($fav_post->ID)); ?>"> |
| 148 | <?php echo esc_html($fav_post->post_title); ?> |
| 149 | </a> |
| 150 | </td> |
| 151 | <td style="text-align: right;"> |
| 152 | <?php echo WPDM()->package->favBtn($fav, ['size' => 'btn-xs rem-fav fav_' . $fav, 'a2f_label' => __('Remove', 'download-manager'), 'rff_label' => __('Remove', 'download-manager')], false); ?> |
| 153 | </td> |
| 154 | </tr> |
| 155 | <?php |
| 156 | } |
| 157 | } |
| 158 | ?> |
| 159 | </tbody> |
| 160 | </table> |
| 161 | </div> |
| 162 | </div> |
| 163 | <?php |
| 164 | } |
| 165 | } |
| 166 | ?> |
| 167 | |
| 168 | <!-- Recent Downloads --> |
| 169 | <div class="wpdm-card" style="margin-top: 1.5rem;"> |
| 170 | <div class="wpdm-card-header"> |
| 171 | <h3> |
| 172 | <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg> |
| 173 | <?php esc_html_e('Recent Downloads', 'download-manager'); ?> |
| 174 | </h3> |
| 175 | </div> |
| 176 | <?php |
| 177 | $recent = $wpdb->get_results($wpdb->prepare( |
| 178 | "SELECT p.post_title, s.* FROM {$wpdb->prefix}posts p, {$wpdb->prefix}ahm_download_stats s WHERE s.uid = %d AND s.pid = p.ID ORDER BY s.timestamp DESC LIMIT 5", |
| 179 | $current_user->ID |
| 180 | )); |
| 181 | ?> |
| 182 | <?php if (!empty($recent)) : ?> |
| 183 | <div class="wpdm-table-wrap"> |
| 184 | <table class="wpdm-table"> |
| 185 | <thead> |
| 186 | <tr> |
| 187 | <th><?php esc_html_e('Package Name', 'download-manager'); ?></th> |
| 188 | <th class="wpdm-hide-mobile"><?php esc_html_e('Download Time', 'download-manager'); ?></th> |
| 189 | <th class="wpdm-hide-mobile"><?php esc_html_e('IP Address', 'download-manager'); ?></th> |
| 190 | </tr> |
| 191 | </thead> |
| 192 | <tbody> |
| 193 | <?php foreach ($recent as $stat) : ?> |
| 194 | <tr> |
| 195 | <td> |
| 196 | <a class="wpdm-table-link" href="<?php echo esc_url(get_permalink($stat->pid)); ?>"> |
| 197 | <?php echo esc_html($stat->post_title); ?> |
| 198 | </a> |
| 199 | </td> |
| 200 | <td class="wpdm-hide-mobile"> |
| 201 | <span class="wpdm-date"><?php echo date_i18n(get_option('date_format') . " H:i", $stat->timestamp + wpdm_tzoffset()); ?></span> |
| 202 | </td> |
| 203 | <td class="wpdm-hide-mobile"> |
| 204 | <span class="wpdm-ip"><?php echo esc_html($stat->ip); ?></span> |
| 205 | </td> |
| 206 | </tr> |
| 207 | <?php endforeach; ?> |
| 208 | </tbody> |
| 209 | </table> |
| 210 | </div> |
| 211 | <?php else : ?> |
| 212 | <div class="wpdm-card-body"> |
| 213 | <div class="wpdm-empty-state wpdm-empty-state--compact"> |
| 214 | <svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg> |
| 215 | <p><?php esc_html_e('No downloads yet', 'download-manager'); ?></p> |
| 216 | </div> |
| 217 | </div> |
| 218 | <?php endif; ?> |
| 219 | </div> |
| 220 | |
| 221 | <script> |
| 222 | jQuery(function($) { |
| 223 | $('.rem-fav').on('click', function() { |
| 224 | var ret = $(this).attr('class').match(/fav_([0-9]+)/); |
| 225 | if (ret && ret[1]) { |
| 226 | $('#fav_' + ret[1]).fadeOut(300, function() { $(this).remove(); }); |
| 227 | } |
| 228 | }); |
| 229 | }); |
| 230 | </script> |
| 231 |