function _uc_file_download in Ubercart 7.3
Same name and namespace in other branches
- 6.2 uc_file/uc_file.pages.inc \_uc_file_download()
Handles file downloading and error states.
Parameters
$fid: The fid of the file specified to download.
$key: The hash key of a user's download.
See also
1 string reference to '_uc_file_download'
- uc_file_menu in uc_file/
uc_file.module - Implements hook_menu().
File
- uc_file/
uc_file.pages.inc, line 188 - File menu items.
Code
function _uc_file_download($fid) {
global $user;
// Error messages for various failed download states.
$admin_message = t('Please contact the site administrator if this message has been received in error.');
$error_messages = array(
UC_FILE_ERROR_NOT_A_FILE => t('The file you requested does not exist.'),
UC_FILE_ERROR_TOO_MANY_BOGUS_REQUESTS => t('You have attempted to download an incorrect file URL too many times.'),
UC_FILE_ERROR_INVALID_DOWNLOAD => t('The following URL is not a valid download link.') . ' ',
UC_FILE_ERROR_TOO_MANY_LOCATIONS => t('You have downloaded this file from too many different locations.'),
UC_FILE_ERROR_TOO_MANY_DOWNLOADS => t('You have reached the download limit for this file.'),
UC_FILE_ERROR_EXPIRED => t('This file download has expired.') . ' ',
UC_FILE_ERROR_HOOK_ERROR => t('A hook denied your access to this file.') . ' ',
);
$ip = ip_address();
if (user_access('view all downloads')) {
$file_download = uc_file_get_by_id($fid);
}
else {
$file_download = uc_file_get_by_uid($user->uid, $fid);
}
if (isset($file_download->filename)) {
$file_download->full_path = uc_file_qualify_file($file_download->filename);
}
else {
return MENU_ACCESS_DENIED;
}
// If it's ok, we push the file to the user.
$status = UC_FILE_ERROR_OK;
if (!user_access('view all downloads')) {
$status = _uc_file_download_validate($file_download, $user, $ip);
}
if ($status == UC_FILE_ERROR_OK) {
_uc_file_download_transfer($file_download, $ip);
}
else {
drupal_set_message($error_messages[$status] . $admin_message, 'error');
// Kick 'em to the curb. >:)
_uc_file_download_redirect($user->uid);
}
drupal_exit();
}