rector fixes

This commit is contained in:
Dennis Eichhorn 2023-09-24 14:56:44 +00:00
parent fb15795ef0
commit 4b6f7bf4ff
7 changed files with 40 additions and 56 deletions

View File

@ -208,7 +208,7 @@ final class Installer extends InstallerAbstract
/** @var \Modules\Media\Controller\ApiController $module */ /** @var \Modules\Media\Controller\ApiController $module */
$module = $app->moduleManager->getModuleInstance('Media'); $module = $app->moduleManager->getModuleInstance('Media');
$path = !isset($data['path']) ? ($data['virtualPath'] ?? '') : $data['path']; $path = isset($data['path']) ? ($data['path']) : $data['virtualPath'] ?? '';
$response = new HttpResponse(); $response = new HttpResponse();
$request = new HttpRequest(new HttpUri('')); $request = new HttpRequest(new HttpUri(''));
@ -285,9 +285,9 @@ final class Installer extends InstallerAbstract
$module->apiMediaTypeL11nCreate($request, $response); $module->apiMediaTypeL11nCreate($request, $response);
} }
return !\is_array($type) return \is_array($type)
? $type->toArray() ? $type
: $type; : $type->toArray();
} }
/** /**

View File

@ -819,14 +819,10 @@ final class ApiController extends Controller
} }
$virtualPath = \urldecode($request->getDataString('virtualpath') ?? '/'); $virtualPath = \urldecode($request->getDataString('virtualpath') ?? '/');
$basePath = __DIR__ . '/../../../Modules/Media/Files';
$outputDir = ''; $outputDir = $request->hasData('path')
$basePath = __DIR__ . '/../../../Modules/Media/Files'; ? $basePath . '/' . \ltrim($request->getDataString('path') ?? '', '\\/')
if (!$request->hasData('path')) { : self::createMediaPath($basePath);
$outputDir = self::createMediaPath($basePath);
} else {
$outputDir = $basePath . '/' . \ltrim($request->getDataString('path') ?? '', '\\/');
}
$dirPath = $outputDir . '/' . ($request->getDataString('name') ?? ''); $dirPath = $outputDir . '/' . ($request->getDataString('name') ?? '');
$outputDir = \substr($outputDir, \strlen(__DIR__ . '/../../..')); $outputDir = \substr($outputDir, \strlen(__DIR__ . '/../../..'));
@ -896,7 +892,7 @@ final class ApiController extends Controller
{ {
$status = false; $status = false;
if (!empty($physicalPath)) { if (!empty($physicalPath)) {
$status = !\is_dir($physicalPath) ? \mkdir($physicalPath, 0755, true) : true; $status = \is_dir($physicalPath) ? true : \mkdir($physicalPath, 0755, true);
} }
$path = \trim($path, '/'); $path = \trim($path, '/');
@ -972,16 +968,13 @@ final class ApiController extends Controller
$basePath = __DIR__ . '/../../../Modules/Media/Files'; $basePath = __DIR__ . '/../../../Modules/Media/Files';
if (!$request->hasData('path')) { if (!$request->hasData('path')) {
$outputDir = self::createMediaPath($basePath); $outputDir = self::createMediaPath($basePath);
} elseif (\stripos(
FileUtils::absolute($basePath . '/' . \ltrim($path, '\\/')),
FileUtils::absolute(__DIR__ . '/../../../')
) !== 0) {
$outputDir = self::createMediaPath($basePath);
} else { } else {
if (\stripos( $outputDir = $basePath . '/' . \ltrim($path, '\\/');
FileUtils::absolute($basePath . '/' . \ltrim($path, '\\/')),
FileUtils::absolute(__DIR__ . '/../../../')
) !== 0
) {
$outputDir = self::createMediaPath($basePath);
} else {
$outputDir = $basePath . '/' . \ltrim($path, '\\/');
}
} }
if (!\is_dir($outputDir)) { if (!\is_dir($outputDir)) {
@ -1079,7 +1072,6 @@ final class ApiController extends Controller
return; return;
} }
if (!isset($data, $data['guard'])) { if (!isset($data, $data['guard'])) {
if (!isset($data)) { if (!isset($data)) {
$data = []; $data = [];
@ -1087,11 +1079,9 @@ final class ApiController extends Controller
$data['guard'] = __DIR__ . '/../Files'; $data['guard'] = __DIR__ . '/../Files';
} }
} else { } elseif (empty($data) || !isset($data['guard'])) {
if (empty($data) || !isset($data['guard'])) { $response->header->status = RequestStatusCode::R_403;
$response->header->status = RequestStatusCode::R_403; $this->createInvalidReturnResponse($request, $response, $media);
$this->createInvalidReturnResponse($request, $response, $media);
}
} }
if (!Guard::isSafePath($filePath, $data['guard'] ?? '')) { if (!Guard::isSafePath($filePath, $data['guard'] ?? '')) {

View File

@ -243,28 +243,24 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/Media/Theme/Backend/media-list'); $view->setTemplate('/Modules/Media/Theme/Backend/media-list');
} else { } else {
$sub = $request->getDataString('sub') ?? ''; $sub = $request->getDataString('sub') ?? '';
if (\is_dir($media->getPath()) if (\is_dir($media->getPath() . $sub)) {
&& (\is_dir($media->getPath() . $sub))
) {
$listView = new ListView($this->app->l11nManager, $request, $response); $listView = new ListView($this->app->l11nManager, $request, $response);
$listView->setTemplate('/modules/Media/Theme/Backend/Components/Media/list'); $listView->setTemplate('/modules/Media/Theme/Backend/Components/Media/list');
$view->data['view'] = $listView; $view->data['view'] = $listView;
} else { } elseif ($media->class === MediaClass::REFERENCE) {
if ($media->class === MediaClass::REFERENCE) { /** @var \Modules\Media\Models\Media $media */
/** @var \Modules\Media\Models\Media $media */ $media->source = MediaMapper::get()
$media->source = MediaMapper::get() ->with('createdBy')
->with('createdBy') ->with('tags')
->with('tags') ->with('tags/title')
->with('tags/title') ->with('content')
->with('content') ->where('id', $media->source?->id ?? 0)
->where('id', $media->source?->id ?? 0) ->where('tags/title/language', $request->header->l11n->language)
->where('tags/title/language', $request->header->l11n->language) ->execute();
->execute();
$view->data['view'] = $this->createMediaView($media->source, $request, $response); $view->data['view'] = $this->createMediaView($media->source, $request, $response);
} else { } else {
$view->data['view'] = $this->createMediaView($media, $request, $response); $view->data['view'] = $this->createMediaView($media, $request, $response);
}
} }
} }
} }

View File

@ -165,14 +165,14 @@ class UploadFile
return $result; 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; $result[$key]['status'] = UploadStatus::WRONG_EXTENSION;
return $result; return $result;
} }
$split = \explode('.', $f['name']); $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] : ''; $result[$key]['extension'] = ($c = \count($split)) > 1 ? $split[$c - 1] : '';
if (!$this->preserveFileName || \is_file($path . '/' . $result[$key]['filename'])) { if (!$this->preserveFileName || \is_file($path . '/' . $result[$key]['filename'])) {
@ -190,10 +190,8 @@ class UploadFile
} }
} }
if (!\is_dir($path)) { if (!\is_dir($path) && !Directory::create($path, 0755, true)) {
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.');
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'])) { if (!\rename($f['tmp_name'], $dest = $path . '/' . $result[$key]['filename'])) {

View File

@ -209,7 +209,7 @@ $next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&id='
<td data-label="<?= $this->getHtml('Tag'); ?>"><?php $tags = $value->getTags(); foreach ($tags as $tag) : ?> <td data-label="<?= $this->getHtml('Tag'); ?>"><?php $tags = $value->getTags(); foreach ($tags as $tag) : ?>
<a href="<?= $url; ?>"> <a href="<?= $url; ?>">
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"> <span class="tag" style="background: <?= $this->printHtml($tag->color); ?>">
<?= !empty($tag->icon) ? '<i class="' . $this->printHtml($tag->icon) . '"></i>' : ''; ?> <?= empty($tag->icon) ? '' : '<i class="' . $this->printHtml($tag->icon) . '"></i>'; ?>
<?= $this->printHtml($tag->getL11n()); ?> <?= $this->printHtml($tag->getL11n()); ?>
</span> </span>
</a> </a>

View File

@ -97,7 +97,7 @@ echo $this->data['nav']->render();
); ?></a> ); ?></a>
<tr><td><?= $this->getHtml('Tags'); ?><td> <tr><td><?= $this->getHtml('Tags'); ?><td>
<?php foreach ($tags as $tag) : ?> <?php foreach ($tags as $tag) : ?>
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= !empty($tag->icon) ? '<i class="' . $this->printHtml($tag->icon) . '"></i>' : ''; ?><?= $this->printHtml($tag->getL11n()); ?></span> <span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= empty($tag->icon) ? '' : '<i class="' . $this->printHtml($tag->icon) . '"></i>'; ?><?= $this->printHtml($tag->getL11n()); ?></span>
<?php endforeach; ?> <?php endforeach; ?>
<tr><td colspan="2"><?= $this->getHtml('Description'); ?> <tr><td colspan="2"><?= $this->getHtml('Description'); ?>
<tr><td colspan="2"><?= $media->description; ?> <tr><td colspan="2"><?= $media->description; ?>

View File

@ -381,7 +381,7 @@ function phpServe() : void
// Execute the command and store the process ID // Execute the command and store the process ID
$output = []; $output = [];
echo \sprintf('Starting server...') . \PHP_EOL; echo 'Starting server...' . \PHP_EOL;
echo \sprintf(' Current directory: %s', \getcwd()) . \PHP_EOL; echo \sprintf(' Current directory: %s', \getcwd()) . \PHP_EOL;
echo \sprintf(' %s', $command); echo \sprintf(' %s', $command);
\exec($command, $output); \exec($command, $output);
@ -406,7 +406,7 @@ function phpServe() : void
// Kill the web server when the process ends // Kill the web server when the process ends
\register_shutdown_function(function() use ($killCommand, $pid) : void { \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; echo \sprintf(' %s - Killing process with ID %d', \date('r'), $pid) . \PHP_EOL;
\exec($killCommand . $pid); \exec($killCommand . $pid);
}); });