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 */
$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();
}
/**

View File

@ -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'] ?? '')) {

View File

@ -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);
}
}
}

View File

@ -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'])) {

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) : ?>
<a href="<?= $url; ?>">
<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()); ?>
</span>
</a>

View File

@ -97,7 +97,7 @@ echo $this->data['nav']->render();
); ?></a>
<tr><td><?= $this->getHtml('Tags'); ?><td>
<?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; ?>
<tr><td colspan="2"><?= $this->getHtml('Description'); ?>
<tr><td colspan="2"><?= $media->description; ?>

View File

@ -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);
});