From 4cfc175da480a13704dd6b52e49723c9a84cb62d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 16 Jun 2021 14:00:24 +0200 Subject: [PATCH] Strip the `loading` attribute from smileys for AMP output See #4290 --- wcfsetup/install/files/lib/data/smiley/Smiley.class.php | 7 +++++-- .../system/html/output/node/HtmlOutputNodeImg.class.php | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/data/smiley/Smiley.class.php b/wcfsetup/install/files/lib/data/smiley/Smiley.class.php index 20bc1a7726..4518cca9c7 100644 --- a/wcfsetup/install/files/lib/data/smiley/Smiley.class.php +++ b/wcfsetup/install/files/lib/data/smiley/Smiley.class.php @@ -128,9 +128,10 @@ class Smiley extends DatabaseObject implements ITitledObject * Returns the html code to render the smiley. * * @param string $class (additional) class(es) of the smiley element + * @param bool $isAmp * @return string */ - public function getHtml($class = '') + public function getHtml($class = '', $isAmp = false) { $srcset = ($this->smileyPath2x) ? ' srcset="' . StringUtil::encodeHTML($this->getURL2x()) . ' 2x"' : ''; $height = ($this->getHeight()) ? ' height="' . $this->getHeight() . '"' : ''; @@ -139,6 +140,8 @@ class Smiley extends DatabaseObject implements ITitledObject $class = ' ' . $class; } - return '' . StringUtil::encodeHTML($this->smileyCode) . ''; + $loading = ($isAmp) ? '' : ' loading="eager"'; + + return '' . StringUtil::encodeHTML($this->smileyCode) . ''; } } diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php index 72e1968c69..b209137180 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php @@ -36,6 +36,8 @@ class HtmlOutputNodeImg extends AbstractHtmlOutputNode */ public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) { + $isAmp = ($htmlNodeProcessor instanceof AmpHtmlOutputNodeProcessor); + /** @var \DOMElement $element */ foreach ($elements as $element) { $class = $element->getAttribute('class'); @@ -50,7 +52,7 @@ class HtmlOutputNodeImg extends AbstractHtmlOutputNode } else { // Ensure that the smiley's HTML is up to date. $doc = new \DOMDocument(); - $doc->loadHTML($smiley->getHtml()); + $doc->loadHTML($smiley->getHtml('', $isAmp)); $smileyNode = $element->ownerDocument->importNode($doc->getElementsByTagName('img')->item(0), true); $element->parentNode->replaceChild($smileyNode, $element); } -- 2.20.1