Skip to content
Snippets Groups Projects
Commit 89fceb4f authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

re #448

parent 3e7e8848
No related branches found
No related tags found
No related merge requests found
...@@ -111,7 +111,7 @@ class FileManager ...@@ -111,7 +111,7 @@ class FileManager
return 'file-generic'; return 'file-generic';
} }
list($category, $type) = explode('/', $mime_type, 2); [$category, $type] = explode('/', $mime_type, 2);
switch($category) { switch($category) {
case 'image': case 'image':
...@@ -1618,7 +1618,7 @@ class FileManager ...@@ -1618,7 +1618,7 @@ class FileManager
$header_parts = explode(';', $disposition_header); $header_parts = explode(';', $disposition_header);
foreach ($header_parts as $part) { foreach ($header_parts as $part) {
$part = trim($part); $part = trim($part);
list($key, $value) = explode('=', $part, 2); [$key, $value] = explode('=', $part, 2);
if (mb_strtolower($key) === 'filename') { if (mb_strtolower($key) === 'filename') {
$header['filename'] = trim($value, '"'); $header['filename'] = trim($value, '"');
} }
...@@ -1725,10 +1725,10 @@ class FileManager ...@@ -1725,10 +1725,10 @@ class FileManager
} }
/** /**
* returns config array for upload types and sizes * returns config array for upload types and sizes for a given range id
* *
* @param $range_id string id of Course Institute User * @param string $range_id id of Course Institute User
* @param null $user_id string * @param string|null $user_id Optional user id
* @return array * @return array
*/ */
public static function getUploadTypeConfig($range_id, $user_id = null) public static function getUploadTypeConfig($range_id, $user_id = null)
...@@ -1753,15 +1753,28 @@ class FileManager ...@@ -1753,15 +1753,28 @@ class FileManager
$active_upload_type = 'attachments'; $active_upload_type = 'attachments';
} }
if (!isset($GLOBALS['UPLOAD_TYPES'][$active_upload_type])) { return self::loadUploadTypeConfig($active_upload_type, $status);
$active_upload_type = 'default'; }
/**
* Loads the upload type configuration for a specific type and status.
*
* @param string $type
* @param string $status
*
* @return array{type: string, file_types: array, file_size: int}
*/
public static function loadUploadTypeConfig(string $type, string $status): array
{
if (!isset($GLOBALS['UPLOAD_TYPES'][$type])) {
$type = 'default';
} }
$upload_type = $GLOBALS['UPLOAD_TYPES'][$active_upload_type]; $upload_type = $GLOBALS['UPLOAD_TYPES'][$type];
return [ return [
'type' => $upload_type['type'], 'type' => $upload_type['type'],
'file_types' => $upload_type['file_types'], 'file_types' => $upload_type['file_types'],
'file_size' => $upload_type['file_sizes'][$status] 'file_size' => $upload_type['file_sizes'][$status],
]; ];
} }
......
...@@ -238,6 +238,25 @@ class MessageFolder extends StandardFolder implements FolderType ...@@ -238,6 +238,25 @@ class MessageFolder extends StandardFolder implements FolderType
{ {
} }
/**
* This method handles file upload validation.
*
* @param array $uploaded_file The uploaded file that shall be validated.
* @param string $user_id The user who wishes to upload a file
* in this MessageFolder.
*
* @return string|null An error message on failure, null on success.
*/
public function validateUpload(FileType $newfile, $user_id)
{
$status = $GLOBALS['perm']->get_perm($user_id);
return $this->getValidationMessages(
FileManager::loadUploadTypeConfig('attachments', $status),
$newfile
);
}
/** /**
* Handles the deletion of a file inside this folder. * Handles the deletion of a file inside this folder.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment