From: Alexander Ebert Date: Fri, 14 Jul 2023 16:29:19 +0000 (+0200) Subject: Simplify the handling of the alignment CSS classes X-Git-Tag: 6.0.0_Alpha_6~6^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2f69f0f5169116ea673ca0d6b36af6db69b35244;p=GitHub%2FWoltLab%2FWCF.git Simplify the handling of the alignment CSS classes --- diff --git a/wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php b/wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php index ea111666d8..be5eb8250d 100644 --- a/wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php @@ -35,7 +35,18 @@ final class AttachmentBBCode extends AbstractBBCode $outputType = $parser->getOutputType(); if ($attachment->showAsImage() && $attachment->canViewPreview() && ($outputType == 'text/html' || $outputType == 'text/simplified-html')) { - return $this->showImage($attachment, $outputType, $openingTag['attributes']); + $hasParentLink = false; + if (!empty($closingTag['__parents'])) { + /** @var \DOMElement $parent */ + foreach ($closingTag['__parents'] as $parent) { + if ($parent->nodeName === 'a') { + $hasParentLink = true; + break; + } + } + } + + return $this->showImage($attachment, $outputType, $openingTag['attributes'], $hasParentLink); } elseif (\substr($attachment->fileType, 0, 6) === 'video/' && $outputType == 'text/html') { return $this->showVideoPlayer($attachment); } elseif (\substr($attachment->fileType, 0, 6) === 'audio/' && $outputType == 'text/html') { @@ -45,28 +56,17 @@ final class AttachmentBBCode extends AbstractBBCode return StringUtil::getAnchorTag($attachment->getLink(), $attachment->filename); } - private function showImage(Attachment $attachment, string $outputType, array $attributes): string + private function showImage(Attachment $attachment, string $outputType, array $attributes, bool $hasParentLink): string { $alignment = $attributes[1] ?? ''; - $thumbnail = $this->renderImageAsThumbnail($attachment, $outputType, $attributes[2] ?? false); - $hasParentLink = false; - if (!empty($closingTag['__parents'])) { - /** @var \DOMElement $parent */ - foreach ($closingTag['__parents'] as $parent) { - if ($parent->nodeName === 'a') { - $hasParentLink = true; - break; - } - } - } - if ($thumbnail === false) { - $class = ''; - if ($alignment === 'left' || $alignment === 'right') { - $class = 'messageFloatObject' . \ucfirst($alignment); - } + $class = match ($alignment) { + "left" => "messageFloatObjectLeft", + "right" => "messageFloatObjectRight", + default => "" + }; $source = StringUtil::encodeHTML($attachment->getLink()); $title = StringUtil::encodeHTML($attachment->filename); @@ -115,10 +115,11 @@ final class AttachmentBBCode extends AbstractBBCode $linkParameters['thumbnail'] = 1; } - $class = ''; - if ($alignment == 'left' || $alignment == 'right') { - $class = 'messageFloatObject' . \ucfirst($alignment); - } + $class = match ($alignment) { + "left" => "messageFloatObjectLeft", + "right" => "messageFloatObjectRight", + default => "" + }; $imageClasses = ''; if (!$attachment->hasThumbnail()) {