Version Description
- Added a new filter hook 'sdm_post_type_capability'. This hook can be used to apply a customization and override the default capability from 'administrator' to other roles.
- The '%' symbol is now allowed in the download URL field.
- Added current_user_can() checks to ajax calls.
Download this release
Release Info
Developer | mra13 |
Plugin | Simple Download Monitor |
Version | 3.9.7 |
Comparing to | |
See all releases |
Code changes from version 3.9.5.1 to 3.9.7
- includes/admin-side/sdm-admin-add-ons-page.php +100 -100
- includes/admin-side/sdm-admin-edit-download.php +376 -0
- includes/admin-side/sdm-admin-export-logs.php +88 -104
- includes/admin-side/sdm-admin-individual-item-logs-page.php +75 -68
- includes/sdm-admin-menu-handler.php +791 -730
- includes/sdm-blocks.php +135 -99
- includes/sdm-debug.php +21 -21
- includes/sdm-download-request-handler.php +249 -247
- includes/sdm-latest-downloads.php +73 -68
- includes/sdm-logs-list-table.php +261 -227
- includes/sdm-popular-downloads.php +61 -56
- includes/sdm-search-shortcode-handler.php +115 -114
- includes/sdm-user-login-related.php +36 -36
- includes/sdm-utility-functions-admin-side.php +270 -253
- includes/sdm-utility-functions.php +478 -470
- js/sdm_admin_scripts.js +5 -2
- js/sdm_admin_stats.js +71 -0
- main.php +150 -503
- readme.txt +14 -1
- sdm-download-logs.csv +0 -0
- sdm-post-type-and-taxonomy.php +109 -107
- sdm-post-type-content-handler.php +179 -172
- sdm-shortcodes.php +7 -4
includes/admin-side/sdm-admin-add-ons-page.php
CHANGED
@@ -1,100 +1,100 @@
|
|
1 |
-
<?php
|
2 |
-
$output = '';
|
3 |
-
echo '<link type="text/css" rel="stylesheet" href="' . WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_addons_listing.css" />' . "\n";
|
4 |
-
?>
|
5 |
-
|
6 |
-
<div class="wrap">
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
</div><!-- end of .wrap -->
|
1 |
+
<?php
|
2 |
+
$output = '';
|
3 |
+
echo '<link type="text/css" rel="stylesheet" href="' . WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_addons_listing.css" />' . "\n";
|
4 |
+
?>
|
5 |
+
|
6 |
+
<div class="wrap">
|
7 |
+
<h1>Add-ons</h1>
|
8 |
+
|
9 |
+
<div id="poststuff"><div id="post-body">
|
10 |
+
|
11 |
+
<?php
|
12 |
+
$addons_data = array();
|
13 |
+
|
14 |
+
$addon_1 = array(
|
15 |
+
'name' => 'Squeeze Form Addon',
|
16 |
+
'thumbnail' => WP_SIMPLE_DL_MONITOR_URL . '/images/addons/sdm-squeeze-form-addon-icon.png',
|
17 |
+
'description' => "This addone lets you collect visitor's name and email address in exchange for a downloadable item of your site.",
|
18 |
+
'page_url' => 'https://simple-download-monitor.com/squeeze-form-addon-for-simple-download-monitor/',
|
19 |
+
);
|
20 |
+
array_push( $addons_data, $addon_1 );
|
21 |
+
|
22 |
+
$addon_2 = array(
|
23 |
+
'name' => 'Email on Download',
|
24 |
+
'thumbnail' => WP_SIMPLE_DL_MONITOR_URL . '/images/addons/sdm-email-on-download-addon-icon.png',
|
25 |
+
'description' => 'The Email Notification Addon sends you (the site admin) an email whenever one of your files is downloaded.',
|
26 |
+
'page_url' => 'https://simple-download-monitor.com/email-notification-on-download-addon-for-the-simple-download-monitor/',
|
27 |
+
);
|
28 |
+
array_push( $addons_data, $addon_2 );
|
29 |
+
|
30 |
+
$addon_3 = array(
|
31 |
+
'name' => 'Hidden Downloads',
|
32 |
+
'thumbnail' => WP_SIMPLE_DL_MONITOR_URL . '/images/addons/sdm-hidden-downloads-addon-icon.png',
|
33 |
+
'description' => 'Allows you to create hidden download buttons for your downloadable items so the actual location of the file is never revealed.',
|
34 |
+
'page_url' => 'https://simple-download-monitor.com/hidden-downloads-for-simple-download-monitor/',
|
35 |
+
);
|
36 |
+
array_push( $addons_data, $addon_3 );
|
37 |
+
|
38 |
+
$addon_4 = array(
|
39 |
+
'name' => 'Amazon S3 Integration',
|
40 |
+
'thumbnail' => WP_SIMPLE_DL_MONITOR_URL . '/images/addons/sdm-amazon-s3-addon-icon.png',
|
41 |
+
'description' => "Allows you to securely store and deliver digital downloads using Amazon's Simple Storage Service (S3)",
|
42 |
+
'page_url' => 'https://simple-download-monitor.com/amazon-s3-integration-addon/',
|
43 |
+
);
|
44 |
+
array_push( $addons_data, $addon_4 );
|
45 |
+
|
46 |
+
$addon_5 = array(
|
47 |
+
'name' => 'All File Type Uploads',
|
48 |
+
'thumbnail' => WP_SIMPLE_DL_MONITOR_URL . '/images/addons/sdm-allow-uploads-addon-icon.png',
|
49 |
+
'description' => "WordPress by default doesn't allow you to upload all file types. This addon will remove the limitation and allow you to upload all file types.",
|
50 |
+
'page_url' => 'https://simple-download-monitor.com/allow-more-file-types-to-be-uploaded-via-wordpress/',
|
51 |
+
);
|
52 |
+
array_push( $addons_data, $addon_5 );
|
53 |
+
|
54 |
+
$addon_6 = array(
|
55 |
+
'name' => 'Dropbox Integration',
|
56 |
+
'thumbnail' => WP_SIMPLE_DL_MONITOR_URL . '/images/addons/sdm-dropbox-integration-addon.png',
|
57 |
+
'description' => 'Allows you to configure downloads from your Dropbox account so the visitors can download it from your site.',
|
58 |
+
'page_url' => 'https://simple-download-monitor.com/dropbox-addon-for-the-simple-download-monitor/',
|
59 |
+
);
|
60 |
+
array_push( $addons_data, $addon_6 );
|
61 |
+
|
62 |
+
$addon_7 = array(
|
63 |
+
'name' => 'WP eMember Integration',
|
64 |
+
'thumbnail' => WP_SIMPLE_DL_MONITOR_URL . '/images/addons/sdm-emember-integration.png',
|
65 |
+
'description' => 'Allows you to view which member is downloading which item(s). So you can create more downloads that members will like.',
|
66 |
+
'page_url' => 'https://simple-download-monitor.com/tracking-member-downloads/',
|
67 |
+
);
|
68 |
+
array_push( $addons_data, $addon_7 );
|
69 |
+
|
70 |
+
/*** Show the addons list ***/
|
71 |
+
foreach ( $addons_data as $addon ) {
|
72 |
+
$output .= '<div class="sdm_addon_item_canvas">';
|
73 |
+
|
74 |
+
$output .= '<div class="sdm_addon_item_thumb">';
|
75 |
+
$img_src = $addon['thumbnail'];
|
76 |
+
$output .= '<img src="' . $img_src . '" alt="' . $addon['name'] . '">';
|
77 |
+
$output .= '</div>'; //end thumbnail
|
78 |
+
|
79 |
+
$output .= '<div class="sdm_addon_item_body">';
|
80 |
+
$output .= '<div class="sdm_addon_item_name">';
|
81 |
+
$output .= '<a href="' . $addon['page_url'] . '" target="_blank">' . $addon['name'] . '</a>';
|
82 |
+
$output .= '</div>'; //end name
|
83 |
+
|
84 |
+
$output .= '<div class="sdm_addon_item_description">';
|
85 |
+
$output .= $addon['description'];
|
86 |
+
$output .= '</div>'; //end description
|
87 |
+
|
88 |
+
$output .= '<div class="sdm_addon_item_details_link">';
|
89 |
+
$output .= '<a href="' . $addon['page_url'] . '" class="sdm_addon_view_details" target="_blank">View Details</a>';
|
90 |
+
$output .= '</div>'; //end detils link
|
91 |
+
$output .= '</div>'; //end body
|
92 |
+
|
93 |
+
$output .= '</div>'; //end canvas
|
94 |
+
}
|
95 |
+
|
96 |
+
echo $output;
|
97 |
+
?>
|
98 |
+
|
99 |
+
</div></div><!-- end of poststuff and post-body -->
|
100 |
+
</div><!-- end of .wrap -->
|
includes/admin-side/sdm-admin-edit-download.php
ADDED
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SDM_Admin_Edit_Download {
|
4 |
+
|
5 |
+
public function __construct() {
|
6 |
+
add_action( 'add_meta_boxes_sdm_downloads', array( $this, 'add_meta_boxes_handler' ) ); // Create metaboxes
|
7 |
+
add_action( 'save_post_sdm_downloads', array( $this, 'save_post_handler' ), 10, 3 );
|
8 |
+
|
9 |
+
if ( wp_doing_ajax() ) {
|
10 |
+
add_action( 'wp_ajax_sdm_remove_thumbnail_image', array( $this, 'remove_thumbnail_image_ajax_handler' ) );
|
11 |
+
}
|
12 |
+
}
|
13 |
+
|
14 |
+
public function add_meta_boxes_handler( $post ) {
|
15 |
+
add_meta_box( 'sdm_description_meta_box', __( 'Description', 'simple-download-monitor' ), array( $this, 'display_sdm_description_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
16 |
+
add_meta_box( 'sdm_upload_meta_box', __( 'Downloadable File (Visitors will download this item)', 'simple-download-monitor' ), array( $this, 'display_sdm_upload_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
17 |
+
add_meta_box( 'sdm_dispatch_meta_box', __( 'PHP Dispatch or Redirect', 'simple-download-monitor' ), array( $this, 'display_sdm_dispatch_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
18 |
+
add_meta_box( 'sdm_misc_properties_meta_box', __( 'Miscellaneous Download Item Properties', 'simple-download-monitor' ), array( $this, 'display_sdm_misc_properties_meta_box' ), 'sdm_downloads', 'normal', 'default' ); // Meta box for misc properies/settings
|
19 |
+
add_meta_box( 'sdm_thumbnail_meta_box', __( 'File Thumbnail (Optional)', 'simple-download-monitor' ), array( $this, 'display_sdm_thumbnail_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
20 |
+
add_meta_box( 'sdm_stats_meta_box', __( 'Statistics', 'simple-download-monitor' ), array( $this, 'display_sdm_stats_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
21 |
+
do_action( 'sdm_admin_add_edit_download_before_other_details_meta_box_action' );
|
22 |
+
add_meta_box( 'sdm_other_details_meta_box', __( 'Other Details (Optional)', 'simple-download-monitor' ), array( $this, 'display_sdm_other_details_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
23 |
+
add_meta_box( 'sdm_shortcode_meta_box', __( 'Shortcodes', 'simple-download-monitor' ), array( $this, 'display_sdm_shortcode_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
24 |
+
}
|
25 |
+
|
26 |
+
public function remove_thumbnail_image_ajax_handler() {
|
27 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
28 |
+
//Permission denied
|
29 |
+
wp_die( esc_html( __( 'Permission denied!', 'simple-download-monitor' ) ) );
|
30 |
+
exit;
|
31 |
+
}
|
32 |
+
|
33 |
+
//Go ahead with the thumbnail removal
|
34 |
+
$post_id = filter_input( INPUT_POST, 'post_id_del', FILTER_SANITIZE_NUMBER_INT );
|
35 |
+
$post_id = empty( $post_id ) ? 0 : intval( $post_id );
|
36 |
+
$key_exists = metadata_exists( 'post', $post_id, 'sdm_upload_thumbnail' );
|
37 |
+
if ( $key_exists ) {
|
38 |
+
$success = delete_post_meta( $post_id, 'sdm_upload_thumbnail' );
|
39 |
+
if ( $success ) {
|
40 |
+
$response = array( 'success' => true );
|
41 |
+
}
|
42 |
+
} else {
|
43 |
+
// in order for frontend script to not display "Ajax error", let's return some data
|
44 |
+
$response = array( 'not_exists' => true );
|
45 |
+
}
|
46 |
+
|
47 |
+
wp_send_json( $response );
|
48 |
+
}
|
49 |
+
|
50 |
+
public function display_sdm_description_meta_box( $post ) {
|
51 |
+
wp_nonce_field( 'sdm_admin_edit_download_' . $post->ID, 'sdm_admin_edit_download' );
|
52 |
+
|
53 |
+
// Description metabox
|
54 |
+
esc_html_e( 'Add a description for this download item.', 'simple-download-monitor' );
|
55 |
+
echo '<br /><br />';
|
56 |
+
|
57 |
+
$old_description = get_post_meta( $post->ID, 'sdm_description', true );
|
58 |
+
$sdm_description_field = array( 'textarea_name' => 'sdm_description' );
|
59 |
+
wp_editor( $old_description, 'sdm_description_editor_content', $sdm_description_field );
|
60 |
+
}
|
61 |
+
|
62 |
+
public function display_sdm_upload_meta_box( $post ) {
|
63 |
+
// File Upload metabox
|
64 |
+
$old_upload = get_post_meta( $post->ID, 'sdm_upload', true );
|
65 |
+
$old_value = isset( $old_upload ) ? $old_upload : '';
|
66 |
+
|
67 |
+
//Trigger filter to allow "sdm_upload" field validation override.
|
68 |
+
$url_validation_override = apply_filters( 'sdm_file_download_url_validation_override', '' );
|
69 |
+
if ( ! empty( $url_validation_override ) ) { //phpcs:ignore
|
70 |
+
//This site has customized the behavior and overriden the "sdm_upload" field validation. It can be useful if you are offering app download URLs (that has unconventional URL patterns).
|
71 |
+
} else {
|
72 |
+
//Do the normal URL validation.
|
73 |
+
$old_value = esc_url( $old_value );
|
74 |
+
}
|
75 |
+
|
76 |
+
esc_html_e( 'Manually enter a valid URL of the file in the text box below, or click "Select File" button to upload (or choose) the downloadable file.', 'simple-download-monitor' );
|
77 |
+
echo '<br /><br />';
|
78 |
+
|
79 |
+
echo '<div class="sdm-download-edit-file-url-section">';
|
80 |
+
echo '<input id="sdm_upload" type="text" size="100" name="sdm_upload" value="' . esc_attr( $old_value ) . '" placeholder="http://..." />';
|
81 |
+
echo '</div>';
|
82 |
+
|
83 |
+
echo '<br />';
|
84 |
+
echo '<input id="upload_image_button" type="button" class="button-primary" value="' . esc_attr__( 'Select File', 'simple-download-monitor' ) . '" />';
|
85 |
+
|
86 |
+
echo '<br /><br />';
|
87 |
+
esc_html_e( 'Steps to upload a file or choose one from your media library:', 'simple-download-monitor' );
|
88 |
+
echo '<ol>';
|
89 |
+
echo '<li>' . esc_html__( 'Hit the "Select File" button.', 'simple-download-monitor' ) . '</li>';
|
90 |
+
echo '<li>' . esc_html__( 'Upload a new file or choose an existing one from your media library.', 'simple-download-monitor' ) . '</li>';
|
91 |
+
echo '<li>' . esc_html__( 'Click the "Insert" button, this will populate the uploaded file\'s URL in the above text field.', 'simple-download-monitor' ) . '</li>';
|
92 |
+
echo '</ol>';
|
93 |
+
}
|
94 |
+
|
95 |
+
public function display_sdm_dispatch_meta_box( $post ) {
|
96 |
+
$dispatch = get_post_meta( $post->ID, 'sdm_item_dispatch', true );
|
97 |
+
|
98 |
+
if ( $dispatch === '' ) {
|
99 |
+
// No value yet (either new item or saved with older version of plugin)
|
100 |
+
$screen = get_current_screen();
|
101 |
+
|
102 |
+
if ( $screen->action === 'add' ) {
|
103 |
+
// New item: set default value as per plugin settings.
|
104 |
+
$main_opts = get_option( 'sdm_downloads_options' );
|
105 |
+
$dispatch = isset( $main_opts['general_default_dispatch_value'] ) && $main_opts['general_default_dispatch_value'];
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
echo '<input id="sdm_item_dispatch" type="checkbox" name="sdm_item_dispatch" value="yes"' . checked( true, $dispatch, false ) . ' />';
|
110 |
+
echo '<label for="sdm_item_dispatch">' . esc_html__( 'Dispatch the file via PHP directly instead of redirecting to it. PHP Dispatching keeps the download URL hidden. Dispatching works only for local files (files that you uploaded to this site via this plugin or media library).', 'simple-download-monitor' ) . '</label>';
|
111 |
+
}
|
112 |
+
|
113 |
+
// Open Download in new window
|
114 |
+
public function display_sdm_misc_properties_meta_box( $post ) {
|
115 |
+
|
116 |
+
//Check the open in new window value
|
117 |
+
$new_window = get_post_meta( $post->ID, 'sdm_item_new_window', true );
|
118 |
+
if ( $new_window === '' ) {
|
119 |
+
// No value yet (either new item or saved with older version of plugin)
|
120 |
+
$screen = get_current_screen();
|
121 |
+
if ( $screen->action === 'add' ) { //phpcs:ignore
|
122 |
+
//New item: we can set a default value as per plugin settings. If a general settings is introduced at a later stage.
|
123 |
+
//Does nothing at the moment.
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
//Check the sdm_item_disable_single_download_page value
|
128 |
+
$sdm_item_disable_single_download_page = get_post_meta( $post->ID, 'sdm_item_disable_single_download_page', true );
|
129 |
+
$sdm_item_hide_dl_button_single_download_page = get_post_meta( $post->ID, 'sdm_item_hide_dl_button_single_download_page', true );
|
130 |
+
|
131 |
+
echo '<p> <input id="sdm_item_new_window" type="checkbox" name="sdm_item_new_window" value="yes"' . checked( true, $new_window, false ) . ' />';
|
132 |
+
echo '<label for="sdm_item_new_window">' . esc_html__( 'Open download in a new window.', 'simple-download-monitor' ) . '</label> </p>';
|
133 |
+
|
134 |
+
//the new window will have no download button
|
135 |
+
echo '<p> <input id="sdm_item_hide_dl_button_single_download_page" type="checkbox" name="sdm_item_hide_dl_button_single_download_page" value="yes"' . checked( true, $sdm_item_hide_dl_button_single_download_page, false ) . ' />';
|
136 |
+
echo '<label for="sdm_item_hide_dl_button_single_download_page">';
|
137 |
+
|
138 |
+
$disable_dl_button_label = __( 'Hide the download button on the single download page of this item.', 'simple-download-monitor' );
|
139 |
+
echo esc_html( $disable_dl_button_label ) . '</label>';
|
140 |
+
echo '</p>';
|
141 |
+
|
142 |
+
echo '<p> <input id="sdm_item_disable_single_download_page" type="checkbox" name="sdm_item_disable_single_download_page" value="yes"' . checked( true, $sdm_item_disable_single_download_page, false ) . ' />';
|
143 |
+
echo '<label for="sdm_item_disable_single_download_page">';
|
144 |
+
$disable_single_dl_label = __( 'Disable the single download page for this download item. ', 'simple-download-monitor' );
|
145 |
+
$disable_single_dl_label .= __( 'This can be useful if you are using an addon like the ', 'simple-download-monitor' );
|
146 |
+
$disable_single_dl_label .= '<a href="https://simple-download-monitor.com/squeeze-form-addon-for-simple-download-monitor/" target="_blank">Squeeze Form</a>.';
|
147 |
+
echo $disable_single_dl_label . '</label>'; //phpcs:ignore
|
148 |
+
echo '</p>';
|
149 |
+
|
150 |
+
$sdm_item_anonymous_can_download = get_post_meta( $post->ID, 'sdm_item_anonymous_can_download', true );
|
151 |
+
|
152 |
+
echo '<p> <input id="sdm_item_anonymous_can_download" type="checkbox" name="sdm_item_anonymous_can_download" value="yes"' . checked( true, $sdm_item_anonymous_can_download, false ) . ' />';
|
153 |
+
echo '<label for="sdm_item_anonymous_can_download">' . esc_html__( 'Ignore "Only Allow Logged-in Users to Download" global setting for this item.', 'simple-download-monitor' ) . '</label> </p>';
|
154 |
+
}
|
155 |
+
|
156 |
+
public function display_sdm_thumbnail_meta_box( $post ) {
|
157 |
+
// Thumbnail upload metabox
|
158 |
+
$old_thumbnail = get_post_meta( $post->ID, 'sdm_upload_thumbnail', true );
|
159 |
+
$old_value = isset( $old_thumbnail ) ? $old_thumbnail : '';
|
160 |
+
esc_html_e( 'Manually enter a valid URL, or click "Select Image" to upload (or choose) the file thumbnail image.', 'simple-download-monitor' );
|
161 |
+
?>
|
162 |
+
<br /><br />
|
163 |
+
<input id="sdm_upload_thumbnail" type="text" size="100" name="sdm_upload_thumbnail" value="<?php echo esc_attr( $old_value ); ?>" placeholder="http://..." />
|
164 |
+
<br /><br />
|
165 |
+
<input id="upload_thumbnail_button" type="button" class="button-primary" value="<?php esc_attr_e( 'Select Image', 'simple-download-monitor' ); ?>" />
|
166 |
+
<input id="remove_thumbnail_button" type="button" class="button" value="<?php esc_attr_e( 'Remove Image', 'simple-download-monitor' ); ?>" />
|
167 |
+
<br /><br />
|
168 |
+
|
169 |
+
<span id="sdm_admin_thumb_preview">
|
170 |
+
<?php
|
171 |
+
if ( ! empty( $old_value ) ) {
|
172 |
+
?>
|
173 |
+
<img id="sdm_thumbnail_image" src="<?php echo esc_url( $old_value ); ?>" style="max-width:200px;" />
|
174 |
+
<?php
|
175 |
+
}
|
176 |
+
?>
|
177 |
+
</span>
|
178 |
+
|
179 |
+
<?php
|
180 |
+
echo '<p class="description">';
|
181 |
+
esc_html_e( 'This thumbnail image will be used to create a fancy file download box if you want to use it.', 'simple-download-monitor' );
|
182 |
+
echo '</p>';
|
183 |
+
}
|
184 |
+
|
185 |
+
public function display_sdm_stats_meta_box( $post ) {
|
186 |
+
//Stats metabox
|
187 |
+
$old_count = get_post_meta( $post->ID, 'sdm_count_offset', true );
|
188 |
+
$value = isset( $old_count ) && ! empty( $old_count ) ? $old_count : '0';
|
189 |
+
|
190 |
+
// Get checkbox for "disable download logging"
|
191 |
+
$no_logs = get_post_meta( $post->ID, 'sdm_item_no_log', true );
|
192 |
+
$checked = isset( $no_logs ) && $no_logs === 'on' ? ' checked' : '';
|
193 |
+
|
194 |
+
esc_html_e( 'These are the statistics for this download item.', 'simple-download-monitor' );
|
195 |
+
echo '<br /><br />';
|
196 |
+
|
197 |
+
global $wpdb;
|
198 |
+
$wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post->ID ) ); //phpcs:ignore
|
199 |
+
|
200 |
+
echo '<div class="sdm-download-edit-dl-count">';
|
201 |
+
esc_html_e( 'Number of Downloads:', 'simple-download-monitor' );
|
202 |
+
echo ' <strong>' . esc_html( $wpdb->num_rows ) . '</strong>';
|
203 |
+
echo '</div>';
|
204 |
+
|
205 |
+
echo '<div class="sdm-download-edit-offset-count">';
|
206 |
+
esc_html_e( 'Offset Count: ', 'simple-download-monitor' );
|
207 |
+
echo '<br />';
|
208 |
+
echo ' <input type="text" size="10" name="sdm_count_offset" value="' . esc_attr( $value ) . '" />';
|
209 |
+
echo '<p class="description">' . esc_html__( 'Enter any positive or negative numerical value; to offset the download count shown to the visitors (when using the download counter shortcode).', 'simple-download-monitor' ) . '</p>';
|
210 |
+
echo '</div>';
|
211 |
+
|
212 |
+
echo '<br />';
|
213 |
+
echo '<div class="sdm-download-edit-disable-logging">';
|
214 |
+
echo '<input type="checkbox" name="sdm_item_no_log" ' . esc_attr( $checked ) . ' />';
|
215 |
+
echo '<span style="margin-left: 5px;"></span>';
|
216 |
+
esc_html_e( 'Disable download logging for this item.', 'simple-download-monitor' );
|
217 |
+
echo '</div>';
|
218 |
+
}
|
219 |
+
|
220 |
+
public function display_sdm_other_details_meta_box( $post ) {
|
221 |
+
//Other details metabox
|
222 |
+
$show_date_fd = get_post_meta( $post->ID, 'sdm_item_show_date_fd', true );
|
223 |
+
$sdm_item_show_file_size_fd = get_post_meta( $post->ID, 'sdm_item_show_file_size_fd', true );
|
224 |
+
$sdm_item_show_item_version_fd = get_post_meta( $post->ID, 'sdm_item_show_item_version_fd', true );
|
225 |
+
|
226 |
+
$file_size = get_post_meta( $post->ID, 'sdm_item_file_size', true );
|
227 |
+
$file_size = isset( $file_size ) ? $file_size : '';
|
228 |
+
|
229 |
+
$version = get_post_meta( $post->ID, 'sdm_item_version', true );
|
230 |
+
$version = isset( $version ) ? $version : '';
|
231 |
+
|
232 |
+
$download_button_text = get_post_meta( $post->ID, 'sdm_download_button_text', true );
|
233 |
+
$download_button_text = isset( $download_button_text ) ? $download_button_text : '';
|
234 |
+
|
235 |
+
echo '<div class="sdm-download-edit-filesize">';
|
236 |
+
echo '<strong>' . esc_html__( 'File Size: ', 'simple-download-monitor' ) . '</strong>';
|
237 |
+
echo '<br />';
|
238 |
+
echo ' <input type="text" name="sdm_item_file_size" value="' . esc_attr( $file_size ) . '" size="20" />';
|
239 |
+
echo '<p class="description">' . esc_html__( 'Enter the size of this file (example value: 2.15 MB).', 'simple-download-monitor' ) . '</p>';
|
240 |
+
echo '<div class="sdm-download-edit-show-file-size"> <input id="sdm_item_show_file_size_fd" type="checkbox" name="sdm_item_show_file_size_fd" value="yes"' . checked( true, $sdm_item_show_file_size_fd, false ) . ' />';
|
241 |
+
echo '<label for="sdm_item_show_file_size_fd">' . esc_html__( 'Show file size in fancy display.', 'simple-download-monitor' ) . '</label> </div>';
|
242 |
+
echo '</div>';
|
243 |
+
echo '<hr />';
|
244 |
+
|
245 |
+
echo '<div class="sdm-download-edit-version">';
|
246 |
+
echo '<strong>' . esc_html__( 'Version: ', 'simple-download-monitor' ) . '</strong>';
|
247 |
+
echo '<br />';
|
248 |
+
echo ' <input type="text" name="sdm_item_version" value="' . esc_attr( $version ) . '" size="20" />';
|
249 |
+
echo '<p class="description">' . esc_html__( 'Enter the version number for this item if any (example value: v2.5.10).', 'simple-download-monitor' ) . '</p>';
|
250 |
+
echo '<div class="sdm-download-edit-show-item-version"> <input id="sdm_item_show_item_version_fd" type="checkbox" name="sdm_item_show_item_version_fd" value="yes"' . checked( true, $sdm_item_show_item_version_fd, false ) . ' />';
|
251 |
+
echo '<label for="sdm_item_show_item_version_fd">' . esc_html__( 'Show version number in fancy display.', 'simple-download-monitor' ) . '</label> </div>';
|
252 |
+
echo '</div>';
|
253 |
+
echo '<hr />';
|
254 |
+
|
255 |
+
echo '<div class="sdm-download-edit-show-publish-date">';
|
256 |
+
echo '<strong>' . esc_html__( 'Publish Date: ', 'simple-download-monitor' ) . '</strong>';
|
257 |
+
echo '<br /> <input id="sdm_item_show_date_fd" type="checkbox" name="sdm_item_show_date_fd" value="yes"' . checked( true, $show_date_fd, false ) . ' />';
|
258 |
+
echo '<label for="sdm_item_show_date_fd">' . esc_html__( 'Show download published date in fancy display.', 'simple-download-monitor' ) . '</label>';
|
259 |
+
echo '</div>';
|
260 |
+
echo '<hr />';
|
261 |
+
|
262 |
+
echo '<div class="sdm-download-edit-button-text">';
|
263 |
+
echo '<strong>' . esc_html__( 'Download Button Text: ', 'simple-download-monitor' ) . '</strong>';
|
264 |
+
echo '<br />';
|
265 |
+
echo '<input id="sdm-download-button-text" type="text" name="sdm_download_button_text" value="' . esc_attr( $download_button_text ) . '" />';
|
266 |
+
echo '<p class="description">' . esc_html__( 'You can use this field to customize the download now button text of this item.', 'simple-download-monitor' ) . '</p>';
|
267 |
+
echo '</div>';
|
268 |
+
}
|
269 |
+
|
270 |
+
public function display_sdm_shortcode_meta_box( $post ) {
|
271 |
+
//Shortcode metabox
|
272 |
+
esc_html_e( 'The following shortcode can be used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter (in the post editor) to add this shortcode to a post or page.', 'simple-download-monitor' );
|
273 |
+
echo '<br />';
|
274 |
+
$shortcode_text = '[sdm_download id="' . $post->ID . '" fancy="0"]';
|
275 |
+
echo "<input type='text' class='code' onfocus='this.select();' readonly='readonly' value='" . esc_attr( $shortcode_text ) . "' size='40'>";
|
276 |
+
echo '<br /><br />';
|
277 |
+
|
278 |
+
esc_html_e( 'The following shortcode can be used to show a download counter for this item.', 'simple-download-monitor' );
|
279 |
+
echo '<br />';
|
280 |
+
$shortcode_text = '[sdm_download_counter id="' . $post->ID . '"]';
|
281 |
+
echo "<input type='text' class='code' onfocus='this.select();' readonly='readonly' value='" . esc_attr( $shortcode_text ) . "' size='40'>";
|
282 |
+
|
283 |
+
echo '<br /><br />';
|
284 |
+
echo wp_kses(
|
285 |
+
__( 'Read the full shortcode <a href="https://simple-download-monitor.com/miscellaneous-shortcodes-and-shortcode-parameters/" target="_blank">usage documentation here</a>.', 'simple-download-monitor' ),
|
286 |
+
array(
|
287 |
+
'a' => array(
|
288 |
+
'href' => array(),
|
289 |
+
'target' => array(),
|
290 |
+
),
|
291 |
+
)
|
292 |
+
);
|
293 |
+
}
|
294 |
+
|
295 |
+
public function save_post_handler( $post_id, $post, $update ) {
|
296 |
+
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! $update || empty( $post_id ) ) {
|
297 |
+
return;
|
298 |
+
}
|
299 |
+
|
300 |
+
$action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING );
|
301 |
+
|
302 |
+
if ( empty( $action ) ) {
|
303 |
+
return;
|
304 |
+
}
|
305 |
+
|
306 |
+
check_admin_referer( 'sdm_admin_edit_download_' . $post_id, 'sdm_admin_edit_download' );
|
307 |
+
|
308 |
+
// *** Description ***
|
309 |
+
if ( isset( $_POST['sdm_description'] ) ) {
|
310 |
+
update_post_meta( $post_id, 'sdm_description', wp_kses_post( wp_unslash( $_POST['sdm_description'] ) ) );
|
311 |
+
}
|
312 |
+
|
313 |
+
// *** File Upload ***
|
314 |
+
if ( isset( $_POST['sdm_upload'] ) ) {
|
315 |
+
update_post_meta( $post_id, 'sdm_upload', esc_url( $_POST['sdm_upload'], array( 'http', 'https', 'dropbox' ) ) );
|
316 |
+
}
|
317 |
+
|
318 |
+
// *** PHP Dispatch or Redirect ***
|
319 |
+
$value = filter_input( INPUT_POST, 'sdm_item_dispatch', FILTER_VALIDATE_BOOLEAN );
|
320 |
+
update_post_meta( $post_id, 'sdm_item_dispatch', $value );
|
321 |
+
|
322 |
+
// *** Miscellaneous Download Item Properties ***
|
323 |
+
// Get POST-ed data as boolean value
|
324 |
+
$new_window_open = filter_input( INPUT_POST, 'sdm_item_new_window', FILTER_VALIDATE_BOOLEAN );
|
325 |
+
$sdm_item_hide_dl_button_single_download_page = filter_input( INPUT_POST, 'sdm_item_hide_dl_button_single_download_page', FILTER_VALIDATE_BOOLEAN );
|
326 |
+
$sdm_item_disable_single_download_page = filter_input( INPUT_POST, 'sdm_item_disable_single_download_page', FILTER_VALIDATE_BOOLEAN );
|
327 |
+
$sdm_item_anonymous_can_download = filter_input( INPUT_POST, 'sdm_item_anonymous_can_download', FILTER_VALIDATE_BOOLEAN );
|
328 |
+
|
329 |
+
//Save the data
|
330 |
+
update_post_meta( $post_id, 'sdm_item_new_window', $new_window_open );
|
331 |
+
update_post_meta( $post_id, 'sdm_item_hide_dl_button_single_download_page', $sdm_item_hide_dl_button_single_download_page );
|
332 |
+
update_post_meta( $post_id, 'sdm_item_disable_single_download_page', $sdm_item_disable_single_download_page );
|
333 |
+
update_post_meta( $post_id, 'sdm_item_anonymous_can_download', $sdm_item_anonymous_can_download );
|
334 |
+
|
335 |
+
// *** File Thumbnail ***
|
336 |
+
if ( isset( $_POST['sdm_upload_thumbnail'] ) ) {
|
337 |
+
update_post_meta( $post_id, 'sdm_upload_thumbnail', sanitize_text_field( wp_unslash( $_POST['sdm_upload_thumbnail'] ) ) );
|
338 |
+
}
|
339 |
+
|
340 |
+
// *** Statistics ***
|
341 |
+
if ( isset( $_POST['sdm_count_offset'] ) && is_numeric( $_POST['sdm_count_offset'] ) ) {
|
342 |
+
update_post_meta( $post_id, 'sdm_count_offset', intval( $_POST['sdm_count_offset'] ) );
|
343 |
+
}
|
344 |
+
|
345 |
+
// Checkbox for disabling download logging for this item
|
346 |
+
if ( isset( $_POST['sdm_item_no_log'] ) ) {
|
347 |
+
update_post_meta( $post_id, 'sdm_item_no_log', sanitize_text_field( wp_unslash( $_POST['sdm_item_no_log'] ) ) );
|
348 |
+
} else {
|
349 |
+
delete_post_meta( $post_id, 'sdm_item_no_log' );
|
350 |
+
}
|
351 |
+
|
352 |
+
// *** Other Details ***
|
353 |
+
$show_date_fd = filter_input( INPUT_POST, 'sdm_item_show_date_fd', FILTER_VALIDATE_BOOLEAN );
|
354 |
+
update_post_meta( $post_id, 'sdm_item_show_date_fd', $show_date_fd );
|
355 |
+
|
356 |
+
$sdm_item_show_file_size_fd = filter_input( INPUT_POST, 'sdm_item_show_file_size_fd', FILTER_VALIDATE_BOOLEAN );
|
357 |
+
update_post_meta( $post_id, 'sdm_item_show_file_size_fd', $sdm_item_show_file_size_fd );
|
358 |
+
|
359 |
+
$sdm_item_show_item_version_fd = filter_input( INPUT_POST, 'sdm_item_show_item_version_fd', FILTER_VALIDATE_BOOLEAN );
|
360 |
+
update_post_meta( $post_id, 'sdm_item_show_item_version_fd', $sdm_item_show_item_version_fd );
|
361 |
+
|
362 |
+
if ( isset( $_POST['sdm_item_file_size'] ) ) {
|
363 |
+
update_post_meta( $post_id, 'sdm_item_file_size', sanitize_text_field( wp_unslash( $_POST['sdm_item_file_size'] ) ) );
|
364 |
+
}
|
365 |
+
|
366 |
+
if ( isset( $_POST['sdm_item_version'] ) ) {
|
367 |
+
update_post_meta( $post_id, 'sdm_item_version', sanitize_text_field( wp_unslash( $_POST['sdm_item_version'] ) ) );
|
368 |
+
}
|
369 |
+
|
370 |
+
if ( isset( $_POST['sdm_download_button_text'] ) ) {
|
371 |
+
update_post_meta( $post_id, 'sdm_download_button_text', sanitize_text_field( wp_unslash( $_POST['sdm_download_button_text'] ) ) );
|
372 |
+
}
|
373 |
+
}
|
374 |
+
}
|
375 |
+
|
376 |
+
new SDM_Admin_Edit_Download();
|
includes/admin-side/sdm-admin-export-logs.php
CHANGED
@@ -1,122 +1,106 @@
|
|
1 |
<?php
|
2 |
|
3 |
function sdm_logs_export_tab_page() {
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
if (isset($_POST['sdm_export_log_entries'])) {
|
29 |
-
//validate date fields
|
30 |
-
if (sdm_validate_date_field([$start_date, $end_date])) {
|
31 |
-
//Export log entries
|
32 |
-
$log_file_url = sdm_export_download_logs_to_csv($start_date, $end_date);
|
33 |
-
echo '<div id="message" class="updated"><p>';
|
34 |
-
_e('Log entries exported! Click on the following link to download the file.', 'simple-download-monitor');
|
35 |
-
echo '<br /><br /><a href="' . $log_file_url . '">' . __('Download Logs CSV File', 'simple-download-monitor') . '</a>';
|
36 |
-
echo '</p></div>';
|
37 |
-
}else{
|
38 |
-
echo '<div id="message" class="error"><p>';
|
39 |
-
_e('Please select a valid date range.', 'simple-download-monitor');
|
40 |
-
echo '</p></div>';
|
41 |
-
}
|
42 |
-
}
|
43 |
|
44 |
-
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
onSubmit="return confirm('Are you sure you want to export all the log entries?');">
|
59 |
-
<div>
|
60 |
-
<label for="sdm_stats_start_date_input"><?php _e('Start Date: ', 'simple-download-monitor'); ?></label>
|
61 |
-
<input type="text"
|
62 |
-
id="sdm_stats_start_date_input"
|
63 |
-
class="datepicker d-block w-100"
|
64 |
-
name="sdm_stats_start_date"
|
65 |
-
value="<?php echo $start_date; ?>">
|
66 |
-
<label for="sdm_stats_end_date_input"><?php _e('End Date: ', 'simple-download-monitor'); ?></label>
|
67 |
-
<input type="text"
|
68 |
-
id="sdm_stats_end_date_input"
|
69 |
-
class="datepicker d-block w-100"
|
70 |
-
name="sdm_stats_end_date"
|
71 |
-
value="<?php echo $end_date; ?>">
|
72 |
-
</div>
|
73 |
-
<br>
|
74 |
-
<div id="sdm_logs_date_buttons">
|
75 |
-
<button class="button" type="button"
|
76 |
-
data-start-date="<?php echo date('Y-m-d'); ?>"
|
77 |
-
data-end-date="<?php echo date('Y-m-d'); ?>"><?php _e('Today', 'simple-download-monitor'); ?></button>
|
78 |
-
<button class="button" type="button"
|
79 |
-
data-start-date="<?php echo date('Y-m-01'); ?>"
|
80 |
-
data-end-date="<?php echo date('Y-m-d'); ?>"><?php _e('This Month', 'simple-download-monitor'); ?></button>
|
81 |
-
<button class="button" type="button"
|
82 |
-
data-start-date="<?php echo date('Y-m-d', strtotime('first day of last month')); ?>"
|
83 |
-
data-end-date="<?php echo date('Y-m-d', strtotime('last day of last month')); ?>"><?php _e('Last Month', 'simple-download-monitor'); ?></button>
|
84 |
-
<button class="button" type="button"
|
85 |
-
data-start-date="<?php echo date('Y-01-01'); ?>"
|
86 |
-
data-end-date="<?php echo date('Y-m-d'); ?>"><?php _e('This Year', 'simple-download-monitor'); ?></button>
|
87 |
-
<button class="button" type="button"
|
88 |
-
data-start-date="<?php echo date("Y-01-01", strtotime("-1 year")); ?>"
|
89 |
-
data-end-date="<?php echo date("Y-12-31", strtotime('last year')); ?>"><?php _e('Last Year', 'simple-download-monitor'); ?></button>
|
90 |
-
<button class="button" type="button"
|
91 |
-
data-start-date="<?php echo "1970-01-01"; ?>"
|
92 |
-
data-end-date="<?php echo date('Y-m-d'); ?>"><?php _e('All Time', 'simple-download-monitor'); ?></button>
|
93 |
-
</div>
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
value="<?php _e('Export Log Entries to CSV File', 'simple-download-monitor'); ?>"/>
|
98 |
-
</div>
|
99 |
-
</form>
|
100 |
-
</div>
|
101 |
-
</div>
|
102 |
|
103 |
-
|
104 |
-
</div>
|
105 |
-
|
106 |
-
<?php
|
107 |
}
|
108 |
|
109 |
?>
|
110 |
|
111 |
<script>
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
</script>
|
1 |
<?php
|
2 |
|
3 |
function sdm_logs_export_tab_page() {
|
4 |
+
// jQuery functions
|
5 |
+
wp_enqueue_script( 'jquery-ui-datepicker' );
|
6 |
+
wp_enqueue_style( 'sdm_jquery_ui_style' );
|
7 |
|
8 |
+
// tab heading
|
9 |
+
echo '<h2>';
|
10 |
+
esc_html_e( 'Export Download Log Entries', 'simple-download-monitor' );
|
11 |
+
echo '</h2>';
|
12 |
|
13 |
+
// datetime fileds
|
14 |
+
if ( isset( $_POST['sdm_stats_start_date'] ) ) {
|
15 |
+
$start_date = sanitize_text_field( $_POST['sdm_stats_start_date'] );
|
16 |
+
} else {
|
17 |
+
// default start date is 30 days back
|
18 |
+
$start_date = date( 'Y-m-d', time() - 60 * 60 * 24 * 30 );
|
19 |
+
}
|
20 |
|
21 |
+
if ( isset( $_POST['sdm_stats_end_date'] ) ) {
|
22 |
+
$end_date = sanitize_text_field( $_POST['sdm_stats_end_date'] );
|
23 |
+
} else {
|
24 |
+
$end_date = date( 'Y-m-d', time() );
|
25 |
+
}
|
26 |
|
27 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
<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;">
|
30 |
+
<p><?php esc_html_e( 'This menu allows you to export all the log entries to a CSV file that you can download. The download link will be shown at the top of this page.', 'simple-download-monitor' ); ?></p>
|
31 |
+
</div>
|
32 |
|
33 |
+
<div id="poststuff">
|
34 |
+
<div id="post-body">
|
35 |
+
<div class="postbox">
|
36 |
+
<h3 class="hndle"><label
|
37 |
+
for="title"><?php esc_html_e( 'Choose Date Range (yyyy-mm-dd)', 'simple-download-monitor' ); ?></label>
|
38 |
+
</h3>
|
39 |
+
<div class="inside">
|
40 |
+
<form id="sdm_choose_logs_date" method="post"
|
41 |
+
onSubmit="return confirm('Are you sure you want to export all the log entries?');">
|
42 |
+
<div>
|
43 |
+
<label for="sdm_stats_start_date_input"><?php esc_html_e( 'Start Date: ', 'simple-download-monitor' ); ?></label>
|
44 |
+
<input type="text"
|
45 |
+
id="sdm_stats_start_date_input"
|
46 |
+
class="datepicker d-block w-100"
|
47 |
+
name="sdm_stats_start_date"
|
48 |
+
value="<?php echo esc_attr( $start_date ); ?>">
|
49 |
+
<label for="sdm_stats_end_date_input"><?php esc_html_e( 'End Date: ', 'simple-download-monitor' ); ?></label>
|
50 |
+
<input type="text"
|
51 |
+
id="sdm_stats_end_date_input"
|
52 |
+
class="datepicker d-block w-100"
|
53 |
+
name="sdm_stats_end_date"
|
54 |
+
value="<?php echo esc_attr( $end_date ); ?>">
|
55 |
+
</div>
|
56 |
+
<br>
|
57 |
+
<div id="sdm_logs_date_buttons">
|
58 |
+
<button class="button" type="button"
|
59 |
+
data-start-date="<?php echo esc_attr( date( 'Y-m-d' ) ); ?>"
|
60 |
+
data-end-date="<?php echo esc_attr( date( 'Y-m-d' ) ); ?>"><?php esc_html_e( 'Today', 'simple-download-monitor' ); ?></button>
|
61 |
+
<button class="button" type="button"
|
62 |
+
data-start-date="<?php echo esc_attr( date( 'Y-m-01' ) ); ?>"
|
63 |
+
data-end-date="<?php echo esc_attr( date( 'Y-m-d' ) ); ?>"><?php esc_html_e( 'This Month', 'simple-download-monitor' ); ?></button>
|
64 |
+
<button class="button" type="button"
|
65 |
+
data-start-date="<?php echo esc_attr( date( 'Y-m-d', strtotime( 'first day of last month' ) ) ); ?>"
|
66 |
+
data-end-date="<?php echo esc_attr( date( 'Y-m-d', strtotime( 'last day of last month' ) ) ); ?>"><?php esc_html_e( 'Last Month', 'simple-download-monitor' ); ?></button>
|
67 |
+
<button class="button" type="button"
|
68 |
+
data-start-date="<?php echo esc_attr( date( 'Y-01-01' ) ); ?>"
|
69 |
+
data-end-date="<?php echo esc_attr( date( 'Y-m-d' ) ); ?>"><?php esc_html_e( 'This Year', 'simple-download-monitor' ); ?></button>
|
70 |
+
<button class="button" type="button"
|
71 |
+
data-start-date="<?php echo esc_attr( date( 'Y-01-01', strtotime( '-1 year' ) ) ); ?>"
|
72 |
+
data-end-date="<?php echo esc_attr( date( 'Y-12-31', strtotime( 'last year' ) ) ); ?>"><?php esc_html_e( 'Last Year', 'simple-download-monitor' ); ?></button>
|
73 |
+
<button class="button" type="button"
|
74 |
+
data-start-date="<?php echo '1970-01-01'; ?>"
|
75 |
+
data-end-date="<?php echo esc_attr( date( 'Y-m-d' ) ); ?>"><?php esc_html_e( 'All Time', 'simple-download-monitor' ); ?></button>
|
76 |
+
</div>
|
77 |
|
78 |
+
<div class="submit">
|
79 |
+
<input type="submit" class="button-primary" name="sdm_export_log_entries"
|
80 |
+
value="<?php esc_html_e( 'Export Log Entries to CSV File', 'simple-download-monitor' ); ?>"/>
|
81 |
+
</div>
|
82 |
+
<?php wp_nonce_field( 'sdm_export_logs', 'sdm_export_logs_nonce' ); ?>
|
83 |
+
</form>
|
84 |
+
</div>
|
85 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
+
</div>
|
88 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
+
<?php
|
|
|
|
|
|
|
91 |
}
|
92 |
|
93 |
?>
|
94 |
|
95 |
<script>
|
96 |
+
jQuery(document).ready(function () {
|
97 |
+
jQuery('#sdm_logs_date_buttons button').click(function (e) {
|
98 |
+
jQuery('#sdm_choose_logs_date').find('input[name="sdm_stats_start_date"]').val(jQuery(this).attr('data-start-date'));
|
99 |
+
jQuery('#sdm_choose_logs_date').find('input[name="sdm_stats_end_date"]').val(jQuery(this).attr('data-end-date'));
|
100 |
+
});
|
101 |
|
102 |
+
jQuery('.datepicker').datepicker({
|
103 |
+
dateFormat: 'yy-mm-dd'
|
104 |
+
});
|
105 |
+
});
|
106 |
+
</script>
|
includes/admin-side/sdm-admin-individual-item-logs-page.php
CHANGED
@@ -1,68 +1,75 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function sdm_handle_individual_logs_tab_page(){
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function sdm_handle_individual_logs_tab_page() {
|
4 |
+
echo '<h2>';
|
5 |
+
esc_html_e( 'Specific Download Item Logs', 'simple-download-monitor' );
|
6 |
+
echo '</h2>';
|
7 |
+
|
8 |
+
$sdm_logs_dl_id = isset( $_REQUEST['sdm_logs_dl_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['sdm_logs_dl_id'] ) ) : '';
|
9 |
+
$sdm_logs_dl_id = intval( $sdm_logs_dl_id );
|
10 |
+
|
11 |
+
if ( isset( $_REQUEST['sdm_show_specific_item_logs'] ) ) {
|
12 |
+
$sdm_specific_download_id = isset( $_REQUEST['sdm_specific_download_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['sdm_specific_download_id'] ) ) : '';
|
13 |
+
$sdm_specific_download_id = intval( $sdm_specific_download_id );
|
14 |
+
|
15 |
+
if ( ! empty( $sdm_specific_download_id ) ) {
|
16 |
+
check_admin_referer( 'sdm_view_specific_download_id_log' );
|
17 |
+
$target_url = 'edit.php?post_type=sdm_downloads&page=sdm-logs&action=sdm-logs-by-download&sdm_logs_dl_id=' . $sdm_specific_download_id;
|
18 |
+
$target_url = wp_nonce_url( $target_url, 'sdm_view_log_' . $sdm_specific_download_id );
|
19 |
+
sdm_redirect_to_url( $target_url );
|
20 |
+
exit;
|
21 |
+
}
|
22 |
+
}
|
23 |
+
|
24 |
+
?>
|
25 |
+
|
26 |
+
<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;">
|
27 |
+
<p><?php esc_html_e( 'This menu allows you to view the download logs of individual items.', 'simple-download-monitor' ); ?></p>
|
28 |
+
</div>
|
29 |
+
|
30 |
+
<div id="poststuff"><div id="post-body">
|
31 |
+
|
32 |
+
<div class="postbox">
|
33 |
+
<h3 class="hndle"><label for="title"><?php esc_html_e( 'View Specific Item Logs', 'simple-download-monitor' ); ?></label></h3>
|
34 |
+
<div class="inside">
|
35 |
+
<form method="post" action="" >
|
36 |
+
<?php wp_nonce_field( 'sdm_view_specific_download_id_log' ); ?>
|
37 |
+
<?php esc_html_e( 'Enter the Download ID of the item: ', 'simple-download-monitor' ); ?>
|
38 |
+
<input type="text" name="sdm_specific_download_id" value="<?php echo esc_attr( $sdm_logs_dl_id ); ?>" size="10" />
|
39 |
+
<p class='description'>
|
40 |
+
<?php esc_html_e( 'You can find the Download ID of an item from the Downloads menu of the plugin.', 'simple-download-monitor' ); ?>
|
41 |
+
</p>
|
42 |
+
<div class="submit">
|
43 |
+
<input type="submit" class="button" name="sdm_show_specific_item_logs" value="<?php esc_html_e( 'View Logs', 'simple-download-monitor' ); ?>" />
|
44 |
+
</div>
|
45 |
+
</form>
|
46 |
+
</div>
|
47 |
+
</div>
|
48 |
+
|
49 |
+
</div></div><!-- end of .poststuff and .post-body -->
|
50 |
+
|
51 |
+
<?php
|
52 |
+
if ( isset( $sdm_logs_dl_id ) && ! empty( $sdm_logs_dl_id ) ) {
|
53 |
+
//Show the specific item logs
|
54 |
+
|
55 |
+
check_admin_referer( 'sdm_view_log_' . $sdm_logs_dl_id );
|
56 |
+
|
57 |
+
$page = isset( $_REQUEST['page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) : '';
|
58 |
+
|
59 |
+
/* Prepare everything for the specific logs table */
|
60 |
+
//Create an instance of our package class...
|
61 |
+
$sdm_list_table = new sdm_List_Table();
|
62 |
+
//Fetch, prepare, sort, and filter our data...
|
63 |
+
$sdm_list_table->prepare_items();
|
64 |
+
echo '<strong>' . esc_html__( 'The following table shows the download logs of the item with Download ID: ', 'simple-download-monitor' ) . esc_html( $sdm_logs_dl_id ) . '</strong>'
|
65 |
+
?>
|
66 |
+
<!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
|
67 |
+
<form id="sdm_downloads-filter" method="post">
|
68 |
+
<input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
|
69 |
+
<!-- Now we can render the completed list table -->
|
70 |
+
<?php $sdm_list_table->display(); ?>
|
71 |
+
</form>
|
72 |
+
<?php
|
73 |
+
}
|
74 |
+
|
75 |
+
}
|
includes/sdm-admin-menu-handler.php
CHANGED
@@ -1,730 +1,791 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
* Creates/adds the other admin menu page links to the main SDM custom post type menu
|
4 |
-
*/
|
5 |
-
|
6 |
-
function sdm_handle_admin_menu() {
|
7 |
-
|
8 |
-
//***** Create the 'logs' and 'settings' submenu pages
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
}
|
14 |
-
|
15 |
-
add_filter( 'allowed_options', 'sdm_admin_menu_function_hook' );
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
*
|
34 |
-
|
35 |
-
|
36 |
-
function
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
}
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
//
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
$
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Creates/adds the other admin menu page links to the main SDM custom post type menu
|
4 |
+
*/
|
5 |
+
|
6 |
+
function sdm_handle_admin_menu() {
|
7 |
+
|
8 |
+
//***** Create the 'logs' and 'settings' submenu pages
|
9 |
+
$sdm_logs_page = add_submenu_page( 'edit.php?post_type=sdm_downloads', __( 'Logs', 'simple-download-monitor' ), __( 'Logs', 'simple-download-monitor' ), 'manage_options', 'sdm-logs', 'sdm_create_logs_page' );
|
10 |
+
$sdm_logs_page = add_submenu_page( 'edit.php?post_type=sdm_downloads', __( 'Stats', 'simple-download-monitor' ), __( 'Stats', 'simple-download-monitor' ), 'manage_options', 'sdm-stats', 'sdm_create_stats_page' );
|
11 |
+
$sdm_settings_page = add_submenu_page( 'edit.php?post_type=sdm_downloads', __( 'Settings', 'simple-download-monitor' ), __( 'Settings', 'simple-download-monitor' ), 'manage_options', 'sdm-settings', 'sdm_create_settings_page' );
|
12 |
+
$sdm_addons_page = add_submenu_page( 'edit.php?post_type=sdm_downloads', __( 'Add-ons', 'simple-download-monitor' ), __( 'Add-ons', 'simple-download-monitor' ), 'manage_options', 'sdm-addons', 'sdm_create_addons_page' );
|
13 |
+
}
|
14 |
+
|
15 |
+
add_filter( 'allowed_options', 'sdm_admin_menu_function_hook' );
|
16 |
+
|
17 |
+
add_action( 'admin_enqueue_scripts', 'sdm_admin_menu_enqueue_scripts' );
|
18 |
+
|
19 |
+
function sdm_admin_menu_enqueue_scripts( $hook_suffix ) {
|
20 |
+
switch ( $hook_suffix ) {
|
21 |
+
case 'sdm_downloads_page_sdm-stats':
|
22 |
+
wp_register_script( 'sdm-admin-stats', WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_admin_stats.js', array( 'jquery' ), WP_SIMPLE_DL_MONITOR_VERSION, true );
|
23 |
+
wp_enqueue_script( 'sdm-admin-stats' );
|
24 |
+
break;
|
25 |
+
default:
|
26 |
+
break;
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Its hook for add advanced tab, and working on saving options to db, if not used, you receive error "options page not found"
|
32 |
+
*
|
33 |
+
* @param array $allowed_options
|
34 |
+
* @return string
|
35 |
+
*/
|
36 |
+
function sdm_admin_menu_function_hook( $allowed_options = array() ) {
|
37 |
+
$allowed_options['recaptcha_options_section'] = array( 'sdm_advanced_options' );
|
38 |
+
$allowed_options['termscond_options_section'] = array( 'sdm_advanced_options' );
|
39 |
+
$allowed_options['adsense_options_section'] = array( 'sdm_advanced_options' );
|
40 |
+
$allowed_options['maps_api_options_section'] = array( 'sdm_advanced_options' );
|
41 |
+
|
42 |
+
return $allowed_options;
|
43 |
+
}
|
44 |
+
|
45 |
+
/*
|
46 |
+
* Settings menu page
|
47 |
+
*/
|
48 |
+
|
49 |
+
function sdm_create_settings_page() {
|
50 |
+
|
51 |
+
echo '<div class="wrap">';
|
52 |
+
//echo '<div id="poststuff"><div id="post-body">';
|
53 |
+
?>
|
54 |
+
<style>
|
55 |
+
div.sdm-settings-grid {
|
56 |
+
display: inline-block;
|
57 |
+
}
|
58 |
+
div.sdm-main-cont {
|
59 |
+
width: 80%;
|
60 |
+
}
|
61 |
+
div.sdm-sidebar-cont {
|
62 |
+
width: 19%;
|
63 |
+
float: right;
|
64 |
+
}
|
65 |
+
div#poststuff {
|
66 |
+
min-width: 19%;
|
67 |
+
}
|
68 |
+
.sdm-stars-container {
|
69 |
+
text-align: center;
|
70 |
+
margin-top: 10px;
|
71 |
+
}
|
72 |
+
.sdm-stars-container span {
|
73 |
+
vertical-align: text-top;
|
74 |
+
color: #ffb900;
|
75 |
+
}
|
76 |
+
.sdm-stars-container a {
|
77 |
+
text-decoration: none;
|
78 |
+
}
|
79 |
+
@media (max-width: 782px) {
|
80 |
+
div.sdm-settings-grid {
|
81 |
+
display: block;
|
82 |
+
float: none;
|
83 |
+
width: 100%;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
</style>
|
87 |
+
<h1><?php esc_html_e( 'Simple Download Monitor Settings Page', 'simple-download-monitor' ); ?></h1>
|
88 |
+
|
89 |
+
<?php
|
90 |
+
ob_start();
|
91 |
+
$wpsdm_plugin_tabs = array(
|
92 |
+
'sdm-settings' => __( 'General Settings', 'simple-download-monitor' ),
|
93 |
+
'sdm-settings&action=advanced-settings' => __( 'Advanced Settings', 'simple-download-monitor' ),
|
94 |
+
);
|
95 |
+
$current = '';
|
96 |
+
if ( isset( $_GET['page'] ) ) {
|
97 |
+
$current = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
98 |
+
if ( isset( $_GET['action'] ) ) {
|
99 |
+
$action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING );
|
100 |
+
$current .= '&action=' . $action;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
$nav_tabs = '';
|
104 |
+
$nav_tabs .= '<h2 class="nav-tab-wrapper">';
|
105 |
+
foreach ( $wpsdm_plugin_tabs as $location => $tabname ) {
|
106 |
+
if ( $current === $location ) {
|
107 |
+
$class = ' nav-tab-active';
|
108 |
+
} else {
|
109 |
+
$class = '';
|
110 |
+
}
|
111 |
+
$nav_tabs .= '<a class="nav-tab' . $class . '" href="?post_type=sdm_downloads&page=' . $location . '">' . $tabname . '</a>';
|
112 |
+
}
|
113 |
+
$nav_tabs .= '</h2>';
|
114 |
+
|
115 |
+
if ( isset( $_GET['action'] ) ) {
|
116 |
+
$action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING );
|
117 |
+
switch ( $action ) {
|
118 |
+
case 'advanced-settings':
|
119 |
+
sdm_admin_menu_advanced_settings();
|
120 |
+
break;
|
121 |
+
}
|
122 |
+
} else {
|
123 |
+
sdm_admin_menu_general_settings();
|
124 |
+
}
|
125 |
+
$settings_cont = ob_get_clean();
|
126 |
+
echo $nav_tabs; //phpcs:ignore
|
127 |
+
?>
|
128 |
+
<div class="sdm-settings-cont">
|
129 |
+
<div class="sdm-settings-grid sdm-main-cont">
|
130 |
+
<!-- settings page form -->
|
131 |
+
<form method="post" action="options.php">
|
132 |
+
<?php echo $settings_cont; //phpcs:ignore?>
|
133 |
+
<!-- End of settings page form -->
|
134 |
+
</form>
|
135 |
+
</div>
|
136 |
+
<div id="poststuff" class="sdm-settings-grid sdm-sidebar-cont">
|
137 |
+
<div class="postbox" style="min-width: inherit;">
|
138 |
+
<h3 class="hndle"><label for="title"><?php esc_html_e( 'Plugin Documentation', 'simple-download-monitor' ); ?></label></h3>
|
139 |
+
<div class="inside">
|
140 |
+
<?php
|
141 |
+
echo wp_kses(
|
142 |
+
// translators: %s = URL to documentation page
|
143 |
+
sprintf( __( 'Please read the <a target="_blank" href="%s">Simple Download Monitor</a> plugin setup instructions and tutorials to learn how to configure and use it.', 'simple-download-monitor' ), 'https://simple-download-monitor.com/download-monitor-tutorials/' ),
|
144 |
+
array(
|
145 |
+
'a' => array(
|
146 |
+
'target' => array(),
|
147 |
+
'href' => array(),
|
148 |
+
),
|
149 |
+
)
|
150 |
+
);
|
151 |
+
?>
|
152 |
+
</div>
|
153 |
+
</div>
|
154 |
+
<div class="postbox" style="min-width: inherit;">
|
155 |
+
<h3 class="hndle"><label for="title"><?php esc_html_e( 'Add-ons', 'simple-download-monitor' ); ?></label></h3>
|
156 |
+
<div class="inside">
|
157 |
+
<?php
|
158 |
+
echo wp_kses(
|
159 |
+
// translators: %s = URL to add-ons page
|
160 |
+
sprintf( __( 'Want additional functionality? Check out our <a target="_blank" href="%s">Add-Ons!</a>', 'simple-download-monitor' ), 'edit.php?post_type=sdm_downloads&page=sdm-addons' ),
|
161 |
+
array(
|
162 |
+
'a' => array(
|
163 |
+
'target' => array(),
|
164 |
+
'href' => array(),
|
165 |
+
),
|
166 |
+
)
|
167 |
+
);
|
168 |
+
?>
|
169 |
+
</div>
|
170 |
+
</div>
|
171 |
+
<div class="postbox" style="min-width: inherit;">
|
172 |
+
<h3 class="hndle"><label for="title"><?php esc_html_e( 'Rate Us', 'simple-download-monitor' ); ?></label></h3>
|
173 |
+
<div class="inside">
|
174 |
+
<?php
|
175 |
+
echo wp_kses(
|
176 |
+
// translators: %s = URL to rating page
|
177 |
+
sprintf( __( 'Like the plugin? Please give us a <a href="%s" target="_blank">rating!</a>', 'simple-download-monitor' ), 'https://wordpress.org/support/plugin/simple-download-monitor/reviews/?filter=5' ),
|
178 |
+
array(
|
179 |
+
'a' => array(
|
180 |
+
'target' => array(),
|
181 |
+
'href' => array(),
|
182 |
+
),
|
183 |
+
)
|
184 |
+
);
|
185 |
+
?>
|
186 |
+
<div class="sdm-stars-container">
|
187 |
+
<a href="https://wordpress.org/support/plugin/simple-download-monitor/reviews/?filter=5" target="_blank">
|
188 |
+
<span class="dashicons dashicons-star-filled"></span>
|
189 |
+
<span class="dashicons dashicons-star-filled"></span>
|
190 |
+
<span class="dashicons dashicons-star-filled"></span>
|
191 |
+
<span class="dashicons dashicons-star-filled"></span>
|
192 |
+
<span class="dashicons dashicons-star-filled"></span>
|
193 |
+
</a>
|
194 |
+
</div>
|
195 |
+
</div>
|
196 |
+
</div>
|
197 |
+
<div class="postbox" style="min-width: inherit;">
|
198 |
+
<h3 class="hndle"><label for="title"><?php esc_html_e( 'Our Other Plugins', 'simple-download-monitor' ); ?></label></h3>
|
199 |
+
<div class="inside">
|
200 |
+
<?php
|
201 |
+
echo wp_kses(
|
202 |
+
// translators: %s = URL to other plugins page
|
203 |
+
sprintf( __( 'Check out <a target="_blank" href="%s">our other plugins</a>', 'simple-download-monitor' ), 'https://www.tipsandtricks-hq.com/development-center' ),
|
204 |
+
array(
|
205 |
+
'a' => array(
|
206 |
+
'target' => array(),
|
207 |
+
'href' => array(),
|
208 |
+
),
|
209 |
+
)
|
210 |
+
);
|
211 |
+
?>
|
212 |
+
</div>
|
213 |
+
</div>
|
214 |
+
<div class="postbox" style="min-width: inherit;">
|
215 |
+
<h3 class="hndle"><label for="title"><?php esc_html_e( 'Social', 'simple-download-monitor' ); ?></label></h3>
|
216 |
+
<div class="inside">
|
217 |
+
<?php
|
218 |
+
echo wp_kses(
|
219 |
+
// translators: %s = Twitter URL
|
220 |
+
sprintf( __( '<a target="_blank" href="%s">Facebook</a>', 'simple-download-monitor' ), 'https://www.facebook.com/Tips-and-Tricks-HQ-681802408532789/' ),
|
221 |
+
array(
|
222 |
+
'a' => array(
|
223 |
+
'target' => array(),
|
224 |
+
'href' => array(),
|
225 |
+
),
|
226 |
+
)
|
227 |
+
);
|
228 |
+
?>
|
229 |
+
|
|
230 |
+
<?php
|
231 |
+
echo wp_kses(
|
232 |
+
// translators: %s = Twitter URL
|
233 |
+
sprintf( __( '<a target="_blank" href="%s">Twitter</a>', 'simple-download-monitor' ), 'https://twitter.com/TipsAndTricksHQ' ),
|
234 |
+
array(
|
235 |
+
'a' => array(
|
236 |
+
'target' => array(),
|
237 |
+
'href' => array(),
|
238 |
+
),
|
239 |
+
)
|
240 |
+
);
|
241 |
+
?>
|
242 |
+
</div>
|
243 |
+
</div>
|
244 |
+
</div>
|
245 |
+
</div>
|
246 |
+
|
247 |
+
<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;">
|
248 |
+
<p>
|
249 |
+
<?php esc_html_e( 'If you need an easy to use and supported plugin for selling your digital items then check out our ', 'simple-download-monitor' ); ?>
|
250 |
+
<a href="https://wordpress.org/plugins/wp-express-checkout/" target="_blank"><?php esc_html_e( 'WP Express Checkout', 'simple-download-monitor' ); ?></a>
|
251 |
+
or <a href="https://wordpress.org/plugins/stripe-payments/" target="_blank"><?php esc_html_e( 'Stripe Payments', 'simple-download-monitor' ); ?></a>
|
252 |
+
or <a href="https://www.tipsandtricks-hq.com/wordpress-estore-plugin-complete-solution-to-sell-digital-products-from-your-wordpress-blog-securely-1059" target="_blank"><?php esc_html_e( 'WP eStore', 'simple-download-monitor' ); ?></a> Plugin.
|
253 |
+
</p>
|
254 |
+
</div>
|
255 |
+
|
256 |
+
<?php
|
257 |
+
echo '</div>'; //end of wrap
|
258 |
+
}
|
259 |
+
|
260 |
+
function sdm_admin_menu_general_settings() {
|
261 |
+
?>
|
262 |
+
<!-- BEGIN GENERAL OPTIONS DIV -->
|
263 |
+
<?php
|
264 |
+
// This prints out all hidden setting fields
|
265 |
+
do_settings_sections( 'general_options_section' );
|
266 |
+
settings_fields( 'sdm_downloads_options' );
|
267 |
+
|
268 |
+
submit_button();
|
269 |
+
?>
|
270 |
+
<!-- END GENERAL OPTIONS DIV -->
|
271 |
+
|
272 |
+
<!-- BEGIN USER LOGIN OPTIONS DIV -->
|
273 |
+
<?php
|
274 |
+
// This prints out all hidden setting fields
|
275 |
+
do_settings_sections( 'user_login_options_section' );
|
276 |
+
settings_fields( 'sdm_downloads_options' );
|
277 |
+
|
278 |
+
submit_button();
|
279 |
+
?>
|
280 |
+
<!-- END USER LOGIN OPTIONS DIV -->
|
281 |
+
|
282 |
+
<!-- BEGIN ADMIN OPTIONS DIV -->
|
283 |
+
<?php
|
284 |
+
// This prints out all hidden setting fields
|
285 |
+
do_settings_sections( 'admin_options_section' );
|
286 |
+
settings_fields( 'sdm_downloads_options' );
|
287 |
+
|
288 |
+
submit_button();
|
289 |
+
?>
|
290 |
+
<!-- END ADMIN OPTIONS DIV -->
|
291 |
+
|
292 |
+
<!-- BEGIN COLORS DIV -->
|
293 |
+
<?php
|
294 |
+
// This prints out all hidden setting fields
|
295 |
+
do_settings_sections( 'sdm_colors_section' );
|
296 |
+
settings_fields( 'sdm_downloads_options' );
|
297 |
+
|
298 |
+
submit_button();
|
299 |
+
?>
|
300 |
+
<!-- END COLORS OPTIONS DIV -->
|
301 |
+
|
302 |
+
<!-- BEGIN DEBUG OPTIONS DIV -->
|
303 |
+
<?php
|
304 |
+
// This prints out all hidden setting fields
|
305 |
+
do_settings_sections( 'sdm_debug_section' );
|
306 |
+
settings_fields( 'sdm_downloads_options' );
|
307 |
+
|
308 |
+
submit_button();
|
309 |
+
?>
|
310 |
+
<!-- END DEBUG OPTIONS DIV -->
|
311 |
+
<!-- BEGIN DELDATA OPTIONS DIV -->
|
312 |
+
<?php
|
313 |
+
// This prints out all hidden setting fields
|
314 |
+
do_settings_sections( 'sdm_deldata_section' );
|
315 |
+
settings_fields( 'sdm_downloads_options' );
|
316 |
+
|
317 |
+
$deldataNonce = wp_create_nonce( 'sdm_delete_data' );
|
318 |
+
?>
|
319 |
+
<!-- END DELDATA OPTIONS DIV -->
|
320 |
+
|
321 |
+
<script>
|
322 |
+
jQuery('button#sdmDeleteData').click(function (e) {
|
323 |
+
e.preventDefault();
|
324 |
+
jQuery(this).attr('disabled', 'disabled');
|
325 |
+
if (confirm("<?php echo esc_js( __( "Are you sure want to delete all plugin's data and deactivate plugin?", 'simple-download-monitor' ) ); ?>")) {
|
326 |
+
jQuery.post(ajaxurl,
|
327 |
+
{'action': 'sdm_delete_data', 'nonce': '<?php echo esc_js( $deldataNonce ); ?>'},
|
328 |
+
function (result) {
|
329 |
+
if (result === '1') {
|
330 |
+
alert('<?php echo esc_js( __( 'Data has been deleted and plugin deactivated. Click OK to go to Plugins page.', 'simple-download-monitor' ) ); ?>');
|
331 |
+
jQuery(location).attr('href', '<?php echo esc_js( get_admin_url() . 'plugins.php' ); ?>');
|
332 |
+
return true;
|
333 |
+
} else {
|
334 |
+
alert('<?php echo esc_js( __( 'Error occurred.', 'simple-download-monitor' ) ); ?>');
|
335 |
+
}
|
336 |
+
});
|
337 |
+
} else {
|
338 |
+
jQuery(this).removeAttr('disabled');
|
339 |
+
}
|
340 |
+
});
|
341 |
+
jQuery('a#sdm-reset-log').click(function (e) {
|
342 |
+
e.preventDefault();
|
343 |
+
jQuery.post(ajaxurl,
|
344 |
+
{'action': 'sdm_reset_log', 'nonce': '<?php echo esc_js( $deldataNonce ); ?>'},
|
345 |
+
function (result) {
|
346 |
+
if (result === '1') {
|
347 |
+
alert('Log has been reset.');
|
348 |
+
}
|
349 |
+
});
|
350 |
+
});
|
351 |
+
</script>
|
352 |
+
<?php
|
353 |
+
}
|
354 |
+
|
355 |
+
function sdm_admin_menu_advanced_settings() {
|
356 |
+
//More advanced options will be added here in the future.
|
357 |
+
// This prints out all hidden setting fields
|
358 |
+
do_settings_sections( 'recaptcha_options_section' );
|
359 |
+
settings_fields( 'recaptcha_options_section' );
|
360 |
+
submit_button();
|
361 |
+
|
362 |
+
do_settings_sections( 'termscond_options_section' );
|
363 |
+
settings_fields( 'termscond_options_section' );
|
364 |
+
submit_button();
|
365 |
+
|
366 |
+
do_settings_sections( 'adsense_options_section' );
|
367 |
+
settings_fields( 'adsense_options_section' );
|
368 |
+
submit_button();
|
369 |
+
|
370 |
+
do_settings_sections( 'maps_api_options_section' );
|
371 |
+
settings_fields( 'maps_api_options_section' );
|
372 |
+
submit_button();
|
373 |
+
}
|
374 |
+
|
375 |
+
/*
|
376 |
+
* * Logs menu page
|
377 |
+
*/
|
378 |
+
|
379 |
+
function sdm_create_logs_page() {
|
380 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
381 |
+
wp_die( 'You do not have permission to access this settings page.' );
|
382 |
+
}
|
383 |
+
|
384 |
+
echo '<div class="wrap">';
|
385 |
+
|
386 |
+
$sdm_logs_menu_tabs = array(
|
387 |
+
'sdm-logs' => __( 'Main Logs', 'simple-download-monitor' ),
|
388 |
+
'sdm-logs&action=sdm-logs-by-download' => __( 'Specific Item Logs', 'simple-download-monitor' ),
|
389 |
+
'sdm-logs&action=sdm-logs-export' => __( 'Export', 'simple-download-monitor' ),
|
390 |
+
);
|
391 |
+
|
392 |
+
$current = '';
|
393 |
+
if ( isset( $_GET['page'] ) ) {
|
394 |
+
$current = sanitize_text_field( $_GET['page'] );
|
395 |
+
if ( isset( $_GET['action'] ) ) {
|
396 |
+
$current .= '&action=' . sanitize_text_field( $_GET['action'] );
|
397 |
+
}
|
398 |
+
}
|
399 |
+
$content = '';
|
400 |
+
foreach ( $sdm_logs_menu_tabs as $location => $tabname ) {
|
401 |
+
if ( $current === $location ) {
|
402 |
+
$class = ' nav-tab-active';
|
403 |
+
} else {
|
404 |
+
$class = '';
|
405 |
+
}
|
406 |
+
$content .= '<a class="nav-tab' . $class . '" href="?post_type=sdm_downloads&page=' . $location . '">' . $tabname . '</a>';
|
407 |
+
}
|
408 |
+
echo '<h2 class="nav-tab-wrapper">';
|
409 |
+
echo wp_kses(
|
410 |
+
$content,
|
411 |
+
array(
|
412 |
+
'a' => array(
|
413 |
+
'href' => array(),
|
414 |
+
'class' => array(),
|
415 |
+
),
|
416 |
+
)
|
417 |
+
);
|
418 |
+
echo '</h2>';
|
419 |
+
|
420 |
+
if ( isset( $_GET['action'] ) ) {
|
421 |
+
switch ( $_GET['action'] ) {
|
422 |
+
case 'sdm-logs-by-download':
|
423 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/admin-side/sdm-admin-individual-item-logs-page.php';
|
424 |
+
sdm_handle_individual_logs_tab_page();
|
425 |
+
break;
|
426 |
+
case 'sdm-logs-export':
|
427 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/admin-side/sdm-admin-export-logs.php';
|
428 |
+
sdm_logs_export_tab_page();
|
429 |
+
break;
|
430 |
+
default:
|
431 |
+
sdm_handle_logs_main_tab_page();
|
432 |
+
break;
|
433 |
+
}
|
434 |
+
} else {
|
435 |
+
sdm_handle_logs_main_tab_page();
|
436 |
+
}
|
437 |
+
|
438 |
+
echo '</div>'; //<!-- end of wrap -->
|
439 |
+
}
|
440 |
+
|
441 |
+
function sdm_handle_logs_main_tab_page() {
|
442 |
+
global $wpdb;
|
443 |
+
$advanced_options = get_option( 'sdm_advanced_options' );
|
444 |
+
|
445 |
+
if ( isset( $_POST['sdm_reset_log_entries'] ) ) {
|
446 |
+
//Reset log entries
|
447 |
+
$table_name = $wpdb->prefix . 'sdm_downloads';
|
448 |
+
$query = "TRUNCATE $table_name";
|
449 |
+
$result = $wpdb->query( $query );
|
450 |
+
echo '<div id="message" class="updated fade"><p>';
|
451 |
+
esc_html_e( 'Download log entries deleted!', 'simple-download-monitor' );
|
452 |
+
echo '</p></div>';
|
453 |
+
}
|
454 |
+
|
455 |
+
if ( isset( $_POST['sdm_trim_log_entries'] ) ) {
|
456 |
+
//Trim log entries
|
457 |
+
$interval_val = intval( $_POST['sdm_trim_log_entries_days'] );
|
458 |
+
$interval_unit = 'DAY';
|
459 |
+
$cur_time = current_time( 'mysql' );
|
460 |
+
|
461 |
+
//Save the interval value for future use on this site.
|
462 |
+
$advanced_options ['sdm_trim_log_entries_days_saved'] = $interval_val;
|
463 |
+
update_option( 'sdm_advanced_options', $advanced_options );
|
464 |
+
|
465 |
+
//Trim entries in the DB table.
|
466 |
+
$table_name = $wpdb->prefix . 'sdm_downloads';
|
467 |
+
$cond = " DATE_SUB('$cur_time',INTERVAL '$interval_val' $interval_unit) > date_time";
|
468 |
+
$result = $wpdb->query( "DELETE FROM $table_name WHERE $cond", OBJECT );
|
469 |
+
|
470 |
+
echo '<div id="message" class="updated fade"><p>';
|
471 |
+
esc_html_e( 'Download log entries trimmed!', 'simple-download-monitor' );
|
472 |
+
echo '</p></div>';
|
473 |
+
}
|
474 |
+
|
475 |
+
//Set the default log trim days value
|
476 |
+
$trim_log_entries_days_default_val = isset( $advanced_options ['sdm_trim_log_entries_days_saved'] ) ? $advanced_options ['sdm_trim_log_entries_days_saved'] : '30';
|
477 |
+
|
478 |
+
/* Display the logs table */
|
479 |
+
//Create an instance of our package class...
|
480 |
+
$sdmListTable = new sdm_List_Table();
|
481 |
+
//Fetch, prepare, sort, and filter our data...
|
482 |
+
$sdmListTable->prepare_items();
|
483 |
+
?>
|
484 |
+
|
485 |
+
<h2><?php esc_html_e( 'Download Logs', 'simple-download-monitor' ); ?></h2>
|
486 |
+
|
487 |
+
<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;">
|
488 |
+
<p><?php esc_html_e( 'This page lists all tracked downloads.', 'simple-download-monitor' ); ?></p>
|
489 |
+
</div>
|
490 |
+
|
491 |
+
<div id="poststuff"><div id="post-body">
|
492 |
+
|
493 |
+
<!-- Log reset button -->
|
494 |
+
<div class="postbox">
|
495 |
+
<h3 class="hndle"><label for="title"><?php esc_html_e( 'Reset Download Log Entries', 'simple-download-monitor' ); ?></label></h3>
|
496 |
+
<div class="inside">
|
497 |
+
<form method="post" action="" onSubmit="return confirm('Are you sure you want to reset all the log entries?');" >
|
498 |
+
<div class="submit">
|
499 |
+
<input type="submit" class="button" name="sdm_reset_log_entries" value="<?php esc_html_e( 'Reset Log Entries', 'simple-download-monitor' ); ?>" />
|
500 |
+
<p class="description"><?php esc_html_e( 'This button will reset all log entries. It can useful if you want to export all your log entries then reset them.', 'simple-download-monitor' ); ?></p>
|
501 |
+
</div>
|
502 |
+
</form>
|
503 |
+
|
504 |
+
<form method="post" action="" onSubmit="return confirm('Are you sure you want to trim log entries?');" >
|
505 |
+
<div class="submit">
|
506 |
+
Delete Log Entries Older Than <input name="sdm_trim_log_entries_days" type="text" size="4" value="<?php echo esc_attr( $trim_log_entries_days_default_val ); ?>"/> Days
|
507 |
+
<input type="submit" class="button" name="sdm_trim_log_entries" value="<?php esc_html_e( 'Trim Log Entries', 'simple-download-monitor' ); ?>" />
|
508 |
+
<p class="description"><?php esc_html_e( 'This option can be useful if you want to delete older log entries. Enter a number of days value then click the Trim Log Entries button.', 'simple-download-monitor' ); ?></p>
|
509 |
+
</div>
|
510 |
+
</form>
|
511 |
+
</div>
|
512 |
+
</div>
|
513 |
+
|
514 |
+
</div></div><!-- end of .poststuff and .post-body -->
|
515 |
+
|
516 |
+
<!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
|
517 |
+
<form id="sdm_downloads-filter" method="post">
|
518 |
+
<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
|
519 |
+
<!-- Now we can render the completed list table -->
|
520 |
+
<?php $sdmListTable->display(); ?>
|
521 |
+
</form>
|
522 |
+
|
523 |
+
<script type="text/javascript">
|
524 |
+
jQuery(document).ready(function ($) {
|
525 |
+
$('.fade').click(function () {
|
526 |
+
$(this).fadeOut('slow');
|
527 |
+
});
|
528 |
+
});
|
529 |
+
</script>
|
530 |
+
<?php
|
531 |
+
}
|
532 |
+
|
533 |
+
function sdm_create_stats_page() {
|
534 |
+
|
535 |
+
$main_opts = get_option( 'sdm_downloads_options' );
|
536 |
+
|
537 |
+
if ( isset( $main_opts['admin_no_logs'] ) ) {
|
538 |
+
?>
|
539 |
+
<div class="notice notice-warning"><p><b>Download Logs are disabled in <a href="?post_type=sdm_downloads&page=settings">plugin settings</a>. Please enable Download Logs to see current stats.</b></p></div>
|
540 |
+
<?php
|
541 |
+
}
|
542 |
+
wp_enqueue_script( 'sdm_google_charts' );
|
543 |
+
wp_enqueue_script( 'jquery-ui-datepicker' );
|
544 |
+
wp_enqueue_style( 'sdm_jquery_ui_style' );
|
545 |
+
|
546 |
+
if ( isset( $_POST['sdm_stats_start_date'] ) ) {
|
547 |
+
$start_date = sanitize_text_field( $_POST['sdm_stats_start_date'] );
|
548 |
+
} else {
|
549 |
+
// default start date is 30 days back
|
550 |
+
$start_date = date( 'Y-m-d', time() - 60 * 60 * 24 * 30 );
|
551 |
+
}
|
552 |
+
|
553 |
+
if ( isset( $_POST['sdm_stats_end_date'] ) ) {
|
554 |
+
$end_date = sanitize_text_field( $_POST['sdm_stats_end_date'] );
|
555 |
+
} else {
|
556 |
+
$end_date = date( 'Y-m-d', time() );
|
557 |
+
}
|
558 |
+
if ( isset( $_REQUEST['sdm_active_tab'] ) && ! empty( $_REQUEST['sdm_active_tab'] ) ) {
|
559 |
+
$active_tab = sanitize_text_field( $_REQUEST['sdm_active_tab'] );
|
560 |
+
} else {
|
561 |
+
$active_tab = 'datechart';
|
562 |
+
}
|
563 |
+
$downloads_by_date = sdm_get_downloads_by_date( $start_date, $end_date, false );
|
564 |
+
|
565 |
+
$downloads_by_country = sdm_get_downloads_by_country( $start_date, $end_date, false );
|
566 |
+
|
567 |
+
$adv_opts = get_option( 'sdm_advanced_options' );
|
568 |
+
|
569 |
+
$api_key = '';
|
570 |
+
if ( isset( $adv_opts['maps_api_key'] ) ) {
|
571 |
+
$api_key = $adv_opts['maps_api_key'];
|
572 |
+
}
|
573 |
+
?>
|
574 |
+
<style>
|
575 |
+
#sdm-api-key-warning {
|
576 |
+
padding: 5px 0;
|
577 |
+
width: auto;
|
578 |
+
margin: 5px 0;
|
579 |
+
display: none;
|
580 |
+
}
|
581 |
+
</style>
|
582 |
+
<div class="wrap">
|
583 |
+
<h2><?php esc_html_e( 'Stats', 'simple-download-monitor' ); ?></h2>
|
584 |
+
<div id="poststuff"><div id="post-body">
|
585 |
+
|
586 |
+
<div class="postbox">
|
587 |
+
<h3 class="hndle"><label for="title"><?php esc_html_e( 'Choose Date Range (yyyy-mm-dd)', 'simple-download-monitor' ); ?></label></h3>
|
588 |
+
<div class="inside">
|
589 |
+
<form id="sdm_choose_date" method="post">
|
590 |
+
<input type="hidden" name="sdm_active_tab" value="<?php echo esc_attr( sdm_sanitize_text( $active_tab ) ); ?>">
|
591 |
+
<?php esc_html_e( 'Start Date: ', 'simple-download-monitor' ); ?><input type="text" class="datepicker" name="sdm_stats_start_date" value="<?php echo esc_attr( sdm_sanitize_text( $start_date ) ); ?>">
|
592 |
+
<?php esc_html_e( 'End Date: ', 'simple-download-monitor' ); ?><input type="text" class="datepicker" name="sdm_stats_end_date" value="<?php echo esc_attr( sdm_sanitize_text( $start_date ) ); ?>">
|
593 |
+
<p id="sdm_date_buttons">
|
594 |
+
<button type="button" data-start-date="<?php echo esc_attr( date( 'Y-m-01' ) ); ?>" data-end-date="<?php echo esc_attr( date( 'Y-m-d' ) ); ?>"><?php esc_html_e( 'This Month', 'simple-download-monitor' ); ?></button>
|
595 |
+
<button type="button" data-start-date="<?php echo esc_attr( date( 'Y-m-d', strtotime( 'first day of last month' ) ) ); ?>" data-end-date="<?php echo esc_attr( date( 'Y-m-d', strtotime( 'last day of last month' ) ) ); ?>"><?php esc_html_e( 'Last Month', 'simple-download-monitor' ); ?></button>
|
596 |
+
<button button type="button" data-start-date="<?php echo esc_attr( date( 'Y-01-01' ) ); ?>" data-end-date="<?php echo esc_attr( date( 'Y-m-d' ) ); ?>"><?php esc_html_e( 'This Year', 'simple-download-monitor' ); ?></button>
|
597 |
+
<button button type="button" data-start-date="<?php echo esc_attr( date( 'Y-01-01', strtotime( '-1 year' ) ) ); ?>" data-end-date="<?php echo esc_attr( date( 'Y-12-31', strtotime( 'last year' ) ) ); ?>"><?php esc_html_e( 'Last Year', 'simple-download-monitor' ); ?></button>
|
598 |
+
<button button type="button" data-start-date="<?php echo '1970-01-01'; ?>" data-end-date="<?php echo esc_attr( date( 'Y-m-d' ) ); ?>"><?php esc_html_e( 'All Time', 'simple-download-monitor' ); ?></button>
|
599 |
+
</p>
|
600 |
+
<div class="submit">
|
601 |
+
<input type="submit" class="button-primary" value="<?php esc_html_e( 'View Stats', 'simple-download-monitor' ); ?>">
|
602 |
+
</div>
|
603 |
+
</form>
|
604 |
+
</div>
|
605 |
+
</div>
|
606 |
+
<div class="nav-tab-wrapper sdm-tabs">
|
607 |
+
<a href="edit.php?post_type=sdm_downloads&page=sdm-stats&sdm_active_tab=datechart" class="nav-tab<?php echo ( $active_tab === 'datechart' ? ' nav-tab-active' : '' ); ?>" data-tab-name="datechart"><?php esc_html_e( 'Downloads by date', 'simple-download-monitor' ); ?></a>
|
608 |
+
<a href="edit.php?post_type=sdm_downloads&page=stats&sdm_active_tab=geochart" href="" class="nav-tab<?php echo ( $active_tab === 'geochart' ? ' nav-tab-active' : '' ); ?>" data-tab-name="geochart"><?php esc_html_e( 'Downloads by country', 'simple-download-monitor' ); ?></a>
|
609 |
+
<a href="edit.php?post_type=sdm_downloads&page=stats&sdm_active_tab=countrylistchart" href="" class="nav-tab<?php echo ( $active_tab === 'countrylistchart' ? ' nav-tab-active' : '' ); ?>" data-tab-name="countrylistchart"><?php esc_html_e( 'Downloads by country list', 'simple-download-monitor' ); ?></a>
|
610 |
+
<a href="edit.php?post_type=sdm_downloads&page=stats&sdm_active_tab=browserList" href="" class="nav-tab<?php echo ( $active_tab === 'browserList' ? ' nav-tab-active' : '' ); ?>" data-tab-name="browserList"><?php esc_html_e( 'Downloads by browser', 'simple-download-monitor' ); ?></a>
|
611 |
+
<a href="edit.php?post_type=sdm_downloads&page=stats&sdm_active_tab=osList" href="" class="nav-tab<?php echo ( $active_tab === 'osList' ? ' nav-tab-active' : '' ); ?>" data-tab-name="osList"><?php esc_html_e( 'Downloads by OS', 'simple-download-monitor' ); ?></a>
|
612 |
+
<a href="edit.php?post_type=sdm_downloads&page=stats&sdm_active_tab=topDownloads" href="" class="nav-tab<?php echo ( $active_tab === 'topDownloads' ? ' nav-tab-active' : '' ); ?>" data-tab-name="topDownloads"><?php esc_html_e( 'Top Downloads', 'simple-download-monitor' ); ?></a>
|
613 |
+
</div>
|
614 |
+
<div class="sdm-tabs-content-wrapper" style="height: 500px;margin-top: 10px;">
|
615 |
+
<div data-tab-name="datechart" class="sdm-tab"<?php echo ( $active_tab === 'datechart' ? '' : ' style="display:none;"' ); ?>>
|
616 |
+
<div id="downloads_chart" style="width: auto; max-width: 700px"></div>
|
617 |
+
</div>
|
618 |
+
<div data-tab-name="geochart" class="sdm-tab"<?php echo ( $active_tab === 'geochart' ? '' : ' style="display:none;"' ); ?>>
|
619 |
+
<div id="sdm-api-key-warning">
|
620 |
+
<div class="sdm_yellow_box">
|
621 |
+
<span class="dashicons dashicons-warning" style="color: #ffae42;"></span>
|
622 |
+
<?php
|
623 |
+
echo wp_kses(
|
624 |
+
__( 'Enter your Google Maps API Key <a href="edit.php?post_type=sdm_downloads&page=sdm-settings&action=advanced-settings#maps_api_key" target="_blank">in the settings</a> to properly display the chart.', 'simple-download-monitor' ),
|
625 |
+
array(
|
626 |
+
'a' => array(
|
627 |
+
'target' => array(),
|
628 |
+
'href' => array(),
|
629 |
+
),
|
630 |
+
)
|
631 |
+
);
|
632 |
+
?>
|
633 |
+
</div>
|
634 |
+
</div>
|
635 |
+
|
636 |
+
<div id="country_chart" style="width: auto; max-width: 700px; height:437px;"></div>
|
637 |
+
</div>
|
638 |
+
|
639 |
+
<div data-tab-name="countrylistchart" class="sdm-tab"<?php echo ( $active_tab === 'countrylistchart' ? '' : ' style="display:none;"' ); ?>>
|
640 |
+
<div class="wrap">
|
641 |
+
<table class="widefat">
|
642 |
+
<thead>
|
643 |
+
<th><strong><?php esc_html_e( 'Country Name', 'simple-download-monitor' ); ?></strong></th>
|
644 |
+
<th><strong><?php esc_html_e( 'Total Downloads', 'simple-download-monitor' ); ?></strong></th>
|
645 |
+
</thead>
|
646 |
+
<tbody>
|
647 |
+
<?php
|
648 |
+
//An array containing the downloads.
|
649 |
+
$downloads_by_country_array = sdm_get_downloads_by_country( $start_date, $end_date, false );
|
650 |
+
foreach ( $downloads_by_country_array as $item ) {
|
651 |
+
if ( empty( $item['country'] ) ) {
|
652 |
+
//Lets skip any unknown country rows
|
653 |
+
continue;
|
654 |
+
}
|
655 |
+
echo '<tr>';
|
656 |
+
echo '<td>' . esc_html( $item['country'] ) . '</td>';
|
657 |
+
echo '<td>' . esc_html( $item['cnt'] ) . '</td>';
|
658 |
+
echo '</tr>';
|
659 |
+
}
|
660 |
+
?>
|
661 |
+
</tbody>
|
662 |
+
<tfoot>
|
663 |
+
<th><strong><?php esc_html_e( 'Country Name', 'simple-download-monitor' ); ?></strong></th>
|
664 |
+
<th><strong><?php esc_html_e( 'Total Downloads', 'simple-download-monitor' ); ?></strong></th>
|
665 |
+
</tfoot>
|
666 |
+
</table>
|
667 |
+
</div>
|
668 |
+
</div><!-- end of countrylistchart -->
|
669 |
+
|
670 |
+
<div data-tab-name="browserList"
|
671 |
+
class="sdm-tab"<?php echo( $active_tab === 'browserList' ? '' : ' style="display:none;"' ); ?>>
|
672 |
+
<div class="wrap">
|
673 |
+
<table class="widefat">
|
674 |
+
<thead>
|
675 |
+
<th><strong><?php esc_html_e( 'Browser', 'simple-download-monitor' ); ?></strong></th>
|
676 |
+
<th><strong><?php esc_html_e( 'Total Downloads', 'simple-download-monitor' ); ?></strong></th>
|
677 |
+
</thead>
|
678 |
+
<tbody>
|
679 |
+
<?php
|
680 |
+
$downloads_by_browser_array = sdm_get_all_downloads_by_browser( $start_date, $end_date );
|
681 |
+
foreach ( $downloads_by_browser_array as $name => $count ) {
|
682 |
+
?>
|
683 |
+
<tr>
|
684 |
+
<td><?php echo esc_html( $name ); ?></td>
|
685 |
+
<td><?php echo esc_html( $count ); ?></td>
|
686 |
+
</tr>
|
687 |
+
<?php } ?>
|
688 |
+
</tbody>
|
689 |
+
<tfoot>
|
690 |
+
<th><strong><?php esc_html_e( 'Browser', 'simple-download-monitor' ); ?></strong></th>
|
691 |
+
<th><strong><?php esc_html_e( 'Total Downloads', 'simple-download-monitor' ); ?></strong></th>
|
692 |
+
</tfoot>
|
693 |
+
</table>
|
694 |
+
</div>
|
695 |
+
</div><!-- end of browserList tab-->
|
696 |
+
|
697 |
+
<div data-tab-name="osList"
|
698 |
+
class="sdm-tab"<?php echo( $active_tab === 'osList' ? '' : ' style="display:none;"' ); ?>>
|
699 |
+
<div class="wrap">
|
700 |
+
<table class="widefat">
|
701 |
+
<thead>
|
702 |
+
<th><strong><?php esc_html_e( 'Operating System', 'simple-download-monitor' ); ?></strong></th>
|
703 |
+
<th><strong><?php esc_html_e( 'Total Downloads', 'simple-download-monitor' ); ?></strong></th>
|
704 |
+
</thead>
|
705 |
+
<tbody>
|
706 |
+
<?php
|
707 |
+
$downloads_by_os_array = sdm_get_all_downloads_by_os( $start_date, $end_date );
|
708 |
+
foreach ( $downloads_by_os_array as $name => $count ) {
|
709 |
+
?>
|
710 |
+
<tr>
|
711 |
+
<td><?php echo esc_html( $name ); ?></td>
|
712 |
+
<td><?php echo esc_html( $count ); ?></td>
|
713 |
+
</tr>
|
714 |
+
<?php } ?>
|
715 |
+
</tbody>
|
716 |
+
<tfoot>
|
717 |
+
<th><strong><?php esc_html_e( 'Operating System', 'simple-download-monitor' ); ?></strong></th>
|
718 |
+
<th><strong><?php esc_html_e( 'Total Downloads', 'simple-download-monitor' ); ?></strong></th>
|
719 |
+
</tfoot>
|
720 |
+
</table>
|
721 |
+
</div>
|
722 |
+
</div><!-- end of osList tab-->
|
723 |
+
|
724 |
+
<div data-tab-name="topDownloads"
|
725 |
+
class="sdm-tab"<?php echo( $active_tab === 'topDownloads' ? '' : ' style="display:none;"' ); ?>>
|
726 |
+
<div class="wrap">
|
727 |
+
<table class="widefat">
|
728 |
+
<thead>
|
729 |
+
<th><strong><?php esc_html_e( 'Download Item', 'simple-download-monitor' ); ?></strong></th>
|
730 |
+
<th><strong><?php esc_html_e( 'Total Downloads', 'simple-download-monitor' ); ?></strong></th>
|
731 |
+
</thead>
|
732 |
+
<tbody>
|
733 |
+
<?php
|
734 |
+
$downloads_by_count = sdm_get_top_downloads_by_count( $start_date, $end_date, 15 );
|
735 |
+
foreach ( $downloads_by_count as $item ) {
|
736 |
+
?>
|
737 |
+
<tr>
|
738 |
+
<td><?php echo esc_html( $item['post_title'] ); ?></td>
|
739 |
+
<td><?php echo esc_html( $item['cnt'] ); ?></td>
|
740 |
+
</tr>
|
741 |
+
<?php } ?>
|
742 |
+
</tbody>
|
743 |
+
<tfoot>
|
744 |
+
<th><strong><?php esc_html_e( 'Download Item', 'simple-download-monitor' ); ?></strong></th>
|
745 |
+
<th><strong><?php esc_html_e( 'Total Downloads', 'simple-download-monitor' ); ?></strong></th>
|
746 |
+
</tfoot>
|
747 |
+
</table>
|
748 |
+
</div>
|
749 |
+
</div><!-- end of top downloads tab-->
|
750 |
+
|
751 |
+
</div>
|
752 |
+
</div></div>
|
753 |
+
</div>
|
754 |
+
|
755 |
+
<?php
|
756 |
+
|
757 |
+
$dbd_prop = array();
|
758 |
+
|
759 |
+
foreach ( $downloads_by_date as $dbd ) {
|
760 |
+
$dbd_prop[] = array( $dbd['day'], intval( $dbd['cnt'] ) );
|
761 |
+
}
|
762 |
+
|
763 |
+
$dbc_prop = array();
|
764 |
+
|
765 |
+
$dbc_prop[] = array( __( 'Country', 'simple-download-monitor' ), __( 'Downloads', 'simple-download-monitor' ) );
|
766 |
+
|
767 |
+
foreach ( $downloads_by_country as $dbc ) {
|
768 |
+
$dbc_prop[] = array( $dbc['country'], intval( $dbc['cnt'] ) );
|
769 |
+
}
|
770 |
+
|
771 |
+
wp_localize_script(
|
772 |
+
'sdm-admin-stats',
|
773 |
+
'sdmAdminStats',
|
774 |
+
array(
|
775 |
+
'activeTab' => $active_tab,
|
776 |
+
'apiKey' => $api_key,
|
777 |
+
'dByDate' => $dbd_prop,
|
778 |
+
'dByCountry' => $dbc_prop,
|
779 |
+
'str' => array(
|
780 |
+
'downloadsByDate' => __( 'Downloads by Date', 'simple-download-monitor' ),
|
781 |
+
'date' => __( 'Date', 'simple-download-monitor' ),
|
782 |
+
'numberOfDownloads' => __( 'Number of downloads', 'simple-download-monitor' ),
|
783 |
+
'downloads' => __( 'Downloads', 'single-download-monitor' ),
|
784 |
+
),
|
785 |
+
)
|
786 |
+
);
|
787 |
+
}
|
788 |
+
|
789 |
+
function sdm_create_addons_page() {
|
790 |
+
include WP_SIMPLE_DL_MONITOR_PATH . 'includes/admin-side/sdm-admin-add-ons-page.php';
|
791 |
+
}
|
includes/sdm-blocks.php
CHANGED
@@ -2,116 +2,152 @@
|
|
2 |
|
3 |
class SDMBlocks {
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
}
|
8 |
-
|
9 |
-
function register_block() {
|
10 |
-
if ( ! function_exists( 'register_block_type' ) ) {
|
11 |
-
// Gutenberg is not active.
|
12 |
-
return;
|
13 |
}
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
$
|
21 |
-
$fancyArr[] = array( 'label' => "Fancy 0", 'value' => 0 );
|
22 |
-
$fancyArr[] = array( 'label' => "Fancy 1", 'value' => 1 );
|
23 |
-
$fancyArr[] = array( 'label' => "Fancy 2", 'value' => 2 );
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
$colorArr[] = array( 'label' => $label, 'value' => $value );
|
31 |
-
}
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
wp_localize_script( 'sdm-blocks-script', 'sdmDownloadBlockColor', $colorArr );
|
36 |
-
wp_localize_script( 'sdm-blocks-script', 'sdmBlockDownloadItemStr', array(
|
37 |
-
'title' => __( 'SDM Download', 'simple-download-monitor' ),
|
38 |
-
'download' => __( 'Download Item', 'simple-download-monitor' ),
|
39 |
-
'downloadHelp' => __( 'Select download item.', 'simple-download-monitor' ),
|
40 |
-
'buttonText' => __( 'Button Text', 'simple-download-monitor' ),
|
41 |
-
'buttonTextHelp' => __( 'Customized text for the download button. Leave it blank to use default text.', 'simple-download-monitor' ),
|
42 |
-
'fancy' => __( 'Template', 'simple-download-monitor' ),
|
43 |
-
'fancyHelp' => __( 'Select download item template.', 'simple-download-monitor' ),
|
44 |
-
'newWindow' => __( 'Open Download in a New Window', 'simple-download-monitor' ),
|
45 |
-
'color' => __( 'Button Color', 'simple-download-monitor' ),
|
46 |
-
'colorHelp' => __( 'Select button color. Note that this option may not work for some templates.', 'simple-download-monitor' ),
|
47 |
-
) );
|
48 |
-
|
49 |
-
register_block_type( 'simple-download-monitor/download-item', array(
|
50 |
-
'attributes' => array(
|
51 |
-
'itemId' => array(
|
52 |
-
'type' => 'string',
|
53 |
-
'default' => 0,
|
54 |
-
),
|
55 |
-
'fancyId' => array(
|
56 |
-
'type' => 'string',
|
57 |
-
'default' => 0,
|
58 |
-
),
|
59 |
-
'color' => array(
|
60 |
-
'type' => 'string',
|
61 |
-
'default' => '',
|
62 |
-
),
|
63 |
-
'buttonText' => array(
|
64 |
-
'type' => 'string',
|
65 |
-
'default' => '',
|
66 |
-
),
|
67 |
-
'newWindow' => array(
|
68 |
-
'type' => 'boolean',
|
69 |
-
'default' => false,
|
70 |
-
),
|
71 |
-
),
|
72 |
-
'editor_script' => 'sdm-blocks-script',
|
73 |
-
'render_callback' => array( $this, 'render_item_block' ),
|
74 |
-
) );
|
75 |
-
}
|
76 |
-
|
77 |
-
function render_item_block( $atts ) {
|
78 |
-
|
79 |
-
$itemId = ! empty( $atts[ 'itemId' ] ) ? intval( $atts[ 'itemId' ] ) : 0;
|
80 |
-
$fancyId = ! empty( $atts[ 'fancyId' ] ) ? intval( $atts[ 'fancyId' ] ) : 0;
|
81 |
-
$color = ! empty( $atts[ 'color' ] ) ? $atts[ 'color' ] : '';
|
82 |
-
$buttonText = ! empty( $atts[ 'buttonText' ] ) ? esc_attr( $atts[ 'buttonText' ] ) : sdm_get_download_form_with_termsncond( $itemId );
|
83 |
-
$newWindow = ! empty( $atts[ 'newWindow' ] ) ? 1 : 0;
|
84 |
-
|
85 |
-
if ( empty( $itemId ) ) {
|
86 |
-
return '<p>' . __( 'Select item to view', 'simple-download-monitor' ) . '</p>';
|
87 |
-
}
|
88 |
|
89 |
-
|
90 |
-
|
|
|
91 |
|
92 |
-
|
93 |
-
$sc_str .= ' button_only="1"';
|
94 |
}
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
}
|
112 |
-
wp_reset_postdata();
|
113 |
-
return $itemsArr;
|
114 |
-
}
|
115 |
|
116 |
}
|
117 |
|
2 |
|
3 |
class SDMBlocks {
|
4 |
|
5 |
+
function __construct() {
|
6 |
+
add_action( 'init', array( $this, 'register_block' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
}
|
8 |
|
9 |
+
function register_block() {
|
10 |
+
if ( ! function_exists( 'register_block_type' ) ) {
|
11 |
+
// Gutenberg is not active.
|
12 |
+
return;
|
13 |
+
}
|
14 |
+
|
15 |
+
wp_enqueue_style( 'sdm-styles', WP_SIMPLE_DL_MONITOR_URL . '/css/sdm_wp_styles.css' );
|
16 |
+
|
17 |
+
wp_register_script(
|
18 |
+
'sdm-blocks-script',
|
19 |
+
WP_SIMPLE_DL_MONITOR_URL . '/js/sdm_blocks.js',
|
20 |
+
array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor' ),
|
21 |
+
WP_SIMPLE_DL_MONITOR_VERSION
|
22 |
+
);
|
23 |
+
|
24 |
+
$fancyArr = array();
|
25 |
+
$fancyArr[] = array(
|
26 |
+
'label' => 'Fancy 0',
|
27 |
+
'value' => 0,
|
28 |
+
);
|
29 |
+
$fancyArr[] = array(
|
30 |
+
'label' => 'Fancy 1',
|
31 |
+
'value' => 1,
|
32 |
+
);
|
33 |
+
$fancyArr[] = array(
|
34 |
+
'label' => 'Fancy 2',
|
35 |
+
'value' => 2,
|
36 |
+
);
|
37 |
+
|
38 |
+
$defColorArr = sdm_get_download_button_colors();
|
39 |
+
|
40 |
+
$colorArr = array();
|
41 |
+
$colorArr[] = array(
|
42 |
+
'label' => __( 'Default', 'simple-download-monitor' ),
|
43 |
+
'value' => '',
|
44 |
+
);
|
45 |
+
foreach ( $defColorArr as $value => $label ) {
|
46 |
+
$colorArr[] = array(
|
47 |
+
'label' => $label,
|
48 |
+
'value' => $value,
|
49 |
+
);
|
50 |
+
}
|
51 |
+
|
52 |
+
wp_localize_script( 'sdm-blocks-script', 'sdmDownloadBlockItems', $this->get_items_array() );
|
53 |
+
wp_localize_script( 'sdm-blocks-script', 'sdmDownloadBlockFancy', $fancyArr );
|
54 |
+
wp_localize_script( 'sdm-blocks-script', 'sdmDownloadBlockColor', $colorArr );
|
55 |
+
wp_localize_script(
|
56 |
+
'sdm-blocks-script',
|
57 |
+
'sdmBlockDownloadItemStr',
|
58 |
+
array(
|
59 |
+
'title' => __( 'SDM Download', 'simple-download-monitor' ),
|
60 |
+
'download' => __( 'Download Item', 'simple-download-monitor' ),
|
61 |
+
'downloadHelp' => __( 'Select download item.', 'simple-download-monitor' ),
|
62 |
+
'buttonText' => __( 'Button Text', 'simple-download-monitor' ),
|
63 |
+
'buttonTextHelp' => __( 'Customized text for the download button. Leave it blank to use default text.', 'simple-download-monitor' ),
|
64 |
+
'fancy' => __( 'Template', 'simple-download-monitor' ),
|
65 |
+
'fancyHelp' => __( 'Select download item template.', 'simple-download-monitor' ),
|
66 |
+
'newWindow' => __( 'Open Download in a New Window', 'simple-download-monitor' ),
|
67 |
+
'color' => __( 'Button Color', 'simple-download-monitor' ),
|
68 |
+
'colorHelp' => __( 'Select button color. Note that this option may not work for some templates.', 'simple-download-monitor' ),
|
69 |
+
)
|
70 |
+
);
|
71 |
+
|
72 |
+
register_block_type(
|
73 |
+
'simple-download-monitor/download-item',
|
74 |
+
array(
|
75 |
+
'attributes' => array(
|
76 |
+
'itemId' => array(
|
77 |
+
'type' => 'string',
|
78 |
+
'default' => 0,
|
79 |
+
),
|
80 |
+
'fancyId' => array(
|
81 |
+
'type' => 'string',
|
82 |
+
'default' => 0,
|
83 |
+
),
|
84 |
+
'color' => array(
|
85 |
+
'type' => 'string',
|
86 |
+
'default' => '',
|
87 |
+
),
|
88 |
+
'buttonText' => array(
|
89 |
+
'type' => 'string',
|
90 |
+
'default' => '',
|
91 |
+
),
|
92 |
+
'newWindow' => array(
|
93 |
+
'type' => 'boolean',
|
94 |
+
'default' => false,
|
95 |
+
),
|
96 |
+
),
|
97 |
+
'editor_script' => 'sdm-blocks-script',
|
98 |
+
'render_callback' => array( $this, 'render_item_block' ),
|
99 |
+
)
|
100 |
+
);
|
101 |
+
}
|
102 |
|
103 |
+
function render_item_block( $atts ) {
|
|
|
|
|
|
|
104 |
|
105 |
+
$itemId = ! empty( $atts['itemId'] ) ? intval( $atts['itemId'] ) : 0;
|
106 |
+
$fancyId = ! empty( $atts['fancyId'] ) ? intval( $atts['fancyId'] ) : 0;
|
107 |
+
$color = ! empty( $atts['color'] ) ? $atts['color'] : '';
|
108 |
+
$buttonText = ! empty( $atts['buttonText'] ) ? esc_attr( $atts['buttonText'] ) : sdm_get_download_form_with_termsncond( $itemId );
|
109 |
+
$newWindow = ! empty( $atts['newWindow'] ) ? 1 : 0;
|
110 |
|
111 |
+
if ( empty( $itemId ) ) {
|
112 |
+
return '<p>' . __( 'Select item to view', 'simple-download-monitor' ) . '</p>';
|
113 |
+
}
|
|
|
|
|
114 |
|
115 |
+
$sc_str = 'sdm_download id="%d" fancy="%d" button_text="%s" new_window="%d" color="%s"';
|
116 |
+
$sc_str = sprintf( $sc_str, $itemId, $fancyId, $buttonText, $newWindow, $color );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
+
if ( ! empty( $atts['btnOnly'] ) ) {
|
119 |
+
$sc_str .= ' button_only="1"';
|
120 |
+
}
|
121 |
|
122 |
+
return do_shortcode( '[' . $sc_str . ']' );
|
|
|
123 |
}
|
124 |
|
125 |
+
private function get_items_array() {
|
126 |
+
$q = get_posts(
|
127 |
+
array(
|
128 |
+
'post_type' => 'sdm_downloads',
|
129 |
+
'post_status' => 'publish',
|
130 |
+
'posts_per_page' => -1,
|
131 |
+
'orderby' => 'title',
|
132 |
+
'order' => 'ASC',
|
133 |
+
)
|
134 |
+
);
|
135 |
+
$itemsArr = array(
|
136 |
+
array(
|
137 |
+
'label' => __( '(Select item)', 'simple-download-monitor' ),
|
138 |
+
'value' => 0,
|
139 |
+
),
|
140 |
+
);
|
141 |
+
foreach ( $q as $post ) {
|
142 |
+
$title = html_entity_decode( $post->post_title );
|
143 |
+
$itemsArr[] = array(
|
144 |
+
'label' => esc_attr( $title ),
|
145 |
+
'value' => $post->ID,
|
146 |
+
);
|
147 |
+
}
|
148 |
+
wp_reset_postdata();
|
149 |
+
return $itemsArr;
|
150 |
}
|
|
|
|
|
|
|
151 |
|
152 |
}
|
153 |
|
includes/sdm-debug.php
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SDM_Debug {
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SDM_Debug {
|
4 |
+
|
5 |
+
public function __construct() {
|
6 |
+
|
7 |
+
}
|
8 |
+
|
9 |
+
static function log( $msg, $success = true ) {
|
10 |
+
$opts = get_option( 'sdm_downloads_options' );
|
11 |
+
if ( isset( $opts['enable_debug'] ) && $opts['enable_debug'] == 'on' ) {
|
12 |
+
file_put_contents( WP_SDM_LOG_FILE, date( 'Y-m-d H:i:s', time() ) . ': [' . ( $success === true ? 'SUCCESS' : 'FAIL' ) . '] ' . $msg . "\r\n", FILE_APPEND );
|
13 |
+
}
|
14 |
+
}
|
15 |
+
|
16 |
+
static function reset_log() {
|
17 |
+
file_put_contents( WP_SDM_LOG_FILE, date( 'Y-m-d H:i:s', time() ) . ': Log has been reset.' . "\r\n" );
|
18 |
+
file_put_contents( WP_SDM_LOG_FILE, '-------------------------------------------------------' . "\r\n", FILE_APPEND );
|
19 |
+
}
|
20 |
+
|
21 |
+
}
|
includes/sdm-download-request-handler.php
CHANGED
@@ -1,247 +1,249 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
//Handles the download request
|
4 |
-
function handle_sdm_download_via_direct_post() {
|
5 |
-
if ( isset( $_REQUEST['smd_process_download'] ) && $_REQUEST['smd_process_download'] == '1' ) {
|
6 |
-
global $wpdb;
|
7 |
-
$download_id = absint( $_REQUEST['download_id'] );
|
8 |
-
$download_title = get_the_title( $download_id );
|
9 |
-
$download_link = get_post_meta( $download_id, 'sdm_upload', true );
|
10 |
-
|
11 |
-
//Do some validation checks
|
12 |
-
if ( ! $download_id ) {
|
13 |
-
wp_die( __( 'Error! Incorrect download item id.', 'simple-download-monitor' ) );
|
14 |
-
}
|
15 |
-
if ( empty( $download_link ) ) {
|
16 |
-
wp_die( printf( __( 'Error! This download item (%s) does not have any download link. Edit this item and specify a downloadable file URL for it.', 'simple-download-monitor' ), $download_id ) );
|
17 |
-
}
|
18 |
-
|
19 |
-
sdm_recaptcha_verify();
|
20 |
-
|
21 |
-
//Check download password (if applicable for this download)
|
22 |
-
$post_object = get_post( $download_id ); // Get post object
|
23 |
-
$post_pass = $post_object->post_password; // Get post password
|
24 |
-
if ( ! empty( $post_pass ) ) {//This download item has a password. So validate the password.
|
25 |
-
$pass_val = $_REQUEST['pass_text'];
|
26 |
-
if ( empty( $pass_val ) ) {//No password was submitted with the downoad request.
|
27 |
-
do_action( 'sdm_process_download_request_no_password' );
|
28 |
-
|
29 |
-
$dl_post_url = get_permalink( $download_id );
|
30 |
-
$error_msg = __( 'Error! This download requires a password.', 'simple-download-monitor' );
|
31 |
-
$error_msg .= '<p>';
|
32 |
-
$error_msg .= '<a href="' . $dl_post_url . '">' . __( 'Click here', 'simple-download-monitor' ) . '</a>';
|
33 |
-
$error_msg .= __( ' and enter a valid password for this item', 'simple-download-monitor' );
|
34 |
-
$error_msg .= '</p>';
|
35 |
-
wp_die( $error_msg );
|
36 |
-
}
|
37 |
-
if ( $post_pass != $pass_val ) {
|
38 |
-
//Incorrect password submitted.
|
39 |
-
do_action( 'sdm_process_download_request_incorrect_password' );
|
40 |
-
|
41 |
-
wp_die( __( 'Error! Incorrect password. This download requires a valid password.', 'simple-download-monitor' ) );
|
42 |
-
} else {
|
43 |
-
//Password is valid. Go ahead with the download
|
44 |
-
}
|
45 |
-
}
|
46 |
-
//End of password check
|
47 |
-
|
48 |
-
$main_option = get_option( 'sdm_downloads_options' );
|
49 |
-
|
50 |
-
$ipaddress
|
51 |
-
//Check if do not capture IP is enabled.
|
52 |
-
if ( ! isset( $main_option['admin_do_not_capture_ip'] ) ) {
|
53 |
-
$ipaddress = sdm_get_ip_address();
|
54 |
-
}
|
55 |
-
|
56 |
-
|
57 |
-
//Check if do not capture User Agent is enabled.
|
58 |
-
if ( ! isset( $main_option['admin_do_not_capture_user_agent'] ) ) {
|
59 |
-
//Get the user agent data. The get_browser() function doesn't work on many servers. So use the HTTP var.
|
60 |
-
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
61 |
-
$user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
|
62 |
-
}
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
//Check if do not capture Referer URL is enabled.
|
67 |
-
if ( ! isset( $main_option['admin_do_not_capture_referrer_url'] ) ) {
|
68 |
-
//Get the user agent data. The get_browser() function doesn't work on many servers. So use the HTTP var.
|
69 |
-
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
|
70 |
-
$referrer_url = sanitize_text_field( $_SERVER['HTTP_REFERER'] );
|
71 |
-
}
|
72 |
-
|
73 |
-
|
74 |
-
$date_time = current_time( 'mysql' );
|
75 |
-
$visitor_country = ! empty( $ipaddress ) ? sdm_ip_info( $ipaddress, 'country' ) : '';
|
76 |
-
|
77 |
-
$visitor_name = sdm_get_logged_in_user();
|
78 |
-
|
79 |
-
$anonymous_can_download = get_post_meta( $download_id, 'sdm_item_anonymous_can_download', true );
|
80 |
-
|
81 |
-
// Check if we only allow the download for logged-in users
|
82 |
-
if ( isset( $main_option['only_logged_in_can_download'] ) ) {
|
83 |
-
if ( $main_option['only_logged_in_can_download'] && $visitor_name === false && ! $anonymous_can_download ) {
|
84 |
-
//User not logged in, let's display the error message.
|
85 |
-
//But first let's see if we have login page URL set so we can display it as well
|
86 |
-
$loginMsg = '';
|
87 |
-
if ( isset( $main_option['general_login_page_url'] ) && ! empty( $main_option['general_login_page_url'] ) ) {
|
88 |
-
//We have a login page URL set. Lets use it.
|
89 |
-
|
90 |
-
if ( isset( $main_option['redirect_user_back_to_download_page'] ) ) {
|
91 |
-
//Redirect to download page after login feature is enabled.
|
92 |
-
$dl_post_url = get_permalink( $download_id );//The single download item page
|
93 |
-
$redirect_url = apply_filters( 'sdm_after_login_redirect_query_arg', $dl_post_url );
|
94 |
-
$login_page_url = add_query_arg( array( 'sdm_redirect_to' => urlencode( $redirect_url ) ), $main_option['general_login_page_url'] );
|
95 |
-
} else {
|
96 |
-
$login_page_url = $main_option['general_login_page_url'];
|
97 |
-
}
|
98 |
-
|
99 |
-
$tpl = __( '__Click here__ to go to login page.', 'simple-download-monitor' );
|
100 |
-
$loginMsg = preg_replace( '/__(.*)__/', ' <a href="' . $login_page_url . '">$1</a> $2', $tpl );
|
101 |
-
}
|
102 |
-
wp_die( __( 'You need to be logged in to download this file.', 'simple-download-monitor' ) . $loginMsg );
|
103 |
-
}
|
104 |
-
}
|
105 |
-
|
106 |
-
$visitor_name = ( $visitor_name === false ) ? __( 'Not Logged In', 'simple-download-monitor' ) : $visitor_name;
|
107 |
-
|
108 |
-
// Get option for global disabling of download logging
|
109 |
-
$no_logs = isset( $main_option['admin_no_logs'] );
|
110 |
-
|
111 |
-
// Get optoin for logging only unique IPs
|
112 |
-
$unique_ips = isset( $main_option['admin_log_unique'] );
|
113 |
-
|
114 |
-
// Get post meta for individual disabling of download logging
|
115 |
-
$get_meta = get_post_meta( $download_id, 'sdm_item_no_log', true );
|
116 |
-
$item_logging_checked = isset( $get_meta ) && $get_meta === 'on' ? 'on' : 'off';
|
117 |
-
|
118 |
-
$dl_logging_needed = true;
|
119 |
-
|
120 |
-
// Check if download logs have been disabled (globally or per download item)
|
121 |
-
if ( $no_logs === true || $item_logging_checked === 'on' ) {
|
122 |
-
$dl_logging_needed = false;
|
123 |
-
}
|
124 |
-
|
125 |
-
// Check if we are only logging unique ips
|
126 |
-
if ( $unique_ips === true ) {
|
127 |
-
$check_ip = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id="' . $download_id . '" AND visitor_ip = "' . $ipaddress . '"' );
|
128 |
-
|
129 |
-
//This IP is already logged for this download item. No need to log it again.
|
130 |
-
if ( $check_ip ) {
|
131 |
-
$dl_logging_needed = false;
|
132 |
-
}
|
133 |
-
}
|
134 |
-
|
135 |
-
// Check if "Do Not Count Downloads from Bots" setting is enabled
|
136 |
-
if ( isset( $main_option['admin_dont_log_bots'] ) ) {
|
137 |
-
//it is. Now let's check if visitor is a bot
|
138 |
-
if ( sdm_visitor_is_bot() ) {
|
139 |
-
//visitor is a bot. We neither log nor count this download
|
140 |
-
$dl_logging_needed = false;
|
141 |
-
}
|
142 |
-
}
|
143 |
-
|
144 |
-
if ( $dl_logging_needed ) {
|
145 |
-
// We need to log this download.
|
146 |
-
$table = $wpdb->prefix . 'sdm_downloads';
|
147 |
-
$data = array(
|
148 |
-
'post_id' => $download_id,
|
149 |
-
'post_title' => $download_title,
|
150 |
-
'file_url' => $download_link,
|
151 |
-
'visitor_ip' => $ipaddress,
|
152 |
-
'date_time' => $date_time,
|
153 |
-
'visitor_country' => $visitor_country,
|
154 |
-
'visitor_name' => $visitor_name,
|
155 |
-
'user_agent' => $user_agent,
|
156 |
-
|
157 |
-
);
|
158 |
-
|
159 |
-
$data
|
160 |
-
$insert_table = $wpdb->insert( $table, $data );
|
161 |
-
|
162 |
-
if ( $insert_table ) {
|
163 |
-
//Download request was logged successfully
|
164 |
-
} else {
|
165 |
-
//Failed to log the download request
|
166 |
-
wp_die( __( 'Error! Failed to log the download request in the database table', 'simple-download-monitor' ) );
|
167 |
-
}
|
168 |
-
}
|
169 |
-
|
170 |
-
// Allow plugin extensions to hook into download request.
|
171 |
-
do_action( 'sdm_process_download_request', $download_id, $download_link );
|
172 |
-
|
173 |
-
// Should the item be dispatched?
|
174 |
-
$dispatch = apply_filters( 'sdm_dispatch_downloads', get_post_meta( $download_id, 'sdm_item_dispatch', true ) );
|
175 |
-
|
176 |
-
// Only local file can be dispatched.
|
177 |
-
if ( $dispatch && ( stripos( $download_link, WP_CONTENT_URL ) === 0 ) ) {
|
178 |
-
// Get file path
|
179 |
-
$file = path_join( WP_CONTENT_DIR, ltrim( substr( $download_link, strlen( WP_CONTENT_URL ) ), '/' ) );
|
180 |
-
// Try to dispatch file (terminates script execution on success)
|
181 |
-
sdm_dispatch_file( $file );
|
182 |
-
}
|
183 |
-
|
184 |
-
// As a fallback or when dispatching is disabled, redirect to the file
|
185 |
-
// (and terminate script execution).
|
186 |
-
sdm_redirect_to_url( $download_link );
|
187 |
-
}
|
188 |
-
}
|
189 |
-
|
190 |
-
/**
|
191 |
-
* Dispatch file with $filename and terminate script execution, if the file is
|
192 |
-
* readable and headers have not been sent yet.
|
193 |
-
*
|
194 |
-
* @
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
header( 'Content-
|
210 |
-
header( 'Content-
|
211 |
-
header( '
|
212 |
-
header( '
|
213 |
-
header( '
|
214 |
-
header( '
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
*
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
$
|
233 |
-
$
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//Handles the download request
|
4 |
+
function handle_sdm_download_via_direct_post() {
|
5 |
+
if ( isset( $_REQUEST['smd_process_download'] ) && $_REQUEST['smd_process_download'] == '1' ) {
|
6 |
+
global $wpdb;
|
7 |
+
$download_id = absint( $_REQUEST['download_id'] );
|
8 |
+
$download_title = get_the_title( $download_id );
|
9 |
+
$download_link = get_post_meta( $download_id, 'sdm_upload', true );
|
10 |
+
|
11 |
+
//Do some validation checks
|
12 |
+
if ( ! $download_id ) {
|
13 |
+
wp_die( __( 'Error! Incorrect download item id.', 'simple-download-monitor' ) );
|
14 |
+
}
|
15 |
+
if ( empty( $download_link ) ) {
|
16 |
+
wp_die( printf( __( 'Error! This download item (%s) does not have any download link. Edit this item and specify a downloadable file URL for it.', 'simple-download-monitor' ), $download_id ) );
|
17 |
+
}
|
18 |
+
|
19 |
+
sdm_recaptcha_verify();
|
20 |
+
|
21 |
+
//Check download password (if applicable for this download)
|
22 |
+
$post_object = get_post( $download_id ); // Get post object
|
23 |
+
$post_pass = $post_object->post_password; // Get post password
|
24 |
+
if ( ! empty( $post_pass ) ) {//This download item has a password. So validate the password.
|
25 |
+
$pass_val = $_REQUEST['pass_text'];
|
26 |
+
if ( empty( $pass_val ) ) {//No password was submitted with the downoad request.
|
27 |
+
do_action( 'sdm_process_download_request_no_password' );
|
28 |
+
|
29 |
+
$dl_post_url = get_permalink( $download_id );
|
30 |
+
$error_msg = __( 'Error! This download requires a password.', 'simple-download-monitor' );
|
31 |
+
$error_msg .= '<p>';
|
32 |
+
$error_msg .= '<a href="' . $dl_post_url . '">' . __( 'Click here', 'simple-download-monitor' ) . '</a>';
|
33 |
+
$error_msg .= __( ' and enter a valid password for this item', 'simple-download-monitor' );
|
34 |
+
$error_msg .= '</p>';
|
35 |
+
wp_die( $error_msg );
|
36 |
+
}
|
37 |
+
if ( $post_pass != $pass_val ) {
|
38 |
+
//Incorrect password submitted.
|
39 |
+
do_action( 'sdm_process_download_request_incorrect_password' );
|
40 |
+
|
41 |
+
wp_die( __( 'Error! Incorrect password. This download requires a valid password.', 'simple-download-monitor' ) );
|
42 |
+
} else {
|
43 |
+
//Password is valid. Go ahead with the download
|
44 |
+
}
|
45 |
+
}
|
46 |
+
//End of password check
|
47 |
+
|
48 |
+
$main_option = get_option( 'sdm_downloads_options' );
|
49 |
+
|
50 |
+
$ipaddress = '';
|
51 |
+
//Check if do not capture IP is enabled.
|
52 |
+
if ( ! isset( $main_option['admin_do_not_capture_ip'] ) ) {
|
53 |
+
$ipaddress = sdm_get_ip_address();
|
54 |
+
}
|
55 |
+
|
56 |
+
$user_agent = '';
|
57 |
+
//Check if do not capture User Agent is enabled.
|
58 |
+
if ( ! isset( $main_option['admin_do_not_capture_user_agent'] ) ) {
|
59 |
+
//Get the user agent data. The get_browser() function doesn't work on many servers. So use the HTTP var.
|
60 |
+
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
61 |
+
$user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
$referrer_url = '';
|
66 |
+
//Check if do not capture Referer URL is enabled.
|
67 |
+
if ( ! isset( $main_option['admin_do_not_capture_referrer_url'] ) ) {
|
68 |
+
//Get the user agent data. The get_browser() function doesn't work on many servers. So use the HTTP var.
|
69 |
+
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
|
70 |
+
$referrer_url = sanitize_text_field( $_SERVER['HTTP_REFERER'] );
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
$date_time = current_time( 'mysql' );
|
75 |
+
$visitor_country = ! empty( $ipaddress ) ? sdm_ip_info( $ipaddress, 'country' ) : '';
|
76 |
+
|
77 |
+
$visitor_name = sdm_get_logged_in_user();
|
78 |
+
|
79 |
+
$anonymous_can_download = get_post_meta( $download_id, 'sdm_item_anonymous_can_download', true );
|
80 |
+
|
81 |
+
// Check if we only allow the download for logged-in users
|
82 |
+
if ( isset( $main_option['only_logged_in_can_download'] ) ) {
|
83 |
+
if ( $main_option['only_logged_in_can_download'] && $visitor_name === false && ! $anonymous_can_download ) {
|
84 |
+
//User not logged in, let's display the error message.
|
85 |
+
//But first let's see if we have login page URL set so we can display it as well
|
86 |
+
$loginMsg = '';
|
87 |
+
if ( isset( $main_option['general_login_page_url'] ) && ! empty( $main_option['general_login_page_url'] ) ) {
|
88 |
+
//We have a login page URL set. Lets use it.
|
89 |
+
|
90 |
+
if ( isset( $main_option['redirect_user_back_to_download_page'] ) ) {
|
91 |
+
//Redirect to download page after login feature is enabled.
|
92 |
+
$dl_post_url = get_permalink( $download_id );//The single download item page
|
93 |
+
$redirect_url = apply_filters( 'sdm_after_login_redirect_query_arg', $dl_post_url );
|
94 |
+
$login_page_url = add_query_arg( array( 'sdm_redirect_to' => urlencode( $redirect_url ) ), $main_option['general_login_page_url'] );
|
95 |
+
} else {
|
96 |
+
$login_page_url = $main_option['general_login_page_url'];
|
97 |
+
}
|
98 |
+
|
99 |
+
$tpl = __( '__Click here__ to go to login page.', 'simple-download-monitor' );
|
100 |
+
$loginMsg = preg_replace( '/__(.*)__/', ' <a href="' . $login_page_url . '">$1</a> $2', $tpl );
|
101 |
+
}
|
102 |
+
wp_die( __( 'You need to be logged in to download this file.', 'simple-download-monitor' ) . $loginMsg );
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
$visitor_name = ( $visitor_name === false ) ? __( 'Not Logged In', 'simple-download-monitor' ) : $visitor_name;
|
107 |
+
|
108 |
+
// Get option for global disabling of download logging
|
109 |
+
$no_logs = isset( $main_option['admin_no_logs'] );
|
110 |
+
|
111 |
+
// Get optoin for logging only unique IPs
|
112 |
+
$unique_ips = isset( $main_option['admin_log_unique'] );
|
113 |
+
|
114 |
+
// Get post meta for individual disabling of download logging
|
115 |
+
$get_meta = get_post_meta( $download_id, 'sdm_item_no_log', true );
|
116 |
+
$item_logging_checked = isset( $get_meta ) && $get_meta === 'on' ? 'on' : 'off';
|
117 |
+
|
118 |
+
$dl_logging_needed = true;
|
119 |
+
|
120 |
+
// Check if download logs have been disabled (globally or per download item)
|
121 |
+
if ( $no_logs === true || $item_logging_checked === 'on' ) {
|
122 |
+
$dl_logging_needed = false;
|
123 |
+
}
|
124 |
+
|
125 |
+
// Check if we are only logging unique ips
|
126 |
+
if ( $unique_ips === true ) {
|
127 |
+
$check_ip = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id="' . $download_id . '" AND visitor_ip = "' . $ipaddress . '"' );
|
128 |
+
|
129 |
+
//This IP is already logged for this download item. No need to log it again.
|
130 |
+
if ( $check_ip ) {
|
131 |
+
$dl_logging_needed = false;
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
// Check if "Do Not Count Downloads from Bots" setting is enabled
|
136 |
+
if ( isset( $main_option['admin_dont_log_bots'] ) ) {
|
137 |
+
//it is. Now let's check if visitor is a bot
|
138 |
+
if ( sdm_visitor_is_bot() ) {
|
139 |
+
//visitor is a bot. We neither log nor count this download
|
140 |
+
$dl_logging_needed = false;
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
if ( $dl_logging_needed ) {
|
145 |
+
// We need to log this download.
|
146 |
+
$table = $wpdb->prefix . 'sdm_downloads';
|
147 |
+
$data = array(
|
148 |
+
'post_id' => $download_id,
|
149 |
+
'post_title' => $download_title,
|
150 |
+
'file_url' => $download_link,
|
151 |
+
'visitor_ip' => $ipaddress,
|
152 |
+
'date_time' => $date_time,
|
153 |
+
'visitor_country' => $visitor_country,
|
154 |
+
'visitor_name' => $visitor_name,
|
155 |
+
'user_agent' => $user_agent,
|
156 |
+
'referrer_url' => $referrer_url,
|
157 |
+
);
|
158 |
+
|
159 |
+
$data = array_filter( $data ); //Remove any null values.
|
160 |
+
$insert_table = $wpdb->insert( $table, $data );
|
161 |
+
|
162 |
+
if ( $insert_table ) {
|
163 |
+
//Download request was logged successfully
|
164 |
+
} else {
|
165 |
+
//Failed to log the download request
|
166 |
+
wp_die( __( 'Error! Failed to log the download request in the database table', 'simple-download-monitor' ) );
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
// Allow plugin extensions to hook into download request.
|
171 |
+
do_action( 'sdm_process_download_request', $download_id, $download_link );
|
172 |
+
|
173 |
+
// Should the item be dispatched?
|
174 |
+
$dispatch = apply_filters( 'sdm_dispatch_downloads', get_post_meta( $download_id, 'sdm_item_dispatch', true ) );
|
175 |
+
|
176 |
+
// Only local file can be dispatched.
|
177 |
+
if ( $dispatch && ( stripos( $download_link, WP_CONTENT_URL ) === 0 ) ) {
|
178 |
+
// Get file path
|
179 |
+
$file = path_join( WP_CONTENT_DIR, ltrim( substr( $download_link, strlen( WP_CONTENT_URL ) ), '/' ) );
|
180 |
+
// Try to dispatch file (terminates script execution on success)
|
181 |
+
sdm_dispatch_file( $file );
|
182 |
+
}
|
183 |
+
|
184 |
+
// As a fallback or when dispatching is disabled, redirect to the file
|
185 |
+
// (and terminate script execution).
|
186 |
+
sdm_redirect_to_url( $download_link );
|
187 |
+
}
|
188 |
+
}
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Dispatch file with $filename and terminate script execution, if the file is
|
192 |
+
* readable and headers have not been sent yet.
|
193 |
+
*
|
194 |
+
* @param string $filename
|
195 |
+
* @return void
|
196 |
+
*/
|
197 |
+
function sdm_dispatch_file( $filename ) {
|
198 |
+
|
199 |
+
if ( headers_sent() ) {
|
200 |
+
trigger_error( __FUNCTION__ . ": Cannot dispatch file $filename, headers already sent." );
|
201 |
+
return;
|
202 |
+
}
|
203 |
+
|
204 |
+
if ( ! is_readable( $filename ) ) {
|
205 |
+
trigger_error( __FUNCTION__ . ": Cannot dispatch file $filename, file is not readable." );
|
206 |
+
return;
|
207 |
+
}
|
208 |
+
|
209 |
+
header( 'Content-Description: File Transfer' );
|
210 |
+
header( 'Content-Type: application/octet-stream' ); // http://stackoverflow.com/a/20509354
|
211 |
+
header( 'Content-Disposition: attachment; filename="' . basename( $filename ) . '"' );
|
212 |
+
header( 'Expires: 0' );
|
213 |
+
header( 'Cache-Control: must-revalidate' );
|
214 |
+
header( 'Pragma: public' );
|
215 |
+
header( 'Content-Length: ' . filesize( $filename ) );
|
216 |
+
|
217 |
+
ob_end_clean();
|
218 |
+
readfile( $filename );
|
219 |
+
exit;
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* If reCAPTCHA Enabled verify answer, send it to google API
|
224 |
+
*
|
225 |
+
* @return boolean
|
226 |
+
*/
|
227 |
+
function sdm_recaptcha_verify() {
|
228 |
+
$main_advanced_opts = get_option( 'sdm_advanced_options' );
|
229 |
+
$recaptcha_enable = isset( $main_advanced_opts['recaptcha_enable'] ) ? true : false;
|
230 |
+
if ( $recaptcha_enable ) {
|
231 |
+
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_POST['g-recaptcha-response'] ) ) {
|
232 |
+
$recaptcha_secret_key = $main_advanced_opts['recaptcha_secret_key'];
|
233 |
+
$recaptcha_response = filter_input( INPUT_POST, 'g-recaptcha-response', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
|
234 |
+
$response = wp_remote_get( "https://www.google.com/recaptcha/api/siteverify?secret={$recaptcha_secret_key}&response={$recaptcha_response}" );
|
235 |
+
$response = json_decode( $response['body'], 1 );
|
236 |
+
|
237 |
+
if ( $response['success'] ) {
|
238 |
+
return true;
|
239 |
+
} else {
|
240 |
+
wp_die( '<p><strong>' . __( 'ERROR:', 'simple-download-monitor' ) . '</strong> ' . __( 'Google reCAPTCHA verification failed.', 'simple-download-monitor' ) . "</p>\n\n<p><a href=" . wp_get_referer() . '>« ' . __( 'Back', 'simple-download-monitor' ) . '</a>', '', 403 );
|
241 |
+
return false;
|
242 |
+
}
|
243 |
+
} else {
|
244 |
+
wp_die( '<p><strong>' . __( 'ERROR:', 'simple-download-monitor' ) . '</strong> ' . __( 'Google reCAPTCHA verification failed.', 'simple-download-monitor' ) . ' ' . __( 'Do you have JavaScript enabled?', 'simple-download-monitor' ) . "</p>\n\n<p><a href=" . wp_get_referer() . '>« ' . __( 'Back', 'simple-download-monitor' ) . '</a>', '', 403 );
|
245 |
+
return false;
|
246 |
+
}
|
247 |
+
}
|
248 |
+
return true;
|
249 |
+
}
|
includes/sdm-latest-downloads.php
CHANGED
@@ -1,68 +1,73 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function sdm_show_latest_downloads($args){
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function sdm_show_latest_downloads( $args ) {
|
4 |
+
|
5 |
+
extract(
|
6 |
+
shortcode_atts(
|
7 |
+
array(
|
8 |
+
'number' => '5',
|
9 |
+
'fancy' => '0',
|
10 |
+
'button_text' => '',
|
11 |
+
'new_window' => '',
|
12 |
+
'orderby' => 'post_date',
|
13 |
+
'order' => 'DESC',
|
14 |
+
'category_slug' => '',
|
15 |
+
),
|
16 |
+
$args
|
17 |
+
)
|
18 |
+
);
|
19 |
+
|
20 |
+
$query_args = array(
|
21 |
+
'post_type' => 'sdm_downloads',
|
22 |
+
'show_posts' => -1,
|
23 |
+
'posts_per_page' => $number,
|
24 |
+
'orderby' => $orderby,
|
25 |
+
'order' => $order,
|
26 |
+
);
|
27 |
+
|
28 |
+
//Check if the query needs to be for a category
|
29 |
+
if ( ! empty( $category_slug ) ) {
|
30 |
+
$field = 'slug';
|
31 |
+
$terms = $category_slug;
|
32 |
+
|
33 |
+
//Add the category slug parameters for the query args
|
34 |
+
$query_args['tax_query'] = array(
|
35 |
+
array(
|
36 |
+
'taxonomy' => 'sdm_categories',
|
37 |
+
'field' => $field,
|
38 |
+
'terms' => $terms,
|
39 |
+
),
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
+
// Query cpt's based on arguments above
|
44 |
+
$get_posts = get_posts( $query_args );
|
45 |
+
|
46 |
+
// If no cpt's are found
|
47 |
+
if ( ! $get_posts ) {
|
48 |
+
return '<p style="color: red;">' . __( 'There are no download items matching this shortcode criteria.', 'simple-download-monitor' ) . '</p>';
|
49 |
+
}
|
50 |
+
// Else iterate cpt's
|
51 |
+
else {
|
52 |
+
|
53 |
+
$output = '';
|
54 |
+
if ( $fancy == '0' ) {
|
55 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy0/sdm-fancy-0.php';
|
56 |
+
$output .= sdm_generate_fancy0_latest_downloads_display_output( $get_posts, $args );
|
57 |
+
}
|
58 |
+
if ( $fancy == '1' ) {
|
59 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy1/sdm-fancy-1.php';
|
60 |
+
$output .= sdm_generate_fancy1_latest_downloads_display_output( $get_posts, $args );
|
61 |
+
} elseif ( $fancy == '2' ) {
|
62 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy2/sdm-fancy-2.php';
|
63 |
+
$output .= sdm_generate_fancy2_latest_downloads_display_output( $get_posts, $args );
|
64 |
+
} elseif ( $fancy == '3' ) {
|
65 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy3/sdm-fancy-3.php';
|
66 |
+
$output .= sdm_generate_fancy3_latest_downloads_display_output( $get_posts, $args );
|
67 |
+
}
|
68 |
+
|
69 |
+
// Return results
|
70 |
+
return apply_filters( 'sdm_latest_downloads_shortcode_output', $output, $args, $get_posts );
|
71 |
+
} // End else iterate cpt's
|
72 |
+
|
73 |
+
}
|
includes/sdm-logs-list-table.php
CHANGED
@@ -1,227 +1,261 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
//*****
|
4 |
-
//***** Check WP_List_Table exists
|
5 |
-
if (!class_exists('WP_List_Table')) {
|
6 |
-
|
7 |
-
}
|
8 |
-
|
9 |
-
//*****
|
10 |
-
//***** Define our new Table
|
11 |
-
class sdm_List_Table extends WP_List_Table {
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
//*****
|
4 |
+
//***** Check WP_List_Table exists
|
5 |
+
if ( ! class_exists( 'WP_List_Table' ) ) {
|
6 |
+
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
7 |
+
}
|
8 |
+
|
9 |
+
//*****
|
10 |
+
//***** Define our new Table
|
11 |
+
class sdm_List_Table extends WP_List_Table {
|
12 |
+
|
13 |
+
function __construct() {
|
14 |
+
|
15 |
+
global $status, $page;
|
16 |
+
|
17 |
+
//Set parent defaults
|
18 |
+
parent::__construct(
|
19 |
+
array(
|
20 |
+
'singular' => __( 'Download', 'simple-download-monitor' ), //singular name of the listed records
|
21 |
+
'plural' => __( 'Downloads', 'simple-download-monitor' ), //plural name of the listed records
|
22 |
+
'ajax' => false, //does this table support ajax?
|
23 |
+
)
|
24 |
+
);
|
25 |
+
}
|
26 |
+
|
27 |
+
function column_default( $item, $column_name ) {
|
28 |
+
|
29 |
+
switch ( $column_name ) {
|
30 |
+
case 'URL':
|
31 |
+
case 'visitor_ip':
|
32 |
+
case 'date':
|
33 |
+
return $item[ $column_name ];
|
34 |
+
case 'visitor_country':
|
35 |
+
return $item[ $column_name ];
|
36 |
+
case 'visitor_name':
|
37 |
+
return $item[ $column_name ];
|
38 |
+
case 'user_agent':
|
39 |
+
return $item[ $column_name ];
|
40 |
+
case 'referrer_url':
|
41 |
+
return $item[ $column_name ];
|
42 |
+
default:
|
43 |
+
return print_r( $item, true ); //Show the whole array for troubleshooting purposes
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
function column_title( $item ) {
|
48 |
+
$delete_log_nonce = wp_create_nonce( 'sdm_delete_log_entry' );
|
49 |
+
//Build row actions
|
50 |
+
$actions = array(
|
51 |
+
'edit' => sprintf( '<a href="' . admin_url( 'post.php?post=' . $item['ID'] . '&action=edit' ) . '">' . __( 'Edit', 'simple-download-monitor' ) . '</a>' ),
|
52 |
+
'delete' => sprintf( '<a href="?post_type=sdm_downloads&page=sdm-logs&action=%s&download=%s&row_id=%s&_wpnonce=%s" onclick="return confirm(\'Are you sure you want to delete this entry?\')">' . __( 'Delete', 'simple-download-monitor' ) . '</a>', 'delete', $item['ID'], $item['row_id'], $delete_log_nonce ),
|
53 |
+
);
|
54 |
+
|
55 |
+
//Return the title contents
|
56 |
+
return sprintf(
|
57 |
+
'%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
|
58 |
+
/* $1%s */ $item['title'],
|
59 |
+
/* $2%s */ $item['ID'],
|
60 |
+
/* $3%s */ $this->row_actions( $actions )
|
61 |
+
);
|
62 |
+
}
|
63 |
+
|
64 |
+
function column_cb( $item ) {
|
65 |
+
|
66 |
+
return sprintf(
|
67 |
+
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
|
68 |
+
/* $1%s */ $this->_args['singular'], //Let's simply repurpose the table's singular label ("Download")
|
69 |
+
/* $2%s */ $item['row_id'] //The value of the checkbox should be the record's id
|
70 |
+
);
|
71 |
+
}
|
72 |
+
|
73 |
+
function get_columns() {
|
74 |
+
|
75 |
+
$columns = array(
|
76 |
+
'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
|
77 |
+
'title' => __( 'Title', 'simple-download-monitor' ),
|
78 |
+
'URL' => __( 'File', 'simple-download-monitor' ),
|
79 |
+
'visitor_ip' => __( 'Visitor IP', 'simple-download-monitor' ),
|
80 |
+
'date' => __( 'Date', 'simple-download-monitor' ),
|
81 |
+
'visitor_country' => __( 'Country', 'simple-download-monitor' ),
|
82 |
+
'visitor_name' => __( 'Username', 'simple-download-monitor' ),
|
83 |
+
'user_agent' => __( 'User Agent', 'simple-download-monitor' ),
|
84 |
+
'referrer_url' => __( 'Referrer URL', 'simple-download-monitor' ),
|
85 |
+
);
|
86 |
+
return $columns;
|
87 |
+
}
|
88 |
+
|
89 |
+
function get_sortable_columns() {
|
90 |
+
|
91 |
+
$sortable_columns = array(
|
92 |
+
'title' => array( 'post_title', false ), //true means it's already sorted
|
93 |
+
'URL' => array( 'file_url', false ),
|
94 |
+
'visitor_ip' => array( 'visitor_ip', false ),
|
95 |
+
'date' => array( 'date_time', false ),
|
96 |
+
'visitor_country' => array( 'visitor_country', false ),
|
97 |
+
'visitor_name' => array( 'visitor_name', false ),
|
98 |
+
'user_agent' => array( 'user_agent', false ),
|
99 |
+
);
|
100 |
+
return $sortable_columns;
|
101 |
+
}
|
102 |
+
|
103 |
+
function get_bulk_actions() {
|
104 |
+
|
105 |
+
$actions = array();
|
106 |
+
$actions['delete2'] = __( 'Delete Permanently', 'simple-download-monitor' );
|
107 |
+
|
108 |
+
return $actions;
|
109 |
+
}
|
110 |
+
|
111 |
+
function process_bulk_action() {
|
112 |
+
|
113 |
+
// if bulk 'Delete Permanently' was clicked
|
114 |
+
if ( 'delete2' === $this->current_action() ) {
|
115 |
+
|
116 |
+
//Check bulk delete nonce
|
117 |
+
$nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
|
118 |
+
$action = 'bulk-' . $this->_args['plural'];
|
119 |
+
|
120 |
+
if ( ! wp_verify_nonce( $nonce, $action ) ) {
|
121 |
+
wp_die( __( 'Nope! Security check failed!', 'simple-download-monitor' ) );
|
122 |
+
}
|
123 |
+
|
124 |
+
if ( ! isset( $_POST['download'] ) || $_POST['download'] == null ) {
|
125 |
+
echo '<div id="message" class="updated fade"><p><strong>' . __( 'No entries were selected.', 'simple-download-monitor' ) . '</strong></p><p><em>' . __( 'Click to Dismiss', 'simple-download-monitor' ) . '</em></p></div>';
|
126 |
+
return;
|
127 |
+
}
|
128 |
+
|
129 |
+
foreach ( $_POST['download'] as $item ) {
|
130 |
+
$row_id = sanitize_text_field( $item );
|
131 |
+
if ( ! is_numeric( $row_id ) ) {
|
132 |
+
wp_die( __( 'Error! The row id value of a log entry must be numeric.', 'simple-download-monitor' ) );
|
133 |
+
}
|
134 |
+
|
135 |
+
global $wpdb;
|
136 |
+
$del_row = $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'sdm_downloads WHERE id = "' . $row_id . '"' );
|
137 |
+
}
|
138 |
+
if ( $del_row ) {
|
139 |
+
echo '<div id="message" class="updated fade"><p><strong>' . __( 'Entries Deleted!', 'simple-download-monitor' ) . '</strong></p><p><em>' . __( 'Click to Dismiss', 'simple-download-monitor' ) . '</em></p></div>';
|
140 |
+
} else {
|
141 |
+
echo '<div id="message" class="updated fade"><p><strong>' . __( 'Error', 'simple-download-monitor' ) . '</strong></p><p><em>' . __( 'Click to Dismiss', 'simple-download-monitor' ) . '</em></p></div>';
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
// If single entry 'Delete' was clicked
|
146 |
+
if ( 'delete' === $this->current_action() ) {
|
147 |
+
|
148 |
+
//Check bulk delete nonce
|
149 |
+
$nonce = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING );
|
150 |
+
$action = 'sdm_delete_log_entry';
|
151 |
+
if ( ! wp_verify_nonce( $nonce, $action ) ) {
|
152 |
+
wp_die( __( 'Nope! Security check failed!', 'simple-download-monitor' ) );
|
153 |
+
}
|
154 |
+
|
155 |
+
//Grab the row id
|
156 |
+
$row_id = filter_input( INPUT_GET, 'row_id', FILTER_SANITIZE_STRING );
|
157 |
+
|
158 |
+
global $wpdb;
|
159 |
+
$del_row = $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'sdm_downloads WHERE id = "' . $row_id . '"' );
|
160 |
+
if ( $del_row ) {
|
161 |
+
echo '<div id="message" class="updated fade"><p><strong>' . __( 'Entry Deleted!', 'simple-download-monitor' ) . '</strong></p><p><em>' . __( 'Click to Dismiss', 'simple-download-monitor' ) . '</em></p></div>';
|
162 |
+
} else {
|
163 |
+
echo '<div id="message" class="updated fade"><p><strong>' . __( 'Error', 'simple-download-monitor' ) . '</strong></p><p><em>' . __( 'Click to Dismiss', 'simple-download-monitor' ) . '</em></p></div>';
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
function prepare_items() {
|
169 |
+
|
170 |
+
global $wpdb; //This is used only if making any database queries
|
171 |
+
$per_page = apply_filters( 'sdm_download_logs_menu_items_per_page', 50 );
|
172 |
+
$columns = $this->get_columns();
|
173 |
+
$hidden = array();
|
174 |
+
$sortable = $this->get_sortable_columns();
|
175 |
+
$current_page = $this->get_pagenum();
|
176 |
+
|
177 |
+
$this->_column_headers = array( $columns, $hidden, $sortable );
|
178 |
+
$this->process_bulk_action();
|
179 |
+
|
180 |
+
// Grab the sort inputs then sanitize the values before using it in the query. Use a whitelist approach to sanitize it.
|
181 |
+
$orderby_column = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : '';
|
182 |
+
$sort_order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : '';
|
183 |
+
if ( empty( $orderby_column ) ) {
|
184 |
+
$orderby_column = 'date_time';
|
185 |
+
$sort_order = 'DESC';
|
186 |
+
}
|
187 |
+
$orderby_column = sdm_sanitize_value_by_array(
|
188 |
+
$orderby_column,
|
189 |
+
array(
|
190 |
+
'post_title' => '1',
|
191 |
+
'file_url' => '1',
|
192 |
+
'visitor_ip' => '1',
|
193 |
+
'date_time' => '1',
|
194 |
+
'visitor_country' => '1',
|
195 |
+
'visitor_name' => '1',
|
196 |
+
'user_agent' => '1',
|
197 |
+
'referrer_url' => '1',
|
198 |
+
)
|
199 |
+
);
|
200 |
+
$sort_order = sdm_sanitize_value_by_array(
|
201 |
+
$sort_order,
|
202 |
+
array(
|
203 |
+
'DESC' => '1',
|
204 |
+
'ASC' => '1',
|
205 |
+
)
|
206 |
+
);
|
207 |
+
|
208 |
+
//Do a query to find the total number of rows then calculate the query limit
|
209 |
+
$table_name = $wpdb->prefix . 'sdm_downloads';
|
210 |
+
|
211 |
+
if ( isset( $_REQUEST['sdm_logs_dl_id'] ) && ! empty( $_REQUEST['sdm_logs_dl_id'] ) ) {
|
212 |
+
//For specific download logs
|
213 |
+
$dl_id = sanitize_text_field( $_REQUEST['sdm_logs_dl_id'] );
|
214 |
+
$dl_id = intval( $dl_id );
|
215 |
+
|
216 |
+
$query = "SELECT COUNT(*) FROM $table_name WHERE post_id = $dl_id";
|
217 |
+
$total_items = $wpdb->get_var( $query );//For pagination requirement
|
218 |
+
$query = "SELECT * FROM $table_name WHERE post_id = $dl_id ORDER BY $orderby_column $sort_order";
|
219 |
+
} else {
|
220 |
+
//For all download logs
|
221 |
+
$query = "SELECT COUNT(*) FROM $table_name";
|
222 |
+
$total_items = $wpdb->get_var( $query );//For pagination requirement
|
223 |
+
|
224 |
+
$query = "SELECT * FROM $table_name ORDER BY $orderby_column $sort_order";
|
225 |
+
}
|
226 |
+
|
227 |
+
$offset = ( $current_page - 1 ) * $per_page;
|
228 |
+
$query .= ' LIMIT ' . (int) $offset . ',' . (int) $per_page;//Limit to query to only load a limited number of records
|
229 |
+
|
230 |
+
$data_results = $wpdb->get_results( $query );
|
231 |
+
|
232 |
+
//Prepare the array with the correct index names that the table is expecting.
|
233 |
+
$data = array();
|
234 |
+
foreach ( $data_results as $data_result ) {
|
235 |
+
$data[] = array(
|
236 |
+
'row_id' => $data_result->id,
|
237 |
+
'ID' => $data_result->post_id,
|
238 |
+
'title' => $data_result->post_title,
|
239 |
+
'URL' => $data_result->file_url,
|
240 |
+
'visitor_ip' => $data_result->visitor_ip,
|
241 |
+
'date' => $data_result->date_time,
|
242 |
+
'visitor_country' => $data_result->visitor_country,
|
243 |
+
'visitor_name' => $data_result->visitor_name,
|
244 |
+
'user_agent' => $data_result->user_agent,
|
245 |
+
'referrer_url' => $data_result->referrer_url,
|
246 |
+
);
|
247 |
+
}
|
248 |
+
|
249 |
+
// Now we add our *sorted* data to the items property, where it can be used by the rest of the class.
|
250 |
+
$this->items = $data;
|
251 |
+
|
252 |
+
$this->set_pagination_args(
|
253 |
+
array(
|
254 |
+
'total_items' => $total_items, //WE have to calculate the total number of items
|
255 |
+
'per_page' => $per_page, //WE have to determine how many items to show on a page
|
256 |
+
'total_pages' => ceil( $total_items / $per_page ), //WE have to calculate the total number of pages
|
257 |
+
)
|
258 |
+
);
|
259 |
+
}
|
260 |
+
|
261 |
+
}
|
includes/sdm-popular-downloads.php
CHANGED
@@ -2,65 +2,70 @@
|
|
2 |
|
3 |
function sdm_show_popular_downloads( $args ) {
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
$get_posts = $wpdb->get_results( $q );
|
40 |
|
41 |
-
|
42 |
-
if ( ! $get_posts ) {
|
43 |
-
return '<p style="color: red;">' . __( 'There are no download items matching this shortcode criteria.', 'simple-download-monitor' ) . '</p>';
|
44 |
-
}
|
45 |
-
// Else iterate cpt's
|
46 |
-
else {
|
47 |
|
48 |
-
|
49 |
-
if ( $
|
50 |
-
|
51 |
-
$output .= sdm_generate_fancy0_popular_downloads_display_output( $get_posts, $args );
|
52 |
-
} else if ( $fancy == '1' ) {
|
53 |
-
include_once(WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy1/sdm-fancy-1.php');
|
54 |
-
$output .= sdm_generate_fancy1_popular_downloads_display_output( $get_posts, $args );
|
55 |
-
} else if ( $fancy == '2' ) {
|
56 |
-
include_once(WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy2/sdm-fancy-2.php');
|
57 |
-
$output .= sdm_generate_fancy2_popular_downloads_display_output( $get_posts, $args );
|
58 |
-
} else if ( $fancy == '3' ) {
|
59 |
-
include_once(WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy3/sdm-fancy-3.php');
|
60 |
-
$output .= sdm_generate_fancy3_popular_downloads_display_output( $get_posts, $args );
|
61 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
}
|
2 |
|
3 |
function sdm_show_popular_downloads( $args ) {
|
4 |
|
5 |
+
extract(
|
6 |
+
shortcode_atts(
|
7 |
+
array(
|
8 |
+
'number' => '5',
|
9 |
+
'fancy' => '0',
|
10 |
+
'button_text' => '',
|
11 |
+
'new_window' => '',
|
12 |
+
'orderby' => 'post_date',
|
13 |
+
'order' => 'DESC',
|
14 |
+
'category_slug' => '',
|
15 |
+
),
|
16 |
+
$args
|
17 |
+
)
|
18 |
+
);
|
19 |
|
20 |
+
global $wpdb;
|
21 |
+
//Check if the query needs to be for a category
|
22 |
+
if ( ! empty( $category_slug ) ) {
|
23 |
+
$q = 'SELECT posts.*, downloads.id, downloads.post_id, terms.*, termrel.*, postmeta.*, (COUNT(downloads.post_id) + postmeta.meta_value) AS cnt'
|
24 |
+
. ' FROM ' . $wpdb->prefix . 'posts as posts, ' . $wpdb->prefix . 'sdm_downloads as downloads, ' . $wpdb->prefix . 'terms as terms, ' . $wpdb->prefix . 'term_relationships as termrel, ' . $wpdb->prefix . 'postmeta as postmeta WHERE'
|
25 |
+
. ' posts.id=downloads.post_id'
|
26 |
+
. " AND (postmeta.meta_key='sdm_count_offset' AND postmeta.post_id=downloads.post_id)"
|
27 |
+
. ' AND (terms.slug= %s AND termrel.object_id=downloads.post_id AND termrel.term_taxonomy_id=terms.term_id)'
|
28 |
+
. ' GROUP BY downloads.post_id'
|
29 |
+
. ' ORDER BY cnt DESC, %s %s'
|
30 |
+
. ' LIMIT %d;';
|
31 |
+
$q = $wpdb->prepare( $q, $category_slug, $orderby, $order, $number );
|
32 |
+
} else {
|
33 |
+
//no categury_slug present
|
34 |
+
$q = 'SELECT posts.*, downloads.id, downloads.post_id, postmeta.*, (COUNT(downloads.post_id) + postmeta.meta_value) AS cnt'
|
35 |
+
. ' FROM ' . $wpdb->prefix . 'posts as posts, ' . $wpdb->prefix . 'sdm_downloads as downloads, ' . $wpdb->prefix . 'postmeta as postmeta WHERE'
|
36 |
+
. ' posts.id=downloads.post_id'
|
37 |
+
. " AND (postmeta.meta_key='sdm_count_offset' AND postmeta.post_id=downloads.post_id)"
|
38 |
+
. ' GROUP BY downloads.post_id'
|
39 |
+
. ' ORDER BY cnt DESC, %s %s'
|
40 |
+
. ' LIMIT %d;';
|
41 |
+
$q = $wpdb->prepare( $q, $orderby, $order, $number );
|
42 |
+
}
|
|
|
|
|
43 |
|
44 |
+
$get_posts = $wpdb->get_results( $q );
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
// If no cpt's are found
|
47 |
+
if ( ! $get_posts ) {
|
48 |
+
return '<p style="color: red;">' . __( 'There are no download items matching this shortcode criteria.', 'simple-download-monitor' ) . '</p>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
}
|
50 |
+
// Else iterate cpt's
|
51 |
+
else {
|
52 |
+
|
53 |
+
$output = '';
|
54 |
+
if ( $fancy == '0' ) {
|
55 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy0/sdm-fancy-0.php';
|
56 |
+
$output .= sdm_generate_fancy0_popular_downloads_display_output( $get_posts, $args );
|
57 |
+
} elseif ( $fancy == '1' ) {
|
58 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy1/sdm-fancy-1.php';
|
59 |
+
$output .= sdm_generate_fancy1_popular_downloads_display_output( $get_posts, $args );
|
60 |
+
} elseif ( $fancy == '2' ) {
|
61 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy2/sdm-fancy-2.php';
|
62 |
+
$output .= sdm_generate_fancy2_popular_downloads_display_output( $get_posts, $args );
|
63 |
+
} elseif ( $fancy == '3' ) {
|
64 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy3/sdm-fancy-3.php';
|
65 |
+
$output .= sdm_generate_fancy3_popular_downloads_display_output( $get_posts, $args );
|
66 |
+
}
|
67 |
|
68 |
+
// Return results
|
69 |
+
return apply_filters( 'sdm_popular_downloads_shortcode_output', $output, $args, $get_posts );
|
70 |
+
} // End else iterate cpt's
|
71 |
}
|
includes/sdm-search-shortcode-handler.php
CHANGED
@@ -1,114 +1,115 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function sdm_search_form_shortcode($args) {
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
AND $wpdb->posts.
|
37 |
-
AND
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function sdm_search_form_shortcode( $args ) {
|
4 |
+
$atts = shortcode_atts(
|
5 |
+
array(
|
6 |
+
'fancy' => '',
|
7 |
+
'class' => '', // wrapper class
|
8 |
+
'placeholder' => 'Search...', // placeholder for search input
|
9 |
+
'description_max_length' => 50, // short description symbols count
|
10 |
+
),
|
11 |
+
$args
|
12 |
+
);
|
13 |
+
|
14 |
+
global $wpdb;
|
15 |
+
|
16 |
+
// Check if we have a search value posted
|
17 |
+
$s_term = isset( $_POST['sdm_search_term'] ) ? stripslashes( sanitize_text_field( esc_html( $_POST['sdm_search_term'] ) ) ) : '';
|
18 |
+
|
19 |
+
if ( ! empty( $s_term ) ) {
|
20 |
+
// we got search term posted
|
21 |
+
$keywords_searched = array();
|
22 |
+
$posts_collection = array();
|
23 |
+
$parts = explode( ' ', $s_term );
|
24 |
+
foreach ( $parts as $keyword ) {
|
25 |
+
if ( strlen( $keyword ) < 3 ) {
|
26 |
+
//Ignore keywords less than 3 characters long
|
27 |
+
continue;
|
28 |
+
}
|
29 |
+
|
30 |
+
$keywords_searched[] = $keyword;
|
31 |
+
|
32 |
+
$querystr = "
|
33 |
+
SELECT $wpdb->posts.*, $wpdb->postmeta.meta_value as description
|
34 |
+
FROM $wpdb->posts, $wpdb->postmeta
|
35 |
+
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
|
36 |
+
AND $wpdb->posts.post_status = 'publish'
|
37 |
+
AND $wpdb->posts.post_type = 'sdm_downloads'
|
38 |
+
AND ($wpdb->posts.post_title LIKE '%$keyword%'
|
39 |
+
OR ($wpdb->postmeta.meta_key='sdm_description' AND $wpdb->postmeta.meta_value LIKE '%$keyword%') )
|
40 |
+
GROUP BY $wpdb->posts.ID
|
41 |
+
";
|
42 |
+
$query_result = $wpdb->get_results( $querystr, OBJECT );
|
43 |
+
|
44 |
+
//Merge the results of this keyword with the collection array. Also remove any duplicate.
|
45 |
+
$posts_collection = array_merge( $posts_collection, $query_result );
|
46 |
+
//$posts_collection = array_unique(array_merge($posts_collection, $query_result), SORT_REGULAR);
|
47 |
+
}
|
48 |
+
|
49 |
+
//Lets get rid of any duplicates
|
50 |
+
$unique_posts_collection_id = array();
|
51 |
+
foreach ( $posts_collection as $key => $post ) {
|
52 |
+
if ( in_array( $post->ID, $unique_posts_collection_id ) ) {
|
53 |
+
//This is a duplicate.
|
54 |
+
unset( $posts_collection[ $key ] );//Delete this entry from the collection.
|
55 |
+
} else {
|
56 |
+
//This post ID is not in the collection yet. Add it.
|
57 |
+
$unique_posts_collection_id[] = $post->ID;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
//Create the result entries output using a template.
|
62 |
+
$s_results = sdm_generate_search_result_using_template( $posts_collection, $atts );
|
63 |
+
|
64 |
+
//Show the search result
|
65 |
+
if ( ! empty( $s_results ) ) {
|
66 |
+
$result_output = '<h2 class="sdm_search_result_heading">' . __( 'Showing search results for ', 'simple-download-monitor' ) . '"' . $s_term . '"</h2>';
|
67 |
+
$result_output .= '<div class="sdm_search_result_number_of_items">' . __( 'Number of items found: ', 'simple-download-monitor' ) . count( $posts_collection ) . '</div>';
|
68 |
+
$result_output .= '<div class="sdm_search_result_keywords">' . __( 'Keywords searched: ', 'simple-download-monitor' ) . implode( ', ', $keywords_searched ) . '</div>';
|
69 |
+
$result_output .= '<div class="sdm_search_result_listing">' . $s_results . '</div>';
|
70 |
+
} else {
|
71 |
+
$result_output = '<h2 class="sdm_search_result_heading">' . __( 'Nothing found for ', 'simple-download-monitor' ) . '"' . $s_term . '".</h2>';
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
$out = '';
|
76 |
+
$out .= '<form id="sdm_search_form" class="' . ( empty( $atts['class'] ) ? '' : ' ' . $atts['class'] ) . '" method="POST">';
|
77 |
+
$out .= '<input type="search" class="search-field" name="sdm_search_term" value="' . $s_term . '" placeholder="' . $atts['placeholder'] . '">';
|
78 |
+
$out .= '<input type="submit" class="sdm_search_submit" name="sdm_search_submit" value="Search">';
|
79 |
+
$out .= '</form>';
|
80 |
+
$out .= isset( $result_output ) ? $result_output : '';
|
81 |
+
|
82 |
+
return $out;
|
83 |
+
}
|
84 |
+
|
85 |
+
function sdm_generate_search_result_using_template( $posts_collection, $args = array() ) {
|
86 |
+
$s_results = '';
|
87 |
+
|
88 |
+
if ( isset( $args['fancy'] ) && ! empty( $args['fancy'] ) ) {
|
89 |
+
if ( $args['fancy'] == '1' ) {
|
90 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy1/sdm-fancy-1.php';
|
91 |
+
$s_results .= sdm_generate_fancy1_category_display_output( $posts_collection, $args );
|
92 |
+
} elseif ( $args['fancy'] == '2' ) {
|
93 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy2/sdm-fancy-2.php';
|
94 |
+
$s_results .= sdm_generate_fancy2_category_display_output( $posts_collection, $args );
|
95 |
+
} elseif ( $args['fancy'] == '3' ) {
|
96 |
+
include_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/templates/fancy3/sdm-fancy-3.php';
|
97 |
+
$s_results .= sdm_generate_fancy3_category_display_output( $posts_collection, $args );
|
98 |
+
}
|
99 |
+
} else {
|
100 |
+
//No fancy template is used. Show the search result using the standard search display
|
101 |
+
foreach ( $posts_collection as $post ) {
|
102 |
+
$meta = get_post_meta( $post->ID );
|
103 |
+
$s_results .= '<div class="sdm_search_result_item">';
|
104 |
+
$s_results .= '<h4><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h4>';
|
105 |
+
$descr = strip_shortcodes( $meta['sdm_description'][0] );
|
106 |
+
if ( strlen( $descr ) > $args['description_max_length'] ) {
|
107 |
+
$descr = substr( $descr, 0, $args['description_max_length'] ) . '[...]';
|
108 |
+
}
|
109 |
+
$s_results .= '<span>' . $descr . '</span>';
|
110 |
+
$s_results .= '</div>';
|
111 |
+
}
|
112 |
+
}
|
113 |
+
|
114 |
+
return $s_results;
|
115 |
+
}
|
includes/sdm-user-login-related.php
CHANGED
@@ -1,36 +1,36 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Handles the after login redirect if standard
|
5 |
-
*/
|
6 |
-
function sdm_after_wp_user_login_redirect( $redirect_to, $request, $user ) {
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
}
|
16 |
-
add_filter( 'login_redirect', 'sdm_after_wp_user_login_redirect', 10, 3 );
|
17 |
-
|
18 |
-
/*
|
19 |
-
* Handles the redirect in some other situation (example: a plugin is being used for user management/membership system).
|
20 |
-
*/
|
21 |
-
function sdm_check_redirect_query_and_settings(){
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Handles the after login redirect if standard WordPress's user login is being used with this feature.
|
5 |
+
*/
|
6 |
+
function sdm_after_wp_user_login_redirect( $redirect_to, $request, $user ) {
|
7 |
+
if ( isset( $_REQUEST['sdm_redirect_to'] ) && ! empty( $_REQUEST['sdm_redirect_to'] ) ) {
|
8 |
+
//Check if the "redirect_user_back_to_download_page" feature is enabled on this site.
|
9 |
+
$main_option = get_option( 'sdm_downloads_options' );
|
10 |
+
if ( isset( $main_option['redirect_user_back_to_download_page'] ) ) {
|
11 |
+
$redirect_to = urldecode( $_REQUEST['sdm_redirect_to'] );
|
12 |
+
}
|
13 |
+
}
|
14 |
+
return $redirect_to;
|
15 |
+
}
|
16 |
+
add_filter( 'login_redirect', 'sdm_after_wp_user_login_redirect', 10, 3 );
|
17 |
+
|
18 |
+
/*
|
19 |
+
* Handles the redirect in some other situation (example: a plugin is being used for user management/membership system).
|
20 |
+
*/
|
21 |
+
function sdm_check_redirect_query_and_settings() {
|
22 |
+
|
23 |
+
if ( isset( $_REQUEST['sdm_redirect_to'] ) && ! empty( $_REQUEST['sdm_redirect_to'] ) ) {
|
24 |
+
//Check if the "redirect_user_back_to_download_page" feature is enabled on this site.
|
25 |
+
$main_option = get_option( 'sdm_downloads_options' );
|
26 |
+
if ( isset( $main_option['redirect_user_back_to_download_page'] ) ) {
|
27 |
+
//Check if the user is logged-in (since we only want to redirect a logged-in user.
|
28 |
+
$visitor_name = sdm_get_logged_in_user();
|
29 |
+
if ( $visitor_name !== false ) {
|
30 |
+
$redirect_url = urldecode( $_REQUEST['sdm_redirect_to'] );
|
31 |
+
wp_safe_redirect( $redirect_url );//user wp safe redirect.
|
32 |
+
exit;
|
33 |
+
}
|
34 |
+
}
|
35 |
+
}
|
36 |
+
}
|
includes/sdm-utility-functions-admin-side.php
CHANGED
@@ -1,253 +1,270 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function sdm_export_download_logs_to_csv($start_date, $end_date) {
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function sdm_export_download_logs_to_csv( $start_date, $end_date ) {
|
4 |
+
//appending time to start and end date
|
5 |
+
$start_date_time = $start_date . ' 00:00:00';
|
6 |
+
$end_date_time = $end_date . ' 23:59:59';
|
7 |
+
|
8 |
+
global $wpdb;
|
9 |
+
$table_name = $wpdb->prefix . 'sdm_downloads';
|
10 |
+
$resultset_query = $wpdb->prepare( "SELECT * FROM $table_name WHERE date_time BETWEEN %s AND %s ORDER BY id DESC", $start_date_time, $end_date_time );
|
11 |
+
$resultset = $wpdb->get_results( $resultset_query, OBJECT );
|
12 |
+
|
13 |
+
$csv_file_name = sprintf( 'sdm-download-logs-%s_%s.csv', $start_date, $end_date );
|
14 |
+
header( 'Content-Type: text/csv' );
|
15 |
+
header( 'Content-Disposition: attachment; filename="' . $csv_file_name . '"' );
|
16 |
+
header( 'Pragma: no-cache' );
|
17 |
+
header( 'Expires: 0' );
|
18 |
+
|
19 |
+
$fp = fopen( 'php://output', 'w' );
|
20 |
+
|
21 |
+
$header_names = array( 'Log ID', 'Download ID', 'Download Title', 'File URL', 'Date', 'IP Address', 'Country', 'Name' );
|
22 |
+
fputcsv( $fp, $header_names );
|
23 |
+
|
24 |
+
foreach ( $resultset as $result ) {
|
25 |
+
if ( empty( $result->purchase_qty ) ) {
|
26 |
+
$result->purchase_qty = 1;
|
27 |
+
}
|
28 |
+
|
29 |
+
$fields = array( $result->id, $result->post_id, $result->post_title, $result->file_url, $result->date_time, $result->visitor_ip, $result->visitor_country, $result->visitor_name, $result->user_agent );
|
30 |
+
fputcsv( $fp, $fields );
|
31 |
+
}
|
32 |
+
|
33 |
+
exit();
|
34 |
+
}
|
35 |
+
|
36 |
+
function sdm_get_downloads_by_date( $start_date = '', $end_date = '', $returnStr = true ) {
|
37 |
+
global $wpdb;
|
38 |
+
|
39 |
+
$q = $wpdb->prepare(
|
40 |
+
"SELECT COUNT(id) as cnt, DATE_FORMAT(`date_time`,'%%Y-%%m-%%d') as day
|
41 |
+
FROM " . $wpdb->prefix . "sdm_downloads
|
42 |
+
WHERE DATE_FORMAT(`date_time`,'%%Y-%%m-%%d')>=%s
|
43 |
+
AND DATE_FORMAT(`date_time`,'%%Y-%%m-%%d')<=%s
|
44 |
+
GROUP BY DAY(date_time) ORDER BY date_time",
|
45 |
+
$start_date,
|
46 |
+
$end_date
|
47 |
+
);
|
48 |
+
|
49 |
+
$res = $wpdb->get_results( $q, ARRAY_A );
|
50 |
+
if ( $returnStr ) {
|
51 |
+
$downloads_by_date_str = '';
|
52 |
+
foreach ( $res as $item ) {
|
53 |
+
$downloads_by_date_str .= '["' . $item['day'] . '", ' . $item['cnt'] . '],';
|
54 |
+
}
|
55 |
+
return $downloads_by_date_str;
|
56 |
+
} else {
|
57 |
+
return $res;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
function sdm_get_downloads_by_country( $start_date = '', $end_date = '', $returnStr = true ) {
|
62 |
+
global $wpdb;
|
63 |
+
|
64 |
+
$q = $wpdb->prepare(
|
65 |
+
'SELECT COUNT(id) as cnt, visitor_country as country
|
66 |
+
FROM ' . $wpdb->prefix . "sdm_downloads
|
67 |
+
WHERE DATE_FORMAT(`date_time`,'%%Y-%%m-%%d')>=%s
|
68 |
+
AND DATE_FORMAT(`date_time`,'%%Y-%%m-%%d')<=%s
|
69 |
+
GROUP BY visitor_country",
|
70 |
+
$start_date,
|
71 |
+
$end_date
|
72 |
+
);
|
73 |
+
$res = $wpdb->get_results( $q, ARRAY_A );
|
74 |
+
|
75 |
+
if ( $returnStr ) {
|
76 |
+
$downloads_by_country_str = "['Country', 'Downloads'],";
|
77 |
+
foreach ( $res as $item ) {
|
78 |
+
$downloads_by_country_str .= '["' . $item['country'] . '", ' . $item['cnt'] . '],';
|
79 |
+
}
|
80 |
+
return $downloads_by_country_str;
|
81 |
+
} else {
|
82 |
+
return $res;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Retrieves all user agent fields form downloads
|
88 |
+
*
|
89 |
+
* @param string $start_date
|
90 |
+
* @param string $end_date
|
91 |
+
*
|
92 |
+
* @return array
|
93 |
+
*/
|
94 |
+
function sdm_get_all_download_user_agent( $start_date = '', $end_date = '' ) {
|
95 |
+
global $wpdb;
|
96 |
+
|
97 |
+
$q = $wpdb->prepare(
|
98 |
+
'SELECT user_agent
|
99 |
+
FROM ' . $wpdb->prefix . "sdm_downloads
|
100 |
+
WHERE DATE_FORMAT(`date_time`,'%%Y-%%m-%%d')>=%s
|
101 |
+
AND DATE_FORMAT(`date_time`,'%%Y-%%m-%%d')<=%s",
|
102 |
+
$start_date,
|
103 |
+
$end_date
|
104 |
+
);
|
105 |
+
|
106 |
+
return $wpdb->get_results( $q, ARRAY_A );
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Processes all user agent to browser
|
111 |
+
*
|
112 |
+
* @param string $start_date
|
113 |
+
* @param string $end_date
|
114 |
+
*
|
115 |
+
* @return array
|
116 |
+
*/
|
117 |
+
|
118 |
+
function sdm_get_all_downloads_by_browser( $start_date = '', $end_date = '' ) {
|
119 |
+
$user_agents = sdm_get_all_download_user_agent( $start_date, $end_date );
|
120 |
+
|
121 |
+
$browsers = array();
|
122 |
+
foreach ( $user_agents as $agent ) {
|
123 |
+
$browserArray = array(
|
124 |
+
'Microsoft Edge' => 'Edg',
|
125 |
+
'Opera' => '(OPR)|(OPX)',
|
126 |
+
'Vivaldi' => 'Vivaldi',
|
127 |
+
'Firefox' => 'Firefox',
|
128 |
+
'Samsung Browser' => 'SamsungBrowser',
|
129 |
+
'Chrome' => 'Chrome',
|
130 |
+
'Internet Explorer' => 'MSIE',
|
131 |
+
'Safari' => 'Safari',
|
132 |
+
);
|
133 |
+
$browser = 'Other';
|
134 |
+
foreach ( $browserArray as $k => $v ) {
|
135 |
+
if ( preg_match( "/$v/", $agent['user_agent'] ) ) {
|
136 |
+
$browser = $k;
|
137 |
+
break;
|
138 |
+
}
|
139 |
+
}
|
140 |
+
if ( isset( $browsers[ $browser ] ) ) {
|
141 |
+
$browsers[ $browser ] += 1;
|
142 |
+
} else {
|
143 |
+
$browsers[ $browser ] = 1;
|
144 |
+
}
|
145 |
+
}
|
146 |
+
return moveArrayElementToEnd( $browsers, 'Other' );
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Processes all user agent to operating system
|
151 |
+
*
|
152 |
+
* @param string $start_date
|
153 |
+
* @param string $end_date
|
154 |
+
*
|
155 |
+
* @return array
|
156 |
+
*/
|
157 |
+
|
158 |
+
function sdm_get_all_downloads_by_os( $start_date = '', $end_date = '' ) {
|
159 |
+
$user_agents = sdm_get_all_download_user_agent( $start_date, $end_date );
|
160 |
+
|
161 |
+
$operating_systems = array();
|
162 |
+
foreach ( $user_agents as $agent ) {
|
163 |
+
$osArray = array(
|
164 |
+
'Windows 10 Phone' => '(Windows Phone)|(Microsoft; Lumia)',
|
165 |
+
'Android' => '(Linux; Android)|Android',
|
166 |
+
'ChromeOS' => '(X11; CrOS)',
|
167 |
+
'SymbianOS' => 'SymbianOS',
|
168 |
+
'Windows 98' => '(Win98)|(Windows 98)',
|
169 |
+
'Windows 2000' => '(Windows 2000)|(Windows NT 5.0)',
|
170 |
+
'Windows ME' => 'Windows ME',
|
171 |
+
'Windows XP' => '(Windows XP)|(Windows NT 5.1)',
|
172 |
+
'Windows Vista' => 'Windows NT 6.0',
|
173 |
+
'Windows 8' => 'Windows NT 6.2',
|
174 |
+
'Windows 8.1' => 'Windows NT 6.3',
|
175 |
+
'Windows 7' => '(Windows NT 6.1)|(Windows NT 7.0)',
|
176 |
+
'Windows 10' => 'Windows NT 10.0',
|
177 |
+
'Linux' => '(X11)|(Linux)',
|
178 |
+
'iOS' => '(Apple-iPhone)|(iPhone)|(iPhone OS)',
|
179 |
+
'macOS' => '(Mac_PowerPC)|(Macintosh)|(Mac OS)',
|
180 |
+
);
|
181 |
+
$os = 'Other';
|
182 |
+
foreach ( $osArray as $k => $v ) {
|
183 |
+
if ( preg_match( "/$v/", $agent['user_agent'] ) ) {
|
184 |
+
$os = $k;
|
185 |
+
break;
|
186 |
+
}
|
187 |
+
}
|
188 |
+
if ( isset( $operating_systems[ $os ] ) ) {
|
189 |
+
$operating_systems[ $os ] += 1;
|
190 |
+
} else {
|
191 |
+
$operating_systems[ $os ] = 1;
|
192 |
+
}
|
193 |
+
}
|
194 |
+
return moveArrayElementToEnd( $operating_systems, 'Other' );
|
195 |
+
}
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Retrieves top downloads by download count
|
199 |
+
*
|
200 |
+
* @param string $start_date
|
201 |
+
* @param string $end_date
|
202 |
+
* @param int $limit Total number of records to retrieve
|
203 |
+
*
|
204 |
+
* @return array
|
205 |
+
*/
|
206 |
+
function sdm_get_top_downloads_by_count( $start_date = '', $end_date = '', $limit = 25 ) {
|
207 |
+
global $wpdb;
|
208 |
+
|
209 |
+
$q = $wpdb->prepare(
|
210 |
+
'SELECT COUNT(id) as cnt, post_title
|
211 |
+
FROM ' . $wpdb->prefix . "sdm_downloads
|
212 |
+
WHERE DATE_FORMAT(`date_time`,'%%Y-%%m-%%d')>=%s
|
213 |
+
AND DATE_FORMAT(`date_time`,'%%Y-%%m-%%d')<=%s
|
214 |
+
GROUP BY post_title
|
215 |
+
ORDER BY cnt DESC LIMIT $limit",
|
216 |
+
$start_date,
|
217 |
+
$end_date
|
218 |
+
);
|
219 |
+
$res = $wpdb->get_results( $q, ARRAY_A );
|
220 |
+
|
221 |
+
return $res;
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Checks if valid date or not
|
226 |
+
*
|
227 |
+
* @param mixed $data
|
228 |
+
*
|
229 |
+
* @return boolean
|
230 |
+
*/
|
231 |
+
function sdm_validate_date_field( $data ) {
|
232 |
+
if ( is_array( $data ) ) {
|
233 |
+
foreach ( $data as $date ) {
|
234 |
+
$date_elements = explode( '-', $date );
|
235 |
+
|
236 |
+
$year = isset( $date_elements[0] ) ? $date_elements[0] : null;
|
237 |
+
$month = isset( $date_elements[1] ) ? $date_elements[1] : null;
|
238 |
+
$day = isset( $date_elements[2] ) ? $date_elements[2] : null;
|
239 |
+
|
240 |
+
return checkdate( (int) $month, (int) $day, (int) $year );
|
241 |
+
}
|
242 |
+
}
|
243 |
+
$date_elements = explode( '-', $data );
|
244 |
+
|
245 |
+
$year = isset( $date_elements[0] ) ? $date_elements[0] : null;
|
246 |
+
$month = isset( $date_elements[1] ) ? $date_elements[1] : null;
|
247 |
+
$day = isset( $date_elements[2] ) ? $date_elements[2] : null;
|
248 |
+
|
249 |
+
return checkdate( (int) $month, (int) $day, (int) $year );
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* move an array element by its key to the end.
|
254 |
+
*
|
255 |
+
* @param array $array The array being reordered.
|
256 |
+
* @param string|int $key They key of the element you want to move.
|
257 |
+
*
|
258 |
+
* @return array
|
259 |
+
*/
|
260 |
+
function moveArrayElementToEnd( array &$array, $key ) {
|
261 |
+
if ( ( $k = array_search( $key, array_keys( $array ) ) ) === false ) {
|
262 |
+
return $array;
|
263 |
+
}
|
264 |
+
|
265 |
+
$p1 = array_splice( $array, $k, 1 );
|
266 |
+
$p2 = array_splice( $array, 0, count( $array ) );
|
267 |
+
$array = array_merge( $p2, $p1, $array );
|
268 |
+
|
269 |
+
return $array;
|
270 |
+
}
|
includes/sdm-utility-functions.php
CHANGED
@@ -1,470 +1,478 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Get (filtered) list of all download button colors.
|
5 |
-
*
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
$
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
$
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
*
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
}
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
$
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
}
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Get (filtered) list of all download button colors.
|
5 |
+
*
|
6 |
+
* @return array Array of colors: color key => color name.
|
7 |
+
*/
|
8 |
+
function sdm_get_download_button_colors() {
|
9 |
+
return apply_filters(
|
10 |
+
'sdm_download_button_color_options',
|
11 |
+
array(
|
12 |
+
'green' => __( 'Green', 'simple-download-monitor' ),
|
13 |
+
'blue' => __( 'Blue', 'simple-download-monitor' ),
|
14 |
+
'purple' => __( 'Purple', 'simple-download-monitor' ),
|
15 |
+
'teal' => __( 'Teal', 'simple-download-monitor' ),
|
16 |
+
'darkblue' => __( 'Dark Blue', 'simple-download-monitor' ),
|
17 |
+
'black' => __( 'Black', 'simple-download-monitor' ),
|
18 |
+
'grey' => __( 'Grey', 'simple-download-monitor' ),
|
19 |
+
'pink' => __( 'Pink', 'simple-download-monitor' ),
|
20 |
+
'orange' => __( 'Orange', 'simple-download-monitor' ),
|
21 |
+
'white' => __( 'White', 'simple-download-monitor' ),
|
22 |
+
)
|
23 |
+
);
|
24 |
+
}
|
25 |
+
|
26 |
+
function sdm_get_download_count_for_post( $id ) {
|
27 |
+
// Get number of downloads by counting db columns matching postID
|
28 |
+
global $wpdb;
|
29 |
+
$table = $wpdb->prefix . 'sdm_downloads';
|
30 |
+
$wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table . ' WHERE post_id=%s', $id ) );
|
31 |
+
// Count database rows
|
32 |
+
$db_count = $wpdb->num_rows;
|
33 |
+
|
34 |
+
// Check post meta to see if we need to offset the count before displaying to viewers
|
35 |
+
$get_offset = get_post_meta( $id, 'sdm_count_offset', true );
|
36 |
+
|
37 |
+
if ( $get_offset && $get_offset != '' ) {
|
38 |
+
|
39 |
+
$db_count = $db_count + $get_offset;
|
40 |
+
}
|
41 |
+
|
42 |
+
return $db_count;
|
43 |
+
}
|
44 |
+
|
45 |
+
function sdm_get_password_entry_form( $id, $args = array(), $class = '' ) {
|
46 |
+
$action_url = WP_SIMPLE_DL_MONITOR_SITE_HOME_URL . '/?smd_process_download=1&download_id=' . $id;
|
47 |
+
|
48 |
+
//Get the download button text
|
49 |
+
$button_text = isset( $args['button_text'] ) ? $args['button_text'] : '';
|
50 |
+
if ( empty( $button_text ) ) {//Use the default text for the button
|
51 |
+
$button_text_string = sdm_get_default_download_button_text( $id );
|
52 |
+
} else { //Use the custom text
|
53 |
+
$button_text_string = $button_text;
|
54 |
+
}
|
55 |
+
|
56 |
+
$uuid = uniqid( 'sdm-pass-' );
|
57 |
+
|
58 |
+
$data = '';
|
59 |
+
|
60 |
+
//Enter password label
|
61 |
+
$enter_password_label = __( 'Enter Password to Download:', 'simple-download-monitor' );
|
62 |
+
$enter_password_label = apply_filters( 'sdm_enter_password_to_download_label', $enter_password_label );
|
63 |
+
$data .= '<span class="sdm_enter_password_label_text">' . $enter_password_label . '</span>';
|
64 |
+
|
65 |
+
//Check if new window is enabled
|
66 |
+
$new_window = get_post_meta( $id, 'sdm_item_new_window', true );
|
67 |
+
$window_target = empty( $new_window ) ? '' : ' target="_blank"';
|
68 |
+
|
69 |
+
//Form code
|
70 |
+
$data .= '<form action="' . $action_url . '" method="post" id="' . $uuid . '" class="sdm-download-form"' . $window_target . '>';
|
71 |
+
$data .= '<input type="password" name="pass_text" class="sdm_pass_text" value="" /> ';
|
72 |
+
|
73 |
+
$data .= sdm_get_download_with_recaptcha();
|
74 |
+
|
75 |
+
//Check if Terms & Condition enabled
|
76 |
+
$data .= sdm_get_checkbox_for_termsncond();
|
77 |
+
|
78 |
+
$data .= '<span class="sdm-download-button">';
|
79 |
+
$data .= '<a href="#" name="sdm_dl_pass_submit" class="pass_sumbit sdm_pass_protected_download sdm_download_with_condition ' . $class . '">' . $button_text_string . '</a>';
|
80 |
+
$data .= '</span>';
|
81 |
+
$data .= '<input type="hidden" name="download_id" value="' . $id . '" />';
|
82 |
+
$data .= '</form>';
|
83 |
+
return $data;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Get remote IP address.
|
88 |
+
*
|
89 |
+
* @link http://stackoverflow.com/questions/1634782/what-is-the-most-accurate-way-to-retrieve-a-users-correct-ip-address-in-php
|
90 |
+
*
|
91 |
+
* @param bool $ignore_private_and_reserved Ignore IPs that fall into private or reserved IP ranges.
|
92 |
+
* @return mixed IP address as a string or null, if remote IP address cannot be determined (or is ignored).
|
93 |
+
*/
|
94 |
+
function sdm_get_ip_address( $ignore_private_and_reserved = false ) {
|
95 |
+
$flags = $ignore_private_and_reserved ? ( FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) : 0;
|
96 |
+
foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
|
97 |
+
if ( array_key_exists( $key, $_SERVER ) === true ) {
|
98 |
+
foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
|
99 |
+
$ip = trim( $ip ); // just to be safe
|
100 |
+
|
101 |
+
if ( filter_var( $ip, FILTER_VALIDATE_IP, $flags ) !== false ) {
|
102 |
+
return $ip;
|
103 |
+
}
|
104 |
+
}
|
105 |
+
}
|
106 |
+
}
|
107 |
+
return null;
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Get location information (country or other info) for given IP address.
|
112 |
+
*
|
113 |
+
* @param string $ip
|
114 |
+
* @param string $purpose
|
115 |
+
* @return mixed
|
116 |
+
*/
|
117 |
+
function sdm_ip_info( $ip, $purpose = 'location' ) {
|
118 |
+
|
119 |
+
$continents = array(
|
120 |
+
'AF' => 'Africa',
|
121 |
+
'AN' => 'Antarctica',
|
122 |
+
'AS' => 'Asia',
|
123 |
+
'EU' => 'Europe',
|
124 |
+
'OC' => 'Australia (Oceania)',
|
125 |
+
'NA' => 'North America',
|
126 |
+
'SA' => 'South America',
|
127 |
+
);
|
128 |
+
|
129 |
+
$ipdat = @json_decode( file_get_contents( 'http://www.geoplugin.net/json.gp?ip=' . $ip ) );
|
130 |
+
|
131 |
+
if ( @strlen( trim( $ipdat->geoplugin_countryCode ) ) === 2 ) {
|
132 |
+
switch ( $purpose ) {
|
133 |
+
case 'location':
|
134 |
+
return array(
|
135 |
+
'city' => @$ipdat->geoplugin_city,
|
136 |
+
'state' => @$ipdat->geoplugin_regionName,
|
137 |
+
'country' => @$ipdat->geoplugin_countryName,
|
138 |
+
'country_code' => @$ipdat->geoplugin_countryCode,
|
139 |
+
'continent' => @$continents[ strtoupper( $ipdat->geoplugin_continentCode ) ],
|
140 |
+
'continent_code' => @$ipdat->geoplugin_continentCode,
|
141 |
+
);
|
142 |
+
case 'address':
|
143 |
+
$address = array( $ipdat->geoplugin_countryName );
|
144 |
+
if ( @strlen( $ipdat->geoplugin_regionName ) >= 1 ) {
|
145 |
+
$address[] = $ipdat->geoplugin_regionName;
|
146 |
+
}
|
147 |
+
if ( @strlen( $ipdat->geoplugin_city ) >= 1 ) {
|
148 |
+
$address[] = $ipdat->geoplugin_city;
|
149 |
+
}
|
150 |
+
return implode( ', ', array_reverse( $address ) );
|
151 |
+
case 'city':
|
152 |
+
return @$ipdat->geoplugin_city;
|
153 |
+
case 'state':
|
154 |
+
return @$ipdat->geoplugin_regionName;
|
155 |
+
case 'region':
|
156 |
+
return @$ipdat->geoplugin_regionName;
|
157 |
+
case 'country':
|
158 |
+
return @$ipdat->geoplugin_countryName;
|
159 |
+
case 'countrycode':
|
160 |
+
return @$ipdat->geoplugin_countryCode;
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
// Either no info found or invalid $purpose.
|
165 |
+
return null;
|
166 |
+
}
|
167 |
+
|
168 |
+
/*
|
169 |
+
* Checks if the string exists in the array key value of the provided array. If it doesn't exist, it returns the first key element from the valid values.
|
170 |
+
*/
|
171 |
+
|
172 |
+
function sdm_sanitize_value_by_array( $to_check, $valid_values ) {
|
173 |
+
$keys = array_keys( $valid_values );
|
174 |
+
$keys = array_map( 'strtolower', $keys );
|
175 |
+
if ( in_array( $to_check, $keys ) ) {
|
176 |
+
return $to_check;
|
177 |
+
}
|
178 |
+
return reset( $keys ); //Return the first element from the valid values
|
179 |
+
}
|
180 |
+
|
181 |
+
function sdm_get_logged_in_user() {
|
182 |
+
$visitor_name = false;
|
183 |
+
|
184 |
+
if ( is_user_logged_in() ) { // Get WP user name (if logged in)
|
185 |
+
$current_user = wp_get_current_user();
|
186 |
+
$visitor_name = $current_user->user_login;
|
187 |
+
}
|
188 |
+
|
189 |
+
//WP eMember plugin integration
|
190 |
+
if ( class_exists( 'Emember_Auth' ) ) {
|
191 |
+
//WP eMember plugin is installed.
|
192 |
+
$emember_auth = Emember_Auth::getInstance();
|
193 |
+
$username = $emember_auth->getUserInfo( 'user_name' );
|
194 |
+
if ( ! empty( $username ) ) {//Member is logged in.
|
195 |
+
$visitor_name = $username; //Override the visitor name to emember username.
|
196 |
+
}
|
197 |
+
}
|
198 |
+
|
199 |
+
$visitor_name = apply_filters( 'sdm_get_logged_in_user_name', $visitor_name );
|
200 |
+
|
201 |
+
return $visitor_name;
|
202 |
+
}
|
203 |
+
|
204 |
+
// Checks if current visitor is a bot
|
205 |
+
function sdm_visitor_is_bot() {
|
206 |
+
$bots = array( 'archiver', 'baiduspider', 'bingbot', 'binlar', 'casper', 'checkprivacy', 'clshttp', 'cmsworldmap', 'comodo', 'curl', 'diavol', 'dotbot', 'DuckDuckBot', 'Exabot', 'email', 'extract', 'facebookexternalhit', 'feedfinder', 'flicky', 'googlebot', 'grab', 'harvest', 'httrack', 'ia_archiver', 'jakarta', 'kmccrew', 'libwww', 'loader', 'MJ12bot', 'miner', 'msnbot', 'nikto', 'nutch', 'planetwork', 'purebot', 'pycurl', 'python', 'scan', 'skygrid', 'slurp', 'sucker', 'turnit', 'vikspider', 'wget', 'winhttp', 'yandex', 'yandexbot', 'yahoo', 'youda', 'zmeu', 'zune', 'Sidetrade', 'AhrefsBot' );
|
207 |
+
|
208 |
+
$isBot = false;
|
209 |
+
|
210 |
+
$user_agent = wp_kses_data( $_SERVER['HTTP_USER_AGENT'] );
|
211 |
+
|
212 |
+
foreach ( $bots as $bot ) {
|
213 |
+
if ( stripos( $user_agent, $bot ) !== false ) {
|
214 |
+
$isBot = true;
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
if ( empty( $user_agent ) || $user_agent == ' ' ) {
|
219 |
+
$isBot = true;
|
220 |
+
}
|
221 |
+
|
222 |
+
//This filter can be used to override what you consider bot via your own custom function. You can read the user-agent value from the server var.
|
223 |
+
$isBot = apply_filters( 'sdm_visitor_is_bot', $isBot );
|
224 |
+
|
225 |
+
return $isBot;
|
226 |
+
}
|
227 |
+
|
228 |
+
function sdm_get_download_form_with_recaptcha( $id, $args = array(), $class = '' ) {
|
229 |
+
$action_url = WP_SIMPLE_DL_MONITOR_SITE_HOME_URL . '/?smd_process_download=1&download_id=' . $id;
|
230 |
+
|
231 |
+
//Get the download button text
|
232 |
+
$button_text = isset( $args['button_text'] ) ? $args['button_text'] : '';
|
233 |
+
if ( empty( $button_text ) ) {//Use the default text for the button
|
234 |
+
$button_text_string = sdm_get_default_download_button_text( $id );
|
235 |
+
} else { //Use the custom text
|
236 |
+
$button_text_string = $button_text;
|
237 |
+
}
|
238 |
+
|
239 |
+
$main_advanced_opts = get_option( 'sdm_advanced_options' );
|
240 |
+
|
241 |
+
$new_window = get_post_meta( $id, 'sdm_item_new_window', true );
|
242 |
+
$window_target = empty( $new_window ) ? '' : ' target="_blank"';
|
243 |
+
|
244 |
+
$data = '<form action="' . $action_url . '" method="post" class="sdm-g-recaptcha-form sdm-download-form"' . $window_target . '>';
|
245 |
+
|
246 |
+
$data .= '<div class="sdm-recaptcha-button">';
|
247 |
+
$data .= '<div class="g-recaptcha sdm-g-recaptcha"></div>';
|
248 |
+
|
249 |
+
//Check if Terms & Condition enabled
|
250 |
+
$data .= sdm_get_checkbox_for_termsncond();
|
251 |
+
|
252 |
+
$data .= '<a href="#" class="' . $class . ' sdm_download_with_condition">' . $button_text_string . '</a>';
|
253 |
+
$data .= '</div>';
|
254 |
+
$data .= '<input type="hidden" name="download_id" value="' . $id . '" />';
|
255 |
+
$data .= '</form>';
|
256 |
+
return $data;
|
257 |
+
}
|
258 |
+
|
259 |
+
function sdm_get_download_with_recaptcha() {
|
260 |
+
$main_advanced_opts = get_option( 'sdm_advanced_options' );
|
261 |
+
$recaptcha_enable = isset( $main_advanced_opts['recaptcha_enable'] ) ? true : false;
|
262 |
+
if ( $recaptcha_enable ) {
|
263 |
+
return '<div class="g-recaptcha sdm-g-recaptcha"></div>';
|
264 |
+
}
|
265 |
+
return '';
|
266 |
+
}
|
267 |
+
|
268 |
+
function sdm_get_checkbox_for_termsncond() {
|
269 |
+
$main_advanced_opts = get_option( 'sdm_advanced_options' );
|
270 |
+
$termscond_enable = isset( $main_advanced_opts['termscond_enable'] ) ? true : false;
|
271 |
+
if ( $termscond_enable ) {
|
272 |
+
$data = '<div class="sdm-termscond-checkbox">';
|
273 |
+
$data .= '<input type="checkbox" class="agree_termscond" value="1"/> ' . __( 'I agree to the ', 'simple-download-monitor' ) . '<a href="' . $main_advanced_opts['termscond_url'] . '" target="_blank">' . __( 'terms and conditions', 'simple-download-monitor' ) . '</a>';
|
274 |
+
$data .= '</div>';
|
275 |
+
return $data;
|
276 |
+
}
|
277 |
+
return '';
|
278 |
+
}
|
279 |
+
|
280 |
+
function sdm_get_download_form_with_termsncond( $id, $args = array(), $class = '' ) {
|
281 |
+
$action_url = WP_SIMPLE_DL_MONITOR_SITE_HOME_URL . '/?smd_process_download=1&download_id=' . $id;
|
282 |
+
|
283 |
+
//Get the download button text
|
284 |
+
$button_text = isset( $args['button_text'] ) ? $args['button_text'] : '';
|
285 |
+
if ( empty( $button_text ) ) {//Use the default text for the button
|
286 |
+
$button_text_string = sdm_get_default_download_button_text( $id );
|
287 |
+
} else { //Use the custom text
|
288 |
+
$button_text_string = $button_text;
|
289 |
+
}
|
290 |
+
|
291 |
+
$main_advanced_opts = get_option( 'sdm_advanced_options' );
|
292 |
+
$termscond_enable = isset( $main_advanced_opts['termscond_enable'] ) ? true : false;
|
293 |
+
|
294 |
+
$new_window = get_post_meta( $id, 'sdm_item_new_window', true );
|
295 |
+
$window_target = empty( $new_window ) ? '' : ' target="_blank"';
|
296 |
+
|
297 |
+
$data = '<form action="' . $action_url . '" method="post" class="sdm-download-form"' . $window_target . '>';
|
298 |
+
$data .= sdm_get_checkbox_for_termsncond();
|
299 |
+
$data .= '<div class="sdm-termscond-button">';
|
300 |
+
$data .= '<a href="#" class="' . $class . ' sdm_download_with_condition">' . $button_text_string . '</a>';
|
301 |
+
$data .= '</div>';
|
302 |
+
$data .= '<input type="hidden" name="download_id" value="' . $id . '" />';
|
303 |
+
$data .= '</form>';
|
304 |
+
return $data;
|
305 |
+
}
|
306 |
+
|
307 |
+
function sdm_get_default_download_button_text( $download_id ) {
|
308 |
+
$default_text = __( 'Download Now!', 'simple-download-monitor' );
|
309 |
+
$meta_text = get_post_meta( $download_id, 'sdm_download_button_text', true );
|
310 |
+
|
311 |
+
$button_text = ! empty( $meta_text ) ? $meta_text : $default_text;
|
312 |
+
return $button_text;
|
313 |
+
}
|
314 |
+
|
315 |
+
/*
|
316 |
+
* Use this function to read the current page's URL
|
317 |
+
*/
|
318 |
+
function sdm_get_current_page_url() {
|
319 |
+
$page_url = 'http';
|
320 |
+
|
321 |
+
if ( isset( $_SERVER['SCRIPT_URI'] ) && ! empty( $_SERVER['SCRIPT_URI'] ) ) {
|
322 |
+
$page_url = $_SERVER['SCRIPT_URI'];
|
323 |
+
$page_url = apply_filters( 'sdm_get_current_page_url', $page_url );
|
324 |
+
return $page_url;
|
325 |
+
}
|
326 |
+
|
327 |
+
if ( isset( $_SERVER['HTTPS'] ) && ( $_SERVER['HTTPS'] == 'on' ) ) {
|
328 |
+
$page_url .= 's';
|
329 |
+
}
|
330 |
+
$page_url .= '://';
|
331 |
+
if ( isset( $_SERVER['SERVER_PORT'] ) && ( $_SERVER['SERVER_PORT'] != '80' ) ) {
|
332 |
+
$page_url .= ltrim( $_SERVER['SERVER_NAME'], '.*' ) . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
|
333 |
+
} else {
|
334 |
+
$page_url .= ltrim( $_SERVER['SERVER_NAME'], '.*' ) . $_SERVER['REQUEST_URI'];
|
335 |
+
}
|
336 |
+
|
337 |
+
$page_url = apply_filters( 'sdm_get_current_page_url', $page_url );
|
338 |
+
return $page_url;
|
339 |
+
}
|
340 |
+
|
341 |
+
/*
|
342 |
+
* Use this function to redirect to a URL
|
343 |
+
*/
|
344 |
+
function sdm_redirect_to_url( $url, $delay = '0', $exit = '1' ) {
|
345 |
+
$url = apply_filters( 'sdm_before_redirect_to_url', $url );
|
346 |
+
if ( empty( $url ) ) {
|
347 |
+
echo '<strong>';
|
348 |
+
_e( 'Error! The URL value is empty. Please specify a correct URL value to redirect to!', 'simple-download-monitor' );
|
349 |
+
echo '</strong>';
|
350 |
+
exit;
|
351 |
+
}
|
352 |
+
if ( ! headers_sent() ) {
|
353 |
+
header( 'Location: ' . $url );
|
354 |
+
} else {
|
355 |
+
echo '<meta http-equiv="refresh" content="' . $delay . ';url=' . $url . '" />';
|
356 |
+
}
|
357 |
+
if ( $exit == '1' ) {//exit
|
358 |
+
exit;
|
359 |
+
}
|
360 |
+
}
|
361 |
+
|
362 |
+
/*
|
363 |
+
* Utility function to insert a download record into the logs DB table. Used by addons sometimes.
|
364 |
+
*/
|
365 |
+
function sdm_insert_download_to_logs_table( $download_id ) {
|
366 |
+
global $wpdb;
|
367 |
+
|
368 |
+
if ( ! $download_id ) {
|
369 |
+
SDM_Debug::log( 'Error! insert to logs function called with incorrect download item id.', false );
|
370 |
+
return;
|
371 |
+
}
|
372 |
+
|
373 |
+
$main_option = get_option( 'sdm_downloads_options' );
|
374 |
+
|
375 |
+
$download_title = get_the_title( $download_id );
|
376 |
+
$download_link = get_post_meta( $download_id, 'sdm_upload', true );
|
377 |
+
|
378 |
+
$ipaddress = '';
|
379 |
+
//Check if do not capture IP is enabled.
|
380 |
+
if ( ! isset( $main_option['admin_do_not_capture_ip'] ) ) {
|
381 |
+
$ipaddress = sdm_get_ip_address();
|
382 |
+
}
|
383 |
+
|
384 |
+
$user_agent = '';
|
385 |
+
//Check if do not capture User Agent is enabled.
|
386 |
+
if ( ! isset( $main_option['admin_do_not_capture_user_agent'] ) ) {
|
387 |
+
//Get the user agent data. The get_browser() function doesn't work on many servers. So use the HTTP var.
|
388 |
+
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
389 |
+
$user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
|
390 |
+
}
|
391 |
+
}
|
392 |
+
|
393 |
+
$referrer_url = '';
|
394 |
+
//Check if do not capture Referer URL is enabled.
|
395 |
+
if ( ! isset( $main_option['admin_do_not_capture_referrer_url'] ) ) {
|
396 |
+
//Get the user agent data. The get_browser() function doesn't work on many servers. So use the HTTP var.
|
397 |
+
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
|
398 |
+
$referrer_url = sanitize_text_field( $_SERVER['HTTP_REFERER'] );
|
399 |
+
}
|
400 |
+
}
|
401 |
+
|
402 |
+
$date_time = current_time( 'mysql' );
|
403 |
+
$visitor_country = ! empty( $ipaddress ) ? sdm_ip_info( $ipaddress, 'country' ) : '';
|
404 |
+
|
405 |
+
$visitor_name = sdm_get_logged_in_user();
|
406 |
+
$visitor_name = ( $visitor_name === false ) ? __( 'Not Logged In', 'simple-download-monitor' ) : $visitor_name;
|
407 |
+
|
408 |
+
// Get option for global disabling of download logging
|
409 |
+
$no_logs = isset( $main_option['admin_no_logs'] );
|
410 |
+
|
411 |
+
// Get optoin for logging only unique IPs
|
412 |
+
$unique_ips = isset( $main_option['admin_log_unique'] );
|
413 |
+
|
414 |
+
// Get post meta for individual disabling of download logging
|
415 |
+
$get_meta = get_post_meta( $download_id, 'sdm_item_no_log', true );
|
416 |
+
$item_logging_checked = isset( $get_meta ) && $get_meta === 'on' ? 'on' : 'off';
|
417 |
+
|
418 |
+
$dl_logging_needed = true;
|
419 |
+
|
420 |
+
// Check if download logs have been disabled (globally or per download item)
|
421 |
+
if ( $no_logs === true || $item_logging_checked === 'on' ) {
|
422 |
+
$dl_logging_needed = false;
|
423 |
+
}
|
424 |
+
|
425 |
+
// Check if we are only logging unique ips
|
426 |
+
if ( $unique_ips === true ) {
|
427 |
+
$check_ip = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id="' . $download_id . '" AND visitor_ip = "' . $ipaddress . '"' );
|
428 |
+
|
429 |
+
//This IP is already logged for this download item. No need to log it again.
|
430 |
+
if ( $check_ip ) {
|
431 |
+
$dl_logging_needed = false;
|
432 |
+
}
|
433 |
+
}
|
434 |
+
|
435 |
+
// Check if "Do Not Count Downloads from Bots" setting is enabled
|
436 |
+
if ( isset( $main_option['admin_dont_log_bots'] ) ) {
|
437 |
+
//it is. Now let's check if visitor is a bot
|
438 |
+
if ( sdm_visitor_is_bot() ) {
|
439 |
+
//visitor is a bot. We neither log nor count this download
|
440 |
+
$dl_logging_needed = false;
|
441 |
+
}
|
442 |
+
}
|
443 |
+
|
444 |
+
if ( $dl_logging_needed ) {
|
445 |
+
// We need to log this download.
|
446 |
+
$table = $wpdb->prefix . 'sdm_downloads';
|
447 |
+
$data = array(
|
448 |
+
'post_id' => $download_id,
|
449 |
+
'post_title' => $download_title,
|
450 |
+
'file_url' => $download_link,
|
451 |
+
'visitor_ip' => $ipaddress,
|
452 |
+
'date_time' => $date_time,
|
453 |
+
'visitor_country' => $visitor_country,
|
454 |
+
'visitor_name' => $visitor_name,
|
455 |
+
'user_agent' => $user_agent,
|
456 |
+
'referrer_url' => $referrer_url,
|
457 |
+
);
|
458 |
+
|
459 |
+
$data = array_filter( $data ); //Remove any null values.
|
460 |
+
$insert_table = $wpdb->insert( $table, $data );
|
461 |
+
|
462 |
+
if ( $insert_table ) {
|
463 |
+
//Download request was logged successfully
|
464 |
+
SDM_Debug::log( 'Download has been logged in the logs table for download ID: ' . $download_id );
|
465 |
+
} else {
|
466 |
+
//Failed to log the download request
|
467 |
+
SDM_Debug::log( 'Error! Failed to log the download request in the database table.', false );
|
468 |
+
}
|
469 |
+
}
|
470 |
+
}
|
471 |
+
|
472 |
+
function sdm_sanitize_text( $text ) {
|
473 |
+
$text = htmlspecialchars( $text );
|
474 |
+
$text = strip_tags( $text );
|
475 |
+
$text = sanitize_text_field( $text );
|
476 |
+
$text = esc_attr( $text );
|
477 |
+
return $text;
|
478 |
+
}
|
js/sdm_admin_scripts.js
CHANGED
@@ -45,11 +45,14 @@ jQuery(document).ready(function ($) {
|
|
45 |
|
46 |
// Remove thumbnail image from CPT
|
47 |
$('#remove_thumbnail_button').click(function () {
|
|
|
|
|
|
|
48 |
$.post(
|
49 |
-
|
50 |
{
|
51 |
action: 'sdm_remove_thumbnail_image',
|
52 |
-
post_id_del:
|
53 |
},
|
54 |
function (response) {
|
55 |
if (response) { // ** If response was successful
|
45 |
|
46 |
// Remove thumbnail image from CPT
|
47 |
$('#remove_thumbnail_button').click(function () {
|
48 |
+
if ($('#sdm_thumbnail_image').length === 0) {
|
49 |
+
return;
|
50 |
+
}
|
51 |
$.post(
|
52 |
+
sdm_admin.ajax_url,
|
53 |
{
|
54 |
action: 'sdm_remove_thumbnail_image',
|
55 |
+
post_id_del: sdm_admin.post_id
|
56 |
},
|
57 |
function (response) {
|
58 |
if (response) { // ** If response was successful
|
js/sdm_admin_stats.js
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var sdm = [];
|
2 |
+
sdm.datechart = false;
|
3 |
+
sdm.geochart = false;
|
4 |
+
sdm.activeTab = sdmAdminStats.activeTab;
|
5 |
+
sdm.apiKey = sdmAdminStats.apiKey;
|
6 |
+
|
7 |
+
jQuery('#sdm_date_buttons button').click(function (e) {
|
8 |
+
jQuery('#sdm_choose_date').find('input[name="sdm_stats_start_date"]').val(jQuery(this).attr('data-start-date'));
|
9 |
+
jQuery('#sdm_choose_date').find('input[name="sdm_stats_end_date"]').val(jQuery(this).attr('data-end-date'));
|
10 |
+
});
|
11 |
+
|
12 |
+
function sdm_init_chart(tab) {
|
13 |
+
if (!sdm.datechart && tab === 'datechart') {
|
14 |
+
sdm.datechart = true;
|
15 |
+
google.charts.load('current', { 'packages': ['corechart'] });
|
16 |
+
google.charts.setOnLoadCallback(sdm_drawDateChart);
|
17 |
+
} else if (!sdm.geochart && tab === 'geochart') {
|
18 |
+
sdm.geochart = true;
|
19 |
+
var chartOpts = {};
|
20 |
+
chartOpts.packages = ['geochart'];
|
21 |
+
if (sdm.apiKey) {
|
22 |
+
chartOpts.mapsApiKey = sdm.apiKey;
|
23 |
+
} else {
|
24 |
+
//show API Key warning
|
25 |
+
jQuery('#sdm-api-key-warning').fadeIn('slow');
|
26 |
+
}
|
27 |
+
google.charts.load('current', chartOpts);
|
28 |
+
google.charts.setOnLoadCallback(sdm_drawGeoChart);
|
29 |
+
}
|
30 |
+
}
|
31 |
+
function sdm_drawDateChart() {
|
32 |
+
var sdm_dateData = new google.visualization.DataTable();
|
33 |
+
sdm_dateData.addColumn('string', sdmAdminStats.str.date);
|
34 |
+
sdm_dateData.addColumn('number', sdmAdminStats.str.numberOfDownloads);
|
35 |
+
sdm_dateData.addRows(sdmAdminStats.dByDate);
|
36 |
+
|
37 |
+
var sdm_dateChart = new google.visualization.AreaChart(document.getElementById('downloads_chart'));
|
38 |
+
sdm_dateChart.draw(sdm_dateData, {
|
39 |
+
width: 'auto', height: 300, title: sdmAdminStats.str.downloadsByDate, colors: ['#3366CC', '#9AA2B4', '#FFE1C9'],
|
40 |
+
hAxis: { title: sdmAdminStats.str.date, titleTextStyle: { color: 'black' } },
|
41 |
+
vAxis: { title: sdmAdminStats.str.downloads, titleTextStyle: { color: 'black' } },
|
42 |
+
legend: 'top'
|
43 |
+
});
|
44 |
+
}
|
45 |
+
function sdm_drawGeoChart() {
|
46 |
+
|
47 |
+
var sdm_countryData = google.visualization.arrayToDataTable(sdmAdminStats.dByCountry);
|
48 |
+
|
49 |
+
var sdm_countryOptions = { colorAxis: { colors: ['#ddf', '#00f'] } };
|
50 |
+
|
51 |
+
var sdm_countryChart = new google.visualization.GeoChart(document.getElementById('country_chart'));
|
52 |
+
|
53 |
+
sdm_countryChart.draw(sdm_countryData, sdm_countryOptions);
|
54 |
+
|
55 |
+
}
|
56 |
+
jQuery(function () {
|
57 |
+
sdm_init_chart(sdm.activeTab);
|
58 |
+
jQuery('div.sdm-tabs a').click(function (e) {
|
59 |
+
e.preventDefault();
|
60 |
+
var tab = jQuery(this).attr('data-tab-name');
|
61 |
+
jQuery('div.sdm-tabs').find('a').removeClass('nav-tab-active');
|
62 |
+
jQuery(this).addClass('nav-tab-active');
|
63 |
+
jQuery('div.sdm-tabs-content-wrapper').find('div.sdm-tab').hide();
|
64 |
+
jQuery('div.sdm-tabs-content-wrapper').find('div[data-tab-name="' + tab + '"]').fadeIn('fast');
|
65 |
+
sdm_init_chart(tab);
|
66 |
+
jQuery('#sdm_choose_date').find('input[name="sdm_active_tab"]').val(tab);
|
67 |
+
});
|
68 |
+
jQuery('.datepicker').datepicker({
|
69 |
+
dateFormat: 'yy-mm-dd'
|
70 |
+
});
|
71 |
+
});
|
main.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Simple Download Monitor
|
4 |
* Plugin URI: https://simple-download-monitor.com/
|
5 |
* Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
|
6 |
-
* Version: 3.9.
|
7 |
* Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
|
8 |
* Author URI: https://www.tipsandtricks-hq.com/development-center
|
9 |
* License: GPL2
|
@@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
14 |
exit;
|
15 |
}
|
16 |
|
17 |
-
define( 'WP_SIMPLE_DL_MONITOR_VERSION', '3.9.
|
18 |
define( 'WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname( plugin_basename( __FILE__ ) ) );
|
19 |
define( 'WP_SIMPLE_DL_MONITOR_URL', plugins_url( '', __FILE__ ) );
|
20 |
define( 'WP_SIMPLE_DL_MONITOR_PATH', plugin_dir_path( __FILE__ ) );
|
@@ -116,22 +116,67 @@ function sdm_admin_init_time_tasks() {
|
|
116 |
add_action( 'wp_ajax_sdm_reset_log', 'sdm_reset_log_handler' );
|
117 |
add_action( 'wp_ajax_sdm_delete_data', 'sdm_delete_data_handler' );
|
118 |
|
119 |
-
if ( is_admin() ) {
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
}
|
129 |
-
|
130 |
}
|
131 |
}
|
132 |
}
|
133 |
|
134 |
function sdm_reset_log_handler() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
SDM_Debug::reset_log();
|
136 |
echo '1';
|
137 |
wp_die();
|
@@ -142,6 +187,12 @@ function sdm_delete_data_handler() {
|
|
142 |
//nonce check failed
|
143 |
wp_die( 0 );
|
144 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
global $wpdb;
|
146 |
//let's find and delete smd_download posts and meta
|
147 |
$posts = $wpdb->get_results( 'SELECT id FROM ' . $wpdb->prefix . 'posts WHERE post_type="sdm_downloads"', ARRAY_A );
|
@@ -211,15 +262,8 @@ class simpleDownloadManager {
|
|
211 |
|
212 |
if ( is_admin() ) {
|
213 |
add_action( 'admin_menu', array( $this, 'sdm_create_menu_pages' ) ); // Create admin pages
|
214 |
-
add_action( 'add_meta_boxes', array( $this, 'sdm_create_upload_metabox' ) ); // Create metaboxes
|
215 |
|
216 |
-
|
217 |
-
add_action( 'save_post', array( $this, 'sdm_save_upload_meta_data' ) ); // Save 'upload file' metabox
|
218 |
-
add_action( 'save_post', array( $this, 'sdm_save_dispatch_meta_data' ) ); // Save 'dispatch' metabox
|
219 |
-
add_action( 'save_post', array( $this, 'sdm_save_misc_properties_meta_data' ) ); // Save 'misc properties/settings' metabox
|
220 |
-
add_action( 'save_post', array( $this, 'sdm_save_thumbnail_meta_data' ) ); // Save 'thumbnail' metabox
|
221 |
-
add_action( 'save_post', array( $this, 'sdm_save_statistics_meta_data' ) ); // Save 'statistics' metabox
|
222 |
-
add_action( 'save_post', array( $this, 'sdm_save_other_details_meta_data' ) ); // Save 'other details' metabox
|
223 |
|
224 |
add_action( 'admin_enqueue_scripts', array( $this, 'sdm_admin_scripts' ) ); // Register admin scripts
|
225 |
add_action( 'admin_print_styles', array( $this, 'sdm_admin_styles' ) ); // Register admin styles
|
@@ -254,7 +298,14 @@ class simpleDownloadManager {
|
|
254 |
'image_removed' => __( 'Image Successfully Removed', 'simple-download-monitor' ),
|
255 |
'ajax_error' => __( 'Error with AJAX', 'simple-download-monitor' ),
|
256 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
wp_localize_script( 'sdm-upload', 'sdm_translations', $sdmTranslations );
|
|
|
258 |
}
|
259 |
}
|
260 |
|
@@ -290,393 +341,6 @@ class simpleDownloadManager {
|
|
290 |
sdm_handle_admin_menu();
|
291 |
}
|
292 |
|
293 |
-
public function sdm_create_upload_metabox() {
|
294 |
-
|
295 |
-
//***** Create metaboxes for the custom post type
|
296 |
-
add_meta_box( 'sdm_description_meta_box', __( 'Description', 'simple-download-monitor' ), array( $this, 'display_sdm_description_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
297 |
-
add_meta_box( 'sdm_upload_meta_box', __( 'Downloadable File (Visitors will download this item)', 'simple-download-monitor' ), array( $this, 'display_sdm_upload_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
298 |
-
add_meta_box( 'sdm_dispatch_meta_box', __( 'PHP Dispatch or Redirect', 'simple-download-monitor' ), array( $this, 'display_sdm_dispatch_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
299 |
-
add_meta_box( 'sdm_misc_properties_meta_box', __( 'Miscellaneous Download Item Properties', 'simple-download-monitor' ), array( $this, 'display_sdm_misc_properties_meta_box' ), 'sdm_downloads', 'normal', 'default' ); // Meta box for misc properies/settings
|
300 |
-
add_meta_box( 'sdm_thumbnail_meta_box', __( 'File Thumbnail (Optional)', 'simple-download-monitor' ), array( $this, 'display_sdm_thumbnail_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
301 |
-
add_meta_box( 'sdm_stats_meta_box', __( 'Statistics', 'simple-download-monitor' ), array( $this, 'display_sdm_stats_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
302 |
-
do_action( 'sdm_admin_add_edit_download_before_other_details_meta_box_action' );
|
303 |
-
add_meta_box( 'sdm_other_details_meta_box', __( 'Other Details (Optional)', 'simple-download-monitor' ), array( $this, 'display_sdm_other_details_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
304 |
-
add_meta_box( 'sdm_shortcode_meta_box', __( 'Shortcodes', 'simple-download-monitor' ), array( $this, 'display_sdm_shortcode_meta_box' ), 'sdm_downloads', 'normal', 'default' );
|
305 |
-
}
|
306 |
-
|
307 |
-
public function display_sdm_description_meta_box( $post ) {
|
308 |
-
// Description metabox
|
309 |
-
_e( 'Add a description for this download item.', 'simple-download-monitor' );
|
310 |
-
echo '<br /><br />';
|
311 |
-
|
312 |
-
$old_description = get_post_meta( $post->ID, 'sdm_description', true );
|
313 |
-
$sdm_description_field = array( 'textarea_name' => 'sdm_description' );
|
314 |
-
wp_editor( $old_description, 'sdm_description_editor_content', $sdm_description_field );
|
315 |
-
|
316 |
-
wp_nonce_field( 'sdm_description_box_nonce', 'sdm_description_box_nonce_check' );
|
317 |
-
}
|
318 |
-
|
319 |
-
public function display_sdm_upload_meta_box( $post ) {
|
320 |
-
// File Upload metabox
|
321 |
-
$old_upload = get_post_meta( $post->ID, 'sdm_upload', true );
|
322 |
-
$old_value = isset( $old_upload ) ? $old_upload : '';
|
323 |
-
|
324 |
-
//Trigger filter to allow "sdm_upload" field validation override.
|
325 |
-
$url_validation_override = apply_filters( 'sdm_file_download_url_validation_override', '' );
|
326 |
-
if ( ! empty( $url_validation_override ) ) {
|
327 |
-
//This site has customized the behavior and overriden the "sdm_upload" field validation. It can be useful if you are offering app download URLs (that has unconventional URL patterns).
|
328 |
-
} else {
|
329 |
-
//Do the normal URL validation.
|
330 |
-
$old_value = esc_url( $old_value );
|
331 |
-
}
|
332 |
-
|
333 |
-
_e( 'Manually enter a valid URL of the file in the text box below, or click "Select File" button to upload (or choose) the downloadable file.', 'simple-download-monitor' );
|
334 |
-
echo '<br /><br />';
|
335 |
-
|
336 |
-
echo '<div class="sdm-download-edit-file-url-section">';
|
337 |
-
echo '<input id="sdm_upload" type="text" size="100" name="sdm_upload" value="' . $old_value . '" placeholder="http://..." />';
|
338 |
-
echo '</div>';
|
339 |
-
|
340 |
-
echo '<br />';
|
341 |
-
echo '<input id="upload_image_button" type="button" class="button-primary" value="' . __( 'Select File', 'simple-download-monitor' ) . '" />';
|
342 |
-
|
343 |
-
echo '<br /><br />';
|
344 |
-
_e( 'Steps to upload a file or choose one from your media library:', 'simple-download-monitor' );
|
345 |
-
echo '<ol>';
|
346 |
-
echo '<li>' . __( 'Hit the "Select File" button.', 'simple-download-monitor' ) . '</li>';
|
347 |
-
echo '<li>' . __( 'Upload a new file or choose an existing one from your media library.', 'simple-download-monitor' ) . '</li>';
|
348 |
-
echo '<li>' . __( 'Click the "Insert" button, this will populate the uploaded file\'s URL in the above text field.', 'simple-download-monitor' ) . '</li>';
|
349 |
-
echo '</ol>';
|
350 |
-
|
351 |
-
wp_nonce_field( 'sdm_upload_box_nonce', 'sdm_upload_box_nonce_check' );
|
352 |
-
}
|
353 |
-
|
354 |
-
public function display_sdm_dispatch_meta_box( $post ) {
|
355 |
-
$dispatch = get_post_meta( $post->ID, 'sdm_item_dispatch', true );
|
356 |
-
|
357 |
-
if ( $dispatch === '' ) {
|
358 |
-
// No value yet (either new item or saved with older version of plugin)
|
359 |
-
$screen = get_current_screen();
|
360 |
-
|
361 |
-
if ( $screen->action === 'add' ) {
|
362 |
-
// New item: set default value as per plugin settings.
|
363 |
-
$main_opts = get_option( 'sdm_downloads_options' );
|
364 |
-
$dispatch = isset( $main_opts['general_default_dispatch_value'] ) && $main_opts['general_default_dispatch_value'];
|
365 |
-
}
|
366 |
-
}
|
367 |
-
|
368 |
-
echo '<input id="sdm_item_dispatch" type="checkbox" name="sdm_item_dispatch" value="yes"' . checked( true, $dispatch, false ) . ' />';
|
369 |
-
echo '<label for="sdm_item_dispatch">' . __( 'Dispatch the file via PHP directly instead of redirecting to it. PHP Dispatching keeps the download URL hidden. Dispatching works only for local files (files that you uploaded to this site via this plugin or media library).', 'simple-download-monitor' ) . '</label>';
|
370 |
-
|
371 |
-
wp_nonce_field( 'sdm_dispatch_box_nonce', 'sdm_dispatch_box_nonce_check' );
|
372 |
-
}
|
373 |
-
|
374 |
-
// Open Download in new window
|
375 |
-
public function display_sdm_misc_properties_meta_box( $post ) {
|
376 |
-
|
377 |
-
//Check the open in new window value
|
378 |
-
$new_window = get_post_meta( $post->ID, 'sdm_item_new_window', true );
|
379 |
-
if ( $new_window === '' ) {
|
380 |
-
// No value yet (either new item or saved with older version of plugin)
|
381 |
-
$screen = get_current_screen();
|
382 |
-
if ( $screen->action === 'add' ) {
|
383 |
-
//New item: we can set a default value as per plugin settings. If a general settings is introduced at a later stage.
|
384 |
-
//Does nothing at the moment.
|
385 |
-
}
|
386 |
-
}
|
387 |
-
|
388 |
-
//Check the sdm_item_disable_single_download_page value
|
389 |
-
$sdm_item_disable_single_download_page = get_post_meta( $post->ID, 'sdm_item_disable_single_download_page', true );
|
390 |
-
$sdm_item_hide_dl_button_single_download_page = get_post_meta( $post->ID, 'sdm_item_hide_dl_button_single_download_page', true );
|
391 |
-
|
392 |
-
echo '<p> <input id="sdm_item_new_window" type="checkbox" name="sdm_item_new_window" value="yes"' . checked( true, $new_window, false ) . ' />';
|
393 |
-
echo '<label for="sdm_item_new_window">' . __( 'Open download in a new window.', 'simple-download-monitor' ) . '</label> </p>';
|
394 |
-
|
395 |
-
//the new window will have no download button
|
396 |
-
echo '<p> <input id="sdm_item_hide_dl_button_single_download_page" type="checkbox" name="sdm_item_hide_dl_button_single_download_page" value="yes"' . checked( true, $sdm_item_hide_dl_button_single_download_page, false ) . ' />';
|
397 |
-
echo '<label for="sdm_item_hide_dl_button_single_download_page">';
|
398 |
-
|
399 |
-
$disable_dl_button_label = __( 'Hide the download button on the single download page of this item.', 'simple-download-monitor' );
|
400 |
-
echo $disable_dl_button_label . '</label>';
|
401 |
-
echo '</p>';
|
402 |
-
|
403 |
-
echo '<p> <input id="sdm_item_disable_single_download_page" type="checkbox" name="sdm_item_disable_single_download_page" value="yes"' . checked( true, $sdm_item_disable_single_download_page, false ) . ' />';
|
404 |
-
echo '<label for="sdm_item_disable_single_download_page">';
|
405 |
-
$disable_single_dl_label = __( 'Disable the single download page for this download item. ', 'simple-download-monitor' );
|
406 |
-
$disable_single_dl_label .= __( 'This can be useful if you are using an addon like the ', 'simple-download-monitor' );
|
407 |
-
$disable_single_dl_label .= '<a href="https://simple-download-monitor.com/squeeze-form-addon-for-simple-download-monitor/" target="_blank">Squeeze Form</a>' . '.';
|
408 |
-
echo $disable_single_dl_label . '</label>';
|
409 |
-
echo '</p>';
|
410 |
-
|
411 |
-
$sdm_item_anonymous_can_download = get_post_meta( $post->ID, 'sdm_item_anonymous_can_download', true );
|
412 |
-
|
413 |
-
echo '<p> <input id="sdm_item_anonymous_can_download" type="checkbox" name="sdm_item_anonymous_can_download" value="yes"' . checked( true, $sdm_item_anonymous_can_download, false ) . ' />';
|
414 |
-
echo '<label for="sdm_item_anonymous_can_download">' . __( 'Ignore "Only Allow Logged-in Users to Download" global setting for this item.', 'simple-download-monitor' ) . '</label> </p>';
|
415 |
-
|
416 |
-
wp_nonce_field( 'sdm_misc_properties_box_nonce', 'sdm_misc_properties_box_nonce_check' );
|
417 |
-
}
|
418 |
-
|
419 |
-
public function display_sdm_thumbnail_meta_box( $post ) {
|
420 |
-
// Thumbnail upload metabox
|
421 |
-
$old_thumbnail = get_post_meta( $post->ID, 'sdm_upload_thumbnail', true );
|
422 |
-
$old_value = isset( $old_thumbnail ) ? $old_thumbnail : '';
|
423 |
-
_e( 'Manually enter a valid URL, or click "Select Image" to upload (or choose) the file thumbnail image.', 'simple-download-monitor' );
|
424 |
-
?>
|
425 |
-
<br /><br />
|
426 |
-
<input id="sdm_upload_thumbnail" type="text" size="100" name="sdm_upload_thumbnail" value="<?php echo esc_url( $old_value ); ?>" placeholder="http://..." />
|
427 |
-
<br /><br />
|
428 |
-
<input id="upload_thumbnail_button" type="button" class="button-primary" value="<?php _e( 'Select Image', 'simple-download-monitor' ); ?>" />
|
429 |
-
<input id="remove_thumbnail_button" type="button" class="button" value="<?php _e( 'Remove Image', 'simple-download-monitor' ); ?>" />
|
430 |
-
<br /><br />
|
431 |
-
|
432 |
-
<span id="sdm_admin_thumb_preview">
|
433 |
-
<?php
|
434 |
-
if ( ! empty( $old_value ) ) {
|
435 |
-
?>
|
436 |
-
<img id="sdm_thumbnail_image" src="<?php echo esc_url( $old_value ); ?>" style="max-width:200px;" />
|
437 |
-
<?php
|
438 |
-
}
|
439 |
-
?>
|
440 |
-
</span>
|
441 |
-
|
442 |
-
<?php
|
443 |
-
echo '<p class="description">';
|
444 |
-
_e( 'This thumbnail image will be used to create a fancy file download box if you want to use it.', 'simple-download-monitor' );
|
445 |
-
echo '</p>';
|
446 |
-
|
447 |
-
wp_nonce_field( 'sdm_thumbnail_box_nonce', 'sdm_thumbnail_box_nonce_check' );
|
448 |
-
}
|
449 |
-
|
450 |
-
public function display_sdm_stats_meta_box( $post ) {
|
451 |
-
//Stats metabox
|
452 |
-
$old_count = get_post_meta( $post->ID, 'sdm_count_offset', true );
|
453 |
-
$value = isset( $old_count ) && $old_count != '' ? $old_count : '0';
|
454 |
-
|
455 |
-
// Get checkbox for "disable download logging"
|
456 |
-
$no_logs = get_post_meta( $post->ID, 'sdm_item_no_log', true );
|
457 |
-
$checked = isset( $no_logs ) && $no_logs === 'on' ? 'checked="checked"' : '';
|
458 |
-
|
459 |
-
_e( 'These are the statistics for this download item.', 'simple-download-monitor' );
|
460 |
-
echo '<br /><br />';
|
461 |
-
|
462 |
-
global $wpdb;
|
463 |
-
$wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post->ID ) );
|
464 |
-
|
465 |
-
echo '<div class="sdm-download-edit-dl-count">';
|
466 |
-
_e( 'Number of Downloads:', 'simple-download-monitor' );
|
467 |
-
echo ' <strong>' . $wpdb->num_rows . '</strong>';
|
468 |
-
echo '</div>';
|
469 |
-
|
470 |
-
echo '<div class="sdm-download-edit-offset-count">';
|
471 |
-
_e( 'Offset Count: ', 'simple-download-monitor' );
|
472 |
-
echo '<br />';
|
473 |
-
echo ' <input type="text" size="10" name="sdm_count_offset" value="' . esc_attr( $value ) . '" />';
|
474 |
-
echo '<p class="description">' . __( 'Enter any positive or negative numerical value; to offset the download count shown to the visitors (when using the download counter shortcode).', 'simple-download-monitor' ) . '</p>';
|
475 |
-
echo '</div>';
|
476 |
-
|
477 |
-
echo '<br />';
|
478 |
-
echo '<div class="sdm-download-edit-disable-logging">';
|
479 |
-
echo '<input type="checkbox" name="sdm_item_no_log" ' . $checked . ' />';
|
480 |
-
echo '<span style="margin-left: 5px;"></span>';
|
481 |
-
_e( 'Disable download logging for this item.', 'simple-download-monitor' );
|
482 |
-
echo '</div>';
|
483 |
-
|
484 |
-
wp_nonce_field( 'sdm_count_offset_nonce', 'sdm_count_offset_nonce_check' );
|
485 |
-
}
|
486 |
-
|
487 |
-
public function display_sdm_other_details_meta_box( $post ) {
|
488 |
-
//Other details metabox
|
489 |
-
$show_date_fd = get_post_meta( $post->ID, 'sdm_item_show_date_fd', true );
|
490 |
-
$sdm_item_show_file_size_fd = get_post_meta( $post->ID, 'sdm_item_show_file_size_fd', true );
|
491 |
-
$sdm_item_show_item_version_fd = get_post_meta( $post->ID, 'sdm_item_show_item_version_fd', true );
|
492 |
-
|
493 |
-
$file_size = get_post_meta( $post->ID, 'sdm_item_file_size', true );
|
494 |
-
$file_size = isset( $file_size ) ? $file_size : '';
|
495 |
-
|
496 |
-
$version = get_post_meta( $post->ID, 'sdm_item_version', true );
|
497 |
-
$version = isset( $version ) ? $version : '';
|
498 |
-
|
499 |
-
$download_button_text = get_post_meta( $post->ID, 'sdm_download_button_text', true );
|
500 |
-
$download_button_text = isset( $download_button_text ) ? $download_button_text : '';
|
501 |
-
|
502 |
-
echo '<div class="sdm-download-edit-filesize">';
|
503 |
-
echo '<strong>' . __( 'File Size: ', 'simple-download-monitor' ) . '</strong>';
|
504 |
-
echo '<br />';
|
505 |
-
echo ' <input type="text" name="sdm_item_file_size" value="' . esc_attr( $file_size ) . '" size="20" />';
|
506 |
-
echo '<p class="description">' . __( 'Enter the size of this file (example value: 2.15 MB).', 'simple-download-monitor' ) . '</p>';
|
507 |
-
echo '<div class="sdm-download-edit-show-file-size"> <input id="sdm_item_show_file_size_fd" type="checkbox" name="sdm_item_show_file_size_fd" value="yes"' . checked( true, $sdm_item_show_file_size_fd, false ) . ' />';
|
508 |
-
echo '<label for="sdm_item_show_file_size_fd">' . __( 'Show file size in fancy display.', 'simple-download-monitor' ) . '</label> </div>';
|
509 |
-
echo '</div>';
|
510 |
-
echo '<hr />';
|
511 |
-
|
512 |
-
echo '<div class="sdm-download-edit-version">';
|
513 |
-
echo '<strong>' . __( 'Version: ', 'simple-download-monitor' ) . '</strong>';
|
514 |
-
echo '<br />';
|
515 |
-
echo ' <input type="text" name="sdm_item_version" value="' . esc_attr( $version ) . '" size="20" />';
|
516 |
-
echo '<p class="description">' . __( 'Enter the version number for this item if any (example value: v2.5.10).', 'simple-download-monitor' ) . '</p>';
|
517 |
-
echo '<div class="sdm-download-edit-show-item-version"> <input id="sdm_item_show_item_version_fd" type="checkbox" name="sdm_item_show_item_version_fd" value="yes"' . checked( true, $sdm_item_show_item_version_fd, false ) . ' />';
|
518 |
-
echo '<label for="sdm_item_show_item_version_fd">' . __( 'Show version number in fancy display.', 'simple-download-monitor' ) . '</label> </div>';
|
519 |
-
echo '</div>';
|
520 |
-
echo '<hr />';
|
521 |
-
|
522 |
-
echo '<div class="sdm-download-edit-show-publish-date">';
|
523 |
-
echo '<strong>' . __( 'Publish Date: ', 'simple-download-monitor' ) . '</strong>';
|
524 |
-
echo '<br /> <input id="sdm_item_show_date_fd" type="checkbox" name="sdm_item_show_date_fd" value="yes"' . checked( true, $show_date_fd, false ) . ' />';
|
525 |
-
echo '<label for="sdm_item_show_date_fd">' . __( 'Show download published date in fancy display.', 'simple-download-monitor' ) . '</label>';
|
526 |
-
echo '</div>';
|
527 |
-
echo '<hr />';
|
528 |
-
|
529 |
-
echo '<div class="sdm-download-edit-button-text">';
|
530 |
-
echo '<strong>' . __( 'Download Button Text: ', 'simple-download-monitor' ) . '</strong>';
|
531 |
-
echo '<br />';
|
532 |
-
echo "<input id='sdm-download-button-text' type='text' name='sdm_download_button_text' value='{$download_button_text}' />";
|
533 |
-
echo '<p class="description">' . __( 'You can use this field to customize the download now button text of this item.', 'simple-download-monitor' ) . '</p>';
|
534 |
-
echo '</div>';
|
535 |
-
|
536 |
-
wp_nonce_field( 'sdm_other_details_nonce', 'sdm_other_details_nonce_check' );
|
537 |
-
}
|
538 |
-
|
539 |
-
public function display_sdm_shortcode_meta_box( $post ) {
|
540 |
-
//Shortcode metabox
|
541 |
-
_e( 'The following shortcode can be used on posts or pages to embed a download now button for this file. You can also use the shortcode inserter (in the post editor) to add this shortcode to a post or page.', 'simple-download-monitor' );
|
542 |
-
echo '<br />';
|
543 |
-
$shortcode_text = '[sdm_download id="' . $post->ID . '" fancy="0"]';
|
544 |
-
echo "<input type='text' class='code' onfocus='this.select();' readonly='readonly' value='" . $shortcode_text . "' size='40'>";
|
545 |
-
echo '<br /><br />';
|
546 |
-
|
547 |
-
_e( 'The following shortcode can be used to show a download counter for this item.', 'simple-download-monitor' );
|
548 |
-
echo '<br />';
|
549 |
-
$shortcode_text = '[sdm_download_counter id="' . $post->ID . '"]';
|
550 |
-
echo "<input type='text' class='code' onfocus='this.select();' readonly='readonly' value='" . $shortcode_text . "' size='40'>";
|
551 |
-
|
552 |
-
echo '<br /><br />';
|
553 |
-
_e( 'Read the full shortcode usage documentation <a href="https://simple-download-monitor.com/miscellaneous-shortcodes-and-shortcode-parameters/" target="_blank">here</a>.', 'simple-download-monitor' );
|
554 |
-
}
|
555 |
-
|
556 |
-
public function sdm_save_description_meta_data( $post_id ) {
|
557 |
-
// Save Description metabox
|
558 |
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
559 |
-
return;
|
560 |
-
}
|
561 |
-
if ( ! isset( $_POST['sdm_description_box_nonce_check'] ) || ! wp_verify_nonce( $_POST['sdm_description_box_nonce_check'], 'sdm_description_box_nonce' ) ) {
|
562 |
-
return;
|
563 |
-
}
|
564 |
-
if ( isset( $_POST['sdm_description'] ) ) {
|
565 |
-
update_post_meta( $post_id, 'sdm_description', wp_kses_post( $_POST['sdm_description'] ) );
|
566 |
-
}
|
567 |
-
}
|
568 |
-
|
569 |
-
public function sdm_save_upload_meta_data( $post_id ) {
|
570 |
-
// Save File Upload metabox
|
571 |
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
572 |
-
return;
|
573 |
-
}
|
574 |
-
if ( ! isset( $_POST['sdm_upload_box_nonce_check'] ) || ! wp_verify_nonce( $_POST['sdm_upload_box_nonce_check'], 'sdm_upload_box_nonce' ) ) {
|
575 |
-
return;
|
576 |
-
}
|
577 |
-
|
578 |
-
if ( isset( $_POST['sdm_upload'] ) ) {
|
579 |
-
update_post_meta( $post_id, 'sdm_upload', sanitize_text_field( $_POST['sdm_upload'] ) );
|
580 |
-
}
|
581 |
-
}
|
582 |
-
|
583 |
-
public function sdm_save_dispatch_meta_data( $post_id ) {
|
584 |
-
// Save "Dispatch or Redirect" metabox
|
585 |
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
586 |
-
return;
|
587 |
-
}
|
588 |
-
if ( ! isset( $_POST['sdm_dispatch_box_nonce_check'] ) || ! wp_verify_nonce( $_POST['sdm_dispatch_box_nonce_check'], 'sdm_dispatch_box_nonce' ) ) {
|
589 |
-
return;
|
590 |
-
}
|
591 |
-
// Get POST-ed data as boolean value
|
592 |
-
$value = filter_input( INPUT_POST, 'sdm_item_dispatch', FILTER_VALIDATE_BOOLEAN );
|
593 |
-
update_post_meta( $post_id, 'sdm_item_dispatch', $value );
|
594 |
-
}
|
595 |
-
|
596 |
-
public function sdm_save_misc_properties_meta_data( $post_id ) {
|
597 |
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
598 |
-
return;
|
599 |
-
}
|
600 |
-
if ( ! isset( $_POST['sdm_misc_properties_box_nonce_check'] ) || ! wp_verify_nonce( $_POST['sdm_misc_properties_box_nonce_check'], 'sdm_misc_properties_box_nonce' ) ) {
|
601 |
-
return;
|
602 |
-
}
|
603 |
-
// Get POST-ed data as boolean value
|
604 |
-
$new_window_open = filter_input( INPUT_POST, 'sdm_item_new_window', FILTER_VALIDATE_BOOLEAN );
|
605 |
-
$sdm_item_hide_dl_button_single_download_page = filter_input( INPUT_POST, 'sdm_item_hide_dl_button_single_download_page', FILTER_VALIDATE_BOOLEAN );
|
606 |
-
$sdm_item_disable_single_download_page = filter_input( INPUT_POST, 'sdm_item_disable_single_download_page', FILTER_VALIDATE_BOOLEAN );
|
607 |
-
$sdm_item_anonymous_can_download = filter_input( INPUT_POST, 'sdm_item_anonymous_can_download', FILTER_VALIDATE_BOOLEAN );
|
608 |
-
|
609 |
-
//Save the data
|
610 |
-
update_post_meta( $post_id, 'sdm_item_new_window', $new_window_open );
|
611 |
-
update_post_meta( $post_id, 'sdm_item_hide_dl_button_single_download_page', $sdm_item_hide_dl_button_single_download_page );
|
612 |
-
update_post_meta( $post_id, 'sdm_item_disable_single_download_page', $sdm_item_disable_single_download_page );
|
613 |
-
update_post_meta( $post_id, 'sdm_item_anonymous_can_download', $sdm_item_anonymous_can_download );
|
614 |
-
}
|
615 |
-
|
616 |
-
public function sdm_save_thumbnail_meta_data( $post_id ) {
|
617 |
-
// Save Thumbnail Upload metabox
|
618 |
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
619 |
-
return;
|
620 |
-
}
|
621 |
-
if ( ! isset( $_POST['sdm_thumbnail_box_nonce_check'] ) || ! wp_verify_nonce( $_POST['sdm_thumbnail_box_nonce_check'], 'sdm_thumbnail_box_nonce' ) ) {
|
622 |
-
return;
|
623 |
-
}
|
624 |
-
if ( isset( $_POST['sdm_upload_thumbnail'] ) ) {
|
625 |
-
update_post_meta( $post_id, 'sdm_upload_thumbnail', sanitize_text_field( $_POST['sdm_upload_thumbnail'] ) );
|
626 |
-
}
|
627 |
-
}
|
628 |
-
|
629 |
-
public function sdm_save_statistics_meta_data( $post_id ) {
|
630 |
-
// Save Statistics Upload metabox
|
631 |
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
632 |
-
return;
|
633 |
-
}
|
634 |
-
if ( ! isset( $_POST['sdm_count_offset_nonce_check'] ) || ! wp_verify_nonce( $_POST['sdm_count_offset_nonce_check'], 'sdm_count_offset_nonce' ) ) {
|
635 |
-
return;
|
636 |
-
}
|
637 |
-
if ( isset( $_POST['sdm_count_offset'] ) && is_numeric( $_POST['sdm_count_offset'] ) ) {
|
638 |
-
update_post_meta( $post_id, 'sdm_count_offset', intval( $_POST['sdm_count_offset'] ) );
|
639 |
-
}
|
640 |
-
|
641 |
-
// Checkbox for disabling download logging for this item
|
642 |
-
if ( isset( $_POST['sdm_item_no_log'] ) ) {
|
643 |
-
update_post_meta( $post_id, 'sdm_item_no_log', sanitize_text_field( $_POST['sdm_item_no_log'] ) );
|
644 |
-
} else {
|
645 |
-
delete_post_meta( $post_id, 'sdm_item_no_log' );
|
646 |
-
}
|
647 |
-
}
|
648 |
-
|
649 |
-
public function sdm_save_other_details_meta_data( $post_id ) {
|
650 |
-
// Save Statistics Upload metabox
|
651 |
-
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
652 |
-
return;
|
653 |
-
}
|
654 |
-
if ( ! isset( $_POST['sdm_other_details_nonce_check'] ) || ! wp_verify_nonce( $_POST['sdm_other_details_nonce_check'], 'sdm_other_details_nonce' ) ) {
|
655 |
-
return;
|
656 |
-
}
|
657 |
-
|
658 |
-
$show_date_fd = filter_input( INPUT_POST, 'sdm_item_show_date_fd', FILTER_VALIDATE_BOOLEAN );
|
659 |
-
update_post_meta( $post_id, 'sdm_item_show_date_fd', $show_date_fd );
|
660 |
-
|
661 |
-
$sdm_item_show_file_size_fd = filter_input( INPUT_POST, 'sdm_item_show_file_size_fd', FILTER_VALIDATE_BOOLEAN );
|
662 |
-
update_post_meta( $post_id, 'sdm_item_show_file_size_fd', $sdm_item_show_file_size_fd );
|
663 |
-
|
664 |
-
$sdm_item_show_item_version_fd = filter_input( INPUT_POST, 'sdm_item_show_item_version_fd', FILTER_VALIDATE_BOOLEAN );
|
665 |
-
update_post_meta( $post_id, 'sdm_item_show_item_version_fd', $sdm_item_show_item_version_fd );
|
666 |
-
|
667 |
-
if ( isset( $_POST['sdm_item_file_size'] ) ) {
|
668 |
-
update_post_meta( $post_id, 'sdm_item_file_size', sanitize_text_field( $_POST['sdm_item_file_size'] ) );
|
669 |
-
}
|
670 |
-
|
671 |
-
if ( isset( $_POST['sdm_item_version'] ) ) {
|
672 |
-
update_post_meta( $post_id, 'sdm_item_version', sanitize_text_field( $_POST['sdm_item_version'] ) );
|
673 |
-
}
|
674 |
-
|
675 |
-
if ( isset( $_POST['sdm_download_button_text'] ) ) {
|
676 |
-
update_post_meta( $post_id, 'sdm_download_button_text', sanitize_text_field( $_POST['sdm_download_button_text'] ) );
|
677 |
-
}
|
678 |
-
}
|
679 |
-
|
680 |
public function sdm_remove_view_link_cpt( $action, $post ) {
|
681 |
|
682 |
// Only execute on SDM CPT posts page
|
@@ -715,8 +379,8 @@ class simpleDownloadManager {
|
|
715 |
|
716 |
add_settings_field( 'admin_log_unique', __( 'Log Unique IP', 'simple-download-monitor' ), array( $this, 'admin_log_unique' ), 'admin_options_section', 'admin_options' );
|
717 |
add_settings_field( 'admin_do_not_capture_ip', __( 'Do Not Capture IP Address', 'simple-download-monitor' ), array( $this, 'admin_do_not_capture_ip' ), 'admin_options_section', 'admin_options' );
|
718 |
-
|
719 |
-
|
720 |
add_settings_field( 'admin_dont_log_bots', __( 'Do Not Count Downloads from Bots', 'simple-download-monitor' ), array( $this, 'admin_dont_log_bots' ), 'admin_options_section', 'admin_options' );
|
721 |
add_settings_field( 'admin_no_logs', __( 'Disable Download Logs', 'simple-download-monitor' ), array( $this, 'admin_no_logs_cb' ), 'admin_options_section', 'admin_options' );
|
722 |
|
@@ -751,40 +415,40 @@ class simpleDownloadManager {
|
|
751 |
|
752 |
public function general_options_cb() {
|
753 |
//Set the message that will be shown below the general options settings heading
|
754 |
-
|
755 |
}
|
756 |
|
757 |
public function user_login_options_cb() {
|
758 |
//Set the message that will be shown below the user login related settings heading
|
759 |
-
|
760 |
}
|
761 |
|
762 |
public function admin_options_cb() {
|
763 |
//Set the message that will be shown below the admin options settings heading
|
764 |
-
|
765 |
}
|
766 |
|
767 |
public function sdm_colors_cb() {
|
768 |
//Set the message that will be shown below the color options settings heading
|
769 |
-
|
770 |
}
|
771 |
|
772 |
public function sdm_debug_cb() {
|
773 |
//Set the message that will be shown below the debug options settings heading
|
774 |
-
|
775 |
}
|
776 |
|
777 |
public function sdm_deldata_cb() {
|
778 |
//Set the message that will be shown below the debug options settings heading
|
779 |
-
|
780 |
-
echo '<p><b>' .
|
781 |
-
echo '<p><button id="sdmDeleteData" class="button" style="color:red;">' .
|
782 |
echo '<br />';
|
783 |
}
|
784 |
|
785 |
public function recaptcha_options_cb() {
|
786 |
//Set the message that will be shown below the recaptcha options settings heading
|
787 |
-
|
788 |
}
|
789 |
|
790 |
public function termscond_options_cb() {
|
@@ -793,102 +457,110 @@ class simpleDownloadManager {
|
|
793 |
|
794 |
public function adsense_options_cb() {
|
795 |
//Set the message that will be shown below the adsense/ad code settings heading
|
796 |
-
|
797 |
}
|
798 |
|
799 |
public function maps_api_options_cb() {
|
800 |
-
|
801 |
}
|
802 |
|
803 |
public function recaptcha_enable_cb() {
|
804 |
$main_opts = get_option( 'sdm_advanced_options' );
|
805 |
echo '<input name="sdm_advanced_options[recaptcha_enable]" id="recaptcha_enable" type="checkbox" ' . checked( 1, isset( $main_opts['recaptcha_enable'] ), false ) . ' /> ';
|
806 |
-
echo '<p class="description">' .
|
807 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
808 |
}
|
809 |
|
810 |
public function recaptcha_site_key_cb() {
|
811 |
$main_opts = get_option( 'sdm_advanced_options' );
|
812 |
$value = isset( $main_opts['recaptcha_site_key'] ) ? $main_opts['recaptcha_site_key'] : '';
|
813 |
-
echo '<input size="100" name="sdm_advanced_options[recaptcha_site_key]" id="recaptcha_site_key" type="text" value="' . $value . '" /> ';
|
814 |
-
echo '<p class="description">' .
|
815 |
}
|
816 |
|
817 |
public function recaptcha_secret_key_cb() {
|
818 |
$main_opts = get_option( 'sdm_advanced_options' );
|
819 |
$value = isset( $main_opts['recaptcha_secret_key'] ) ? $main_opts['recaptcha_secret_key'] : '';
|
820 |
-
echo '<input size="100" name="sdm_advanced_options[recaptcha_secret_key]" id="recaptcha_secret_key" type="text" value="' . $value . '" /> ';
|
821 |
-
echo '<p class="description">' .
|
822 |
}
|
823 |
|
824 |
public function hide_download_count_cb() {
|
825 |
$main_opts = get_option( 'sdm_downloads_options' );
|
826 |
echo '<input name="sdm_downloads_options[general_hide_donwload_count]" id="general_hide_download_count" type="checkbox" ' . checked( 1, isset( $main_opts['general_hide_donwload_count'] ), false ) . ' /> ';
|
827 |
-
echo '<label for="general_hide_download_count">' .
|
828 |
}
|
829 |
|
830 |
public function general_default_dispatch_value_cb() {
|
831 |
$main_opts = get_option( 'sdm_downloads_options' );
|
832 |
$value = isset( $main_opts['general_default_dispatch_value'] ) && $main_opts['general_default_dispatch_value'];
|
833 |
echo '<input name="sdm_downloads_options[general_default_dispatch_value]" id="general_default_dispatch_value" type="checkbox" value="1"' . checked( true, $value, false ) . ' />';
|
834 |
-
echo '<label for="general_default_dispatch_value">' .
|
835 |
}
|
836 |
|
837 |
public function general_only_logged_in_can_download_cb() {
|
838 |
$main_opts = get_option( 'sdm_downloads_options' );
|
839 |
$value = isset( $main_opts['only_logged_in_can_download'] ) && $main_opts['only_logged_in_can_download'];
|
840 |
echo '<input name="sdm_downloads_options[only_logged_in_can_download]" id="only_logged_in_can_download" type="checkbox" value="1"' . checked( true, $value, false ) . ' />';
|
841 |
-
echo '<label for="only_logged_in_can_download">' .
|
842 |
}
|
843 |
|
844 |
public function redirect_user_back_to_download_page_cb() {
|
845 |
$main_opts = get_option( 'sdm_downloads_options' );
|
846 |
$value = isset( $main_opts['redirect_user_back_to_download_page'] ) && $main_opts['redirect_user_back_to_download_page'];
|
847 |
echo '<input name="sdm_downloads_options[redirect_user_back_to_download_page]" id="redirect_user_back_to_download_page" type="checkbox" value="1"' . checked( true, $value, false ) . ' />';
|
848 |
-
echo '<label for="redirect_user_back_to_download_page">' .
|
849 |
}
|
850 |
|
851 |
public function general_login_page_url_cb() {
|
852 |
$main_opts = get_option( 'sdm_downloads_options' );
|
853 |
$value = isset( $main_opts['general_login_page_url'] ) ? $main_opts['general_login_page_url'] : '';
|
854 |
-
echo '<input size="100" name="sdm_downloads_options[general_login_page_url]" id="general_login_page_url" type="text" value="' . $value . '" />';
|
855 |
-
echo '<p class="description">' .
|
856 |
}
|
857 |
|
858 |
public function admin_log_unique() {
|
859 |
$main_opts = get_option( 'sdm_downloads_options' );
|
860 |
echo '<input name="sdm_downloads_options[admin_log_unique]" id="admin_log_unique" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_log_unique'] ), false ) . ' /> ';
|
861 |
-
echo '<label for="admin_log_unique">' .
|
862 |
}
|
863 |
|
864 |
public function admin_do_not_capture_ip() {
|
865 |
$main_opts = get_option( 'sdm_downloads_options' );
|
866 |
echo '<input name="sdm_downloads_options[admin_do_not_capture_ip]" id="admin_do_not_capture_ip" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_do_not_capture_ip'] ), false ) . ' /> ';
|
867 |
-
echo '<label for="admin_do_not_capture_ip">' .
|
868 |
}
|
869 |
|
870 |
public function admin_do_not_capture_user_agent() {
|
871 |
$main_opts = get_option( 'sdm_downloads_options' );
|
872 |
echo '<input name="sdm_downloads_options[admin_do_not_capture_user_agent]" id="admin_do_not_capture_user_agent" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_do_not_capture_user_agent'] ), false ) . ' /> ';
|
873 |
-
echo '<label for="admin_do_not_capture_user_agent">' .
|
874 |
}
|
875 |
|
876 |
public function admin_do_not_capture_referrer_url() {
|
877 |
$main_opts = get_option( 'sdm_downloads_options' );
|
878 |
echo '<input name="sdm_downloads_options[admin_do_not_capture_referrer_url]" id="admin_do_not_capture_referrer_url" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_do_not_capture_referrer_url'] ), false ) . ' /> ';
|
879 |
-
echo '<label for="admin_do_not_capture_referrer_url">' .
|
880 |
}
|
881 |
|
882 |
public function admin_dont_log_bots() {
|
883 |
$main_opts = get_option( 'sdm_downloads_options' );
|
884 |
echo '<input name="sdm_downloads_options[admin_dont_log_bots]" id="admin_dont_log_bots" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_dont_log_bots'] ), false ) . ' /> ';
|
885 |
-
echo '<label for="admin_dont_log_bots">' .
|
886 |
}
|
887 |
|
888 |
public function admin_no_logs_cb() {
|
889 |
$main_opts = get_option( 'sdm_downloads_options' );
|
890 |
echo '<input name="sdm_downloads_options[admin_no_logs]" id="admin_no_logs" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_no_logs'] ), false ) . ' /> ';
|
891 |
-
echo '<label for="admin_no_logs">' .
|
892 |
}
|
893 |
|
894 |
public function download_button_color_cb() {
|
@@ -899,7 +571,7 @@ class simpleDownloadManager {
|
|
899 |
|
900 |
echo '<select name="sdm_downloads_options[download_button_color]" id="download_button_color" class="sdm_opts_ajax_dropdowns">';
|
901 |
foreach ( $color_opts as $color_class => $color_name ) {
|
902 |
-
echo '<option value="' . $color_class . '"' . selected( $color_class, $color_opt, false ) . '>' . $color_name . '</option>';
|
903 |
}
|
904 |
echo '</select> ';
|
905 |
esc_html_e( 'Adjusts the color of the "Download Now" button.', 'simple-download-monitor' );
|
@@ -908,40 +580,48 @@ class simpleDownloadManager {
|
|
908 |
public function enable_debug_cb() {
|
909 |
$main_opts = get_option( 'sdm_downloads_options' );
|
910 |
echo '<input name="sdm_downloads_options[enable_debug]" id="enable_debug" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['enable_debug'] ), false ) . ' /> ';
|
911 |
-
echo '<label for="enable_debug">' .
|
912 |
-
'<p class="description"><a href="' . get_admin_url() . '?sdm-action=view_log" target="_blank">' .
|
913 |
-
|
914 |
-
|
915 |
-
'<a id="sdm-reset-log" href="#0" style="color: red">' .
|
916 |
-
|
917 |
}
|
918 |
|
919 |
public function termscond_enable_cb() {
|
920 |
$main_opts = get_option( 'sdm_advanced_options' );
|
921 |
echo '<input name="sdm_advanced_options[termscond_enable]" id="termscond_enable" type="checkbox" ' . checked( 1, isset( $main_opts['termscond_enable'] ), false ) . ' /> ';
|
922 |
-
echo '<p class="description">' .
|
923 |
}
|
924 |
|
925 |
public function termscond_url_cb() {
|
926 |
$main_opts = get_option( 'sdm_advanced_options' );
|
927 |
$value = isset( $main_opts['termscond_url'] ) ? $main_opts['termscond_url'] : '';
|
928 |
-
echo '<input size="100" name="sdm_advanced_options[termscond_url]" id="termscond_url" type="text" value="' . $value . '" /> ';
|
929 |
-
echo '<p class="description">' .
|
930 |
}
|
931 |
|
932 |
public function adsense_below_description_cb() {
|
933 |
$main_opts = get_option( 'sdm_advanced_options' );
|
934 |
$value = isset( $main_opts['adsense_below_description'] ) ? $main_opts['adsense_below_description'] : '';
|
935 |
//echo '<input size="100" name="sdm_advanced_options[adsense_below_description]" id="adsense_below_description" type="text" value="'.$value.'" /> ';
|
936 |
-
echo '<textarea name="sdm_advanced_options[adsense_below_description]" id="adsense_below_description" rows="6" cols="60">' . $value . '</textarea>';
|
937 |
-
echo '<p class="description">' .
|
938 |
}
|
939 |
|
940 |
public function maps_api_key_cb() {
|
941 |
$main_opts = get_option( 'sdm_advanced_options' );
|
942 |
$value = isset( $main_opts['maps_api_key'] ) ? $main_opts['maps_api_key'] : '';
|
943 |
-
echo '<input size="100" name="sdm_advanced_options[maps_api_key]" id="maps_api_key" type="text" value="' . $value . '" />';
|
944 |
-
echo '<p class="description">' .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
945 |
}
|
946 |
|
947 |
public function sdm_add_clone_record_btn( $action, $post ) {
|
@@ -967,7 +647,7 @@ class simpleDownloadManager {
|
|
967 |
array(
|
968 |
'action' => 'sdm_clone_post',
|
969 |
'post' => $post_id,
|
970 |
-
'ref' =>
|
971 |
'_nonce' => wp_create_nonce( 'sdm_downloads' ),
|
972 |
),
|
973 |
esc_url( admin_url( 'admin.php' ) )
|
@@ -978,15 +658,14 @@ class simpleDownloadManager {
|
|
978 |
|
979 |
global $wpdb;
|
980 |
if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'sdm_clone_post' == $_REQUEST['action'] ) ) ) {
|
981 |
-
wp_die(
|
982 |
}
|
983 |
|
984 |
/*
|
985 |
* Nonce verification
|
986 |
*/
|
987 |
-
|
988 |
-
|
989 |
-
}
|
990 |
|
991 |
/*
|
992 |
* get the original post id
|
@@ -1066,7 +745,7 @@ class simpleDownloadManager {
|
|
1066 |
wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
|
1067 |
exit;
|
1068 |
} else {
|
1069 |
-
wp_die(
|
1070 |
}
|
1071 |
}
|
1072 |
|
@@ -1095,45 +774,13 @@ function sdm_tiny_get_post_ids_ajax_call() {
|
|
1095 |
);
|
1096 |
}
|
1097 |
|
1098 |
-
$response =
|
1099 |
array(
|
1100 |
'success' => true,
|
1101 |
'test' => $test,
|
1102 |
-
)
|
1103 |
-
);
|
1104 |
-
|
1105 |
-
header( 'Content-Type: application/json' );
|
1106 |
-
echo $response;
|
1107 |
-
exit;
|
1108 |
-
}
|
1109 |
-
|
1110 |
-
//Remove Thumbnail Image
|
1111 |
-
//add_action('wp_ajax_nopriv_sdm_remove_thumbnail_image', '');//This is only available to logged-in users
|
1112 |
-
add_action( 'wp_ajax_sdm_remove_thumbnail_image', 'sdm_remove_thumbnail_image_ajax_call' ); //Execute this for authenticated users only
|
1113 |
-
|
1114 |
-
function sdm_remove_thumbnail_image_ajax_call() {
|
1115 |
-
if ( ! current_user_can( 'edit_posts' ) ) {
|
1116 |
-
//Permission denied
|
1117 |
-
wp_die( __( 'Permission denied!', 'simple-download-monitor' ) );
|
1118 |
-
exit;
|
1119 |
-
}
|
1120 |
-
|
1121 |
-
//Go ahead with the thumbnail removal
|
1122 |
-
$post_id = intval( $_POST['post_id_del'] );
|
1123 |
-
$key_exists = metadata_exists( 'post', $post_id, 'sdm_upload_thumbnail' );
|
1124 |
-
if ( $key_exists ) {
|
1125 |
-
$success = delete_post_meta( $post_id, 'sdm_upload_thumbnail' );
|
1126 |
-
if ( $success ) {
|
1127 |
-
$response = json_encode( array( 'success' => true ) );
|
1128 |
-
}
|
1129 |
-
} else {
|
1130 |
-
// in order for frontend script to not display "Ajax error", let's return some data
|
1131 |
-
$response = json_encode( array( 'not_exists' => true ) );
|
1132 |
-
}
|
1133 |
|
1134 |
-
|
1135 |
-
echo $response;
|
1136 |
-
exit;
|
1137 |
}
|
1138 |
|
1139 |
// Populate category tree
|
@@ -1142,8 +789,10 @@ add_action( 'wp_ajax_sdm_pop_cats', 'sdm_pop_cats_ajax_call' );
|
|
1142 |
|
1143 |
function sdm_pop_cats_ajax_call() {
|
1144 |
|
1145 |
-
$cat_slug
|
1146 |
-
$
|
|
|
|
|
1147 |
// Query custom posts based on taxonomy slug
|
1148 |
$posts = get_posts(
|
1149 |
array(
|
@@ -1175,10 +824,8 @@ function sdm_pop_cats_ajax_call() {
|
|
1175 |
}
|
1176 |
|
1177 |
// Generate ajax response
|
1178 |
-
$response =
|
1179 |
-
|
1180 |
-
echo $response;
|
1181 |
-
exit;
|
1182 |
}
|
1183 |
|
1184 |
/*
|
@@ -1221,20 +868,20 @@ function sdm_downloads_columns_content( $column_name, $post_ID ) {
|
|
1221 |
$old_thumbnail = get_post_meta( $post_ID, 'sdm_upload_thumbnail', true );
|
1222 |
//$old_value = isset($old_thumbnail) ? $old_thumbnail : '';
|
1223 |
if ( $old_thumbnail ) {
|
1224 |
-
echo '<p class="sdm_downloads_thumbnail_in_admin_listing"><img src="' . $old_thumbnail . '" style="width:50px;height:50px;" /></p>';
|
1225 |
}
|
1226 |
}
|
1227 |
if ( $column_name == 'sdm_downloads_id' ) {
|
1228 |
-
echo '<p class="sdm_downloads_postid">' . $post_ID . '</p>';
|
1229 |
}
|
1230 |
if ( $column_name == 'sdm_downloads_file' ) {
|
1231 |
$old_file = get_post_meta( $post_ID, 'sdm_upload', true );
|
1232 |
$file = isset( $old_file ) ? $old_file : '--';
|
1233 |
-
echo '<p class="sdm_downloads_file">' . $file . '</p>';
|
1234 |
}
|
1235 |
if ( $column_name == 'sdm_downloads_count' ) {
|
1236 |
global $wpdb;
|
1237 |
$wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post_ID ) );
|
1238 |
-
echo '<p class="sdm_downloads_count">' . $wpdb->num_rows . '</p>';
|
1239 |
}
|
1240 |
}
|
3 |
* Plugin Name: Simple Download Monitor
|
4 |
* Plugin URI: https://simple-download-monitor.com/
|
5 |
* Description: Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
|
6 |
+
* Version: 3.9.7
|
7 |
* Author: Tips and Tricks HQ, Ruhul Amin, Josh Lobe
|
8 |
* Author URI: https://www.tipsandtricks-hq.com/development-center
|
9 |
* License: GPL2
|
14 |
exit;
|
15 |
}
|
16 |
|
17 |
+
define( 'WP_SIMPLE_DL_MONITOR_VERSION', '3.9.7' );
|
18 |
define( 'WP_SIMPLE_DL_MONITOR_DIR_NAME', dirname( plugin_basename( __FILE__ ) ) );
|
19 |
define( 'WP_SIMPLE_DL_MONITOR_URL', plugins_url( '', __FILE__ ) );
|
20 |
define( 'WP_SIMPLE_DL_MONITOR_PATH', plugin_dir_path( __FILE__ ) );
|
116 |
add_action( 'wp_ajax_sdm_reset_log', 'sdm_reset_log_handler' );
|
117 |
add_action( 'wp_ajax_sdm_delete_data', 'sdm_delete_data_handler' );
|
118 |
|
119 |
+
if ( ! is_admin() || ! user_can( wp_get_current_user(), 'administrator' ) ) {
|
120 |
+
// user is not an admin
|
121 |
+
return;
|
122 |
+
}
|
123 |
+
|
124 |
+
// View log
|
125 |
+
$action = filter_input( INPUT_GET, 'sdm-action', FILTER_SANITIZE_STRING );
|
126 |
+
if ( ! empty( $action ) ) {
|
127 |
+
if ( $action === 'view_log' ) {
|
128 |
+
check_admin_referer( 'sdm_view_log_nonce' );
|
129 |
+
$logfile = fopen( WP_SDM_LOG_FILE, 'rb' );
|
130 |
+
header( 'Content-Type: text/plain' );
|
131 |
+
fpassthru( $logfile );
|
132 |
+
die;
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
// Export log to CSV
|
137 |
+
if ( isset( $_POST['sdm_export_log_entries'] ) ) {
|
138 |
+
check_admin_referer( 'sdm_export_logs', 'sdm_export_logs_nonce' );
|
139 |
+
|
140 |
+
// datetime fileds
|
141 |
+
if ( isset( $_POST['sdm_stats_start_date'] ) ) {
|
142 |
+
$start_date = sanitize_text_field( wp_unslash( $_POST['sdm_stats_start_date'] ) );
|
143 |
+
} else {
|
144 |
+
// default start date is 30 days back
|
145 |
+
$start_date = date( 'Y-m-d', time() - 60 * 60 * 24 * 30 );
|
146 |
+
}
|
147 |
+
|
148 |
+
if ( isset( $_POST['sdm_stats_end_date'] ) ) {
|
149 |
+
$end_date = sanitize_text_field( wp_unslash( $_POST['sdm_stats_end_date'] ) );
|
150 |
+
} else {
|
151 |
+
$end_date = date( 'Y-m-d', time() );
|
152 |
+
}
|
153 |
+
|
154 |
+
if ( sdm_validate_date_field( array( $start_date, $end_date ) ) ) {
|
155 |
+
sdm_export_download_logs_to_csv( $start_date, $end_date );
|
156 |
+
} else {
|
157 |
+
add_action(
|
158 |
+
'admin_notices',
|
159 |
+
function() {
|
160 |
+
echo '<div id="message" class="error"><p>';
|
161 |
+
esc_html_e( 'Please select a valid date range.', 'simple-download-monitor' );
|
162 |
+
echo '</p></div>';
|
163 |
}
|
164 |
+
);
|
165 |
}
|
166 |
}
|
167 |
}
|
168 |
|
169 |
function sdm_reset_log_handler() {
|
170 |
+
if ( ! check_ajax_referer( 'sdm_delete_data', 'nonce', false ) ) {
|
171 |
+
//nonce check failed
|
172 |
+
wp_die( 0 );
|
173 |
+
}
|
174 |
+
|
175 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
176 |
+
//not permissions for current user
|
177 |
+
wp_die( 0 );
|
178 |
+
}
|
179 |
+
|
180 |
SDM_Debug::reset_log();
|
181 |
echo '1';
|
182 |
wp_die();
|
187 |
//nonce check failed
|
188 |
wp_die( 0 );
|
189 |
}
|
190 |
+
|
191 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
192 |
+
//not permissions for current user
|
193 |
+
wp_die( 0 );
|
194 |
+
}
|
195 |
+
|
196 |
global $wpdb;
|
197 |
//let's find and delete smd_download posts and meta
|
198 |
$posts = $wpdb->get_results( 'SELECT id FROM ' . $wpdb->prefix . 'posts WHERE post_type="sdm_downloads"', ARRAY_A );
|
262 |
|
263 |
if ( is_admin() ) {
|
264 |
add_action( 'admin_menu', array( $this, 'sdm_create_menu_pages' ) ); // Create admin pages
|
|
|
265 |
|
266 |
+
require_once WP_SIMPLE_DL_MONITOR_PATH . 'includes/admin-side/sdm-admin-edit-download.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
|
268 |
add_action( 'admin_enqueue_scripts', array( $this, 'sdm_admin_scripts' ) ); // Register admin scripts
|
269 |
add_action( 'admin_print_styles', array( $this, 'sdm_admin_styles' ) ); // Register admin styles
|
298 |
'image_removed' => __( 'Image Successfully Removed', 'simple-download-monitor' ),
|
299 |
'ajax_error' => __( 'Error with AJAX', 'simple-download-monitor' ),
|
300 |
);
|
301 |
+
|
302 |
+
$sdm_admin = array(
|
303 |
+
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
304 |
+
'post_id' => $post->ID,
|
305 |
+
);
|
306 |
+
|
307 |
wp_localize_script( 'sdm-upload', 'sdm_translations', $sdmTranslations );
|
308 |
+
wp_localize_script( 'sdm-upload', 'sdm_admin', $sdm_admin );
|
309 |
}
|
310 |
}
|
311 |
|
341 |
sdm_handle_admin_menu();
|
342 |
}
|
343 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
public function sdm_remove_view_link_cpt( $action, $post ) {
|
345 |
|
346 |
// Only execute on SDM CPT posts page
|
379 |
|
380 |
add_settings_field( 'admin_log_unique', __( 'Log Unique IP', 'simple-download-monitor' ), array( $this, 'admin_log_unique' ), 'admin_options_section', 'admin_options' );
|
381 |
add_settings_field( 'admin_do_not_capture_ip', __( 'Do Not Capture IP Address', 'simple-download-monitor' ), array( $this, 'admin_do_not_capture_ip' ), 'admin_options_section', 'admin_options' );
|
382 |
+
add_settings_field( 'admin_do_not_capture_user_agent', __( 'Do Not Capture User Agent', 'simple-download-monitor' ), array( $this, 'admin_do_not_capture_user_agent' ), 'admin_options_section', 'admin_options' );
|
383 |
+
add_settings_field( 'admin_do_not_capture_referrer_url', __( 'Do Not Capture Referrer URL', 'simple-download-monitor' ), array( $this, 'admin_do_not_capture_referrer_url' ), 'admin_options_section', 'admin_options' );
|
384 |
add_settings_field( 'admin_dont_log_bots', __( 'Do Not Count Downloads from Bots', 'simple-download-monitor' ), array( $this, 'admin_dont_log_bots' ), 'admin_options_section', 'admin_options' );
|
385 |
add_settings_field( 'admin_no_logs', __( 'Disable Download Logs', 'simple-download-monitor' ), array( $this, 'admin_no_logs_cb' ), 'admin_options_section', 'admin_options' );
|
386 |
|
415 |
|
416 |
public function general_options_cb() {
|
417 |
//Set the message that will be shown below the general options settings heading
|
418 |
+
esc_html_e( 'General options settings', 'simple-download-monitor' );
|
419 |
}
|
420 |
|
421 |
public function user_login_options_cb() {
|
422 |
//Set the message that will be shown below the user login related settings heading
|
423 |
+
esc_html_e( 'Visitor login related settings (useful if you only want to allow logged-in users to be able to download files.', 'simple-download-monitor' );
|
424 |
}
|
425 |
|
426 |
public function admin_options_cb() {
|
427 |
//Set the message that will be shown below the admin options settings heading
|
428 |
+
esc_html_e( 'Admin options settings', 'simple-download-monitor' );
|
429 |
}
|
430 |
|
431 |
public function sdm_colors_cb() {
|
432 |
//Set the message that will be shown below the color options settings heading
|
433 |
+
esc_html_e( 'Front End colors settings', 'simple-download-monitor' );
|
434 |
}
|
435 |
|
436 |
public function sdm_debug_cb() {
|
437 |
//Set the message that will be shown below the debug options settings heading
|
438 |
+
esc_html_e( 'Debug settings', 'simple-download-monitor' );
|
439 |
}
|
440 |
|
441 |
public function sdm_deldata_cb() {
|
442 |
//Set the message that will be shown below the debug options settings heading
|
443 |
+
esc_html_e( 'You can delete all the data related to this plugin from database using the button below. Useful when you\'re uninstalling the plugin and don\'t want any leftovers remaining.', 'simple-download-monitor' );
|
444 |
+
echo '<p><b>' . esc_html__( 'Warning', 'simple-download-monitor' ) . ': </b> ' . esc_html__( 'this can\'t be undone. All settings, download items, download logs will be deleted.', 'simple-download-monitor' ) . '</p>';
|
445 |
+
echo '<p><button id="sdmDeleteData" class="button" style="color:red;">' . esc_html__( 'Delete all data and deactivate plugin', 'simple-download-monitor' ) . '</button></p>';
|
446 |
echo '<br />';
|
447 |
}
|
448 |
|
449 |
public function recaptcha_options_cb() {
|
450 |
//Set the message that will be shown below the recaptcha options settings heading
|
451 |
+
esc_html_e( 'Google Captcha (reCAPTCHA) options', 'simple-download-monitor' );
|
452 |
}
|
453 |
|
454 |
public function termscond_options_cb() {
|
457 |
|
458 |
public function adsense_options_cb() {
|
459 |
//Set the message that will be shown below the adsense/ad code settings heading
|
460 |
+
esc_html_e( 'You can use this section to insert adsense or other ad code inside the download item output', 'simple-download-monitor' );
|
461 |
}
|
462 |
|
463 |
public function maps_api_options_cb() {
|
464 |
+
esc_html_e( 'Google Maps API key is required to display the "Downloads by Country" chart.', 'simple-download-monitor' );
|
465 |
}
|
466 |
|
467 |
public function recaptcha_enable_cb() {
|
468 |
$main_opts = get_option( 'sdm_advanced_options' );
|
469 |
echo '<input name="sdm_advanced_options[recaptcha_enable]" id="recaptcha_enable" type="checkbox" ' . checked( 1, isset( $main_opts['recaptcha_enable'] ), false ) . ' /> ';
|
470 |
+
echo '<p class="description">' . wp_kses(
|
471 |
+
__( 'Check this box if you want to use <a href="https://www.google.com/recaptcha/admin" target="_blank">reCAPTCHA</a>. ', 'simple-download-monitor' ),
|
472 |
+
array(
|
473 |
+
'a' => array(
|
474 |
+
'href' => array(),
|
475 |
+
'target' => array(),
|
476 |
+
),
|
477 |
+
)
|
478 |
+
) . '</p>';
|
479 |
+
echo '<p class="description">' . esc_html__( 'The captcha option adds a captcha to the download now buttons.', 'simple-download-monitor' ) . '</p>';
|
480 |
}
|
481 |
|
482 |
public function recaptcha_site_key_cb() {
|
483 |
$main_opts = get_option( 'sdm_advanced_options' );
|
484 |
$value = isset( $main_opts['recaptcha_site_key'] ) ? $main_opts['recaptcha_site_key'] : '';
|
485 |
+
echo '<input size="100" name="sdm_advanced_options[recaptcha_site_key]" id="recaptcha_site_key" type="text" value="' . esc_attr( $value ) . '" /> ';
|
486 |
+
echo '<p class="description">' . esc_html__( 'The site key for the reCAPTCHA API', 'simple-download-monitor' ) . '</p>';
|
487 |
}
|
488 |
|
489 |
public function recaptcha_secret_key_cb() {
|
490 |
$main_opts = get_option( 'sdm_advanced_options' );
|
491 |
$value = isset( $main_opts['recaptcha_secret_key'] ) ? $main_opts['recaptcha_secret_key'] : '';
|
492 |
+
echo '<input size="100" name="sdm_advanced_options[recaptcha_secret_key]" id="recaptcha_secret_key" type="text" value="' . esc_attr( $value ) . '" /> ';
|
493 |
+
echo '<p class="description">' . esc_html__( 'The secret key for the reCAPTCHA API', 'simple-download-monitor' ) . '</p>';
|
494 |
}
|
495 |
|
496 |
public function hide_download_count_cb() {
|
497 |
$main_opts = get_option( 'sdm_downloads_options' );
|
498 |
echo '<input name="sdm_downloads_options[general_hide_donwload_count]" id="general_hide_download_count" type="checkbox" ' . checked( 1, isset( $main_opts['general_hide_donwload_count'] ), false ) . ' /> ';
|
499 |
+
echo '<label for="general_hide_download_count">' . esc_html__( 'Hide the download count that is shown in some of the fancy templates.', 'simple-download-monitor' ) . '</label>';
|
500 |
}
|
501 |
|
502 |
public function general_default_dispatch_value_cb() {
|
503 |
$main_opts = get_option( 'sdm_downloads_options' );
|
504 |
$value = isset( $main_opts['general_default_dispatch_value'] ) && $main_opts['general_default_dispatch_value'];
|
505 |
echo '<input name="sdm_downloads_options[general_default_dispatch_value]" id="general_default_dispatch_value" type="checkbox" value="1"' . checked( true, $value, false ) . ' />';
|
506 |
+
echo '<label for="general_default_dispatch_value">' . esc_html__( 'When you create a new download item, The PHP Dispatching option should be enabled by default. PHP Dispatching keeps the URL of the downloadable files hidden.', 'simple-download-monitor' ) . '</label>';
|
507 |
}
|
508 |
|
509 |
public function general_only_logged_in_can_download_cb() {
|
510 |
$main_opts = get_option( 'sdm_downloads_options' );
|
511 |
$value = isset( $main_opts['only_logged_in_can_download'] ) && $main_opts['only_logged_in_can_download'];
|
512 |
echo '<input name="sdm_downloads_options[only_logged_in_can_download]" id="only_logged_in_can_download" type="checkbox" value="1"' . checked( true, $value, false ) . ' />';
|
513 |
+
echo '<label for="only_logged_in_can_download">' . esc_html__( 'Enable this option if you want to allow downloads only for logged-in users. When enabled, anonymous users clicking on the download button will receive an error message.', 'simple-download-monitor' ) . '</label>';
|
514 |
}
|
515 |
|
516 |
public function redirect_user_back_to_download_page_cb() {
|
517 |
$main_opts = get_option( 'sdm_downloads_options' );
|
518 |
$value = isset( $main_opts['redirect_user_back_to_download_page'] ) && $main_opts['redirect_user_back_to_download_page'];
|
519 |
echo '<input name="sdm_downloads_options[redirect_user_back_to_download_page]" id="redirect_user_back_to_download_page" type="checkbox" value="1"' . checked( true, $value, false ) . ' />';
|
520 |
+
echo '<label for="redirect_user_back_to_download_page">' . esc_html__( 'Only works if you have set a Login Page URL value above. Enable this option if you want to redirect the users to the download page after they log into the site.', 'simple-download-monitor' ) . '</label>';
|
521 |
}
|
522 |
|
523 |
public function general_login_page_url_cb() {
|
524 |
$main_opts = get_option( 'sdm_downloads_options' );
|
525 |
$value = isset( $main_opts['general_login_page_url'] ) ? $main_opts['general_login_page_url'] : '';
|
526 |
+
echo '<input size="100" name="sdm_downloads_options[general_login_page_url]" id="general_login_page_url" type="text" value="' . esc_attr( $value ) . '" />';
|
527 |
+
echo '<p class="description">' . esc_html__( '(Optional) Specify a login page URL where users can login. This is useful if you only allow logged in users to be able to download. This link will be added to the message that is shown to anonymous users.', 'simple-download-monitor' ) . '</p>';
|
528 |
}
|
529 |
|
530 |
public function admin_log_unique() {
|
531 |
$main_opts = get_option( 'sdm_downloads_options' );
|
532 |
echo '<input name="sdm_downloads_options[admin_log_unique]" id="admin_log_unique" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_log_unique'] ), false ) . ' /> ';
|
533 |
+
echo '<label for="admin_log_unique">' . esc_html__( 'Only logs downloads from unique IP addresses.', 'simple-download-monitor' ) . '</label>';
|
534 |
}
|
535 |
|
536 |
public function admin_do_not_capture_ip() {
|
537 |
$main_opts = get_option( 'sdm_downloads_options' );
|
538 |
echo '<input name="sdm_downloads_options[admin_do_not_capture_ip]" id="admin_do_not_capture_ip" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_do_not_capture_ip'] ), false ) . ' /> ';
|
539 |
+
echo '<label for="admin_do_not_capture_ip">' . esc_html__( 'Use this if you do not want to capture the IP address and Country of the visitors when they download an item.', 'simple-download-monitor' ) . '</label>';
|
540 |
}
|
541 |
|
542 |
public function admin_do_not_capture_user_agent() {
|
543 |
$main_opts = get_option( 'sdm_downloads_options' );
|
544 |
echo '<input name="sdm_downloads_options[admin_do_not_capture_user_agent]" id="admin_do_not_capture_user_agent" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_do_not_capture_user_agent'] ), false ) . ' /> ';
|
545 |
+
echo '<label for="admin_do_not_capture_user_agent">' . esc_html__( 'Use this if you do not want to capture the User Agent value of the browser when they download an item.', 'simple-download-monitor' ) . '</label>';
|
546 |
}
|
547 |
|
548 |
public function admin_do_not_capture_referrer_url() {
|
549 |
$main_opts = get_option( 'sdm_downloads_options' );
|
550 |
echo '<input name="sdm_downloads_options[admin_do_not_capture_referrer_url]" id="admin_do_not_capture_referrer_url" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_do_not_capture_referrer_url'] ), false ) . ' /> ';
|
551 |
+
echo '<label for="admin_do_not_capture_referrer_url">' . esc_html__( 'Use this if you do not want to capture the Referrer URL value when they download an item. The plugin only tries to capture this value if it is available.', 'simple-download-monitor' ) . '</label>';
|
552 |
}
|
553 |
|
554 |
public function admin_dont_log_bots() {
|
555 |
$main_opts = get_option( 'sdm_downloads_options' );
|
556 |
echo '<input name="sdm_downloads_options[admin_dont_log_bots]" id="admin_dont_log_bots" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_dont_log_bots'] ), false ) . ' /> ';
|
557 |
+
echo '<label for="admin_dont_log_bots">' . esc_html__( 'When enabled, the plugin won\'t count and log downloads from bots.', 'simple-download-monitor' ) . '</label>';
|
558 |
}
|
559 |
|
560 |
public function admin_no_logs_cb() {
|
561 |
$main_opts = get_option( 'sdm_downloads_options' );
|
562 |
echo '<input name="sdm_downloads_options[admin_no_logs]" id="admin_no_logs" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['admin_no_logs'] ), false ) . ' /> ';
|
563 |
+
echo '<label for="admin_no_logs">' . esc_html__( 'Disables all download logs. (This global option overrides the individual download item option.)', 'simple-download-monitor' ) . '</label>';
|
564 |
}
|
565 |
|
566 |
public function download_button_color_cb() {
|
571 |
|
572 |
echo '<select name="sdm_downloads_options[download_button_color]" id="download_button_color" class="sdm_opts_ajax_dropdowns">';
|
573 |
foreach ( $color_opts as $color_class => $color_name ) {
|
574 |
+
echo '<option value="' . esc_attr( $color_class ) . '"' . selected( $color_class, $color_opt, false ) . '>' . esc_html( $color_name ) . '</option>';
|
575 |
}
|
576 |
echo '</select> ';
|
577 |
esc_html_e( 'Adjusts the color of the "Download Now" button.', 'simple-download-monitor' );
|
580 |
public function enable_debug_cb() {
|
581 |
$main_opts = get_option( 'sdm_downloads_options' );
|
582 |
echo '<input name="sdm_downloads_options[enable_debug]" id="enable_debug" type="checkbox" class="sdm_opts_ajax_checkboxes" ' . checked( 1, isset( $main_opts['enable_debug'] ), false ) . ' /> ';
|
583 |
+
echo '<label for="enable_debug">' . esc_html__( 'Check this option to enable debug logging.', 'simple-download-monitor' ) .
|
584 |
+
'<p class="description"><a href="' . esc_url( wp_nonce_url( get_admin_url() . '?sdm-action=view_log', 'sdm_view_log_nonce' ) ) . '" target="_blank">' .
|
585 |
+
esc_html__( 'Click here', 'simple-download-monitor' ) . '</a>' .
|
586 |
+
esc_html__( ' to view log file.', 'simple-download-monitor' ) . '<br>' .
|
587 |
+
'<a id="sdm-reset-log" href="#0" style="color: red">' . esc_html__( 'Click here', 'simple-download-monitor' ) . '</a>' .
|
588 |
+
esc_html__( ' to reset log file.', 'simple-download-monitor' ) . '</p></label>';
|
589 |
}
|
590 |
|
591 |
public function termscond_enable_cb() {
|
592 |
$main_opts = get_option( 'sdm_advanced_options' );
|
593 |
echo '<input name="sdm_advanced_options[termscond_enable]" id="termscond_enable" type="checkbox" ' . checked( 1, isset( $main_opts['termscond_enable'] ), false ) . ' /> ';
|
594 |
+
echo '<p class="description">' . esc_html__( 'You can use this option to make the visitors agree to your terms before they can download the item.', 'simple-download-monitor' ) . '</p>';
|
595 |
}
|
596 |
|
597 |
public function termscond_url_cb() {
|
598 |
$main_opts = get_option( 'sdm_advanced_options' );
|
599 |
$value = isset( $main_opts['termscond_url'] ) ? $main_opts['termscond_url'] : '';
|
600 |
+
echo '<input size="100" name="sdm_advanced_options[termscond_url]" id="termscond_url" type="text" value="' . esc_attr( $value ) . '" /> ';
|
601 |
+
echo '<p class="description">' . esc_html__( 'Enter the URL of your terms and conditions page.', 'simple-download-monitor' ) . '</p>';
|
602 |
}
|
603 |
|
604 |
public function adsense_below_description_cb() {
|
605 |
$main_opts = get_option( 'sdm_advanced_options' );
|
606 |
$value = isset( $main_opts['adsense_below_description'] ) ? $main_opts['adsense_below_description'] : '';
|
607 |
//echo '<input size="100" name="sdm_advanced_options[adsense_below_description]" id="adsense_below_description" type="text" value="'.$value.'" /> ';
|
608 |
+
echo '<textarea name="sdm_advanced_options[adsense_below_description]" id="adsense_below_description" rows="6" cols="60">' . $value . '</textarea>'; //phpcs:ignore
|
609 |
+
echo '<p class="description">' . esc_html__( 'Enter the Adsense or Ad code that you want to show below the download item description.', 'simple-download-monitor' ) . '</p>';
|
610 |
}
|
611 |
|
612 |
public function maps_api_key_cb() {
|
613 |
$main_opts = get_option( 'sdm_advanced_options' );
|
614 |
$value = isset( $main_opts['maps_api_key'] ) ? $main_opts['maps_api_key'] : '';
|
615 |
+
echo '<input size="100" name="sdm_advanced_options[maps_api_key]" id="maps_api_key" type="text" value="' . esc_attr( $value ) . '" />';
|
616 |
+
echo '<p class="description">' . wp_kses(
|
617 |
+
__( 'Enter your Google Maps API key. You can create new API key using <a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">this instruction</a>.', 'simple-download-monitor' ),
|
618 |
+
array(
|
619 |
+
'a' => array(
|
620 |
+
'target' => array(),
|
621 |
+
'href' => array(),
|
622 |
+
),
|
623 |
+
)
|
624 |
+
) . '</p>';
|
625 |
}
|
626 |
|
627 |
public function sdm_add_clone_record_btn( $action, $post ) {
|
647 |
array(
|
648 |
'action' => 'sdm_clone_post',
|
649 |
'post' => $post_id,
|
650 |
+
'ref' => add_query_arg( $wp->query_string, '', home_url( $wp->request ) ),
|
651 |
'_nonce' => wp_create_nonce( 'sdm_downloads' ),
|
652 |
),
|
653 |
esc_url( admin_url( 'admin.php' ) )
|
658 |
|
659 |
global $wpdb;
|
660 |
if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) || ( isset( $_REQUEST['action'] ) && 'sdm_clone_post' == $_REQUEST['action'] ) ) ) {
|
661 |
+
wp_die( esc_html__( 'No post to duplicate has been supplied!', 'simple-download-monitor' ) );
|
662 |
}
|
663 |
|
664 |
/*
|
665 |
* Nonce verification
|
666 |
*/
|
667 |
+
|
668 |
+
check_admin_referer( 'sdm_downloads', '_nonce' );
|
|
|
669 |
|
670 |
/*
|
671 |
* get the original post id
|
745 |
wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) );
|
746 |
exit;
|
747 |
} else {
|
748 |
+
wp_die( esc_html__( 'Post creation failed, could not find original post: ', 'simple-download-monitor' ) . esc_html( $post_id ) );
|
749 |
}
|
750 |
}
|
751 |
|
774 |
);
|
775 |
}
|
776 |
|
777 |
+
$response =
|
778 |
array(
|
779 |
'success' => true,
|
780 |
'test' => $test,
|
781 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
782 |
|
783 |
+
wp_send_json( $response );
|
|
|
|
|
784 |
}
|
785 |
|
786 |
// Populate category tree
|
789 |
|
790 |
function sdm_pop_cats_ajax_call() {
|
791 |
|
792 |
+
$cat_slug = filter_input( INPUT_POST, 'cat_slug', FILTER_SANITIZE_STRING ); // Get button cpt slug
|
793 |
+
$cat_slug = empty( $cat_slug ) ? '' : sanitize_text_field( $cat_slug );
|
794 |
+
|
795 |
+
// $parent_id = intval( $_POST['parent_id'] ); // Get button cpt id
|
796 |
// Query custom posts based on taxonomy slug
|
797 |
$posts = get_posts(
|
798 |
array(
|
824 |
}
|
825 |
|
826 |
// Generate ajax response
|
827 |
+
$response = array( 'final_array' => $final_array );
|
828 |
+
wp_send_json( $response );
|
|
|
|
|
829 |
}
|
830 |
|
831 |
/*
|
868 |
$old_thumbnail = get_post_meta( $post_ID, 'sdm_upload_thumbnail', true );
|
869 |
//$old_value = isset($old_thumbnail) ? $old_thumbnail : '';
|
870 |
if ( $old_thumbnail ) {
|
871 |
+
echo '<p class="sdm_downloads_thumbnail_in_admin_listing"><img src="' . esc_url( $old_thumbnail ) . '" style="width:50px;height:50px;" /></p>';
|
872 |
}
|
873 |
}
|
874 |
if ( $column_name == 'sdm_downloads_id' ) {
|
875 |
+
echo '<p class="sdm_downloads_postid">' . esc_html( $post_ID ) . '</p>';
|
876 |
}
|
877 |
if ( $column_name == 'sdm_downloads_file' ) {
|
878 |
$old_file = get_post_meta( $post_ID, 'sdm_upload', true );
|
879 |
$file = isset( $old_file ) ? $old_file : '--';
|
880 |
+
echo '<p class="sdm_downloads_file">' . esc_html( $file ) . '</p>';
|
881 |
}
|
882 |
if ( $column_name == 'sdm_downloads_count' ) {
|
883 |
global $wpdb;
|
884 |
$wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'sdm_downloads WHERE post_id=%s', $post_ID ) );
|
885 |
+
echo '<p class="sdm_downloads_count">' . esc_html( $wpdb->num_rows ) . '</p>';
|
886 |
}
|
887 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.tipsandtricks-hq.com
|
|
4 |
Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, downloadmanager, file manager, protect downloads, password, download category, file tree, ajax, download template, grid, documents, ip address
|
5 |
Requires at least: 5.0
|
6 |
Tested up to: 5.8
|
7 |
-
Stable tag: 3.9.
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
|
@@ -190,6 +190,19 @@ For screenshots please visit the [download monitor plugin page](https://www.tips
|
|
190 |
|
191 |
== Changelog ==
|
192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
= 3.9.5.1 =
|
194 |
- Updated the read permission of the download post type to fix the permalink of the item (shown below the title of the post when editing).
|
195 |
- Changed the downloads menu permission from 'update_core' to 'manage_options' for better compatibility with WP Multi-Site install.
|
4 |
Tags: download, downloads, count, counter, tracker, tracking, hits, logging, monitor, manager, files, media, digital, download monitor, download manager, downloadmanager, file manager, protect downloads, password, download category, file tree, ajax, download template, grid, documents, ip address
|
5 |
Requires at least: 5.0
|
6 |
Tested up to: 5.8
|
7 |
+
Stable tag: 3.9.7
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
Easily manage downloadable files and monitor downloads of your digital files from your WordPress site.
|
190 |
|
191 |
== Changelog ==
|
192 |
|
193 |
+
= 3.9.7 =
|
194 |
+
- Added a new filter hook 'sdm_post_type_capability'. This hook can be used to apply a customization and override the default capability from 'administrator' to other roles.
|
195 |
+
- The '%' symbol is now allowed in the download URL field.
|
196 |
+
- Added current_user_can() checks to ajax calls.
|
197 |
+
|
198 |
+
= 3.9.6 =
|
199 |
+
- The Export Logs to CSV feature now pushes the CSV file directly to the browser.
|
200 |
+
- The JavaScript code for the stats menu has been moved to a separate file.
|
201 |
+
- Added nonce check for view and reset log.
|
202 |
+
- Added nonce check to the 'Specific Item logs' menu.
|
203 |
+
- Fixed the issue with "remove download thumbnail" button not working.
|
204 |
+
- WPCS modifications and code reformatting.
|
205 |
+
|
206 |
= 3.9.5.1 =
|
207 |
- Updated the read permission of the download post type to fix the permalink of the item (shown below the title of the post when editing).
|
208 |
- Changed the downloads menu permission from 'update_core' to 'manage_options' for better compatibility with WP Multi-Site install.
|
sdm-download-logs.csv
DELETED
File without changes
|
sdm-post-type-and-taxonomy.php
CHANGED
@@ -1,107 +1,109 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
function sdm_register_post_type() {
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
'
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function sdm_register_post_type() {
|
4 |
+
|
5 |
+
//***** Create 'sdm_downloads' Custom Post Type
|
6 |
+
$labels = array(
|
7 |
+
'name' => __( 'Downloads', 'simple-download-monitor' ),
|
8 |
+
'singular_name' => __( 'Downloads', 'simple-download-monitor' ),
|
9 |
+
'add_new' => __( 'Add New', 'simple-download-monitor' ),
|
10 |
+
'add_new_item' => __( 'Add New', 'simple-download-monitor' ),
|
11 |
+
'edit_item' => __( 'Edit Download', 'simple-download-monitor' ),
|
12 |
+
'new_item' => __( 'New Download', 'simple-download-monitor' ),
|
13 |
+
'all_items' => __( 'Downloads', 'simple-download-monitor' ),
|
14 |
+
'view_item' => __( 'View Download', 'simple-download-monitor' ),
|
15 |
+
'search_items' => __( 'Search Downloads', 'simple-download-monitor' ),
|
16 |
+
'not_found' => __( 'No Downloads found', 'simple-download-monitor' ),
|
17 |
+
'not_found_in_trash' => __( 'No Downloads found in Trash', 'simple-download-monitor' ),
|
18 |
+
'parent_item_colon' => __( 'Parent Download', 'simple-download-monitor' ),
|
19 |
+
'menu_name' => __( 'Downloads', 'simple-download-monitor' ),
|
20 |
+
);
|
21 |
+
|
22 |
+
//Trigger filter hook to allow overriding of the default SDM Post capability.
|
23 |
+
$sdm_post_capability = apply_filters( 'sdm_post_type_capability', 'manage_options' );
|
24 |
+
$capabilities = array(
|
25 |
+
'edit_post' => $sdm_post_capability,
|
26 |
+
'delete_post' => $sdm_post_capability,
|
27 |
+
'read_post' => $sdm_post_capability,
|
28 |
+
'edit_posts' => $sdm_post_capability,
|
29 |
+
'edit_others_posts' => $sdm_post_capability,
|
30 |
+
'delete_posts' => $sdm_post_capability,
|
31 |
+
'publish_posts' => $sdm_post_capability,
|
32 |
+
'read_private_posts' => $sdm_post_capability,
|
33 |
+
);
|
34 |
+
|
35 |
+
$sdm_permalink_base = 'sdm_downloads'; //TODO - add an option to configure in the settings maybe?
|
36 |
+
$sdm_slug = untrailingslashit( $sdm_permalink_base );
|
37 |
+
$args = array(
|
38 |
+
'labels' => $labels,
|
39 |
+
'public' => true,
|
40 |
+
'publicly_queryable' => true,
|
41 |
+
'show_ui' => true,
|
42 |
+
'show_in_menu' => true,
|
43 |
+
'query_var' => true,
|
44 |
+
'rewrite' => array( 'slug' => $sdm_slug ),
|
45 |
+
'capability_type' => 'post',
|
46 |
+
'capabilities' => $capabilities,
|
47 |
+
'has_archive' => true,
|
48 |
+
'hierarchical' => false,
|
49 |
+
'menu_position' => null,
|
50 |
+
'menu_icon' => 'dashicons-download',
|
51 |
+
'supports' => array( 'title' ),
|
52 |
+
);
|
53 |
+
|
54 |
+
//Trigger filter before registering the post type. Can be used to override the slug of the downloads
|
55 |
+
$args = apply_filters( 'sdm_downloads_post_type_before_register', $args );
|
56 |
+
|
57 |
+
register_post_type( 'sdm_downloads', $args );
|
58 |
+
}
|
59 |
+
|
60 |
+
function sdm_create_taxonomies() {
|
61 |
+
|
62 |
+
//***** Create CATEGORIES Taxonomy
|
63 |
+
$labels_tags = array(
|
64 |
+
'name' => __( 'Download Categories', 'simple-download-monitor' ),
|
65 |
+
'singular_name' => __( 'Download Category', 'simple-download-monitor' ),
|
66 |
+
'search_items' => __( 'Search Categories', 'simple-download-monitor' ),
|
67 |
+
'all_items' => __( 'All Categories', 'simple-download-monitor' ),
|
68 |
+
'parent_item' => __( 'Categories Genre', 'simple-download-monitor' ),
|
69 |
+
'parent_item_colon' => __( 'Categories Genre:', 'simple-download-monitor' ),
|
70 |
+
'edit_item' => __( 'Edit Category', 'simple-download-monitor' ),
|
71 |
+
'update_item' => __( 'Update Category', 'simple-download-monitor' ),
|
72 |
+
'add_new_item' => __( 'Add New Category', 'simple-download-monitor' ),
|
73 |
+
'new_item_name' => __( 'New Category', 'simple-download-monitor' ),
|
74 |
+
'menu_name' => __( 'Categories', 'simple-download-monitor' ),
|
75 |
+
);
|
76 |
+
$args_tags = array(
|
77 |
+
'hierarchical' => true,
|
78 |
+
'labels' => $labels_tags,
|
79 |
+
'show_ui' => true,
|
80 |
+
'query_var' => true,
|
81 |
+
'rewrite' => array( 'slug' => 'sdm_categories' ),
|
82 |
+
'show_admin_column' => true,
|
83 |
+
);
|
84 |
+
register_taxonomy( 'sdm_categories', array( 'sdm_downloads' ), $args_tags );
|
85 |
+
|
86 |
+
//***** Create TAGS Taxonomy
|
87 |
+
$labels_tags = array(
|
88 |
+
'name' => __( 'Download Tags', 'simple-download-monitor' ),
|
89 |
+
'singular_name' => __( 'Download Tag', 'simple-download-monitor' ),
|
90 |
+
'search_items' => __( 'Search Tags', 'simple-download-monitor' ),
|
91 |
+
'all_items' => __( 'All Tags', 'simple-download-monitor' ),
|
92 |
+
'parent_item' => __( 'Tags Genre', 'simple-download-monitor' ),
|
93 |
+
'parent_item_colon' => __( 'Tags Genre:', 'simple-download-monitor' ),
|
94 |
+
'edit_item' => __( 'Edit Tag', 'simple-download-monitor' ),
|
95 |
+
'update_item' => __( 'Update Tag', 'simple-download-monitor' ),
|
96 |
+
'add_new_item' => __( 'Add New Tag', 'simple-download-monitor' ),
|
97 |
+
'new_item_name' => __( 'New Tag', 'simple-download-monitor' ),
|
98 |
+
'menu_name' => __( 'Tags', 'simple-download-monitor' ),
|
99 |
+
);
|
100 |
+
$args_tags = array(
|
101 |
+
'hierarchical' => false,
|
102 |
+
'labels' => $labels_tags,
|
103 |
+
'show_ui' => true,
|
104 |
+
'query_var' => true,
|
105 |
+
'rewrite' => array( 'slug' => 'sdm_tags' ),
|
106 |
+
'show_admin_column' => true,
|
107 |
+
);
|
108 |
+
register_taxonomy( 'sdm_tags', array( 'sdm_downloads' ), $args_tags );
|
109 |
+
}
|
sdm-post-type-content-handler.php
CHANGED
@@ -4,168 +4,175 @@
|
|
4 |
add_filter( 'the_content', 'filter_sdm_post_type_content' );
|
5 |
|
6 |
function filter_sdm_post_type_content( $content ) {
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
// if (isset($main_opts['only_logged_in_can_download'])) {
|
91 |
-
// if ($main_opts['only_logged_in_can_download'] && sdm_get_logged_in_user()===false) {
|
92 |
-
// // User not logged in, let's display the message
|
93 |
-
// $download_button_code = __('You need to be logged in to download this file.','simple-download-monitor');
|
94 |
-
// }
|
95 |
-
// }
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
}
|
155 |
|
156 |
-
//$content .= '<div class="sdm_post_meta_section"></div>';//TODO - Show post meta (category and tags)
|
157 |
-
$content .= '</div>'; //end .sdm_post_item_top_right
|
158 |
-
|
159 |
-
$content .= '</div>'; //end of .sdm_download_item_top
|
160 |
-
|
161 |
-
$content .= '<div style="clear:both;"></div>';
|
162 |
-
|
163 |
-
$content .= '</div>'; //end .sdm_post_item
|
164 |
-
|
165 |
return $content;
|
166 |
-
}
|
167 |
-
|
168 |
-
return $content;
|
169 |
}
|
170 |
|
171 |
//The following filters are applied to the output of the SDM description field.
|
@@ -178,13 +185,13 @@ add_filter( 'sdm_downloads_description', 'shortcode_unautop' );
|
|
178 |
add_filter( 'sdm_downloads_description', 'prepend_attachment' );
|
179 |
|
180 |
function sdm_get_item_description_output( $id ) {
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
|
187 |
-
|
188 |
}
|
189 |
|
190 |
//Add adsense or ad code below the description (if applicable)
|
@@ -192,11 +199,11 @@ add_filter( 'sdm_cpt_below_download_description', 'sdm_add_ad_code_below_descrip
|
|
192 |
add_filter( 'sdm_fancy1_below_download_description', 'sdm_add_ad_code_below_description', 10, 2 );
|
193 |
|
194 |
function sdm_add_ad_code_below_description( $output, $args ) {
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
}
|
4 |
add_filter( 'the_content', 'filter_sdm_post_type_content' );
|
5 |
|
6 |
function filter_sdm_post_type_content( $content ) {
|
7 |
+
global $post;
|
8 |
+
if ( isset( $post->post_type ) && $post->post_type == 'sdm_downloads' ) {//Handle the content for sdm_downloads type post
|
9 |
+
//$download_id = $post->ID;
|
10 |
+
//$args = array('id' => $download_id, 'fancy' => '1');
|
11 |
+
//$content = sdm_create_download_shortcode($args);
|
12 |
+
$id = $post->ID;
|
13 |
+
|
14 |
+
//Check if the single download page is disabled.
|
15 |
+
$sdm_item_disable_single_download_page = get_post_meta( $id, 'sdm_item_disable_single_download_page', true );
|
16 |
+
if ( $sdm_item_disable_single_download_page ) {
|
17 |
+
//Page is disabled. Show message and return.
|
18 |
+
$content .= '<div class="sdm_post_single_download_page_disabled_msg">';
|
19 |
+
$msg = __( 'The admin of this site has disabled this download item page.', 'simple-download-monitor' );
|
20 |
+
$content .= apply_filters( 'sdm_post_single_download_page_disabled_msg', $msg );
|
21 |
+
$content .= '</div>';
|
22 |
+
return $content;
|
23 |
+
}
|
24 |
+
|
25 |
+
//Check to see if the download link cpt is password protected
|
26 |
+
$get_cpt_object = get_post( $id );
|
27 |
+
$cpt_is_password = ! empty( $get_cpt_object->post_password ) ? 'yes' : 'no'; // yes = download is password protected;
|
28 |
+
//Get item thumbnail
|
29 |
+
$item_download_thumbnail = get_post_meta( $id, 'sdm_upload_thumbnail', true );
|
30 |
+
$isset_download_thumbnail = isset( $item_download_thumbnail ) && ! empty( $item_download_thumbnail ) ? '<img class="sdm_post_thumbnail_image" src="' . $item_download_thumbnail . '" />' : '';
|
31 |
+
|
32 |
+
//Get item title
|
33 |
+
$item_title = get_the_title( $id );
|
34 |
+
$isset_item_title = isset( $item_title ) && ! empty( $item_title ) ? $item_title : '';
|
35 |
+
|
36 |
+
//Get item description
|
37 |
+
$isset_item_description = sdm_get_item_description_output( $id );
|
38 |
+
|
39 |
+
//$isset_item_description = apply_filters('the_content', $isset_item_description);
|
40 |
+
//Get item file size
|
41 |
+
$item_file_size = get_post_meta( $id, 'sdm_item_file_size', true );
|
42 |
+
$isset_item_file_size = isset( $item_file_size ) ? $item_file_size : '';
|
43 |
+
|
44 |
+
//Get item version
|
45 |
+
$item_version = get_post_meta( $id, 'sdm_item_version', true );
|
46 |
+
$isset_item_version = isset( $item_version ) ? $item_version : '';
|
47 |
+
|
48 |
+
//Check if show published date is enabled
|
49 |
+
$show_date_fd = get_post_meta( $id, 'sdm_item_show_date_fd', true );
|
50 |
+
//Get published date
|
51 |
+
$published_date = get_the_date( get_option( 'date_format' ), $id );
|
52 |
+
|
53 |
+
// See if user color option is selected
|
54 |
+
$main_opts = get_option( 'sdm_downloads_options' );
|
55 |
+
$color_opt = isset( $main_opts['download_button_color'] ) ? $main_opts['download_button_color'] : null;
|
56 |
+
$def_color = isset( $color_opt ) ? str_replace( ' ', '', strtolower( $color_opt ) ) : __( 'green', 'simple-download-monitor' );
|
57 |
+
|
58 |
+
//Download counter
|
59 |
+
//$dl_counter = sdm_create_counter_shortcode(array('id'=>$id));
|
60 |
+
//*** Generate the download now button code ***
|
61 |
+
$button_text_string = sdm_get_default_download_button_text( $post->ID );
|
62 |
+
|
63 |
+
// See if new window parameter is set
|
64 |
+
$new_window = get_post_meta( $id, 'sdm_item_new_window', true );
|
65 |
+
$window_target = empty( $new_window ) ? '_self' : '_blank';
|
66 |
+
|
67 |
+
$homepage = get_bloginfo( 'url' );
|
68 |
+
$download_url = $homepage . '/?smd_process_download=1&download_id=' . $id;
|
69 |
+
$download_button_code = '<a href="' . $download_url . '" class="sdm_download ' . $def_color . '" title="' . $isset_item_title . '" target="' . $window_target . '">' . $button_text_string . '</a>';
|
70 |
+
|
71 |
+
$main_advanced_opts = get_option( 'sdm_advanced_options' );
|
72 |
+
|
73 |
+
//Check if Terms & Condition enabled
|
74 |
+
$termscond_enable = isset( $main_advanced_opts['termscond_enable'] ) ? true : false;
|
75 |
+
if ( $termscond_enable ) {
|
76 |
+
$download_button_code = sdm_get_download_form_with_termsncond( $id, array(), 'sdm_download ' . $def_color );
|
77 |
+
}
|
78 |
+
|
79 |
+
//Check if reCAPTCHA enabled
|
80 |
+
$recaptcha_enable = isset( $main_advanced_opts['recaptcha_enable'] ) ? true : false;
|
81 |
+
if ( $recaptcha_enable && $cpt_is_password == 'no' ) {
|
82 |
+
$download_button_code = sdm_get_download_form_with_recaptcha( $id, array(), 'sdm_download ' . $def_color );
|
83 |
+
}
|
84 |
+
|
85 |
+
if ( $cpt_is_password !== 'no' ) {//This is a password protected download so replace the download now button with password requirement
|
86 |
+
$download_button_code = sdm_get_password_entry_form( $id, array(), 'sdm_download ' . $def_color );
|
87 |
+
}
|
88 |
+
|
89 |
+
// Check if we only allow the download for logged-in users
|
90 |
+
// if (isset($main_opts['only_logged_in_can_download'])) {
|
91 |
+
// if ($main_opts['only_logged_in_can_download'] && sdm_get_logged_in_user()===false) {
|
92 |
+
// // User not logged in, let's display the message
|
93 |
+
// $download_button_code = __('You need to be logged in to download this file.','simple-download-monitor');
|
94 |
+
// }
|
95 |
+
// }
|
96 |
+
|
97 |
+
$db_count = sdm_get_download_count_for_post( $id );
|
98 |
+
$string = ( $db_count == '1' ) ? __( 'Download', 'simple-download-monitor' ) : __( 'Downloads', 'simple-download-monitor' );
|
99 |
+
$download_count_string = '<span class="sdm_post_count_number">' . $db_count . '</span><span class="sdm_post_count_string"> ' . $string . '</span>';
|
100 |
+
|
101 |
+
//Output the download item details
|
102 |
+
$content = '<div class="sdm_post_item">';
|
103 |
+
$content .= '<div class="sdm_post_item_top">';
|
104 |
+
|
105 |
+
$content .= '<div class="sdm_post_item_top_left">';
|
106 |
+
$content .= '<div class="sdm_post_thumbnail">' . $isset_download_thumbnail . '</div>';
|
107 |
+
$content .= '</div>'; //end .sdm_post_item_top_left
|
108 |
+
|
109 |
+
$content .= '<div class="sdm_post_item_top_right">';
|
110 |
+
$content .= '<div class="sdm_post_title">' . $isset_item_title . '</div>';
|
111 |
+
|
112 |
+
if ( ! isset( $main_opts['general_hide_donwload_count'] ) ) {//The hide download count is enabled.
|
113 |
+
$content .= '<div class="sdm_post_download_count">' . $download_count_string . '</div>';
|
114 |
+
}
|
115 |
+
|
116 |
+
$content .= '<div class="sdm_post_description">' . $isset_item_description . '</div>';
|
117 |
+
|
118 |
+
//This hook can be used to add content below the description
|
119 |
+
$params = array( 'id' => $id );
|
120 |
+
$content .= apply_filters( 'sdm_cpt_below_download_description', '', $params );
|
121 |
+
|
122 |
+
//Check if the button of the single download page is disabled.
|
123 |
+
$sdm_item_hide_dl_button_single_download_page = get_post_meta( $id, 'sdm_item_hide_dl_button_single_download_page', true );
|
124 |
+
if ( $sdm_item_hide_dl_button_single_download_page ) {
|
125 |
+
//the download button is disabled.
|
126 |
+
$content .= '<div class="sdm_post_single_download_page_disabled_dl_button_msg">';
|
127 |
+
$msg = '<p>' . __( 'The admin of this site has disabled the download button for this page.', 'simple-download-monitor' ) . '</p>';
|
128 |
+
$content .= apply_filters( 'sdm_post_single_download_page_disabled_dl_button_msg', $msg );
|
129 |
+
$content .= '</div>';
|
130 |
+
} else {
|
131 |
+
$download_link = '<div class="sdm_download_link">' . $download_button_code . '</div>';
|
132 |
+
$content .= '<div class="sdm_post_download_section">' . apply_filters(
|
133 |
+
'sdm_single_page_dl_link',
|
134 |
+
$download_link,
|
135 |
+
array(
|
136 |
+
'id' => $id,
|
137 |
+
'button_text' => $button_text_string,
|
138 |
+
)
|
139 |
+
) . '</div>';
|
140 |
+
}
|
141 |
+
|
142 |
+
if ( ! empty( $isset_item_file_size ) ) {//Show file size info
|
143 |
+
$content .= '<div class="sdm_post_download_file_size">';
|
144 |
+
$content .= '<span class="sdm_post_download_size_label">' . __( 'Size: ', 'simple-download-monitor' ) . '</span>';
|
145 |
+
$content .= '<span class="sdm_post_download_size_value">' . $isset_item_file_size . '</span>';
|
146 |
+
$content .= '</div>';
|
147 |
+
}
|
148 |
+
|
149 |
+
if ( ! empty( $isset_item_version ) ) {//Show version info
|
150 |
+
$content .= '<div class="sdm_post_download_version">';
|
151 |
+
$content .= '<span class="sdm_post_download_version_label">' . __( 'Version: ', 'simple-download-monitor' ) . '</span>';
|
152 |
+
$content .= '<span class="sdm_post_download_version_value">' . $isset_item_version . '</span>';
|
153 |
+
$content .= '</div>';
|
154 |
+
}
|
155 |
+
|
156 |
+
if ( $show_date_fd ) {//Show Published date
|
157 |
+
$content .= '<div class="sdm_post_download_published_date">';
|
158 |
+
$content .= '<span class="sdm_post_download_published_date_label">' . __( 'Published: ', 'simple-download-monitor' ) . '</span>';
|
159 |
+
$content .= '<span class="sdm_post_download_published_date_value">' . $published_date . '</span>';
|
160 |
+
$content .= '</div>';
|
161 |
+
}
|
162 |
+
|
163 |
+
//$content .= '<div class="sdm_post_meta_section"></div>';//TODO - Show post meta (category and tags)
|
164 |
+
$content .= '</div>'; //end .sdm_post_item_top_right
|
165 |
+
|
166 |
+
$content .= '</div>'; //end of .sdm_download_item_top
|
167 |
+
|
168 |
+
$content .= '<div style="clear:both;"></div>';
|
169 |
+
|
170 |
+
$content .= '</div>'; //end .sdm_post_item
|
171 |
+
|
172 |
+
return $content;
|
173 |
}
|
174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
return $content;
|
|
|
|
|
|
|
176 |
}
|
177 |
|
178 |
//The following filters are applied to the output of the SDM description field.
|
185 |
add_filter( 'sdm_downloads_description', 'prepend_attachment' );
|
186 |
|
187 |
function sdm_get_item_description_output( $id ) {
|
188 |
+
$item_description = get_post_meta( $id, 'sdm_description', true );
|
189 |
+
$isset_item_description = isset( $item_description ) && ! empty( $item_description ) ? $item_description : '';
|
190 |
+
//$isset_item_description = apply_filters('the_content', $isset_item_description);
|
191 |
+
//Lets apply all the filters like do_shortcode, wptexturize, convert_smilies, wpautop etc.
|
192 |
+
$filtered_item_description = apply_filters( 'sdm_downloads_description', $isset_item_description );
|
193 |
|
194 |
+
return $filtered_item_description;
|
195 |
}
|
196 |
|
197 |
//Add adsense or ad code below the description (if applicable)
|
199 |
add_filter( 'sdm_fancy1_below_download_description', 'sdm_add_ad_code_below_description', 10, 2 );
|
200 |
|
201 |
function sdm_add_ad_code_below_description( $output, $args ) {
|
202 |
+
$main_advanced_opts = get_option( 'sdm_advanced_options' );
|
203 |
+
$adsense_below_desc = isset( $main_advanced_opts['adsense_below_description'] ) ? $main_advanced_opts['adsense_below_description'] : '';
|
204 |
+
if ( ! empty( $adsense_below_desc ) ) {
|
205 |
+
//Ad code is configured in settings. Lets add it to the output.
|
206 |
+
$output .= '<div class="sdm_below_description_ad_code">' . $adsense_below_desc . '</div>';
|
207 |
+
}
|
208 |
+
return $output;
|
209 |
}
|
sdm-shortcodes.php
CHANGED
@@ -35,6 +35,7 @@ function sdm_register_shortcodes() {
|
|
35 |
* Process (sanitize) download button shortcode attributes:
|
36 |
* - convert "id" to absolute integer
|
37 |
* - set "color" to color from settings or default color, if empty
|
|
|
38 |
* @param array $atts
|
39 |
* @return array
|
40 |
*/
|
@@ -84,9 +85,9 @@ function sdm_create_download_shortcode( $atts ) {
|
|
84 |
return '<p style="color: red;">' . __( 'Error! Please enter an ID value with this shortcode.', 'simple-download-monitor' ) . '</p>';
|
85 |
}
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
|
91 |
// Check to see if the download link cpt is password protected
|
92 |
$get_cpt_object = get_post( $id );
|
@@ -299,7 +300,7 @@ function sdm_handle_category_shortcode( $args ) {
|
|
299 |
|
300 |
// See if user color option is selected
|
301 |
$main_opts = get_option( 'sdm_downloads_options' );
|
302 |
-
$color_opt = isset( $main_opts[
|
303 |
$def_color = isset( $color_opt ) ? str_replace( ' ', '', strtolower( $color_opt ) ) : 'green';
|
304 |
|
305 |
if ( $fancy == '0' ) {
|
@@ -418,6 +419,7 @@ function sdm_download_categories_shortcode() {
|
|
418 |
|
419 |
/**
|
420 |
* Return HTML list with SDM categories rendered according to $atts.
|
|
|
421 |
* @param array $atts
|
422 |
* @param int $parent
|
423 |
* @return string
|
@@ -461,6 +463,7 @@ function sdm_download_categories_list_walker( $atts, $parent = 0 ) {
|
|
461 |
|
462 |
/**
|
463 |
* Return output of `sdm_download_categories_list` shortcode.
|
|
|
464 |
* @param array $attributes
|
465 |
* @return string
|
466 |
*/
|
35 |
* Process (sanitize) download button shortcode attributes:
|
36 |
* - convert "id" to absolute integer
|
37 |
* - set "color" to color from settings or default color, if empty
|
38 |
+
*
|
39 |
* @param array $atts
|
40 |
* @return array
|
41 |
*/
|
85 |
return '<p style="color: red;">' . __( 'Error! Please enter an ID value with this shortcode.', 'simple-download-monitor' ) . '</p>';
|
86 |
}
|
87 |
|
88 |
+
$id = intval( $id );
|
89 |
+
$color = sdm_sanitize_text( $color );
|
90 |
+
$css_class = sdm_sanitize_text( $css_class );
|
91 |
|
92 |
// Check to see if the download link cpt is password protected
|
93 |
$get_cpt_object = get_post( $id );
|
300 |
|
301 |
// See if user color option is selected
|
302 |
$main_opts = get_option( 'sdm_downloads_options' );
|
303 |
+
$color_opt = isset( $main_opts['download_button_color'] ) ? $main_opts['download_button_color'] : null;
|
304 |
$def_color = isset( $color_opt ) ? str_replace( ' ', '', strtolower( $color_opt ) ) : 'green';
|
305 |
|
306 |
if ( $fancy == '0' ) {
|
419 |
|
420 |
/**
|
421 |
* Return HTML list with SDM categories rendered according to $atts.
|
422 |
+
*
|
423 |
* @param array $atts
|
424 |
* @param int $parent
|
425 |
* @return string
|
463 |
|
464 |
/**
|
465 |
* Return output of `sdm_download_categories_list` shortcode.
|
466 |
+
*
|
467 |
* @param array $attributes
|
468 |
* @return string
|
469 |
*/
|