Simple Download Monitor - Version 2.5

Version Description

  • Added a new feature to password protect a downloadable file.
  • Added a new shortcode to show the download count to your visitors.
Download this release

Release Info

Developer mra13
Plugin Icon 128x128 Simple Download Monitor
Version 2.5
Comparing to
See all releases

Code changes from version 2.2 to 2.5

Files changed (3) hide show
  1. js/sdm_wp_scripts.js +38 -0
  2. main.php +130 -12
  3. readme.txt +28 -12
js/sdm_wp_scripts.js ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Simple Download Monitor frontend scripts
2
+
3
+ jQuery(document).ready(function($) {
4
+
5
+
6
+ $('.pass_sumbit').click(function() {
7
+
8
+ this_button_id = $(this).next().val(); // Get download cpt id from hidden input field
9
+ password_attempt = $(this).prev().val(); // Get password text
10
+
11
+ $.post(
12
+ sdm_ajax_script.ajaxurl,
13
+ {
14
+ action: 'sdm_check_pass',
15
+ pass_val: password_attempt,
16
+ button_id: this_button_id
17
+ },
18
+ function(response) {
19
+
20
+ if(response) { // ** If response was successful
21
+
22
+ if(response.success === 'no') { // If the password match failed
23
+
24
+ alert('Incorrect Password');
25
+ $('.pass_text').val(''); // Clear password field
26
+ }
27
+
28
+ if(response.url != '') { // If the password match was a success
29
+
30
+ window.location.href = response.url; // Redirect to download url
31
+ $('.pass_text').val(''); // Clear password field
32
+ }
33
+ }
34
+ }
35
+ );
36
+ });
37
+
38
+ });
main.php CHANGED
@@ -3,8 +3,8 @@
3
  * Plugin Name: Simple Download Monitor
4
  * Plugin URI: http://www.tipsandtricks-hq.com/development-center
5
  * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
- * Version: 2.2
7
- * Author: Tips and Tricks HQ, Ruhul Amin, Josh
8
  * Author URI: http://www.tipsandtricks-hq.com/development-center
9
  * License: GPL2
10
  */
@@ -14,7 +14,7 @@ define('WP_SIMPLE_DL_MONITOR_URL', plugins_url('',__FILE__));
14
  define('WP_SIMPLE_DL_MONITOR_PATH',plugin_dir_path( __FILE__ ));
15
 
16
  global $sdm_db_version;
17
- $sdm_db_version = '2.2';
18
 
19
  register_activation_hook(__FILE__, 'sdm_install_db_table' );
20
  function sdm_install_db_table() {
@@ -321,6 +321,11 @@ class simpleDownloadManager {
321
  <!-- End of settings page form -->
322
  </form>
323
 
 
 
 
 
 
324
  <?php
325
  echo '</div></div>';//end of post-stuff
326
  echo '</div>';//end of wrap
@@ -346,7 +351,7 @@ class simpleDownloadManager {
346
  'sdm_downloads', 'normal', 'default'
347
  );
348
  add_meta_box('sdm_shortcode_meta_box',
349
- __('Shortcode', 'sdm_lang'),
350
  array( &$this, 'display_sdm_shortcode_meta_box'),
351
  'sdm_downloads', 'normal', 'default'
352
  );
@@ -409,8 +414,12 @@ class simpleDownloadManager {
409
  public function display_sdm_shortcode_meta_box( $post ) { // Shortcode metabox
410
 
411
  _e('This is the shortcode which can used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter to add this shortcode to a post or page.','sdm_lang');
412
- echo '<br /><br />';
413
  echo '[sdm-download id="'.$post->ID.'" fancy="0"]';
 
 
 
 
414
  }
415
 
416
  public function display_sdm_stats_meta_box( $post ) { // Stats metabox
@@ -748,21 +757,26 @@ function sdm_create_logs_page(){
748
  }
749
 
750
  /*
751
- ** Register Shortcode
752
  */
753
- add_action( 'init', 'sdm_register_shortcode' );
754
- function sdm_register_shortcode() {
755
 
756
- add_shortcode('sdm-download', 'sdm_create_shortcode' );
 
757
  }
758
- // Create Shortcode
759
- function sdm_create_shortcode( $atts ) {
760
 
761
  extract( shortcode_atts( array(
762
  'id' => 'id',
763
  'fancy' => '0'
764
  ), $atts ) );
765
 
 
 
 
 
766
  // Get CPT thumbnail
767
  $item_download_thumbnail = get_post_meta( $id, 'sdm_upload_thumbnail', true );
768
  $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_download_thumbnail_image" src="'.$item_download_thumbnail.'" />' : '';
@@ -788,6 +802,10 @@ function sdm_create_shortcode( $atts ) {
788
  $homepage = get_bloginfo('url');
789
  $download_url = $homepage. '/?smd_process_download=1&download_id='.$id;
790
  $download_button_code = '<a href="'.$download_url.'" class="sdm_download '.$def_color.'" title="'.$isset_item_title.'">'.__('Download Now!', 'sdm_lang').'</a>';
 
 
 
 
791
  //End of download now button code generation
792
 
793
  if ($fancy == '0') {
@@ -811,12 +829,47 @@ function sdm_create_shortcode( $atts ) {
811
  }
812
  }
813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
814
  /*
815
  ** Register scripts for front-end posts/pages
816
  */
817
  add_action( 'wp_enqueue_scripts', 'sdm_wp_scripts' );
818
  function sdm_wp_scripts() {
 
819
  wp_enqueue_style( 'sdm-styles', WP_SIMPLE_DL_MONITOR_URL. '/css/sdm_wp_styles.css' );
 
 
 
 
 
820
  }
821
 
822
  function handle_sdm_download_via_direct_post()
@@ -842,7 +895,7 @@ function handle_sdm_download_via_direct_post()
842
  $insert_table = $wpdb->insert( $table, $data );
843
 
844
  if ($insert_table) {//Download request was logged successfully
845
- wp_safe_redirect($download_link);
846
  }
847
  else {//Failed to log the download request
848
  wp_die ("Error! Failed to log the download request in the database table");
@@ -851,6 +904,23 @@ function handle_sdm_download_via_direct_post()
851
  }
852
  }
853
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
854
  // Tinymce Button Populate Post ID's
855
  add_action( 'wp_ajax_nopriv_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
856
  add_action( 'wp_ajax_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
@@ -887,7 +957,55 @@ function sdm_remove_thumbnail_image_ajax_call() {
887
  echo $response;
888
  exit;
889
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
890
 
 
 
 
 
 
 
 
 
 
891
 
892
  /*
893
  ** Setup Sortable Columns
3
  * Plugin Name: Simple Download Monitor
4
  * Plugin URI: http://www.tipsandtricks-hq.com/development-center
5
  * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
+ * Version: 2.5
7
+ * Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
8
  * Author URI: http://www.tipsandtricks-hq.com/development-center
9
  * License: GPL2
10
  */
14
  define('WP_SIMPLE_DL_MONITOR_PATH',plugin_dir_path( __FILE__ ));
15
 
16
  global $sdm_db_version;
17
+ $sdm_db_version = '2.5';
18
 
19
  register_activation_hook(__FILE__, 'sdm_install_db_table' );
20
  function sdm_install_db_table() {
321
  <!-- End of settings page form -->
322
  </form>
323
 
324
+ <div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
325
+ <p>If you need a feature rich and supported plugin for selling your digital items then checkout our <a href="http://www.tipsandtricks-hq.com/wordpress-estore-plugin-complete-solution-to-sell-digital-products-from-your-wordpress-blog-securely-1059" target="_blank">WP eStore Plugin</a>
326
+ </p>
327
+ </div>
328
+
329
  <?php
330
  echo '</div></div>';//end of post-stuff
331
  echo '</div>';//end of wrap
351
  'sdm_downloads', 'normal', 'default'
352
  );
353
  add_meta_box('sdm_shortcode_meta_box',
354
+ __('Shortcodes', 'sdm_lang'),
355
  array( &$this, 'display_sdm_shortcode_meta_box'),
356
  'sdm_downloads', 'normal', 'default'
357
  );
414
  public function display_sdm_shortcode_meta_box( $post ) { // Shortcode metabox
415
 
416
  _e('This is the shortcode which can used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter to add this shortcode to a post or page.','sdm_lang');
417
+ echo '<br />';
418
  echo '[sdm-download id="'.$post->ID.'" fancy="0"]';
419
+ echo '<br /><br />';
420
+ _e('This shortcode may be used as a download counter.', 'sdm_lang');
421
+ echo '<br />';
422
+ echo '[sdm-download-counter id="'.$post->ID.'"]';
423
  }
424
 
425
  public function display_sdm_stats_meta_box( $post ) { // Stats metabox
757
  }
758
 
759
  /*
760
+ ** Register Download Shortcode
761
  */
762
+ add_action( 'init', 'sdm_register_shortcodes' );
763
+ function sdm_register_shortcodes() {
764
 
765
+ add_shortcode('sdm-download', 'sdm_create_download_shortcode' ); // For download shortcode
766
+ add_shortcode('sdm-download-counter', 'sdm_create_counter_shortcode' ); // For counter shortcode
767
  }
768
+ // Create Download Shortcode
769
+ function sdm_create_download_shortcode( $atts ) {
770
 
771
  extract( shortcode_atts( array(
772
  'id' => 'id',
773
  'fancy' => '0'
774
  ), $atts ) );
775
 
776
+ // Check to see if the download link cpt is password protected
777
+ $get_cpt_object = get_post($id);
778
+ $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
779
+
780
  // Get CPT thumbnail
781
  $item_download_thumbnail = get_post_meta( $id, 'sdm_upload_thumbnail', true );
782
  $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_download_thumbnail_image" src="'.$item_download_thumbnail.'" />' : '';
802
  $homepage = get_bloginfo('url');
803
  $download_url = $homepage. '/?smd_process_download=1&download_id='.$id;
804
  $download_button_code = '<a href="'.$download_url.'" class="sdm_download '.$def_color.'" title="'.$isset_item_title.'">'.__('Download Now!', 'sdm_lang').'</a>';
805
+
806
+ if($cpt_is_password !== 'no'){//This is a password protected download so replace the download now button with password requirement
807
+ $download_button_code = sdm_get_password_entry_form($id);
808
+ }
809
  //End of download now button code generation
810
 
811
  if ($fancy == '0') {
829
  }
830
  }
831
 
832
+ function sdm_get_password_entry_form($id)
833
+ {
834
+ $data = __('Enter Password to Download:','sdm_lang');
835
+ $data .= '<form method="post">';
836
+ $data .= '<input type="text" class="pass_text" /> ';
837
+ $data .= '<input type="button" class="pass_sumbit" value="'.__('Submit','sdm_lang').'" />';
838
+ $data .= '<input type="hidden" value="'.$id.'" />';
839
+ $data .= '</form>';
840
+ return $data;
841
+ }
842
+
843
+ // Create Counter Shortcode
844
+ function sdm_create_counter_shortcode( $atts ) {
845
+
846
+ extract( shortcode_atts( array(
847
+ 'id' => 'id'
848
+ ), $atts ) );
849
+
850
+ // Get number of downloads by counting db columns matching postID
851
+ global $wpdb;
852
+ $table = $wpdb->prefix.'sdm_downloads';
853
+ $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$table.' WHERE post_id=%s', $id));
854
+
855
+ // Return result
856
+ return $wpdb->num_rows.' '.__('Downloads','sdm_lang');
857
+ }
858
+
859
+
860
+
861
  /*
862
  ** Register scripts for front-end posts/pages
863
  */
864
  add_action( 'wp_enqueue_scripts', 'sdm_wp_scripts' );
865
  function sdm_wp_scripts() {
866
+
867
  wp_enqueue_style( 'sdm-styles', WP_SIMPLE_DL_MONITOR_URL. '/css/sdm_wp_styles.css' );
868
+ wp_register_script('sdm-scripts', WP_SIMPLE_DL_MONITOR_URL. '/js/sdm_wp_scripts.js', array( 'jquery' ) );
869
+ wp_enqueue_script('sdm-scripts');
870
+
871
+ // Localize ajax script for frontend
872
+ wp_localize_script( 'sdm-scripts', 'sdm_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
873
  }
874
 
875
  function handle_sdm_download_via_direct_post()
895
  $insert_table = $wpdb->insert( $table, $data );
896
 
897
  if ($insert_table) {//Download request was logged successfully
898
+ sdm_redirect_to_url($download_link);
899
  }
900
  else {//Failed to log the download request
901
  wp_die ("Error! Failed to log the download request in the database table");
904
  }
905
  }
906
 
907
+ function sdm_redirect_to_url($url,$delay='0',$exit='1')
908
+ {
909
+ if(empty($url)){
910
+ echo "<strong>Error! The URL value is empty. Please specify a correct URL value to redirect to!</strong>";
911
+ exit;
912
+ }
913
+ if (!headers_sent()){
914
+ header('Location: ' . $url);
915
+ }
916
+ else{
917
+ echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'" />';
918
+ }
919
+ if($exit == '1'){//exit
920
+ exit;
921
+ }
922
+ }
923
+
924
  // Tinymce Button Populate Post ID's
925
  add_action( 'wp_ajax_nopriv_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
926
  add_action( 'wp_ajax_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
957
  echo $response;
958
  exit;
959
  }
960
+ // Check download password
961
+ add_action( 'wp_ajax_nopriv_sdm_check_pass', 'sdm_check_pass_ajax_call' );
962
+ add_action( 'wp_ajax_sdm_check_pass', 'sdm_check_pass_ajax_call' );
963
+ function sdm_check_pass_ajax_call() {
964
+
965
+ $button_id = $_POST['button_id']; // Get button cpt id
966
+ $pass_val = $_POST['pass_val']; // Get password attempt
967
+ $success = '';
968
+ $download_link = '';
969
+
970
+ // Get post object
971
+ $post_object = get_post($button_id);
972
+ // Get post password
973
+ $post_pass = $post_object->post_password;
974
+
975
+ // Check if password is a match
976
+ if($post_pass != $pass_val) { // Match is a failure
977
+
978
+ $success = 'no'; // Pass back to ajax
979
+ }
980
+ else { // Match is a success
981
+
982
+ $success = 'yes'; // Pass back to ajax
983
+
984
+ $download_id = $button_id;
985
+ $download_title = get_the_title( $download_id );
986
+ $download_link = get_post_meta( $download_id, 'sdm_upload', true );
987
+ $ipaddress = $_SERVER["REMOTE_ADDR"];
988
+ $date_time = current_time( 'mysql' );
989
+
990
+ global $wpdb;
991
+ $table = $wpdb->prefix . 'sdm_downloads';
992
+ $data = array(
993
+ 'post_id' => $download_id,
994
+ 'post_title' => $download_title,
995
+ 'file_url' => $download_link,
996
+ 'visitor_ip' => $ipaddress,
997
+ 'date_time' => $date_time
998
+ );
999
 
1000
+ $insert_table = $wpdb->insert( $table, $data );
1001
+ }
1002
+
1003
+ // Generate ajax response
1004
+ $response = json_encode( array( 'success' => $success, 'url' => $download_link ));
1005
+ header( 'Content-Type: application/json' );
1006
+ echo $response;
1007
+ exit;
1008
+ }
1009
 
1010
  /*
1011
  ** Setup Sortable Columns
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Simple Download Monitor ===
2
- Contributors: Tips and Tricks HQ, Ruhul Amin, Josh
3
  Donate link: http://www.tipsandtricks-hq.com
4
- Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, file manager
5
  Requires at least: 3.0
6
- Tested up to: 3.7.1
7
- Stable tag: 2.2
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
@@ -13,20 +13,22 @@ Easily manage downloadable files and monitor downloads of your digital files fro
13
 
14
  I developed the Simple Download Monitor plugin because I wanted to monitor the number of downloads of my files.
15
 
16
- This plugin is very useful for managing and tracking your digital file download counts.
17
 
18
  You can configure downloadable files from your WordPress admin dashboard via an elegant user interface. Then allow your visitors to download the files and this plugin will monitor which files get downloaded how many times.
19
 
20
- The plugin will also log the IP addresses of the users who download your files.
21
 
22
  It has a very user-friendly interface for uploading, managing, monitoring and tracking file downloads.
23
 
 
 
24
  = Simple Download Monitor Features =
25
 
26
- * Add, edit and remove downloads from an easy to use interface
27
- * Drag and drop file uploads
28
- * Assign categories and tags to your downloadable files
29
- * Use shortcodes to display a download now button on a WordPress post/page
30
  * Show a trackable download now button for your files anywhere on your site.
31
  * Download counter for each file.
32
  * Track IP addresses of the users who downloaded your files.
@@ -35,9 +37,13 @@ It has a very user-friendly interface for uploading, managing, monitoring and tr
35
  * Option to use a nice looking template to show your download now buttons.
36
  * Ability to search and sort your downloadable files in the admin dashboard.
37
  * Track the number of downloads for each of your files.
 
38
  * Tinymce button in the WordPress post/page editor so you can easily add the shortcode.
 
 
 
39
 
40
- View more details on the [plugin page](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin)
41
 
42
  = Simple Download Monitor Plugin Usage =
43
 
@@ -95,10 +101,20 @@ Yes, you can use both local paths and external URLs.
95
 
96
  == Screenshots ==
97
 
98
- For screenshots please visit the plugin page
99
 
100
  == Changelog ==
101
 
 
 
 
 
 
 
 
 
 
 
102
  = 2.2 =
103
  * Fixed the plugin language translation issue. Now it can be translated to any language.
104
 
1
  === Simple Download Monitor ===
2
+ Contributors: Tips and Tricks HQ, Ruhul Amin, josh401
3
  Donate link: http://www.tipsandtricks-hq.com
4
+ Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, file manager, protect downloads,
5
  Requires at least: 3.0
6
+ Tested up to: 3.8.1
7
+ Stable tag: 2.5
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
13
 
14
  I developed the Simple Download Monitor plugin because I wanted to monitor the number of downloads of my files.
15
 
16
+ This plugin is very useful for managing and tracking your digital file download counts. You can password protect your downloadable files too.
17
 
18
  You can configure downloadable files from your WordPress admin dashboard via an elegant user interface. Then allow your visitors to download the files and this plugin will monitor which files get downloaded how many times.
19
 
20
+ The plugin will log the IP addresses of the users who download your digital files.
21
 
22
  It has a very user-friendly interface for uploading, managing, monitoring and tracking file downloads.
23
 
24
+ http://www.youtube.com/watch?v=L-mXbs7kp0s
25
+
26
  = Simple Download Monitor Features =
27
 
28
+ * Add, edit and remove downloads from an easy to use interface.
29
+ * Drag and drop file uploads.
30
+ * Assign categories and tags to your downloadable files.
31
+ * Use shortcodes to display a download now button on a WordPress post/page.
32
  * Show a trackable download now button for your files anywhere on your site.
33
  * Download counter for each file.
34
  * Track IP addresses of the users who downloaded your files.
37
  * Option to use a nice looking template to show your download now buttons.
38
  * Ability to search and sort your downloadable files in the admin dashboard.
39
  * Track the number of downloads for each of your files.
40
+ * WordPress Shortcode for embedding a download link for a file.
41
  * Tinymce button in the WordPress post/page editor so you can easily add the shortcode.
42
+ * Ability to add the download now buttons to your sidebar widget.
43
+ * Create password protected download now buttons. Users will only be able to download the file if they enter the correct password
44
+ * Shortcode to show the download counter of a file. Use it to show off your file download count.
45
 
46
+ View more usage details on the [download monitor plugin](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin) page.
47
 
48
  = Simple Download Monitor Plugin Usage =
49
 
101
 
102
  == Screenshots ==
103
 
104
+ For screenshots please visit the [download monitor plugin page](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin)
105
 
106
  == Changelog ==
107
 
108
+ = 2.5 =
109
+ * Added a new feature to password protect a downloadable file.
110
+ * Added a new shortcode to show the download count to your visitors.
111
+
112
+ = 2.4 =
113
+ * Fixed an issue with file download using external file URL.
114
+
115
+ = 2.3 =
116
+ * Wordpress 3.8 compatibility
117
+
118
  = 2.2 =
119
  * Fixed the plugin language translation issue. Now it can be translated to any language.
120