Download Monitor - Version 4.0.1

Version Description

Download this release

Release Info

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

Code changes from version 4.0.0 to 4.0.1

download-monitor.php CHANGED
@@ -3,7 +3,7 @@
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: 4.0.0
7
  Author: Never5
8
  Author URI: https://www.never5.com
9
  Requires at least: 3.8
@@ -33,7 +33,7 @@ if ( ! defined( 'ABSPATH' ) ) {
33
  } // Exit if accessed directly
34
 
35
  // Define DLM Version
36
- define( 'DLM_VERSION', '4.0.0' );
37
 
38
  // Define DLM FILE
39
  define( 'DLM_PLUGIN_FILE', __FILE__ );
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: 4.0.1
7
  Author: Never5
8
  Author URI: https://www.never5.com
9
  Requires at least: 3.8
33
  } // Exit if accessed directly
34
 
35
  // Define DLM Version
36
+ define( 'DLM_VERSION', '4.0.1' );
37
 
38
  // Define DLM FILE
39
  define( 'DLM_PLUGIN_FILE', __FILE__ );
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.9.2
7
- Stable tag: 4.0.0
8
  License: GPLv3
9
  Text Domain: -
10
 
@@ -115,6 +115,17 @@ More documentation can be found in our [Knowledge Base](https://www.download-mon
115
 
116
  == Changelog ==
117
 
 
 
 
 
 
 
 
 
 
 
 
118
  = 4.0.0: January 22, 2018 =
119
  * Feature: Added reports page for download statistics.
120
  * Feature: Added hash values to version blocks.
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.9.2
7
+ Stable tag: 4.0.1
8
  License: GPLv3
9
  Text Domain: -
10
 
115
 
116
  == Changelog ==
117
 
118
+ = 4.0.1: January 25, 2018 =
119
+ * Tweak: Fixed an issue that caused widget limit to not work.
120
+ * Tweak: Fixed an count() warning in PHP7.2 on extension page.
121
+ * Tweak: Fixed a passed by reference notice in lower PHP versions in get_visitor_ip() call.
122
+ * Tweak: Added 'dlm_download_count' filter to fitler get_download_count() return value.
123
+ * Tweak: Downloads now return an empty version if no version is added. This prevents mulitple possible fatal errors when external scripts don't check if get_version() returns null.
124
+ * Tweak: Added an extra check to if website needs upgrading. If there are new downloads in the database, no upgrade is recommended.
125
+ * Tweak: Added an extra warning on the upgrade page to users that navigate to the page while we think no upgrade is needed.
126
+ * Tweak: Requesting a non existing download no longer triggers a fatal error (exception is now properly handled).
127
+ * Tweak: Correct exception handling when trying to save meta boxes of non existing download.
128
+
129
  = 4.0.0: January 22, 2018 =
130
  * Feature: Added reports page for download statistics.
131
  * Feature: Added hash values to version blocks.
src/Admin/Extensions.php CHANGED
@@ -55,7 +55,7 @@ class DLM_Admin_Extensions {
55
  echo '<div id="message" class="updated">' . $response->message . '</div>' . PHP_EOL;
56
  }
57
 
58
- if ( count( $response ) > 0 && isset( $response->extensions ) && count( $response->extensions ) > 0 ) {
59
 
60
  // Extensions
61
  $extensions = $response->extensions;
55
  echo '<div id="message" class="updated">' . $response->message . '</div>' . PHP_EOL;
56
  }
57
 
58
+ if ( isset( $response ) > 0 && isset( $response->extensions ) && count( $response->extensions ) > 0 ) {
59
 
60
  // Extensions
61
  $extensions = $response->extensions;
src/Admin/WritePanels.php CHANGED
@@ -294,7 +294,13 @@ class DLM_Admin_Writepanels {
294
  *
295
  */
296
  /** @var DLM_Download $download */
297
- $download = download_monitor()->service( 'download_repository' )->retrieve_single( $post_id );
 
 
 
 
 
 
298
 
299
  // set the 'Download Options'
300
  $download->set_featured( ( isset( $_POST['_featured'] ) ) );
294
  *
295
  */
296
  /** @var DLM_Download $download */
297
+ try {
298
+ $download = download_monitor()->service( 'download_repository' )->retrieve_single( $post_id );
299
+ }catch (Exception $e) {
300
+ // download not found, no point in continueing
301
+ return;
302
+ }
303
+
304
 
305
  // set the 'Download Options'
306
  $download->set_featured( ( isset( $_POST['_featured'] ) ) );
src/Download/Download.php CHANGED
@@ -266,11 +266,16 @@ class DLM_Download {
266
  * @return int
267
  */
268
  public function get_download_count() {
 
 
 
 
 
269
  if ( null != $this->get_version() && ! $this->get_version()->is_latest() ) {
270
- return $this->get_version()->get_download_count();
271
- } else {
272
- return $this->download_count;
273
  }
 
 
274
  }
275
 
276
  /**
@@ -383,6 +388,12 @@ class DLM_Download {
383
  $latest = array_shift( $versions );
384
  $latest->set_latest( true );
385
  $this->version = $latest;
 
 
 
 
 
 
386
  }
387
  }
388
 
266
  * @return int
267
  */
268
  public function get_download_count() {
269
+
270
+ // set default download count
271
+ $download_count = $this->download_count;
272
+
273
+ // set download count of latest version if set
274
  if ( null != $this->get_version() && ! $this->get_version()->is_latest() ) {
275
+ $download_count = $this->get_version()->get_download_count();
 
 
276
  }
277
+
278
+ return apply_filters( 'dlm_download_count', $download_count, $this );
279
  }
280
 
281
  /**
388
  $latest = array_shift( $versions );
389
  $latest->set_latest( true );
390
  $this->version = $latest;
391
+ } else {
392
+ // return an empty version if there is no version
393
+ $this->version = new DLM_Download_Version();
394
+
395
+ // set empty version as latest so download object doesn't think we're dealing with a 'special' version
396
+ $this->version->set_latest( true );
397
  }
398
  }
399
 
src/DownloadHandler.php CHANGED
@@ -280,7 +280,12 @@ class DLM_Download_Handler {
280
  $download = null;
281
 
282
  if ( $download_id > 0 ) {
283
- $download = download_monitor()->service( 'download_repository' )->retrieve_single( $download_id );
 
 
 
 
 
284
  }
285
 
286
  // Handle version (if set)
@@ -294,7 +299,7 @@ class DLM_Download_Handler {
294
  $version_id = absint( $_GET['v'] );
295
  }
296
 
297
- if ( $version_id ) {
298
  try {
299
  $version = download_monitor()->service( 'version_repository' )->retrieve_single( $version_id );
300
  $download->set_version( $version );
280
  $download = null;
281
 
282
  if ( $download_id > 0 ) {
283
+ try {
284
+ $download = download_monitor()->service( 'download_repository' )->retrieve_single( $download_id );
285
+ }catch (Exception $e) {
286
+ // download not found
287
+ }
288
+
289
  }
290
 
291
  // Handle version (if set)
299
  $version_id = absint( $_GET['v'] );
300
  }
301
 
302
+ if ( null != $download && $version_id ) {
303
  try {
304
  $version = download_monitor()->service( 'version_repository' )->retrieve_single( $version_id );
305
  $download->set_version( $version );
src/LegacyUpgrader/Checker.php CHANGED
@@ -19,17 +19,29 @@ class DLM_LU_Checker {
19
  private function has_legacy_tables() {
20
  global $wpdb;
21
 
22
- $du = new DLM_LU_Download_Upgrader();
23
- $legacy_tables = $du->get_legacy_tables();
24
- $sql = "SELECT 1 FROM `" . $legacy_tables['files'] . "` LIMIT 1;";
25
- $o_suppress_errors = $wpdb->suppress_errors;
26
  $wpdb->suppress_errors = true;
27
- $r = $wpdb->query( $sql );
28
  $wpdb->suppress_errors = $o_suppress_errors;
29
 
30
  return ( $r !== false );
31
  }
32
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  /**
34
  * Mark website as upgraded
35
  *
@@ -51,9 +63,21 @@ class DLM_LU_Checker {
51
  return false;
52
  }
53
 
 
54
  if ( ! $this->has_been_upgraded() ) {
 
 
55
  if ( $this->has_legacy_tables() ) {
56
- return true;
 
 
 
 
 
 
 
 
 
57
  }
58
  }
59
 
19
  private function has_legacy_tables() {
20
  global $wpdb;
21
 
22
+ $du = new DLM_LU_Download_Upgrader();
23
+ $legacy_tables = $du->get_legacy_tables();
24
+ $sql = "SELECT 1 FROM `" . $legacy_tables['files'] . "` LIMIT 1;";
25
+ $o_suppress_errors = $wpdb->suppress_errors;
26
  $wpdb->suppress_errors = true;
27
+ $r = $wpdb->query( $sql );
28
  $wpdb->suppress_errors = $o_suppress_errors;
29
 
30
  return ( $r !== false );
31
  }
32
 
33
+ /**
34
+ * Returns true if there is at least one 'new' downloads.
35
+ * A new download is a custom post type with type 'dlm_download'
36
+ * @return bool
37
+ */
38
+ private function has_modern_downloads() {
39
+ $repo = new DLM_WordPress_Download_Repository();
40
+ $amount = $repo->num_rows();
41
+
42
+ return ( $amount > 0 );
43
+ }
44
+
45
  /**
46
  * Mark website as upgraded
47
  *
63
  return false;
64
  }
65
 
66
+ // check if we already upgraded
67
  if ( ! $this->has_been_upgraded() ) {
68
+
69
+ // check if we have legacy tables
70
  if ( $this->has_legacy_tables() ) {
71
+
72
+ /**
73
+ * Check if there are already 'new' download
74
+ * We're doing this because there are users that manually upgraded in the past
75
+ * So they will have the legacy tables but don't need converting
76
+ */
77
+ if ( ! $this->has_modern_downloads() ) {
78
+ return true;
79
+ }
80
+
81
  }
82
  }
83
 
src/LegacyUpgrader/Page.php CHANGED
@@ -24,12 +24,35 @@ class DLM_LU_Page {
24
  * Display page
25
  */
26
  public function view() {
 
 
 
 
 
 
 
 
 
 
 
 
27
  ?>
28
  <div class="wrap">
29
  <h1><?php _e( 'Download Monitor - Legacy Upgrade', 'download-monitor' ); ?></h1><br/>
30
  <p><?php printf( __( "Welcome to the Download Monitor Legacy Upgrader. On this page we will upgrade your old Download Monitor (legacy) data so it will work with the latest version. If you're on this page, it should mean that you updated to this version from Download Monitor %s. If you're unsure if this is correct, or you want to read more about the legacy upgrade, we've setup a page that will explain this process in a lot more detail. %sClick here%s if to view that page.", 'download-monitor' ), "<strong>3.x</strong>", "<a href='https://www.download-monitor.com/kb/legacy-upgrade?utm_source=plugin&utm_medium=dlm-lu-upgrade-page&utm_campaign=dlm-lu-more-information' target='_blank'>", "</a>" ); ?></p>
31
-
32
- <div id="dlm-legacy-upgrade-container"></div>
 
 
 
 
 
 
 
 
 
 
 
33
  </div>
34
  <?php
35
  }
24
  * Display page
25
  */
26
  public function view() {
27
+
28
+ $show_upgrader = true;
29
+ $checker = new DLM_LU_Checker();
30
+ if ( ! $checker->needs_upgrading() ) {
31
+ $show_upgrader = false;
32
+ }
33
+
34
+ if ( isset( $_GET['dlm_lu_force'] ) ) {
35
+ $show_upgrader = true;
36
+ }
37
+
38
+
39
  ?>
40
  <div class="wrap">
41
  <h1><?php _e( 'Download Monitor - Legacy Upgrade', 'download-monitor' ); ?></h1><br/>
42
  <p><?php printf( __( "Welcome to the Download Monitor Legacy Upgrader. On this page we will upgrade your old Download Monitor (legacy) data so it will work with the latest version. If you're on this page, it should mean that you updated to this version from Download Monitor %s. If you're unsure if this is correct, or you want to read more about the legacy upgrade, we've setup a page that will explain this process in a lot more detail. %sClick here%s if to view that page.", 'download-monitor' ), "<strong>3.x</strong>", "<a href='https://www.download-monitor.com/kb/legacy-upgrade?utm_source=plugin&utm_medium=dlm-lu-upgrade-page&utm_campaign=dlm-lu-more-information' target='_blank'>", "</a>" ); ?></p>
43
+ <?php
44
+ if ( ! $show_upgrader ) {
45
+ ?>
46
+ <p style='font-weight:bold;color:#a00;font-size:1.4em;'><?php _e( "WARNING: We don't think your database needs upgrading. Only continue if you're 100% sure what you're doing!", 'download-monitor' ); ?></p>
47
+ <a class="button button-primary button-large"
48
+ href="<?php echo add_query_arg( array( 'page' => 'dlm_legacy_upgrade', 'dlm_lu_force' => 'true' ), admin_url( 'options.php' ) ); ?>"><?php _e( "I'm sure I want to run the upgrader anyway", 'download-monitor' ); ?></a>
49
+ <?php
50
+ } else {
51
+ ?>
52
+ <div id="dlm-legacy-upgrade-container"></div>
53
+ <?php
54
+ }
55
+ ?>
56
  </div>
57
  <?php
58
  }
src/Utils.php CHANGED
@@ -8,7 +8,15 @@ abstract class DLM_Utils {
8
  * @return string
9
  */
10
  public static function get_visitor_ip() {
11
- return sanitize_text_field( ( ( '1' == get_option( 'dlm_allow_x_forwarded_for', 0 ) ) && ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ? trim( array_shift( explode( ",", $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) : $_SERVER['REMOTE_ADDR'] );
 
 
 
 
 
 
 
 
12
  }
13
 
14
  /**
8
  * @return string
9
  */
10
  public static function get_visitor_ip() {
11
+
12
+ $ip = $_SERVER['REMOTE_ADDR'];
13
+
14
+ if ( ( '1' == get_option( 'dlm_allow_x_forwarded_for', 0 ) ) && ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
15
+ $parts = explode( ",", $_SERVER['HTTP_X_FORWARDED_FOR'] );
16
+ $ip = trim( array_shift( $parts ) );
17
+ }
18
+
19
+ return sanitize_text_field( $ip );
20
  }
21
 
22
  /**
src/Widgets/Downloads.php CHANGED
@@ -64,7 +64,6 @@ class DLM_Widget_Downloads extends WP_Widget {
64
  'post_status' => 'publish',
65
  'post_type' => 'dlm_download',
66
  'no_found_rows' => 1,
67
- 'posts_per_page' => $posts_per_page,
68
  'orderby' => $orderby,
69
  'order' => $order,
70
  'meta_query' => array(),
@@ -91,7 +90,7 @@ class DLM_Widget_Downloads extends WP_Widget {
91
  }
92
 
93
  // fetch downloads
94
- $downloads = download_monitor()->service( 'download_repository' )->retrieve( $args );
95
 
96
  if ( count( $downloads ) > 0 ) {
97
 
64
  'post_status' => 'publish',
65
  'post_type' => 'dlm_download',
66
  'no_found_rows' => 1,
 
67
  'orderby' => $orderby,
68
  'order' => $order,
69
  'meta_query' => array(),
90
  }
91
 
92
  // fetch downloads
93
+ $downloads = download_monitor()->service( 'download_repository' )->retrieve( $args, $posts_per_page );
94
 
95
  if ( count( $downloads ) > 0 ) {
96