Added missing width/height attributes in amp version
authorMarcel Werk <burntime@woltlab.com>
Thu, 14 Dec 2017 10:12:20 +0000 (11:12 +0100)
committerMarcel Werk <burntime@woltlab.com>
Thu, 14 Dec 2017 10:12:20 +0000 (11:12 +0100)
com.woltlab.wcf/templates/mediaBBCodeTag.tpl
wcfsetup/install/files/lib/system/html/output/AmpHtmlOutputProcessor.class.php

index a988ab095cbdb1fc987e0136100b1a5698421c0d..e80ee2c1ed336c4cd524b29e88c840d40cb3294f 100644 (file)
@@ -1,10 +1,10 @@
 <span class="mediaBBCode{if $float != 'none'} messageFloatObject{$float|ucfirst}{/if}">
        {if $thumbnailSize != 'original'}
-               <a href="{$media->getLink()}" class="embeddedAttachmentLink jsImageViewer"><img src="{$media->getThumbnailLink($thumbnailSize)}" alt="{$media->altText}" title="{$media->title}"></a>
+               <a href="{$media->getLink()}" class="embeddedAttachmentLink jsImageViewer"><img src="{$media->getThumbnailLink($thumbnailSize)}" alt="{$media->altText}" title="{$media->title}" data-width="{@$media->getThumbnailWidth($thumbnailSize)}" data-height="{@$media->getThumbnailHeight($thumbnailSize)}"></a>
        {else}
-               <img src="{$media->getLink()}" alt="{$media->altText}" title="{$media->title}">
+               <img src="{$media->getLink()}" alt="{$media->altText}" title="{$media->title}" data-width="{@$media->width}" data-height="{@$media->height}">
        {/if}
-               
+       
        {if $media->caption}
                <span class="mediaBBCodeCaption">{$media->caption}</span>
        {/if}
index 7115f35ca1a70086616dadf28a46b635c89d8bde..b0a3205a891f4c6f9d62cca176b417b801a0edc9 100644 (file)
@@ -103,7 +103,12 @@ class AmpHtmlOutputProcessor extends HtmlOutputProcessor {
        public function getHtml() {
                $html = $this->getHtmlOutputNodeProcessor()->getHtml();
                
-               $html = str_ireplace('<img', '<amp-img layout="flex-item"', $html);
+               $html = preg_replace_callback('/<img([^>]+)>/i', function($match) {
+                       $attributes = str_replace('data-width="', 'width="', $match[1]);
+                       $attributes = str_replace('data-height="', 'height="', $attributes);
+                       return '<amp-img layout="flex-item"'.$attributes.'>';
+               }, $html);
+               
                $html = str_ireplace('<iframe', '<amp-iframe layout="responsive" width="480" height="300" sizes="(min-width: 480px) 480px, 100vw" ', $html);
                $html = str_ireplace('</iframe>', '<div class="wscIframePlaceholder" placeholder=""></div></amp-iframe>', $html);