@@ -2,7 +2,11 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace System\Utils { |
| 4 | 4 | |
| 5 | - use System\Modules\Informer, System\Utils\Messages, Explorer, Language, Request; |
|
| 5 | + use System\Modules\Informer; |
|
| 6 | + use System\Utils\Messages; |
|
| 7 | + use Explorer; |
|
| 8 | + use Language; |
|
| 9 | + use Request; |
|
| 6 | 10 | |
| 7 | 11 | abstract class Uploader { |
| 8 | 12 | |
@@ -10,19 +10,33 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | private static function translateError(int $error) { |
| 12 | 12 | |
| 13 | - if ($error === UPLOAD_ERR_INI_SIZE) return 'UPLOADER_ERROR_INI_SIZE'; |
|
| 13 | + if ($error === UPLOAD_ERR_INI_SIZE) { |
|
| 14 | + return 'UPLOADER_ERROR_INI_SIZE'; |
|
| 15 | + } |
|
| 14 | 16 | |
| 15 | - if ($error === UPLOAD_ERR_FORM_SIZE) return 'UPLOADER_ERROR_FORM_SIZE'; |
|
| 17 | + if ($error === UPLOAD_ERR_FORM_SIZE) { |
|
| 18 | + return 'UPLOADER_ERROR_FORM_SIZE'; |
|
| 19 | + } |
|
| 16 | 20 | |
| 17 | - if ($error === UPLOAD_ERR_PARTIAL) return 'UPLOADER_ERROR_PARTIAL'; |
|
| 21 | + if ($error === UPLOAD_ERR_PARTIAL) { |
|
| 22 | + return 'UPLOADER_ERROR_PARTIAL'; |
|
| 23 | + } |
|
| 18 | 24 | |
| 19 | - if ($error === UPLOAD_ERR_NO_FILE) return 'UPLOADER_ERROR_NO_FILE'; |
|
| 25 | + if ($error === UPLOAD_ERR_NO_FILE) { |
|
| 26 | + return 'UPLOADER_ERROR_NO_FILE'; |
|
| 27 | + } |
|
| 20 | 28 | |
| 21 | - if ($error === UPLOAD_ERR_NO_TMP_DIR) return 'UPLOADER_ERROR_NO_TMP_DIR'; |
|
| 29 | + if ($error === UPLOAD_ERR_NO_TMP_DIR) { |
|
| 30 | + return 'UPLOADER_ERROR_NO_TMP_DIR'; |
|
| 31 | + } |
|
| 22 | 32 | |
| 23 | - if ($error === UPLOAD_ERR_CANT_WRITE) return 'UPLOADER_ERROR_CANT_WRITE'; |
|
| 33 | + if ($error === UPLOAD_ERR_CANT_WRITE) { |
|
| 34 | + return 'UPLOADER_ERROR_CANT_WRITE'; |
|
| 35 | + } |
|
| 24 | 36 | |
| 25 | - if ($error === UPLOAD_ERR_EXTENSION) return 'UPLOADER_ERROR_EXTENSION'; |
|
| 37 | + if ($error === UPLOAD_ERR_EXTENSION) { |
|
| 38 | + return 'UPLOADER_ERROR_EXTENSION'; |
|
| 39 | + } |
|
| 26 | 40 | |
| 27 | 41 | # ------------------------ |
| 28 | 42 | |
@@ -33,39 +47,55 @@ discard block |
||
| 33 | 47 | |
| 34 | 48 | public static function save(string $name, string $dir_name) { |
| 35 | 49 | |
| 36 | - if ((false === ($file = Request::file($name))) || !is_uploaded_file($file['tmp_name'])) return false; |
|
| 50 | + if ((false === ($file = Request::file($name))) || !is_uploaded_file($file['tmp_name'])) { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 37 | 53 | |
| 38 | 54 | # Check for demo mode |
| 39 | 55 | |
| 40 | - if (Informer::isDemoMode()) return 'DEMO_MODE_RESTRICTION'; |
|
| 56 | + if (Informer::isDemoMode()) { |
|
| 57 | + return 'DEMO_MODE_RESTRICTION'; |
|
| 58 | + } |
|
| 41 | 59 | |
| 42 | 60 | # Check for upload errors |
| 43 | 61 | |
| 44 | - if ($file['error'] !== UPLOAD_ERR_OK) return self::translateError($file['error']); |
|
| 62 | + if ($file['error'] !== UPLOAD_ERR_OK) { |
|
| 63 | + return self::translateError($file['error']); |
|
| 64 | + } |
|
| 45 | 65 | |
| 46 | 66 | # Check size |
| 47 | 67 | |
| 48 | - if ($file['size'] > CONFIG_UPLOADS_MAX_SIZE) return 'UPLOADER_ERROR_SIZE'; |
|
| 68 | + if ($file['size'] > CONFIG_UPLOADS_MAX_SIZE) { |
|
| 69 | + return 'UPLOADER_ERROR_SIZE'; |
|
| 70 | + } |
|
| 49 | 71 | |
| 50 | 72 | # Check file extension |
| 51 | 73 | |
| 52 | 74 | $extensions = ['php', 'phtml', 'php3', 'php4', 'php5', 'phps']; |
| 53 | 75 | |
| 54 | - if (in_array(Explorer::extension($file['name'], false), $extensions)) return 'UPLOADER_ERROR_TYPE'; |
|
| 76 | + if (in_array(Explorer::extension($file['name'], false), $extensions)) { |
|
| 77 | + return 'UPLOADER_ERROR_TYPE'; |
|
| 78 | + } |
|
| 55 | 79 | |
| 56 | 80 | # Check target directory |
| 57 | 81 | |
| 58 | - if (!Explorer::isDir($dir_name)) return 'UPLOADER_ERROR_DIR'; |
|
| 82 | + if (!Explorer::isDir($dir_name)) { |
|
| 83 | + return 'UPLOADER_ERROR_DIR'; |
|
| 84 | + } |
|
| 59 | 85 | |
| 60 | 86 | # Check target file |
| 61 | 87 | |
| 62 | 88 | $file_name = ($dir_name . '/' . basename($file['name'])); |
| 63 | 89 | |
| 64 | - if (Explorer::isDir($file_name) || Explorer::isFile($file_name)) return 'UPLOADER_ERROR_EXISTS'; |
|
| 90 | + if (Explorer::isDir($file_name) || Explorer::isFile($file_name)) { |
|
| 91 | + return 'UPLOADER_ERROR_EXISTS'; |
|
| 92 | + } |
|
| 65 | 93 | |
| 66 | 94 | # Save uploaded file |
| 67 | 95 | |
| 68 | - if (!@move_uploaded_file($file['tmp_name'], $file_name)) return 'UPLOADER_ERROR_SAVE'; |
|
| 96 | + if (!@move_uploaded_file($file['tmp_name'], $file_name)) { |
|
| 97 | + return 'UPLOADER_ERROR_SAVE'; |
|
| 98 | + } |
|
| 69 | 99 | |
| 70 | 100 | # ------------------------ |
| 71 | 101 | |
@@ -47,13 +47,17 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | # Check for demo mode |
| 49 | 49 | |
| 50 | - if (Informer::isDemoMode()) return $ajax->error(Language::get('DEMO_MODE_RESTRICTION')); |
|
| 50 | + if (Informer::isDemoMode()) { |
|
| 51 | + return $ajax->error(Language::get('DEMO_MODE_RESTRICTION')); |
|
| 52 | + } |
|
| 51 | 53 | |
| 52 | 54 | # Remove item |
| 53 | 55 | |
| 54 | 56 | if (Request::post('action') === 'remove') { |
| 55 | 57 | |
| 56 | - if (!$this->entity->remove()) return $ajax->error(Language::get(static::$message_error_remove)); |
|
| 58 | + if (!$this->entity->remove()) { |
|
| 59 | + return $ajax->error(Language::get(static::$message_error_remove)); |
|
| 60 | + } |
|
| 57 | 61 | } |
| 58 | 62 | |
| 59 | 63 | # ------------------------ |
@@ -84,7 +88,9 @@ discard block |
||
| 84 | 88 | |
| 85 | 89 | # Handle ajax request |
| 86 | 90 | |
| 87 | - if (Request::isAjax()) return $this->handleAjax(); |
|
| 91 | + if (Request::isAjax()) { |
|
| 92 | + return $this->handleAjax(); |
|
| 93 | + } |
|
| 88 | 94 | |
| 89 | 95 | # Create form |
| 90 | 96 | |
@@ -101,7 +107,9 @@ discard block |
||
| 101 | 107 | |
| 102 | 108 | # Display success message |
| 103 | 109 | |
| 104 | - if (false !== Request::get('submitted')) Messages::success(Language::get(static::$message_success_rename)); |
|
| 110 | + if (false !== Request::get('submitted')) { |
|
| 111 | + Messages::success(Language::get(static::$message_success_rename)); |
|
| 112 | + } |
|
| 105 | 113 | |
| 106 | 114 | # ------------------------ |
| 107 | 115 | |
@@ -29,23 +29,31 @@ |
||
| 29 | 29 | |
| 30 | 30 | # Check for demo mode |
| 31 | 31 | |
| 32 | - if (Informer::isDemoMode()) return 'DEMO_MODE_RESTRICTION'; |
|
| 32 | + if (Informer::isDemoMode()) { |
|
| 33 | + return 'DEMO_MODE_RESTRICTION'; |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | # Validate name |
| 35 | 37 | |
| 36 | - if (false === ($name = Filemanager\Validate::name($name))) return 'FILEMANAGER_ERROR_NAME_INVALID'; |
|
| 38 | + if (false === ($name = Filemanager\Validate::name($name))) { |
|
| 39 | + return 'FILEMANAGER_ERROR_NAME_INVALID'; |
|
| 40 | + } |
|
| 37 | 41 | |
| 38 | 42 | # Check if item exists |
| 39 | 43 | |
| 40 | 44 | if ((0 !== strcasecmp($this->entity->name(), $name)) && |
| 41 | 45 | |
| 42 | - @file_exists($this->entity->parent()->pathFull() . $name)) return 'FILEMANAGER_ERROR_EXISTS'; |
|
| 46 | + @file_exists($this->entity->parent()->pathFull() . $name)) { |
|
| 47 | + return 'FILEMANAGER_ERROR_EXISTS'; |
|
| 48 | + } |
|
| 43 | 49 | |
| 44 | 50 | # Rename item |
| 45 | 51 | |
| 46 | - if (!$this->entity->rename($name)) return (($this->entity->type() === FILEMANAGER_TYPE_DIR) ? |
|
| 52 | + if (!$this->entity->rename($name)) { |
|
| 53 | + return (($this->entity->type() === FILEMANAGER_TYPE_DIR) ? |
|
| 47 | 54 | |
| 48 | 55 | 'FILEMANAGER_ERROR_DIR_RENAME' : 'FILEMANAGER_ERROR_FILE_RENAME'); |
| 56 | + } |
|
| 49 | 57 | |
| 50 | 58 | # ------------------------ |
| 51 | 59 | |
@@ -29,23 +29,31 @@ |
||
| 29 | 29 | |
| 30 | 30 | # Check for demo mode |
| 31 | 31 | |
| 32 | - if (Informer::isDemoMode()) return 'DEMO_MODE_RESTRICTION'; |
|
| 32 | + if (Informer::isDemoMode()) { |
|
| 33 | + return 'DEMO_MODE_RESTRICTION'; |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | # Validate name |
| 35 | 37 | |
| 36 | - if (false === ($name = Filemanager\Validate::name($name))) return 'FILEMANAGER_ERROR_NAME_INVALID'; |
|
| 38 | + if (false === ($name = Filemanager\Validate::name($name))) { |
|
| 39 | + return 'FILEMANAGER_ERROR_NAME_INVALID'; |
|
| 40 | + } |
|
| 37 | 41 | |
| 38 | 42 | # Check if item exists |
| 39 | 43 | |
| 40 | - if (@file_exists($this->parent->pathFull() . $name)) return 'FILEMANAGER_ERROR_EXISTS'; |
|
| 44 | + if (@file_exists($this->parent->pathFull() . $name)) { |
|
| 45 | + return 'FILEMANAGER_ERROR_EXISTS'; |
|
| 46 | + } |
|
| 41 | 47 | |
| 42 | 48 | # Create item |
| 43 | 49 | |
| 44 | 50 | $entity = Filemanager::get($type, $this->parent); |
| 45 | 51 | |
| 46 | - if (!$entity->create($name)) return (($entity->type() === FILEMANAGER_TYPE_DIR) ? |
|
| 52 | + if (!$entity->create($name)) { |
|
| 53 | + return (($entity->type() === FILEMANAGER_TYPE_DIR) ? |
|
| 47 | 54 | |
| 48 | 55 | 'FILEMANAGER_ERROR_DIR_CREATE' : 'FILEMANAGER_ERROR_FILE_CREATE'); |
| 56 | + } |
|
| 49 | 57 | |
| 50 | 58 | # ------------------------ |
| 51 | 59 | |