0) {
$file = get_attached_file($mediaid);
$file = apply_filters("wpdm_media_download", $file, $mediaid);
FileSystem::downloadFile($file, basename($file), 10240, 0, array('play' => 1));
die();
}
}
}
function makeMediaPass(){
if(wpdm_query_var('__xnonce') && wp_verify_nonce(wpdm_query_var('__xnonce'), NONCE_KEY)){
$mediaid = Crypt::decrypt(wpdm_query_var('__meida'));
$password = get_post_meta($mediaid, '__wpdm_media_pass', true);
if($password === wpdm_query_var('__pswd')){
$mediakey = uniqid();
$xpire_sex = (int)get_option('__wpdm_private_link_expiration_period') * (int)get_option('__wpdm_private_link_expiration_period_unit');
$xpire_sex = $xpire_sex > 0 ? $xpire_sex : 30;
TempStorage::set('__wpdm_meida_key_'.$mediakey, $mediaid, $xpire_sex);
wp_send_json(array('success' => true, '__mediakey' => $mediakey));
}
}
wp_send_json(array('success' => false, 'error' => __( "Error: Wrong Password! Try Again.", "download-manager" )));
}
function protectMediaLibrary(){
if(isset($_REQUEST['wpdmmediaid'])){
global $wpdb, $current_user;
$media = get_post($_REQUEST['wpdmmediaid']);
$media_meta = wp_get_attachment_metadata($_REQUEST['wpdmmediaid']);
//wpdmdd($media_meta);
//wpdmdd($media);
$media->path = str_replace(home_url('/'), ABSPATH.'/', $media->guid);
$media->filesize = wpdm_file_size($media->path);
$access = get_post_meta($media->ID, '__wpdm_media_access', true);
$password = get_post_meta($media->ID, '__wpdm_media_pass', true);
$private = get_post_meta($media->ID, '__wpdm_private', true);
if(current_user_can('manage_options')) $private = false;
$user_roles = is_user_logged_in() ? $current_user->roles + array('public') : array();
$user_roles[] = 'public';
if(!is_array($access)) $access = [];
$user_allowed = array_intersect($user_roles, $access);
$user_allowed = count($user_allowed);
if( $private && ( $password || !$user_allowed ) ) {
\WPDM_Messages::fullPage(__( "Protected Media File", "download-manager" ), UI::card(__( "Protected Media File", "download-manager" ), __( "You are not allowed to access the media file", "download-manager" ), '', ['class' => 'bg-danger text-white']), 'error');
/*$picon = wp_get_attachment_image($media->ID, 'thumbnail', true);
$keyvalid = true;
$__hash = Crypt::encrypt($media->ID);
$download_url = "";
include wpdm_tpl_path("media-download.php");
die();*/
}
$upload_dir = wp_upload_dir();
$file_path = $upload_dir['basedir'].'/'.$_REQUEST['wpdmmedia'];
$file_path = apply_filters("wpdm_media_download", $file_path, $media->ID);
FileSystem::downloadFile($file_path, basename($file_path), 10240, 0, array('play' => 1));
die();
}
}
function updateMediaAccess(){
$protected = get_option("__wpdm_media_private");
$protected = $protected ? (array)json_decode($protected) : array();
$upload_dir = wp_upload_dir();
$upload_dir = $upload_dir['basedir'];
$htaccess_rules = "