diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 77e21df..9fc3d9f 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -165,7 +165,7 @@ final class ApiController extends Controller } $upload = new UploadFile(); - $upload->setOutputDir($outputDir); + $upload->outputDir = $outputDir; $status = $upload->upload($files, $name, $absolute, $encryptionKey); @@ -178,7 +178,7 @@ final class ApiController extends Controller string $path = '', ) : array { $upload = new UploadFile(); - $upload->setOutputDir($path); + $upload->outputDir = $path; $status = $upload->upload($files, $name, true, ''); diff --git a/Models/Media.php b/Models/Media.php index 0316759..6fcf41a 100755 --- a/Models/Media.php +++ b/Models/Media.php @@ -261,7 +261,7 @@ class Media implements \JsonSerializable */ public function setPassword(?string $password) : void { - $temp = $password === null ? null : \password_hash($password, \PASSWORD_DEFAULT); + $temp = $password === null ? null : \password_hash($password, \PASSWORD_BCRYPT); $this->password = $temp === false ? null : $temp; } diff --git a/Models/UploadFile.php b/Models/UploadFile.php index af55cdd..3e3c0f6 100755 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -45,7 +45,7 @@ class UploadFile * @var bool * @since 1.0.0 */ - private bool $isInterlaced = true; + public bool $isInterlaced = true; /** * Upload max size. @@ -53,7 +53,7 @@ class UploadFile * @var int * @since 1.0.0 */ - private int $maxSize = 50000000; + public int $maxSize = 50000000; /** * Allowed mime types. @@ -69,15 +69,7 @@ class UploadFile * @var string * @since 1.0.0 */ - private string $outputDir = __DIR__ . '/../../Modules/Media/Files'; - - /** - * Output file name. - * - * @var string - * @since 1.0.0 - */ - private string $fileName = ''; + public string $outputDir = __DIR__ . '/../../Modules/Media/Files'; /** * Output file name. @@ -85,7 +77,7 @@ class UploadFile * @var bool * @since 1.0.0 */ - private bool $preserveFileName = true; + public bool $preserveFileName = true; /** * Upload file to server. @@ -153,8 +145,8 @@ class UploadFile return $result; } - $split = \explode('.', $f['name']); - $result[$key]['name'] = \count($files) === 1 && !empty($name) + $split = \explode('.', $f['name']); + $result[$key]['filename'] = \count($files) === 1 && !empty($name) ? $name : $f['name']; @@ -162,14 +154,14 @@ class UploadFile $result[$key]['extension'] = $extension; if ($this->preserveFileName) { - $this->fileName = $f['name']; - $result[$key]['filename'] = $this->fileName; + $name = $f['name']; + $result[$key]['filename'] = $name; } - if (empty($this->fileName) || \is_file($path . '/' . $this->fileName)) { + if (empty($name) || \is_file($path . '/' . $name)) { try { - $this->fileName = $this->createFileName($path, $f['tmp_name'], $extension); - $result[$key]['filename'] = $this->fileName; + $name = $this->createFileName($path, $f['tmp_name'], $extension); + $result[$key]['filename'] = $name; } catch (\Exception $e) { $result[$key]['filename'] = $f['name']; $result[$key]['status'] = UploadStatus::FAILED_HASHING; @@ -186,7 +178,7 @@ class UploadFile } } - if (!\rename($f['tmp_name'], $dest = $path . '/' . $this->fileName)) { + if (!\rename($f['tmp_name'], $dest = $path . '/' . $name)) { $result[$key]['status'] = UploadStatus::NOT_MOVABLE; return $result; @@ -349,40 +341,6 @@ class UploadFile } } - /** - * @return int - * - * @since 1.0.0 - */ - public function getMaxSize() : int - { - return $this->maxSize; - } - - /** - * @param bool $isInterlaced Is interlaced - * - * @return void - * - * @since 1.0.0 - */ - public function setInterlaced(bool $isInterlaced) : void - { - $this->isInterlaced = $isInterlaced; - } - - /** - * @param int $maxSize Max allowed file size - * - * @return void - * - * @since 1.0.0 - */ - public function setMaxSize(int $maxSize) : void - { - $this->maxSize = $maxSize; - } - /** * @return string[] * @@ -416,66 +374,4 @@ class UploadFile { $this->allowedTypes[] = $allowedTypes; } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getOutputDir() : string - { - return $this->outputDir; - } - - /** - * Define output directory of the upload - * - * @param string $outputDir Output directory of the uploaded file - * - * @return void - * - * @since 1.0.0 - */ - public function setOutputDir(string $outputDir) : void - { - $this->outputDir = $outputDir; - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getFileName() : string - { - return $this->fileName; - } - - /** - * Set the file name of the uploaded file - * - * @param string $fileName File name of the uploaded file - * - * @return void - * - * @since 1.0.0 - */ - public function setFileName(string $fileName) : void - { - $this->fileName = $fileName; - } - - /** - * Define if the uploaded file name should be the same file name as the original file - * - * @param bool $preserveFileName Keep file name of the original file - * - * @return void - * - * @since 1.0.0 - */ - public function setPreserveFileName(bool $preserveFileName) : void - { - $this->preserveFileName = $preserveFileName; - } } diff --git a/Theme/Backend/Components/Media/list.tpl.php b/Theme/Backend/Components/Media/list.tpl.php index 4db3fa4..6d3097c 100755 --- a/Theme/Backend/Components/Media/list.tpl.php +++ b/Theme/Backend/Components/Media/list.tpl.php @@ -1,4 +1,17 @@ -getData('path') ?? '/'); -/** - * @var \Modules\Media\Models\Media[] $media - */ -$media = $this->getData('media'); +/** @var \Modules\Media\Models\Media[] $media */ +$media = $this->getData('media') ?? []; + +/** @var \Modules\Admin\Models\Account $account */ $account = $this->getData('account'); $accountDir = $account->getId() . ' ' . $account->login; @@ -193,7 +192,7 @@ $next = empty($media) ? '{/prefix}media/list' : '{/prefix}media/list?{?}&id= getTags(); foreach ($tags as $tag) : ?> - icon !== null ? '' : ''; ?>printHtml($tag->getTitle()); ?> + icon !== null ? '' : ''; ?>printHtml($tag->getL11n()); ?> printHtml($value->extension); ?> diff --git a/Theme/Backend/media-single.tpl.php b/Theme/Backend/media-single.tpl.php index b9a520a..53eb4d6 100755 --- a/Theme/Backend/media-single.tpl.php +++ b/Theme/Backend/media-single.tpl.php @@ -56,7 +56,7 @@ echo $this->getData('nav')->render(); ); ?> getHtml('Tags'); ?> - icon !== null ? '' : ''; ?>printHtml($tag->getTitle()); ?> + icon !== null ? '' : ''; ?>printHtml($tag->getL11n()); ?> getHtml('Description'); ?> description; ?>