diff --git a/Admin/Installer.php b/Admin/Installer.php index 01380b6..33addb7 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -208,7 +208,7 @@ final class Installer extends InstallerAbstract /** @var \Modules\Media\Controller\ApiController $module */ $module = $app->moduleManager->getModuleInstance('Media'); - $path = !isset($data['path']) ? ($data['virtualPath'] ?? '') : $data['path']; + $path = isset($data['path']) ? ($data['path']) : $data['virtualPath'] ?? ''; $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); @@ -285,9 +285,9 @@ final class Installer extends InstallerAbstract $module->apiMediaTypeL11nCreate($request, $response); } - return !\is_array($type) - ? $type->toArray() - : $type; + return \is_array($type) + ? $type + : $type->toArray(); } /** diff --git a/Controller/ApiController.php b/Controller/ApiController.php index a9ec43a..3d9e969 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -819,14 +819,10 @@ final class ApiController extends Controller } $virtualPath = \urldecode($request->getDataString('virtualpath') ?? '/'); - - $outputDir = ''; - $basePath = __DIR__ . '/../../../Modules/Media/Files'; - if (!$request->hasData('path')) { - $outputDir = self::createMediaPath($basePath); - } else { - $outputDir = $basePath . '/' . \ltrim($request->getDataString('path') ?? '', '\\/'); - } + $basePath = __DIR__ . '/../../../Modules/Media/Files'; + $outputDir = $request->hasData('path') + ? $basePath . '/' . \ltrim($request->getDataString('path') ?? '', '\\/') + : self::createMediaPath($basePath); $dirPath = $outputDir . '/' . ($request->getDataString('name') ?? ''); $outputDir = \substr($outputDir, \strlen(__DIR__ . '/../../..')); @@ -896,7 +892,7 @@ final class ApiController extends Controller { $status = false; if (!empty($physicalPath)) { - $status = !\is_dir($physicalPath) ? \mkdir($physicalPath, 0755, true) : true; + $status = \is_dir($physicalPath) ? true : \mkdir($physicalPath, 0755, true); } $path = \trim($path, '/'); @@ -972,16 +968,13 @@ final class ApiController extends Controller $basePath = __DIR__ . '/../../../Modules/Media/Files'; if (!$request->hasData('path')) { $outputDir = self::createMediaPath($basePath); + } elseif (\stripos( + FileUtils::absolute($basePath . '/' . \ltrim($path, '\\/')), + FileUtils::absolute(__DIR__ . '/../../../') + ) !== 0) { + $outputDir = self::createMediaPath($basePath); } else { - if (\stripos( - FileUtils::absolute($basePath . '/' . \ltrim($path, '\\/')), - FileUtils::absolute(__DIR__ . '/../../../') - ) !== 0 - ) { - $outputDir = self::createMediaPath($basePath); - } else { - $outputDir = $basePath . '/' . \ltrim($path, '\\/'); - } + $outputDir = $basePath . '/' . \ltrim($path, '\\/'); } if (!\is_dir($outputDir)) { @@ -1079,7 +1072,6 @@ final class ApiController extends Controller return; } - if (!isset($data, $data['guard'])) { if (!isset($data)) { $data = []; @@ -1087,11 +1079,9 @@ final class ApiController extends Controller $data['guard'] = __DIR__ . '/../Files'; } - } else { - if (empty($data) || !isset($data['guard'])) { - $response->header->status = RequestStatusCode::R_403; - $this->createInvalidReturnResponse($request, $response, $media); - } + } elseif (empty($data) || !isset($data['guard'])) { + $response->header->status = RequestStatusCode::R_403; + $this->createInvalidReturnResponse($request, $response, $media); } if (!Guard::isSafePath($filePath, $data['guard'] ?? '')) { diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 971fcbc..062dfbc 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -243,28 +243,24 @@ final class BackendController extends Controller $view->setTemplate('/Modules/Media/Theme/Backend/media-list'); } else { $sub = $request->getDataString('sub') ?? ''; - if (\is_dir($media->getPath()) - && (\is_dir($media->getPath() . $sub)) - ) { + if (\is_dir($media->getPath() . $sub)) { $listView = new ListView($this->app->l11nManager, $request, $response); $listView->setTemplate('/modules/Media/Theme/Backend/Components/Media/list'); $view->data['view'] = $listView; - } else { - if ($media->class === MediaClass::REFERENCE) { - /** @var \Modules\Media\Models\Media $media */ - $media->source = MediaMapper::get() - ->with('createdBy') - ->with('tags') - ->with('tags/title') - ->with('content') - ->where('id', $media->source?->id ?? 0) - ->where('tags/title/language', $request->header->l11n->language) - ->execute(); + } elseif ($media->class === MediaClass::REFERENCE) { + /** @var \Modules\Media\Models\Media $media */ + $media->source = MediaMapper::get() + ->with('createdBy') + ->with('tags') + ->with('tags/title') + ->with('content') + ->where('id', $media->source?->id ?? 0) + ->where('tags/title/language', $request->header->l11n->language) + ->execute(); - $view->data['view'] = $this->createMediaView($media->source, $request, $response); - } else { - $view->data['view'] = $this->createMediaView($media, $request, $response); - } + $view->data['view'] = $this->createMediaView($media->source, $request, $response); + } else { + $view->data['view'] = $this->createMediaView($media, $request, $response); } } } diff --git a/Models/UploadFile.php b/Models/UploadFile.php index e041189..6d731cc 100755 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -165,14 +165,14 @@ class UploadFile return $result; } - if (!empty($this->allowedTypes) && \array_search($f['type'], $this->allowedTypes, true) === false) { + if (!empty($this->allowedTypes) && !in_array($f['type'], $this->allowedTypes, true)) { $result[$key]['status'] = UploadStatus::WRONG_EXTENSION; return $result; } $split = \explode('.', $f['name']); - $result[$key]['filename'] = !empty($fileNames) ? $fileNames[$fCounter] : $f['name']; + $result[$key]['filename'] = empty($fileNames) ? $f['name'] : $fileNames[$fCounter]; $result[$key]['extension'] = ($c = \count($split)) > 1 ? $split[$c - 1] : ''; if (!$this->preserveFileName || \is_file($path . '/' . $result[$key]['filename'])) { @@ -190,10 +190,8 @@ class UploadFile } } - if (!\is_dir($path)) { - if (!Directory::create($path, 0755, true)) { - FileLogger::getInstance()->error('Couldn\t upload media file. There maybe is a problem with your permission or uploaded file.'); - } + if (!\is_dir($path) && !Directory::create($path, 0755, true)) { + FileLogger::getInstance()->error('Couldn\t upload media file. There maybe is a problem with your permission or uploaded file.'); } if (!\rename($f['tmp_name'], $dest = $path . '/' . $result[$key]['filename'])) { diff --git a/Theme/Backend/media-list.tpl.php b/Theme/Backend/media-list.tpl.php index 6be0de3..e13b4a4 100755 --- a/Theme/Backend/media-list.tpl.php +++ b/Theme/Backend/media-list.tpl.php @@ -209,7 +209,7 @@ $next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id=' getTags(); foreach ($tags as $tag) : ?> - icon) ? '' : ''; ?> + icon) ? '' : ''; ?> printHtml($tag->getL11n()); ?> diff --git a/Theme/Backend/media-single.tpl.php b/Theme/Backend/media-single.tpl.php index 989a04c..f7f0aa7 100755 --- a/Theme/Backend/media-single.tpl.php +++ b/Theme/Backend/media-single.tpl.php @@ -97,7 +97,7 @@ echo $this->data['nav']->render(); ); ?> getHtml('Tags'); ?> - icon) ? '' : ''; ?>printHtml($tag->getL11n()); ?> + icon) ? '' : ''; ?>printHtml($tag->getL11n()); ?> getHtml('Description'); ?> description; ?> diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index b904f0c..44438e2 100755 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -381,7 +381,7 @@ function phpServe() : void // Execute the command and store the process ID $output = []; - echo \sprintf('Starting server...') . \PHP_EOL; + echo 'Starting server...' . \PHP_EOL; echo \sprintf(' Current directory: %s', \getcwd()) . \PHP_EOL; echo \sprintf(' %s', $command); \exec($command, $output); @@ -406,7 +406,7 @@ function phpServe() : void // Kill the web server when the process ends \register_shutdown_function(function() use ($killCommand, $pid) : void { - echo \PHP_EOL . \sprintf('Stopping server...') . \PHP_EOL; + echo \PHP_EOL . 'Stopping server...' . \PHP_EOL; echo \sprintf(' %s - Killing process with ID %d', \date('r'), $pid) . \PHP_EOL; \exec($killCommand . $pid); });