From: Alexander Ebert Date: Wed, 16 Jun 2021 12:00:24 +0000 (+0200) Subject: Strip the `loading` attribute from smileys for AMP output X-Git-Tag: 5.4.0_Beta_2~9 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4cfc175da480a13704dd6b52e49723c9a84cb62d;p=GitHub%2FWoltLab%2FWCF.git Strip the `loading` attribute from smileys for AMP output See #4290 --- 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); }