From 36dcd706d8b448a94be1f80f24830786d1a74b78 Mon Sep 17 00:00:00 2001 From: Fabian Schmid Date: Wed, 6 Sep 2023 14:38:24 +0200 Subject: [PATCH] [FIX] 0036305: Instruction Files Issue - Unizip a zip-file does not work, and with German language -> it is possible to "unzip" a standard-file --- .../classes/class.ilFileSystemGUI.php | 5 ++-- .../classes/class.ilFileSystemTableGUI.php | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Services/FileSystem/classes/class.ilFileSystemGUI.php b/Services/FileSystem/classes/class.ilFileSystemGUI.php index 053723d5c075..d7f8862e9bfb 100755 --- a/Services/FileSystem/classes/class.ilFileSystemGUI.php +++ b/Services/FileSystem/classes/class.ilFileSystemGUI.php @@ -704,7 +704,7 @@ public function uploadFile(): void $name, true ); - // end upload + // end upload } elseif ($uploaded_file) { // check if the file is in the ftp directory and readable if (ilUploadFiles::_checkUploadFile($uploaded_file)) { @@ -935,7 +935,8 @@ public function defineCommands(): void "method" => "unzipFile", "name" => $this->lng->txt("unzip"), "int" => true, - "single" => true + "single" => true, + "id" => "unzip_file" ), 3 => array( "object" => $this, diff --git a/Services/FileSystem/classes/class.ilFileSystemTableGUI.php b/Services/FileSystem/classes/class.ilFileSystemTableGUI.php index 7868e386c783..d76cc9792e23 100644 --- a/Services/FileSystem/classes/class.ilFileSystemTableGUI.php +++ b/Services/FileSystem/classes/class.ilFileSystemTableGUI.php @@ -82,7 +82,8 @@ public function __construct( $this->row_commands[] = array( "cmd" => "extCommand_" . $i, "caption" => $command["name"], - "allow_dir" => $command["allow_dir"] ?? "" + "allow_dir" => $command["allow_dir"] ?? "", + "id" => $command["id"] ?? "", ); } } @@ -254,13 +255,26 @@ protected function fillRow(array $a_set): void } // single item commands - if (sizeof($this->row_commands) && - !($a_set["type"] == "dir" && $a_set["entry"] == "..")) { + + $zip_mime_types = [ + "application/zip", + "application/x-zip" + ]; + + if (count($this->row_commands) > 0 + && !(($a_set["type"] ?? '') === "dir" && ($a_set["entry"] ?? '') === "..")) { $advsel = new ilAdvancedSelectionListGUI(); $advsel->setListTitle(''); foreach ($this->row_commands as $rcom) { - if ($rcom["allow_dir"] || $a_set["type"] != "dir") { - if (($rcom["caption"] == "Unzip" && MimeType::getMimeType($this->cur_dir . $a_set['entry']) == "application/zip") || $rcom["caption"] != "Unzip") { + if ($rcom["allow_dir"] || ($a_set["type"] ?? '') !== "dir") { + // see https://mantis.ilias.de/view.php?id=36305 + // will be dropped soon anyway... + $path = $this->cur_dir . $a_set['entry']; + $mime_type = MimeType::getMimeType($path); + if ( + $rcom["id"] !== "unzip_file" + || ($rcom["id"] === "unzip_file" && in_array($mime_type, $zip_mime_types)) + ) { $this->ctrl->setParameter($this->parent_obj, "fhsh", $hash); $url = $this->ctrl->getLinkTarget($this->parent_obj, $rcom["cmd"]); $this->ctrl->setParameter($this->parent_obj, "fhsh", "");