Simple Download Monitor - Version 3.4.3

Version Description

  • The [sdm_search_form] can take the fancy template as a shortcode argument to display the search result using that template.
Download this release

Release Info

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

Code changes from version 3.4.0 to 3.4.3

css/sdm_wp_styles.css CHANGED
@@ -345,4 +345,17 @@
345
  .sdm_object_tree .sdm_post_title{
346
  margin-right: 5px;
347
  display: block;
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  }
345
  .sdm_object_tree .sdm_post_title{
346
  margin-right: 5px;
347
  display: block;
348
+ }
349
+
350
+ /* Search form and results */
351
+
352
+ .sdm_search_result_item {
353
+ margin-top: 20px;
354
+ margin-bottom: 10px;
355
+ padding-bottom: 5px;
356
+ border-bottom: 1px solid silver
357
+ }
358
+
359
+ .sdm_search_result_item:last-child {
360
+ border-bottom: none;
361
  }
includes/sdm-download-request-handler.php CHANGED
@@ -9,7 +9,7 @@ function handle_sdm_download_via_direct_post() {
9
  $download_link = get_post_meta($download_id, 'sdm_upload', true);
10
 
11
  //Do some validation checks
12
- if ( !$download_id ) {
13
  wp_die(__('Error! Incorrect download item id.', 'simple-download-monitor'));
14
  }
15
  if (empty($download_link)) {
@@ -17,25 +17,25 @@ function handle_sdm_download_via_direct_post() {
17
  }
18
 
19
  //Check download password (if applicable for this download)
20
- $post_object = get_post($download_id);// Get post object
21
- $post_pass = $post_object->post_password;// Get post password
22
- if(!empty($post_pass)){//This download item has a password. So validate the password.
23
  $pass_val = $_REQUEST['pass_text'];
24
- if(empty($pass_val)){//No password was submitted with the downoad request.
25
  $dl_post_url = get_permalink($download_id);
26
  $error_msg = __('Error! This download requires a password.', 'simple-download-monitor');
27
  $error_msg .= '<p>';
28
- $error_msg .= '<a href="'.$dl_post_url.'">'.__('Click here', 'simple-download-monitor').'</a>';
29
  $error_msg .= __(' and enter a valid password for this item', 'simple-download-monitor');
30
  $error_msg .= '</p>';
31
  wp_die($error_msg);
32
  }
33
- if ($post_pass != $pass_val) {
34
  //Incorrect password submitted.
35
  wp_die(__('Error! Incorrect password. This download requires a valid password.', 'simple-download-monitor'));
36
  } else {
37
  //Password is valid. Go ahead with the download
38
- }
39
  }
40
  //End of password check
41
 
@@ -43,15 +43,21 @@ function handle_sdm_download_via_direct_post() {
43
  $date_time = current_time('mysql');
44
  $visitor_country = $ipaddress ? sdm_ip_info($ipaddress, 'country') : '';
45
 
46
- if (is_user_logged_in()) { // Get user name (if logged in)
47
- $current_user = wp_get_current_user();
48
- $visitor_name = $current_user->user_login;
49
- } else {
50
- $visitor_name = __('Not Logged In', 'simple-download-monitor');
 
 
 
 
 
51
  }
52
 
 
 
53
  // Get option for global disabling of download logging
54
- $main_option = get_option('sdm_downloads_options');
55
  $no_logs = isset($main_option['admin_no_logs']);
56
 
57
  // Get optoin for logging only unique IPs
@@ -109,7 +115,7 @@ function handle_sdm_download_via_direct_post() {
109
  $dispatch = apply_filters('sdm_dispatch_downloads', get_post_meta($download_id, 'sdm_item_dispatch', true));
110
 
111
  // Only local file can be dispatched.
112
- if ( $dispatch && (stripos($download_link, WP_CONTENT_URL) === 0) ) {
113
  // Get file path
114
  $file = path_join(WP_CONTENT_DIR, ltrim(substr($download_link, strlen(WP_CONTENT_URL)), '/'));
115
  // Try to dispatch file (terminates script execution on success)
@@ -125,8 +131,9 @@ function handle_sdm_download_via_direct_post() {
125
  /*
126
  * Use this function to redirect to a URL
127
  */
 
128
  function sdm_redirect_to_url($url, $delay = '0', $exit = '1') {
129
- $url = apply_filters('sdm_before_redirect_to_url',$url);
130
  if (empty($url)) {
131
  echo '<strong>';
132
  _e('Error! The URL value is empty. Please specify a correct URL value to redirect to!', 'simple-download-monitor');
@@ -151,19 +158,19 @@ function sdm_redirect_to_url($url, $delay = '0', $exit = '1') {
151
  */
152
  function sdm_dispatch_file($filename) {
153
 
154
- if ( headers_sent() ) {
155
  trigger_error(__FUNCTION__ . ": Cannot dispatch file $filename, headers already sent.");
156
  return;
157
  }
158
 
159
- if ( !is_readable($filename) ) {
160
  trigger_error(__FUNCTION__ . ": Cannot dispatch file $filename, file is not readable.");
161
  return;
162
  }
163
 
164
  header('Content-Description: File Transfer');
165
  header('Content-Type: application/octet-stream'); // http://stackoverflow.com/a/20509354
166
- header('Content-Disposition: attachment; filename="'.basename($filename).'"');
167
  header('Expires: 0');
168
  header('Cache-Control: must-revalidate');
169
  header('Pragma: public');
9
  $download_link = get_post_meta($download_id, 'sdm_upload', true);
10
 
11
  //Do some validation checks
12
+ if (!$download_id) {
13
  wp_die(__('Error! Incorrect download item id.', 'simple-download-monitor'));
14
  }
15
  if (empty($download_link)) {
17
  }
18
 
19
  //Check download password (if applicable for this download)
20
+ $post_object = get_post($download_id); // Get post object
21
+ $post_pass = $post_object->post_password; // Get post password
22
+ if (!empty($post_pass)) {//This download item has a password. So validate the password.
23
  $pass_val = $_REQUEST['pass_text'];
24
+ if (empty($pass_val)) {//No password was submitted with the downoad request.
25
  $dl_post_url = get_permalink($download_id);
26
  $error_msg = __('Error! This download requires a password.', 'simple-download-monitor');
27
  $error_msg .= '<p>';
28
+ $error_msg .= '<a href="' . $dl_post_url . '">' . __('Click here', 'simple-download-monitor') . '</a>';
29
  $error_msg .= __(' and enter a valid password for this item', 'simple-download-monitor');
30
  $error_msg .= '</p>';
31
  wp_die($error_msg);
32
  }
33
+ if ($post_pass != $pass_val) {
34
  //Incorrect password submitted.
35
  wp_die(__('Error! Incorrect password. This download requires a valid password.', 'simple-download-monitor'));
36
  } else {
37
  //Password is valid. Go ahead with the download
38
+ }
39
  }
40
  //End of password check
41
 
43
  $date_time = current_time('mysql');
44
  $visitor_country = $ipaddress ? sdm_ip_info($ipaddress, 'country') : '';
45
 
46
+ $main_option = get_option('sdm_downloads_options');
47
+
48
+ $visitor_name = sdm_get_logged_in_user();
49
+
50
+ // Check if we only allow the download for logged-in users
51
+ if (isset($main_option['only_logged_in_can_download'])) {
52
+ if ($main_option['only_logged_in_can_download'] && $visitor_name === false) {
53
+ // User not logged in, let's display the message
54
+ wp_die(__('You need to be logged in to download this file.', 'simple-download-monitor'));
55
+ }
56
  }
57
 
58
+ $visitor_name = ($visitor_name === false) ? __('Not Logged In', 'simple-download-monitor') : $visitor_name;
59
+
60
  // Get option for global disabling of download logging
 
61
  $no_logs = isset($main_option['admin_no_logs']);
62
 
63
  // Get optoin for logging only unique IPs
115
  $dispatch = apply_filters('sdm_dispatch_downloads', get_post_meta($download_id, 'sdm_item_dispatch', true));
116
 
117
  // Only local file can be dispatched.
118
+ if ($dispatch && (stripos($download_link, WP_CONTENT_URL) === 0)) {
119
  // Get file path
120
  $file = path_join(WP_CONTENT_DIR, ltrim(substr($download_link, strlen(WP_CONTENT_URL)), '/'));
121
  // Try to dispatch file (terminates script execution on success)
131
  /*
132
  * Use this function to redirect to a URL
133
  */
134
+
135
  function sdm_redirect_to_url($url, $delay = '0', $exit = '1') {
136
+ $url = apply_filters('sdm_before_redirect_to_url', $url);
137
  if (empty($url)) {
138
  echo '<strong>';
139
  _e('Error! The URL value is empty. Please specify a correct URL value to redirect to!', 'simple-download-monitor');
158
  */
159
  function sdm_dispatch_file($filename) {
160
 
161
+ if (headers_sent()) {
162
  trigger_error(__FUNCTION__ . ": Cannot dispatch file $filename, headers already sent.");
163
  return;
164
  }
165
 
166
+ if (!is_readable($filename)) {
167
  trigger_error(__FUNCTION__ . ": Cannot dispatch file $filename, file is not readable.");
168
  return;
169
  }
170
 
171
  header('Content-Description: File Transfer');
172
  header('Content-Type: application/octet-stream'); // http://stackoverflow.com/a/20509354
173
+ header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
174
  header('Expires: 0');
175
  header('Cache-Control: must-revalidate');
176
  header('Pragma: public');
includes/sdm-search-shortcode-handler.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function sdm_search_form_shortcode($args) {
4
+ $atts = shortcode_atts(
5
+ array(
6
+ 'fancy' => '',
7
+ 'class' => '', // wrapper class
8
+ 'placeholder' => 'Search...', // placeholder for search input
9
+ 'description_max_length' => 50, // short description symbols count
10
+ ), $args
11
+ );
12
+
13
+ // Check if we have a search value posted
14
+ $s_term = isset($_POST['sdm_search_term']) ? stripslashes(sanitize_text_field(esc_html($_POST['sdm_search_term']))) : '';
15
+
16
+ if (!empty($s_term)) {
17
+ // we got search term posted
18
+ global $wpdb;
19
+ $querystr = "
20
+ SELECT $wpdb->posts.*, $wpdb->postmeta.meta_value as description
21
+ FROM $wpdb->posts, $wpdb->postmeta
22
+ WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
23
+ AND $wpdb->posts.post_status = 'publish'
24
+ AND $wpdb->posts.post_type = 'sdm_downloads'
25
+ AND ($wpdb->posts.post_title LIKE '%$s_term%'
26
+ OR ($wpdb->postmeta.meta_key='sdm_description' AND $wpdb->postmeta.meta_value LIKE '%$s_term%') )
27
+ GROUP BY $wpdb->posts.ID
28
+ ";
29
+ $posts_collection = $wpdb->get_results($querystr, OBJECT);
30
+ $s_results = sdm_generate_search_result_using_template($posts_collection, $atts);
31
+
32
+ if (!empty($s_results)) {
33
+ $s_results = '<h2>Search results for "' . $s_term . '":</h2>' . $s_results;
34
+ } else {
35
+ $s_results = '<h2>Nothing found for "' . $s_term . '".</h2>';
36
+ }
37
+ }
38
+
39
+ $out = '';
40
+ $out .= '<form id="sdm_search_form" class="' . (empty($atts['class']) ? '' : ' ' . $atts['class']) . '" method="POST">';
41
+ $out .= '<input type="search" class="search-field" name="sdm_search_term" value="' . $s_term . '" placeholder="' . $atts['placeholder'] . '">';
42
+ $out .= '<input type="submit" class="sdm_search_submit" name="sdm_search_submit" value="Search">';
43
+ $out .= '</form>';
44
+ $out .= isset($s_results) ? $s_results : '';
45
+
46
+ return $out;
47
+ }
48
+
49
+ function sdm_generate_search_result_using_template($posts_collection, $args = array()) {
50
+ $s_results = '';
51
+
52
+ if (isset($args['fancy']) && !empty($args['fancy'])) {
53
+ if ($args['fancy'] == '1') {
54
+ include_once(WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy1/sdm-fancy-1.php');
55
+ $s_results .= sdm_generate_fancy1_category_display_output($posts_collection, $args);
56
+ } else if ($args['fancy'] == '2') {
57
+ include_once(WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy2/sdm-fancy-2.php');
58
+ $s_results .= sdm_generate_fancy2_category_display_output($posts_collection, $args);
59
+ }
60
+ } else {
61
+ //No fancy template is used. Show the search result using the standard search display
62
+ foreach ($posts_collection as $post) {
63
+ $meta = get_post_meta($post->ID);
64
+ $s_results .= '<div class="sdm_search_result_item">';
65
+ $s_results .= '<h4><a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a></h4>';
66
+ $descr = strip_shortcodes($meta['sdm_description'][0]);
67
+ if (strlen($descr) > $args['description_max_length']) {
68
+ $descr = substr($descr, 0, $args['description_max_length']) . '[...]';
69
+ }
70
+ $s_results .= '<span>' . $descr . '</span>';
71
+ $s_results .= '</div>';
72
+ }
73
+ }
74
+
75
+ return $s_results;
76
+ }
includes/sdm-utility-functions.php CHANGED
@@ -55,12 +55,21 @@ function sdm_get_item_description_output($id){
55
  return $isset_item_description;
56
  }
57
 
58
- function sdm_get_password_entry_form($id) {
59
- $action_url = WP_SIMPLE_DL_MONITOR_SITE_HOME_URL . '/?smd_process_download=1&download_id=' . $id;
 
 
 
 
 
 
 
 
 
60
  $data = __('Enter Password to Download:', 'simple-download-monitor');
61
  $data .= '<form action="'.$action_url.'" method="post" >';
62
  $data .= '<input type="password" name="pass_text" class="sdm_pass_text" value="" /> ';
63
- $data .= '<input type="submit" name="sdm_dl_pass_submit" class="pass_sumbit" value="' . __('Submit', 'simple-download-monitor') . '" />';
64
  $data .= '<input type="hidden" name="download_id" value="' . $id . '" />';
65
  $data .= '</form>';
66
  return $data;
@@ -157,3 +166,24 @@ function sdm_sanitize_value_by_array($to_check, $valid_values)
157
  }
158
  return reset($keys);//Return the first element from the valid values
159
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  return $isset_item_description;
56
  }
57
 
58
+ function sdm_get_password_entry_form($id, $args=array()) {
59
+ $action_url = WP_SIMPLE_DL_MONITOR_SITE_HOME_URL . '/?smd_process_download=1&download_id=' . $id;
60
+
61
+ //Get the download button text
62
+ $button_text = isset($args['button_text']) ? $args['button_text'] : '';
63
+ if (empty($button_text)) {//Use the default text for the button
64
+ $button_text_string = __('Download Now!', 'simple-download-monitor');
65
+ } else {//Use the custom text
66
+ $button_text_string = $button_text;
67
+ }
68
+
69
  $data = __('Enter Password to Download:', 'simple-download-monitor');
70
  $data .= '<form action="'.$action_url.'" method="post" >';
71
  $data .= '<input type="password" name="pass_text" class="sdm_pass_text" value="" /> ';
72
+ $data .= '<input type="submit" name="sdm_dl_pass_submit" class="pass_sumbit sdm_pass_protected_download" value="' . $button_text_string . '" />';
73
  $data .= '<input type="hidden" name="download_id" value="' . $id . '" />';
74
  $data .= '</form>';
75
  return $data;
166
  }
167
  return reset($keys);//Return the first element from the valid values
168
  }
169
+
170
+ function sdm_get_logged_in_user() {
171
+ $visitor_name = false;
172
+
173
+ if (is_user_logged_in()) { // Get WP user name (if logged in)
174
+ $current_user = wp_get_current_user();
175
+ $visitor_name = $current_user->user_login;
176
+ }
177
+
178
+ //WP eMember plugin integration
179
+ if (class_exists('Emember_Auth')) {
180
+ //WP eMember plugin is installed.
181
+ $emember_auth = Emember_Auth::getInstance();
182
+ $username = $emember_auth->getUserInfo('user_name');
183
+ if (!empty($username)) {//Member is logged in.
184
+ $visitor_name = $username; //Override the visitor name to emember username.
185
+ }
186
+ }
187
+
188
+ return $visitor_name;
189
+ }
includes/templates/fancy0/sdm-fancy-0.php CHANGED
@@ -89,7 +89,7 @@ function sdm_generate_fancy0_display_output($args) {
89
  $get_cpt_object = get_post($id);
90
  $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
91
  if ($cpt_is_password !== 'no') {//This is a password protected download so replace the download now button with password requirement
92
- $download_button_code = sdm_get_password_entry_form($id);
93
  }
94
 
95
  $output = "";
89
  $get_cpt_object = get_post($id);
90
  $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
91
  if ($cpt_is_password !== 'no') {//This is a password protected download so replace the download now button with password requirement
92
+ $download_button_code = sdm_get_password_entry_form($id, $args);
93
  }
94
 
95
  $output = "";
includes/templates/fancy1/sdm-fancy-1.php CHANGED
@@ -35,7 +35,7 @@ function sdm_generate_fancy1_category_display_output($get_posts, $args) {
35
  * id, fancy, button_text, new_window
36
  */
37
 
38
- function sdm_generate_fancy1_display_output($atts) {
39
 
40
  $shortcode_atts = sanitize_sdm_create_download_shortcode_atts(
41
  shortcode_atts(array(
@@ -46,7 +46,7 @@ function sdm_generate_fancy1_display_output($atts) {
46
  'css_class' => '',
47
  'show_size' => '',
48
  'show_version' => '',
49
- ), $atts)
50
  );
51
 
52
  // Make shortcode attributes available in function local scope.
@@ -90,7 +90,7 @@ function sdm_generate_fancy1_display_output($atts) {
90
  $get_cpt_object = get_post($id);
91
  $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
92
  if ($cpt_is_password !== 'no') {//This is a password protected download so replace the download now button with password requirement
93
- $download_button_code = sdm_get_password_entry_form($id);
94
  }
95
 
96
  $db_count = sdm_get_download_count_for_post($id);
35
  * id, fancy, button_text, new_window
36
  */
37
 
38
+ function sdm_generate_fancy1_display_output($args) {
39
 
40
  $shortcode_atts = sanitize_sdm_create_download_shortcode_atts(
41
  shortcode_atts(array(
46
  'css_class' => '',
47
  'show_size' => '',
48
  'show_version' => '',
49
+ ), $args)
50
  );
51
 
52
  // Make shortcode attributes available in function local scope.
90
  $get_cpt_object = get_post($id);
91
  $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
92
  if ($cpt_is_password !== 'no') {//This is a password protected download so replace the download now button with password requirement
93
+ $download_button_code = sdm_get_password_entry_form($id, $args);
94
  }
95
 
96
  $db_count = sdm_get_download_count_for_post($id);
includes/templates/fancy2/sdm-fancy-2.php CHANGED
@@ -52,7 +52,7 @@ function sdm_generate_fancy2_category_display_output($get_posts, $args) {
52
  * id, fancy, button_text, new_window
53
  */
54
 
55
- function sdm_generate_fancy2_display_output($atts) {
56
 
57
  $shortcode_atts = sanitize_sdm_create_download_shortcode_atts(
58
  shortcode_atts(array(
@@ -63,7 +63,7 @@ function sdm_generate_fancy2_display_output($atts) {
63
  'css_class' => 'sdm_fancy2_grid',
64
  'show_size' => '',
65
  'show_version' => '',
66
- ), $atts)
67
  );
68
 
69
  // Make shortcode attributes available in function local scope.
@@ -85,7 +85,7 @@ function sdm_generate_fancy2_display_output($atts) {
85
  $get_cpt_object = get_post($id);
86
  $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
87
  if ($cpt_is_password !== 'no') {//This is a password protected download so replace the download now button with password requirement
88
- $download_button_code = sdm_get_password_entry_form($id);
89
  }
90
 
91
  // Get item thumbnail
52
  * id, fancy, button_text, new_window
53
  */
54
 
55
+ function sdm_generate_fancy2_display_output($args) {
56
 
57
  $shortcode_atts = sanitize_sdm_create_download_shortcode_atts(
58
  shortcode_atts(array(
63
  'css_class' => 'sdm_fancy2_grid',
64
  'show_size' => '',
65
  'show_version' => '',
66
+ ), $args)
67
  );
68
 
69
  // Make shortcode attributes available in function local scope.
85
  $get_cpt_object = get_post($id);
86
  $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
87
  if ($cpt_is_password !== 'no') {//This is a password protected download so replace the download now button with password requirement
88
+ $download_button_code = sdm_get_password_entry_form($id, $args);
89
  }
90
 
91
  // Get item thumbnail
main.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
  /**
3
- * Plugin Name: Simple Download Monitor
4
- * Plugin URI: https://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin
5
- * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
- * Version: 3.4.0
7
- * Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
8
- * Author URI: https://www.tipsandtricks-hq.com/development-center
9
- * License: GPL2
10
- */
11
 
12
  if (!defined('ABSPATH')) {
13
  exit;
14
  }
15
 
16
- define('WP_SIMPLE_DL_MONITOR_VERSION', '3.4.0');
17
  define('WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname(plugin_basename(__FILE__)));
18
  define('WP_SIMPLE_DL_MONITOR_URL', plugins_url('', __FILE__));
19
  define('WP_SIMPLE_DL_MONITOR_PATH', plugin_dir_path(__FILE__));
@@ -28,6 +28,7 @@ include_once('includes/sdm-utility-functions-admin-side.php');
28
  include_once('includes/sdm-download-request-handler.php');
29
  include_once('includes/sdm-logs-list-table.php');
30
  include_once('includes/sdm-latest-downloads.php');
 
31
  include_once('sdm-post-type-and-taxonomy.php');
32
  include_once('sdm-shortcodes.php');
33
  include_once('sdm-post-type-content-handler.php');
@@ -82,6 +83,7 @@ function sdm_plugins_loaded_tasks() {
82
  * * Handle Generic Init tasks
83
  */
84
  add_action('init', 'sdm_init_time_tasks');
 
85
  function sdm_init_time_tasks() {
86
  //Handle download request if any
87
  handle_sdm_download_via_direct_post();
@@ -90,6 +92,7 @@ function sdm_init_time_tasks() {
90
  /*
91
  * DB upgrade check
92
  */
 
93
  function sdm_db_update_check() {
94
  if (is_admin()) {//Check if DB needs to be upgraded
95
  global $sdm_db_version;
@@ -211,7 +214,7 @@ class simpleDownloadManager {
211
  }
212
 
213
  public function sdm_create_upload_metabox() {
214
-
215
  //***** Create metaboxes for the custom post type
216
  add_meta_box('sdm_description_meta_box', __('Description', 'simple-download-monitor'), array($this, 'display_sdm_description_meta_box'), 'sdm_downloads', 'normal', 'default');
217
  add_meta_box('sdm_upload_meta_box', __('Upload File', 'simple-download-monitor'), array($this, 'display_sdm_upload_meta_box'), 'sdm_downloads', 'normal', 'default');
@@ -220,7 +223,6 @@ class simpleDownloadManager {
220
  add_meta_box('sdm_stats_meta_box', __('Statistics', 'simple-download-monitor'), array($this, 'display_sdm_stats_meta_box'), 'sdm_downloads', 'normal', 'default');
221
  add_meta_box('sdm_other_details_meta_box', __('Other Details (Optional)', 'simple-download-monitor'), array($this, 'display_sdm_other_details_meta_box'), 'sdm_downloads', 'normal', 'default');
222
  add_meta_box('sdm_shortcode_meta_box', __('Shortcodes', 'simple-download-monitor'), array($this, 'display_sdm_shortcode_meta_box'), 'sdm_downloads', 'normal', 'default');
223
-
224
  }
225
 
226
  public function display_sdm_description_meta_box($post) { // Description metabox
@@ -237,17 +239,17 @@ class simpleDownloadManager {
237
  public function display_sdm_upload_meta_box($post) { // File Upload metabox
238
  $old_upload = get_post_meta($post->ID, 'sdm_upload', true);
239
  $old_value = isset($old_upload) ? $old_upload : '';
240
-
241
  _e('Manually enter a valid URL of the file in the text box below, or click "Select File" button to upload (or choose) the downloadable file.', 'simple-download-monitor');
242
  echo '<br /><br />';
243
-
244
- echo '<div class="sdm-download-edit-file-url-section">';
245
- echo '<input id="sdm_upload" type="text" size="100" name="sdm_upload" value="'.$old_value.'" placeholder="http://..." />';
246
  echo '</div>';
247
-
248
  echo '<br />';
249
- echo '<input id="upload_image_button" type="button" class="button-primary" value="'.__('Select File', 'simple-download-monitor').'" />';
250
-
251
  echo '<br /><br />';
252
  _e('Steps to upload a file or choose one from your media library:', 'simple-download-monitor');
253
  echo '<ol>';
@@ -262,11 +264,11 @@ class simpleDownloadManager {
262
  public function display_sdm_dispatch_meta_box($post) {
263
  $dispatch = get_post_meta($post->ID, 'sdm_item_dispatch', true);
264
 
265
- if ( $dispatch === '' ) {
266
  // No value yet (either new item or saved with older version of plugin)
267
  $screen = get_current_screen();
268
 
269
- if ( $screen->action === 'add' ) {
270
  // New item: set default value as per plugin settings.
271
  $main_opts = get_option('sdm_downloads_options');
272
  $dispatch = isset($main_opts['general_default_dispatch_value']) && $main_opts['general_default_dispatch_value'];
@@ -283,7 +285,6 @@ class simpleDownloadManager {
283
  $old_thumbnail = get_post_meta($post->ID, 'sdm_upload_thumbnail', true);
284
  $old_value = isset($old_thumbnail) ? $old_thumbnail : '';
285
  _e('Manually enter a valid URL, or click "Select Image" to upload (or choose) the file thumbnail image.', 'simple-download-monitor');
286
-
287
  ?>
288
  <br /><br />
289
  <input id="sdm_upload_thumbnail" type="text" size="100" name="sdm_upload_thumbnail" value="<?php echo $old_value; ?>" placeholder="http://..." />
@@ -300,12 +301,12 @@ class simpleDownloadManager {
300
  }
301
  ?>
302
  </span>
303
-
304
  <?php
305
  echo '<p class="description">';
306
  _e('This thumbnail image will be used to create a fancy file download box if you want to use it.', 'simple-download-monitor');
307
  echo '</p>';
308
-
309
  wp_nonce_field('sdm_thumbnail_box_nonce', 'sdm_thumbnail_box_nonce_check');
310
  }
311
 
@@ -322,19 +323,19 @@ class simpleDownloadManager {
322
 
323
  global $wpdb;
324
  $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post->ID));
325
-
326
  echo '<div class="sdm-download-edit-dl-count">';
327
  _e('Number of Downloads:', 'simple-download-monitor');
328
  echo ' <strong>' . $wpdb->num_rows . '</strong>';
329
  echo '</div>';
330
-
331
  echo '<div class="sdm-download-edit-offset-count">';
332
  _e('Offset Count: ', 'simple-download-monitor');
333
  echo '<br />';
334
  echo ' <input type="text" size="10" name="sdm_count_offset" value="' . $value . '" />';
335
- echo '<p class="description">'.__('Enter any positive or negative numerical value; to offset the download count shown to the visitors (when using the download counter shortcode).', 'simple-download-monitor').'</p>';
336
  echo '</div>';
337
-
338
  echo '<br />';
339
  echo '<div class="sdm-download-edit-disable-logging">';
340
  echo '<input type="checkbox" name="sdm_item_no_log" ' . $checked . ' />';
@@ -344,32 +345,31 @@ class simpleDownloadManager {
344
 
345
  wp_nonce_field('sdm_count_offset_nonce', 'sdm_count_offset_nonce_check');
346
  }
347
-
348
- public function display_sdm_other_details_meta_box($post){ //Other details metabox
349
  $file_size = get_post_meta($post->ID, 'sdm_item_file_size', true);
350
  $file_size = isset($file_size) ? $file_size : '';
351
-
352
  $version = get_post_meta($post->ID, 'sdm_item_version', true);
353
  $version = isset($version) ? $version : '';
354
-
355
  echo '<div class="sdm-download-edit-filesize">';
356
  _e('File Size: ', 'simple-download-monitor');
357
  echo '<br />';
358
  echo ' <input type="text" name="sdm_item_file_size" value="' . $file_size . '" size="20" />';
359
- echo '<p class="description">'.__('Enter the size of this file (example value: 2.15 MB). You can show this value in the fancy display by using a shortcode parameter.', 'simple-download-monitor').'</p>';
360
  echo '</div>';
361
-
362
  echo '<div class="sdm-download-edit-version">';
363
  _e('Version: ', 'simple-download-monitor');
364
  echo '<br />';
365
  echo ' <input type="text" name="sdm_item_version" value="' . $version . '" size="20" />';
366
- echo '<p class="description">'.__('Enter the version number for this item if any (example value: v2.5.10). You can show this value in the fancy display by using a shortcode parameter.', 'simple-download-monitor').'</p>';
367
  echo '</div>';
368
-
369
  wp_nonce_field('sdm_other_details_nonce', 'sdm_other_details_nonce_check');
370
-
371
  }
372
-
373
  public function display_sdm_shortcode_meta_box($post) { //Shortcode metabox
374
  _e('The following shortcode can be used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter (in the post editor) to add this shortcode to a post or page.', 'simple-download-monitor');
375
  echo '<br />';
@@ -379,10 +379,10 @@ class simpleDownloadManager {
379
  _e('The following shortcode can be used to show a download counter for this item.', 'simple-download-monitor');
380
  echo '<br />';
381
  echo '[sdm_download_counter id="' . $post->ID . '"]';
382
-
383
  echo '<br /><br />';
384
  echo 'Read the full shortcode usage documentation <a href="https://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin" target="_blank">here</a>.';
385
- }
386
 
387
  public function sdm_save_description_meta_data($post_id) { // Save Description metabox
388
  if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
@@ -410,7 +410,7 @@ class simpleDownloadManager {
410
  if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
411
  return;
412
  }
413
- if ( !isset($_POST['sdm_dispatch_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_dispatch_box_nonce_check'], 'sdm_dispatch_box_nonce') ) {
414
  return;
415
  }
416
  // Get POST-ed data as boolean value
@@ -447,24 +447,23 @@ class simpleDownloadManager {
447
  delete_post_meta($post_id, 'sdm_item_no_log');
448
  }
449
  }
450
-
451
  public function sdm_save_other_details_meta_data($post_id) { // Save Statistics Upload metabox
452
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
453
  return;
454
  }
455
- if (!isset($_POST['sdm_other_details_nonce_check']) || !wp_verify_nonce($_POST['sdm_other_details_nonce_check'], 'sdm_other_details_nonce')){
456
  return;
457
  }
458
 
459
  if (isset($_POST['sdm_item_file_size'])) {
460
  update_post_meta($post_id, 'sdm_item_file_size', $_POST['sdm_item_file_size']);
461
  }
462
-
463
- if (isset($_POST['sdm_item_version'])){
464
  update_post_meta($post_id, 'sdm_item_version', $_POST['sdm_item_version']);
465
  }
466
-
467
- }
468
 
469
  public function sdm_remove_view_link_cpt($action, $post) {
470
 
@@ -480,7 +479,7 @@ class simpleDownloadManager {
480
 
481
  //Register the main setting
482
  register_setting('sdm_downloads_options', 'sdm_downloads_options');
483
-
484
  //Add all the settings section that will go under the main settings
485
  add_settings_section('general_options', __('General Options', 'simple-download-monitor'), array($this, 'general_options_cb'), 'general_options_section');
486
  add_settings_section('admin_options', __('Admin Options', 'simple-download-monitor'), array($this, 'admin_options_cb'), 'admin_options_section');
@@ -489,19 +488,20 @@ class simpleDownloadManager {
489
  //Add all the individual settings fields that goes under the sections
490
  add_settings_field('general_hide_donwload_count', __('Hide Download Count', 'simple-download-monitor'), array($this, 'hide_download_count_cb'), 'general_options_section', 'general_options');
491
  add_settings_field('general_default_dispatch_value', __('PHP Dispatching', 'simple-download-monitor'), array($this, 'general_default_dispatch_value_cb'), 'general_options_section', 'general_options');
492
-
 
493
  add_settings_field('admin_tinymce_button', __('Remove Tinymce Button', 'simple-download-monitor'), array($this, 'admin_tinymce_button_cb'), 'admin_options_section', 'admin_options');
494
  add_settings_field('admin_log_unique', __('Log Unique IP', 'simple-download-monitor'), array($this, 'admin_log_unique'), 'admin_options_section', 'admin_options');
495
  add_settings_field('admin_no_logs', __('Disable Download Logs', 'simple-download-monitor'), array($this, 'admin_no_logs_cb'), 'admin_options_section', 'admin_options');
496
-
497
  add_settings_field('download_button_color', __('Download Button Color', 'simple-download-monitor'), array($this, 'download_button_color_cb'), 'sdm_colors_section', 'sdm_colors');
498
  }
499
 
500
  public function general_options_cb() {
501
  //Set the message that will be shown below the general options settings heading
502
- _e('General options settings', 'simple-download-monitor');
503
  }
504
-
505
  public function admin_options_cb() {
506
  //Set the message that will be shown below the admin options settings heading
507
  _e('Admin options settings', 'simple-download-monitor');
@@ -524,7 +524,14 @@ class simpleDownloadManager {
524
  echo '<input name="sdm_downloads_options[general_default_dispatch_value]" id="general_default_dispatch_value" type="checkbox" value="1"' . checked(true, $value, false) . ' />';
525
  echo '<label for="general_default_dispatch_value">' . __('When you create a new download item, The PHP Dispatching option should be enabled by default. PHP Dispatching keeps the URL of the downloadable files hidden.', 'simple-download-monitor') . '</label>';
526
  }
527
-
 
 
 
 
 
 
 
528
  public function admin_tinymce_button_cb() {
529
  $main_opts = get_option('sdm_downloads_options');
530
  echo '<input name="sdm_downloads_options[admin_tinymce_button]" id="admin_tinymce_button" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked(1, isset($main_opts['admin_tinymce_button']), false) . ' /> ';
@@ -557,8 +564,9 @@ class simpleDownloadManager {
557
  esc_html_e('Adjusts the color of the "Download Now" button.', 'simple-download-monitor');
558
  }
559
 
560
- }//End of simpleDownloadManager class
561
 
 
562
  //Initialize the simpleDownloadManager class
563
  $simpleDownloadManager = new simpleDownloadManager();
564
 
@@ -586,14 +594,14 @@ function sdm_tiny_get_post_ids_ajax_call() {
586
 
587
  //Remove Thumbnail Image
588
  //add_action('wp_ajax_nopriv_sdm_remove_thumbnail_image', '');//This is only available to logged-in users
589
- add_action('wp_ajax_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call');//Execute this for authenticated users only
590
 
591
  function sdm_remove_thumbnail_image_ajax_call() {
592
- if(!current_user_can('edit_posts')){
593
  //Permission denied
594
  wp_die(__('Permission denied!', 'simple-download-monitor'));
595
  exit;
596
- }
597
 
598
  //Go ahead with the thumbnail removal
599
  $post_id = $_POST['post_id_del'];
1
  <?php
2
  /**
3
+ * Plugin Name: Simple Download Monitor
4
+ * Plugin URI: https://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin
5
+ * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
+ * Version: 3.4.3
7
+ * Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
8
+ * Author URI: https://www.tipsandtricks-hq.com/development-center
9
+ * License: GPL2
10
+ */
11
 
12
  if (!defined('ABSPATH')) {
13
  exit;
14
  }
15
 
16
+ define('WP_SIMPLE_DL_MONITOR_VERSION', '3.4.3');
17
  define('WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname(plugin_basename(__FILE__)));
18
  define('WP_SIMPLE_DL_MONITOR_URL', plugins_url('', __FILE__));
19
  define('WP_SIMPLE_DL_MONITOR_PATH', plugin_dir_path(__FILE__));
28
  include_once('includes/sdm-download-request-handler.php');
29
  include_once('includes/sdm-logs-list-table.php');
30
  include_once('includes/sdm-latest-downloads.php');
31
+ include_once('includes/sdm-search-shortcode-handler.php');
32
  include_once('sdm-post-type-and-taxonomy.php');
33
  include_once('sdm-shortcodes.php');
34
  include_once('sdm-post-type-content-handler.php');
83
  * * Handle Generic Init tasks
84
  */
85
  add_action('init', 'sdm_init_time_tasks');
86
+
87
  function sdm_init_time_tasks() {
88
  //Handle download request if any
89
  handle_sdm_download_via_direct_post();
92
  /*
93
  * DB upgrade check
94
  */
95
+
96
  function sdm_db_update_check() {
97
  if (is_admin()) {//Check if DB needs to be upgraded
98
  global $sdm_db_version;
214
  }
215
 
216
  public function sdm_create_upload_metabox() {
217
+
218
  //***** Create metaboxes for the custom post type
219
  add_meta_box('sdm_description_meta_box', __('Description', 'simple-download-monitor'), array($this, 'display_sdm_description_meta_box'), 'sdm_downloads', 'normal', 'default');
220
  add_meta_box('sdm_upload_meta_box', __('Upload File', 'simple-download-monitor'), array($this, 'display_sdm_upload_meta_box'), 'sdm_downloads', 'normal', 'default');
223
  add_meta_box('sdm_stats_meta_box', __('Statistics', 'simple-download-monitor'), array($this, 'display_sdm_stats_meta_box'), 'sdm_downloads', 'normal', 'default');
224
  add_meta_box('sdm_other_details_meta_box', __('Other Details (Optional)', 'simple-download-monitor'), array($this, 'display_sdm_other_details_meta_box'), 'sdm_downloads', 'normal', 'default');
225
  add_meta_box('sdm_shortcode_meta_box', __('Shortcodes', 'simple-download-monitor'), array($this, 'display_sdm_shortcode_meta_box'), 'sdm_downloads', 'normal', 'default');
 
226
  }
227
 
228
  public function display_sdm_description_meta_box($post) { // Description metabox
239
  public function display_sdm_upload_meta_box($post) { // File Upload metabox
240
  $old_upload = get_post_meta($post->ID, 'sdm_upload', true);
241
  $old_value = isset($old_upload) ? $old_upload : '';
242
+
243
  _e('Manually enter a valid URL of the file in the text box below, or click "Select File" button to upload (or choose) the downloadable file.', 'simple-download-monitor');
244
  echo '<br /><br />';
245
+
246
+ echo '<div class="sdm-download-edit-file-url-section">';
247
+ echo '<input id="sdm_upload" type="text" size="100" name="sdm_upload" value="' . $old_value . '" placeholder="http://..." />';
248
  echo '</div>';
249
+
250
  echo '<br />';
251
+ echo '<input id="upload_image_button" type="button" class="button-primary" value="' . __('Select File', 'simple-download-monitor') . '" />';
252
+
253
  echo '<br /><br />';
254
  _e('Steps to upload a file or choose one from your media library:', 'simple-download-monitor');
255
  echo '<ol>';
264
  public function display_sdm_dispatch_meta_box($post) {
265
  $dispatch = get_post_meta($post->ID, 'sdm_item_dispatch', true);
266
 
267
+ if ($dispatch === '') {
268
  // No value yet (either new item or saved with older version of plugin)
269
  $screen = get_current_screen();
270
 
271
+ if ($screen->action === 'add') {
272
  // New item: set default value as per plugin settings.
273
  $main_opts = get_option('sdm_downloads_options');
274
  $dispatch = isset($main_opts['general_default_dispatch_value']) && $main_opts['general_default_dispatch_value'];
285
  $old_thumbnail = get_post_meta($post->ID, 'sdm_upload_thumbnail', true);
286
  $old_value = isset($old_thumbnail) ? $old_thumbnail : '';
287
  _e('Manually enter a valid URL, or click "Select Image" to upload (or choose) the file thumbnail image.', 'simple-download-monitor');
 
288
  ?>
289
  <br /><br />
290
  <input id="sdm_upload_thumbnail" type="text" size="100" name="sdm_upload_thumbnail" value="<?php echo $old_value; ?>" placeholder="http://..." />
301
  }
302
  ?>
303
  </span>
304
+
305
  <?php
306
  echo '<p class="description">';
307
  _e('This thumbnail image will be used to create a fancy file download box if you want to use it.', 'simple-download-monitor');
308
  echo '</p>';
309
+
310
  wp_nonce_field('sdm_thumbnail_box_nonce', 'sdm_thumbnail_box_nonce_check');
311
  }
312
 
323
 
324
  global $wpdb;
325
  $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post->ID));
326
+
327
  echo '<div class="sdm-download-edit-dl-count">';
328
  _e('Number of Downloads:', 'simple-download-monitor');
329
  echo ' <strong>' . $wpdb->num_rows . '</strong>';
330
  echo '</div>';
331
+
332
  echo '<div class="sdm-download-edit-offset-count">';
333
  _e('Offset Count: ', 'simple-download-monitor');
334
  echo '<br />';
335
  echo ' <input type="text" size="10" name="sdm_count_offset" value="' . $value . '" />';
336
+ echo '<p class="description">' . __('Enter any positive or negative numerical value; to offset the download count shown to the visitors (when using the download counter shortcode).', 'simple-download-monitor') . '</p>';
337
  echo '</div>';
338
+
339
  echo '<br />';
340
  echo '<div class="sdm-download-edit-disable-logging">';
341
  echo '<input type="checkbox" name="sdm_item_no_log" ' . $checked . ' />';
345
 
346
  wp_nonce_field('sdm_count_offset_nonce', 'sdm_count_offset_nonce_check');
347
  }
348
+
349
+ public function display_sdm_other_details_meta_box($post) { //Other details metabox
350
  $file_size = get_post_meta($post->ID, 'sdm_item_file_size', true);
351
  $file_size = isset($file_size) ? $file_size : '';
352
+
353
  $version = get_post_meta($post->ID, 'sdm_item_version', true);
354
  $version = isset($version) ? $version : '';
355
+
356
  echo '<div class="sdm-download-edit-filesize">';
357
  _e('File Size: ', 'simple-download-monitor');
358
  echo '<br />';
359
  echo ' <input type="text" name="sdm_item_file_size" value="' . $file_size . '" size="20" />';
360
+ echo '<p class="description">' . __('Enter the size of this file (example value: 2.15 MB). You can show this value in the fancy display by using a shortcode parameter.', 'simple-download-monitor') . '</p>';
361
  echo '</div>';
362
+
363
  echo '<div class="sdm-download-edit-version">';
364
  _e('Version: ', 'simple-download-monitor');
365
  echo '<br />';
366
  echo ' <input type="text" name="sdm_item_version" value="' . $version . '" size="20" />';
367
+ echo '<p class="description">' . __('Enter the version number for this item if any (example value: v2.5.10). You can show this value in the fancy display by using a shortcode parameter.', 'simple-download-monitor') . '</p>';
368
  echo '</div>';
369
+
370
  wp_nonce_field('sdm_other_details_nonce', 'sdm_other_details_nonce_check');
 
371
  }
372
+
373
  public function display_sdm_shortcode_meta_box($post) { //Shortcode metabox
374
  _e('The following shortcode can be used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter (in the post editor) to add this shortcode to a post or page.', 'simple-download-monitor');
375
  echo '<br />';
379
  _e('The following shortcode can be used to show a download counter for this item.', 'simple-download-monitor');
380
  echo '<br />';
381
  echo '[sdm_download_counter id="' . $post->ID . '"]';
382
+
383
  echo '<br /><br />';
384
  echo 'Read the full shortcode usage documentation <a href="https://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin" target="_blank">here</a>.';
385
+ }
386
 
387
  public function sdm_save_description_meta_data($post_id) { // Save Description metabox
388
  if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
410
  if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
411
  return;
412
  }
413
+ if (!isset($_POST['sdm_dispatch_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_dispatch_box_nonce_check'], 'sdm_dispatch_box_nonce')) {
414
  return;
415
  }
416
  // Get POST-ed data as boolean value
447
  delete_post_meta($post_id, 'sdm_item_no_log');
448
  }
449
  }
450
+
451
  public function sdm_save_other_details_meta_data($post_id) { // Save Statistics Upload metabox
452
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
453
  return;
454
  }
455
+ if (!isset($_POST['sdm_other_details_nonce_check']) || !wp_verify_nonce($_POST['sdm_other_details_nonce_check'], 'sdm_other_details_nonce')) {
456
  return;
457
  }
458
 
459
  if (isset($_POST['sdm_item_file_size'])) {
460
  update_post_meta($post_id, 'sdm_item_file_size', $_POST['sdm_item_file_size']);
461
  }
462
+
463
+ if (isset($_POST['sdm_item_version'])) {
464
  update_post_meta($post_id, 'sdm_item_version', $_POST['sdm_item_version']);
465
  }
466
+ }
 
467
 
468
  public function sdm_remove_view_link_cpt($action, $post) {
469
 
479
 
480
  //Register the main setting
481
  register_setting('sdm_downloads_options', 'sdm_downloads_options');
482
+
483
  //Add all the settings section that will go under the main settings
484
  add_settings_section('general_options', __('General Options', 'simple-download-monitor'), array($this, 'general_options_cb'), 'general_options_section');
485
  add_settings_section('admin_options', __('Admin Options', 'simple-download-monitor'), array($this, 'admin_options_cb'), 'admin_options_section');
488
  //Add all the individual settings fields that goes under the sections
489
  add_settings_field('general_hide_donwload_count', __('Hide Download Count', 'simple-download-monitor'), array($this, 'hide_download_count_cb'), 'general_options_section', 'general_options');
490
  add_settings_field('general_default_dispatch_value', __('PHP Dispatching', 'simple-download-monitor'), array($this, 'general_default_dispatch_value_cb'), 'general_options_section', 'general_options');
491
+ add_settings_field('only_logged_in_can_download', __('Only Allow Logged-in Users to Download', 'simple-download-monitor'), array($this, 'general_only_logged_in_can_download_cb'), 'general_options_section', 'general_options');
492
+
493
  add_settings_field('admin_tinymce_button', __('Remove Tinymce Button', 'simple-download-monitor'), array($this, 'admin_tinymce_button_cb'), 'admin_options_section', 'admin_options');
494
  add_settings_field('admin_log_unique', __('Log Unique IP', 'simple-download-monitor'), array($this, 'admin_log_unique'), 'admin_options_section', 'admin_options');
495
  add_settings_field('admin_no_logs', __('Disable Download Logs', 'simple-download-monitor'), array($this, 'admin_no_logs_cb'), 'admin_options_section', 'admin_options');
496
+
497
  add_settings_field('download_button_color', __('Download Button Color', 'simple-download-monitor'), array($this, 'download_button_color_cb'), 'sdm_colors_section', 'sdm_colors');
498
  }
499
 
500
  public function general_options_cb() {
501
  //Set the message that will be shown below the general options settings heading
502
+ _e('General options settings', 'simple-download-monitor');
503
  }
504
+
505
  public function admin_options_cb() {
506
  //Set the message that will be shown below the admin options settings heading
507
  _e('Admin options settings', 'simple-download-monitor');
524
  echo '<input name="sdm_downloads_options[general_default_dispatch_value]" id="general_default_dispatch_value" type="checkbox" value="1"' . checked(true, $value, false) . ' />';
525
  echo '<label for="general_default_dispatch_value">' . __('When you create a new download item, The PHP Dispatching option should be enabled by default. PHP Dispatching keeps the URL of the downloadable files hidden.', 'simple-download-monitor') . '</label>';
526
  }
527
+
528
+ public function general_only_logged_in_can_download_cb() {
529
+ $main_opts = get_option('sdm_downloads_options');
530
+ $value = isset($main_opts['only_logged_in_can_download']) && $main_opts['only_logged_in_can_download'];
531
+ echo '<input name="sdm_downloads_options[only_logged_in_can_download]" id="only_logged_in_can_download" type="checkbox" value="1"' . checked(true, $value, false) . ' />';
532
+ echo '<label for="only_logged_in_can_download">' . __('Enable this option if you want to allow downloads only for logged-in users. When enabled, anonymous users clicking on the download button will receive an error message.', 'simple-download-monitor') . '</label>';
533
+ }
534
+
535
  public function admin_tinymce_button_cb() {
536
  $main_opts = get_option('sdm_downloads_options');
537
  echo '<input name="sdm_downloads_options[admin_tinymce_button]" id="admin_tinymce_button" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked(1, isset($main_opts['admin_tinymce_button']), false) . ' /> ';
564
  esc_html_e('Adjusts the color of the "Download Now" button.', 'simple-download-monitor');
565
  }
566
 
567
+ }
568
 
569
+ //End of simpleDownloadManager class
570
  //Initialize the simpleDownloadManager class
571
  $simpleDownloadManager = new simpleDownloadManager();
572
 
594
 
595
  //Remove Thumbnail Image
596
  //add_action('wp_ajax_nopriv_sdm_remove_thumbnail_image', '');//This is only available to logged-in users
597
+ add_action('wp_ajax_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call'); //Execute this for authenticated users only
598
 
599
  function sdm_remove_thumbnail_image_ajax_call() {
600
+ if (!current_user_can('edit_posts')) {
601
  //Permission denied
602
  wp_die(__('Permission denied!', 'simple-download-monitor'));
603
  exit;
604
+ }
605
 
606
  //Go ahead with the thumbnail removal
607
  $post_id = $_POST['post_id_del'];
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Tips and Tricks HQ, Ruhul Amin, josh401, mbrsolution, chesio
3
  Donate link: https://www.tipsandtricks-hq.com
4
  Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, downloadmanager, file manager, protect downloads, password, download category, file tree, ajax, download template, grid, documents, ip address
5
  Requires at least: 4.1.0
6
- Tested up to: 4.7
7
- Stable tag: 3.4.0
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
@@ -64,6 +64,7 @@ https://www.youtube.com/watch?v=L-mXbs7kp0s
64
  * You can also choose to only monitor downloads from unique IP address only.
65
  * Option to specify file size info so it can be shown to your visitors.
66
  * Option to specify version number info for the download item so it can be shown to your visitors.
 
67
 
68
  View more details on the [download monitor plugin](https://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin) page.
69
 
@@ -170,6 +171,17 @@ For screenshots please visit the [download monitor plugin page](https://www.tips
170
 
171
  == Changelog ==
172
 
 
 
 
 
 
 
 
 
 
 
 
173
  = 3.4.0 =
174
  - Added a new hook to allow plugin extensions to hook into download request handling.
175
  - Added empty index file to the plugin folder.
3
  Donate link: https://www.tipsandtricks-hq.com
4
  Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, downloadmanager, file manager, protect downloads, password, download category, file tree, ajax, download template, grid, documents, ip address
5
  Requires at least: 4.1.0
6
+ Tested up to: 4.8
7
+ Stable tag: 3.4.2
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
64
  * You can also choose to only monitor downloads from unique IP address only.
65
  * Option to specify file size info so it can be shown to your visitors.
66
  * Option to specify version number info for the download item so it can be shown to your visitors.
67
+ * Option to restrict downloads to logged-in users only.
68
 
69
  View more details on the [download monitor plugin](https://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin) page.
70
 
171
 
172
  == Changelog ==
173
 
174
+ = 3.4.3 =
175
+ - The [sdm_search_form] can take the fancy template as a shortcode argument to display the search result using that template.
176
+
177
+ = 3.4.2 =
178
+ - Added a new option "Only Allow Logged-in Users to Download".
179
+ - Added [sdm_search_form] shortcode to display a search form for searching SDM downloads only.
180
+
181
+ = 3.4.1 =
182
+ - The password protected download button will use the "button_text" specified in the shortcode (if any).
183
+ - The download now log will track WP eMember plugin username if the user is logged in as a member.
184
+
185
  = 3.4.0 =
186
  - Added a new hook to allow plugin extensions to hook into download request handling.
187
  - Added empty index file to the plugin folder.
sdm-post-type-content-handler.php CHANGED
@@ -51,6 +51,14 @@ function filter_sdm_post_type_content($content) {
51
  $download_button_code = sdm_get_password_entry_form($id);
52
  }
53
 
 
 
 
 
 
 
 
 
54
  $db_count = sdm_get_download_count_for_post($id);
55
  $string = ($db_count == '1') ? __('Download', 'simple-download-monitor') : __('Downloads', 'simple-download-monitor');
56
  $download_count_string = '<span class="sdm_post_count_number">' . $db_count . '</span><span class="sdm_post_count_string"> ' . $string . '</span>';
@@ -101,4 +109,4 @@ function filter_sdm_post_type_content($content) {
101
  }
102
 
103
  return $content;
104
- }
51
  $download_button_code = sdm_get_password_entry_form($id);
52
  }
53
 
54
+ // Check if we only allow the download for logged-in users
55
+ // if (isset($main_opts['only_logged_in_can_download'])) {
56
+ // if ($main_opts['only_logged_in_can_download'] && sdm_get_logged_in_user()===false) {
57
+ // // User not logged in, let's display the message
58
+ // $download_button_code = __('You need to be logged in to download this file.','simple-download-monitor');
59
+ // }
60
+ // }
61
+
62
  $db_count = sdm_get_download_count_for_post($id);
63
  $string = ($db_count == '1') ? __('Download', 'simple-download-monitor') : __('Downloads', 'simple-download-monitor');
64
  $download_count_string = '<span class="sdm_post_count_number">' . $db_count . '</span><span class="sdm_post_count_string"> ' . $string . '</span>';
109
  }
110
 
111
  return $content;
112
+ }
sdm-shortcodes.php CHANGED
@@ -13,16 +13,16 @@ function sdm_register_shortcodes() {
13
  add_shortcode('sdm-download-counter', 'sdm_create_counter_shortcode'); // For counter shortcode (for backwards compatibility)
14
  add_shortcode('sdm_latest_downloads', 'sdm_show_latest_downloads'); // For showing X number of latest downloads
15
  add_shortcode('sdm-latest-downloads', 'sdm_show_latest_downloads'); // For showing X number of latest downloads(for backwards compatibility)
16
-
17
  add_shortcode('sdm_download_link', 'sdm_create_simple_download_link');
18
-
19
  add_shortcode('sdm_show_dl_from_category', 'sdm_handle_category_shortcode'); //For category shortcode
20
  add_shortcode('sdm_download_categories', 'sdm_download_categories_shortcode'); // Ajax file tree browser
21
-
22
  add_shortcode('sdm_download_categories_list', 'sdm_download_categories_list_shortcode');
 
23
  }
24
 
25
-
26
  /**
27
  * Process (sanitize) download button shortcode attributes:
28
  * - convert "id" to absolute integer
@@ -38,12 +38,10 @@ function sanitize_sdm_create_download_shortcode_atts($atts) {
38
  // See if user color option is selected
39
  $main_opts = get_option('sdm_downloads_options');
40
 
41
- if ( empty($atts['color']) ) {
42
  // No color provided by shortcode, read color from plugin settings.
43
- $atts['color']
44
- = isset($main_opts['download_button_color'])
45
- ? strtolower($main_opts['download_button_color']) // default values needs to be lowercased
46
- : 'green'
47
  ;
48
  }
49
 
@@ -53,18 +51,17 @@ function sanitize_sdm_create_download_shortcode_atts($atts) {
53
  return $atts;
54
  }
55
 
56
-
57
  // Create Download Shortcode
58
  function sdm_create_download_shortcode($atts) {
59
 
60
  $shortcode_atts = sanitize_sdm_create_download_shortcode_atts(
61
- shortcode_atts(array(
62
- 'id' => '',
63
- 'fancy' => '0',
64
- 'button_text' => __('Download Now!', 'simple-download-monitor'),
65
- 'new_window' => '',
66
- 'color' => '',
67
- ), $atts)
68
  );
69
 
70
  // Make shortcode attributes available in function local scope.
@@ -88,12 +85,12 @@ function sdm_create_download_shortcode($atts) {
88
  $download_button_code = '<a href="' . $download_url . '" class="sdm_download ' . $color . '" title="' . $item_title . '" target="' . $window_target . '">' . $button_text . '</a>';
89
 
90
  if ($cpt_is_password !== 'no') {//This is a password protected download so replace the download now button with password requirement
91
- $download_button_code = sdm_get_password_entry_form($id);
92
  }
93
  //End of download now button code generation
94
 
95
  $output = '';
96
- switch ( $fancy ) {
97
  case '1':
98
  include_once('includes/templates/fancy1/sdm-fancy-1.php');
99
  $output .= sdm_generate_fancy1_display_output($shortcode_atts);
@@ -112,15 +109,15 @@ function sdm_create_download_shortcode($atts) {
112
  return apply_filters('sdm_download_shortcode_output', $output, $atts);
113
  }
114
 
115
- function sdm_create_simple_download_link($atts){
116
  extract(shortcode_atts(array(
117
  'id' => '',
118
- ), $atts));
119
 
120
  if (empty($id)) {
121
  return '<p style="color: red;">' . __('Error! Please enter an ID value with this shortcode.', 'simple-download-monitor') . '</p>';
122
  }
123
-
124
  return WP_SIMPLE_DL_MONITOR_SITE_HOME_URL . '/?smd_process_download=1&download_id=' . $id;
125
  }
126
 
@@ -155,9 +152,9 @@ function sdm_handle_category_shortcode($args) {
155
  'button_text' => __('Download Now!', 'simple-download-monitor'),
156
  'new_window' => '',
157
  'orderby' => 'post_date',
158
- 'order' => 'DESC',
159
  'pagination' => '',
160
- ), $args));
161
 
162
  // Define vars
163
  $field = '';
@@ -187,17 +184,17 @@ function sdm_handle_category_shortcode($args) {
187
  }
188
 
189
  // For pagination
190
- $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
191
- if(isset($args['pagination'])){
192
- if(!is_numeric($args['pagination'])){
193
  return '<p style="color: red;">' . __('Error! You must enter a numeric number for the "pagination" parameter of the shortcode. Refer to the usage documentation.', 'simple-download-monitor') . '</p>';
194
  }
195
  $posts_per_page = $args['pagination'];
196
  } else {
197
  $posts_per_page = 9999;
198
  }
199
-
200
-
201
  // Query cpt's based on arguments above
202
  $get_posts = get_posts(array(
203
  'post_type' => 'sdm_downloads',
@@ -211,7 +208,7 @@ function sdm_handle_category_shortcode($args) {
211
  )
212
  ),
213
  'orderby' => $orderby,
214
- 'order' => $order,
215
  'paged' => $paged,
216
  ));
217
 
@@ -263,25 +260,25 @@ function sdm_handle_category_shortcode($args) {
263
  }
264
 
265
  // Pagination related
266
- if(isset($args['pagination'])){
267
  $posts_per_page = $args['pagination'];
268
  $count_sdm_posts = wp_count_posts('sdm_downloads');
269
- $published_sdm_posts = $count_sdm_posts->publish;
270
  $total_pages = ceil($published_sdm_posts / $posts_per_page);
271
-
272
  $big = 999999999; // Need an unlikely integer
273
- $pagination = paginate_links( array(
274
- 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
275
- 'format' => '',
276
- 'add_args' => '',
277
- 'current' => max( 1, get_query_var( 'paged' ) ),
278
- 'total' => $total_pages,
279
- 'prev_text' => '&larr;',
280
- 'next_text' => '&rarr;',
281
- ) );
282
- $output .= '<div class="sdm_pagination">'.$pagination.'</div>';
283
  }
284
-
285
  // Return results
286
  return apply_filters('sdm_category_download_items_shortcode_output', $output, $args, $get_posts);
287
  } // End else iterate cpt's
@@ -315,7 +312,6 @@ function sdm_download_categories_shortcode() {
315
  return '<div class="sdm_object_tree">' . custom_taxonomy_walker('sdm_categories') . '</div>';
316
  }
317
 
318
-
319
  /**
320
  * Return HTML list with SDM categories rendered according to $atts.
321
  * @param array $atts
@@ -337,17 +333,19 @@ function sdm_download_categories_list_walker($atts, $parent = 0) {
337
  ));
338
 
339
  // Return empty string, if no terms found.
340
- if ( empty($terms) ) { return ''; }
 
 
341
 
342
  // Produce list of download categories under $parent.
343
  $out = '<' . $list_tag . '>';
344
 
345
- foreach ( $terms as $term ) {
346
  $out .= '<li>'
347
  . '<a href="' . get_term_link($term) . '">' . $term->name . '</a>' // link
348
  . ( $count ? (' <span>(' . $term->count . ')</span>') : '') // count
349
  . ( $hierarchical ? sdm_download_categories_list_walker($atts, $term->term_id) : '' ) // subcategories
350
- . '</li>'
351
  ;
352
  }
353
 
@@ -356,7 +354,6 @@ function sdm_download_categories_list_walker($atts, $parent = 0) {
356
  return $out;
357
  }
358
 
359
-
360
  /**
361
  * Return output of `sdm_download_categories_list` shortcode.
362
  * @param array $attributes
@@ -365,18 +362,18 @@ function sdm_download_categories_list_walker($atts, $parent = 0) {
365
  function sdm_download_categories_list_shortcode($attributes) {
366
 
367
  $atts = shortcode_atts(
368
- array(
369
- 'class' => 'sdm-download-categories', // wrapper class
370
- 'empty' => '0', // show empty categories
371
- 'numbered' => '0', // use <ol> instead of <ul> to wrap the list
372
- 'count' => '0', // display count of items in every category
373
- 'hierarchical' => '1', // display subcategories as well
374
- ), $attributes
375
  );
376
 
377
  return
378
- '<div class="' . esc_attr($atts['class']) . '">'
379
- . sdm_download_categories_list_walker($atts)
380
- . '</div>'
381
  ;
382
  }
13
  add_shortcode('sdm-download-counter', 'sdm_create_counter_shortcode'); // For counter shortcode (for backwards compatibility)
14
  add_shortcode('sdm_latest_downloads', 'sdm_show_latest_downloads'); // For showing X number of latest downloads
15
  add_shortcode('sdm-latest-downloads', 'sdm_show_latest_downloads'); // For showing X number of latest downloads(for backwards compatibility)
16
+
17
  add_shortcode('sdm_download_link', 'sdm_create_simple_download_link');
18
+
19
  add_shortcode('sdm_show_dl_from_category', 'sdm_handle_category_shortcode'); //For category shortcode
20
  add_shortcode('sdm_download_categories', 'sdm_download_categories_shortcode'); // Ajax file tree browser
21
+
22
  add_shortcode('sdm_download_categories_list', 'sdm_download_categories_list_shortcode');
23
+ add_shortcode('sdm_search_form', 'sdm_search_form_shortcode');
24
  }
25
 
 
26
  /**
27
  * Process (sanitize) download button shortcode attributes:
28
  * - convert "id" to absolute integer
38
  // See if user color option is selected
39
  $main_opts = get_option('sdm_downloads_options');
40
 
41
+ if (empty($atts['color'])) {
42
  // No color provided by shortcode, read color from plugin settings.
43
+ $atts['color'] = isset($main_opts['download_button_color']) ? strtolower($main_opts['download_button_color']) // default values needs to be lowercased
44
+ : 'green'
 
 
45
  ;
46
  }
47
 
51
  return $atts;
52
  }
53
 
 
54
  // Create Download Shortcode
55
  function sdm_create_download_shortcode($atts) {
56
 
57
  $shortcode_atts = sanitize_sdm_create_download_shortcode_atts(
58
+ shortcode_atts(array(
59
+ 'id' => '',
60
+ 'fancy' => '0',
61
+ 'button_text' => __('Download Now!', 'simple-download-monitor'),
62
+ 'new_window' => '',
63
+ 'color' => '',
64
+ ), $atts)
65
  );
66
 
67
  // Make shortcode attributes available in function local scope.
85
  $download_button_code = '<a href="' . $download_url . '" class="sdm_download ' . $color . '" title="' . $item_title . '" target="' . $window_target . '">' . $button_text . '</a>';
86
 
87
  if ($cpt_is_password !== 'no') {//This is a password protected download so replace the download now button with password requirement
88
+ $download_button_code = sdm_get_password_entry_form($id, $atts);
89
  }
90
  //End of download now button code generation
91
 
92
  $output = '';
93
+ switch ($fancy) {
94
  case '1':
95
  include_once('includes/templates/fancy1/sdm-fancy-1.php');
96
  $output .= sdm_generate_fancy1_display_output($shortcode_atts);
109
  return apply_filters('sdm_download_shortcode_output', $output, $atts);
110
  }
111
 
112
+ function sdm_create_simple_download_link($atts) {
113
  extract(shortcode_atts(array(
114
  'id' => '',
115
+ ), $atts));
116
 
117
  if (empty($id)) {
118
  return '<p style="color: red;">' . __('Error! Please enter an ID value with this shortcode.', 'simple-download-monitor') . '</p>';
119
  }
120
+
121
  return WP_SIMPLE_DL_MONITOR_SITE_HOME_URL . '/?smd_process_download=1&download_id=' . $id;
122
  }
123
 
152
  'button_text' => __('Download Now!', 'simple-download-monitor'),
153
  'new_window' => '',
154
  'orderby' => 'post_date',
155
+ 'order' => 'DESC',
156
  'pagination' => '',
157
+ ), $args));
158
 
159
  // Define vars
160
  $field = '';
184
  }
185
 
186
  // For pagination
187
+ $paged = ( get_query_var('paged') ) ? absint(get_query_var('paged')) : 1;
188
+ if (isset($args['pagination'])) {
189
+ if (!is_numeric($args['pagination'])) {
190
  return '<p style="color: red;">' . __('Error! You must enter a numeric number for the "pagination" parameter of the shortcode. Refer to the usage documentation.', 'simple-download-monitor') . '</p>';
191
  }
192
  $posts_per_page = $args['pagination'];
193
  } else {
194
  $posts_per_page = 9999;
195
  }
196
+
197
+
198
  // Query cpt's based on arguments above
199
  $get_posts = get_posts(array(
200
  'post_type' => 'sdm_downloads',
208
  )
209
  ),
210
  'orderby' => $orderby,
211
+ 'order' => $order,
212
  'paged' => $paged,
213
  ));
214
 
260
  }
261
 
262
  // Pagination related
263
+ if (isset($args['pagination'])) {
264
  $posts_per_page = $args['pagination'];
265
  $count_sdm_posts = wp_count_posts('sdm_downloads');
266
+ $published_sdm_posts = $count_sdm_posts->publish;
267
  $total_pages = ceil($published_sdm_posts / $posts_per_page);
268
+
269
  $big = 999999999; // Need an unlikely integer
270
+ $pagination = paginate_links(array(
271
+ 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
272
+ 'format' => '',
273
+ 'add_args' => '',
274
+ 'current' => max(1, get_query_var('paged')),
275
+ 'total' => $total_pages,
276
+ 'prev_text' => '&larr;',
277
+ 'next_text' => '&rarr;',
278
+ ));
279
+ $output .= '<div class="sdm_pagination">' . $pagination . '</div>';
280
  }
281
+
282
  // Return results
283
  return apply_filters('sdm_category_download_items_shortcode_output', $output, $args, $get_posts);
284
  } // End else iterate cpt's
312
  return '<div class="sdm_object_tree">' . custom_taxonomy_walker('sdm_categories') . '</div>';
313
  }
314
 
 
315
  /**
316
  * Return HTML list with SDM categories rendered according to $atts.
317
  * @param array $atts
333
  ));
334
 
335
  // Return empty string, if no terms found.
336
+ if (empty($terms)) {
337
+ return '';
338
+ }
339
 
340
  // Produce list of download categories under $parent.
341
  $out = '<' . $list_tag . '>';
342
 
343
+ foreach ($terms as $term) {
344
  $out .= '<li>'
345
  . '<a href="' . get_term_link($term) . '">' . $term->name . '</a>' // link
346
  . ( $count ? (' <span>(' . $term->count . ')</span>') : '') // count
347
  . ( $hierarchical ? sdm_download_categories_list_walker($atts, $term->term_id) : '' ) // subcategories
348
+ . '</li>'
349
  ;
350
  }
351
 
354
  return $out;
355
  }
356
 
 
357
  /**
358
  * Return output of `sdm_download_categories_list` shortcode.
359
  * @param array $attributes
362
  function sdm_download_categories_list_shortcode($attributes) {
363
 
364
  $atts = shortcode_atts(
365
+ array(
366
+ 'class' => 'sdm-download-categories', // wrapper class
367
+ 'empty' => '0', // show empty categories
368
+ 'numbered' => '0', // use <ol> instead of <ul> to wrap the list
369
+ 'count' => '0', // display count of items in every category
370
+ 'hierarchical' => '1', // display subcategories as well
371
+ ), $attributes
372
  );
373
 
374
  return
375
+ '<div class="' . esc_attr($atts['class']) . '">'
376
+ . sdm_download_categories_list_walker($atts)
377
+ . '</div>'
378
  ;
379
  }