Download Monitor - Version 1.9.4

Version Description

Download this release

Release Info

Developer barrykooij
Plugin Icon 128x128 Download Monitor
Version 1.9.4
Comparing to
See all releases

Code changes from version 1.9.3 to 1.9.4

download-monitor.php CHANGED
@@ -3,11 +3,11 @@
3
  Plugin Name: Download Monitor
4
  Plugin URI: https://www.download-monitor.com
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.9.3
7
  Author: Never5
8
  Author URI: https://www.never5.com
9
  Requires at least: 3.8
10
- Tested up to: 4.5
11
  Text Domain: download-monitor
12
 
13
  License: GPL v3
@@ -33,7 +33,7 @@ if ( ! defined( 'ABSPATH' ) ) {
33
  } // Exit if accessed directly
34
 
35
  // Define DLM Version
36
- define( 'DLM_VERSION', '1.9.3' );
37
 
38
  function __download_monitor_main() {
39
 
3
  Plugin Name: Download Monitor
4
  Plugin URI: https://www.download-monitor.com
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.9.4
7
  Author: Never5
8
  Author URI: https://www.never5.com
9
  Requires at least: 3.8
10
+ Tested up to: 4.5.1
11
  Text Domain: download-monitor
12
 
13
  License: GPL v3
33
  } // Exit if accessed directly
34
 
35
  // Define DLM Version
36
+ define( 'DLM_VERSION', '1.9.4' );
37
 
38
  function __download_monitor_main() {
39
 
includes/class-dlm-cookie-manager.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class DLM_Cookie_Manager {
4
+
5
+ const KEY = 'wp_dlm_downloading';
6
+
7
+ /**
8
+ * Check if the cookie is exists for this download & version. If it does exists the requester has requested the exact same download & version in the past minute.
9
+ *
10
+ * @param DLM_Download $download
11
+ *
12
+ * @return bool
13
+ */
14
+ public static function exists( $download ) {
15
+ $exists = false;
16
+
17
+ // get JSON data
18
+ $cdata = self::get_cookie_data();
19
+
20
+ // check if no parse errors occurred
21
+ if ( null != $cdata && is_array( $cdata ) && ! empty( $cdata ) ) {
22
+
23
+ // check in cookie data for download AND version ID
24
+ if ( $cdata['download'] == $download->id && $cdata['version'] == $download->get_the_version_number() ) {
25
+ $exists = true;
26
+ }
27
+ }
28
+
29
+
30
+ return $exists;
31
+ }
32
+
33
+ /**
34
+ * Get cookie data
35
+ *
36
+ * @return array|null
37
+ */
38
+ public static function get_cookie_data() {
39
+ $cdata = null;
40
+ if ( ! empty( $_COOKIE[ self::KEY ] ) ) {
41
+ $cdata = json_decode( base64_decode( $_COOKIE[ self::KEY ] ), true );
42
+ }
43
+
44
+ return $cdata;
45
+ }
46
+
47
+ /**
48
+ * Set cookie
49
+ *
50
+ * @param DLM_Download $download
51
+ */
52
+ public static function set_cookie( $download ) {
53
+ setcookie( self::KEY, base64_encode( json_encode( array(
54
+ 'download' => $download->id,
55
+ 'version' => $download->get_the_version_number()
56
+ ) ) ), time() + 60, COOKIEPATH, COOKIE_DOMAIN, false, true );
57
+ }
58
+
59
+ }
includes/class-dlm-download-handler.php CHANGED
@@ -302,13 +302,13 @@ class DLM_Download_Handler {
302
  $logging = new DLM_Logging();
303
 
304
  // Check if logging is enabled and if unique ips is enabled
305
- if ( $logging->is_logging_enabled() ) {
306
 
307
  // set create_log to true
308
  $create_log = true;
309
 
310
  // check if requester downloaded this version before
311
- if ( '1' == get_option( 'dlm_count_unique_ips', '0' ) && true === $this->has_ip_downloaded_version( $version ) ) {
312
  $create_log = false;
313
  }
314
 
@@ -390,14 +390,16 @@ class DLM_Download_Handler {
390
  }
391
 
392
  // check if user downloaded this version in the past minute
393
- if ( empty( $_COOKIE['wp_dlm_downloading'] ) || $download->get_the_version_number() != $_COOKIE['wp_dlm_downloading'] ) {
394
 
 
 
395
 
396
  // bool if we need to increment download count
397
  $increment_download_count = true;
398
 
399
  // check if unique ips option is enabled and if so, if visitor already downloaded this file version
400
- if ( '1' == get_option( 'dlm_enable_logging' ) && '1' == get_option( 'dlm_count_unique_ips' ) && true === $this->has_ip_downloaded_version( $version ) ) {
401
  $increment_download_count = false;
402
  }
403
 
@@ -411,7 +413,7 @@ class DLM_Download_Handler {
411
  do_action( 'dlm_downloading', $download, $version, $file_path );
412
 
413
  // Set cookie to prevent double logging
414
- setcookie( 'wp_dlm_downloading', $download->get_the_version_number(), time() + 60, COOKIEPATH, COOKIE_DOMAIN, false, true );
415
  }
416
 
417
  // Redirect to the file...
@@ -626,16 +628,4 @@ class DLM_Download_Handler {
626
  return $status;
627
  }
628
 
629
- /**
630
- * Check if visitor has downloaded version in the past 24 hours
631
- *
632
- * @param DLM_Download_Version $version
633
- *
634
- * @return bool
635
- */
636
- private function has_ip_downloaded_version( $version ) {
637
- global $wpdb;
638
-
639
- return ( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->download_log} WHERE type = 'download' AND `version_id` = %d AND `user_ip` = %s", $version->id, DLM_Utils::get_visitor_ip() ) ) ) > 0 );
640
- }
641
  }
302
  $logging = new DLM_Logging();
303
 
304
  // Check if logging is enabled and if unique ips is enabled
305
+ if ( $logging->is_logging_enabled() && false === DLM_Cookie_Manager::exists( $download ) ) {
306
 
307
  // set create_log to true
308
  $create_log = true;
309
 
310
  // check if requester downloaded this version before
311
+ if ( $logging->is_count_unique_ips_only() && true === $logging->has_ip_downloaded_version( $version ) ) {
312
  $create_log = false;
313
  }
314
 
390
  }
391
 
392
  // check if user downloaded this version in the past minute
393
+ if ( false == DLM_Cookie_Manager::exists( $download ) ) {
394
 
395
+ // DLM Logging object
396
+ $logger = new DLM_Logging();
397
 
398
  // bool if we need to increment download count
399
  $increment_download_count = true;
400
 
401
  // check if unique ips option is enabled and if so, if visitor already downloaded this file version
402
+ if ( $logger->is_logging_enabled() && $logger->is_count_unique_ips_only() && true === $logger->has_ip_downloaded_version( $version ) ) {
403
  $increment_download_count = false;
404
  }
405
 
413
  do_action( 'dlm_downloading', $download, $version, $file_path );
414
 
415
  // Set cookie to prevent double logging
416
+ DLM_Cookie_Manager::set_cookie( $download );
417
  }
418
 
419
  // Redirect to the file...
628
  return $status;
629
  }
630
 
 
 
 
 
 
 
 
 
 
 
 
 
631
  }
includes/class-dlm-logging.php CHANGED
@@ -18,6 +18,28 @@ class DLM_Logging {
18
  return ( 1 == get_option( 'dlm_enable_logging', 0 ) );
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  /**
22
  * create_log function.
23
  *
18
  return ( 1 == get_option( 'dlm_enable_logging', 0 ) );
19
  }
20
 
21
+ /**
22
+ * Check if 'dlm_count_unique_ips' is enabled
23
+ *
24
+ * @return bool
25
+ */
26
+ public function is_count_unique_ips_only() {
27
+ return ( '1' == get_option( 'dlm_count_unique_ips', 0 ) );
28
+ }
29
+
30
+ /**
31
+ * Check if visitor has downloaded version in the past 24 hours
32
+ *
33
+ * @param DLM_Download_Version $version
34
+ *
35
+ * @return bool
36
+ */
37
+ public function has_ip_downloaded_version( $version ) {
38
+ global $wpdb;
39
+
40
+ return ( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->download_log} WHERE type = 'download' AND `version_id` = %d AND `user_ip` = %s", $version->id, DLM_Utils::get_visitor_ip() ) ) ) > 0 );
41
+ }
42
+
43
  /**
44
  * create_log function.
45
  *
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Download Monitor ===
2
- Contributors: never5, barrykooij, mikejolley
3
  Donate link: http://www.barrykooij.com/donate/
4
  Tags: download, downloads, monitor, hits, download monitor, tracking, admin, count, counter, files, versions, download count, logging, AJAX, digital, documents, download category, download manager, download template, downloadmanager, file manager, file tree, grid, hits, ip-address, manager, media, monitor, password, protect downloads, tracker
5
  Requires at least: 3.8
6
- Tested up to: 4.5
7
- Stable tag: 1.9.3
8
  License: GPLv3
9
 
10
  Download Monitor is a plugin for uploading and managing downloads, tracking downloads, and displaying links.
@@ -118,6 +118,10 @@ More documentation can be found in our [Knowledge Base](https://www.download-mon
118
 
119
  == Changelog ==
120
 
 
 
 
 
121
  = 1.9.3: April 11, 2016 =
122
  * Tweak: Small rework of [downloads] loop. Downloads now filterable per download via dlm_shortcode_downloads_loop_download.
123
  * Tweak: We now report missing versions for removed downloads in logs, props [Matt Mower](https://github.com/mdmower).
1
  === Download Monitor ===
2
+ Contributors: never5, barrykooij, mikejolley, hchouhan
3
  Donate link: http://www.barrykooij.com/donate/
4
  Tags: download, downloads, monitor, hits, download monitor, tracking, admin, count, counter, files, versions, download count, logging, AJAX, digital, documents, download category, download manager, download template, downloadmanager, file manager, file tree, grid, hits, ip-address, manager, media, monitor, password, protect downloads, tracker
5
  Requires at least: 3.8
6
+ Tested up to: 4.6
7
+ Stable tag: 1.9.4
8
  License: GPLv3
9
 
10
  Download Monitor is a plugin for uploading and managing downloads, tracking downloads, and displaying links.
118
 
119
  == Changelog ==
120
 
121
+ = 1.9.4: May 2, 2016 =
122
+ * Tweak: Various cookie tweaks to prevent incorrect double logging entries.
123
+ * Tweak: Added a Cookie Manager class to centralize cookie related tasks.
124
+
125
  = 1.9.3: April 11, 2016 =
126
  * Tweak: Small rework of [downloads] loop. Downloads now filterable per download via dlm_shortcode_downloads_loop_download.
127
  * Tweak: We now report missing versions for removed downloads in logs, props [Matt Mower](https://github.com/mdmower).