<?php
add_action ("ws_plugin__s2member_during_file_download_access", "my_s2_file_download_counts");
function my_s2_file_download_counts ($vars = array ())
{
if ($vars["serving"] && $vars["valid_file_download_key"] && ($file = $vars["req"]["file_download"]))
if (is_user_logged_in () && is_object ($user = wp_get_current_user ()) && !empty ($user->ID) && ($user_id = $user->ID))
{
$current_download_counts = (array)get_user_option ("my_s2_file_download_counts", $user_id);
update_user_option ($user_id, "my_s2_file_download_counts", (int)@$current_download_counts[$file] + 1);
}
}
function my_s2_file_download_count_for ($file = FALSE, $user_id = FALSE)
{
if ($file && ($user_id || (is_object ($user = wp_get_current_user ()) && !empty ($user->ID) && ($user_id = $user->ID))))
{
$current_download_counts = (array)get_user_option ("my_s2_file_download_counts", $user_id);
return (int)@$current_download_counts[$file];
}
return /* Default return value. */ 0;
}
?>
<?php echo my_s2_file_download_count_for("access-s2member-ccap-post345/file.mov"); # Returns the count for this file, for the current User. ?>
<?php echo my_s2_file_download_count_for("access-s2member-ccap-post345/file.mov", ($user_id = 123)); # Returns the count for this file, for a specific User. ?>
Statistics: Posted by Jason Caldwell — December 2nd, 2011, 5:05 pm
Statistics: Posted by kennymcnett — December 2nd, 2011, 7:53 am
Statistics: Posted by Jason Caldwell — December 2nd, 2011, 6:46 am
Statistics: Posted by kennymcnett — December 2nd, 2011, 6:16 am
Sorry, just want to make sure I understand correctly. Can you elaborate just a bit further on this for me please? Did you say, "This IS good for me", or no? It sounds like you might not need the use of a Download Key, but just clarify a bit further so I can be sure please.
The conditionals in my php only display the links to the s2member-files if they user has either the post's ccap or a premium membership.
As I understand the security for the s2member-files folder, because the files are in a subfolder, the only users that can access them via a direct url would be users who are logged in and possess a ccap equal to the subfolder name (e.g., 'videos'). This is good for me, because I don't want users sharing links with each other.
Statistics: Posted by Jason Caldwell — December 2nd, 2011, 4:35 am
Statistics: Posted by kennymcnett — December 2nd, 2011, 4:08 am
Calculations returned by these functions do NOT include File Downloads that were accessed with an Advanced File Download Key.
Statistics: Posted by Jason Caldwell — December 2nd, 2011, 3:46 am
[s2File download="example.zip" download_key="true" /]
Statistics: Posted by kennymcnett — December 1st, 2011, 12:32 pm
<?php
$archived_downloads = get_user_option ("s2member_file_download_access_arc", $user_id);
if (is_array ($archived_downloads) && !empty ($archived_downloads))
{
foreach ($archived_downloads as $archived_download)
{
$date = $archived_download["date"];
$file = $archived_download["file"];
// Do something custom here if you like.
}
}
?>
Statistics: Posted by colinp386 — October 27th, 2011, 12:14 pm
Remember though, if a particular User/Member downloads the same exact file 10 times, s2Member only counts that as ONE file download ( this is the intended behavior ).
<?php
add_action ("ws_plugin__s2member_during_file_download_access", "my_s2_file_download_counts");
function my_s2_file_download_counts ($vars = array ())
{
if (($serving = $vars["serving"]) && ($file = $vars["req"]["file_download"]) && ($user_id = $vars["user_id"]))
{
$counts = (array)get_user_option ("my_s2_file_download_counts", $user_id);
$counts[$file] = (!empty ($counts[$file])) ? (int)$counts[$file] + 1 : (int)1;
update_user_option ($user_id, "my_s2_file_download_counts", $counts);
}
}
function my_total_user_downloads_of ($file, $user = FALSE)
{
if (($user = (is_object ($user)) ? $user : ((is_user_logged_in ()) ? wp_get_current_user () : false)) && !empty ($user->ID) && ($user_id = $user->ID))
{
$counts = (array)get_user_option ("my_s2_file_download_counts", $user_id);
$total = (!empty ($counts[$file])) ? (int)$counts[$file] : (int)0;
}
return (!empty ($total)) ? $total : 0;
}
?>
<?php echo my_total_user_downloads_of("example-file.zip"); // For the current User. ?>
<?php
$user = new WP_User("123"); /* For user ID #123 ( i.e. a specific User ). */
echo my_total_user_downloads_of("example-file.zip", $user); /* For a specific User. */
?>
Statistics: Posted by Jason Caldwell — October 26th, 2011, 6:13 pm
Statistics: Posted by kennymcnett — October 26th, 2011, 5:36 pm
<?php
function s2_total_user_downloads_of ($file, $check_archives_too = TRUE)
{
global $wpdb; /* Global database object reference. */
/**/
$q1 = mysql_query ("SELECT SQL_CALC_FOUND_ROWS DISTINCT `user_id` FROM `" . $wpdb->usermeta . "` WHERE (`meta_key` = '" . $wpdb->prefix . "s2member_file_download_access_log'" . (($check_archives_too) ? " OR `meta_key` = '" . $wpdb->prefix . "s2member_file_download_access_arc'" : "") . ") AND `meta_value` REGEXP '.*\"file\";s:[0-9]+:\"" . esc_sql ($file) . "\".*' LIMIT 1", $wpdb->dbh);
$q2 = mysql_query ("SELECT FOUND_ROWS()", $wpdb->dbh);
/**/
$users = (int)mysql_result ($q2, 0);
/**/
mysql_free_result($q2);
mysql_free_result($q1);
/**/
return $users;
}
?>
<?php echo s2_total_user_downloads_of("example-file.zip"); ?>
Statistics: Posted by Jason Caldwell — October 26th, 2011, 5:32 pm
<?php
$archived_downloads = get_user_option ("s2member_file_download_access_arc", $user_id);
if (is_array ($archived_downloads) && !empty ($archived_downloads))
{
foreach ($archived_downloads as $archived_download)
{
$date = $archived_download["date"];
$file = $archived_download["file"];
// Do something custom here if you like.
}
}
?>
Statistics: Posted by Jason Caldwell — October 26th, 2011, 4:17 pm
/*
Shortcode Name: pkg-downloads
Description: if activated, will show the downloaded files for current user.
Author: Colin
Version: 1.0
*/
add_shortcode('pkg-downloads', 'pkg_downloads_shortcode');
function pkg_downloads_shortcode() {
global $user_id;
$current_user = wp_get_current_user();
if ( !($current_user instanceof WP_User) )
return;
echo 'User ID: ' . $current_user->ID . '<br />';
$user_id = $current_user->ID;
$downloads = get_user_option("s2member_file_download_access_log", $user_id);
echo 'Current Downloads<br />';
print_r($downloads);
echo '<br />';
echo 'Archived Downloads<br />';
$archived_downloads = get_user_option("s2member_file_download_access_arc", $user_id);
print_r($archived_downloads);
}
Statistics: Posted by colinp386 — October 26th, 2011, 3:39 pm
Statistics: Posted by kennymcnett — October 21st, 2011, 11:25 am
Statistics: Posted by guardian — October 7th, 2011, 8:15 am
Statistics: Posted by colinp386 — October 3rd, 2011, 11:17 pm
<?php
$user_id = 1;
$downloads = get_user_option("s2member_file_download_access_log", $user_id);
print_r($downloads); /* Array of file downloads in the current period of time, as configured by the site owner under Basic Download Restrictions for s2Member. */
?>
<?php
$user_id = 1;
$archived_downloads = get_user_option("s2member_file_download_access_arc", $user_id);
print_r($archived_downloads); /* Array of file downloads for previous periods of time, as configured by the site owner under Basic Download Restrictions for s2Member. */
?>
Statistics: Posted by Jason Caldwell — October 3rd, 2011, 10:33 pm
Statistics: Posted by colinp386 — September 29th, 2011, 8:03 pm