Download Monitor - Version 1.0.4

Version Description

  • Tweak admin page detection to work when no downloads exist.
  • Fix dashboard widget warning.
  • Add filters to logs and export csv function.
  • Added extra columns to CSV.
Download this release

Release Info

Developer mikejolley
Plugin Icon 128x128 Download Monitor
Version 1.0.4
Comparing to
See all releases

Code changes from version 1.0.3 to 1.0.4

assets/css/admin.css CHANGED
@@ -1,7 +1,4 @@
1
  /* Logs */
2
- #dlm_logs .tablenav.top {
3
- display: none;
4
- }
5
  #dlm_logs td {
6
  padding: 7px 7px;
7
  vertical-align: middle;
1
  /* Logs */
 
 
 
2
  #dlm_logs td {
3
  padding: 7px 7px;
4
  vertical-align: middle;
assets/css/admin.less CHANGED
@@ -1,8 +1,5 @@
1
  /* Logs */
2
  #dlm_logs {
3
- .tablenav.top {
4
- display: none;
5
- }
6
  td {
7
  padding: 7px 7px;
8
  vertical-align: middle;
1
  /* Logs */
2
  #dlm_logs {
 
 
 
3
  td {
4
  padding: 7px 7px;
5
  vertical-align: middle;
download-monitor.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Download Monitor
4
  Plugin URI: http://mikejolley.com/projects/download-monitor/
5
  Description: A full solution for managing downloadable files, monitoring downloads and outputting download links and file information on your WordPress powered site.
6
- Version: 1.0.3
7
  Author: Mike Jolley
8
  Author URI: http://mikejolley.com
9
  Requires at least: 3.5
@@ -39,7 +39,7 @@ class WP_DLM {
39
  global $wpdb;
40
 
41
  // Define constants
42
- define( 'DLM_VERSION', '1.0.3' );
43
 
44
  // Table for logs
45
  $wpdb->download_log = $wpdb->prefix . 'download_log';
3
  Plugin Name: Download Monitor
4
  Plugin URI: http://mikejolley.com/projects/download-monitor/
5
  Description: A full solution for managing downloadable files, monitoring downloads and outputting download links and file information on your WordPress powered site.
6
+ Version: 1.0.4
7
  Author: Mike Jolley
8
  Author URI: http://mikejolley.com
9
  Requires at least: 3.5
39
  global $wpdb;
40
 
41
  // Define constants
42
+ define( 'DLM_VERSION', '1.0.4' );
43
 
44
  // Table for logs
45
  $wpdb->download_log = $wpdb->prefix . 'download_log';
includes/admin/class-dlm-admin-dashboard.php CHANGED
@@ -49,8 +49,10 @@ class DLM_Admin_Dashboard {
49
 
50
  $download_ids = get_posts( $args );
51
 
52
- if ( empty( $download_ids ) )
53
  echo '<p>' . __( 'There are no stats available yet!', 'download_monitor' ) . '</p>';
 
 
54
 
55
  $downloads = array();
56
 
@@ -58,8 +60,8 @@ class DLM_Admin_Dashboard {
58
  $downloads[ $download_id ] = get_post_meta( $download_id, '_download_count', true );
59
  }
60
 
61
- $max_count = max( $downloads );
62
-
63
  ?>
64
  <table class="download_chart" cellpadding="0" cellspacing="0">
65
  <thead>
@@ -70,7 +72,7 @@ class DLM_Admin_Dashboard {
70
  </thead>
71
  <tbody>
72
  <?php
73
- foreach ( $downloads as $download_id => $count ) {
74
  $download = new DLM_Download( $download_id );
75
 
76
  $width = $count / ( $max_count ? $max_count : 1 ) * 67;
49
 
50
  $download_ids = get_posts( $args );
51
 
52
+ if ( empty( $download_ids ) ) {
53
  echo '<p>' . __( 'There are no stats available yet!', 'download_monitor' ) . '</p>';
54
+ return;
55
+ }
56
 
57
  $downloads = array();
58
 
60
  $downloads[ $download_id ] = get_post_meta( $download_id, '_download_count', true );
61
  }
62
 
63
+ if ( $downloads )
64
+ $max_count = max( $downloads );
65
  ?>
66
  <table class="download_chart" cellpadding="0" cellspacing="0">
67
  <thead>
72
  </thead>
73
  <tbody>
74
  <?php
75
+ if ( $downloads ) foreach ( $downloads as $download_id => $count ) {
76
  $download = new DLM_Download( $download_id );
77
 
78
  $width = $count / ( $max_count ? $max_count : 1 ) * 67;
includes/admin/class-dlm-admin.php CHANGED
@@ -194,7 +194,7 @@ class DLM_Admin {
194
  $enqueue = false;
195
 
196
  if ( $hook == 'post-new.php' || $hook == 'post.php' || $hook == 'edit.php' )
197
- if ( 'dlm_download' === $post->post_type )
198
  $enqueue = true;
199
 
200
  if ( strstr( $hook, 'dlm_download_page' ) )
@@ -358,7 +358,7 @@ class DLM_Admin {
358
  <div class="wrap">
359
  <div id="icon-edit" class="icon32 icon32-posts-dlm_download"><br/></div>
360
 
361
- <h2><?php _e( 'Download Logs', 'download_monitor' ); ?> <a href="<?php echo admin_url( '?dlm_download_logs=true' ); ?>" class="add-new-h2"><?php _e( 'Export CSV', 'download_monitor' ); ?></a></h2><br/>
362
  <form id="dlm_logs">
363
  <?php $DLM_Logging_List_Table->display() ?>
364
  </form>
@@ -378,17 +378,31 @@ class DLM_Admin {
378
  if ( empty( $_GET['dlm_download_logs'] ) )
379
  return;
380
 
 
 
 
381
  $items = $wpdb->get_results(
382
- "SELECT * FROM {$wpdb->download_log}
383
- WHERE type = 'download'
384
- ORDER BY download_date DESC"
 
 
 
 
 
 
 
 
385
  );
386
 
387
  $rows = array();
388
  $row = array();
389
  $row[] = __( 'Download ID', 'download_monitor' );
390
  $row[] = __( 'Version ID', 'download_monitor' );
 
391
  $row[] = __( 'User ID', 'download_monitor' );
 
 
392
  $row[] = __( 'User IP', 'download_monitor' );
393
  $row[] = __( 'User Agent', 'download_monitor' );
394
  $row[] = __( 'Date', 'download_monitor' );
@@ -400,7 +414,28 @@ class DLM_Admin {
400
  $row = array();
401
  $row[] = $item->download_id;
402
  $row[] = $item->version_id;
 
 
 
 
 
 
 
 
 
403
  $row[] = $item->user_id;
 
 
 
 
 
 
 
 
 
 
 
 
404
  $row[] = $item->user_ip;
405
  $row[] = $item->user_agent;
406
  $row[] = $item->download_date;
194
  $enqueue = false;
195
 
196
  if ( $hook == 'post-new.php' || $hook == 'post.php' || $hook == 'edit.php' )
197
+ if ( ( ! empty( $_GET['post_type'] ) && $_GET['post_type'] == 'dlm_download' ) || ( ! empty( $post->post_type ) && 'dlm_download' === $post->post_type ) )
198
  $enqueue = true;
199
 
200
  if ( strstr( $hook, 'dlm_download_page' ) )
358
  <div class="wrap">
359
  <div id="icon-edit" class="icon32 icon32-posts-dlm_download"><br/></div>
360
 
361
+ <h2><?php _e( 'Download Logs', 'download_monitor' ); ?> <a href="<?php echo add_query_arg( 'dlm_download_logs', 'true' ); ?>" class="add-new-h2"><?php _e( 'Export CSV', 'download_monitor' ); ?></a></h2><br/>
362
  <form id="dlm_logs">
363
  <?php $DLM_Logging_List_Table->display() ?>
364
  </form>
378
  if ( empty( $_GET['dlm_download_logs'] ) )
379
  return;
380
 
381
+ $filter_status = isset( $_REQUEST['filter_status'] ) ? sanitize_text_field( $_REQUEST['filter_status'] ) : '';
382
+ $filter_month = ! empty( $_REQUEST['filter_month'] ) ? sanitize_text_field( $_REQUEST['filter_month'] ) : '';
383
+
384
  $items = $wpdb->get_results(
385
+ $wpdb->prepare(
386
+ "SELECT * FROM {$wpdb->download_log}
387
+ WHERE type = 'download'
388
+ " . ( $filter_status ? "AND download_status = '%s'" : "%s" ) . "
389
+ " . ( $filter_month ? "AND download_date >= '%s'" : "%s" ) . "
390
+ " . ( $filter_month ? "AND download_date <= '%s'" : "%s" ) . "
391
+ ORDER BY download_date DESC",
392
+ ( $filter_status ? $filter_status : "" ),
393
+ ( $filter_month ? date( 'Y-m-01', strtotime( $filter_month ) ) : "" ),
394
+ ( $filter_month ? date( 'Y-m-t', strtotime( $filter_month ) ) : "" )
395
+ )
396
  );
397
 
398
  $rows = array();
399
  $row = array();
400
  $row[] = __( 'Download ID', 'download_monitor' );
401
  $row[] = __( 'Version ID', 'download_monitor' );
402
+ $row[] = __( 'Filename', 'download_monitor' );
403
  $row[] = __( 'User ID', 'download_monitor' );
404
+ $row[] = __( 'User Login', 'download_monitor' );
405
+ $row[] = __( 'User Email', 'download_monitor' );
406
  $row[] = __( 'User IP', 'download_monitor' );
407
  $row[] = __( 'User Agent', 'download_monitor' );
408
  $row[] = __( 'Date', 'download_monitor' );
414
  $row = array();
415
  $row[] = $item->download_id;
416
  $row[] = $item->version_id;
417
+
418
+ $download = new DLM_Download( $item->download_id );
419
+ $download->set_version( $item->version_id );
420
+
421
+ if ( $download->exists() && $download->get_the_filename() )
422
+ $row[] = $download->get_the_filename();
423
+ else
424
+ $row[] = '-';
425
+
426
  $row[] = $item->user_id;
427
+
428
+ if ( $item->user_id )
429
+ $user = get_user_by( 'id', $item->user_id );
430
+
431
+ if ( ! isset( $user ) || ! $user ) {
432
+ $row[] = '-';
433
+ $row[] = '-';
434
+ } else {
435
+ $row[] = $user->user_login;
436
+ $row[] = $user->user_email;
437
+ }
438
+
439
  $row[] = $item->user_ip;
440
  $row[] = $item->user_agent;
441
  $row[] = $item->download_date;
includes/admin/class-dlm-logging-list-table.php CHANGED
@@ -12,13 +12,20 @@ class DLM_Logging_List_Table extends WP_List_Table {
12
  * @access public
13
  */
14
  function __construct(){
15
- global $status, $page;
16
 
17
  parent::__construct( array(
18
  'singular' => 'log',
19
  'plural' => 'logs',
20
  'ajax' => false
21
  ) );
 
 
 
 
 
 
 
22
  }
23
 
24
  /**
@@ -123,6 +130,64 @@ class DLM_Logging_List_Table extends WP_List_Table {
123
  return $columns;
124
  }
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  /**
127
  * prepare_items function.
128
  *
@@ -132,7 +197,7 @@ class DLM_Logging_List_Table extends WP_List_Table {
132
  function prepare_items() {
133
  global $wpdb;
134
 
135
- $per_page = 40;
136
  $current_page = $this->get_pagenum();
137
 
138
  // Init headers
@@ -148,8 +213,14 @@ class DLM_Logging_List_Table extends WP_List_Table {
148
  $wpdb->prepare(
149
  "SELECT * FROM {$wpdb->download_log}
150
  WHERE type = 'download'
 
 
 
151
  ORDER BY download_date DESC
152
  LIMIT %d, %d",
 
 
 
153
  ( $current_page - 1 ) * $per_page,
154
  $per_page
155
  )
12
  * @access public
13
  */
14
  function __construct(){
15
+ global $status, $page, $wpdb;
16
 
17
  parent::__construct( array(
18
  'singular' => 'log',
19
  'plural' => 'logs',
20
  'ajax' => false
21
  ) );
22
+
23
+ $this->filter_status = isset( $_REQUEST['filter_status'] ) ? sanitize_text_field( $_REQUEST['filter_status'] ) : '';
24
+ $this->logs_per_page = ! empty( $_REQUEST['logs_per_page'] ) ? intval( $_REQUEST['logs_per_page'] ) : 25;
25
+ $this->filter_month = ! empty( $_REQUEST['filter_month'] ) ? sanitize_text_field( $_REQUEST['filter_month'] ) : '';
26
+
27
+ if ( $this->logs_per_page < 1 )
28
+ $this->logs_per_page = 9999999999999;
29
  }
30
 
31
  /**
130
  return $columns;
131
  }
132
 
133
+ /**
134
+ * Generate the table navigation above or below the table
135
+ */
136
+ public function display_tablenav( $which ) {
137
+ ?>
138
+ <div class="tablenav <?php echo esc_attr( $which ); ?>">
139
+ <?php if ( 'top' == $which ) : ?>
140
+ <div class="alignleft actions">
141
+ <select name="filter_status">
142
+ <option value=""><?php _e( 'Any status', 'download_monitor' ); ?></option>
143
+ <option value="failed" <?php selected( $this->filter_status, 'failed' ); ?>><?php _e( 'Failed', 'download_monitor' ); ?></option>
144
+ <option value="redirected" <?php selected( $this->filter_status, 'redirected' ); ?>><?php _e( 'Redirected', 'download_monitor' ); ?></option>
145
+ <option value="completed" <?php selected( $this->filter_status, 'completed' ); ?>><?php _e( 'Completed', 'download_monitor' ); ?></option>
146
+ </select>
147
+ <select name="filter_month">
148
+ <option value=""><?php _e( 'Any month', 'download_monitor' ); ?></option>
149
+ <?php
150
+ global $wpdb;
151
+
152
+ $oldest = $wpdb->get_var(
153
+ "SELECT download_date FROM {$wpdb->download_log}
154
+ WHERE type = 'download'
155
+ ORDER BY download_date ASC
156
+ LIMIT 1"
157
+ );
158
+ $month = current_time( 'timestamp' );
159
+
160
+ if ( $oldest )
161
+ $oldest_month = strtotime( $oldest );
162
+ else
163
+ $oldest_month = $month;
164
+
165
+ do {
166
+ echo '<option value="' . date( 'Y-m', $month ) . '" ' . selected( date( 'Y-m', $month ), $this->filter_month, false ). '>' . date_i18n( 'F Y', $month ) . '</option>';
167
+ $month = strtotime( '-1 Month', $month );
168
+ } while ( $month >= $oldest_month );
169
+ ?>
170
+ </select>
171
+ <select name="logs_per_page">
172
+ <option value="25"><?php _e( '25 per page', 'download_monitor' ); ?></option>
173
+ <option value="50" <?php selected( $this->logs_per_page, 50 ) ?>><?php _e( '50 per page', 'download_monitor' ); ?></option>
174
+ <option value="100" <?php selected( $this->logs_per_page, 100 ) ?>><?php _e( '100 per page', 'download_monitor' ); ?></option>
175
+ <option value="200" <?php selected( $this->logs_per_page, 200 ) ?>><?php _e( '200 per page', 'download_monitor' ); ?></option>
176
+ <option value="-1" <?php selected( $this->logs_per_page, -1 ) ?>><?php _e( 'Show All', 'download_monitor' ); ?></option>
177
+ </select>
178
+ <input type="hidden" name="post_type" value="dlm_download" />
179
+ <input type="hidden" name="page" value="download-monitor-logs" />
180
+ <input type="submit" value="<?php _e( 'Filter', 'download_monitor' ); ?>" class="button" />
181
+ </div>
182
+ <?php endif; ?>
183
+ <?php
184
+ $this->extra_tablenav( $which );
185
+ $this->pagination( $which );
186
+ ?>
187
+ <br class="clear" />
188
+ </div><?php
189
+ }
190
+
191
  /**
192
  * prepare_items function.
193
  *
197
  function prepare_items() {
198
  global $wpdb;
199
 
200
+ $per_page = $this->logs_per_page;
201
  $current_page = $this->get_pagenum();
202
 
203
  // Init headers
213
  $wpdb->prepare(
214
  "SELECT * FROM {$wpdb->download_log}
215
  WHERE type = 'download'
216
+ " . ( $this->filter_status ? "AND download_status = '%s'" : "%s" ) . "
217
+ " . ( $this->filter_month ? "AND download_date >= '%s'" : "%s" ) . "
218
+ " . ( $this->filter_month ? "AND download_date <= '%s'" : "%s" ) . "
219
  ORDER BY download_date DESC
220
  LIMIT %d, %d",
221
+ ( $this->filter_status ? $this->filter_status : "" ),
222
+ ( $this->filter_month ? date( 'Y-m-01', strtotime( $this->filter_month ) ) : "" ),
223
+ ( $this->filter_month ? date( 'Y-m-t', strtotime( $this->filter_month ) ) : "" ),
224
  ( $current_page - 1 ) * $per_page,
225
  $per_page
226
  )
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=mike.jol
4
  Tags: download, downloads, monitor, hits, download monitor, tracking, admin, count, counter, files, versions, download count, logging
5
  Requires at least: 3.5
6
  Tested up to: 3.5
7
- Stable tag: 1.0.3
8
  License: GPLv3
9
 
10
  Download Monitor is a plugin for uploading and managing downloads, tracking downloads, and displaying links.
@@ -108,6 +108,12 @@ Admin hits are not counted, log out and try!
108
 
109
  == Changelog ==
110
 
 
 
 
 
 
 
111
  = 1.0.3 =
112
  * Fix config page to work with multibyte tab names.
113
  * Japanese locale by hide92795
4
  Tags: download, downloads, monitor, hits, download monitor, tracking, admin, count, counter, files, versions, download count, logging
5
  Requires at least: 3.5
6
  Tested up to: 3.5
7
+ Stable tag: 1.0.4
8
  License: GPLv3
9
 
10
  Download Monitor is a plugin for uploading and managing downloads, tracking downloads, and displaying links.
108
 
109
  == Changelog ==
110
 
111
+ = 1.0.4 =
112
+ * Tweak admin page detection to work when no downloads exist.
113
+ * Fix dashboard widget warning.
114
+ * Add filters to logs and export csv function.
115
+ * Added extra columns to CSV.
116
+
117
  = 1.0.3 =
118
  * Fix config page to work with multibyte tab names.
119
  * Japanese locale by hide92795