Simple Download Monitor - Version 3.0

Version Description

  • Added an option to specify a download count offset for each download. This will allow you to set a starting download count for each item.
  • Added a new parameter in the shortcode to allow customization of the button text. You can now customize the "Download Now" button text to anything you want from the shortcode.
  • Added a new parameter in the shortcode to allow opening the download in a new window or tab.
Download this release

Release Info

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

Code changes from version 2.9 to 3.0

Files changed (4) hide show
  1. css/images/info.png +0 -0
  2. main.php +902 -861
  3. readme.txt +11 -2
  4. sdm-shortcodes.php +43 -6
css/images/info.png ADDED
Binary file
main.php CHANGED
@@ -3,14 +3,14 @@
3
  * Plugin Name: Simple Download Monitor
4
  * Plugin URI: http://www.tipsandtricks-hq.com/development-center
5
  * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
- * Version: 2.9
7
  * Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
8
  * Author URI: http://www.tipsandtricks-hq.com/development-center
9
  * License: GPL2
10
  */
11
  define('WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname(plugin_basename(__FILE__)));
12
- define('WP_SIMPLE_DL_MONITOR_URL', plugins_url('', __FILE__));
13
- define('WP_SIMPLE_DL_MONITOR_PATH', plugin_dir_path(__FILE__));
14
 
15
  global $sdm_db_version;
16
  $sdm_db_version = '1.1';
@@ -73,1024 +73,1065 @@ function sdm_plugins_loaded_tasks() {
73
  handle_sdm_download_via_direct_post();
74
  }
75
 
76
- /*
77
- * * Add a 'Settings' link to plugins list page
78
- */
79
- add_filter('plugin_action_links', 'sdm_settings_link', 10, 2);
80
-
81
  function sdm_settings_link($links, $file) {
82
- static $this_plugin;
83
- if (!$this_plugin)
84
- $this_plugin = plugin_basename(__FILE__);
85
- if ($file == $this_plugin) {
86
- $settings_link = '<a href="edit.php?post_type=sdm_downloads&page=settings" title="SDM Settings Page">' . __("Settings", 'sdm_lang') . '</a>';
87
- array_unshift($links, $settings_link);
88
- }
89
- return $links;
90
  }
91
-
92
  // Houston... we have lift-off!!
93
  class simpleDownloadManager {
94
-
95
- public function __construct() {
96
-
97
- add_action('init', array(&$this, 'sdm_register_post_type')); // Create 'sdm_downloads' custom post type
98
- add_action('init', array(&$this, 'sdm_create_taxonomies')); // Register 'tags' and 'categories' taxonomies
99
- add_action('init', 'sdm_register_shortcodes'); //Register the shortcodes
100
- add_action('wp_enqueue_scripts', array(&$this, 'sdm_frontend_scripts')); // Register frontend scripts
101
-
102
- if (is_admin()) {
103
- add_action('admin_menu', array(&$this, 'sdm_create_menu_pages')); // Create admin pages
104
- add_action('add_meta_boxes', array(&$this, 'sdm_create_upload_metabox')); // Create metaboxes
105
-
106
- add_action('save_post', array(&$this, 'sdm_save_description_meta_data')); // Save 'description' metabox
107
- add_action('save_post', array(&$this, 'sdm_save_upload_meta_data')); // Save 'upload file' metabox
108
- add_action('save_post', array(&$this, 'sdm_save_thumbnail_meta_data')); // Save 'thumbnail' metabox
109
-
110
- add_action('admin_enqueue_scripts', array(&$this, 'sdm_admin_scripts')); // Register admin scripts
111
- add_action('admin_print_styles', array(&$this, 'sdm_admin_styles')); // Register admin styles
112
-
113
- add_action('admin_init', array(&$this, 'sdm_register_options')); // Register admin options
114
-
115
- add_filter('post_row_actions', array(&$this, 'sdm_remove_view_link_cpt'), 10, 2); // Remove 'View' link in CPT view
116
- }
117
- }
118
-
119
- public function sdm_admin_scripts() {
120
-
121
- global $current_screen, $post;
122
-
123
- if (is_admin() && $current_screen->post_type == 'sdm_downloads' && $current_screen->base == 'post') {
124
-
125
- // These scripts are needed for the media upload thickbox
126
- wp_enqueue_script('media-upload');
127
- wp_enqueue_script('thickbox');
128
- wp_register_script('sdm-upload', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_admin_scripts.js', array('jquery', 'media-upload', 'thickbox'));
129
- wp_enqueue_script('sdm-upload');
130
-
131
- // Pass postID for thumbnail deletion
132
- ?>
133
- <script type="text/javascript">
134
- var sdm_del_thumb_postid = '<?php echo $post->ID; ?>';
135
- </script>
 
136
  <?php
137
- // Localize langauge strings used in js file
138
- $sdmTranslations = array(
139
- 'image_removed' => __('Image Successfully Removed', 'sdm_lang'),
140
- 'ajax_error' => __('Error with AJAX', 'sdm_lang')
141
- );
142
- wp_localize_script('sdm-upload', 'sdm_translations', $sdmTranslations);
143
- }
144
-
145
- // Pass admin ajax url
146
- ?>
147
- <script type="text/javascript">
148
- var sdm_admin_ajax_url = {sdm_admin_ajax_url: '<?php echo admin_url('admin-ajax.php?action=ajax'); ?>'};
149
- var sdm_plugin_url = '<?php echo plugins_url(); ?>';
150
- var tinymce_langs = {select_download_item: '<?php _e('Please select a Download Item:', 'sdm_lang') ?>', download_title: '<?php _e('Download Title', 'sdm_lang') ?>', include_fancy: '<?php _e('Include Fancy Box', 'sdm_lang') ?>', insert_shortcode: '<?php _e('Insert SDM Shortcode', 'sdm_lang') ?>'};
151
- </script>
152
- <?php
153
- }
154
-
155
- public function sdm_frontend_scripts() {
156
-
157
- // Pass language strings to frontend of WP for js usage
158
- ?>
159
- <script type="text/javascript">
160
- var sdm_frontend_translations = {incorrect_password: '<?php _e('Incorrect Password', 'sdm_lang') ?>'};
161
- </script>
162
- <?php
163
- }
164
-
165
- public function sdm_admin_styles() {
166
-
167
- wp_enqueue_style('thickbox'); // Needed for media upload thickbox
168
- wp_enqueue_style('sdm_admin_styles', WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_admin_styles.css'); // Needed for media upload thickbox
169
- }
170
-
171
- public function sdm_register_post_type() {
172
-
173
- //*****
174
- //***** Create 'sdm_downloads' Custom Post Type
175
- $labels = array(
176
- 'name' => __('Downloads', 'sdm_lang'),
177
- 'singular_name' => __('Downloads', 'sdm_lang'),
178
- 'add_new' => __('Add New', 'sdm_lang'),
179
- 'add_new_item' => __('Add New', 'sdm_lang'),
180
- 'edit_item' => __('Edit Download', 'sdm_lang'),
181
- 'new_item' => __('New Download', 'sdm_lang'),
182
- 'all_items' => __('Downloads', 'sdm_lang'),
183
- 'view_item' => __('View Download', 'sdm_lang'),
184
- 'search_items' => __('Search Downloads', 'sdm_lang'),
185
- 'not_found' => __('No Downloads found', 'sdm_lang'),
186
- 'not_found_in_trash' => __('No Downloads found in Trash', 'sdm_lang'),
187
- 'parent_item_colon' => __('', 'sdm_lang'),
188
- 'menu_name' => __('Downloads', 'sdm_lang')
189
- );
190
- $args = array(
191
- 'labels' => $labels,
192
- 'public' => true,
193
- 'publicly_queryable' => true,
194
- 'show_ui' => true,
195
- 'show_in_menu' => true,
196
- 'query_var' => true,
197
- 'rewrite' => array('slug' => 'sdm_downloads'),
198
- 'capability_type' => 'post',
199
- 'has_archive' => true,
200
- 'hierarchical' => false,
201
- 'menu_position' => null,
202
- 'menu_icon' => 'dashicons-download',
203
- 'supports' => array('title')
204
- );
205
- register_post_type('sdm_downloads', $args);
206
- }
207
-
208
- public function sdm_create_taxonomies() {
209
-
210
- //*****
211
- //***** Create CATEGORIES Taxonomy
212
- $labels_tags = array(
213
- 'name' => _x('Categories', 'sdm_lang'),
214
- 'singular_name' => _x('Category', 'sdm_lang'),
215
- 'search_items' => __('Search Categories', 'sdm_lang'),
216
- 'all_items' => __('All Categories', 'sdm_lang'),
217
- 'parent_item' => __('Categories Genre', 'sdm_lang'),
218
- 'parent_item_colon' => __('Categories Genre:', 'sdm_lang'),
219
- 'edit_item' => __('Edit Category', 'sdm_lang'),
220
- 'update_item' => __('Update Category', 'sdm_lang'),
221
- 'add_new_item' => __('Add New Category', 'sdm_lang'),
222
- 'new_item_name' => __('New Category', 'sdm_lang'),
223
- 'menu_name' => __('Categories', 'sdm_lang')
224
- );
225
- $args_tags = array(
226
- 'hierarchical' => true,
227
- 'labels' => $labels_tags,
228
- 'show_ui' => true,
229
- 'query_var' => true,
230
- 'rewrite' => array('slug' => 'sdm_categories'),
231
- 'show_admin_column' => true
232
- );
233
- register_taxonomy('sdm_categories', array('sdm_downloads'), $args_tags);
234
-
235
- //*****
236
- //***** Create TAGS Taxonomy
237
- $labels_tags = array(
238
- 'name' => _x('Tags', 'sdm_lang'),
239
- 'singular_name' => _x('Tag', 'sdm_lang'),
240
- 'search_items' => __('Search Tags', 'sdm_lang'),
241
- 'all_items' => __('All Tags', 'sdm_lang'),
242
- 'parent_item' => __('Tags Genre', 'sdm_lang'),
243
- 'parent_item_colon' => __('Tags Genre:', 'sdm_lang'),
244
- 'edit_item' => __('Edit Tag', 'sdm_lang'),
245
- 'update_item' => __('Update Tag', 'sdm_lang'),
246
- 'add_new_item' => __('Add New Tag', 'sdm_lang'),
247
- 'new_item_name' => __('New Tag', 'sdm_lang'),
248
- 'menu_name' => __('Tags', 'sdm_lang')
249
- );
250
- $args_tags = array(
251
- 'hierarchical' => false,
252
- 'labels' => $labels_tags,
253
- 'show_ui' => true,
254
- 'query_var' => true,
255
- 'rewrite' => array('slug' => 'sdm_tags'),
256
- 'show_admin_column' => true
257
- );
258
- register_taxonomy('sdm_tags', array('sdm_downloads'), $args_tags);
259
- }
260
-
261
- public function sdm_create_menu_pages() {
262
-
263
- //*****
264
- //***** If user clicked to download the bulk export log
265
- if (isset($_GET['download_log'])) {
266
- global $wpdb;
267
- $csv_output = '';
268
- $table = $wpdb->prefix . 'sdm_downloads';
269
-
270
- $result = mysql_query("SHOW COLUMNS FROM " . $table . "");
271
-
272
- $i = 0;
273
- if (mysql_num_rows($result) > 0) {
274
- while ($row = mysql_fetch_assoc($result)) {
275
- $csv_output = $csv_output . $row['Field'] . ",";
276
- $i++;
277
- }
278
- }
279
- $csv_output .= "\n";
280
-
281
- $values = mysql_query("SELECT * FROM " . $table . "");
282
- while ($rowr = mysql_fetch_row($values)) {
283
- for ($j = 0; $j < $i; $j++) {
284
- $csv_output .= $rowr[$j] . ",";
285
- }
286
- $csv_output .= "\n";
287
- }
288
-
289
- header("Pragma: public");
290
- header("Expires: 0");
291
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
292
- header("Cache-Control: private", false);
293
- header("Content-Type: application/octet-stream");
294
- header("Content-Disposition: attachment; filename=\"report.csv\";");
295
- header("Content-Transfer-Encoding: binary");
296
-
297
- echo $csv_output;
298
- exit;
299
- }
300
-
301
- //*****
302
- //***** Create the 'logs' and 'settings' submenu pages
303
- $sdm_logs_page = add_submenu_page('edit.php?post_type=sdm_downloads', __('Logs', 'sdm_lang'), __('Logs', 'sdm_lang'), 'manage_options', 'logs', 'sdm_create_logs_page');
304
- $sdm_settings_page = add_submenu_page('edit.php?post_type=sdm_downloads', __('Settings', 'sdm_lang'), __('Settings', 'sdm_lang'), 'manage_options', 'settings', array(&$this, 'sdm_create_settings_page'));
305
- }
306
-
307
- public function sdm_create_settings_page() {
308
- echo '<div class="wrap">';
309
- echo '<div id="poststuff"><div id="post-body">';
310
- ?>
311
- <h2><?php _e('Simple Download Monitor Settings Page', 'sdm_lang') ?></h2>
312
-
313
- <div style="background: #FFF6D5; border: 1px solid #D1B655; color: #3F2502; padding: 15px 10px">
314
- <a href="http://www.tipsandtricks-hq.com/development-center" target="_blank"><?php _e('Follow us', 'sdm_lang'); ?></a> <?php _e('on Twitter, Google+ or via Email to stay upto date about the new features of this plugin.', 'sdm_lang'); ?>
315
- </div>
316
-
317
- <!-- settings page form -->
318
- <form method="post" action="options.php">
319
-
320
- <!-- BEGIN ADMIN OPTIONS DIV -->
321
- <div id="sdm_admin_opts_div" class="sdm_sliding_div_title">
322
- <div class="sdm_slider_title">
323
- <?php _e('Admin Options', 'sdm_lang') ?>
324
- </div>
325
- <div class="sdm_desc">
326
- <?php _e("Control various plugin features.", 'sdm_lang') ?>
327
- </div>
328
  </div>
329
- <div id="sliding_div1" class="slidingDiv">
 
 
 
 
330
  <?php
331
  // This prints out all hidden setting fields
332
- do_settings_sections('admin_options_section');
333
- settings_fields('sdm_downloads_options');
334
-
335
- submit_button();
336
  ?>
337
- </div>
338
- <!-- END ADMIN OPTIONS DIV -->
339
 
340
- <!-- BEGIN COLORS DIV -->
341
- <div id="sdm_color_opts_div" class="sdm_sliding_div_title">
342
- <div class="sdm_slider_title">
343
- <?php _e('Color Options', 'sdm_lang') ?>
344
- </div>
345
- <div class="sdm_desc">
346
- <?php _e("Adjust color options", 'sdm_lang') ?>
347
- </div>
348
  </div>
349
- <div id="sliding_div2" class="slidingDiv">
 
350
  <?php
351
  // This prints out all hidden setting fields
352
- do_settings_sections('sdm_colors_section');
353
- settings_fields('sdm_downloads_options');
354
 
355
- submit_button();
356
  ?>
357
- </div>
358
- <!-- END COLORS OPTIONS DIV -->
359
-
360
- <!-- End of settings page form -->
361
- </form>
362
-
363
- <div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
364
- <p><?php _e('If you need a feature rich and supported plugin for selling your digital items then checkout our', 'sdm_lang'); ?> <a href="http://www.tipsandtricks-hq.com/wordpress-estore-plugin-complete-solution-to-sell-digital-products-from-your-wordpress-blog-securely-1059" target="_blank"><?php _e('WP eStore Plugin', 'sdm_lang'); ?></a>
365
- </p>
366
  </div>
 
 
 
 
 
 
 
 
 
367
 
368
  <?php
369
- echo '</div></div>'; //end of post-stuff
370
- echo '</div>'; //end of wrap
371
- }
372
-
373
- public function sdm_create_upload_metabox() {
374
-
375
- //*****
376
- //***** Create metaboxes for the custom post type
377
- add_meta_box('sdm_description_meta_box', __('Description', 'sdm_lang'), array(&$this, 'display_sdm_description_meta_box'), 'sdm_downloads', 'normal', 'default'
378
- );
379
- add_meta_box('sdm_upload_meta_box', __('Upload File', 'sdm_lang'), array(&$this, 'display_sdm_upload_meta_box'), 'sdm_downloads', 'normal', 'default'
380
- );
381
- add_meta_box('sdm_thumbnail_meta_box', __('File Thumbnail (Optional)', 'sdm_lang'), array(&$this, 'display_sdm_thumbnail_meta_box'), 'sdm_downloads', 'normal', 'default'
382
- );
383
- add_meta_box('sdm_shortcode_meta_box', __('Shortcodes', 'sdm_lang'), array(&$this, 'display_sdm_shortcode_meta_box'), 'sdm_downloads', 'normal', 'default'
384
- );
385
- add_meta_box('sdm_stats_meta_box', __('Statistics', 'sdm_lang'), array(&$this, 'display_sdm_stats_meta_box'), 'sdm_downloads', 'normal', 'default'
386
- );
387
- }
388
-
389
- public function display_sdm_description_meta_box($post) { // Description metabox
390
- _e('Add a description for this download item.', 'sdm_lang');
391
- echo '<br /><br />';
392
-
393
- $old_description = get_post_meta($post->ID, 'sdm_description', true);
394
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
  <textarea id="sdm_description" name="sdm_description" style="width:60%;height:40px;"><?php echo $old_description; ?></textarea>
396
  <?php
397
- wp_nonce_field('sdm_description_box_nonce', 'sdm_description_box_nonce_check');
398
- }
399
-
400
- public function display_sdm_upload_meta_box($post) { // File Upload metabox
401
- $old_upload = get_post_meta($post->ID, 'sdm_upload', true);
402
- $old_value = isset($old_upload) ? $old_upload : '';
403
- _e('Click "Select File" to upload (or choose) the file.', 'sdm_lang');
404
- ?>
 
405
  <br /><br />
406
- <input id="upload_image_button" type="button" class="button-primary" value="<?php _e('Select File', 'sdm_lang'); ?>" />
407
  <span style="margin-left:40px;"></span>
408
- <?php _e('File URL:', 'sdm_lang') ?> <input id="sdm_upload" type="text" size="70" name="sdm_upload" value="<?php echo $old_value; ?>" />
409
  <?php
410
- wp_nonce_field('sdm_upload_box_nonce', 'sdm_upload_box_nonce_check');
411
- }
412
-
413
- public function display_sdm_thumbnail_meta_box($post) { // Thumbnail upload metabox
414
- $old_thumbnail = get_post_meta($post->ID, 'sdm_upload_thumbnail', true);
415
- $old_value = isset($old_thumbnail) ? $old_thumbnail : '';
416
- _e('Click "Select Image" to upload (or choose) the file thumbnail image. This thumbnail image will be used to create a fancy file download box if you want to use it.', 'sdm_lang');
417
- echo '<br />';
418
- _e('Recommended image size is 75px by 75px.', 'sdm_lang');
419
- ?>
 
420
  <br /><br />
421
- <input id="upload_thumbnail_button" type="button" class="button-primary" value="<?php _e('Select Image', 'sdm_lang'); ?>" />
422
- <input id="remove_thumbnail_button" type="button" class="button" value="<?php _e('Remove Image', 'sdm_lang'); ?>" />
423
  <span style="margin-left:40px;"></span>
424
- <input id="sdm_upload_thumbnail" type="hidden" size="70" name="sdm_upload_thumbnail" value="<?php echo $old_value; ?>" />
425
  <span id="sdm_get_thumb">
426
- <?php
427
- if ($old_value != '') {
428
- ?><img id="sdm_thumbnail_image" src="<?php echo $old_value; ?>" style="width:75px;height:75px;" />
429
  <?php
430
- }
431
- ?></span><?php
432
- wp_nonce_field('sdm_thumbnail_box_nonce', 'sdm_thumbnail_box_nonce_check');
433
- }
434
-
435
- public function display_sdm_shortcode_meta_box($post) { // Shortcode metabox
436
- _e('This is the shortcode which can used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter to add this shortcode to a post or page.', 'sdm_lang');
437
- echo '<br />';
438
- echo '[sdm_download id="' . $post->ID . '" fancy="0"]';
439
- echo '<br /><br />';
440
-
441
- _e('This shortcode may be used as a download counter.', 'sdm_lang');
442
- echo '<br />';
443
- echo '[sdm_download_counter id="' . $post->ID . '"]';
444
- }
445
-
446
- public function display_sdm_stats_meta_box($post) { // Stats metabox
447
- _e('These are the statistics for this download item.', 'sdm_lang');
448
- echo '<br /><br />';
449
-
450
- global $wpdb;
451
- $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post->ID));
452
- _e('Number of Downloads:', 'sdm_lang');
453
- echo ' ' . $wpdb->num_rows;
454
- }
455
-
456
- public function sdm_save_description_meta_data($post_id) { // Save Description metabox
457
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
458
- return;
459
- if (!isset($_POST['sdm_description_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_description_box_nonce_check'], 'sdm_description_box_nonce'))
460
- return;
461
-
462
- if (isset($_POST['sdm_description'])) {
463
- update_post_meta($post_id, 'sdm_description', $_POST['sdm_description']);
464
- }
465
- }
466
-
467
- public function sdm_save_upload_meta_data($post_id) { // Save File Upload metabox
468
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
469
- return;
470
- if (!isset($_POST['sdm_upload_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_upload_box_nonce_check'], 'sdm_upload_box_nonce'))
471
- return;
472
-
473
- if (isset($_POST['sdm_upload'])) {
474
- update_post_meta($post_id, 'sdm_upload', $_POST['sdm_upload']);
475
- }
476
- }
477
-
478
- public function sdm_save_thumbnail_meta_data($post_id) { // Save Thumbnail Upload metabox
479
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
480
- return;
481
- if (!isset($_POST['sdm_thumbnail_box_nonce_check']) || !wp_verify_nonce($_POST['sdm_thumbnail_box_nonce_check'], 'sdm_thumbnail_box_nonce'))
482
- return;
483
-
484
- if (isset($_POST['sdm_upload_thumbnail'])) {
485
- update_post_meta($post_id, 'sdm_upload_thumbnail', $_POST['sdm_upload_thumbnail']);
486
- }
487
- }
488
-
489
- public function sdm_remove_view_link_cpt($action, $post) {
490
-
491
- // Only execute on SDM CPT posts page
492
- if ($post->post_type == 'sdm_downloads') {
493
- unset($action['view']);
494
- }
495
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  return $action;
497
- }
498
-
499
- public function sdm_register_options() {
500
-
501
- register_setting('sdm_downloads_options', 'sdm_downloads_options');
502
- add_settings_section('admin_options', __('Admin Options', 'sdm_lang'), array($this, 'admin_options_cb'), 'admin_options_section');
503
- add_settings_section('sdm_colors', __('Colors', 'sdm_lang'), array($this, 'sdm_colors_cb'), 'sdm_colors_section');
504
-
505
- add_settings_field('admin_tinymce_button', __('Remove Tinymce Button', 'sdm_lang'), array($this, 'admin_tinymce_button_cb'), 'admin_options_section', 'admin_options');
506
- add_settings_field('download_button_color', __('Download Button Color', 'sdm_lang'), array($this, 'download_button_color_cb'), 'sdm_colors_section', 'sdm_colors');
507
- }
508
-
509
- public function admin_options_cb() {
510
- _e('Admin options settings', 'sdm_lang');
511
- }
512
-
513
- public function sdm_colors_cb() {
514
- _e('Front End colors settings', 'sdm_lang');
515
- }
516
-
517
- public function admin_tinymce_button_cb() {
518
- $main_opts = get_option('sdm_downloads_options');
519
- 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) . ' /> ';
520
- _e('Removes the SDM Downloads button from the WP content editor.', 'sdm_lang');
521
- }
522
-
523
- public function download_button_color_cb() {
524
- $main_opts = get_option('sdm_downloads_options');
525
- $color_opt = $main_opts['download_button_color'];
526
- $color_opts = array(__('Green', 'sdm_lang'), __('Blue', 'sdm_lang'), __('Purple', 'sdm_lang'), __('Teal', 'sdm_lang'), __('Dark Blue', 'sdm_lang'), __('Black', 'sdm_lang'), __('Grey', 'sdm_lang'), __('Pink', 'sdm_lang'), __('Orange', 'sdm_lang'), __('White', 'sdm_lang'));
527
- echo '<select name="sdm_downloads_options[download_button_color]" id="download_button_color" class="sdm_opts_ajax_dropdowns">';
528
- if (isset($color_opt)) {
529
- echo '<option value="' . $color_opt . '" selected="selected">' . $color_opt . ' (' . __('current', 'sdm_lang') . ')</option>';
530
- }
531
- foreach ($color_opts as $color) {
532
- echo '<option value="' . $color . '" ' . $sel_color . '>' . $color . '</option>';
533
- }
534
- echo '</select> ';
535
- _e('Adjusts the color of the "Download Now" button.', 'sdm_lang');
536
- }
537
-
538
  }
539
-
540
  $simpleDownloadManager = new simpleDownloadManager();
541
 
542
  /*
543
- * *
544
- * * Logs Page
545
- * *
546
- */
547
  //*****
548
  //***** Check WP_List_Table exists
549
- if (!class_exists('WP_List_Table')) {
550
  require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
551
  }
552
 
553
  //*****
554
  //***** Define our new Table
555
  class sdm_List_Table extends WP_List_Table {
556
-
557
- function __construct() {
558
-
 
559
  global $status, $page;
560
-
561
  //Set parent defaults
562
- parent::__construct(array(
563
- 'singular' => __('Download', 'sdm_lang'), //singular name of the listed records
564
- 'plural' => __('Downloads', 'sdm_lang'), //plural name of the listed records
565
- 'ajax' => false //does this table support ajax?
566
- ));
 
567
  }
568
-
569
- function column_default($item, $column_name) {
570
-
571
- switch ($column_name) {
572
  case 'URL':
573
  case 'visitor_ip':
574
  case 'date':
575
  return $item[$column_name];
576
- case 'visitor_country':
577
- return $item[$column_name];
578
  default:
579
- return print_r($item, true); //Show the whole array for troubleshooting purposes
580
  }
581
  }
582
-
583
- function column_title($item) {
584
-
585
  //Build row actions
586
  $actions = array(
587
- 'edit' => sprintf('<a href="' . admin_url('post.php?post=' . $item['ID'] . '&action=edit') . '">' . __('Edit', 'sdm_lang') . '</a>'),
588
- 'delete' => sprintf('<a href="?post_type=sdm_downloads&page=%s&action=%s&download=%s&datetime=%s">' . __('Delete', 'sdm_lang') . '</a>', $_REQUEST['page'], 'delete', $item['ID'], $item['date'])
589
  );
590
-
591
  //Return the title contents
592
  return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
593
- /* $1%s */ $item['title'],
594
- /* $2%s */ $item['ID'],
595
- /* $3%s */ $this->row_actions($actions)
596
  );
597
  }
598
-
599
- function column_cb($item) {
600
-
601
  return sprintf(
602
- '<input type="checkbox" name="%1$s[]" value="%2$s" />',
603
- /* $1%s */ $this->_args['singular'], //Let's simply repurpose the table's singular label ("Download")
604
- /* $2%s */ $item['ID'] . '|' . $item['date'] //The value of the checkbox should be the record's id
605
  );
606
  }
607
-
608
- function get_columns() {
609
-
610
  $columns = array(
611
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
612
- 'title' => __('Title', 'sdm_lang'),
613
- 'URL' => __('File', 'sdm_lang'),
614
- 'visitor_ip' => __('Visitor IP', 'sdm_lang'),
615
- 'date' => __('Date', 'sdm_lang'),
616
- 'visitor_country' => __('Country', 'sdm_lang')
617
  );
618
  return $columns;
619
  }
620
-
621
  function get_sortable_columns() {
622
-
623
  $sortable_columns = array(
624
- 'title' => array('title', false), //true means it's already sorted
625
- 'URL' => array('URL', false),
626
- 'visitor_ip' => array('visitor_ip', false),
627
- 'date' => array('date', false),
628
- 'visitor_country' => array('visitor_country', false)
629
  );
630
  return $sortable_columns;
631
  }
632
-
633
  function get_bulk_actions() {
634
-
635
  $actions = array();
636
- $actions['delete2'] = __('Delete Permanently', 'sdm_lang');
637
- $actions['export_all'] = __('Export All as Excel', 'sdm_lang');
638
  //$actions['export-selected'] = __( 'Export Selected', 'sdm_lang' );
639
 
640
  return $actions;
641
  }
642
-
643
  function process_bulk_action() {
 
 
 
644
 
645
- // security check!
646
- if (isset($_POST['_wpnonce']) && !empty($_POST['_wpnonce'])) {
647
-
648
- $nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING);
649
  $action = 'bulk-' . $this->_args['plural'];
650
 
651
- if (!wp_verify_nonce($nonce, $action))
652
- wp_die(__('Nope! Security check failed!', 'sdm_lang'));
653
- }
654
-
655
- $action = $this->current_action();
656
-
657
- // If bulk 'Export All' was clicked
658
- if ('export_all' === $this->current_action()) {
659
-
660
- echo '<div id="message" class="updated"><p><strong><a id="sdm_download_export" href="?post_type=sdm_downloads&page=logs&download_log">' . __('Download Export File', 'sdm_lang') . '</a></strong></p></div>';
661
- }
662
-
663
- // if bulk 'Delete Permanently' was clicked
664
- if ('delete2' === $this->current_action()) {
665
 
666
- if (!isset($_POST['download']) || $_POST['download'] == null) {
667
- echo '<div id="message" class="updated fade"><p><strong>' . __('No entries were selected.', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
668
- return;
669
- }
670
-
671
- foreach ($_POST['download'] as $item) {
672
- $str_tok_id = substr($item, 0, strpos($item, '|'));
673
- $str_tok_datetime = substr($item, strpos($item, '|') + 1);
674
-
675
- global $wpdb;
676
- $del_row = $wpdb->query(
677
- 'DELETE FROM ' . $wpdb->prefix . 'sdm_downloads
678
- WHERE post_id = "' . $str_tok_id . '"
679
- AND date_time = "' . $str_tok_datetime . '"'
680
- );
681
- }
682
- if ($del_row) {
683
- echo '<div id="message" class="updated fade"><p><strong>' . __('Entries Deleted!', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
684
- } else {
685
- echo '<div id="message" class="updated fade"><p><strong>' . __('Error', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
686
- }
687
  }
688
 
689
- // If single entry 'Delete' was clicked
690
- if ('delete' === $this->current_action()) {
691
-
692
- $item_id = isset($_GET['download']) ? strtok($_GET['download'], '|') : '';
693
- $item_datetime = isset($_GET['datetime']) ? $_GET['datetime'] : '';
694
-
695
- global $wpdb;
696
- $del_row = $wpdb->query(
697
- 'DELETE FROM ' . $wpdb->prefix . 'sdm_downloads
698
- WHERE post_id = "' . $item_id . '"
699
- AND date_time = "' . $item_datetime . '"'
700
- );
701
- if ($del_row) {
702
- echo '<div id="message" class="updated fade"><p><strong>' . __('Entry Deleted!', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
703
- } else {
704
- echo '<div id="message" class="updated fade"><p><strong>' . __('Error', 'sdm_lang') . '</strong></p><p><em>' . __('Click to Dismiss', 'sdm_lang') . '</em></p></div>';
705
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
706
  }
 
707
  }
708
-
709
  function prepare_items() {
710
-
711
  global $wpdb; //This is used only if making any database queries
712
  $per_page = 10;
713
  $columns = $this->get_columns();
714
  $hidden = array();
715
  $sortable = $this->get_sortable_columns();
716
-
717
-
718
  $this->_column_headers = array($columns, $hidden, $sortable);
719
  $this->process_bulk_action();
720
-
721
  //$data = $this->example_data;
722
-
723
- function usort_reorder($a, $b) {
724
  $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'title'; //If no sort, default to title
725
  $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
726
  $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
727
- return ($order === 'asc') ? $result : -$result; //Send final sort direction to usort
728
- }
729
-
730
- $data_results = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads');
731
- $data = array();
732
- foreach ($data_results as $data_result) {
733
- $data[] = array('ID' => $data_result->post_id, 'title' => $data_result->post_title, 'URL' => $data_result->file_url, 'visitor_ip' => $data_result->visitor_ip, 'date' => $data_result->date_time, 'visitor_country' => $data_result->visitor_country);
734
  }
735
-
736
-
 
 
 
 
 
 
737
  usort($data, 'usort_reorder');
738
  $current_page = $this->get_pagenum();
739
  $total_items = count($data);
740
- $data = array_slice($data, (($current_page - 1) * $per_page), $per_page);
741
-
742
  $this->items = $data;
743
- $this->set_pagination_args(array(
744
- 'total_items' => $total_items, //WE have to calculate the total number of items
745
- 'per_page' => $per_page, //WE have to determine how many items to show on a page
746
- 'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages
747
- ));
748
  }
749
-
750
  }
751
-
752
- function sdm_create_logs_page() {
753
-
754
  //Create an instance of our package class...
755
  $sdmListTable = new sdm_List_Table();
756
  //Fetch, prepare, sort, and filter our data...
757
  $sdmListTable->prepare_items();
 
758
  ?>
759
  <div class="wrap">
760
-
761
  <div id="icon-users" class="icon32"><br/></div>
762
  <h2><?php _e('Download Logs', 'sdm_lang'); ?></h2>
763
-
764
  <div style="background:#ECECEC;border:1px solid #CCC;padding:0 10px;margin-top:5px;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;">
765
  <p><?php _e('This page lists all tracked downloads.', 'sdm_lang'); ?></p>
766
  </div>
767
-
768
  <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
769
  <form id="sdm_downloads-filter" method="post">
770
  <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
771
  <!-- Now we can render the completed list table -->
772
- <?php $sdmListTable->display() ?>
773
  </form>
774
-
775
  </div>
776
  <script type="text/javascript">
777
- jQuery(document).ready(function($) {
778
- $('.fade').click(function() {
779
- $(this).fadeOut('slow');
780
- });
781
- });
782
- </script>
783
  <?php
784
  }
785
 
786
- function sdm_get_password_entry_form($id) {
787
- $data = __('Enter Password to Download:', 'sdm_lang');
788
- $data .= '<form method="post">';
789
- $data .= '<input type="password" class="pass_text" value="" /> ';
790
- $data .= '<input type="button" class="pass_sumbit" value="' . __('Submit', 'sdm_lang') . '" />';
791
- $data .= '<input type="hidden" value="' . $id . '" />';
792
- $data .= '</form>';
793
- return $data;
 
794
  }
795
 
796
  /*
797
- * * Register scripts for front-end posts/pages
798
- */
799
- add_action('wp_enqueue_scripts', 'sdm_wp_scripts');
800
-
801
- function sdm_wp_scripts() {
802
-
803
- wp_enqueue_style('sdm-styles', WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_wp_styles.css');
804
- wp_register_script('sdm-scripts', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_wp_scripts.js', array('jquery'));
805
- wp_enqueue_script('sdm-scripts');
806
-
807
- // Localize ajax script for frontend
808
- wp_localize_script('sdm-scripts', 'sdm_ajax_script', array('ajaxurl' => admin_url('admin-ajax.php')));
809
- }
810
-
811
- function handle_sdm_download_via_direct_post() {
812
- if (isset($_REQUEST['smd_process_download']) && $_REQUEST['smd_process_download'] == '1') {
813
- $download_id = strip_tags($_REQUEST['download_id']);
814
- $download_title = get_the_title($download_id);
815
- $download_link = get_post_meta($download_id, 'sdm_upload', true);
816
- $ipaddress = $_SERVER["REMOTE_ADDR"];
817
- $date_time = current_time('mysql');
818
- $visitor_country = sdm_ip_info('Visitor', 'Country');
819
-
820
- global $wpdb;
821
- $table = $wpdb->prefix . 'sdm_downloads';
822
- $data = array(
823
- 'post_id' => $download_id,
824
- 'post_title' => $download_title,
825
- 'file_url' => $download_link,
826
- 'visitor_ip' => $ipaddress,
827
- 'date_time' => $date_time,
828
- 'visitor_country' => $visitor_country
829
- );
830
-
831
- $insert_table = $wpdb->insert($table, $data);
832
-
833
- if ($insert_table) {//Download request was logged successfully
834
- sdm_redirect_to_url($download_link);
835
- } else {//Failed to log the download request
836
- wp_die(__('Error! Failed to log the download request in the database table', 'sdm_lang'));
837
- }
838
- exit;
839
- }
840
  }
841
 
842
- function sdm_redirect_to_url($url, $delay = '0', $exit = '1') {
843
- if (empty($url)) {
844
- echo '<strong>';
845
- _e('Error! The URL value is empty. Please specify a correct URL value to redirect to!', 'sdm_lang');
846
- echo '</strong>';
847
- exit;
848
- }
849
- if (!headers_sent()) {
850
- header('Location: ' . $url);
851
- } else {
852
- echo '<meta http-equiv="refresh" content="' . $delay . ';url=' . $url . '" />';
853
- }
854
- if ($exit == '1') {//exit
855
- exit;
856
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
857
  }
858
 
859
  // Tinymce Button Populate Post ID's
860
- add_action('wp_ajax_nopriv_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call');
861
- add_action('wp_ajax_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call');
862
-
863
  function sdm_tiny_get_post_ids_ajax_call() {
864
-
865
- $args = array(
866
- 'post_type' => 'sdm_downloads',
867
- );
868
- $loop = new WP_Query($args);
869
- $test = '';
870
- foreach ($loop->posts as $loop_post) {
871
- //$test .= $loop_post->ID.'|'.$loop_post->post_title.'_';
872
- $test[] = array('post_id' => $loop_post->ID, 'post_title' => $loop_post->post_title);
873
- }
874
-
875
- $response = json_encode(array('success' => true, 'test' => $test));
876
-
877
- header('Content-Type: application/json');
878
- echo $response;
879
- exit;
880
  }
881
-
882
  // Remove Thumbnail Image
883
- add_action('wp_ajax_nopriv_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call');
884
- add_action('wp_ajax_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call');
885
-
886
  function sdm_remove_thumbnail_image_ajax_call() {
887
-
888
- $post_id = $_POST['post_id_del'];
889
- $success = delete_post_meta($post_id, 'sdm_upload_thumbnail');
890
- if ($success) {
891
- $response = json_encode(array('success' => true));
892
- }
893
-
894
- header('Content-Type: application/json');
895
- echo $response;
896
- exit;
897
  }
898
-
899
  // Check download password
900
- add_action('wp_ajax_nopriv_sdm_check_pass', 'sdm_check_pass_ajax_call');
901
- add_action('wp_ajax_sdm_check_pass', 'sdm_check_pass_ajax_call');
902
-
903
  function sdm_check_pass_ajax_call() {
904
-
905
- $button_id = $_POST['button_id']; // Get button cpt id
906
- $pass_val = $_POST['pass_val']; // Get password attempt
907
- $success = '';
908
- $download_link = '';
909
-
910
- // Get post object
911
- $post_object = get_post($button_id);
912
- // Get post password
913
- $post_pass = $post_object->post_password;
914
-
915
- // Check if password is a match
916
- if ($post_pass != $pass_val) { // Match is a failure
917
- $success = 'no'; // Pass back to ajax
918
- } else { // Match is a success
919
- $success = 'yes'; // Pass back to ajax
920
-
921
- $download_id = $button_id;
922
- $download_title = get_the_title($download_id);
923
- $download_link = get_post_meta($download_id, 'sdm_upload', true);
924
- $ipaddress = $_SERVER["REMOTE_ADDR"];
925
- $date_time = current_time('mysql');
926
- $visitor_country = sdm_ip_info('Visitor', 'Country');
927
-
928
- global $wpdb;
929
- $table = $wpdb->prefix . 'sdm_downloads';
930
- $data = array(
931
- 'post_id' => $download_id,
932
- 'post_title' => $download_title,
933
- 'file_url' => $download_link,
934
- 'visitor_ip' => $ipaddress,
935
- 'date_time' => $date_time,
936
- 'visitor_country' => $visitor_country
937
- );
938
-
939
- $insert_table = $wpdb->insert($table, $data);
940
- }
941
-
942
- // Generate ajax response
943
- $response = json_encode(array('success' => $success, 'url' => $download_link));
944
- header('Content-Type: application/json');
945
- echo $response;
946
- exit;
 
 
 
947
  }
948
-
949
  // Populate category tree
950
- add_action('wp_ajax_nopriv_sdm_pop_cats', 'sdm_pop_cats_ajax_call');
951
- add_action('wp_ajax_sdm_pop_cats', 'sdm_pop_cats_ajax_call');
952
-
953
  function sdm_pop_cats_ajax_call() {
954
-
955
- $cat_slug = $_POST['cat_slug']; // Get button cpt slug
956
- $parent_id = $_POST['parent_id']; // Get button cpt id
957
- // Query custom posts based on taxonomy slug
958
- $posts = query_posts(array(
959
- 'post_type' => 'sdm_downloads',
960
- //'showposts' => -1,
961
- 'tax_query' => array(
962
- array(
963
- 'taxonomy' => 'sdm_categories',
964
- 'terms' => $cat_slug,
965
- 'field' => 'slug',
966
- 'include_children' => 0
967
- )
968
- ),
969
- 'orderby' => 'title',
970
- 'order' => 'ASC')
971
- );
972
-
973
- // Loop results
974
- foreach ($posts as $post) {
975
-
976
- // Create array of variables to pass to js
977
- $final_array[] = array('id' => $post->ID, 'permalink' => get_permalink($post->ID), 'title' => $post->post_title);
978
- }
979
-
980
- // Generate ajax response
981
- $response = json_encode(array('final_array' => $final_array));
982
- header('Content-Type: application/json');
983
- echo $response;
984
- exit;
 
985
  }
986
 
987
  /*
988
- * * Setup Sortable Columns
989
- */
990
- add_filter('manage_edit-sdm_downloads_columns', 'sdm_create_columns'); // Define columns
991
- add_filter('manage_edit-sdm_downloads_sortable_columns', 'sdm_downloads_sortable'); // Make sortable
992
- add_action('manage_sdm_downloads_posts_custom_column', 'sdm_downloads_columns_content', 10, 2); // Populate new columns
993
-
994
- function sdm_create_columns($cols) {
995
-
996
- unset($cols['title']);
997
- unset($cols['taxonomy-sdm_tags']);
998
- unset($cols['taxonomy-sdm_categories']);
999
- unset($cols['date']);
1000
- unset($cols['visitor_country']);
1001
-
1002
- $cols['sdm_downloads_thumbnail'] = __('Image', 'sdm_lang');
1003
- $cols['title'] = __('Title', 'sdm_lang');
1004
- $cols['sdm_downloads_id'] = __('ID', 'sdm_lang');
1005
- $cols['sdm_downloads_file'] = __('File', 'sdm_lang');
1006
- $cols['taxonomy-sdm_categories'] = __('Categories', 'sdm_lang');
1007
- $cols['taxonomy-sdm_tags'] = __('Tags', 'sdm_lang');
1008
- $cols['sdm_downloads_count'] = __('Downloads', 'sdm_lang');
1009
- $cols['date'] = __('Date Posted', 'sdm_lang');
1010
- $cols['visitor_country'] = __('Visitor Country', 'sdm_lang');
1011
- return $cols;
1012
  }
1013
 
1014
- function sdm_downloads_sortable($cols) {
1015
-
1016
- $cols['sdm_downloads_id'] = 'sdm_downloads_id';
1017
- $cols['sdm_downloads_file'] = 'sdm_downloads_file';
1018
- $cols['sdm_downloads_count'] = 'sdm_downloads_count';
1019
- $cols['taxonomy-sdm_categories'] = 'taxonomy-sdm_categories';
1020
- $cols['taxonomy-sdm_tags'] = 'taxonomy-sdm_tags';
1021
- return $cols;
1022
  }
1023
 
1024
- function sdm_downloads_columns_content($column_name, $post_ID) {
1025
-
1026
- if ($column_name == 'sdm_downloads_thumbnail') {
1027
- $old_thumbnail = get_post_meta($post_ID, 'sdm_upload_thumbnail', true);
1028
- //$old_value = isset($old_thumbnail) ? $old_thumbnail : '';
1029
- if ($old_thumbnail) {
1030
- echo '<p class="sdm_downloads_count"><img src="' . $old_thumbnail . '" style="width:50px;height:50px;" /></p>';
1031
- }
1032
- }
1033
- if ($column_name == 'sdm_downloads_id') {
1034
- echo '<p class="sdm_downloads_postid">' . $post_ID . '</p>';
1035
- }
1036
- if ($column_name == 'sdm_downloads_file') {
1037
- $old_file = get_post_meta($post_ID, 'sdm_upload', true);
1038
- $file = isset($old_file) ? $old_file : '--';
1039
- echo '<p class="sdm_downloads_file">' . $file . '</p>';
1040
- }
1041
- if ($column_name == 'sdm_downloads_count') {
1042
- global $wpdb;
1043
- $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post_ID));
1044
- echo '<p class="sdm_downloads_count">' . $wpdb->num_rows . '</p>';
1045
- }
1046
  }
1047
-
1048
  // Adjust admin column widths
1049
  add_action('admin_head', 'sdm_admin_column_width'); // Adjust column width in admin panel
1050
-
1051
  function sdm_admin_column_width() {
1052
-
1053
  echo '<style type="text/css">';
1054
  echo '.column-sdm_downloads_thumbnail { width:75px !important; overflow:hidden }';
1055
  echo '.column-sdm_downloads_id { width:100px !important; overflow:hidden }';
1056
  echo '.column-taxonomy-sdm_categories { width:200px !important; overflow:hidden }';
1057
  echo '.column-taxonomy-sdm_tags { width:200px !important; overflow:hidden }';
1058
  echo '</style>';
1059
- }
1060
 
1061
  /*
1062
- * * Register Tinymce Button
1063
- */
1064
 
1065
  // First check if option is checked to disable tinymce button
1066
  $main_option = get_option('sdm_downloads_options');
1067
  $tiny_button_option = isset($main_option['admin_tinymce_button']);
1068
- if ($tiny_button_option != true) {
1069
-
1070
- // Okay.. we're good. Add the button.
1071
- add_action('init', 'sdm_downloads_tinymce_button');
1072
-
1073
- function sdm_downloads_tinymce_button() {
1074
-
1075
- add_filter('mce_external_plugins', 'sdm_downloads_add_button');
1076
- add_filter('mce_buttons', 'sdm_downloads_register_button');
1077
- }
1078
-
1079
- function sdm_downloads_add_button($plugin_array) {
1080
-
1081
- $plugin_array['sdm_downloads'] = WP_SIMPLE_DL_MONITOR_URL . '/tinymce/sdm_editor_plugin.js';
1082
- return $plugin_array;
1083
- }
1084
-
1085
- function sdm_downloads_register_button($buttons) {
1086
-
1087
- //array_push( $buttons, 'sdm_downloads' );
1088
- $buttons[] = 'sdm_downloads';
1089
- return $buttons;
1090
- }
1091
-
1092
  }
1093
 
 
1094
  // Helper function to get visitor country (or other info)
1095
  function sdm_ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
1096
  $output = NULL;
@@ -1103,8 +1144,8 @@ function sdm_ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
1103
  $ip = $_SERVER['HTTP_CLIENT_IP'];
1104
  }
1105
  }
1106
- $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose)));
1107
- $support = array("country", "countrycode", "state", "region", "city", "location", "address");
1108
  $continents = array(
1109
  "AF" => "Africa",
1110
  "AN" => "Antarctica",
@@ -1120,11 +1161,11 @@ function sdm_ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
1120
  switch ($purpose) {
1121
  case "location":
1122
  $output = array(
1123
- "city" => @$ipdat->geoplugin_city,
1124
- "state" => @$ipdat->geoplugin_regionName,
1125
- "country" => @$ipdat->geoplugin_countryName,
1126
- "country_code" => @$ipdat->geoplugin_countryCode,
1127
- "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)],
1128
  "continent_code" => @$ipdat->geoplugin_continentCode
1129
  );
1130
  break;
3
  * Plugin Name: Simple Download Monitor
4
  * Plugin URI: http://www.tipsandtricks-hq.com/development-center
5
  * Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
6
+ * Version: 3.0
7
  * Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
8
  * Author URI: http://www.tipsandtricks-hq.com/development-center
9
  * License: GPL2
10
  */
11
  define('WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname(plugin_basename(__FILE__)));
12
+ define('WP_SIMPLE_DL_MONITOR_URL', plugins_url('',__FILE__));
13
+ define('WP_SIMPLE_DL_MONITOR_PATH',plugin_dir_path( __FILE__ ));
14
 
15
  global $sdm_db_version;
16
  $sdm_db_version = '1.1';
73
  handle_sdm_download_via_direct_post();
74
  }
75
 
76
+ /*
77
+ ** Add a 'Settings' link to plugins list page
78
+ */
79
+ add_filter('plugin_action_links', 'sdm_settings_link', 10, 2 );
 
80
  function sdm_settings_link($links, $file) {
81
+ static $this_plugin;
82
+ if (!$this_plugin) $this_plugin = plugin_basename(__FILE__);
83
+ if ($file == $this_plugin){
84
+ $settings_link = '<a href="edit.php?post_type=sdm_downloads&page=settings" title="SDM Settings Page">'.__("Settings",'sdm_lang').'</a>';
85
+ array_unshift($links, $settings_link);
86
+ }
87
+ return $links;
 
88
  }
89
+
90
  // Houston... we have lift-off!!
91
  class simpleDownloadManager {
92
+
93
+ public function __construct() {
94
+
95
+ add_action( 'init', array( &$this, 'sdm_register_post_type' )); // Create 'sdm_downloads' custom post type
96
+ add_action( 'init', array( &$this, 'sdm_create_taxonomies' )); // Register 'tags' and 'categories' taxonomies
97
+ add_action( 'init', 'sdm_register_shortcodes' ); //Register the shortcodes
98
+ add_action( 'wp_enqueue_scripts', array( &$this, 'sdm_frontend_scripts' )); // Register frontend scripts
99
+
100
+ if( is_admin()) {
101
+ add_action( 'admin_menu', array( &$this, 'sdm_create_menu_pages' )); // Create admin pages
102
+ add_action( 'add_meta_boxes', array( &$this, 'sdm_create_upload_metabox' )); // Create metaboxes
103
+
104
+ add_action( 'save_post', array( &$this, 'sdm_save_description_meta_data' )); // Save 'description' metabox
105
+ add_action( 'save_post', array( &$this, 'sdm_save_upload_meta_data' )); // Save 'upload file' metabox
106
+ add_action( 'save_post', array( &$this, 'sdm_save_thumbnail_meta_data' )); // Save 'thumbnail' metabox
107
+ add_action( 'save_post', array( &$this, 'sdm_save_statistics_meta_data' )); // Save 'thumbnail' metabox
108
+
109
+ add_action( 'admin_enqueue_scripts', array( &$this, 'sdm_admin_scripts' )); // Register admin scripts
110
+ add_action( 'admin_print_styles', array( &$this, 'sdm_admin_styles' )); // Register admin styles
111
+
112
+ add_action( 'admin_init', array( &$this, 'sdm_register_options' )); // Register admin options
113
+
114
+ add_filter( 'post_row_actions',array( &$this, 'sdm_remove_view_link_cpt' ), 10, 2); // Remove 'View' link in CPT view
115
+ }
116
+ }
117
+
118
+ public function sdm_admin_scripts() {
119
+
120
+ global $current_screen, $post;
121
+
122
+ if (is_admin() && $current_screen->post_type == 'sdm_downloads' && $current_screen->base == 'post') {
123
+
124
+ // These scripts are needed for the media upload thickbox
125
+ wp_enqueue_script('media-upload');
126
+ wp_enqueue_script('thickbox');
127
+ wp_register_script('sdm-upload', WP_SIMPLE_DL_MONITOR_URL.'/js/sdm_admin_scripts.js', array('jquery','media-upload','thickbox'));
128
+ wp_enqueue_script('sdm-upload');
129
+
130
+ // Pass postID for thumbnail deletion
131
+ ?>
132
+ <script type="text/javascript">
133
+ var sdm_del_thumb_postid = '<?php echo $post->ID; ?>';
134
+ </script>
135
  <?php
136
+
137
+ // Localize langauge strings used in js file
138
+ $sdmTranslations = array(
139
+ 'image_removed' => __('Image Successfully Removed', 'sdm_lang'),
140
+ 'ajax_error' => __('Error with AJAX', 'sdm_lang')
141
+ );
142
+ wp_localize_script( 'sdm-upload', 'sdm_translations', $sdmTranslations );
143
+ }
144
+
145
+ // Pass admin ajax url
146
+ ?>
147
+ <script type="text/javascript">
148
+ var sdm_admin_ajax_url = { sdm_admin_ajax_url: '<?php echo admin_url('admin-ajax.php?action=ajax'); ?>' };
149
+ var sdm_plugin_url = '<?php echo plugins_url(); ?>';
150
+ var tinymce_langs = { select_download_item: '<?php _e('Please select a Download Item:', 'sdm_lang') ?>', download_title: '<?php _e('Download Title', 'sdm_lang') ?>', include_fancy: '<?php _e('Include Fancy Box', 'sdm_lang') ?>', insert_shortcode: '<?php _e('Insert SDM Shortcode', 'sdm_lang') ?>' };
151
+ </script>
152
+ <?php
153
+ }
154
+
155
+ public function sdm_frontend_scripts() {
156
+
157
+ // Pass language strings to frontend of WP for js usage
158
+ ?>
159
+ <script type="text/javascript">
160
+ var sdm_frontend_translations = { incorrect_password: '<?php _e('Incorrect Password', 'sdm_lang') ?>' };
161
+ </script>
162
+ <?php
163
+
164
+ }
165
+
166
+ public function sdm_admin_styles() {
167
+
168
+ wp_enqueue_style('thickbox'); // Needed for media upload thickbox
169
+ wp_enqueue_style('sdm_admin_styles', WP_SIMPLE_DL_MONITOR_URL.'/css/sdm_admin_styles.css'); // Needed for media upload thickbox
170
+ }
171
+
172
+ public function sdm_register_post_type() {
173
+
174
+ //*****
175
+ //***** Create 'sdm_downloads' Custom Post Type
176
+ $labels = array(
177
+ 'name' => __('Downloads','sdm_lang'),
178
+ 'singular_name' => __('Downloads','sdm_lang'),
179
+ 'add_new' => __('Add New','sdm_lang'),
180
+ 'add_new_item' => __('Add New','sdm_lang'),
181
+ 'edit_item' => __('Edit Download','sdm_lang'),
182
+ 'new_item' => __('New Download','sdm_lang'),
183
+ 'all_items' => __('Downloads','sdm_lang'),
184
+ 'view_item' => __('View Download','sdm_lang'),
185
+ 'search_items' => __('Search Downloads','sdm_lang'),
186
+ 'not_found' => __('No Downloads found','sdm_lang'),
187
+ 'not_found_in_trash' => __('No Downloads found in Trash','sdm_lang'),
188
+ 'parent_item_colon' => __('','sdm_lang'),
189
+ 'menu_name' => __('Downloads','sdm_lang')
190
+ );
191
+ $args = array(
192
+ 'labels' => $labels,
193
+ 'public' => true,
194
+ 'publicly_queryable' => true,
195
+ 'show_ui' => true,
196
+ 'show_in_menu' => true,
197
+ 'query_var' => true,
198
+ 'rewrite' => array( 'slug' => 'sdm_downloads' ),
199
+ 'capability_type' => 'post',
200
+ 'has_archive' => true,
201
+ 'hierarchical' => false,
202
+ 'menu_position' => null,
203
+ 'menu_icon' => 'dashicons-download',
204
+ 'supports' => array( 'title' )
205
+ );
206
+ register_post_type( 'sdm_downloads', $args );
207
+ }
208
+
209
+ public function sdm_create_taxonomies() {
210
+
211
+ //*****
212
+ //***** Create CATEGORIES Taxonomy
213
+ $labels_tags = array(
214
+ 'name' => _x( 'Categories', 'sdm_lang' ),
215
+ 'singular_name' => _x( 'Category', 'sdm_lang' ),
216
+ 'search_items' => __( 'Search Categories', 'sdm_lang' ),
217
+ 'all_items' => __( 'All Categories', 'sdm_lang' ),
218
+ 'parent_item' => __( 'Categories Genre', 'sdm_lang' ),
219
+ 'parent_item_colon' => __( 'Categories Genre:', 'sdm_lang' ),
220
+ 'edit_item' => __( 'Edit Category', 'sdm_lang' ),
221
+ 'update_item' => __( 'Update Category', 'sdm_lang' ),
222
+ 'add_new_item' => __( 'Add New Category', 'sdm_lang' ),
223
+ 'new_item_name' => __( 'New Category', 'sdm_lang' ),
224
+ 'menu_name' => __( 'Categories', 'sdm_lang' )
225
+ );
226
+ $args_tags = array(
227
+ 'hierarchical' => true,
228
+ 'labels' => $labels_tags,
229
+ 'show_ui' => true,
230
+ 'query_var' => true,
231
+ 'rewrite' => array( 'slug' => 'sdm_categories' ),
232
+ 'show_admin_column' => true
233
+ );
234
+ register_taxonomy( 'sdm_categories', array( 'sdm_downloads' ), $args_tags );
235
+
236
+ //*****
237
+ //***** Create TAGS Taxonomy
238
+ $labels_tags = array(
239
+ 'name' => _x( 'Tags', 'sdm_lang' ),
240
+ 'singular_name' => _x( 'Tag', 'sdm_lang' ),
241
+ 'search_items' => __( 'Search Tags', 'sdm_lang' ),
242
+ 'all_items' => __( 'All Tags', 'sdm_lang' ),
243
+ 'parent_item' => __( 'Tags Genre', 'sdm_lang' ),
244
+ 'parent_item_colon' => __( 'Tags Genre:', 'sdm_lang' ),
245
+ 'edit_item' => __( 'Edit Tag', 'sdm_lang' ),
246
+ 'update_item' => __( 'Update Tag', 'sdm_lang' ),
247
+ 'add_new_item' => __( 'Add New Tag', 'sdm_lang' ),
248
+ 'new_item_name' => __( 'New Tag', 'sdm_lang' ),
249
+ 'menu_name' => __( 'Tags', 'sdm_lang' )
250
+ );
251
+ $args_tags = array(
252
+ 'hierarchical' => false,
253
+ 'labels' => $labels_tags,
254
+ 'show_ui' => true,
255
+ 'query_var' => true,
256
+ 'rewrite' => array( 'slug' => 'sdm_tags' ),
257
+ 'show_admin_column' => true
258
+ );
259
+ register_taxonomy( 'sdm_tags', array( 'sdm_downloads' ), $args_tags );
260
+ }
261
+
262
+ public function sdm_create_menu_pages() {
263
+
264
+ //*****
265
+ //***** If user clicked to download the bulk export log
266
+ if(isset($_GET['download_log']))
267
+ {
268
+ global $wpdb;
269
+ $csv_output = '';
270
+ $table = $wpdb->prefix.'sdm_downloads';
271
+
272
+ $result = mysql_query("SHOW COLUMNS FROM ".$table."");
273
+
274
+ $i = 0;
275
+ if (mysql_num_rows($result) > 0) {
276
+ while ($row = mysql_fetch_assoc($result)) {
277
+ $csv_output = $csv_output . $row['Field'].",";
278
+ $i++;
279
+ }
280
+ }
281
+ $csv_output .= "\n";
282
+
283
+ $values = mysql_query("SELECT * FROM ".$table."");
284
+ while ($rowr = mysql_fetch_row($values)) {
285
+ for ($j=0; $j<$i; $j++) {
286
+ $csv_output .= $rowr[$j].",";
287
+ }
288
+ $csv_output .= "\n";
289
+ }
290
+
291
+ header("Pragma: public");
292
+ header("Expires: 0");
293
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
294
+ header("Cache-Control: private", false);
295
+ header("Content-Type: application/octet-stream");
296
+ header("Content-Disposition: attachment; filename=\"report.csv\";" );
297
+ header("Content-Transfer-Encoding: binary");
298
+
299
+ echo $csv_output;
300
+ exit;
301
+ }
302
+
303
+ //*****
304
+ //***** Create the 'logs' and 'settings' submenu pages
305
+ $sdm_logs_page = add_submenu_page( 'edit.php?post_type=sdm_downloads', __('Logs', 'sdm_lang'), __('Logs', 'sdm_lang'), 'manage_options', 'logs', 'sdm_create_logs_page' );
306
+ $sdm_settings_page = add_submenu_page( 'edit.php?post_type=sdm_downloads', __('Settings', 'sdm_lang'), __('Settings', 'sdm_lang'), 'manage_options', 'settings', array( &$this, 'sdm_create_settings_page' ));
307
+ }
308
+
309
+ public function sdm_create_settings_page()
310
+ {
311
+ echo '<div class="wrap">';
312
+ echo '<div id="poststuff"><div id="post-body">';
313
+ ?>
314
+ <h2><?php _e('Simple Download Monitor Settings Page', 'sdm_lang') ?></h2>
315
+
316
+ <div style="background: #FFF6D5; border: 1px solid #D1B655; color: #3F2502; padding: 15px 10px">
317
+ <a href="http://www.tipsandtricks-hq.com/development-center" target="_blank"><?php _e('Follow us', 'sdm_lang'); ?></a> <?php _e('on Twitter, Google+ or via Email to stay upto date about the new features of this plugin.','sdm_lang'); ?>
318
+ </div>
319
+
320
+ <!-- settings page form -->
321
+ <form method="post" action="options.php">
322
+
323
+ <!-- BEGIN ADMIN OPTIONS DIV -->
324
+ <div id="sdm_admin_opts_div" class="sdm_sliding_div_title">
325
+ <div class="sdm_slider_title">
326
+ <?php _e('Admin Options', 'sdm_lang') ?>
327
  </div>
328
+ <div class="sdm_desc">
329
+ <?php _e("Control various plugin features.", 'sdm_lang') ?>
330
+ </div>
331
+ </div>
332
+ <div id="sliding_div1" class="slidingDiv">
333
  <?php
334
  // This prints out all hidden setting fields
335
+ do_settings_sections( 'admin_options_section' );
336
+ settings_fields( 'sdm_downloads_options' );
337
+
338
+ submit_button();
339
  ?>
340
+ </div>
341
+ <!-- END ADMIN OPTIONS DIV -->
342
 
343
+ <!-- BEGIN COLORS DIV -->
344
+ <div id="sdm_color_opts_div" class="sdm_sliding_div_title">
345
+ <div class="sdm_slider_title">
346
+ <?php _e('Color Options', 'sdm_lang') ?>
347
+ </div>
348
+ <div class="sdm_desc">
349
+ <?php _e("Adjust color options", 'sdm_lang') ?>
 
350
  </div>
351
+ </div>
352
+ <div id="sliding_div2" class="slidingDiv">
353
  <?php
354
  // This prints out all hidden setting fields
355
+ do_settings_sections( 'sdm_colors_section' );
356
+ settings_fields( 'sdm_downloads_options' );
357
 
358
+ submit_button();
359
  ?>
 
 
 
 
 
 
 
 
 
360
  </div>
361
+ <!-- END COLORS OPTIONS DIV -->
362
+
363
+ <!-- End of settings page form -->
364
+ </form>
365
+
366
+ <div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
367
+ <p><?php _e('If you need a feature rich and supported plugin for selling your digital items then checkout our','sdm_lang'); ?> <a href="http://www.tipsandtricks-hq.com/wordpress-estore-plugin-complete-solution-to-sell-digital-products-from-your-wordpress-blog-securely-1059" target="_blank"><?php _e('WP eStore Plugin', 'sdm_lang'); ?></a>
368
+ </p>
369
+ </div>
370
 
371
  <?php
372
+ echo '</div></div>';//end of post-stuff
373
+ echo '</div>';//end of wrap
374
+ }
375
+
376
+ public function sdm_create_upload_metabox() {
377
+
378
+ //*****
379
+ //***** Create metaboxes for the custom post type
380
+ add_meta_box('sdm_description_meta_box',
381
+ __('Description', 'sdm_lang'),
382
+ array( &$this, 'display_sdm_description_meta_box'),
383
+ 'sdm_downloads', 'normal', 'default'
384
+ );
385
+ add_meta_box('sdm_upload_meta_box',
386
+ __('Upload File', 'sdm_lang'),
387
+ array( &$this, 'display_sdm_upload_meta_box'),
388
+ 'sdm_downloads', 'normal', 'default'
389
+ );
390
+ add_meta_box('sdm_thumbnail_meta_box',
391
+ __('File Thumbnail (Optional)', 'sdm_lang'),
392
+ array( &$this, 'display_sdm_thumbnail_meta_box'),
393
+ 'sdm_downloads', 'normal', 'default'
394
+ );
395
+ add_meta_box('sdm_shortcode_meta_box',
396
+ __('Shortcodes', 'sdm_lang'),
397
+ array( &$this, 'display_sdm_shortcode_meta_box'),
398
+ 'sdm_downloads', 'normal', 'default'
399
+ );
400
+ add_meta_box('sdm_stats_meta_box',
401
+ __('Statistics', 'sdm_lang'),
402
+ array( &$this, 'display_sdm_stats_meta_box'),
403
+ 'sdm_downloads', 'normal', 'default'
404
+ );
405
+ }
406
+
407
+ public function display_sdm_description_meta_box( $post ) { // Description metabox
408
+
409
+ _e('Add a description for this download item.','sdm_lang');
410
+ echo '<br /><br />';
411
+
412
+ $old_description = get_post_meta( $post->ID, 'sdm_description', true );
413
+ ?>
414
  <textarea id="sdm_description" name="sdm_description" style="width:60%;height:40px;"><?php echo $old_description; ?></textarea>
415
  <?php
416
+ wp_nonce_field( 'sdm_description_box_nonce', 'sdm_description_box_nonce_check' );
417
+ }
418
+
419
+ public function display_sdm_upload_meta_box( $post ) { // File Upload metabox
420
+
421
+ $old_upload = get_post_meta( $post->ID, 'sdm_upload', true );
422
+ $old_value = isset($old_upload) ? $old_upload : '';
423
+ _e('Click "Select File" to upload (or choose) the file.', 'sdm_lang');
424
+ ?>
425
  <br /><br />
426
+ <input id="upload_image_button" type="button" class="button-primary" value="<?php _e('Select File', 'sdm_lang'); ?>" />
427
  <span style="margin-left:40px;"></span>
428
+ <?php _e('File URL:', 'sdm_lang') ?> <input id="sdm_upload" type="text" size="70" name="sdm_upload" value="<?php echo $old_value; ?>" />
429
  <?php
430
+ wp_nonce_field( 'sdm_upload_box_nonce', 'sdm_upload_box_nonce_check' );
431
+ }
432
+
433
+ public function display_sdm_thumbnail_meta_box( $post ) { // Thumbnail upload metabox
434
+
435
+ $old_thumbnail = get_post_meta( $post->ID, 'sdm_upload_thumbnail', true );
436
+ $old_value = isset($old_thumbnail) ? $old_thumbnail : '';
437
+ _e('Click "Select Image" to upload (or choose) the file thumbnail image. This thumbnail image will be used to create a fancy file download box if you want to use it.', 'sdm_lang');
438
+ echo '<br />';
439
+ _e('Recommended image size is 75px by 75px.', 'sdm_lang');
440
+ ?>
441
  <br /><br />
442
+ <input id="upload_thumbnail_button" type="button" class="button-primary" value="<?php _e('Select Image', 'sdm_lang'); ?>" />
443
+ <input id="remove_thumbnail_button" type="button" class="button" value="<?php _e('Remove Image', 'sdm_lang'); ?>" />
444
  <span style="margin-left:40px;"></span>
445
+ <input id="sdm_upload_thumbnail" type="hidden" size="70" name="sdm_upload_thumbnail" value="<?php echo $old_value; ?>" />
446
  <span id="sdm_get_thumb">
447
+ <?php
448
+ if($old_value != '') {
449
+ ?><img id="sdm_thumbnail_image" src="<?php echo $old_value; ?>" style="width:75px;height:75px;" />
450
  <?php
451
+ }
452
+ ?></span><?php
453
+ wp_nonce_field( 'sdm_thumbnail_box_nonce', 'sdm_thumbnail_box_nonce_check' );
454
+ }
455
+
456
+ public function display_sdm_shortcode_meta_box( $post ) { // Shortcode metabox
457
+
458
+ _e('This is the shortcode which can used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter to add this shortcode to a post or page.','sdm_lang');
459
+ echo '<br />';
460
+ echo '[sdm_download id="'.$post->ID.'" fancy="0"]';
461
+ echo '<br /><br />';
462
+
463
+ _e('This shortcode may be used as a download counter.', 'sdm_lang');
464
+ echo '<br />';
465
+ echo '[sdm_download_counter id="'.$post->ID.'"]';
466
+ }
467
+
468
+ public function display_sdm_stats_meta_box( $post ) { // Stats metabox
469
+
470
+ $old_count = get_post_meta( $post->ID, 'sdm_count_offset', true );
471
+ $value = isset($old_count) && $old_count != '' ? $old_count : '0';
472
+
473
+ _e('These are the statistics for this download item.','sdm_lang');
474
+ echo '<br /><br />';
475
+
476
+ global $wpdb;
477
+ $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$wpdb->prefix.'sdm_downloads WHERE post_id=%s', $post->ID));
478
+ _e('Number of Downloads:', 'sdm_lang'); echo ' <strong>'.$wpdb->num_rows.'</strong>';
479
+ echo '<span style="margin-left: 20px;"></span>';
480
+ _e('Offset Count', 'sdm_lang');
481
+ echo ' <input type="text" style="width:50px;" name="sdm_count_offset" value="'.$value.'" />';
482
+ echo ' <img src="'.WP_SIMPLE_DL_MONITOR_URL.'/css/images/info.png" style="margin-left:10px;" title="Enter any positive or negative numerical value; to offset the download count shown, when using the download counter shortcode." />';
483
+ wp_nonce_field( 'sdm_count_offset_nonce', 'sdm_count_offset_nonce_check' );
484
+ }
485
+
486
+ public function sdm_save_description_meta_data($post_id) { // Save Description metabox
487
+
488
+ if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
489
+ return;
490
+ if( !isset( $_POST['sdm_description_box_nonce_check'] ) || !wp_verify_nonce( $_POST['sdm_description_box_nonce_check'], 'sdm_description_box_nonce' ) )
491
+ return;
492
+
493
+ if( isset( $_POST['sdm_description'] ) ) {
494
+ update_post_meta( $post_id, 'sdm_description', $_POST['sdm_description'] );
495
+ }
496
+
497
+ }
498
+
499
+ public function sdm_save_upload_meta_data($post_id) { // Save File Upload metabox
500
+
501
+ if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
502
+ return;
503
+ if( !isset( $_POST['sdm_upload_box_nonce_check'] ) || !wp_verify_nonce( $_POST['sdm_upload_box_nonce_check'], 'sdm_upload_box_nonce' ) )
504
+ return;
505
+
506
+ if( isset( $_POST['sdm_upload'] ) ) {
507
+ update_post_meta( $post_id, 'sdm_upload', $_POST['sdm_upload'] );
508
+ }
509
+ }
510
+
511
+ public function sdm_save_thumbnail_meta_data($post_id) { // Save Thumbnail Upload metabox
512
+
513
+ if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
514
+ return;
515
+ if( !isset( $_POST['sdm_thumbnail_box_nonce_check'] ) || !wp_verify_nonce( $_POST['sdm_thumbnail_box_nonce_check'], 'sdm_thumbnail_box_nonce' ) )
516
+ return;
517
+
518
+ if( isset( $_POST['sdm_upload_thumbnail'] ) ) {
519
+ update_post_meta( $post_id, 'sdm_upload_thumbnail', $_POST['sdm_upload_thumbnail'] );
520
+ }
521
+ }
522
+
523
+ public function sdm_save_statistics_meta_data($post_id) { // Save Thumbnail Upload metabox
524
+
525
+ if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
526
+ return;
527
+ if( !isset( $_POST['sdm_count_offset_nonce_check'] ) || !wp_verify_nonce( $_POST['sdm_count_offset_nonce_check'], 'sdm_count_offset_nonce' ) )
528
+ return;
529
+
530
+ if(isset($_POST['sdm_count_offset']) && is_numeric($_POST['sdm_count_offset'])) {
531
+
532
+ update_post_meta( $post_id, 'sdm_count_offset', $_POST['sdm_count_offset'] );
533
+ }
534
+ }
535
+
536
+ public function sdm_remove_view_link_cpt($action, $post) {
537
+
538
+ // Only execute on SDM CPT posts page
539
+ if($post->post_type == 'sdm_downloads') {
540
+ unset ($action['view']);
541
+ }
542
+
543
  return $action;
544
+ }
545
+
546
+ public function sdm_register_options() {
547
+
548
+ register_setting( 'sdm_downloads_options', 'sdm_downloads_options' );
549
+ add_settings_section( 'admin_options', __('Admin Options', 'sdm_lang'), array( $this, 'admin_options_cb' ), 'admin_options_section' );
550
+ add_settings_section( 'sdm_colors', __('Colors', 'sdm_lang'), array( $this, 'sdm_colors_cb' ), 'sdm_colors_section' );
551
+
552
+ add_settings_field( 'admin_tinymce_button', __('Remove Tinymce Button', 'sdm_lang'), array( $this, 'admin_tinymce_button_cb' ), 'admin_options_section', 'admin_options' );
553
+ add_settings_field( 'download_button_color', __('Download Button Color', 'sdm_lang'), array( $this, 'download_button_color_cb' ), 'sdm_colors_section', 'sdm_colors' );
554
+ }
555
+ public function admin_options_cb() {
556
+ _e('Admin options settings', 'sdm_lang');
557
+ }
558
+ public function sdm_colors_cb() {
559
+ _e('Front End colors settings', 'sdm_lang');
560
+ }
561
+ public function admin_tinymce_button_cb() {
562
+ $main_opts = get_option('sdm_downloads_options');
563
+ echo '<input name="sdm_downloads_options[admin_tinymce_button]" id="admin_tinymce_button" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset($main_opts['admin_tinymce_button']), false ) . ' /> ';
564
+ _e('Removes the SDM Downloads button from the WP content editor.', 'sdm_lang');
565
+ }
566
+ public function download_button_color_cb() {
567
+ $main_opts = get_option('sdm_downloads_options');
568
+ $color_opt = $main_opts['download_button_color'];
569
+ $color_opts = array( __('Green','sdm_lang'), __('Blue','sdm_lang'),__('Purple','sdm_lang'),__('Teal','sdm_lang'),__('Dark Blue','sdm_lang'),__('Black','sdm_lang'),__('Grey','sdm_lang'),__('Pink','sdm_lang'),__('Orange','sdm_lang'),__('White','sdm_lang') );
570
+ echo '<select name="sdm_downloads_options[download_button_color]" id="download_button_color" class="sdm_opts_ajax_dropdowns">';
571
+ if(isset($color_opt)) {
572
+ echo '<option value="'.$color_opt.'" selected="selected">'.$color_opt.' ('.__('current', 'sdm_lang').')</option>';
573
+ }
574
+ foreach ($color_opts as $color) {
575
+ echo '<option value="'.$color.'" '.$sel_color.'>'.$color.'</option>';
576
+ }
577
+ echo '</select> ';
578
+ _e('Adjusts the color of the "Download Now" button.', 'sdm_lang');
579
+ }
580
+
 
 
 
 
581
  }
 
582
  $simpleDownloadManager = new simpleDownloadManager();
583
 
584
  /*
585
+ **
586
+ ** Logs Page
587
+ **
588
+ */
589
  //*****
590
  //***** Check WP_List_Table exists
591
+ if(!class_exists('WP_List_Table')){
592
  require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
593
  }
594
 
595
  //*****
596
  //***** Define our new Table
597
  class sdm_List_Table extends WP_List_Table {
598
+
599
+
600
+ function __construct(){
601
+
602
  global $status, $page;
603
+
604
  //Set parent defaults
605
+ parent::__construct( array(
606
+ 'singular' => __('Download', 'sdm_lang'), //singular name of the listed records
607
+ 'plural' => __('Downloads', 'sdm_lang'), //plural name of the listed records
608
+ 'ajax' => false //does this table support ajax?
609
+ ) );
610
+
611
  }
612
+
613
+ function column_default($item, $column_name){
614
+
615
+ switch($column_name){
616
  case 'URL':
617
  case 'visitor_ip':
618
  case 'date':
619
  return $item[$column_name];
620
+ case 'visitor_country':
621
+ return $item[$column_name];
622
  default:
623
+ return print_r($item,true); //Show the whole array for troubleshooting purposes
624
  }
625
  }
626
+
627
+ function column_title($item){
628
+
629
  //Build row actions
630
  $actions = array(
631
+ 'edit' => sprintf('<a href="'.admin_url( 'post.php?post='.$item['ID'].'&action=edit' ).'">'.__('Edit', 'sdm_lang').'</a>'),
632
+ 'delete' => sprintf('<a href="?post_type=sdm_downloads&page=%s&action=%s&download=%s&datetime=%s">'.__('Delete', 'sdm_lang').'</a>',$_REQUEST['page'],'delete',$item['ID'],$item['date'])
633
  );
634
+
635
  //Return the title contents
636
  return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
637
+ /*$1%s*/ $item['title'],
638
+ /*$2%s*/ $item['ID'],
639
+ /*$3%s*/ $this->row_actions($actions)
640
  );
641
  }
642
+
643
+ function column_cb($item){
644
+
645
  return sprintf(
646
+ '<input type="checkbox" name="%1$s[]" value="%2$s" />',
647
+ /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("Download")
648
+ /*$2%s*/ $item['ID'].'|'.$item['date'] //The value of the checkbox should be the record's id
649
  );
650
  }
651
+
652
+ function get_columns(){
653
+
654
  $columns = array(
655
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
656
+ 'title' => __('Title','sdm_lang'),
657
+ 'URL' => __('File','sdm_lang'),
658
+ 'visitor_ip' => __('Visitor IP','sdm_lang'),
659
+ 'date' => __('Date','sdm_lang'),
660
+ 'visitor_country' => __('Country','sdm_lang')
661
  );
662
  return $columns;
663
  }
664
+
665
  function get_sortable_columns() {
666
+
667
  $sortable_columns = array(
668
+ 'title' => array('title',false), //true means it's already sorted
669
+ 'URL' => array('URL',false),
670
+ 'visitor_ip' => array('visitor_ip',false),
671
+ 'date' => array('date',false),
672
+ 'visitor_country' => array('visitor_country',false)
673
  );
674
  return $sortable_columns;
675
  }
676
+
677
  function get_bulk_actions() {
678
+
679
  $actions = array();
680
+ $actions['delete2'] = __( 'Delete Permanently', 'sdm_lang' );
681
+ $actions['export_all'] = __( 'Export All as Excel', 'sdm_lang' );
682
  //$actions['export-selected'] = __( 'Export Selected', 'sdm_lang' );
683
 
684
  return $actions;
685
  }
686
+
687
  function process_bulk_action() {
688
+
689
+ // security check!
690
+ if ( isset( $_POST['_wpnonce'] ) && ! empty( $_POST['_wpnonce'] ) ) {
691
 
692
+ $nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
 
 
 
693
  $action = 'bulk-' . $this->_args['plural'];
694
 
695
+ if ( ! wp_verify_nonce( $nonce, $action ) )
696
+ wp_die( __('Nope! Security check failed!', 'sdm_lang') );
 
 
 
 
 
 
 
 
 
 
 
 
697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
698
  }
699
 
700
+ $action = $this->current_action();
701
+
702
+ // If bulk 'Export All' was clicked
703
+ if( 'export_all' === $this->current_action() ) {
704
+
705
+ echo '<div id="message" class="updated"><p><strong><a id="sdm_download_export" href="?post_type=sdm_downloads&page=logs&download_log">'.__('Download Export File', 'sdm_lang').'</a></strong></p></div>';
706
+ }
707
+
708
+ // if bulk 'Delete Permanently' was clicked
709
+ if( 'delete2' === $this->current_action() ) {
710
+
711
+ if( !isset($_POST['download']) || $_POST['download'] == null) {
712
+ echo '<div id="message" class="updated fade"><p><strong>'.__('No entries were selected.', 'sdm_lang').'</strong></p><p><em>'.__('Click to Dismiss', 'sdm_lang').'</em></p></div>';
713
+ return;
714
+ }
715
+
716
+ foreach($_POST['download'] as $item) {
717
+ $str_tok_id = substr($item, 0, strpos($item, '|'));
718
+ $str_tok_datetime = substr($item,strpos($item,'|')+1);
719
+
720
+ global $wpdb;
721
+ $del_row = $wpdb->query(
722
+ 'DELETE FROM '.$wpdb->prefix.'sdm_downloads
723
+ WHERE post_id = "'.$str_tok_id.'"
724
+ AND date_time = "'.$str_tok_datetime.'"'
725
+ );
726
+ }
727
+ if($del_row) {
728
+ echo '<div id="message" class="updated fade"><p><strong>'.__('Entries Deleted!', 'sdm_lang').'</strong></p><p><em>'.__('Click to Dismiss', 'sdm_lang').'</em></p></div>';
729
+ }
730
+ else {
731
+ echo '<div id="message" class="updated fade"><p><strong>'.__('Error', 'sdm_lang').'</strong></p><p><em>'.__('Click to Dismiss', 'sdm_lang').'</em></p></div>';
732
+ }
733
+ }
734
+
735
+ // If single entry 'Delete' was clicked
736
+ if( 'delete'===$this->current_action() ) {
737
+
738
+ $item_id = isset($_GET['download']) ? strtok($_GET['download'], '|') : '';
739
+ $item_datetime = isset($_GET['datetime']) ? $_GET['datetime'] : '';
740
+
741
+ global $wpdb;
742
+ $del_row = $wpdb->query(
743
+ 'DELETE FROM '.$wpdb->prefix.'sdm_downloads
744
+ WHERE post_id = "'.$item_id.'"
745
+ AND date_time = "'.$item_datetime.'"'
746
+ );
747
+ if($del_row) {
748
+ echo '<div id="message" class="updated fade"><p><strong>'.__('Entry Deleted!', 'sdm_lang').'</strong></p><p><em>'.__('Click to Dismiss', 'sdm_lang').'</em></p></div>';
749
+ }
750
+ else {
751
+ echo '<div id="message" class="updated fade"><p><strong>'.__('Error', 'sdm_lang').'</strong></p><p><em>'.__('Click to Dismiss', 'sdm_lang').'</em></p></div>';
752
+ }
753
  }
754
+
755
  }
756
+
757
  function prepare_items() {
758
+
759
  global $wpdb; //This is used only if making any database queries
760
  $per_page = 10;
761
  $columns = $this->get_columns();
762
  $hidden = array();
763
  $sortable = $this->get_sortable_columns();
764
+
765
+
766
  $this->_column_headers = array($columns, $hidden, $sortable);
767
  $this->process_bulk_action();
 
768
  //$data = $this->example_data;
769
+
770
+ function usort_reorder($a,$b){
771
  $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'title'; //If no sort, default to title
772
  $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
773
  $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
774
+ return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
 
 
 
 
 
 
775
  }
776
+
777
+ $data_results = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'sdm_downloads');
778
+ $data = array();
779
+ foreach ($data_results as $data_result) {
780
+ $data[] = array( 'ID' => $data_result->post_id, 'title' => $data_result->post_title, 'URL' => $data_result->file_url, 'visitor_ip' => $data_result->visitor_ip, 'date' => $data_result->date_time, 'visitor_country' => $data_result->visitor_country );
781
+ }
782
+
783
+
784
  usort($data, 'usort_reorder');
785
  $current_page = $this->get_pagenum();
786
  $total_items = count($data);
787
+ $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
788
+
789
  $this->items = $data;
790
+ $this->set_pagination_args( array(
791
+ 'total_items' => $total_items, //WE have to calculate the total number of items
792
+ 'per_page' => $per_page, //WE have to determine how many items to show on a page
793
+ 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages
794
+ ) );
795
  }
796
+
797
  }
798
+ function sdm_create_logs_page(){
799
+
 
800
  //Create an instance of our package class...
801
  $sdmListTable = new sdm_List_Table();
802
  //Fetch, prepare, sort, and filter our data...
803
  $sdmListTable->prepare_items();
804
+
805
  ?>
806
  <div class="wrap">
807
+
808
  <div id="icon-users" class="icon32"><br/></div>
809
  <h2><?php _e('Download Logs', 'sdm_lang'); ?></h2>
810
+
811
  <div style="background:#ECECEC;border:1px solid #CCC;padding:0 10px;margin-top:5px;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;">
812
  <p><?php _e('This page lists all tracked downloads.', 'sdm_lang'); ?></p>
813
  </div>
814
+
815
  <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
816
  <form id="sdm_downloads-filter" method="post">
817
  <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
818
  <!-- Now we can render the completed list table -->
819
+ <?php $sdmListTable->display() ?>
820
  </form>
821
+
822
  </div>
823
  <script type="text/javascript">
824
+ jQuery(document).ready(function($){
825
+ $('.fade').click(function(){$(this).fadeOut('slow');});
826
+ });
827
+ </script>
 
 
828
  <?php
829
  }
830
 
831
+ function sdm_get_password_entry_form($id)
832
+ {
833
+ $data = __('Enter Password to Download:','sdm_lang');
834
+ $data .= '<form method="post">';
835
+ $data .= '<input type="password" class="pass_text" value="" /> ';
836
+ $data .= '<input type="button" class="pass_sumbit" value="'.__('Submit','sdm_lang').'" />';
837
+ $data .= '<input type="hidden" value="'.$id.'" />';
838
+ $data .= '</form>';
839
+ return $data;
840
  }
841
 
842
  /*
843
+ ** Register scripts for front-end posts/pages
844
+ */
845
+ add_action( 'wp_enqueue_scripts', 'sdm_wp_scripts' );
846
+ function sdm_wp_scripts() {
847
+
848
+ wp_enqueue_style( 'sdm-styles', WP_SIMPLE_DL_MONITOR_URL. '/css/sdm_wp_styles.css' );
849
+ wp_register_script('sdm-scripts', WP_SIMPLE_DL_MONITOR_URL. '/js/sdm_wp_scripts.js', array( 'jquery' ) );
850
+ wp_enqueue_script('sdm-scripts');
851
+
852
+ // Localize ajax script for frontend
853
+ wp_localize_script( 'sdm-scripts', 'sdm_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
854
  }
855
 
856
+ function handle_sdm_download_via_direct_post()
857
+ {
858
+ if(isset($_REQUEST['smd_process_download']) && $_REQUEST['smd_process_download'] == '1')
859
+ {
860
+ $download_id = strip_tags($_REQUEST['download_id']);
861
+ $download_title = get_the_title( $download_id );
862
+ $download_link = get_post_meta( $download_id, 'sdm_upload', true );
863
+ $ipaddress = $_SERVER["REMOTE_ADDR"];
864
+ $date_time = current_time( 'mysql' );
865
+ $visitor_country = sdm_ip_info('Visitor', 'Country');
866
+
867
+ global $wpdb;
868
+ $table = $wpdb->prefix . 'sdm_downloads';
869
+ $data = array(
870
+ 'post_id' => $download_id,
871
+ 'post_title' => $download_title,
872
+ 'file_url' => $download_link,
873
+ 'visitor_ip' => $ipaddress,
874
+ 'date_time' => $date_time,
875
+ 'visitor_country' => $visitor_country
876
+ );
877
+
878
+ $insert_table = $wpdb->insert( $table, $data );
879
+
880
+ if ($insert_table) {//Download request was logged successfully
881
+ sdm_redirect_to_url($download_link);
882
+ }
883
+ else {//Failed to log the download request
884
+ wp_die ( __('Error! Failed to log the download request in the database table', 'sdm_lang') );
885
+ }
886
+ exit;
887
+ }
888
+ }
889
+
890
+ function sdm_redirect_to_url($url,$delay='0',$exit='1')
891
+ {
892
+ if(empty($url)){
893
+ echo '<strong>';
894
+ _e('Error! The URL value is empty. Please specify a correct URL value to redirect to!', 'sdm_lang');
895
+ echo '</strong>';
896
+ exit;
897
+ }
898
+ if (!headers_sent()){
899
+ header('Location: ' . $url);
900
+ }
901
+ else{
902
+ echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'" />';
903
+ }
904
+ if($exit == '1'){//exit
905
+ exit;
906
+ }
907
  }
908
 
909
  // Tinymce Button Populate Post ID's
910
+ add_action( 'wp_ajax_nopriv_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
911
+ add_action( 'wp_ajax_sdm_tiny_get_post_ids', 'sdm_tiny_get_post_ids_ajax_call' );
 
912
  function sdm_tiny_get_post_ids_ajax_call() {
913
+
914
+ $args = array(
915
+ 'post_type' => 'sdm_downloads',
916
+ );
917
+ $loop = new WP_Query($args);
918
+ $test = '';
919
+ foreach ($loop->posts as $loop_post) {
920
+ //$test .= $loop_post->ID.'|'.$loop_post->post_title.'_';
921
+ $test[] = array('post_id' => $loop_post->ID, 'post_title' => $loop_post->post_title);
922
+ }
923
+
924
+ $response = json_encode( array( 'success' => true, 'test' => $test ));
925
+
926
+ header( 'Content-Type: application/json' );
927
+ echo $response;
928
+ exit;
929
  }
 
930
  // Remove Thumbnail Image
931
+ add_action( 'wp_ajax_nopriv_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call' );
932
+ add_action( 'wp_ajax_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call' );
 
933
  function sdm_remove_thumbnail_image_ajax_call() {
934
+
935
+ $post_id = $_POST['post_id_del'];
936
+ $success = delete_post_meta( $post_id, 'sdm_upload_thumbnail' );
937
+ if($success) {
938
+ $response = json_encode( array( 'success' => true ));
939
+ }
940
+
941
+ header( 'Content-Type: application/json' );
942
+ echo $response;
943
+ exit;
944
  }
 
945
  // Check download password
946
+ add_action( 'wp_ajax_nopriv_sdm_check_pass', 'sdm_check_pass_ajax_call' );
947
+ add_action( 'wp_ajax_sdm_check_pass', 'sdm_check_pass_ajax_call' );
 
948
  function sdm_check_pass_ajax_call() {
949
+
950
+ $button_id = $_POST['button_id']; // Get button cpt id
951
+ $pass_val = $_POST['pass_val']; // Get password attempt
952
+ $success = '';
953
+ $download_link = '';
954
+
955
+ // Get post object
956
+ $post_object = get_post($button_id);
957
+ // Get post password
958
+ $post_pass = $post_object->post_password;
959
+
960
+ // Check if password is a match
961
+ if($post_pass != $pass_val) { // Match is a failure
962
+
963
+ $success = 'no'; // Pass back to ajax
964
+ }
965
+ else { // Match is a success
966
+
967
+ $success = 'yes'; // Pass back to ajax
968
+
969
+ $download_id = $button_id;
970
+ $download_title = get_the_title( $download_id );
971
+ $download_link = get_post_meta( $download_id, 'sdm_upload', true );
972
+ $ipaddress = $_SERVER["REMOTE_ADDR"];
973
+ $date_time = current_time( 'mysql' );
974
+ $visitor_country = sdm_ip_info('Visitor', 'Country');
975
+
976
+ global $wpdb;
977
+ $table = $wpdb->prefix . 'sdm_downloads';
978
+ $data = array(
979
+ 'post_id' => $download_id,
980
+ 'post_title' => $download_title,
981
+ 'file_url' => $download_link,
982
+ 'visitor_ip' => $ipaddress,
983
+ 'date_time' => $date_time,
984
+ 'visitor_country' => $visitor_country
985
+ );
986
+
987
+ $insert_table = $wpdb->insert( $table, $data );
988
+ }
989
+
990
+ // Generate ajax response
991
+ $response = json_encode( array( 'success' => $success, 'url' => $download_link ));
992
+ header( 'Content-Type: application/json' );
993
+ echo $response;
994
+ exit;
995
  }
 
996
  // Populate category tree
997
+ add_action( 'wp_ajax_nopriv_sdm_pop_cats', 'sdm_pop_cats_ajax_call' );
998
+ add_action( 'wp_ajax_sdm_pop_cats', 'sdm_pop_cats_ajax_call' );
 
999
  function sdm_pop_cats_ajax_call() {
1000
+
1001
+ $cat_slug = $_POST['cat_slug']; // Get button cpt slug
1002
+ $parent_id = $_POST['parent_id']; // Get button cpt id
1003
+
1004
+ // Query custom posts based on taxonomy slug
1005
+ $posts = query_posts(array(
1006
+ 'post_type' => 'sdm_downloads',
1007
+ //'showposts' => -1,
1008
+ 'tax_query' => array(
1009
+ array(
1010
+ 'taxonomy' => 'sdm_categories',
1011
+ 'terms' => $cat_slug,
1012
+ 'field' => 'slug',
1013
+ 'include_children' => 0
1014
+ )
1015
+ ),
1016
+ 'orderby' => 'title',
1017
+ 'order' => 'ASC' )
1018
+ );
1019
+
1020
+ // Loop results
1021
+ foreach($posts as $post) {
1022
+
1023
+ // Create array of variables to pass to js
1024
+ $final_array[] = array('id' => $post->ID, 'permalink' => get_permalink($post->ID), 'title' => $post->post_title);
1025
+ }
1026
+
1027
+ // Generate ajax response
1028
+ $response = json_encode( array( 'final_array' => $final_array ));
1029
+ header( 'Content-Type: application/json' );
1030
+ echo $response;
1031
+ exit;
1032
  }
1033
 
1034
  /*
1035
+ ** Setup Sortable Columns
1036
+ */
1037
+ add_filter( 'manage_edit-sdm_downloads_columns', 'sdm_create_columns' ); // Define columns
1038
+ add_filter( 'manage_edit-sdm_downloads_sortable_columns', 'sdm_downloads_sortable' ); // Make sortable
1039
+ add_action( 'manage_sdm_downloads_posts_custom_column', 'sdm_downloads_columns_content', 10, 2 ); // Populate new columns
1040
+ function sdm_create_columns( $cols ) {
1041
+
1042
+ unset( $cols['title'] );
1043
+ unset( $cols['taxonomy-sdm_tags'] );
1044
+ unset( $cols['taxonomy-sdm_categories'] );
1045
+ unset( $cols['date'] );
1046
+ unset( $cols['visitor_country'] );
1047
+
1048
+ $cols['sdm_downloads_thumbnail'] = __('Image', 'sdm_lang');
1049
+ $cols['title'] = __('Title', 'sdm_lang');
1050
+ $cols['sdm_downloads_id'] = __('ID', 'sdm_lang');
1051
+ $cols['sdm_downloads_file'] = __('File', 'sdm_lang');
1052
+ $cols['taxonomy-sdm_categories'] = __('Categories', 'sdm_lang');
1053
+ $cols['taxonomy-sdm_tags'] = __('Tags', 'sdm_lang');
1054
+ $cols['sdm_downloads_count'] = __('Downloads', 'sdm_lang');
1055
+ $cols['date'] = __('Date Posted', 'sdm_lang');
1056
+ $cols['visitor_country'] = __('Visitor Country', 'sdm_lang');
1057
+ return $cols;
 
1058
  }
1059
 
1060
+ function sdm_downloads_sortable( $cols ) {
1061
+
1062
+ $cols['sdm_downloads_id'] = 'sdm_downloads_id';
1063
+ $cols['sdm_downloads_file'] = 'sdm_downloads_file';
1064
+ $cols['sdm_downloads_count'] = 'sdm_downloads_count';
1065
+ $cols['taxonomy-sdm_categories'] = 'taxonomy-sdm_categories';
1066
+ $cols['taxonomy-sdm_tags'] = 'taxonomy-sdm_tags';
1067
+ return $cols;
1068
  }
1069
 
1070
+ function sdm_downloads_columns_content( $column_name, $post_ID ) {
1071
+
1072
+ if ($column_name == 'sdm_downloads_thumbnail') {
1073
+ $old_thumbnail = get_post_meta( $post_ID, 'sdm_upload_thumbnail', true );
1074
+ //$old_value = isset($old_thumbnail) ? $old_thumbnail : '';
1075
+ if($old_thumbnail) {
1076
+ echo '<p class="sdm_downloads_count"><img src="'.$old_thumbnail.'" style="width:50px;height:50px;" /></p>';
1077
+ }
1078
+ }
1079
+ if ($column_name == 'sdm_downloads_id') {
1080
+ echo '<p class="sdm_downloads_postid">'.$post_ID.'</p>';
1081
+ }
1082
+ if ($column_name == 'sdm_downloads_file') {
1083
+ $old_file = get_post_meta( $post_ID, 'sdm_upload', true );
1084
+ $file = isset($old_file) ? $old_file : '--';
1085
+ echo '<p class="sdm_downloads_file">'.$file.'</p>';
1086
+ }
1087
+ if ($column_name == 'sdm_downloads_count') {
1088
+ global $wpdb;
1089
+ $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$wpdb->prefix.'sdm_downloads WHERE post_id=%s', $post_ID));
1090
+ echo '<p class="sdm_downloads_count">'.$wpdb->num_rows.'</p>';
1091
+ }
1092
  }
 
1093
  // Adjust admin column widths
1094
  add_action('admin_head', 'sdm_admin_column_width'); // Adjust column width in admin panel
 
1095
  function sdm_admin_column_width() {
1096
+
1097
  echo '<style type="text/css">';
1098
  echo '.column-sdm_downloads_thumbnail { width:75px !important; overflow:hidden }';
1099
  echo '.column-sdm_downloads_id { width:100px !important; overflow:hidden }';
1100
  echo '.column-taxonomy-sdm_categories { width:200px !important; overflow:hidden }';
1101
  echo '.column-taxonomy-sdm_tags { width:200px !important; overflow:hidden }';
1102
  echo '</style>';
1103
+ }
1104
 
1105
  /*
1106
+ ** Register Tinymce Button
1107
+ */
1108
 
1109
  // First check if option is checked to disable tinymce button
1110
  $main_option = get_option('sdm_downloads_options');
1111
  $tiny_button_option = isset($main_option['admin_tinymce_button']);
1112
+ if($tiny_button_option != true) {
1113
+
1114
+ // Okay.. we're good. Add the button.
1115
+ add_action( 'init', 'sdm_downloads_tinymce_button' );
1116
+ function sdm_downloads_tinymce_button() {
1117
+
1118
+ add_filter( 'mce_external_plugins', 'sdm_downloads_add_button' );
1119
+ add_filter( 'mce_buttons', 'sdm_downloads_register_button' );
1120
+ }
1121
+ function sdm_downloads_add_button( $plugin_array ) {
1122
+
1123
+ $plugin_array['sdm_downloads'] = WP_SIMPLE_DL_MONITOR_URL. '/tinymce/sdm_editor_plugin.js';
1124
+ return $plugin_array;
1125
+ }
1126
+ function sdm_downloads_register_button( $buttons ) {
1127
+
1128
+ //array_push( $buttons, 'sdm_downloads' );
1129
+ $buttons[] = 'sdm_downloads';
1130
+ return $buttons;
1131
+ }
 
 
 
 
1132
  }
1133
 
1134
+
1135
  // Helper function to get visitor country (or other info)
1136
  function sdm_ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
1137
  $output = NULL;
1144
  $ip = $_SERVER['HTTP_CLIENT_IP'];
1145
  }
1146
  }
1147
+ $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose)));
1148
+ $support = array("country", "countrycode", "state", "region", "city", "location", "address");
1149
  $continents = array(
1150
  "AF" => "Africa",
1151
  "AN" => "Antarctica",
1161
  switch ($purpose) {
1162
  case "location":
1163
  $output = array(
1164
+ "city" => @$ipdat->geoplugin_city,
1165
+ "state" => @$ipdat->geoplugin_regionName,
1166
+ "country" => @$ipdat->geoplugin_countryName,
1167
+ "country_code" => @$ipdat->geoplugin_countryCode,
1168
+ "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)],
1169
  "continent_code" => @$ipdat->geoplugin_continentCode
1170
  );
1171
  break;
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Tips and Tricks HQ, Ruhul Amin, josh401
3
  Donate link: http://www.tipsandtricks-hq.com
4
  Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, downloadmanager, file manager, protect downloads, password, download category, file tree, ajax,
5
  Requires at least: 3.0
6
- Tested up to: 3.9
7
- Stable tag: 2.9
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
@@ -35,6 +35,7 @@ http://www.youtube.com/watch?v=L-mXbs7kp0s
35
  * Use shortcodes to display a download now button on a WordPress post/page.
36
  * Show a trackable download now button for your files anywhere on your site.
37
  * Download counter for each file.
 
38
  * Track IP addresses of the users who downloaded your files.
39
  * Track date and time of each file downloads.
40
  * Option to upload a thumbnail image for each of your downloadable files.
@@ -44,11 +45,13 @@ http://www.youtube.com/watch?v=L-mXbs7kp0s
44
  * Track the visitors country.
45
  * WordPress Shortcode for embedding a download link for a file.
46
  * Tinymce button in the WordPress post/page editor so you can easily add the shortcode.
 
47
  * Ability to add the download now buttons to your sidebar widget.
48
  * Create password protected download now buttons. Users will only be able to download the file if they enter the correct password
49
  * Shortcode to show the download counter of a file. Use it to show off your file download count.
50
  * Shortcode to show all the downloads from a particular category.
51
  * Shortcode to embed a file tree browser for your downloadable files. The file browser is ajax based and it shows the files structured by categories.
 
52
 
53
  View more details on the [download monitor plugin](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin) page.
54
 
@@ -126,6 +129,12 @@ For screenshots please visit the [download monitor plugin page](http://www.tipsa
126
 
127
  == Changelog ==
128
 
 
 
 
 
 
 
129
  = 2.9 =
130
  * Added visitor Country to database table; allowing tracking of each download visitors Country.
131
  * Visitor Country is also seen in the "Logs" page; can be sorted; and exported.
3
  Donate link: http://www.tipsandtricks-hq.com
4
  Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, downloadmanager, file manager, protect downloads, password, download category, file tree, ajax,
5
  Requires at least: 3.0
6
+ Tested up to: 3.9.1
7
+ Stable tag: 3.0
8
  License: GPLv2 or later
9
 
10
  Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
35
  * Use shortcodes to display a download now button on a WordPress post/page.
36
  * Show a trackable download now button for your files anywhere on your site.
37
  * Download counter for each file.
38
+ * Ability to set a download count offset for each file.
39
  * Track IP addresses of the users who downloaded your files.
40
  * Track date and time of each file downloads.
41
  * Option to upload a thumbnail image for each of your downloadable files.
45
  * Track the visitors country.
46
  * WordPress Shortcode for embedding a download link for a file.
47
  * Tinymce button in the WordPress post/page editor so you can easily add the shortcode.
48
+ * You can customize the "Download Now" button text of an item to anything you want.
49
  * Ability to add the download now buttons to your sidebar widget.
50
  * Create password protected download now buttons. Users will only be able to download the file if they enter the correct password
51
  * Shortcode to show the download counter of a file. Use it to show off your file download count.
52
  * Shortcode to show all the downloads from a particular category.
53
  * Shortcode to embed a file tree browser for your downloadable files. The file browser is ajax based and it shows the files structured by categories.
54
+ * Ability to open the downloads in new browser window or tab. When your users click on a download button, it will open in a new window or tab.
55
 
56
  View more details on the [download monitor plugin](http://www.tipsandtricks-hq.com/simple-wordpress-download-monitor-plugin) page.
57
 
129
 
130
  == Changelog ==
131
 
132
+
133
+ = 3.0 =
134
+ * Added an option to specify a download count offset for each download. This will allow you to set a starting download count for each item.
135
+ * Added a new parameter in the shortcode to allow customization of the button text. You can now customize the "Download Now" button text to anything you want from the shortcode.
136
+ * Added a new parameter in the shortcode to allow opening the download in a new window or tab.
137
+
138
  = 2.9 =
139
  * Added visitor Country to database table; allowing tracking of each download visitors Country.
140
  * Visitor Country is also seen in the "Logs" page; can be sorted; and exported.
sdm-shortcodes.php CHANGED
@@ -18,7 +18,9 @@ function sdm_create_download_shortcode( $atts ) {
18
 
19
  extract( shortcode_atts( array(
20
  'id' => 'id',
21
- 'fancy' => '0'
 
 
22
  ), $atts ) );
23
 
24
  // Check to see if the download link cpt is password protected
@@ -50,10 +52,19 @@ function sdm_create_download_shortcode( $atts ) {
50
  //Download counter
51
  //$dl_counter = sdm_create_counter_shortcode(array('id'=>$id));
52
 
53
- //Generate the download now button code
 
 
 
 
 
 
 
 
 
54
  $homepage = get_bloginfo('url');
55
  $download_url = $homepage. '/?smd_process_download=1&download_id='.$id;
56
- $download_button_code = '<a href="'.$download_url.'" class="sdm_download '.$def_color.'" title="'.$isset_item_title.'">'.__('Download Now!', 'sdm_lang').'</a>';
57
 
58
  if($cpt_is_password !== 'no'){//This is a password protected download so replace the download now button with password requirement
59
  $download_button_code = sdm_get_password_entry_form($id);
@@ -92,9 +103,22 @@ function sdm_create_counter_shortcode( $atts ) {
92
  global $wpdb;
93
  $table = $wpdb->prefix.'sdm_downloads';
94
  $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$table.' WHERE post_id=%s', $id));
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  // Return result
97
- return $wpdb->num_rows.' '.__('Downloads','sdm_lang');
98
  }
99
 
100
  // Create Category Shortcode
@@ -103,7 +127,9 @@ function sdm_handle_category_shortcode($args){
103
  extract( shortcode_atts( array(
104
  'category_slug' => '',
105
  'category_id' => '',
106
- 'fancy' => '0'
 
 
107
  ), $args ) );
108
 
109
  // Define vars
@@ -161,6 +187,17 @@ function sdm_handle_category_shortcode($args){
161
  $color_opt = $main_opts['download_button_color'];
162
  $def_color = isset($color_opt) ? str_replace(' ', '', strtolower($color_opt)) : __('green', 'sdm_lang');
163
 
 
 
 
 
 
 
 
 
 
 
 
164
  // Iterate cpt's
165
  foreach ($get_posts as $item) {
166
 
@@ -181,7 +218,7 @@ function sdm_handle_category_shortcode($args){
181
  $isset_item_description = isset($item_description) && !empty($item_description) ? $item_description : '';
182
 
183
  // Setup download button code
184
- $download_button_code = '<a href="'.$download_url.'" class="sdm_download '.$def_color.'" title="'.$isset_item_title.'">'.__('Download Now!', 'sdm_lang').'</a>';
185
 
186
  // Generate download buttons
187
  if ($fancy == '0') {
18
 
19
  extract( shortcode_atts( array(
20
  'id' => 'id',
21
+ 'fancy' => '0',
22
+ 'button_text' => '',
23
+ 'new_window' => '',
24
  ), $atts ) );
25
 
26
  // Check to see if the download link cpt is password protected
52
  //Download counter
53
  //$dl_counter = sdm_create_counter_shortcode(array('id'=>$id));
54
 
55
+ //*** Generate the download now button code ***
56
+ $window_target = '';
57
+ if(!empty($new_window)){
58
+ $window_target = 'target="_blank"';
59
+ }
60
+ if(empty($button_text)){//Use the default text for the button
61
+ $button_text_string = __('Download Now!', 'sdm_lang');
62
+ }else{//Use the custom text
63
+ $button_text_string = $button_text;
64
+ }
65
  $homepage = get_bloginfo('url');
66
  $download_url = $homepage. '/?smd_process_download=1&download_id='.$id;
67
+ $download_button_code = '<a href="'.$download_url.'" class="sdm_download '.$def_color.'" title="'.$isset_item_title.'" '.$window_target.'>'.$button_text_string.'</a>';
68
 
69
  if($cpt_is_password !== 'no'){//This is a password protected download so replace the download now button with password requirement
70
  $download_button_code = sdm_get_password_entry_form($id);
103
  global $wpdb;
104
  $table = $wpdb->prefix.'sdm_downloads';
105
  $wpdb->get_results($wpdb->prepare('SELECT * FROM '.$table.' WHERE post_id=%s', $id));
106
+ // Count database rows
107
+ $db_count = $wpdb->num_rows;
108
+
109
+ // Check post meta to see if we need to offset the count before displaying to viewers
110
+ $get_offset = get_post_meta( $id, 'sdm_count_offset', true );
111
+
112
+ if($get_offset && $get_offset != '') {
113
+
114
+ $db_count = $db_count + $get_offset;
115
+ }
116
+
117
+ // Set string for singular/plural results
118
+ $string = ($db_count == '1') ? __('Download','sdm_lang') : __('Downloads','sdm_lang');
119
 
120
  // Return result
121
+ return $db_count.' '.$string;
122
  }
123
 
124
  // Create Category Shortcode
127
  extract( shortcode_atts( array(
128
  'category_slug' => '',
129
  'category_id' => '',
130
+ 'fancy' => '0',
131
+ 'button_text' => '',
132
+ 'new_window' => '',
133
  ), $args ) );
134
 
135
  // Define vars
187
  $color_opt = $main_opts['download_button_color'];
188
  $def_color = isset($color_opt) ? str_replace(' ', '', strtolower($color_opt)) : __('green', 'sdm_lang');
189
 
190
+ $window_target = '';
191
+ if(!empty($new_window)){
192
+ $window_target = 'target="_blank"';
193
+ }
194
+
195
+ if(empty($button_text)){//Use the default text for the button
196
+ $button_text_string = __('Download Now!', 'sdm_lang');
197
+ }else{//Use the custom text
198
+ $button_text_string = $button_text;
199
+ }
200
+
201
  // Iterate cpt's
202
  foreach ($get_posts as $item) {
203
 
218
  $isset_item_description = isset($item_description) && !empty($item_description) ? $item_description : '';
219
 
220
  // Setup download button code
221
+ $download_button_code = '<a href="'.$download_url.'" class="sdm_download '.$def_color.'" title="'.$isset_item_title.'" '.$window_target.'>'.$button_text_string.'</a>';
222
 
223
  // Generate download buttons
224
  if ($fancy == '0') {