/** * Downloads a file, a folder or a bunch of either. * * @param String $entry_id Directory entry id of the file or folder or * 'flashed' for a bulk operation * @param bool $inline Indicates whether the download should be * marked as inline (to display the file in the * browser) */ public function index_action($entry_id, $inline = false) { $download_files = array(); $download_type = 'single'; $filename = null; // Download files from bulk-action? if ($entry_id === 'flashed') { foreach ($this->flash['ids'] as $id) { $entry = new DirectoryEntry($id); if ($entry->isDirectory() && !$entry->checkAccess(null, false)) { throw new AccessDeniedException(_('Sie dürfen keinen fremden Ordner herunterladen.')); } $download_files[] = $entry; } $download_type = 'multiple'; } else { try { // Get directory entry $entry = new DirectoryEntry($entry_id); // Determine download type $filename = $entry->file->filename; $download_files[] = $entry; $download_type = $entry->isDirectory() ? 'multiple' : 'single'; if (!$entry->checkAccess(null, false)) { if ($entry->isDirectory()) { throw new AccessDeniedException(_('Sie dürfen keinen fremden Ordner herunterladen.')); } elseif (false) { // TODO: Permission check inactive for now throw new AccessDeniedException(_('Sie dürfen keine fremde Datei herunterladen.')); } } } catch (InvalidArgumentException $e) { // Entry id is not a valid directory entry, // so we assume that it is a foreign folder if ($entry_id !== $GLOBALS['user']->id) { if (!User::exists($entry_id)) { throw new InvalidArgumentException(_('404 - File not found')); } elseif (!Config::get()->PERSONALDOCUMENT_OPEN_ACCESS) { throw new AccessDeniedException(_('Sie dürfen keinen fremden Ordner herunterladen.')); } } $download_files[] = new RootDirectory($entry_id); $download_type = 'multiple'; } } // Download either a zip file or single file if ($download_type === 'multiple') { $this->download_files($download_files, $filename ?: 'Stud-IP'); } else { $this->download_file(reset($download_files), $inline); } }