Admin
1 day ago
AssetManager
1 week ago
Category
2 years ago
Form
6 months ago
MediaLibrary
1 week ago
Package
1 day ago
User
1 day ago
Widgets
2 years ago
__
1 day ago
wpdm-core.php
5 months ago
wpdm-functions.php
1 week ago
wpdm-start-download.php
4 months ago
wpdm-strings.php
3 years ago
wpdm-start-download.php
118 lines
| 1 | <?php |
| 2 | |
| 3 | use WPDM\__\FileSystem; |
| 4 | use WPDM\__\Crypt; |
| 5 | use WPDM\__\Messages; |
| 6 | use WPDM\__\TempStorage; |
| 7 | |
| 8 | if(!defined("ABSPATH")) die('!'); |
| 9 | |
| 10 | |
| 11 | global $current_user, $dfiles; |
| 12 | $current_user = wp_get_current_user(); |
| 13 | |
| 14 | //Check for blocked IPs |
| 15 | if(wpdm_ip_blocked()) { |
| 16 | $_ipblockedmsg = __('Your IP address is blocked!', 'download-manager'); |
| 17 | $ipblockedmsg = get_option('__wpdm_blocked_ips_msg', ''); |
| 18 | $ipblockedmsg = $ipblockedmsg == ''?$_ipblockedmsg:$ipblockedmsg; |
| 19 | Messages::error($ipblockedmsg, 1); |
| 20 | } |
| 21 | |
| 22 | //Check for blocked users by email |
| 23 | if(is_user_logged_in() && $current_user->user_email && !wpdm_verify_email($current_user->user_email)) { |
| 24 | $emsg = get_option('__wpdm_blocked_domain_msg'); |
| 25 | if(trim($emsg) === '') $emsg = __('Your email address is blocked!', 'download-manager'); |
| 26 | Messages::fullPage('Error!', $emsg, 'error'); |
| 27 | } |
| 28 | |
| 29 | do_action("wpdm_onstart_download", $package); |
| 30 | |
| 31 | $speed = (int)get_option('__wpdm_download_speed', 10240); //in KB - default 10 MB |
| 32 | $speed = $speed > 0 ? $speed : 10240; |
| 33 | $speed = apply_filters('wpdm_download_speed', $speed); |
| 34 | //$user = get_user_by('id', $package['author']); |
| 35 | |
| 36 | //$user_upload_dir = UPLOAD_DIR . $user->user_login . '/'; |
| 37 | |
| 38 | $_content_dir = str_replace('\\','/',WP_CONTENT_DIR); |
| 39 | $_old_up_dir = $_content_dir.'/uploads/download-manager-files/'; |
| 40 | //wpdmdd($package); |
| 41 | //Only published packages are downloadable |
| 42 | $downloadable_post_status = apply_filters("wpdm_downloadable_post_status", array('publish','private'), $package); |
| 43 | if(!in_array($package['post_status'], $downloadable_post_status)) Messages::fullPage("404", "<div class='card p-4 bg-danger text-white'>".__( "Package you are trying to download is not available!" , "download-manager" )."</div>"); |
| 44 | |
| 45 | $limit_msg = Messages::download_limit_exceeded($package['ID']); |
| 46 | |
| 47 | if (wpdm_is_download_limit_exceed($package['ID'])) Messages::fullPage("Error!", $limit_msg, 'error'); |
| 48 | //$files = WPDM()->package->getFiles($package['ID']); |
| 49 | $files = $package['files']; |
| 50 | $files = array_values($files); |
| 51 | $fileCount = count($files) && $files[0] !== '' ? 1 : 0; |
| 52 | |
| 53 | if($fileCount === 0){ |
| 54 | Messages::fullPage(__( "No Files", "download-manager" ), \WPDM\__\UI::div(__( "No file is attached with this package!", "download-manager" ), "alert alert-danger d-inline-block")); |
| 55 | } |
| 56 | |
| 57 | //$idvdl = Individual file download status |
| 58 | $idvdl = ( WPDM()->package->isSingleFileDownloadAllowed( $package['ID'] ) || wpdm_query_var('oid', false) ) && isset($_GET['ind']); |
| 59 | |
| 60 | $parallel_download = (int)get_option('__wpdm_parallel_download', 1); |
| 61 | |
| 62 | if($parallel_download === 0 && (int)TempStorage::get("download.".wpdm_get_client_ip()) === 1) |
| 63 | Messages::error(get_option('__wpdm_parallel_download_msg', "Another download is in progress from your IP, please wait until finished."), 1); |
| 64 | |
| 65 | if ($fileCount > 1 && !$idvdl) { |
| 66 | Messages::error(esc_attr__( 'Multi-file download is only available with the pro version!', "download-manager" ), 1); |
| 67 | } |
| 68 | else { |
| 69 | |
| 70 | $tmpfiles = $files; |
| 71 | $indfile = array_shift($tmpfiles); |
| 72 | |
| 73 | $firstfile = array_shift($files); |
| 74 | $firstfile = file_exists($firstfile) ? $firstfile : UPLOAD_DIR.$firstfile; |
| 75 | |
| 76 | WPDM()->downloadHistory->add($package['ID'], $indfile ? : $firstfile, wpdm_query_var('oid')); |
| 77 | |
| 78 | //URL Download |
| 79 | if ($indfile != '' && strpos($indfile, '://')) { |
| 80 | |
| 81 | if (!isset($package['url_protect']) || $package['url_protect'] == 0) { |
| 82 | $indfile = wpdm_escs(htmlspecialchars_decode($indfile)); |
| 83 | header('location: ' . urldecode($indfile)); |
| 84 | |
| 85 | } else { |
| 86 | $r_filename = wpdm_basename($indfile); |
| 87 | $r_filename = explode("?", $r_filename); |
| 88 | $r_filename = $r_filename[0]; |
| 89 | wpdm_download_file($indfile, $r_filename, $speed, 1, $package); |
| 90 | |
| 91 | } |
| 92 | |
| 93 | die(); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | $filepath = WPDM()->fileSystem->absPath($indfile, $package['ID']); |
| 98 | |
| 99 | if(!$filepath) |
| 100 | Messages::fullPage('Error!', "<div class='card bg-danger text-white p-4' style='max-width: 500px;margin: 0 auto;text-align: center'>" . __("Sorry! File not found!", "download-manager") . "</div>", 'error'); |
| 101 | //$plock = get_wpdm_meta($file['id'],'password_lock',true); |
| 102 | //$fileinfo = get_wpdm_meta($package['id'],'fileinfo'); |
| 103 | |
| 104 | $filename = wpdm_basename($filepath); |
| 105 | $filename = preg_replace("/([0-9]+)[wpdm]+_/", "", $filename); |
| 106 | |
| 107 | wpdm_download_file($filepath, $filename, $speed, 1, $package); |
| 108 | //@unlink($filepath); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | TempStorage::kill("download.".wpdm_get_client_ip()); |
| 113 | |
| 114 | do_action("after_download", $package); |
| 115 | |
| 116 | die(); |
| 117 | |
| 118 |