Allow center for media and attachment
authorCyperghost <olaf_schmitz_1@t-online.de>
Wed, 13 Dec 2023 12:04:25 +0000 (13:04 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Wed, 13 Dec 2023 12:04:25 +0000 (13:04 +0100)
com.woltlab.wcf/bbcode.xml
com.woltlab.wcf/templates/mediaBBCodeTag.tpl
wcfsetup/install/files/acp/templates/mediaBBCodeTag.tpl
wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php

index 5f84ea27a5f5273876e3c55f655bbc93015ab496..61ad2dd50295405e2b813c0db9f344d62b90cb75 100644 (file)
                                        <usetext>1</usetext>
                                </attribute>
                                <attribute name="1">
-                                       <validationpattern><![CDATA[^(left|right|none)$]]></validationpattern>
+                                       <validationpattern><![CDATA[^(left|right|center|none)$]]></validationpattern>
                                </attribute>
                                <attribute name="2">
                                        <validationpattern><![CDATA[^(\d+|true|false)$]]></validationpattern>
                                        <validationpattern><![CDATA[^(small|medium|large|original)$]]></validationpattern>
                                </attribute>
                                <attribute name="2">
-                                       <validationpattern><![CDATA[^(left|right|none)$]]></validationpattern>
+                                       <validationpattern><![CDATA[^(left|right|center|none)$]]></validationpattern>
                                </attribute>
                        </attributes>
                </bbcode>
index 848f068fe0b688560b44e8e32187a01527dc22ac..5bfe27894cc08a23b5307c7558eecb823daa3556 100644 (file)
@@ -1,4 +1,5 @@
 {if !$removeLinks|isset}{assign var='removeLinks' value=false}{/if}
+{if $float === 'center'}<p class="text-center">{/if}
 <span class="mediaBBCode{if $float != 'none'} messageFloatObject{$float|ucfirst}{/if}">
        {if $media->isImage}
                {if $thumbnailSize != 'original'}
@@ -33,3 +34,4 @@
                </span>
        {/if}
 </span>
+{if $float === 'center'}</p>{/if}
index 848f068fe0b688560b44e8e32187a01527dc22ac..5bfe27894cc08a23b5307c7558eecb823daa3556 100644 (file)
@@ -1,4 +1,5 @@
 {if !$removeLinks|isset}{assign var='removeLinks' value=false}{/if}
+{if $float === 'center'}<p class="text-center">{/if}
 <span class="mediaBBCode{if $float != 'none'} messageFloatObject{$float|ucfirst}{/if}">
        {if $media->isImage}
                {if $thumbnailSize != 'original'}
@@ -33,3 +34,4 @@
                </span>
        {/if}
 </span>
+{if $float === 'center'}</p>{/if}
index e4a22067bd0bb41d45f9683941af44adf2aa0eb7..8cad546ee60b1c6ec1813a3be7d0c39e79b208c7 100644 (file)
@@ -109,13 +109,21 @@ final class AttachmentBBCode extends AbstractBBCode
             );
         }
 
-        return \sprintf(
+        $span = \sprintf(
             '<span title="%s" class="%s" style="width: %s">%s</span>',
             $title,
             $class,
             $width,
             $imageElement,
         );
+
+        if ($alignment === 'center') {
+            return \sprintf(
+                '<p class="text-center">%s</p>',
+                $span,
+            );
+        }
+        return $span;
     }
 
     private function showImageAsThumbnail(Attachment $attachment, string $alignment, bool $hasParentLink, string $width): string
@@ -156,7 +164,7 @@ final class AttachmentBBCode extends AbstractBBCode
         );
 
         if (!$hasParentLink && $attachment->hasThumbnail() && $attachment->canDownload()) {
-            return \sprintf(
+            $result = \sprintf(
                 '<a href="%s" title="%s" class="embeddedAttachmentLink jsImageViewer %s" style="width: %s">%s%s</a>',
                 StringUtil::encodeHTML(LinkHandler::getInstance()->getLink('Attachment', ['object' => $attachment])),
                 StringUtil::encodeHTML($attachment->filename),
@@ -165,15 +173,23 @@ final class AttachmentBBCode extends AbstractBBCode
                 $imageElement,
                 $enlargeImageControls,
             );
+        } else {
+            $result = \sprintf(
+                '<span class="%s" stlye="width: %s">%s%s</span>',
+                $class,
+                $width,
+                $imageElement,
+                \str_contains($imageClasses, 'embeddedAttachmentLink') ? $enlargeImageControls : '',
+            );
+        }
+        if ($alignment === 'center') {
+            return \sprintf(
+                '<p class="text-center">%s</p>',
+                $result,
+            );
         }
 
-        return \sprintf(
-            '<span class="%s" stlye="width: %s">%s%s</span>',
-            $class,
-            $width,
-            $imageElement,
-            \str_contains($imageClasses, 'embeddedAttachmentLink') ? $enlargeImageControls : '',
-        );
+        return $result;
     }
 
     /**
index 707aefb8aba136b5cbb653c2fa4f8c9b8a2f4b4a..1ab4f929f977a2898b1f638a8ce1f8259fd120a5 100644 (file)
@@ -119,6 +119,8 @@ class HtmlInputNodeImg extends AbstractHtmlInputNode
         if ($parent->tagName === "figure") {
             if (\preg_match('~\b(?<float>image-style-side-left|image-style-side)\b~', $parent->getAttribute('class'), $matches)) {
                 $float = ($matches['float'] === 'image-style-side-left') ? 'left' : 'right';
+            } else {
+                $float = 'center';
             }
 
             $replaceElement = $parent;
@@ -179,6 +181,8 @@ class HtmlInputNodeImg extends AbstractHtmlInputNode
         if ($parent->tagName === "figure") {
             if (\preg_match('~\b(?<float>image-style-side-left|image-style-side)\b~', $parent->getAttribute('class'), $matches)) {
                 $float = ($matches['float'] === 'image-style-side-left') ? 'left' : 'right';
+            } else {
+                $float = 'center';
             }
 
             $replaceElement = $parent;