Simple Download Monitor - Version 3.7.5

Version Description

  • Added an option to configure "after download redirect" in the hidden downloads addon.
Download this release

Release Info

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

Code changes from version 3.7.4.2 to 3.7.5

includes/sdm-utility-functions.php CHANGED
@@ -232,7 +232,7 @@ function sdm_get_download_form_with_recaptcha($id, $args = array(), $class = '')
232
  //Check if Terms & Condition enabled
233
  $data .= sdm_get_checkbox_for_termsncond();
234
 
235
- $data .= '<a href="#" class="sdm_download_with_condition ' . $class . '">' . $button_text_string . '</a>';
236
  $data .= '</div>';
237
  $data .= '<input type="hidden" name="download_id" value="' . $id . '" />';
238
  $data .= '</form>';
@@ -281,7 +281,7 @@ function sdm_get_download_form_with_termsncond($id, $args = array(), $class = ''
281
  $data = '<form action="' . $action_url . '" method="post" class="sdm-download-form"'.$window_target.'>';
282
  $data .= sdm_get_checkbox_for_termsncond();
283
  $data .= '<div class="sdm-termscond-button">';
284
- $data .= '<a href="#" class="sdm_download_with_condition ' . $class . '">' . $button_text_string . '</a>';
285
  $data .= '</div>';
286
  $data .= '<input type="hidden" name="download_id" value="' . $id . '" />';
287
  $data .= '</form>';
232
  //Check if Terms & Condition enabled
233
  $data .= sdm_get_checkbox_for_termsncond();
234
 
235
+ $data .= '<a href="#" class="' . $class . ' sdm_download_with_condition">' . $button_text_string . '</a>';
236
  $data .= '</div>';
237
  $data .= '<input type="hidden" name="download_id" value="' . $id . '" />';
238
  $data .= '</form>';
281
  $data = '<form action="' . $action_url . '" method="post" class="sdm-download-form"'.$window_target.'>';
282
  $data .= sdm_get_checkbox_for_termsncond();
283
  $data .= '<div class="sdm-termscond-button">';
284
+ $data .= '<a href="#" class="' . $class . ' sdm_download_with_condition">' . $button_text_string . '</a>';
285
  $data .= '</div>';
286
  $data .= '<input type="hidden" name="download_id" value="' . $id . '" />';
287
  $data .= '</form>';
js/sdm_wp_scripts.js CHANGED
@@ -1,34 +1,47 @@
1
  // Simple Download Monitor frontend scripts
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  jQuery(document).ready(function ($) {
4
 
5
  // Populate all nested titles and links
6
  $('li.sdm_cat').each(function () {
7
 
8
- var $this = $(this);
9
- this_slug = $this.attr('id');
10
- this_id = $this.children('.sdm_cat_title').attr('id');
11
-
12
- // Run ajax
13
- $.post(
14
- sdm_ajax_script.ajaxurl,
15
- {
16
- action: 'sdm_pop_cats',
17
- cat_slug: this_slug,
18
- parent_id: this_id
19
- },
20
- function (response) {
21
-
22
- // Loop array returned from ajax function
23
- $.each(response.final_array, function (key, value) {
24
-
25
- // Populate each matched post title and permalink
26
- $this.children('.sdm_placeholder').append('<a href="' + value['permalink'] + '"><span class="sdm_post_title" style="cursor:pointer;">' + value['title'] + '</span></a>');
27
- });
28
-
29
- $this.children('span').append('<span style="margin-left:5px;" class="sdm_arrow">&#8616</span>');
30
- }
31
- );
32
  });
33
 
34
  // Hide results on page load
@@ -37,55 +50,55 @@ jQuery(document).ready(function ($) {
37
  // Slide toggle for each list item
38
  $('body').on('click', '.sdm_cat_title', function (e) {
39
 
40
- // If there is any html.. then we have more elements
41
- if ($(this).next().html() != '') {
42
 
43
- $(this).next().slideToggle(); // toggle div titles
44
- }
45
  });
46
 
47
  // Download buttons with terms or captcha has this class applied to it
48
  $('.sdm_download_with_condition').on('click', function (e) {
49
- e.preventDefault();
50
- $(this).closest('form').trigger('submit');
51
  });
52
 
53
  // Check if terms checkbox is enabled.
54
  if ($('.sdm-termscond-checkbox').length) {
55
 
56
- $.each($('.sdm-termscond-checkbox'), function () {
57
- if (!$(this).is(':checked')) {
58
- var cur = $(this).children(':checkbox');
59
- var btn = $(cur).closest('form').find('a.sdm_download,a.sdm_download_with_condition');
60
- $(btn).addClass('sdm_disabled_button');
61
- }
62
- });
63
-
64
- $.each($('.sdm-download-form'), function () {
65
- var form = $(this);
66
- form.on('submit', function () {
67
- if ($('.agree_termscond', form).is(':checked')) {
68
- $('.sdm-termscond-checkbox', form).removeClass('sdm_general_error_msg');
69
- return true;
70
- } else {
71
- $('.sdm-termscond-checkbox', form).addClass('sdm_general_error_msg');
72
- }
73
- return false;
74
- });
75
- });
76
-
77
- $.each($('.agree_termscond'), function () {
78
- var element = $(this);
79
- var form = element.closest('form');
80
- element.on('click', function () {
81
- if (element.is(':checked')) {
82
- $('.sdm_download_with_condition', form).removeClass('sdm_disabled_button');
83
- $('.sdm-termscond-checkbox', form).removeClass('sdm_general_error_msg');
84
- } else {
85
- $('.sdm_download_with_condition', form).addClass('sdm_disabled_button');
86
- $('.sdm-termscond-checkbox', form).addClass('sdm_general_error_msg');
87
- }
88
- });
89
- });
90
  }
91
  });
1
  // Simple Download Monitor frontend scripts
2
 
3
+ function sdm_is_ie() {
4
+
5
+ var ua = window.navigator.userAgent;
6
+ var msie = ua.indexOf("MSIE ");
7
+
8
+ if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
9
+ {
10
+ return true;
11
+ }
12
+
13
+ return false;
14
+ }
15
+
16
  jQuery(document).ready(function ($) {
17
 
18
  // Populate all nested titles and links
19
  $('li.sdm_cat').each(function () {
20
 
21
+ var $this = $(this);
22
+ this_slug = $this.attr('id');
23
+ this_id = $this.children('.sdm_cat_title').attr('id');
24
+
25
+ // Run ajax
26
+ $.post(
27
+ sdm_ajax_script.ajaxurl,
28
+ {
29
+ action: 'sdm_pop_cats',
30
+ cat_slug: this_slug,
31
+ parent_id: this_id
32
+ },
33
+ function (response) {
34
+
35
+ // Loop array returned from ajax function
36
+ $.each(response.final_array, function (key, value) {
37
+
38
+ // Populate each matched post title and permalink
39
+ $this.children('.sdm_placeholder').append('<a href="' + value['permalink'] + '"><span class="sdm_post_title" style="cursor:pointer;">' + value['title'] + '</span></a>');
40
+ });
41
+
42
+ $this.children('span').append('<span style="margin-left:5px;" class="sdm_arrow">&#8616</span>');
43
+ }
44
+ );
45
  });
46
 
47
  // Hide results on page load
50
  // Slide toggle for each list item
51
  $('body').on('click', '.sdm_cat_title', function (e) {
52
 
53
+ // If there is any html.. then we have more elements
54
+ if ($(this).next().html() != '') {
55
 
56
+ $(this).next().slideToggle(); // toggle div titles
57
+ }
58
  });
59
 
60
  // Download buttons with terms or captcha has this class applied to it
61
  $('.sdm_download_with_condition').on('click', function (e) {
62
+ e.preventDefault();
63
+ $(this).closest('form').trigger('submit');
64
  });
65
 
66
  // Check if terms checkbox is enabled.
67
  if ($('.sdm-termscond-checkbox').length) {
68
 
69
+ $.each($('.sdm-termscond-checkbox'), function () {
70
+ if (!$(this).is(':checked')) {
71
+ var cur = $(this).children(':checkbox');
72
+ var btn = $(cur).closest('form').find('a.sdm_download,a.sdm_download_with_condition');
73
+ $(btn).addClass('sdm_disabled_button');
74
+ }
75
+ });
76
+
77
+ $.each($('.sdm-download-form'), function () {
78
+ var form = $(this);
79
+ form.on('submit', function () {
80
+ if ($('.agree_termscond', form).is(':checked')) {
81
+ $('.sdm-termscond-checkbox', form).removeClass('sdm_general_error_msg');
82
+ return true;
83
+ } else {
84
+ $('.sdm-termscond-checkbox', form).addClass('sdm_general_error_msg');
85
+ }
86
+ return false;
87
+ });
88
+ });
89
+
90
+ $.each($('.agree_termscond'), function () {
91
+ var element = $(this);
92
+ var form = element.closest('form');
93
+ element.on('click', function () {
94
+ if (element.is(':checked')) {
95
+ $('.sdm_download_with_condition', form).removeClass('sdm_disabled_button');
96
+ $('.sdm-termscond-checkbox', form).removeClass('sdm_general_error_msg');
97
+ } else {
98
+ $('.sdm_download_with_condition', form).addClass('sdm_disabled_button');
99
+ $('.sdm-termscond-checkbox', form).addClass('sdm_general_error_msg');
100
+ }
101
+ });
102
+ });
103
  }
104
  });
main.php CHANGED
@@ -3,24 +3,23 @@
3
  * Plugin Name: Simple Download Monitor
4
  * Plugin URI: https://simple-download-monitor.com/
5
  * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
- * Version: 3.7.4.2
7
  * Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
8
  * Author URI: https://www.tipsandtricks-hq.com/development-center
9
  * License: GPL2
10
  * Text Domain: simple-download-monitor
11
  * Domain Path: /languages/
12
  */
13
-
14
- if (!defined('ABSPATH')) {
15
  exit;
16
  }
17
 
18
- define('WP_SIMPLE_DL_MONITOR_VERSION', '3.7.4.2');
19
- define('WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname(plugin_basename(__FILE__)));
20
- define('WP_SIMPLE_DL_MONITOR_URL', plugins_url('', __FILE__));
21
- define('WP_SIMPLE_DL_MONITOR_PATH', plugin_dir_path(__FILE__));
22
- define('WP_SIMPLE_DL_MONITOR_SITE_HOME_URL', home_url());
23
- define('WP_SDM_LOG_FILE', WP_SIMPLE_DL_MONITOR_PATH . 'sdm-debug-log.txt');
24
 
25
  global $sdm_db_version;
26
  $sdm_db_version = '1.2';
@@ -39,7 +38,7 @@ include_once('sdm-shortcodes.php');
39
  include_once('sdm-post-type-content-handler.php');
40
 
41
  //Activation hook handler
42
- register_activation_hook(__FILE__, 'sdm_install_db_table');
43
 
44
  function sdm_install_db_table() {
45
 
@@ -60,9 +59,9 @@ function sdm_install_db_table() {
60
  );';
61
 
62
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
63
- dbDelta($sql);
64
 
65
- update_option('sdm_db_version', $sdm_db_version);
66
 
67
  //Register the post type so you can flush the rewrite rules
68
  sdm_register_post_type();
@@ -74,11 +73,11 @@ function sdm_install_db_table() {
74
  /*
75
  * * Handle Plugins loaded tasks
76
  */
77
- add_action('plugins_loaded', 'sdm_plugins_loaded_tasks');
78
 
79
  function sdm_plugins_loaded_tasks() {
80
  //Load language
81
- load_plugin_textdomain('simple-download-monitor', false, dirname(plugin_basename(__FILE__)) . '/languages/');
82
 
83
  //Handle db upgrade stuff
84
  sdm_db_update_check();
@@ -87,32 +86,32 @@ function sdm_plugins_loaded_tasks() {
87
  /*
88
  * * Handle Generic Init tasks
89
  */
90
- add_action('init', 'sdm_init_time_tasks');
91
- add_action('admin_init', 'sdm_admin_init_time_tasks');
92
 
93
  function sdm_init_time_tasks() {
94
  //Handle download request if any
95
  handle_sdm_download_via_direct_post();
96
- if (is_admin()) {
97
  //Register Google Charts library
98
- wp_register_script('sdm_google_charts', 'https://www.gstatic.com/charts/loader.js', array(), null, true);
99
- wp_register_style('sdm_jquery_ui_style', WP_SIMPLE_DL_MONITOR_URL . '/css/jquery.ui.min.css', array(), null, 'all');
100
  }
101
  }
102
 
103
  function sdm_admin_init_time_tasks() {
104
  //Register ajax handlers
105
- add_action('wp_ajax_sdm_reset_log', 'sdm_reset_log_handler');
106
- add_action('wp_ajax_sdm_delete_data', 'sdm_delete_data_handler');
107
 
108
- if (is_admin()) {
109
- if (user_can(wp_get_current_user(), 'administrator')) {
110
  // user is an admin
111
- if (isset($_GET['sdm-action'])) {
112
- if ($_GET['sdm-action'] === 'view_log') {
113
- $logfile = fopen(WP_SDM_LOG_FILE, 'rb');
114
- header('Content-Type: text/plain');
115
- fpassthru($logfile);
116
  die;
117
  }
118
  }
@@ -127,31 +126,31 @@ function sdm_reset_log_handler() {
127
  }
128
 
129
  function sdm_delete_data_handler() {
130
- if (!check_ajax_referer('sdm_delete_data', 'nonce', false)) {
131
  //nonce check failed
132
- wp_die(0);
133
  }
134
  global $wpdb;
135
  //let's find and delete smd_download posts and meta
136
- $posts = $wpdb->get_results('SELECT id FROM ' . $wpdb->prefix . 'posts WHERE post_type="sdm_downloads"', ARRAY_A);
137
- if (!is_null($posts)) {
138
- foreach ($posts as $post) {
139
- wp_delete_post($post['id'], true);
140
  }
141
  }
142
  //let's delete options
143
- delete_option('sdm_downloads_options');
144
- delete_option('sdm_db_version');
145
  //remove post type and taxonomies
146
- unregister_post_type('sdm_downloads');
147
- unregister_taxonomy('sdm_categories');
148
- unregister_taxonomy('sdm_tags');
149
  //let's delete sdm_downloads table
150
- $wpdb->query("DROP TABLE " . $wpdb->prefix . "sdm_downloads");
151
  //deactivate plugin
152
- deactivate_plugins(plugin_basename(__FILE__));
153
  //flush rewrite rules
154
- flush_rewrite_rules(false);
155
  echo '1';
156
  wp_die();
157
  }
@@ -161,10 +160,10 @@ function sdm_delete_data_handler() {
161
  */
162
 
163
  function sdm_db_update_check() {
164
- if (is_admin()) {//Check if DB needs to be upgraded
165
  global $sdm_db_version;
166
- $inst_db_version = get_option('sdm_db_version');
167
- if ($inst_db_version != $sdm_db_version) {
168
  sdm_install_db_table();
169
  }
170
  }
@@ -173,15 +172,15 @@ function sdm_db_update_check() {
173
  /*
174
  * * Add a 'Settings' link to plugins list page
175
  */
176
- add_filter('plugin_action_links', 'sdm_settings_link', 10, 2);
177
 
178
- function sdm_settings_link($links, $file) {
179
  static $this_plugin;
180
- if (!$this_plugin)
181
- $this_plugin = plugin_basename(__FILE__);
182
- if ($file == $this_plugin) {
183
- $settings_link = '<a href="edit.php?post_type=sdm_downloads&page=sdm-settings" title="SDM Settings Page">' . __("Settings", 'simple-download-monitor') . '</a>';
184
- array_unshift($links, $settings_link);
185
  }
186
  return $links;
187
  }
@@ -191,48 +190,47 @@ class simpleDownloadManager {
191
 
192
  public function __construct() {
193
 
194
- add_action('init', 'sdm_register_post_type'); // Create 'sdm_downloads' custom post type
195
- add_action('init', 'sdm_create_taxonomies'); // Register 'tags' and 'categories' taxonomies
196
- add_action('init', 'sdm_register_shortcodes'); //Register the shortcodes
197
- add_action('wp_enqueue_scripts', array($this, 'sdm_frontend_scripts')); // Register frontend scripts
198
 
199
- if (is_admin()) {
200
- add_action('admin_menu', array($this, 'sdm_create_menu_pages')); // Create admin pages
201
- add_action('add_meta_boxes', array($this, 'sdm_create_upload_metabox')); // Create metaboxes
202
 
203
- add_action('save_post', array($this, 'sdm_save_description_meta_data')); // Save 'description' metabox
204
- add_action('save_post', array($this, 'sdm_save_upload_meta_data')); // Save 'upload file' metabox
205
- add_action('save_post', array($this, 'sdm_save_dispatch_meta_data')); // Save 'dispatch' metabox
206
- add_action('save_post', array($this, 'sdm_save_misc_properties_meta_data')); // Save 'misc properties/settings' metabox
207
- add_action('save_post', array($this, 'sdm_save_thumbnail_meta_data')); // Save 'thumbnail' metabox
208
- add_action('save_post', array($this, 'sdm_save_statistics_meta_data')); // Save 'statistics' metabox
209
- add_action('save_post', array($this, 'sdm_save_other_details_meta_data')); // Save 'other details' metabox
210
 
211
- add_action('admin_enqueue_scripts', array($this, 'sdm_admin_scripts')); // Register admin scripts
212
- add_action('admin_print_styles', array($this, 'sdm_admin_styles')); // Register admin styles
213
 
214
- add_action('admin_init', array($this, 'sdm_register_options')); // Register admin options
215
  //add_filter('post_row_actions', array($this, 'sdm_remove_view_link_cpt'), 10, 2); // Remove 'View' link in all downloads list view
216
-
217
- add_filter('page_row_actions', array($this, 'sdm_add_clone_record_btn'), 10, 2); // Add 'Clone' link in all downloads list view
218
- add_filter('post_row_actions', array($this, 'sdm_add_clone_record_btn'), 10, 2); // Add 'Clone' link in all downloads list view
219
-
220
- add_action('admin_action_sdm_clone_post', array($this, 'sdm_action_clone_post'));
221
  }
222
-
223
  }
224
-
225
  public function sdm_admin_scripts() {
226
 
227
  global $current_screen, $post;
228
 
229
- if (is_admin() && $current_screen->post_type == 'sdm_downloads' && $current_screen->base == 'post') {
230
 
231
  // These scripts are needed for the media upload thickbox
232
- wp_enqueue_script('media-upload');
233
- wp_enqueue_script('thickbox');
234
- wp_register_script('sdm-upload', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_admin_scripts.js', array('jquery', 'media-upload', 'thickbox'), WP_SIMPLE_DL_MONITOR_VERSION);
235
- wp_enqueue_script('sdm-upload');
236
 
237
  // Pass postID for thumbnail deletion
238
  ?>
@@ -242,58 +240,58 @@ class simpleDownloadManager {
242
  <?php
243
  // Localize langauge strings used in js file
244
  $sdmTranslations = array(
245
- 'select_file' => __('Select File', 'simple-download-monitor'),
246
- 'select_thumbnail' => __('Select Thumbnail', 'simple-download-monitor'),
247
- 'insert' => __('Insert', 'simple-download-monitor'),
248
- 'image_removed' => __('Image Successfully Removed', 'simple-download-monitor'),
249
- 'ajax_error' => __('Error with AJAX', 'simple-download-monitor')
250
  );
251
- wp_localize_script('sdm-upload', 'sdm_translations', $sdmTranslations);
252
  }
253
 
254
  // Pass admin ajax url
255
  ?>
256
  <script type="text/javascript">
257
- var sdm_admin_ajax_url = {sdm_admin_ajax_url: '<?php echo admin_url('admin-ajax.php?action=ajax'); ?>'};
258
  var sdm_plugin_url = '<?php echo plugins_url(); ?>';
259
  var tinymce_langs = {
260
- select_download_item: '<?php _e('Please select a Download Item:', 'simple-download-monitor') ?>',
261
- download_title: '<?php _e('Download Title', 'simple-download-monitor') ?>',
262
- include_fancy: '<?php _e('Include Fancy Box', 'simple-download-monitor') ?>',
263
- open_new_window: '<?php _e('Open New Window', 'simple-download-monitor') ?>',
264
- button_color: '<?php _e('Button Color', 'simple-download-monitor'); ?>',
265
- insert_shortcode: '<?php _e('Insert SDM Shortcode', 'simple-download-monitor') ?>'
266
  };
267
- var sdm_button_colors = <?php echo wp_json_encode(sdm_get_download_button_colors()); ?>;
268
  </script>
269
  <?php
270
  }
271
 
272
  public function sdm_frontend_scripts() {
273
  //Use this function to enqueue fron-end js scripts.
274
- wp_enqueue_style('sdm-styles', WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_wp_styles.css');
275
- wp_register_script('sdm-scripts', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_wp_scripts.js', array('jquery'));
276
- wp_enqueue_script('sdm-scripts');
277
-
278
- //Check if reCAPTCHA is enabled.
279
- $main_advanced_opts = get_option('sdm_advanced_options');
280
- $recaptcha_enable = isset($main_advanced_opts['recaptcha_enable']) ? true : false;
281
- if ($recaptcha_enable) {
282
- wp_register_script('sdm-recaptcha-scripts-js', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_g_recaptcha.js', array(), true);
283
- wp_localize_script("sdm-recaptcha-scripts-js", "sdm_recaptcha_opt", array("site_key" => $main_advanced_opts['recaptcha_site_key']));
284
- wp_register_script('sdm-recaptcha-scripts-lib', "//www.google.com/recaptcha/api.js?hl=".get_locale()."&onload=sdm_reCaptcha&render=explicit", array(), false);
285
- wp_enqueue_script('sdm-recaptcha-scripts-js');
286
- wp_enqueue_script('sdm-recaptcha-scripts-lib');
287
- }
288
 
289
  // Localize ajax script for frontend
290
- wp_localize_script('sdm-scripts', 'sdm_ajax_script', array('ajaxurl' => admin_url('admin-ajax.php')));
291
  }
292
 
293
  public function sdm_admin_styles() {
294
 
295
- wp_enqueue_style('thickbox'); // Needed for media upload thickbox
296
- wp_enqueue_style('sdm_admin_styles', WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_admin_styles.css', array(), WP_SIMPLE_DL_MONITOR_VERSION); // Needed for media upload thickbox
297
  }
298
 
299
  public function sdm_create_menu_pages() {
@@ -304,106 +302,108 @@ class simpleDownloadManager {
304
  public function sdm_create_upload_metabox() {
305
 
306
  //***** Create metaboxes for the custom post type
307
- add_meta_box('sdm_description_meta_box', __('Description', 'simple-download-monitor'), array($this, 'display_sdm_description_meta_box'), 'sdm_downloads', 'normal', 'default');
308
- add_meta_box('sdm_upload_meta_box', __('Downloadable File (Visitors will download this item)', 'simple-download-monitor'), array($this, 'display_sdm_upload_meta_box'), 'sdm_downloads', 'normal', 'default');
309
- add_meta_box('sdm_dispatch_meta_box', __('PHP Dispatch or Redirect', 'simple-download-monitor'), array($this, 'display_sdm_dispatch_meta_box'), 'sdm_downloads', 'normal', 'default');
310
- add_meta_box('sdm_misc_properties_meta_box', __('Miscellaneous Download Properties', 'simple-download-monitor'), array($this, 'display_sdm_misc_properties_meta_box'), 'sdm_downloads', 'normal', 'default');// Meta box for misc properies/settings
311
- add_meta_box('sdm_thumbnail_meta_box', __('File Thumbnail (Optional)', 'simple-download-monitor'), array($this, 'display_sdm_thumbnail_meta_box'), 'sdm_downloads', 'normal', 'default');
312
- add_meta_box('sdm_stats_meta_box', __('Statistics', 'simple-download-monitor'), array($this, 'display_sdm_stats_meta_box'), 'sdm_downloads', 'normal', 'default');
313
- 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');
314
- add_meta_box('sdm_shortcode_meta_box', __('Shortcodes', 'simple-download-monitor'), array($this, 'display_sdm_shortcode_meta_box'), 'sdm_downloads', 'normal', 'default');
315
- }
316
-
317
- public function display_sdm_description_meta_box($post) { // Description metabox
318
- _e('Add a description for this download item.', 'simple-download-monitor');
 
319
  echo '<br /><br />';
320
 
321
- $old_description = get_post_meta($post->ID, 'sdm_description', true);
322
- $sdm_description_field = array('textarea_name' => 'sdm_description');
323
- wp_editor($old_description, "sdm_description_editor_content", $sdm_description_field);
324
-
325
- wp_nonce_field('sdm_description_box_nonce', 'sdm_description_box_nonce_check');
326
  }
327
 
328
- public function display_sdm_upload_meta_box($post) { // File Upload metabox
329
- $old_upload = get_post_meta($post->ID, 'sdm_upload', true);
330
- $old_value = isset($old_upload) ? $old_upload : '';
331
 
332
- _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');
333
  echo '<br /><br />';
334
 
335
  echo '<div class="sdm-download-edit-file-url-section">';
336
- echo '<input id="sdm_upload" type="text" size="100" name="sdm_upload" value="' . esc_url($old_value) . '" placeholder="http://..." />';
337
  echo '</div>';
338
 
339
  echo '<br />';
340
- echo '<input id="upload_image_button" type="button" class="button-primary" value="' . __('Select File', 'simple-download-monitor') . '" />';
341
 
342
  echo '<br /><br />';
343
- _e('Steps to upload a file or choose one from your media library:', 'simple-download-monitor');
344
  echo '<ol>';
345
- echo '<li>' . __('Hit the "Select File" button.', 'simple-download-monitor') . '</li>';
346
- echo '<li>' . __('Upload a new file or choose an existing one from your media library.', 'simple-download-monitor') . '</li>';
347
- echo '<li>' . __('Click the "Insert" button, this will populate the uploaded file\'s URL in the above text field.', 'simple-download-monitor') . '</li>';
348
  echo '</ol>';
349
 
350
- wp_nonce_field('sdm_upload_box_nonce', 'sdm_upload_box_nonce_check');
351
  }
352
 
353
- public function display_sdm_dispatch_meta_box($post) {
354
- $dispatch = get_post_meta($post->ID, 'sdm_item_dispatch', true);
355
 
356
- if ($dispatch === '') {
357
  // No value yet (either new item or saved with older version of plugin)
358
  $screen = get_current_screen();
359
 
360
- if ($screen->action === 'add') {
361
  // New item: set default value as per plugin settings.
362
- $main_opts = get_option('sdm_downloads_options');
363
- $dispatch = isset($main_opts['general_default_dispatch_value']) && $main_opts['general_default_dispatch_value'];
364
  }
365
  }
366
 
367
- echo '<input id="sdm_item_dispatch" type="checkbox" name="sdm_item_dispatch" value="yes"' . checked(true, $dispatch, false) . ' />';
368
- echo '<label for="sdm_item_dispatch">' . __('Dispatch the file via PHP directly instead of redirecting to it. PHP Dispatching keeps the download URL hidden. Dispatching works only for local files (files that you uploaded to this site via this plugin or media library).', 'simple-download-monitor') . '</label>';
369
 
370
- wp_nonce_field('sdm_dispatch_box_nonce', 'sdm_dispatch_box_nonce_check');
371
  }
 
372
  // Open Download in new window
373
- public function display_sdm_misc_properties_meta_box($post) {
374
-
375
- //Check the open in new window value
376
- $new_window = get_post_meta($post->ID, 'sdm_item_new_window', true);
377
- if ($new_window === '') {
378
  // No value yet (either new item or saved with older version of plugin)
379
  $screen = get_current_screen();
380
- if ($screen->action === 'add') {
381
  //New item: we can set a default value as per plugin settings. If a general settings is introduced at a later stage.
382
- //Does nothing at the moment.
383
  }
384
  }
385
-
386
- echo '<p> <input id="sdm_item_new_window" type="checkbox" name="sdm_item_new_window" value="yes"' . checked(true, $new_window, false) . ' />';
387
- echo '<label for="sdm_item_new_window">' . __('Open download in a new window.', 'simple-download-monitor') . '</label> </p>';
388
-
389
- wp_nonce_field('sdm_misc_properties_box_nonce', 'sdm_misc_properties_box_nonce_check');
390
  }
391
 
392
- public function display_sdm_thumbnail_meta_box($post) { // Thumbnail upload metabox
393
- $old_thumbnail = get_post_meta($post->ID, 'sdm_upload_thumbnail', true);
394
- $old_value = isset($old_thumbnail) ? $old_thumbnail : '';
395
- _e('Manually enter a valid URL, or click "Select Image" to upload (or choose) the file thumbnail image.', 'simple-download-monitor');
396
  ?>
397
  <br /><br />
398
- <input id="sdm_upload_thumbnail" type="text" size="100" name="sdm_upload_thumbnail" value="<?php echo esc_url($old_value); ?>" placeholder="http://..." />
399
  <br /><br />
400
- <input id="upload_thumbnail_button" type="button" class="button-primary" value="<?php _e('Select Image', 'simple-download-monitor'); ?>" />
401
- <input id="remove_thumbnail_button" type="button" class="button" value="<?php _e('Remove Image', 'simple-download-monitor'); ?>" />
402
  <br /><br />
403
 
404
  <span id="sdm_admin_thumb_preview">
405
  <?php
406
- if (!empty($old_value)) {
407
  ?><img id="sdm_thumbnail_image" src="<?php echo $old_value; ?>" style="max-width:200px;" />
408
  <?php
409
  }
@@ -412,230 +412,229 @@ class simpleDownloadManager {
412
 
413
  <?php
414
  echo '<p class="description">';
415
- _e('This thumbnail image will be used to create a fancy file download box if you want to use it.', 'simple-download-monitor');
416
  echo '</p>';
417
 
418
- wp_nonce_field('sdm_thumbnail_box_nonce', 'sdm_thumbnail_box_nonce_check');
419
  }
420
 
421
- public function display_sdm_stats_meta_box($post) { //Stats metabox
422
- $old_count = get_post_meta($post->ID, 'sdm_count_offset', true);
423
- $value = isset($old_count) && $old_count != '' ? $old_count : '0';
424
 
425
  // Get checkbox for "disable download logging"
426
- $no_logs = get_post_meta($post->ID, 'sdm_item_no_log', true);
427
- $checked = isset($no_logs) && $no_logs === 'on' ? 'checked="checked"' : '';
428
 
429
- _e('These are the statistics for this download item.', 'simple-download-monitor');
430
  echo '<br /><br />';
431
 
432
  global $wpdb;
433
- $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post->ID));
434
 
435
  echo '<div class="sdm-download-edit-dl-count">';
436
- _e('Number of Downloads:', 'simple-download-monitor');
437
  echo ' <strong>' . $wpdb->num_rows . '</strong>';
438
  echo '</div>';
439
 
440
  echo '<div class="sdm-download-edit-offset-count">';
441
- _e('Offset Count: ', 'simple-download-monitor');
442
  echo '<br />';
443
- echo ' <input type="text" size="10" name="sdm_count_offset" value="' . esc_attr($value) . '" />';
444
- 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>';
445
  echo '</div>';
446
 
447
  echo '<br />';
448
  echo '<div class="sdm-download-edit-disable-logging">';
449
  echo '<input type="checkbox" name="sdm_item_no_log" ' . $checked . ' />';
450
  echo '<span style="margin-left: 5px;"></span>';
451
- _e('Disable download logging for this item.', 'simple-download-monitor');
452
  echo '</div>';
453
 
454
- wp_nonce_field('sdm_count_offset_nonce', 'sdm_count_offset_nonce_check');
455
  }
456
 
457
- public function display_sdm_other_details_meta_box($post) { //Other details metabox
458
-
459
- $show_date_fd = get_post_meta($post->ID, 'sdm_item_show_date_fd', true);
460
- $sdm_item_show_file_size_fd = get_post_meta($post->ID, 'sdm_item_show_file_size_fd', true);
461
- $sdm_item_show_item_version_fd = get_post_meta($post->ID, 'sdm_item_show_item_version_fd', true);
 
 
462
 
463
- $file_size = get_post_meta($post->ID, 'sdm_item_file_size', true);
464
- $file_size = isset($file_size) ? $file_size : '';
 
 
 
465
 
466
- $version = get_post_meta($post->ID, 'sdm_item_version', true);
467
- $version = isset($version) ? $version : '';
468
-
469
- $download_button_text = get_post_meta($post->ID, 'sdm_download_button_text', true);
470
- $download_button_text = isset($download_button_text) ? $download_button_text : '';
471
-
472
  echo '<div class="sdm-download-edit-filesize">';
473
- echo '<strong>'.__('File Size: ', 'simple-download-monitor').'</strong>';
474
  echo '<br />';
475
- echo ' <input type="text" name="sdm_item_file_size" value="' . esc_attr($file_size) . '" size="20" />';
476
- echo '<p class="description">' . __('Enter the size of this file (example value: 2.15 MB).', 'simple-download-monitor') . '</p>';
477
- echo '<div class="sdm-download-edit-show-file-size"> <input id="sdm_item_show_file_size_fd" type="checkbox" name="sdm_item_show_file_size_fd" value="yes"' . checked(true, $sdm_item_show_file_size_fd, false) . ' />';
478
- echo '<label for="sdm_item_show_file_size_fd">' . __('Show file size in fancy display.', 'simple-download-monitor') . '</label> </div>';
479
- echo '</div>';
480
- echo '<hr />';
481
 
482
  echo '<div class="sdm-download-edit-version">';
483
- echo '<strong>'.__('Version: ', 'simple-download-monitor').'</strong>';
484
  echo '<br />';
485
- echo ' <input type="text" name="sdm_item_version" value="' . esc_attr($version) . '" size="20" />';
486
- echo '<p class="description">' . __('Enter the version number for this item if any (example value: v2.5.10).', 'simple-download-monitor') . '</p>';
487
- echo '<div class="sdm-download-edit-show-item-version"> <input id="sdm_item_show_item_version_fd" type="checkbox" name="sdm_item_show_item_version_fd" value="yes"' . checked(true, $sdm_item_show_item_version_fd, false) . ' />';
488
- echo '<label for="sdm_item_show_item_version_fd">' . __('Show version number in fancy display.', 'simple-download-monitor') . '</label> </div>';
489
  echo '</div>';
490
- echo '<hr />';
491
-
492
- echo '<div class="sdm-download-edit-show-publish-date">';
493
- echo '<strong>'.__('Publish Date: ', 'simple-download-monitor').'</strong>';
494
- echo '<br /> <input id="sdm_item_show_date_fd" type="checkbox" name="sdm_item_show_date_fd" value="yes"' . checked(true, $show_date_fd, false) . ' />';
495
- echo '<label for="sdm_item_show_date_fd">' . __('Show download published date in fancy display.', 'simple-download-monitor') . '</label>';
496
- echo '</div>';
497
- echo '<hr />';
498
-
499
- echo '<div class="sdm-download-edit-button-text">';
500
- echo '<strong>'.__('Download Button Text: ', 'simple-download-monitor').'</strong>';
501
- echo '<br />';
502
- echo "<input id='sdm-download-button-text' type='text' name='sdm_download_button_text' value='{$download_button_text}' />";
503
- echo '<p class="description">' . __('You can use this field to customize the download now button text of this item.', 'simple-download-monitor') . '</p>';
504
-
505
- wp_nonce_field('sdm_other_details_nonce', 'sdm_other_details_nonce_check');
506
- }
507
-
508
- public function display_sdm_shortcode_meta_box($post) { //Shortcode metabox
509
- _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');
 
510
  echo '<br />';
511
  $shortcode_text = '[sdm_download id="' . $post->ID . '" fancy="0"]';
512
  echo "<input type='text' class='code' onfocus='this.select();' readonly='readonly' value='" . $shortcode_text . "' size='40'>";
513
  echo "<br /><br />";
514
 
515
- _e('The following shortcode can be used to show a download counter for this item.', 'simple-download-monitor');
516
  echo '<br />';
517
  $shortcode_text = '[sdm_download_counter id="' . $post->ID . '"]';
518
  echo "<input type='text' class='code' onfocus='this.select();' readonly='readonly' value='" . $shortcode_text . "' size='40'>";
519
 
520
  echo '<br /><br />';
521
- _e('Read the full shortcode usage documentation <a href="https://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin" target="_blank">here</a>.', 'simple-download-monitor');
522
  }
523
 
524
- public function sdm_save_description_meta_data($post_id) { // Save Description metabox
525
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
526
  return;
527
  }
528
- if (!isset($_POST['sdm_description_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_description_box_nonce_check'], 'sdm_description_box_nonce')){
529
  return;
530
  }
531
- if (isset($_POST['sdm_description'])) {
532
- update_post_meta($post_id, 'sdm_description', wp_kses_post($_POST['sdm_description']));
533
  }
534
  }
535
 
536
- public function sdm_save_upload_meta_data($post_id) { // Save File Upload metabox
537
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
538
  return;
539
- if (!isset($_POST['sdm_upload_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_upload_box_nonce_check'], 'sdm_upload_box_nonce'))
540
  return;
541
 
542
- if (isset($_POST['sdm_upload'])) {
543
- update_post_meta($post_id, 'sdm_upload', sanitize_text_field($_POST['sdm_upload']));
544
  }
545
  }
546
 
547
- public function sdm_save_dispatch_meta_data($post_id) { // Save "Dispatch or Redirect" metabox
548
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
549
  return;
550
  }
551
- if (!isset($_POST['sdm_dispatch_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_dispatch_box_nonce_check'], 'sdm_dispatch_box_nonce')) {
552
  return;
553
  }
554
  // Get POST-ed data as boolean value
555
- $value = filter_input(INPUT_POST, 'sdm_item_dispatch', FILTER_VALIDATE_BOOLEAN);
556
- update_post_meta($post_id, 'sdm_item_dispatch', $value);
557
  }
558
-
559
- public function sdm_save_misc_properties_meta_data($post_id) {
560
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
561
  return;
562
  }
563
- if (!isset($_POST['sdm_misc_properties_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_misc_properties_box_nonce_check'], 'sdm_misc_properties_box_nonce')) {
564
  return;
565
  }
566
  // Get POST-ed data as boolean value
567
- $new_window_open = filter_input(INPUT_POST, 'sdm_item_new_window', FILTER_VALIDATE_BOOLEAN);
568
 
569
- update_post_meta($post_id, 'sdm_item_new_window', $new_window_open);
570
  }
571
 
572
- public function sdm_save_thumbnail_meta_data($post_id) { // Save Thumbnail Upload metabox
573
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
574
  return;
575
  }
576
- if (!isset($_POST['sdm_thumbnail_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_thumbnail_box_nonce_check'], 'sdm_thumbnail_box_nonce')){
577
  return;
578
  }
579
- if (isset($_POST['sdm_upload_thumbnail'])) {
580
- update_post_meta($post_id, 'sdm_upload_thumbnail', sanitize_text_field($_POST['sdm_upload_thumbnail']));
581
  }
582
  }
583
 
584
- public function sdm_save_statistics_meta_data($post_id) { // Save Statistics Upload metabox
585
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
586
  return;
587
  }
588
- if (!isset($_POST['sdm_count_offset_nonce_check']) || !wp_verify_nonce($_POST['sdm_count_offset_nonce_check'], 'sdm_count_offset_nonce')){
589
  return;
590
  }
591
- if (isset($_POST['sdm_count_offset']) && is_numeric($_POST['sdm_count_offset'])) {
592
- update_post_meta($post_id, 'sdm_count_offset', intval($_POST['sdm_count_offset']));
593
  }
594
 
595
  // Checkbox for disabling download logging for this item
596
- if (isset($_POST['sdm_item_no_log'])) {
597
- update_post_meta($post_id, 'sdm_item_no_log', sanitize_text_field($_POST['sdm_item_no_log']));
598
  } else {
599
- delete_post_meta($post_id, 'sdm_item_no_log');
600
  }
601
  }
602
 
603
- public function sdm_save_other_details_meta_data($post_id) { // Save Statistics Upload metabox
604
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
605
  return;
606
  }
607
- if (!isset($_POST['sdm_other_details_nonce_check']) || !wp_verify_nonce($_POST['sdm_other_details_nonce_check'], 'sdm_other_details_nonce')) {
608
  return;
609
  }
610
 
611
- $show_date_fd = filter_input(INPUT_POST, 'sdm_item_show_date_fd', FILTER_VALIDATE_BOOLEAN);
612
- update_post_meta($post_id, 'sdm_item_show_date_fd', $show_date_fd);
 
 
 
613
 
614
- $sdm_item_show_file_size_fd = filter_input(INPUT_POST, 'sdm_item_show_file_size_fd', FILTER_VALIDATE_BOOLEAN);
615
- update_post_meta($post_id, 'sdm_item_show_file_size_fd', $sdm_item_show_file_size_fd);
 
 
 
 
616
 
617
- $sdm_item_show_item_version_fd = filter_input(INPUT_POST, 'sdm_item_show_item_version_fd', FILTER_VALIDATE_BOOLEAN);
618
- update_post_meta($post_id, 'sdm_item_show_item_version_fd', $sdm_item_show_item_version_fd);
619
-
620
- if (isset($_POST['sdm_item_file_size'])) {
621
- update_post_meta($post_id, 'sdm_item_file_size', sanitize_text_field($_POST['sdm_item_file_size']));
622
  }
623
 
624
- if (isset($_POST['sdm_item_version'])) {
625
- update_post_meta($post_id, 'sdm_item_version', sanitize_text_field($_POST['sdm_item_version']));
626
  }
627
-
628
- if (isset($_POST['sdm_download_button_text'])) {
629
- update_post_meta($post_id, 'sdm_download_button_text', sanitize_text_field($_POST['sdm_download_button_text']));
630
- }
631
-
632
  }
633
 
634
- public function sdm_remove_view_link_cpt($action, $post) {
635
 
636
  // Only execute on SDM CPT posts page
637
- if ($post->post_type == 'sdm_downloads') {
638
- unset($action['view']);
639
  }
640
 
641
  return $action;
@@ -644,345 +643,343 @@ class simpleDownloadManager {
644
  public function sdm_register_options() {
645
 
646
  //Register the main setting
647
- register_setting('sdm_downloads_options', 'sdm_downloads_options');
 
 
 
 
648
 
649
- /*****************************/
650
- /* General Settings Section */
651
- /*****************************/
652
-
653
  //Add all the settings section that will go under the main settings
654
- add_settings_section('general_options', __('General Options', 'simple-download-monitor'), array($this, 'general_options_cb'), 'general_options_section');
655
- add_settings_section('admin_options', __('Admin Options', 'simple-download-monitor'), array($this, 'admin_options_cb'), 'admin_options_section');
656
-
657
- add_settings_section('sdm_colors', __('Colors', 'simple-download-monitor'), array($this, 'sdm_colors_cb'), 'sdm_colors_section');
658
- add_settings_section('sdm_debug', __('Debug', 'simple-download-monitor'), array($this, 'sdm_debug_cb'), 'sdm_debug_section');
659
- add_settings_section('sdm_deldata', __('Delete Plugin Data', 'simple-download-monitor'), array($this, 'sdm_deldata_cb'), 'sdm_deldata_section');
660
-
661
  //Add all the individual settings fields that goes under the sections
662
- add_settings_field('general_hide_donwload_count', __('Hide Download Count', 'simple-download-monitor'), array($this, 'hide_download_count_cb'), 'general_options_section', 'general_options');
663
- add_settings_field('general_default_dispatch_value', __('PHP Dispatching', 'simple-download-monitor'), array($this, 'general_default_dispatch_value_cb'), 'general_options_section', 'general_options');
664
- 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');
665
- add_settings_field('general_login_page_url', __('Login Page URL', 'simple-download-monitor'), array($this, 'general_login_page_url_cb'), 'general_options_section', 'general_options');
666
-
667
- add_settings_field('admin_tinymce_button', __('Remove Tinymce Button', 'simple-download-monitor'), array($this, 'admin_tinymce_button_cb'), 'admin_options_section', 'admin_options');
668
- add_settings_field('admin_log_unique', __('Log Unique IP', 'simple-download-monitor'), array($this, 'admin_log_unique'), 'admin_options_section', 'admin_options');
669
- add_settings_field('admin_do_not_capture_ip', __('Do Not Capture IP Address', 'simple-download-monitor'), array($this, 'admin_do_not_capture_ip'), 'admin_options_section', 'admin_options');
670
- add_settings_field('admin_dont_log_bots', __('Do Not Count Downloads from Bots', 'simple-download-monitor'), array($this, 'admin_dont_log_bots'), 'admin_options_section', 'admin_options');
671
- add_settings_field('admin_no_logs', __('Disable Download Logs', 'simple-download-monitor'), array($this, 'admin_no_logs_cb'), 'admin_options_section', 'admin_options');
672
-
673
- add_settings_field('download_button_color', __('Download Button Color', 'simple-download-monitor'), array($this, 'download_button_color_cb'), 'sdm_colors_section', 'sdm_colors');
674
-
675
- add_settings_field('enable_debug', __('Enable Debug', 'simple-download-monitor'), array($this, 'enable_debug_cb'), 'sdm_debug_section', 'sdm_debug');
676
-
677
- /*****************************/
678
- /* Advanced Settings Section */
679
- /*****************************/
680
- //Add the advanced settings section
681
- add_settings_section('recaptcha_options', __('Google Captcha (reCAPTCHA)', 'simple-download-monitor'), array($this, 'recaptcha_options_cb'), 'recaptcha_options_section');
682
- add_settings_section('termscond_options', __('Terms and Conditions', 'simple-download-monitor'), array($this, 'termscond_options_cb'), 'termscond_options_section');
683
- add_settings_section('adsense_options', __('Adsense/Ad Insertion', 'simple-download-monitor'), array($this, 'adsense_options_cb'), 'adsense_options_section');
684
-
685
- //Add reCAPTCHA section fields
686
- add_settings_field('recaptcha_enable', __('Enable reCAPTCHA', 'simple-download-monitor'), array($this, 'recaptcha_enable_cb'), 'recaptcha_options_section', 'recaptcha_options');
687
- add_settings_field('recaptcha_site_key', __('Site Key', 'simple-download-monitor'), array($this, 'recaptcha_site_key_cb'), 'recaptcha_options_section', 'recaptcha_options');
688
- add_settings_field('recaptcha_secret_key', __('Secret Key', 'simple-download-monitor'), array($this, 'recaptcha_secret_key_cb'), 'recaptcha_options_section', 'recaptcha_options');
689
-
690
- //Add Terms & Condition section fields
691
- add_settings_field('termscond_enable', __('Enable Terms and Conditions', 'simple-download-monitor'), array($this, 'termscond_enable_cb'), 'termscond_options_section', 'termscond_options');
692
- add_settings_field('termscond_url', __('Terms Page URL', 'simple-download-monitor'), array($this, 'termscond_url_cb'), 'termscond_options_section', 'termscond_options');
693
-
694
- //Add Adsense section fields
695
- add_settings_field('adsense_below_description', __('Below Download Description', 'simple-download-monitor'), array($this, 'adsense_below_description_cb'), 'adsense_options_section', 'adsense_options');
696
-
697
  }
698
 
699
  public function general_options_cb() {
700
  //Set the message that will be shown below the general options settings heading
701
- _e('General options settings', 'simple-download-monitor');
702
  }
703
 
704
  public function admin_options_cb() {
705
  //Set the message that will be shown below the admin options settings heading
706
- _e('Admin options settings', 'simple-download-monitor');
707
  }
708
 
709
  public function sdm_colors_cb() {
710
  //Set the message that will be shown below the color options settings heading
711
- _e('Front End colors settings', 'simple-download-monitor');
712
  }
713
 
714
  public function sdm_debug_cb() {
715
  //Set the message that will be shown below the debug options settings heading
716
- _e('Debug settings', 'simple-download-monitor');
717
  }
718
 
719
  public function sdm_deldata_cb() {
720
  //Set the message that will be shown below the debug options settings heading
721
- _e('You can delete all the data related to this plugin from database using the button below. Useful when you\'re uninstalling the plugin and don\'t want any leftovers remaining.', 'simple-download-monitor');
722
- echo '<p><b>' . __('Warning', 'simple-download-monitor') . ': </b> ' . __('this can\'t be undone. All settings, download items, download logs will be deleted.', 'simple-download-monitor') . '</p>';
723
- echo '<p><button id="sdmDeleteData" class="button" style="color:red;">' . __('Delete all data and deactivate plugin', 'simple-download-monitor') . '</button></p>';
724
- echo '<br />';
725
  }
726
 
727
  public function recaptcha_options_cb() {
728
  //Set the message that will be shown below the recaptcha options settings heading
729
- _e('Google Captcha (reCAPTCHA) options', 'simple-download-monitor');
730
  }
731
-
732
  public function termscond_options_cb() {
733
-
734
  }
735
-
736
  public function adsense_options_cb() {
737
  //Set the message that will be shown below the adsense/ad code settings heading
738
- _e('You can use this section to insert adsense or other ad code inside the download item output', 'simple-download-monitor');
739
  }
740
-
741
  public function recaptcha_enable_cb() {
742
- $main_opts = get_option('sdm_advanced_options');
743
- echo '<input name="sdm_advanced_options[recaptcha_enable]" id="recaptcha_enable" type="checkbox" ' . checked(1, isset($main_opts['recaptcha_enable']), false) . ' /> ';
744
- echo '<p class="description">' . __('Check this box if you want to use <a href="https://www.google.com/recaptcha/admin" target="_blank">reCAPTCHA</a>. ', 'simple-download-monitor') . '</p>';
745
- echo '<p class="description">' . __('The captcha option adds a captcha to the download now buttons.', 'simple-download-monitor') . '</p>';
746
  }
747
-
748
  public function recaptcha_site_key_cb() {
749
- $main_opts = get_option('sdm_advanced_options');
750
- $value = isset($main_opts['recaptcha_site_key']) ? $main_opts['recaptcha_site_key'] : '';
751
- echo '<input size="100" name="sdm_advanced_options[recaptcha_site_key]" id="recaptcha_site_key" type="text" value="'.$value.'" /> ';
752
- echo '<p class="description">' . __('The site key for the reCAPTCHA API', 'simple-download-monitor') . '</p>';
753
  }
754
-
755
  public function recaptcha_secret_key_cb() {
756
- $main_opts = get_option('sdm_advanced_options');
757
- $value = isset($main_opts['recaptcha_secret_key']) ? $main_opts['recaptcha_secret_key'] : '';
758
- echo '<input size="100" name="sdm_advanced_options[recaptcha_secret_key]" id="recaptcha_secret_key" type="text" value="'.$value.'" /> ';
759
- echo '<p class="description">' . __('The secret key for the reCAPTCHA API', 'simple-download-monitor') . '</p>';
760
  }
761
-
762
  public function hide_download_count_cb() {
763
- $main_opts = get_option('sdm_downloads_options');
764
- echo '<input name="sdm_downloads_options[general_hide_donwload_count]" id="general_hide_download_count" type="checkbox" ' . checked(1, isset($main_opts['general_hide_donwload_count']), false) . ' /> ';
765
- echo '<label for="general_hide_download_count">' . __('Hide the download count that is shown in some of the fancy templates.', 'simple-download-monitor') . '</label>';
766
  }
767
 
768
  public function general_default_dispatch_value_cb() {
769
- $main_opts = get_option('sdm_downloads_options');
770
- $value = isset($main_opts['general_default_dispatch_value']) && $main_opts['general_default_dispatch_value'];
771
- echo '<input name="sdm_downloads_options[general_default_dispatch_value]" id="general_default_dispatch_value" type="checkbox" value="1"' . checked(true, $value, false) . ' />';
772
- 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>';
773
  }
774
 
775
  public function general_only_logged_in_can_download_cb() {
776
- $main_opts = get_option('sdm_downloads_options');
777
- $value = isset($main_opts['only_logged_in_can_download']) && $main_opts['only_logged_in_can_download'];
778
- 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) . ' />';
779
- 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>';
780
  }
781
 
782
  public function general_login_page_url_cb() {
783
- $main_opts = get_option('sdm_downloads_options');
784
- $value = isset($main_opts['general_login_page_url']) ? $main_opts['general_login_page_url'] : '';
785
  echo '<input size="100" name="sdm_downloads_options[general_login_page_url]" id="general_login_page_url" type="text" value="' . $value . '" />';
786
- echo '<p class="description">' . __('(Optional) Specify a login page URL where users can login. This is useful if you only allow logged in users to be able to download. This link will be added to the message that is shown to anonymous users.', 'simple-download-monitor') . '</p>';
787
  }
788
 
789
  public function admin_tinymce_button_cb() {
790
- $main_opts = get_option('sdm_downloads_options');
791
- 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) . ' /> ';
792
- echo '<label for="admin_tinymce_button">' . __('Removes the SDM Downloads button from the WP content editor.', 'simple-download-monitor') . '</label>';
793
  }
794
 
795
  public function admin_log_unique() {
796
- $main_opts = get_option('sdm_downloads_options');
797
- echo '<input name="sdm_downloads_options[admin_log_unique]" id="admin_log_unique" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked(1, isset($main_opts['admin_log_unique']), false) . ' /> ';
798
- echo '<label for="admin_log_unique">' . __('Only logs downloads from unique IP addresses.', 'simple-download-monitor') . '</label>';
799
  }
800
-
801
  public function admin_do_not_capture_ip() {
802
- $main_opts = get_option('sdm_downloads_options');
803
- echo '<input name="sdm_downloads_options[admin_do_not_capture_ip]" id="admin_do_not_capture_ip" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked(1, isset($main_opts['admin_do_not_capture_ip']), false) . ' /> ';
804
- echo '<label for="admin_do_not_capture_ip">' . __('Use this if you do not want to capture the IP address and Country of the visitors when they download an item.', 'simple-download-monitor') . '</label>';
805
  }
806
 
807
  public function admin_dont_log_bots() {
808
- $main_opts = get_option('sdm_downloads_options');
809
- echo '<input name="sdm_downloads_options[admin_dont_log_bots]" id="admin_dont_log_bots" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked(1, isset($main_opts['admin_dont_log_bots']), false) . ' /> ';
810
- echo '<label for="admin_dont_log_bots">' . __('When enabled, the plugin won\'t count and log downloads from bots.', 'simple-download-monitor') . '</label>';
811
  }
812
 
813
  public function admin_no_logs_cb() {
814
- $main_opts = get_option('sdm_downloads_options');
815
- echo '<input name="sdm_downloads_options[admin_no_logs]" id="admin_no_logs" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked(1, isset($main_opts['admin_no_logs']), false) . ' /> ';
816
- echo '<label for="admin_no_logs">' . __('Disables all download logs. (This global option overrides the individual download item option.)', 'simple-download-monitor') . '</label>';
817
  }
818
 
819
  public function download_button_color_cb() {
820
- $main_opts = get_option('sdm_downloads_options');
821
  // Read current color class.
822
- $color_opt = isset($main_opts['download_button_color']) ? $main_opts['download_button_color'] : null;
823
- $color_opts = sdm_get_download_button_colors();
824
 
825
  echo '<select name="sdm_downloads_options[download_button_color]" id="download_button_color" class="sdm_opts_ajax_dropdowns">';
826
- foreach ($color_opts as $color_class => $color_name) {
827
- echo '<option value="' . $color_class . '"' . selected($color_class, $color_opt, false) . '>' . $color_name . '</option>';
828
  }
829
  echo '</select> ';
830
- esc_html_e('Adjusts the color of the "Download Now" button.', 'simple-download-monitor');
831
  }
832
 
833
  public function enable_debug_cb() {
834
- $main_opts = get_option('sdm_downloads_options');
835
- echo '<input name="sdm_downloads_options[enable_debug]" id="enable_debug" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked(1, isset($main_opts['enable_debug']), false) . ' /> ';
836
- echo '<label for="enable_debug">' . __('Check this option to enable debug logging.', 'simple-download-monitor') .
837
  '<p class="description"><a href="' . get_admin_url() . '?sdm-action=view_log" target="_blank">' .
838
- __('Click here', 'simple-download-monitor') . '</a>' .
839
- __(' to view log file.', 'simple-download-monitor') . '<br>' .
840
- '<a id="sdm-reset-log" href="#0" style="color: red">' . __('Click here', 'simple-download-monitor') . '</a>' .
841
- __(' to reset log file.', 'simple-download-monitor') . '</p></label>';
842
  }
843
 
844
  public function termscond_enable_cb() {
845
- $main_opts = get_option('sdm_advanced_options');
846
- echo '<input name="sdm_advanced_options[termscond_enable]" id="termscond_enable" type="checkbox" ' . checked(1, isset($main_opts['termscond_enable']), false) . ' /> ';
847
- echo '<p class="description">' . __('You can use this option to make the visitors agree to your terms before they can download the item.', 'simple-download-monitor') . '</p>';
848
  }
849
-
850
  public function termscond_url_cb() {
851
- $main_opts = get_option('sdm_advanced_options');
852
- $value = isset($main_opts['termscond_url']) ? $main_opts['termscond_url'] : '';
853
- echo '<input size="100" name="sdm_advanced_options[termscond_url]" id="termscond_url" type="text" value="'.$value.'" /> ';
854
- echo '<p class="description">' . __('Enter the URL of your terms and conditions page.', 'simple-download-monitor') . '</p>';
855
  }
856
-
857
  public function adsense_below_description_cb() {
858
- $main_opts = get_option('sdm_advanced_options');
859
- $value = isset($main_opts['adsense_below_description']) ? $main_opts['adsense_below_description'] : '';
860
- //echo '<input size="100" name="sdm_advanced_options[adsense_below_description]" id="adsense_below_description" type="text" value="'.$value.'" /> ';
861
- echo '<textarea name="sdm_advanced_options[adsense_below_description]" id="adsense_below_description" rows="6" cols="60">'.$value.'</textarea>';
862
- echo '<p class="description">' . __('Enter the Adsense or Ad code that you want to show below the download item description.', 'simple-download-monitor') . '</p>';
863
- }
864
-
865
- public function sdm_add_clone_record_btn($action, $post) {
866
  // Only execute on SDM CPT posts page
867
- if ($post->post_type == 'sdm_downloads') {
868
- $action['clone'] = sprintf(
869
- '<a href="%2$s" aria-label="%1$s">%1$s</a>',
870
- esc_html__( 'Clone', 'simple-download-monitor' ),
871
- $this->get_duplicate_url( $post->ID )
872
- );
873
  }
874
  return $action;
875
  }
876
-
877
  /**
878
- * Returns duplicate post URL
879
- *
880
- * @return string
881
- */
882
- public function get_duplicate_url($post_id) {
883
- global $wp;
884
- return add_query_arg(array(
885
- 'action' => 'sdm_clone_post',
886
- 'post' => $post_id,
887
- 'ref' => urlencode(add_query_arg($wp->query_string, '', home_url($wp->request))),
888
- '_nonce' => wp_create_nonce('sdm_downloads')
889
- ), esc_url(admin_url('admin.php'))
890
- );
891
  }
892
 
893
  public function sdm_action_clone_post() {
894
-
895
- global $wpdb;
896
- if (!( isset($_GET['post']) || isset($_POST['post']) || ( isset($_REQUEST['action']) && 'sdm_clone_post' == $_REQUEST['action'] ) )) {
897
- wp_die(__('No post to duplicate has been supplied!', 'simple-download-monitor'));
898
- }
899
-
900
- /*
901
- * Nonce verification
902
- */
903
- if (!isset($_GET['_nonce']) || !wp_verify_nonce($_GET['_nonce'], 'sdm_downloads'))
904
- return;
905
-
906
- /*
907
- * get the original post id
908
- */
909
- $post_id = (isset($_GET['post']) ? absint($_GET['post']) : absint($_POST['post']) );
910
- /*
911
- * and all the original post data then
912
- */
913
- $post = get_post($post_id);
914
-
915
- /*
916
- * if you don't want current user to be the new post author,
917
- * then change next couple of lines to this: $new_post_author = $post->post_author;
918
- */
919
- $current_user = wp_get_current_user();
920
- $new_post_author = $current_user->ID;
921
-
922
- /*
923
- * if post data exists, create the post duplicate
924
- */
925
- if (isset($post) && $post != null) {
926
-
927
- /*
928
- * new post data array
929
- */
930
- $args = array(
931
- 'comment_status' => $post->comment_status,
932
- 'ping_status' => $post->ping_status,
933
- 'post_author' => $new_post_author,
934
- 'post_content' => $post->post_content,
935
- 'post_excerpt' => $post->post_excerpt,
936
- 'post_name' => $post->post_name,
937
- 'post_parent' => $post->post_parent,
938
- 'post_password' => $post->post_password,
939
- 'post_status' => 'draft',
940
- 'post_title' => $post->post_title,
941
- 'post_type' => $post->post_type,
942
- 'to_ping' => $post->to_ping,
943
- 'menu_order' => $post->menu_order
944
- );
945
-
946
- /*
947
- * insert the post by wp_insert_post() function
948
- */
949
- $new_post_id = wp_insert_post($args);
950
-
951
- /*
952
- * get all current post terms ad set them to the new post draft
953
- */
954
- $taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array("category", "post_tag");
955
- foreach ($taxonomies as $taxonomy) {
956
- $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs'));
957
- wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
958
- }
959
-
960
- /*
961
- * duplicate all post meta just in two SQL queries
962
- */
963
- $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id");
964
- if (count($post_meta_infos) != 0) {
965
- $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
966
- foreach ($post_meta_infos as $meta_info) {
967
- $meta_key = $meta_info->meta_key;
968
- if ($meta_key == '_wp_old_slug')
969
- continue;
970
- $meta_value = addslashes($meta_info->meta_value);
971
- $sql_query_sel[] = "SELECT $new_post_id, '$meta_key', '$meta_value'";
972
- }
973
- $sql_query .= implode(" UNION ALL ", $sql_query_sel);
974
- $wpdb->query($sql_query);
975
- }
976
-
977
- /*
978
- * finally, redirect to the edit post screen for the new draft
979
- */
980
- wp_redirect(admin_url('post.php?action=edit&post=' . $new_post_id));
981
- exit;
982
- } else {
983
- wp_die(__('Post creation failed, could not find original post: ', 'simple-download-monitor') . $post_id);
984
- }
985
  }
 
986
  }
987
 
988
  //End of simpleDownloadManager class
@@ -990,92 +987,91 @@ class simpleDownloadManager {
990
  $simpleDownloadManager = new simpleDownloadManager();
991
 
992
  // Tinymce Button Populate Post ID's
993
- add_action('wp_ajax_nopriv_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call');
994
- add_action('wp_ajax_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call');
995
 
996
  function sdm_tiny_get_post_ids_ajax_call() {
997
 
998
- $posts = get_posts(array(
999
- 'post_type' => 'sdm_downloads',
1000
- 'numberposts' => -1,
1001
- )
1002
  );
1003
- foreach ($posts as $item) {
1004
- $test[] = array('post_id' => $item->ID, 'post_title' => $item->post_title);
1005
  }
1006
 
1007
- $response = json_encode(array('success' => true, 'test' => $test));
1008
 
1009
- header('Content-Type: application/json');
1010
  echo $response;
1011
  exit;
1012
  }
1013
 
1014
  //Remove Thumbnail Image
1015
  //add_action('wp_ajax_nopriv_sdm_remove_thumbnail_image', '');//This is only available to logged-in users
1016
- add_action('wp_ajax_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call'); //Execute this for authenticated users only
1017
 
1018
  function sdm_remove_thumbnail_image_ajax_call() {
1019
- if (!current_user_can('edit_posts')) {
1020
  //Permission denied
1021
- wp_die(__('Permission denied!', 'simple-download-monitor'));
1022
  exit;
1023
  }
1024
 
1025
  //Go ahead with the thumbnail removal
1026
- $post_id = intval($_POST['post_id_del']);
1027
- $key_exists = metadata_exists('post', $post_id, 'sdm_upload_thumbnail');
1028
- if ($key_exists) {
1029
- $success = delete_post_meta($post_id, 'sdm_upload_thumbnail');
1030
- if ($success) {
1031
- $response = json_encode(array('success' => true));
1032
  }
1033
  } else {
1034
  // in order for frontend script to not display "Ajax error", let's return some data
1035
- $response = json_encode(array('not_exists' => true));
1036
  }
1037
 
1038
- header('Content-Type: application/json');
1039
  echo $response;
1040
  exit;
1041
  }
1042
 
1043
  // Populate category tree
1044
- add_action('wp_ajax_nopriv_sdm_pop_cats', 'sdm_pop_cats_ajax_call');
1045
- add_action('wp_ajax_sdm_pop_cats', 'sdm_pop_cats_ajax_call');
1046
 
1047
  function sdm_pop_cats_ajax_call() {
1048
 
1049
- $cat_slug = sanitize_text_field($_POST['cat_slug']); // Get button cpt slug
1050
- $parent_id = intval($_POST['parent_id']); // Get button cpt id
1051
-
1052
  // Query custom posts based on taxonomy slug
1053
- $posts = get_posts(array(
1054
- 'post_type' => 'sdm_downloads',
1055
- 'numberposts' => -1,
1056
- 'tax_query' => array(
1057
  array(
1058
- 'taxonomy' => 'sdm_categories',
1059
- 'field' => 'slug',
1060
- 'terms' => $cat_slug,
1061
- 'include_children' => 0
1062
  )
1063
  ),
1064
- 'orderby' => 'title',
1065
- 'order' => 'ASC')
1066
  );
1067
 
1068
  $final_array = array();
1069
 
1070
  // Loop results
1071
- foreach ($posts as $post) {
1072
  // Create array of variables to pass to js
1073
- $final_array[] = array('id' => $post->ID, 'permalink' => get_permalink($post->ID), 'title' => $post->post_title);
1074
  }
1075
 
1076
  // Generate ajax response
1077
- $response = json_encode(array('final_array' => $final_array));
1078
- header('Content-Type: application/json');
1079
  echo $response;
1080
  exit;
1081
  }
@@ -1083,58 +1079,58 @@ function sdm_pop_cats_ajax_call() {
1083
  /*
1084
  * * Setup Sortable Columns
1085
  */
1086
- add_filter('manage_edit-sdm_downloads_columns', 'sdm_create_columns'); // Define columns
1087
- add_filter('manage_edit-sdm_downloads_sortable_columns', 'sdm_downloads_sortable'); // Make sortable
1088
- add_action('manage_sdm_downloads_posts_custom_column', 'sdm_downloads_columns_content', 10, 2); // Populate new columns
1089
-
1090
- function sdm_create_columns($cols) {
1091
-
1092
- unset($cols['title']);
1093
- unset($cols['taxonomy-sdm_tags']);
1094
- unset($cols['taxonomy-sdm_categories']);
1095
- unset($cols['date']);
1096
-
1097
- $cols['title'] = __('Title', 'simple-download-monitor');
1098
- $cols['sdm_downloads_thumbnail'] = __('Image', 'simple-download-monitor');
1099
- $cols['sdm_downloads_id'] = __('ID', 'simple-download-monitor');
1100
- $cols['sdm_downloads_file'] = __('File', 'simple-download-monitor');
1101
- $cols['taxonomy-sdm_categories'] = __('Categories', 'simple-download-monitor');
1102
- $cols['taxonomy-sdm_tags'] = __('Tags', 'simple-download-monitor');
1103
- $cols['sdm_downloads_count'] = __('Downloads', 'simple-download-monitor');
1104
- $cols['date'] = __('Date Posted', 'simple-download-monitor');
1105
  return $cols;
1106
  }
1107
 
1108
- function sdm_downloads_sortable($cols) {
1109
 
1110
- $cols['sdm_downloads_id'] = 'sdm_downloads_id';
1111
- $cols['sdm_downloads_file'] = 'sdm_downloads_file';
1112
- $cols['sdm_downloads_count'] = 'sdm_downloads_count';
1113
- $cols['taxonomy-sdm_categories'] = 'taxonomy-sdm_categories';
1114
- $cols['taxonomy-sdm_tags'] = 'taxonomy-sdm_tags';
1115
  return $cols;
1116
  }
1117
 
1118
- function sdm_downloads_columns_content($column_name, $post_ID) {
1119
 
1120
- if ($column_name == 'sdm_downloads_thumbnail') {
1121
- $old_thumbnail = get_post_meta($post_ID, 'sdm_upload_thumbnail', true);
1122
  //$old_value = isset($old_thumbnail) ? $old_thumbnail : '';
1123
- if ($old_thumbnail) {
1124
  echo '<p class="sdm_downloads_thumbnail_in_admin_listing"><img src="' . $old_thumbnail . '" style="width:50px;height:50px;" /></p>';
1125
  }
1126
  }
1127
- if ($column_name == 'sdm_downloads_id') {
1128
  echo '<p class="sdm_downloads_postid">' . $post_ID . '</p>';
1129
  }
1130
- if ($column_name == 'sdm_downloads_file') {
1131
- $old_file = get_post_meta($post_ID, 'sdm_upload', true);
1132
- $file = isset($old_file) ? $old_file : '--';
1133
  echo '<p class="sdm_downloads_file">' . $file . '</p>';
1134
  }
1135
- if ($column_name == 'sdm_downloads_count') {
1136
  global $wpdb;
1137
- $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post_ID));
1138
  echo '<p class="sdm_downloads_count">' . $wpdb->num_rows . '</p>';
1139
  }
1140
  }
@@ -1144,26 +1140,26 @@ function sdm_downloads_columns_content($column_name, $post_ID) {
1144
  */
1145
 
1146
  // First check if option is checked to disable tinymce button
1147
- $main_option = get_option('sdm_downloads_options');
1148
- $tiny_button_option = isset($main_option['admin_tinymce_button']);
1149
- if ($tiny_button_option != true) {
1150
 
1151
  // Okay.. we're good. Add the button.
1152
- add_action('init', 'sdm_downloads_tinymce_button');
1153
 
1154
  function sdm_downloads_tinymce_button() {
1155
 
1156
- add_filter('mce_external_plugins', 'sdm_downloads_add_button');
1157
- add_filter('mce_buttons', 'sdm_downloads_register_button');
1158
  }
1159
 
1160
- function sdm_downloads_add_button($plugin_array) {
1161
 
1162
- $plugin_array['sdm_downloads'] = WP_SIMPLE_DL_MONITOR_URL . '/tinymce/sdm_editor_plugin.js';
1163
  return $plugin_array;
1164
  }
1165
 
1166
- function sdm_downloads_register_button($buttons) {
1167
 
1168
  $buttons[] = 'sdm_downloads';
1169
  return $buttons;
3
  * Plugin Name: Simple Download Monitor
4
  * Plugin URI: https://simple-download-monitor.com/
5
  * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
+ * Version: 3.7.5
7
  * Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
8
  * Author URI: https://www.tipsandtricks-hq.com/development-center
9
  * License: GPL2
10
  * Text Domain: simple-download-monitor
11
  * Domain Path: /languages/
12
  */
13
+ if ( ! defined( 'ABSPATH' ) ) {
 
14
  exit;
15
  }
16
 
17
+ define( 'WP_SIMPLE_DL_MONITOR_VERSION', '3.7.5' );
18
+ define( 'WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname( plugin_basename( __FILE__ ) ) );
19
+ define( 'WP_SIMPLE_DL_MONITOR_URL', plugins_url( '', __FILE__ ) );
20
+ define( 'WP_SIMPLE_DL_MONITOR_PATH', plugin_dir_path( __FILE__ ) );
21
+ define( 'WP_SIMPLE_DL_MONITOR_SITE_HOME_URL', home_url() );
22
+ define( 'WP_SDM_LOG_FILE', WP_SIMPLE_DL_MONITOR_PATH . 'sdm-debug-log.txt' );
23
 
24
  global $sdm_db_version;
25
  $sdm_db_version = '1.2';
38
  include_once('sdm-post-type-content-handler.php');
39
 
40
  //Activation hook handler
41
+ register_activation_hook( __FILE__, 'sdm_install_db_table' );
42
 
43
  function sdm_install_db_table() {
44
 
59
  );';
60
 
61
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
62
+ dbDelta( $sql );
63
 
64
+ update_option( 'sdm_db_version', $sdm_db_version );
65
 
66
  //Register the post type so you can flush the rewrite rules
67
  sdm_register_post_type();
73
  /*
74
  * * Handle Plugins loaded tasks
75
  */
76
+ add_action( 'plugins_loaded', 'sdm_plugins_loaded_tasks' );
77
 
78
  function sdm_plugins_loaded_tasks() {
79
  //Load language
80
+ load_plugin_textdomain( 'simple-download-monitor', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
81
 
82
  //Handle db upgrade stuff
83
  sdm_db_update_check();
86
  /*
87
  * * Handle Generic Init tasks
88
  */
89
+ add_action( 'init', 'sdm_init_time_tasks' );
90
+ add_action( 'admin_init', 'sdm_admin_init_time_tasks' );
91
 
92
  function sdm_init_time_tasks() {
93
  //Handle download request if any
94
  handle_sdm_download_via_direct_post();
95
+ if ( is_admin() ) {
96
  //Register Google Charts library
97
+ wp_register_script( 'sdm_google_charts', 'https://www.gstatic.com/charts/loader.js', array(), null, true );
98
+ wp_register_style( 'sdm_jquery_ui_style', WP_SIMPLE_DL_MONITOR_URL . '/css/jquery.ui.min.css', array(), null, 'all' );
99
  }
100
  }
101
 
102
  function sdm_admin_init_time_tasks() {
103
  //Register ajax handlers
104
+ add_action( 'wp_ajax_sdm_reset_log', 'sdm_reset_log_handler' );
105
+ add_action( 'wp_ajax_sdm_delete_data', 'sdm_delete_data_handler' );
106
 
107
+ if ( is_admin() ) {
108
+ if ( user_can( wp_get_current_user(), 'administrator' ) ) {
109
  // user is an admin
110
+ if ( isset( $_GET[ 'sdm-action' ] ) ) {
111
+ if ( $_GET[ 'sdm-action' ] === 'view_log' ) {
112
+ $logfile = fopen( WP_SDM_LOG_FILE, 'rb' );
113
+ header( 'Content-Type: text/plain' );
114
+ fpassthru( $logfile );
115
  die;
116
  }
117
  }
126
  }
127
 
128
  function sdm_delete_data_handler() {
129
+ if ( ! check_ajax_referer( 'sdm_delete_data', 'nonce', false ) ) {
130
  //nonce check failed
131
+ wp_die( 0 );
132
  }
133
  global $wpdb;
134
  //let's find and delete smd_download posts and meta
135
+ $posts = $wpdb->get_results( 'SELECT id FROM ' . $wpdb->prefix . 'posts WHERE post_type="sdm_downloads"', ARRAY_A );
136
+ if ( ! is_null( $posts ) ) {
137
+ foreach ( $posts as $post ) {
138
+ wp_delete_post( $post[ 'id' ], true );
139
  }
140
  }
141
  //let's delete options
142
+ delete_option( 'sdm_downloads_options' );
143
+ delete_option( 'sdm_db_version' );
144
  //remove post type and taxonomies
145
+ unregister_post_type( 'sdm_downloads' );
146
+ unregister_taxonomy( 'sdm_categories' );
147
+ unregister_taxonomy( 'sdm_tags' );
148
  //let's delete sdm_downloads table
149
+ $wpdb->query( "DROP TABLE " . $wpdb->prefix . "sdm_downloads" );
150
  //deactivate plugin
151
+ deactivate_plugins( plugin_basename( __FILE__ ) );
152
  //flush rewrite rules
153
+ flush_rewrite_rules( false );
154
  echo '1';
155
  wp_die();
156
  }
160
  */
161
 
162
  function sdm_db_update_check() {
163
+ if ( is_admin() ) {//Check if DB needs to be upgraded
164
  global $sdm_db_version;
165
+ $inst_db_version = get_option( 'sdm_db_version' );
166
+ if ( $inst_db_version != $sdm_db_version ) {
167
  sdm_install_db_table();
168
  }
169
  }
172
  /*
173
  * * Add a 'Settings' link to plugins list page
174
  */
175
+ add_filter( 'plugin_action_links', 'sdm_settings_link', 10, 2 );
176
 
177
+ function sdm_settings_link( $links, $file ) {
178
  static $this_plugin;
179
+ if ( ! $this_plugin )
180
+ $this_plugin = plugin_basename( __FILE__ );
181
+ if ( $file == $this_plugin ) {
182
+ $settings_link = '<a href="edit.php?post_type=sdm_downloads&page=sdm-settings" title="SDM Settings Page">' . __( "Settings", 'simple-download-monitor' ) . '</a>';
183
+ array_unshift( $links, $settings_link );
184
  }
185
  return $links;
186
  }
190
 
191
  public function __construct() {
192
 
193
+ add_action( 'init', 'sdm_register_post_type' ); // Create 'sdm_downloads' custom post type
194
+ add_action( 'init', 'sdm_create_taxonomies' ); // Register 'tags' and 'categories' taxonomies
195
+ add_action( 'init', 'sdm_register_shortcodes' ); //Register the shortcodes
196
+ add_action( 'wp_enqueue_scripts', array( $this, 'sdm_frontend_scripts' ) ); // Register frontend scripts
197
 
198
+ if ( is_admin() ) {
199
+ add_action( 'admin_menu', array( $this, 'sdm_create_menu_pages' ) ); // Create admin pages
200
+ add_action( 'add_meta_boxes', array( $this, 'sdm_create_upload_metabox' ) ); // Create metaboxes
201
 
202
+ add_action( 'save_post', array( $this, 'sdm_save_description_meta_data' ) ); // Save 'description' metabox
203
+ add_action( 'save_post', array( $this, 'sdm_save_upload_meta_data' ) ); // Save 'upload file' metabox
204
+ add_action( 'save_post', array( $this, 'sdm_save_dispatch_meta_data' ) ); // Save 'dispatch' metabox
205
+ add_action( 'save_post', array( $this, 'sdm_save_misc_properties_meta_data' ) ); // Save 'misc properties/settings' metabox
206
+ add_action( 'save_post', array( $this, 'sdm_save_thumbnail_meta_data' ) ); // Save 'thumbnail' metabox
207
+ add_action( 'save_post', array( $this, 'sdm_save_statistics_meta_data' ) ); // Save 'statistics' metabox
208
+ add_action( 'save_post', array( $this, 'sdm_save_other_details_meta_data' ) ); // Save 'other details' metabox
209
 
210
+ add_action( 'admin_enqueue_scripts', array( $this, 'sdm_admin_scripts' ) ); // Register admin scripts
211
+ add_action( 'admin_print_styles', array( $this, 'sdm_admin_styles' ) ); // Register admin styles
212
 
213
+ add_action( 'admin_init', array( $this, 'sdm_register_options' ) ); // Register admin options
214
  //add_filter('post_row_actions', array($this, 'sdm_remove_view_link_cpt'), 10, 2); // Remove 'View' link in all downloads list view
215
+
216
+ add_filter( 'page_row_actions', array( $this, 'sdm_add_clone_record_btn' ), 10, 2 ); // Add 'Clone' link in all downloads list view
217
+ add_filter( 'post_row_actions', array( $this, 'sdm_add_clone_record_btn' ), 10, 2 ); // Add 'Clone' link in all downloads list view
218
+
219
+ add_action( 'admin_action_sdm_clone_post', array( $this, 'sdm_action_clone_post' ) );
220
  }
 
221
  }
222
+
223
  public function sdm_admin_scripts() {
224
 
225
  global $current_screen, $post;
226
 
227
+ if ( is_admin() && $current_screen->post_type == 'sdm_downloads' && $current_screen->base == 'post' ) {
228
 
229
  // These scripts are needed for the media upload thickbox
230
+ wp_enqueue_script( 'media-upload' );
231
+ wp_enqueue_script( 'thickbox' );
232
+ wp_register_script( 'sdm-upload', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_admin_scripts.js', array( 'jquery', 'media-upload', 'thickbox' ), WP_SIMPLE_DL_MONITOR_VERSION );
233
+ wp_enqueue_script( 'sdm-upload' );
234
 
235
  // Pass postID for thumbnail deletion
236
  ?>
240
  <?php
241
  // Localize langauge strings used in js file
242
  $sdmTranslations = array(
243
+ 'select_file' => __( 'Select File', 'simple-download-monitor' ),
244
+ 'select_thumbnail' => __( 'Select Thumbnail', 'simple-download-monitor' ),
245
+ 'insert' => __( 'Insert', 'simple-download-monitor' ),
246
+ 'image_removed' => __( 'Image Successfully Removed', 'simple-download-monitor' ),
247
+ 'ajax_error' => __( 'Error with AJAX', 'simple-download-monitor' )
248
  );
249
+ wp_localize_script( 'sdm-upload', 'sdm_translations', $sdmTranslations );
250
  }
251
 
252
  // Pass admin ajax url
253
  ?>
254
  <script type="text/javascript">
255
+ var sdm_admin_ajax_url = {sdm_admin_ajax_url: '<?php echo admin_url( 'admin-ajax.php?action=ajax' ); ?>'};
256
  var sdm_plugin_url = '<?php echo plugins_url(); ?>';
257
  var tinymce_langs = {
258
+ select_download_item: '<?php _e( 'Please select a Download Item:', 'simple-download-monitor' ) ?>',
259
+ download_title: '<?php _e( 'Download Title', 'simple-download-monitor' ) ?>',
260
+ include_fancy: '<?php _e( 'Include Fancy Box', 'simple-download-monitor' ) ?>',
261
+ open_new_window: '<?php _e( 'Open New Window', 'simple-download-monitor' ) ?>',
262
+ button_color: '<?php _e( 'Button Color', 'simple-download-monitor' ); ?>',
263
+ insert_shortcode: '<?php _e( 'Insert SDM Shortcode', 'simple-download-monitor' ) ?>'
264
  };
265
+ var sdm_button_colors = <?php echo wp_json_encode( sdm_get_download_button_colors() ); ?>;
266
  </script>
267
  <?php
268
  }
269
 
270
  public function sdm_frontend_scripts() {
271
  //Use this function to enqueue fron-end js scripts.
272
+ wp_enqueue_style( 'sdm-styles', WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_wp_styles.css' );
273
+ wp_register_script( 'sdm-scripts', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_wp_scripts.js', array( 'jquery' ) );
274
+ wp_enqueue_script( 'sdm-scripts' );
275
+
276
+ //Check if reCAPTCHA is enabled.
277
+ $main_advanced_opts = get_option( 'sdm_advanced_options' );
278
+ $recaptcha_enable = isset( $main_advanced_opts[ 'recaptcha_enable' ] ) ? true : false;
279
+ if ( $recaptcha_enable ) {
280
+ wp_register_script( 'sdm-recaptcha-scripts-js', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_g_recaptcha.js', array(), true );
281
+ wp_localize_script( "sdm-recaptcha-scripts-js", "sdm_recaptcha_opt", array( "site_key" => $main_advanced_opts[ 'recaptcha_site_key' ] ) );
282
+ wp_register_script( 'sdm-recaptcha-scripts-lib', "//www.google.com/recaptcha/api.js?hl=" . get_locale() . "&onload=sdm_reCaptcha&render=explicit", array(), false );
283
+ wp_enqueue_script( 'sdm-recaptcha-scripts-js' );
284
+ wp_enqueue_script( 'sdm-recaptcha-scripts-lib' );
285
+ }
286
 
287
  // Localize ajax script for frontend
288
+ wp_localize_script( 'sdm-scripts', 'sdm_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
289
  }
290
 
291
  public function sdm_admin_styles() {
292
 
293
+ wp_enqueue_style( 'thickbox' ); // Needed for media upload thickbox
294
+ wp_enqueue_style( 'sdm_admin_styles', WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_admin_styles.css', array(), WP_SIMPLE_DL_MONITOR_VERSION ); // Needed for media upload thickbox
295
  }
296
 
297
  public function sdm_create_menu_pages() {
302
  public function sdm_create_upload_metabox() {
303
 
304
  //***** Create metaboxes for the custom post type
305
+ add_meta_box( 'sdm_description_meta_box', __( 'Description', 'simple-download-monitor' ), array( $this, 'display_sdm_description_meta_box' ), 'sdm_downloads', 'normal', 'default' );
306
+ add_meta_box( 'sdm_upload_meta_box', __( 'Downloadable File (Visitors will download this item)', 'simple-download-monitor' ), array( $this, 'display_sdm_upload_meta_box' ), 'sdm_downloads', 'normal', 'default' );
307
+ add_meta_box( 'sdm_dispatch_meta_box', __( 'PHP Dispatch or Redirect', 'simple-download-monitor' ), array( $this, 'display_sdm_dispatch_meta_box' ), 'sdm_downloads', 'normal', 'default' );
308
+ add_meta_box( 'sdm_misc_properties_meta_box', __( 'Miscellaneous Download Properties', 'simple-download-monitor' ), array( $this, 'display_sdm_misc_properties_meta_box' ), 'sdm_downloads', 'normal', 'default' ); // Meta box for misc properies/settings
309
+ add_meta_box( 'sdm_thumbnail_meta_box', __( 'File Thumbnail (Optional)', 'simple-download-monitor' ), array( $this, 'display_sdm_thumbnail_meta_box' ), 'sdm_downloads', 'normal', 'default' );
310
+ add_meta_box( 'sdm_stats_meta_box', __( 'Statistics', 'simple-download-monitor' ), array( $this, 'display_sdm_stats_meta_box' ), 'sdm_downloads', 'normal', 'default' );
311
+ do_action( 'sdm_admin_add_edit_download_before_other_details_meta_box_action' );
312
+ 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' );
313
+ add_meta_box( 'sdm_shortcode_meta_box', __( 'Shortcodes', 'simple-download-monitor' ), array( $this, 'display_sdm_shortcode_meta_box' ), 'sdm_downloads', 'normal', 'default' );
314
+ }
315
+
316
+ public function display_sdm_description_meta_box( $post ) { // Description metabox
317
+ _e( 'Add a description for this download item.', 'simple-download-monitor' );
318
  echo '<br /><br />';
319
 
320
+ $old_description = get_post_meta( $post->ID, 'sdm_description', true );
321
+ $sdm_description_field = array( 'textarea_name' => 'sdm_description' );
322
+ wp_editor( $old_description, "sdm_description_editor_content", $sdm_description_field );
323
+
324
+ wp_nonce_field( 'sdm_description_box_nonce', 'sdm_description_box_nonce_check' );
325
  }
326
 
327
+ public function display_sdm_upload_meta_box( $post ) { // File Upload metabox
328
+ $old_upload = get_post_meta( $post->ID, 'sdm_upload', true );
329
+ $old_value = isset( $old_upload ) ? $old_upload : '';
330
 
331
+ _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' );
332
  echo '<br /><br />';
333
 
334
  echo '<div class="sdm-download-edit-file-url-section">';
335
+ echo '<input id="sdm_upload" type="text" size="100" name="sdm_upload" value="' . esc_url( $old_value ) . '" placeholder="http://..." />';
336
  echo '</div>';
337
 
338
  echo '<br />';
339
+ echo '<input id="upload_image_button" type="button" class="button-primary" value="' . __( 'Select File', 'simple-download-monitor' ) . '" />';
340
 
341
  echo '<br /><br />';
342
+ _e( 'Steps to upload a file or choose one from your media library:', 'simple-download-monitor' );
343
  echo '<ol>';
344
+ echo '<li>' . __( 'Hit the "Select File" button.', 'simple-download-monitor' ) . '</li>';
345
+ echo '<li>' . __( 'Upload a new file or choose an existing one from your media library.', 'simple-download-monitor' ) . '</li>';
346
+ echo '<li>' . __( 'Click the "Insert" button, this will populate the uploaded file\'s URL in the above text field.', 'simple-download-monitor' ) . '</li>';
347
  echo '</ol>';
348
 
349
+ wp_nonce_field( 'sdm_upload_box_nonce', 'sdm_upload_box_nonce_check' );
350
  }
351
 
352
+ public function display_sdm_dispatch_meta_box( $post ) {
353
+ $dispatch = get_post_meta( $post->ID, 'sdm_item_dispatch', true );
354
 
355
+ if ( $dispatch === '' ) {
356
  // No value yet (either new item or saved with older version of plugin)
357
  $screen = get_current_screen();
358
 
359
+ if ( $screen->action === 'add' ) {
360
  // New item: set default value as per plugin settings.
361
+ $main_opts = get_option( 'sdm_downloads_options' );
362
+ $dispatch = isset( $main_opts[ 'general_default_dispatch_value' ] ) && $main_opts[ 'general_default_dispatch_value' ];
363
  }
364
  }
365
 
366
+ echo '<input id="sdm_item_dispatch" type="checkbox" name="sdm_item_dispatch" value="yes"' . checked( true, $dispatch, false ) . ' />';
367
+ echo '<label for="sdm_item_dispatch">' . __( 'Dispatch the file via PHP directly instead of redirecting to it. PHP Dispatching keeps the download URL hidden. Dispatching works only for local files (files that you uploaded to this site via this plugin or media library).', 'simple-download-monitor' ) . '</label>';
368
 
369
+ wp_nonce_field( 'sdm_dispatch_box_nonce', 'sdm_dispatch_box_nonce_check' );
370
  }
371
+
372
  // Open Download in new window
373
+ public function display_sdm_misc_properties_meta_box( $post ) {
374
+
375
+ //Check the open in new window value
376
+ $new_window = get_post_meta( $post->ID, 'sdm_item_new_window', true );
377
+ if ( $new_window === '' ) {
378
  // No value yet (either new item or saved with older version of plugin)
379
  $screen = get_current_screen();
380
+ if ( $screen->action === 'add' ) {
381
  //New item: we can set a default value as per plugin settings. If a general settings is introduced at a later stage.
382
+ //Does nothing at the moment.
383
  }
384
  }
385
+
386
+ echo '<p> <input id="sdm_item_new_window" type="checkbox" name="sdm_item_new_window" value="yes"' . checked( true, $new_window, false ) . ' />';
387
+ echo '<label for="sdm_item_new_window">' . __( 'Open download in a new window.', 'simple-download-monitor' ) . '</label> </p>';
388
+
389
+ wp_nonce_field( 'sdm_misc_properties_box_nonce', 'sdm_misc_properties_box_nonce_check' );
390
  }
391
 
392
+ public function display_sdm_thumbnail_meta_box( $post ) { // Thumbnail upload metabox
393
+ $old_thumbnail = get_post_meta( $post->ID, 'sdm_upload_thumbnail', true );
394
+ $old_value = isset( $old_thumbnail ) ? $old_thumbnail : '';
395
+ _e( 'Manually enter a valid URL, or click "Select Image" to upload (or choose) the file thumbnail image.', 'simple-download-monitor' );
396
  ?>
397
  <br /><br />
398
+ <input id="sdm_upload_thumbnail" type="text" size="100" name="sdm_upload_thumbnail" value="<?php echo esc_url( $old_value ); ?>" placeholder="http://..." />
399
  <br /><br />
400
+ <input id="upload_thumbnail_button" type="button" class="button-primary" value="<?php _e( 'Select Image', 'simple-download-monitor' ); ?>" />
401
+ <input id="remove_thumbnail_button" type="button" class="button" value="<?php _e( 'Remove Image', 'simple-download-monitor' ); ?>" />
402
  <br /><br />
403
 
404
  <span id="sdm_admin_thumb_preview">
405
  <?php
406
+ if ( ! empty( $old_value ) ) {
407
  ?><img id="sdm_thumbnail_image" src="<?php echo $old_value; ?>" style="max-width:200px;" />
408
  <?php
409
  }
412
 
413
  <?php
414
  echo '<p class="description">';
415
+ _e( 'This thumbnail image will be used to create a fancy file download box if you want to use it.', 'simple-download-monitor' );
416
  echo '</p>';
417
 
418
+ wp_nonce_field( 'sdm_thumbnail_box_nonce', 'sdm_thumbnail_box_nonce_check' );
419
  }
420
 
421
+ public function display_sdm_stats_meta_box( $post ) { //Stats metabox
422
+ $old_count = get_post_meta( $post->ID, 'sdm_count_offset', true );
423
+ $value = isset( $old_count ) && $old_count != '' ? $old_count : '0';
424
 
425
  // Get checkbox for "disable download logging"
426
+ $no_logs = get_post_meta( $post->ID, 'sdm_item_no_log', true );
427
+ $checked = isset( $no_logs ) && $no_logs === 'on' ? 'checked="checked"' : '';
428
 
429
+ _e( 'These are the statistics for this download item.', 'simple-download-monitor' );
430
  echo '<br /><br />';
431
 
432
  global $wpdb;
433
+ $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post->ID ) );
434
 
435
  echo '<div class="sdm-download-edit-dl-count">';
436
+ _e( 'Number of Downloads:', 'simple-download-monitor' );
437
  echo ' <strong>' . $wpdb->num_rows . '</strong>';
438
  echo '</div>';
439
 
440
  echo '<div class="sdm-download-edit-offset-count">';
441
+ _e( 'Offset Count: ', 'simple-download-monitor' );
442
  echo '<br />';
443
+ echo ' <input type="text" size="10" name="sdm_count_offset" value="' . esc_attr( $value ) . '" />';
444
+ 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>';
445
  echo '</div>';
446
 
447
  echo '<br />';
448
  echo '<div class="sdm-download-edit-disable-logging">';
449
  echo '<input type="checkbox" name="sdm_item_no_log" ' . $checked . ' />';
450
  echo '<span style="margin-left: 5px;"></span>';
451
+ _e( 'Disable download logging for this item.', 'simple-download-monitor' );
452
  echo '</div>';
453
 
454
+ wp_nonce_field( 'sdm_count_offset_nonce', 'sdm_count_offset_nonce_check' );
455
  }
456
 
457
+ public function display_sdm_other_details_meta_box( $post ) { //Other details metabox
458
+ $show_date_fd = get_post_meta( $post->ID, 'sdm_item_show_date_fd', true );
459
+ $sdm_item_show_file_size_fd = get_post_meta( $post->ID, 'sdm_item_show_file_size_fd', true );
460
+ $sdm_item_show_item_version_fd = get_post_meta( $post->ID, 'sdm_item_show_item_version_fd', true );
461
+
462
+ $file_size = get_post_meta( $post->ID, 'sdm_item_file_size', true );
463
+ $file_size = isset( $file_size ) ? $file_size : '';
464
 
465
+ $version = get_post_meta( $post->ID, 'sdm_item_version', true );
466
+ $version = isset( $version ) ? $version : '';
467
+
468
+ $download_button_text = get_post_meta( $post->ID, 'sdm_download_button_text', true );
469
+ $download_button_text = isset( $download_button_text ) ? $download_button_text : '';
470
 
 
 
 
 
 
 
471
  echo '<div class="sdm-download-edit-filesize">';
472
+ echo '<strong>' . __( 'File Size: ', 'simple-download-monitor' ) . '</strong>';
473
  echo '<br />';
474
+ echo ' <input type="text" name="sdm_item_file_size" value="' . esc_attr( $file_size ) . '" size="20" />';
475
+ echo '<p class="description">' . __( 'Enter the size of this file (example value: 2.15 MB).', 'simple-download-monitor' ) . '</p>';
476
+ echo '<div class="sdm-download-edit-show-file-size"> <input id="sdm_item_show_file_size_fd" type="checkbox" name="sdm_item_show_file_size_fd" value="yes"' . checked( true, $sdm_item_show_file_size_fd, false ) . ' />';
477
+ echo '<label for="sdm_item_show_file_size_fd">' . __( 'Show file size in fancy display.', 'simple-download-monitor' ) . '</label> </div>';
478
+ echo '</div>';
479
+ echo '<hr />';
480
 
481
  echo '<div class="sdm-download-edit-version">';
482
+ echo '<strong>' . __( 'Version: ', 'simple-download-monitor' ) . '</strong>';
483
  echo '<br />';
484
+ echo ' <input type="text" name="sdm_item_version" value="' . esc_attr( $version ) . '" size="20" />';
485
+ echo '<p class="description">' . __( 'Enter the version number for this item if any (example value: v2.5.10).', 'simple-download-monitor' ) . '</p>';
486
+ echo '<div class="sdm-download-edit-show-item-version"> <input id="sdm_item_show_item_version_fd" type="checkbox" name="sdm_item_show_item_version_fd" value="yes"' . checked( true, $sdm_item_show_item_version_fd, false ) . ' />';
487
+ echo '<label for="sdm_item_show_item_version_fd">' . __( 'Show version number in fancy display.', 'simple-download-monitor' ) . '</label> </div>';
488
  echo '</div>';
489
+ echo '<hr />';
490
+
491
+ echo '<div class="sdm-download-edit-show-publish-date">';
492
+ echo '<strong>' . __( 'Publish Date: ', 'simple-download-monitor' ) . '</strong>';
493
+ echo '<br /> <input id="sdm_item_show_date_fd" type="checkbox" name="sdm_item_show_date_fd" value="yes"' . checked( true, $show_date_fd, false ) . ' />';
494
+ echo '<label for="sdm_item_show_date_fd">' . __( 'Show download published date in fancy display.', 'simple-download-monitor' ) . '</label>';
495
+ echo '</div>';
496
+ echo '<hr />';
497
+
498
+ echo '<div class="sdm-download-edit-button-text">';
499
+ echo '<strong>' . __( 'Download Button Text: ', 'simple-download-monitor' ) . '</strong>';
500
+ echo '<br />';
501
+ echo "<input id='sdm-download-button-text' type='text' name='sdm_download_button_text' value='{$download_button_text}' />";
502
+ echo '<p class="description">' . __( 'You can use this field to customize the download now button text of this item.', 'simple-download-monitor' ) . '</p>';
503
+ echo '</div>';
504
+
505
+ wp_nonce_field( 'sdm_other_details_nonce', 'sdm_other_details_nonce_check' );
506
+ }
507
+
508
+ public function display_sdm_shortcode_meta_box( $post ) { //Shortcode metabox
509
+ _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' );
510
  echo '<br />';
511
  $shortcode_text = '[sdm_download id="' . $post->ID . '" fancy="0"]';
512
  echo "<input type='text' class='code' onfocus='this.select();' readonly='readonly' value='" . $shortcode_text . "' size='40'>";
513
  echo "<br /><br />";
514
 
515
+ _e( 'The following shortcode can be used to show a download counter for this item.', 'simple-download-monitor' );
516
  echo '<br />';
517
  $shortcode_text = '[sdm_download_counter id="' . $post->ID . '"]';
518
  echo "<input type='text' class='code' onfocus='this.select();' readonly='readonly' value='" . $shortcode_text . "' size='40'>";
519
 
520
  echo '<br /><br />';
521
+ _e( 'Read the full shortcode usage documentation <a href="https://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin" target="_blank">here</a>.', 'simple-download-monitor' );
522
  }
523
 
524
+ public function sdm_save_description_meta_data( $post_id ) { // Save Description metabox
525
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
526
  return;
527
  }
528
+ if ( ! isset( $_POST[ 'sdm_description_box_nonce_check' ] ) || ! wp_verify_nonce( $_POST[ 'sdm_description_box_nonce_check' ], 'sdm_description_box_nonce' ) ) {
529
  return;
530
  }
531
+ if ( isset( $_POST[ 'sdm_description' ] ) ) {
532
+ update_post_meta( $post_id, 'sdm_description', wp_kses_post( $_POST[ 'sdm_description' ] ) );
533
  }
534
  }
535
 
536
+ public function sdm_save_upload_meta_data( $post_id ) { // Save File Upload metabox
537
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
538
  return;
539
+ if ( ! isset( $_POST[ 'sdm_upload_box_nonce_check' ] ) || ! wp_verify_nonce( $_POST[ 'sdm_upload_box_nonce_check' ], 'sdm_upload_box_nonce' ) )
540
  return;
541
 
542
+ if ( isset( $_POST[ 'sdm_upload' ] ) ) {
543
+ update_post_meta( $post_id, 'sdm_upload', sanitize_text_field( $_POST[ 'sdm_upload' ] ) );
544
  }
545
  }
546
 
547
+ public function sdm_save_dispatch_meta_data( $post_id ) { // Save "Dispatch or Redirect" metabox
548
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
549
  return;
550
  }
551
+ if ( ! isset( $_POST[ 'sdm_dispatch_box_nonce_check' ] ) || ! wp_verify_nonce( $_POST[ 'sdm_dispatch_box_nonce_check' ], 'sdm_dispatch_box_nonce' ) ) {
552
  return;
553
  }
554
  // Get POST-ed data as boolean value
555
+ $value = filter_input( INPUT_POST, 'sdm_item_dispatch', FILTER_VALIDATE_BOOLEAN );
556
+ update_post_meta( $post_id, 'sdm_item_dispatch', $value );
557
  }
558
+
559
+ public function sdm_save_misc_properties_meta_data( $post_id ) {
560
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
561
  return;
562
  }
563
+ if ( ! isset( $_POST[ 'sdm_misc_properties_box_nonce_check' ] ) || ! wp_verify_nonce( $_POST[ 'sdm_misc_properties_box_nonce_check' ], 'sdm_misc_properties_box_nonce' ) ) {
564
  return;
565
  }
566
  // Get POST-ed data as boolean value
567
+ $new_window_open = filter_input( INPUT_POST, 'sdm_item_new_window', FILTER_VALIDATE_BOOLEAN );
568
 
569
+ update_post_meta( $post_id, 'sdm_item_new_window', $new_window_open );
570
  }
571
 
572
+ public function sdm_save_thumbnail_meta_data( $post_id ) { // Save Thumbnail Upload metabox
573
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
574
  return;
575
  }
576
+ if ( ! isset( $_POST[ 'sdm_thumbnail_box_nonce_check' ] ) || ! wp_verify_nonce( $_POST[ 'sdm_thumbnail_box_nonce_check' ], 'sdm_thumbnail_box_nonce' ) ) {
577
  return;
578
  }
579
+ if ( isset( $_POST[ 'sdm_upload_thumbnail' ] ) ) {
580
+ update_post_meta( $post_id, 'sdm_upload_thumbnail', sanitize_text_field( $_POST[ 'sdm_upload_thumbnail' ] ) );
581
  }
582
  }
583
 
584
+ public function sdm_save_statistics_meta_data( $post_id ) { // Save Statistics Upload metabox
585
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
586
  return;
587
  }
588
+ if ( ! isset( $_POST[ 'sdm_count_offset_nonce_check' ] ) || ! wp_verify_nonce( $_POST[ 'sdm_count_offset_nonce_check' ], 'sdm_count_offset_nonce' ) ) {
589
  return;
590
  }
591
+ if ( isset( $_POST[ 'sdm_count_offset' ] ) && is_numeric( $_POST[ 'sdm_count_offset' ] ) ) {
592
+ update_post_meta( $post_id, 'sdm_count_offset', intval( $_POST[ 'sdm_count_offset' ] ) );
593
  }
594
 
595
  // Checkbox for disabling download logging for this item
596
+ if ( isset( $_POST[ 'sdm_item_no_log' ] ) ) {
597
+ update_post_meta( $post_id, 'sdm_item_no_log', sanitize_text_field( $_POST[ 'sdm_item_no_log' ] ) );
598
  } else {
599
+ delete_post_meta( $post_id, 'sdm_item_no_log' );
600
  }
601
  }
602
 
603
+ public function sdm_save_other_details_meta_data( $post_id ) { // Save Statistics Upload metabox
604
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
605
  return;
606
  }
607
+ if ( ! isset( $_POST[ 'sdm_other_details_nonce_check' ] ) || ! wp_verify_nonce( $_POST[ 'sdm_other_details_nonce_check' ], 'sdm_other_details_nonce' ) ) {
608
  return;
609
  }
610
 
611
+ $show_date_fd = filter_input( INPUT_POST, 'sdm_item_show_date_fd', FILTER_VALIDATE_BOOLEAN );
612
+ update_post_meta( $post_id, 'sdm_item_show_date_fd', $show_date_fd );
613
+
614
+ $sdm_item_show_file_size_fd = filter_input( INPUT_POST, 'sdm_item_show_file_size_fd', FILTER_VALIDATE_BOOLEAN );
615
+ update_post_meta( $post_id, 'sdm_item_show_file_size_fd', $sdm_item_show_file_size_fd );
616
 
617
+ $sdm_item_show_item_version_fd = filter_input( INPUT_POST, 'sdm_item_show_item_version_fd', FILTER_VALIDATE_BOOLEAN );
618
+ update_post_meta( $post_id, 'sdm_item_show_item_version_fd', $sdm_item_show_item_version_fd );
619
+
620
+ if ( isset( $_POST[ 'sdm_item_file_size' ] ) ) {
621
+ update_post_meta( $post_id, 'sdm_item_file_size', sanitize_text_field( $_POST[ 'sdm_item_file_size' ] ) );
622
+ }
623
 
624
+ if ( isset( $_POST[ 'sdm_item_version' ] ) ) {
625
+ update_post_meta( $post_id, 'sdm_item_version', sanitize_text_field( $_POST[ 'sdm_item_version' ] ) );
 
 
 
626
  }
627
 
628
+ if ( isset( $_POST[ 'sdm_download_button_text' ] ) ) {
629
+ update_post_meta( $post_id, 'sdm_download_button_text', sanitize_text_field( $_POST[ 'sdm_download_button_text' ] ) );
630
  }
 
 
 
 
 
631
  }
632
 
633
+ public function sdm_remove_view_link_cpt( $action, $post ) {
634
 
635
  // Only execute on SDM CPT posts page
636
+ if ( $post->post_type == 'sdm_downloads' ) {
637
+ unset( $action[ 'view' ] );
638
  }
639
 
640
  return $action;
643
  public function sdm_register_options() {
644
 
645
  //Register the main setting
646
+ register_setting( 'sdm_downloads_options', 'sdm_downloads_options' );
647
+
648
+ /* * ************************** */
649
+ /* General Settings Section */
650
+ /* * ************************** */
651
 
 
 
 
 
652
  //Add all the settings section that will go under the main settings
653
+ add_settings_section( 'general_options', __( 'General Options', 'simple-download-monitor' ), array( $this, 'general_options_cb' ), 'general_options_section' );
654
+ add_settings_section( 'admin_options', __( 'Admin Options', 'simple-download-monitor' ), array( $this, 'admin_options_cb' ), 'admin_options_section' );
655
+
656
+ add_settings_section( 'sdm_colors', __( 'Colors', 'simple-download-monitor' ), array( $this, 'sdm_colors_cb' ), 'sdm_colors_section' );
657
+ add_settings_section( 'sdm_debug', __( 'Debug', 'simple-download-monitor' ), array( $this, 'sdm_debug_cb' ), 'sdm_debug_section' );
658
+ add_settings_section( 'sdm_deldata', __( 'Delete Plugin Data', 'simple-download-monitor' ), array( $this, 'sdm_deldata_cb' ), 'sdm_deldata_section' );
659
+
660
  //Add all the individual settings fields that goes under the sections
661
+ add_settings_field( 'general_hide_donwload_count', __( 'Hide Download Count', 'simple-download-monitor' ), array( $this, 'hide_download_count_cb' ), 'general_options_section', 'general_options' );
662
+ add_settings_field( 'general_default_dispatch_value', __( 'PHP Dispatching', 'simple-download-monitor' ), array( $this, 'general_default_dispatch_value_cb' ), 'general_options_section', 'general_options' );
663
+ 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' );
664
+ add_settings_field( 'general_login_page_url', __( 'Login Page URL', 'simple-download-monitor' ), array( $this, 'general_login_page_url_cb' ), 'general_options_section', 'general_options' );
665
+
666
+ add_settings_field( 'admin_tinymce_button', __( 'Remove Tinymce Button', 'simple-download-monitor' ), array( $this, 'admin_tinymce_button_cb' ), 'admin_options_section', 'admin_options' );
667
+ add_settings_field( 'admin_log_unique', __( 'Log Unique IP', 'simple-download-monitor' ), array( $this, 'admin_log_unique' ), 'admin_options_section', 'admin_options' );
668
+ add_settings_field( 'admin_do_not_capture_ip', __( 'Do Not Capture IP Address', 'simple-download-monitor' ), array( $this, 'admin_do_not_capture_ip' ), 'admin_options_section', 'admin_options' );
669
+ add_settings_field( 'admin_dont_log_bots', __( 'Do Not Count Downloads from Bots', 'simple-download-monitor' ), array( $this, 'admin_dont_log_bots' ), 'admin_options_section', 'admin_options' );
670
+ add_settings_field( 'admin_no_logs', __( 'Disable Download Logs', 'simple-download-monitor' ), array( $this, 'admin_no_logs_cb' ), 'admin_options_section', 'admin_options' );
671
+
672
+ add_settings_field( 'download_button_color', __( 'Download Button Color', 'simple-download-monitor' ), array( $this, 'download_button_color_cb' ), 'sdm_colors_section', 'sdm_colors' );
673
+
674
+ add_settings_field( 'enable_debug', __( 'Enable Debug', 'simple-download-monitor' ), array( $this, 'enable_debug_cb' ), 'sdm_debug_section', 'sdm_debug' );
675
+
676
+ /* * ************************** */
677
+ /* Advanced Settings Section */
678
+ /* * ************************** */
679
+ //Add the advanced settings section
680
+ add_settings_section( 'recaptcha_options', __( 'Google Captcha (reCAPTCHA)', 'simple-download-monitor' ), array( $this, 'recaptcha_options_cb' ), 'recaptcha_options_section' );
681
+ add_settings_section( 'termscond_options', __( 'Terms and Conditions', 'simple-download-monitor' ), array( $this, 'termscond_options_cb' ), 'termscond_options_section' );
682
+ add_settings_section( 'adsense_options', __( 'Adsense/Ad Insertion', 'simple-download-monitor' ), array( $this, 'adsense_options_cb' ), 'adsense_options_section' );
683
+
684
+ //Add reCAPTCHA section fields
685
+ add_settings_field( 'recaptcha_enable', __( 'Enable reCAPTCHA', 'simple-download-monitor' ), array( $this, 'recaptcha_enable_cb' ), 'recaptcha_options_section', 'recaptcha_options' );
686
+ add_settings_field( 'recaptcha_site_key', __( 'Site Key', 'simple-download-monitor' ), array( $this, 'recaptcha_site_key_cb' ), 'recaptcha_options_section', 'recaptcha_options' );
687
+ add_settings_field( 'recaptcha_secret_key', __( 'Secret Key', 'simple-download-monitor' ), array( $this, 'recaptcha_secret_key_cb' ), 'recaptcha_options_section', 'recaptcha_options' );
688
+
689
+ //Add Terms & Condition section fields
690
+ add_settings_field( 'termscond_enable', __( 'Enable Terms and Conditions', 'simple-download-monitor' ), array( $this, 'termscond_enable_cb' ), 'termscond_options_section', 'termscond_options' );
691
+ add_settings_field( 'termscond_url', __( 'Terms Page URL', 'simple-download-monitor' ), array( $this, 'termscond_url_cb' ), 'termscond_options_section', 'termscond_options' );
692
+
693
+ //Add Adsense section fields
694
+ add_settings_field( 'adsense_below_description', __( 'Below Download Description', 'simple-download-monitor' ), array( $this, 'adsense_below_description_cb' ), 'adsense_options_section', 'adsense_options' );
 
695
  }
696
 
697
  public function general_options_cb() {
698
  //Set the message that will be shown below the general options settings heading
699
+ _e( 'General options settings', 'simple-download-monitor' );
700
  }
701
 
702
  public function admin_options_cb() {
703
  //Set the message that will be shown below the admin options settings heading
704
+ _e( 'Admin options settings', 'simple-download-monitor' );
705
  }
706
 
707
  public function sdm_colors_cb() {
708
  //Set the message that will be shown below the color options settings heading
709
+ _e( 'Front End colors settings', 'simple-download-monitor' );
710
  }
711
 
712
  public function sdm_debug_cb() {
713
  //Set the message that will be shown below the debug options settings heading
714
+ _e( 'Debug settings', 'simple-download-monitor' );
715
  }
716
 
717
  public function sdm_deldata_cb() {
718
  //Set the message that will be shown below the debug options settings heading
719
+ _e( 'You can delete all the data related to this plugin from database using the button below. Useful when you\'re uninstalling the plugin and don\'t want any leftovers remaining.', 'simple-download-monitor' );
720
+ echo '<p><b>' . __( 'Warning', 'simple-download-monitor' ) . ': </b> ' . __( 'this can\'t be undone. All settings, download items, download logs will be deleted.', 'simple-download-monitor' ) . '</p>';
721
+ echo '<p><button id="sdmDeleteData" class="button" style="color:red;">' . __( 'Delete all data and deactivate plugin', 'simple-download-monitor' ) . '</button></p>';
722
+ echo '<br />';
723
  }
724
 
725
  public function recaptcha_options_cb() {
726
  //Set the message that will be shown below the recaptcha options settings heading
727
+ _e( 'Google Captcha (reCAPTCHA) options', 'simple-download-monitor' );
728
  }
729
+
730
  public function termscond_options_cb() {
731
+
732
  }
733
+
734
  public function adsense_options_cb() {
735
  //Set the message that will be shown below the adsense/ad code settings heading
736
+ _e( 'You can use this section to insert adsense or other ad code inside the download item output', 'simple-download-monitor' );
737
  }
738
+
739
  public function recaptcha_enable_cb() {
740
+ $main_opts = get_option( 'sdm_advanced_options' );
741
+ echo '<input name="sdm_advanced_options[recaptcha_enable]" id="recaptcha_enable" type="checkbox" ' . checked( 1, isset( $main_opts[ 'recaptcha_enable' ] ), false ) . ' /> ';
742
+ echo '<p class="description">' . __( 'Check this box if you want to use <a href="https://www.google.com/recaptcha/admin" target="_blank">reCAPTCHA</a>. ', 'simple-download-monitor' ) . '</p>';
743
+ echo '<p class="description">' . __( 'The captcha option adds a captcha to the download now buttons.', 'simple-download-monitor' ) . '</p>';
744
  }
745
+
746
  public function recaptcha_site_key_cb() {
747
+ $main_opts = get_option( 'sdm_advanced_options' );
748
+ $value = isset( $main_opts[ 'recaptcha_site_key' ] ) ? $main_opts[ 'recaptcha_site_key' ] : '';
749
+ echo '<input size="100" name="sdm_advanced_options[recaptcha_site_key]" id="recaptcha_site_key" type="text" value="' . $value . '" /> ';
750
+ echo '<p class="description">' . __( 'The site key for the reCAPTCHA API', 'simple-download-monitor' ) . '</p>';
751
  }
752
+
753
  public function recaptcha_secret_key_cb() {
754
+ $main_opts = get_option( 'sdm_advanced_options' );
755
+ $value = isset( $main_opts[ 'recaptcha_secret_key' ] ) ? $main_opts[ 'recaptcha_secret_key' ] : '';
756
+ echo '<input size="100" name="sdm_advanced_options[recaptcha_secret_key]" id="recaptcha_secret_key" type="text" value="' . $value . '" /> ';
757
+ echo '<p class="description">' . __( 'The secret key for the reCAPTCHA API', 'simple-download-monitor' ) . '</p>';
758
  }
759
+
760
  public function hide_download_count_cb() {
761
+ $main_opts = get_option( 'sdm_downloads_options' );
762
+ echo '<input name="sdm_downloads_options[general_hide_donwload_count]" id="general_hide_download_count" type="checkbox" ' . checked( 1, isset( $main_opts[ 'general_hide_donwload_count' ] ), false ) . ' /> ';
763
+ echo '<label for="general_hide_download_count">' . __( 'Hide the download count that is shown in some of the fancy templates.', 'simple-download-monitor' ) . '</label>';
764
  }
765
 
766
  public function general_default_dispatch_value_cb() {
767
+ $main_opts = get_option( 'sdm_downloads_options' );
768
+ $value = isset( $main_opts[ 'general_default_dispatch_value' ] ) && $main_opts[ 'general_default_dispatch_value' ];
769
+ echo '<input name="sdm_downloads_options[general_default_dispatch_value]" id="general_default_dispatch_value" type="checkbox" value="1"' . checked( true, $value, false ) . ' />';
770
+ 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>';
771
  }
772
 
773
  public function general_only_logged_in_can_download_cb() {
774
+ $main_opts = get_option( 'sdm_downloads_options' );
775
+ $value = isset( $main_opts[ 'only_logged_in_can_download' ] ) && $main_opts[ 'only_logged_in_can_download' ];
776
+ 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 ) . ' />';
777
+ 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>';
778
  }
779
 
780
  public function general_login_page_url_cb() {
781
+ $main_opts = get_option( 'sdm_downloads_options' );
782
+ $value = isset( $main_opts[ 'general_login_page_url' ] ) ? $main_opts[ 'general_login_page_url' ] : '';
783
  echo '<input size="100" name="sdm_downloads_options[general_login_page_url]" id="general_login_page_url" type="text" value="' . $value . '" />';
784
+ echo '<p class="description">' . __( '(Optional) Specify a login page URL where users can login. This is useful if you only allow logged in users to be able to download. This link will be added to the message that is shown to anonymous users.', 'simple-download-monitor' ) . '</p>';
785
  }
786
 
787
  public function admin_tinymce_button_cb() {
788
+ $main_opts = get_option( 'sdm_downloads_options' );
789
+ 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 ) . ' /> ';
790
+ echo '<label for="admin_tinymce_button">' . __( 'Removes the SDM Downloads button from the WP content editor.', 'simple-download-monitor' ) . '</label>';
791
  }
792
 
793
  public function admin_log_unique() {
794
+ $main_opts = get_option( 'sdm_downloads_options' );
795
+ echo '<input name="sdm_downloads_options[admin_log_unique]" id="admin_log_unique" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts[ 'admin_log_unique' ] ), false ) . ' /> ';
796
+ echo '<label for="admin_log_unique">' . __( 'Only logs downloads from unique IP addresses.', 'simple-download-monitor' ) . '</label>';
797
  }
798
+
799
  public function admin_do_not_capture_ip() {
800
+ $main_opts = get_option( 'sdm_downloads_options' );
801
+ echo '<input name="sdm_downloads_options[admin_do_not_capture_ip]" id="admin_do_not_capture_ip" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts[ 'admin_do_not_capture_ip' ] ), false ) . ' /> ';
802
+ echo '<label for="admin_do_not_capture_ip">' . __( 'Use this if you do not want to capture the IP address and Country of the visitors when they download an item.', 'simple-download-monitor' ) . '</label>';
803
  }
804
 
805
  public function admin_dont_log_bots() {
806
+ $main_opts = get_option( 'sdm_downloads_options' );
807
+ echo '<input name="sdm_downloads_options[admin_dont_log_bots]" id="admin_dont_log_bots" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts[ 'admin_dont_log_bots' ] ), false ) . ' /> ';
808
+ echo '<label for="admin_dont_log_bots">' . __( 'When enabled, the plugin won\'t count and log downloads from bots.', 'simple-download-monitor' ) . '</label>';
809
  }
810
 
811
  public function admin_no_logs_cb() {
812
+ $main_opts = get_option( 'sdm_downloads_options' );
813
+ echo '<input name="sdm_downloads_options[admin_no_logs]" id="admin_no_logs" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts[ 'admin_no_logs' ] ), false ) . ' /> ';
814
+ echo '<label for="admin_no_logs">' . __( 'Disables all download logs. (This global option overrides the individual download item option.)', 'simple-download-monitor' ) . '</label>';
815
  }
816
 
817
  public function download_button_color_cb() {
818
+ $main_opts = get_option( 'sdm_downloads_options' );
819
  // Read current color class.
820
+ $color_opt = isset( $main_opts[ 'download_button_color' ] ) ? $main_opts[ 'download_button_color' ] : null;
821
+ $color_opts = sdm_get_download_button_colors();
822
 
823
  echo '<select name="sdm_downloads_options[download_button_color]" id="download_button_color" class="sdm_opts_ajax_dropdowns">';
824
+ foreach ( $color_opts as $color_class => $color_name ) {
825
+ echo '<option value="' . $color_class . '"' . selected( $color_class, $color_opt, false ) . '>' . $color_name . '</option>';
826
  }
827
  echo '</select> ';
828
+ esc_html_e( 'Adjusts the color of the "Download Now" button.', 'simple-download-monitor' );
829
  }
830
 
831
  public function enable_debug_cb() {
832
+ $main_opts = get_option( 'sdm_downloads_options' );
833
+ echo '<input name="sdm_downloads_options[enable_debug]" id="enable_debug" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts[ 'enable_debug' ] ), false ) . ' /> ';
834
+ echo '<label for="enable_debug">' . __( 'Check this option to enable debug logging.', 'simple-download-monitor' ) .
835
  '<p class="description"><a href="' . get_admin_url() . '?sdm-action=view_log" target="_blank">' .
836
+ __( 'Click here', 'simple-download-monitor' ) . '</a>' .
837
+ __( ' to view log file.', 'simple-download-monitor' ) . '<br>' .
838
+ '<a id="sdm-reset-log" href="#0" style="color: red">' . __( 'Click here', 'simple-download-monitor' ) . '</a>' .
839
+ __( ' to reset log file.', 'simple-download-monitor' ) . '</p></label>';
840
  }
841
 
842
  public function termscond_enable_cb() {
843
+ $main_opts = get_option( 'sdm_advanced_options' );
844
+ echo '<input name="sdm_advanced_options[termscond_enable]" id="termscond_enable" type="checkbox" ' . checked( 1, isset( $main_opts[ 'termscond_enable' ] ), false ) . ' /> ';
845
+ echo '<p class="description">' . __( 'You can use this option to make the visitors agree to your terms before they can download the item.', 'simple-download-monitor' ) . '</p>';
846
  }
847
+
848
  public function termscond_url_cb() {
849
+ $main_opts = get_option( 'sdm_advanced_options' );
850
+ $value = isset( $main_opts[ 'termscond_url' ] ) ? $main_opts[ 'termscond_url' ] : '';
851
+ echo '<input size="100" name="sdm_advanced_options[termscond_url]" id="termscond_url" type="text" value="' . $value . '" /> ';
852
+ echo '<p class="description">' . __( 'Enter the URL of your terms and conditions page.', 'simple-download-monitor' ) . '</p>';
853
  }
854
+
855
  public function adsense_below_description_cb() {
856
+ $main_opts = get_option( 'sdm_advanced_options' );
857
+ $value = isset( $main_opts[ 'adsense_below_description' ] ) ? $main_opts[ 'adsense_below_description' ] : '';
858
+ //echo '<input size="100" name="sdm_advanced_options[adsense_below_description]" id="adsense_below_description" type="text" value="'.$value.'" /> ';
859
+ echo '<textarea name="sdm_advanced_options[adsense_below_description]" id="adsense_below_description" rows="6" cols="60">' . $value . '</textarea>';
860
+ echo '<p class="description">' . __( 'Enter the Adsense or Ad code that you want to show below the download item description.', 'simple-download-monitor' ) . '</p>';
861
+ }
862
+
863
+ public function sdm_add_clone_record_btn( $action, $post ) {
864
  // Only execute on SDM CPT posts page
865
+ if ( $post->post_type == 'sdm_downloads' ) {
866
+ $action[ 'clone' ] = sprintf(
867
+ '<a href="%2$s" aria-label="%1$s">%1$s</a>', esc_html__( 'Clone', 'simple-download-monitor' ), $this->get_duplicate_url( $post->ID )
868
+ );
 
 
869
  }
870
  return $action;
871
  }
872
+
873
  /**
874
+ * Returns duplicate post URL
875
+ *
876
+ * @return string
877
+ */
878
+ public function get_duplicate_url( $post_id ) {
879
+ global $wp;
880
+ return add_query_arg( array(
881
+ 'action' => 'sdm_clone_post',
882
+ 'post' => $post_id,
883
+ 'ref' => urlencode( add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) ),
884
+ '_nonce' => wp_create_nonce( 'sdm_downloads' )
885
+ ), esc_url( admin_url( 'admin.php' ) )
886
+ );
887
  }
888
 
889
  public function sdm_action_clone_post() {
890
+
891
+ global $wpdb;
892
+ if ( ! ( isset( $_GET[ 'post' ] ) || isset( $_POST[ 'post' ] ) || ( isset( $_REQUEST[ 'action' ] ) && 'sdm_clone_post' == $_REQUEST[ 'action' ] ) ) ) {
893
+ wp_die( __( 'No post to duplicate has been supplied!', 'simple-download-monitor' ) );
894
+ }
895
+
896
+ /*
897
+ * Nonce verification
898
+ */
899
+ if ( ! isset( $_GET[ '_nonce' ] ) || ! wp_verify_nonce( $_GET[ '_nonce' ], 'sdm_downloads' ) )
900
+ return;
901
+
902
+ /*
903
+ * get the original post id
904
+ */
905
+ $post_id = (isset( $_GET[ 'post' ] ) ? absint( $_GET[ 'post' ] ) : absint( $_POST[ 'post' ] ) );
906
+ /*
907
+ * and all the original post data then
908
+ */
909
+ $post = get_post( $post_id );
910
+
911
+ /*
912
+ * if you don't want current user to be the new post author,
913
+ * then change next couple of lines to this: $new_post_author = $post->post_author;
914
+ */
915
+ $current_user = wp_get_current_user();
916
+ $new_post_author = $current_user->ID;
917
+
918
+ /*
919
+ * if post data exists, create the post duplicate
920
+ */
921
+ if ( isset( $post ) && $post != null ) {
922
+
923
+ /*
924
+ * new post data array
925
+ */
926
+ $args = array(
927
+ 'comment_status' => $post->comment_status,
928
+ 'ping_status' => $post->ping_status,
929
+ 'post_author' => $new_post_author,
930
+ 'post_content' => $post->post_content,
931
+ 'post_excerpt' => $post->post_excerpt,
932
+ 'post_name' => $post->post_name,
933
+ 'post_parent' => $post->post_parent,
934
+ 'post_password' => $post->post_password,
935
+ 'post_status' => 'draft',
936
+ 'post_title' => $post->post_title,
937
+ 'post_type' => $post->post_type,
938
+ 'to_ping' => $post->to_ping,
939
+ 'menu_order' => $post->menu_order
940
+ );
941
+
942
+ /*
943
+ * insert the post by wp_insert_post() function
944
+ */
945
+ $new_post_id = wp_insert_post( $args );
946
+
947
+ /*
948
+ * get all current post terms ad set them to the new post draft
949
+ */
950
+ $taxonomies = get_object_taxonomies( $post->post_type ); // returns array of taxonomy names for post type, ex array("category", "post_tag");
951
+ foreach ( $taxonomies as $taxonomy ) {
952
+ $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
953
+ wp_set_object_terms( $new_post_id, $post_terms, $taxonomy, false );
954
+ }
955
+
956
+ /*
957
+ * duplicate all post meta just in two SQL queries
958
+ */
959
+ $post_meta_infos = $wpdb->get_results( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id" );
960
+ if ( count( $post_meta_infos ) != 0 ) {
961
+ $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
962
+ foreach ( $post_meta_infos as $meta_info ) {
963
+ $meta_key = $meta_info->meta_key;
964
+ if ( $meta_key == '_wp_old_slug' )
965
+ continue;
966
+ $meta_value = addslashes( $meta_info->meta_value );
967
+ $sql_query_sel[] = "SELECT $new_post_id, '$meta_key', '$meta_value'";
968
+ }
969
+ $sql_query .= implode( " UNION ALL ", $sql_query_sel );
970
+ $wpdb->query( $sql_query );
971
+ }
972
+
973
+ /*
974
+ * finally, redirect to the edit post screen for the new draft
975
+ */
976
+ wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
977
+ exit;
978
+ } else {
979
+ wp_die( __( 'Post creation failed, could not find original post: ', 'simple-download-monitor' ) . $post_id );
980
+ }
981
  }
982
+
983
  }
984
 
985
  //End of simpleDownloadManager class
987
  $simpleDownloadManager = new simpleDownloadManager();
988
 
989
  // Tinymce Button Populate Post ID's
990
+ add_action( 'wp_ajax_nopriv_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
991
+ add_action( 'wp_ajax_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
992
 
993
  function sdm_tiny_get_post_ids_ajax_call() {
994
 
995
+ $posts = get_posts( array(
996
+ 'post_type' => 'sdm_downloads',
997
+ 'numberposts' => -1,
998
+ )
999
  );
1000
+ foreach ( $posts as $item ) {
1001
+ $test[] = array( 'post_id' => $item->ID, 'post_title' => $item->post_title );
1002
  }
1003
 
1004
+ $response = json_encode( array( 'success' => true, 'test' => $test ) );
1005
 
1006
+ header( 'Content-Type: application/json' );
1007
  echo $response;
1008
  exit;
1009
  }
1010
 
1011
  //Remove Thumbnail Image
1012
  //add_action('wp_ajax_nopriv_sdm_remove_thumbnail_image', '');//This is only available to logged-in users
1013
+ add_action( 'wp_ajax_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call' ); //Execute this for authenticated users only
1014
 
1015
  function sdm_remove_thumbnail_image_ajax_call() {
1016
+ if ( ! current_user_can( 'edit_posts' ) ) {
1017
  //Permission denied
1018
+ wp_die( __( 'Permission denied!', 'simple-download-monitor' ) );
1019
  exit;
1020
  }
1021
 
1022
  //Go ahead with the thumbnail removal
1023
+ $post_id = intval( $_POST[ 'post_id_del' ] );
1024
+ $key_exists = metadata_exists( 'post', $post_id, 'sdm_upload_thumbnail' );
1025
+ if ( $key_exists ) {
1026
+ $success = delete_post_meta( $post_id, 'sdm_upload_thumbnail' );
1027
+ if ( $success ) {
1028
+ $response = json_encode( array( 'success' => true ) );
1029
  }
1030
  } else {
1031
  // in order for frontend script to not display "Ajax error", let's return some data
1032
+ $response = json_encode( array( 'not_exists' => true ) );
1033
  }
1034
 
1035
+ header( 'Content-Type: application/json' );
1036
  echo $response;
1037
  exit;
1038
  }
1039
 
1040
  // Populate category tree
1041
+ add_action( 'wp_ajax_nopriv_sdm_pop_cats', 'sdm_pop_cats_ajax_call' );
1042
+ add_action( 'wp_ajax_sdm_pop_cats', 'sdm_pop_cats_ajax_call' );
1043
 
1044
  function sdm_pop_cats_ajax_call() {
1045
 
1046
+ $cat_slug = sanitize_text_field( $_POST[ 'cat_slug' ] ); // Get button cpt slug
1047
+ $parent_id = intval( $_POST[ 'parent_id' ] ); // Get button cpt id
 
1048
  // Query custom posts based on taxonomy slug
1049
+ $posts = get_posts( array(
1050
+ 'post_type' => 'sdm_downloads',
1051
+ 'numberposts' => -1,
1052
+ 'tax_query' => array(
1053
  array(
1054
+ 'taxonomy' => 'sdm_categories',
1055
+ 'field' => 'slug',
1056
+ 'terms' => $cat_slug,
1057
+ 'include_children' => 0
1058
  )
1059
  ),
1060
+ 'orderby' => 'title',
1061
+ 'order' => 'ASC' )
1062
  );
1063
 
1064
  $final_array = array();
1065
 
1066
  // Loop results
1067
+ foreach ( $posts as $post ) {
1068
  // Create array of variables to pass to js
1069
+ $final_array[] = array( 'id' => $post->ID, 'permalink' => get_permalink( $post->ID ), 'title' => $post->post_title );
1070
  }
1071
 
1072
  // Generate ajax response
1073
+ $response = json_encode( array( 'final_array' => $final_array ) );
1074
+ header( 'Content-Type: application/json' );
1075
  echo $response;
1076
  exit;
1077
  }
1079
  /*
1080
  * * Setup Sortable Columns
1081
  */
1082
+ add_filter( 'manage_edit-sdm_downloads_columns', 'sdm_create_columns' ); // Define columns
1083
+ add_filter( 'manage_edit-sdm_downloads_sortable_columns', 'sdm_downloads_sortable' ); // Make sortable
1084
+ add_action( 'manage_sdm_downloads_posts_custom_column', 'sdm_downloads_columns_content', 10, 2 ); // Populate new columns
1085
+
1086
+ function sdm_create_columns( $cols ) {
1087
+
1088
+ unset( $cols[ 'title' ] );
1089
+ unset( $cols[ 'taxonomy-sdm_tags' ] );
1090
+ unset( $cols[ 'taxonomy-sdm_categories' ] );
1091
+ unset( $cols[ 'date' ] );
1092
+
1093
+ $cols[ 'title' ] = __( 'Title', 'simple-download-monitor' );
1094
+ $cols[ 'sdm_downloads_thumbnail' ] = __( 'Image', 'simple-download-monitor' );
1095
+ $cols[ 'sdm_downloads_id' ] = __( 'ID', 'simple-download-monitor' );
1096
+ $cols[ 'sdm_downloads_file' ] = __( 'File', 'simple-download-monitor' );
1097
+ $cols[ 'taxonomy-sdm_categories' ] = __( 'Categories', 'simple-download-monitor' );
1098
+ $cols[ 'taxonomy-sdm_tags' ] = __( 'Tags', 'simple-download-monitor' );
1099
+ $cols[ 'sdm_downloads_count' ] = __( 'Downloads', 'simple-download-monitor' );
1100
+ $cols[ 'date' ] = __( 'Date Posted', 'simple-download-monitor' );
1101
  return $cols;
1102
  }
1103
 
1104
+ function sdm_downloads_sortable( $cols ) {
1105
 
1106
+ $cols[ 'sdm_downloads_id' ] = 'sdm_downloads_id';
1107
+ $cols[ 'sdm_downloads_file' ] = 'sdm_downloads_file';
1108
+ $cols[ 'sdm_downloads_count' ] = 'sdm_downloads_count';
1109
+ $cols[ 'taxonomy-sdm_categories' ] = 'taxonomy-sdm_categories';
1110
+ $cols[ 'taxonomy-sdm_tags' ] = 'taxonomy-sdm_tags';
1111
  return $cols;
1112
  }
1113
 
1114
+ function sdm_downloads_columns_content( $column_name, $post_ID ) {
1115
 
1116
+ if ( $column_name == 'sdm_downloads_thumbnail' ) {
1117
+ $old_thumbnail = get_post_meta( $post_ID, 'sdm_upload_thumbnail', true );
1118
  //$old_value = isset($old_thumbnail) ? $old_thumbnail : '';
1119
+ if ( $old_thumbnail ) {
1120
  echo '<p class="sdm_downloads_thumbnail_in_admin_listing"><img src="' . $old_thumbnail . '" style="width:50px;height:50px;" /></p>';
1121
  }
1122
  }
1123
+ if ( $column_name == 'sdm_downloads_id' ) {
1124
  echo '<p class="sdm_downloads_postid">' . $post_ID . '</p>';
1125
  }
1126
+ if ( $column_name == 'sdm_downloads_file' ) {
1127
+ $old_file = get_post_meta( $post_ID, 'sdm_upload', true );
1128
+ $file = isset( $old_file ) ? $old_file : '--';
1129
  echo '<p class="sdm_downloads_file">' . $file . '</p>';
1130
  }
1131
+ if ( $column_name == 'sdm_downloads_count' ) {
1132
  global $wpdb;
1133
+ $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post_ID ) );
1134
  echo '<p class="sdm_downloads_count">' . $wpdb->num_rows . '</p>';
1135
  }
1136
  }
1140
  */
1141
 
1142
  // First check if option is checked to disable tinymce button
1143
+ $main_option = get_option( 'sdm_downloads_options' );
1144
+ $tiny_button_option = isset( $main_option[ 'admin_tinymce_button' ] );
1145
+ if ( $tiny_button_option != true ) {
1146
 
1147
  // Okay.. we're good. Add the button.
1148
+ add_action( 'init', 'sdm_downloads_tinymce_button' );
1149
 
1150
  function sdm_downloads_tinymce_button() {
1151
 
1152
+ add_filter( 'mce_external_plugins', 'sdm_downloads_add_button' );
1153
+ add_filter( 'mce_buttons', 'sdm_downloads_register_button' );
1154
  }
1155
 
1156
+ function sdm_downloads_add_button( $plugin_array ) {
1157
 
1158
+ $plugin_array[ 'sdm_downloads' ] = WP_SIMPLE_DL_MONITOR_URL . '/tinymce/sdm_editor_plugin.js';
1159
  return $plugin_array;
1160
  }
1161
 
1162
+ function sdm_downloads_register_button( $buttons ) {
1163
 
1164
  $buttons[] = 'sdm_downloads';
1165
  return $buttons;
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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: 5.2
7
- Stable tag: 3.7.4.2
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
@@ -185,6 +185,9 @@ For screenshots please visit the [download monitor plugin page](https://www.tips
185
 
186
  == Changelog ==
187
 
 
 
 
188
  = 3.7.4.2 =
189
  - Fixed [sdm_popular_downloads] shortcode was ignoring button_text parameter for fancy 1 and fancy 2 templates.
190
 
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: 5.2
7
+ Stable tag: 3.7.5
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
185
 
186
  == Changelog ==
187
 
188
+ = 3.7.5 =
189
+ - Added an option to configure "after download redirect" in the hidden downloads addon.
190
+
191
  = 3.7.4.2 =
192
  - Fixed [sdm_popular_downloads] shortcode was ignoring button_text parameter for fancy 1 and fancy 2 templates.
193
 
sdm-post-type-content-handler.php CHANGED
@@ -1,81 +1,81 @@
1
  <?php
2
 
3
  //Handles the output on the SDM individual download page (Custom Post Type)
4
- add_filter('the_content', 'filter_sdm_post_type_content');
5
 
6
- function filter_sdm_post_type_content($content) {
7
  global $post;
8
- if (isset($post->post_type) && $post->post_type == "sdm_downloads") {//Handle the content for sdm_downloads type post
9
- //$download_id = $post->ID;
10
- //$args = array('id' => $download_id, 'fancy' => '1');
11
- //$content = sdm_create_download_shortcode($args);
12
- $id = $post->ID;
13
-
14
- //Check to see if the download link cpt is password protected
15
- $get_cpt_object = get_post($id);
16
- $cpt_is_password = !empty($get_cpt_object->post_password) ? 'yes' : 'no'; // yes = download is password protected;
17
- //Get item thumbnail
18
- $item_download_thumbnail = get_post_meta($id, 'sdm_upload_thumbnail', true);
19
- $isset_download_thumbnail = isset($item_download_thumbnail) && !empty($item_download_thumbnail) ? '<img class="sdm_post_thumbnail_image" src="' . $item_download_thumbnail . '" />' : '';
20
-
21
- //Get item title
22
- $item_title = get_the_title($id);
23
- $isset_item_title = isset($item_title) && !empty($item_title) ? $item_title : '';
24
-
25
- //Get item description
26
- $isset_item_description = sdm_get_item_description_output($id);
27
-
28
- //$isset_item_description = apply_filters('the_content', $isset_item_description);
29
- //Get item file size
30
- $item_file_size = get_post_meta($id, 'sdm_item_file_size', true);
31
- $isset_item_file_size = isset($item_file_size) ? $item_file_size : '';
32
-
33
- //Get item version
34
- $item_version = get_post_meta($id, 'sdm_item_version', true);
35
- $isset_item_version = isset($item_version) ? $item_version : '';
36
-
37
- //Check if show published date is enabled
38
- $show_date_fd = get_post_meta($id, 'sdm_item_show_date_fd', true);
39
- //Get published date
40
- $published_date = get_the_date(get_option('date_format'), $id);
41
-
42
- // See if user color option is selected
43
- $main_opts = get_option('sdm_downloads_options');
44
- $color_opt = $main_opts['download_button_color'];
45
- $def_color = isset($color_opt) ? str_replace(' ', '', strtolower($color_opt)) : __('green', 'simple-download-monitor');
46
-
47
- //Download counter
48
- //$dl_counter = sdm_create_counter_shortcode(array('id'=>$id));
49
- //*** Generate the download now button code ***
50
- $button_text_string = sdm_get_default_download_button_text($post->ID);
51
-
52
- // See if new window parameter is set
53
- $new_window = get_post_meta( $id, 'sdm_item_new_window', true );
54
- $window_target = empty($new_window) ? '_self' : '_blank';
55
-
56
- $homepage = get_bloginfo('url');
57
- $download_url = $homepage . '/?smd_process_download=1&download_id=' . $id;
58
- $download_button_code = '<a href="' . $download_url . '" class="sdm_download ' . $def_color . '" title="' . $isset_item_title . '" target="' . $window_target . '">' . $button_text_string . '</a>';
59
-
60
- $main_advanced_opts = get_option('sdm_advanced_options');
61
-
62
- //Check if Terms & Condition enabled
63
- $termscond_enable = isset($main_advanced_opts['termscond_enable']) ? true : false;
64
- if ($termscond_enable) {
65
- $download_button_code = sdm_get_download_form_with_termsncond($id, array(),'sdm_download ' . $def_color);
66
- }
67
-
68
- //Check if reCAPTCHA enabled
69
- $recaptcha_enable = isset($main_advanced_opts['recaptcha_enable']) ? true : false;
70
- if ($recaptcha_enable && $cpt_is_password == 'no') {
71
- $download_button_code = sdm_get_download_form_with_recaptcha($id, array(),'sdm_download ' . $def_color);
72
- }
73
-
74
- if ($cpt_is_password !== 'no') {//This is a password protected download so replace the download now button with password requirement
75
- $download_button_code = sdm_get_password_entry_form($id, array(),'sdm_download ' . $def_color);
76
- }
77
-
78
- // Check if we only allow the download for logged-in users
79
  // if (isset($main_opts['only_logged_in_can_download'])) {
80
  // if ($main_opts['only_logged_in_can_download'] && sdm_get_logged_in_user()===false) {
81
  // // User not logged in, let's display the message
@@ -83,98 +83,97 @@ function filter_sdm_post_type_content($content) {
83
  // }
84
  // }
85
 
86
- $db_count = sdm_get_download_count_for_post($id);
87
- $string = ($db_count == '1') ? __('Download', 'simple-download-monitor') : __('Downloads', 'simple-download-monitor');
88
- $download_count_string = '<span class="sdm_post_count_number">' . $db_count . '</span><span class="sdm_post_count_string"> ' . $string . '</span>';
89
 
90
- //Output the download item details
91
- $content = '<div class="sdm_post_item">';
92
- $content .= '<div class="sdm_post_item_top">';
93
 
94
- $content .= '<div class="sdm_post_item_top_left">';
95
- $content .= '<div class="sdm_post_thumbnail">' . $isset_download_thumbnail . '</div>';
96
- $content .= '</div>'; //end .sdm_post_item_top_left
97
 
98
- $content .= '<div class="sdm_post_item_top_right">';
99
- $content .= '<div class="sdm_post_title">' . $isset_item_title . '</div>';
100
 
101
- if (!isset($main_opts['general_hide_donwload_count'])) {//The hide download count is enabled.
102
- $content .= '<div class="sdm_post_download_count">' . $download_count_string . '</div>';
103
- }
104
 
105
- $content .= '<div class="sdm_post_description">' . $isset_item_description . '</div>';
106
 
107
- //This hook can be used to add content below the description
108
- $content .= apply_filters('sdm_cpt_below_download_description','');
109
-
110
- $content .= '<div class="sdm_post_download_section"><div class="sdm_download_link">' . $download_button_code . '</div></div>';
111
 
112
- if (!empty($isset_item_file_size)) {//Show file size info
113
- $content .= '<div class="sdm_post_download_file_size">';
114
- $content .= '<span class="sdm_post_download_size_label">' . __('Size: ', 'simple-download-monitor') . '</span>';
115
- $content .= '<span class="sdm_post_download_size_value">' . $isset_item_file_size . '</span>';
116
- $content .= '</div>';
117
- }
118
 
119
- if (!empty($isset_item_version)) {//Show version info
120
- $content .= '<div class="sdm_post_download_version">';
121
- $content .= '<span class="sdm_post_download_version_label">' . __('Version: ', 'simple-download-monitor') . '</span>';
122
- $content .= '<span class="sdm_post_download_version_value">' . $isset_item_version . '</span>';
123
- $content .= '</div>';
124
- }
125
 
126
- if ($show_date_fd) {//Show Published date
127
- $content .= '<div class="sdm_post_download_published_date">';
128
- $content .= '<span class="sdm_post_download_published_date_label">' . __('Published: ', 'simple-download-monitor') . '</span>';
129
- $content .= '<span class="sdm_post_download_published_date_value">' . $published_date . '</span>';
130
- $content .= '</div>';
131
- }
132
 
133
- //$content .= '<div class="sdm_post_meta_section"></div>';//TODO - Show post meta (category and tags)
134
- $content .= '</div>'; //end .sdm_post_item_top_right
 
 
 
 
135
 
136
- $content .= '</div>'; //end of .sdm_download_item_top
 
137
 
138
- $content .= '<div style="clear:both;"></div>';
139
 
140
- $content .= '</div>'; //end .sdm_post_item
141
 
142
- return $content;
 
 
143
  }
144
 
145
  return $content;
146
  }
147
 
148
  //The following filters are applied to the output of the SDM description field.
149
- add_filter('sdm_downloads_description', 'do_shortcode' );
150
- add_filter('sdm_downloads_description', 'wptexturize' );
151
- add_filter('sdm_downloads_description', 'convert_smilies' );
152
- add_filter('sdm_downloads_description', 'convert_chars' );
153
- add_filter('sdm_downloads_description', 'wpautop' );
154
- add_filter('sdm_downloads_description', 'shortcode_unautop' );
155
- add_filter('sdm_downloads_description', 'prepend_attachment' );
156
-
157
- function sdm_get_item_description_output($id) {
158
- $item_description = get_post_meta($id, 'sdm_description', true);
159
- $isset_item_description = isset($item_description) && !empty($item_description) ? $item_description : '';
160
  //$isset_item_description = apply_filters('the_content', $isset_item_description);
161
-
162
  //Lets apply all the filters like do_shortcode, wptexturize, convert_smilies, wpautop etc.
163
- $filtered_item_description = apply_filters('sdm_downloads_description', $isset_item_description);
164
-
165
  return $filtered_item_description;
166
  }
167
 
168
  //Add adsense or ad code below the description (if applicable)
169
- add_filter('sdm_cpt_below_download_description', 'sdm_add_ad_code_below_description');
170
- add_filter('sdm_fancy1_below_download_description', 'sdm_add_ad_code_below_description');
171
-
172
- function sdm_add_ad_code_below_description($output){
173
- $main_advanced_opts = get_option('sdm_advanced_options');
174
- $adsense_below_desc = isset($main_advanced_opts['adsense_below_description']) ? $main_advanced_opts['adsense_below_description'] : '';
175
- if(!empty($adsense_below_desc)){
176
- //Ad code is configured in settings. Lets add it to the output.
177
- $output .= '<div class="sdm_below_description_ad_code">' . $adsense_below_desc . '</div>';
178
  }
179
  return $output;
180
- }
1
  <?php
2
 
3
  //Handles the output on the SDM individual download page (Custom Post Type)
4
+ add_filter( 'the_content', 'filter_sdm_post_type_content' );
5
 
6
+ function filter_sdm_post_type_content( $content ) {
7
  global $post;
8
+ if ( isset( $post->post_type ) && $post->post_type == "sdm_downloads" ) {//Handle the content for sdm_downloads type post
9
+ //$download_id = $post->ID;
10
+ //$args = array('id' => $download_id, 'fancy' => '1');
11
+ //$content = sdm_create_download_shortcode($args);
12
+ $id = $post->ID;
13
+
14
+ //Check to see if the download link cpt is password protected
15
+ $get_cpt_object = get_post( $id );
16
+ $cpt_is_password = ! empty( $get_cpt_object->post_password ) ? 'yes' : 'no'; // yes = download is password protected;
17
+ //Get item thumbnail
18
+ $item_download_thumbnail = get_post_meta( $id, 'sdm_upload_thumbnail', true );
19
+ $isset_download_thumbnail = isset( $item_download_thumbnail ) && ! empty( $item_download_thumbnail ) ? '<img class="sdm_post_thumbnail_image" src="' . $item_download_thumbnail . '" />' : '';
20
+
21
+ //Get item title
22
+ $item_title = get_the_title( $id );
23
+ $isset_item_title = isset( $item_title ) && ! empty( $item_title ) ? $item_title : '';
24
+
25
+ //Get item description
26
+ $isset_item_description = sdm_get_item_description_output( $id );
27
+
28
+ //$isset_item_description = apply_filters('the_content', $isset_item_description);
29
+ //Get item file size
30
+ $item_file_size = get_post_meta( $id, 'sdm_item_file_size', true );
31
+ $isset_item_file_size = isset( $item_file_size ) ? $item_file_size : '';
32
+
33
+ //Get item version
34
+ $item_version = get_post_meta( $id, 'sdm_item_version', true );
35
+ $isset_item_version = isset( $item_version ) ? $item_version : '';
36
+
37
+ //Check if show published date is enabled
38
+ $show_date_fd = get_post_meta( $id, 'sdm_item_show_date_fd', true );
39
+ //Get published date
40
+ $published_date = get_the_date( get_option( 'date_format' ), $id );
41
+
42
+ // See if user color option is selected
43
+ $main_opts = get_option( 'sdm_downloads_options' );
44
+ $color_opt = $main_opts[ 'download_button_color' ];
45
+ $def_color = isset( $color_opt ) ? str_replace( ' ', '', strtolower( $color_opt ) ) : __( 'green', 'simple-download-monitor' );
46
+
47
+ //Download counter
48
+ //$dl_counter = sdm_create_counter_shortcode(array('id'=>$id));
49
+ //*** Generate the download now button code ***
50
+ $button_text_string = sdm_get_default_download_button_text( $post->ID );
51
+
52
+ // See if new window parameter is set
53
+ $new_window = get_post_meta( $id, 'sdm_item_new_window', true );
54
+ $window_target = empty( $new_window ) ? '_self' : '_blank';
55
+
56
+ $homepage = get_bloginfo( 'url' );
57
+ $download_url = $homepage . '/?smd_process_download=1&download_id=' . $id;
58
+ $download_button_code = '<a href="' . $download_url . '" class="sdm_download ' . $def_color . '" title="' . $isset_item_title . '" target="' . $window_target . '">' . $button_text_string . '</a>';
59
+
60
+ $main_advanced_opts = get_option( 'sdm_advanced_options' );
61
+
62
+ //Check if Terms & Condition enabled
63
+ $termscond_enable = isset( $main_advanced_opts[ 'termscond_enable' ] ) ? true : false;
64
+ if ( $termscond_enable ) {
65
+ $download_button_code = sdm_get_download_form_with_termsncond( $id, array(), 'sdm_download ' . $def_color );
66
+ }
67
+
68
+ //Check if reCAPTCHA enabled
69
+ $recaptcha_enable = isset( $main_advanced_opts[ 'recaptcha_enable' ] ) ? true : false;
70
+ if ( $recaptcha_enable && $cpt_is_password == 'no' ) {
71
+ $download_button_code = sdm_get_download_form_with_recaptcha( $id, array(), 'sdm_download ' . $def_color );
72
+ }
73
+
74
+ if ( $cpt_is_password !== 'no' ) {//This is a password protected download so replace the download now button with password requirement
75
+ $download_button_code = sdm_get_password_entry_form( $id, array(), 'sdm_download ' . $def_color );
76
+ }
77
+
78
+ // Check if we only allow the download for logged-in users
79
  // if (isset($main_opts['only_logged_in_can_download'])) {
80
  // if ($main_opts['only_logged_in_can_download'] && sdm_get_logged_in_user()===false) {
81
  // // User not logged in, let's display the message
83
  // }
84
  // }
85
 
86
+ $db_count = sdm_get_download_count_for_post( $id );
87
+ $string = ($db_count == '1') ? __( 'Download', 'simple-download-monitor' ) : __( 'Downloads', 'simple-download-monitor' );
88
+ $download_count_string = '<span class="sdm_post_count_number">' . $db_count . '</span><span class="sdm_post_count_string"> ' . $string . '</span>';
89
 
90
+ //Output the download item details
91
+ $content = '<div class="sdm_post_item">';
92
+ $content .= '<div class="sdm_post_item_top">';
93
 
94
+ $content .= '<div class="sdm_post_item_top_left">';
95
+ $content .= '<div class="sdm_post_thumbnail">' . $isset_download_thumbnail . '</div>';
96
+ $content .= '</div>'; //end .sdm_post_item_top_left
97
 
98
+ $content .= '<div class="sdm_post_item_top_right">';
99
+ $content .= '<div class="sdm_post_title">' . $isset_item_title . '</div>';
100
 
101
+ if ( ! isset( $main_opts[ 'general_hide_donwload_count' ] ) ) {//The hide download count is enabled.
102
+ $content .= '<div class="sdm_post_download_count">' . $download_count_string . '</div>';
103
+ }
104
 
105
+ $content .= '<div class="sdm_post_description">' . $isset_item_description . '</div>';
106
 
107
+ //This hook can be used to add content below the description
108
+ $content .= apply_filters( 'sdm_cpt_below_download_description', '' );
 
 
109
 
110
+ $content .= '<div class="sdm_post_download_section"><div class="sdm_download_link">' . $download_button_code . '</div></div>';
 
 
 
 
 
111
 
112
+ if ( ! empty( $isset_item_file_size ) ) {//Show file size info
113
+ $content .= '<div class="sdm_post_download_file_size">';
114
+ $content .= '<span class="sdm_post_download_size_label">' . __( 'Size: ', 'simple-download-monitor' ) . '</span>';
115
+ $content .= '<span class="sdm_post_download_size_value">' . $isset_item_file_size . '</span>';
116
+ $content .= '</div>';
117
+ }
118
 
119
+ if ( ! empty( $isset_item_version ) ) {//Show version info
120
+ $content .= '<div class="sdm_post_download_version">';
121
+ $content .= '<span class="sdm_post_download_version_label">' . __( 'Version: ', 'simple-download-monitor' ) . '</span>';
122
+ $content .= '<span class="sdm_post_download_version_value">' . $isset_item_version . '</span>';
123
+ $content .= '</div>';
124
+ }
125
 
126
+ if ( $show_date_fd ) {//Show Published date
127
+ $content .= '<div class="sdm_post_download_published_date">';
128
+ $content .= '<span class="sdm_post_download_published_date_label">' . __( 'Published: ', 'simple-download-monitor' ) . '</span>';
129
+ $content .= '<span class="sdm_post_download_published_date_value">' . $published_date . '</span>';
130
+ $content .= '</div>';
131
+ }
132
 
133
+ //$content .= '<div class="sdm_post_meta_section"></div>';//TODO - Show post meta (category and tags)
134
+ $content .= '</div>'; //end .sdm_post_item_top_right
135
 
136
+ $content .= '</div>'; //end of .sdm_download_item_top
137
 
138
+ $content .= '<div style="clear:both;"></div>';
139
 
140
+ $content .= '</div>'; //end .sdm_post_item
141
+
142
+ return $content;
143
  }
144
 
145
  return $content;
146
  }
147
 
148
  //The following filters are applied to the output of the SDM description field.
149
+ add_filter( 'sdm_downloads_description', 'do_shortcode' );
150
+ add_filter( 'sdm_downloads_description', 'wptexturize' );
151
+ add_filter( 'sdm_downloads_description', 'convert_smilies' );
152
+ add_filter( 'sdm_downloads_description', 'convert_chars' );
153
+ add_filter( 'sdm_downloads_description', 'wpautop' );
154
+ add_filter( 'sdm_downloads_description', 'shortcode_unautop' );
155
+ add_filter( 'sdm_downloads_description', 'prepend_attachment' );
156
+
157
+ function sdm_get_item_description_output( $id ) {
158
+ $item_description = get_post_meta( $id, 'sdm_description', true );
159
+ $isset_item_description = isset( $item_description ) && ! empty( $item_description ) ? $item_description : '';
160
  //$isset_item_description = apply_filters('the_content', $isset_item_description);
 
161
  //Lets apply all the filters like do_shortcode, wptexturize, convert_smilies, wpautop etc.
162
+ $filtered_item_description = apply_filters( 'sdm_downloads_description', $isset_item_description );
163
+
164
  return $filtered_item_description;
165
  }
166
 
167
  //Add adsense or ad code below the description (if applicable)
168
+ add_filter( 'sdm_cpt_below_download_description', 'sdm_add_ad_code_below_description' );
169
+ add_filter( 'sdm_fancy1_below_download_description', 'sdm_add_ad_code_below_description' );
170
+
171
+ function sdm_add_ad_code_below_description( $output ) {
172
+ $main_advanced_opts = get_option( 'sdm_advanced_options' );
173
+ $adsense_below_desc = isset( $main_advanced_opts[ 'adsense_below_description' ] ) ? $main_advanced_opts[ 'adsense_below_description' ] : '';
174
+ if ( ! empty( $adsense_below_desc ) ) {
175
+ //Ad code is configured in settings. Lets add it to the output.
176
+ $output .= '<div class="sdm_below_description_ad_code">' . $adsense_below_desc . '</div>';
177
  }
178
  return $output;
179
+ }
sdm-shortcodes.php CHANGED
@@ -131,7 +131,8 @@ function sdm_create_download_shortcode( $atts ) {
131
  $output .= '<div class="sdm_clear_float"></div>';
132
  break;
133
  default: // Default output is the standard download now button (fancy 0)
134
- $output = '<div class="sdm_download_link">' . $download_button_code . '</div>';
 
135
  }
136
 
137
  return apply_filters( 'sdm_download_shortcode_output', $output, $atts );
131
  $output .= '<div class="sdm_clear_float"></div>';
132
  break;
133
  default: // Default output is the standard download now button (fancy 0)
134
+ include_once('includes/templates/fancy0/sdm-fancy-0.php');
135
+ $output .= sdm_generate_fancy0_display_output( $shortcode_atts );
136
  }
137
 
138
  return apply_filters( 'sdm_download_shortcode_output', $output, $atts );