--- /dev/null
+{* Simplified spoiler for Google AMP pages that outputs its content directly. *}
+
+<!-- META_CODE_INNER_CONTENT -->
*/
public static $codeTagNames = ['kbd', 'pre'];
+ /**
+ * Google AMP support
+ * @var boolean
+ */
+ protected $isGoogleAmp = false;
+
/**
* list of open tags with name and uuid
* @var array
return $this->parsedText;
}
+ /**
+ * Enables or disables Google AMP support.
+ *
+ * @param boolean $isGoogleAmp
+ * @since 3.1
+ */
+ public function setIsGoogleAmp($isGoogleAmp) {
+ $this->isGoogleAmp = $isGoogleAmp;
+ }
+
+ /**
+ * Returns true if Google AMP support is enabled.
+ *
+ * @return boolean
+ * @since 3.1
+ */
+ public function getIsGoogleAmp() {
+ return $this->isGoogleAmp;
+ }
+
/**
* Reverts tags to their source representation if they either
* have no matching counter part (such as opening tags without
<?php
namespace wcf\system\html\output;
+use wcf\system\bbcode\HtmlBBCodeParser;
use wcf\util\DOMUtil;
/**
* @inheritDoc
*/
public function getHtml() {
+ // temporarily enable AMP output mode for bbcodes
+ HtmlBBCodeParser::getInstance()->setIsGoogleAmp(true);
+
$html = $this->getHtmlOutputNodeProcessor()->getHtml();
+ // disable AMP output again in order to prevent interference with other
+ // content types that may be processed in the same request
+ HtmlBBCodeParser::getInstance()->setIsGoogleAmp(false);
+
$html = preg_replace_callback('/<img([^>]+)>/i', function($match) {
$attributes = str_replace('data-width="', 'width="', $match[1]);
$attributes = str_replace('data-height="', 'height="', $attributes);
<?php
namespace wcf\system\html\output\node;
+use wcf\system\bbcode\HtmlBBCodeParser;
use wcf\system\html\node\AbstractHtmlNodeProcessor;
use wcf\system\WCF;
use wcf\util\StringUtil;
WCF::getTPL()->assign([
'buttonLabel' => $data['label']
]);
- return WCF::getTPL()->fetch('spoilerMetaCode');
+ return WCF::getTPL()->fetch((HtmlBBCodeParser::getInstance()->getIsGoogleAmp() ? 'spoilerAmpMetaCode' : 'spoilerMetaCode'));
}
}