function video_multidownload_download in Video 6.2
Same name and namespace in other branches
- 5 plugins/video_multidownload/video_multidownload.module \video_multidownload_download()
- 6 plugins/video_multidownload/video_multidownload.module \video_multidownload_download()
1 string reference to 'video_multidownload_download'
- video_multidownload_menu in plugins/
video_multidownload/ video_multidownload.module - Implementation of hook_menu().
File
- plugins/
video_multidownload/ video_multidownload.module, line 181 - Enable multiple file download in video module.
Code
function video_multidownload_download() {
if ($node = node_load(arg(1))) {
if (variable_get("video_multidownload", 0) == 0 or $node->disable_multidownload == 1) {
}
else {
if (arg(3) != '') {
//If we are passed an encoded URL redirect to the downloader.
_video_multidownload_download_goto(arg(3), $node->vid, TRUE);
}
else {
//Multiple file downloads is turned on.
$download_error = FALSE;
//Initialize and clear the error flag.
$node->file_array = array();
//Initialize the final file array.
global $base_url;
$full_download_folder = getcwd() . '/' . $node->download_folder;
//Get absolute path to folder.
//If the download folder is set and valid scan it for files.
if ($node->download_folder != '' and file_exists($full_download_folder)) {
$scan_download_folder = _video_multidownload_scandir($full_download_folder);
//Get array of file names in the directory.
$scan_download_folder['local_dir'] = $full_download_folder;
//For getting filesize.
$scan_download_folder['dir_stub'] = $node->download_folder;
//To put in the URL.
$folder_array[] = $scan_download_folder;
}
//If option is set to use "play" folder and it exists, scan it for files.
$play_dir_stub = str_replace(basename($node->vidfile), "", $node->vidfile);
//Remove the filename from the play file to get directory.
$play_dir = getcwd() . '/' . $play_dir_stub;
//Get the local directory path where the file is kept.
if ($node->use_play_folder == 1 and file_exists($play_dir) and $play_dir_stub != '/') {
//Make sure play stub won't allow scanning base drupal directory.
$scan_play_folder = _video_multidownload_scandir($play_dir);
$scan_play_folder['local_dir'] = $play_dir;
//For getting filesize.
$scan_play_folder['dir_stub'] = $play_dir_stub;
//To put in the URL.
$folder_array[] = $scan_play_folder;
}
if (count($folder_array) > 0) {
//Make sure we have a folder to scan.
foreach ($folder_array as $dir_scan) {
//Scan through one or both folders results.
foreach ($dir_scan as $file) {
//Go through each file in the directory.
if (is_file($dir_scan['local_dir'] . "/" . $file)) {
//Make sure it's a valid file.
//Checks the new file with the files already in the array to eliminate dupes.
$match = false;
foreach ($node->file_array as $file_array_file) {
if ($file_array_file['file'] == $file) {
//If the file is already in the array.
$match = TRUE;
}
}
//If we get here with $match still set FALSE we don't have a dupe.
$file_ext = substr($file, strrpos($file, '.') + 1);
//Get the file extension.
$ext_array = explode(',', variable_get('video_download_ext', 'mov,wmv,avi'));
if (!$match and in_array($file_ext, $ext_array)) {
//Only add file if it's not already in the array and it's extension shouldn't be hidden.
$file_array_size[] = filesize($dir_scan['local_dir'] . $file);
//Create an array of the file sizes for sorting.
global $base_url;
$file_url = $base_url . '/' . $dir_scan['dir_stub'] . $file;
//Generate absolute URL to video.
$file_url = str_replace(' ', '%20', $file_url);
//Replace any spaces in filename.
$encoded_url = base64_encode($file_url);
//Encode URL to base64 MIME value so it can be passed in URL.
$encoded_url = str_replace('/', '-', $encoded_url);
//Replace "/" with "-" so it doesn't mess up the URL.
$node->file_array[] = array(
'file' => $file,
'type' => $file_ext,
'size' => filesize($dir_scan['local_dir'] . $file),
'encoded_url' => $encoded_url,
);
}
}
//Close the valid file check.
}
//Close the directory scan.
}
//Close scan location array.
if (count($node->file_array) > 0) {
//Make sure atleast 1 file was found.
array_multisort($file_array_size, SORT_ASC, $node->file_array);
//Sort based of file size.
}
else {
//Else if no files were found in the directory.
$download_error = TRUE;
}
}
else {
//Else if we have no valid folders to scan.
$download_error = TRUE;
}
//If there was no error send the files array to the theme function for display.
if ($download_error == FALSE) {
print theme('video_multidownload_download', $node);
//Print to the screen from the theme_video_download function.
}
else {
//Else if there is an error download the play file.
_video_download_goto($node->vidfile, $node->vid);
}
}
}
//Close multi-file downloads is turned on.
}
}