Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ampproject/amp-wp into 4380-bump…
Browse files Browse the repository at this point in the history
…-phpstan-to-level-4

* 'develop' of github.com:ampproject/amp-wp:
  Update dependency @wordpress/scripts to v9.1.0
  Update dependency @wordpress/jest-puppeteer-axe to v1.8.0
  Update dependency @wordpress/url to v2.15.0
  Update dependency @wordpress/plugins to v2.16.0
  Raise PHPStan level to 4 in lib/common (#4686)
  Update dependency uuid to v8
  Update dependency webpack to v4.43.0
  Update dependency eslint-plugin-jest to v23.11.0
  Update dependency eslint-plugin-react to v7.20.0 (#4691)
  Update dependency postcss to v7.0.30 (#4649)
  Update dependency moment to v2.25.3 (#4639)
  Update dependency babel-jest to v26 (#4652)
  Update dependency uuid to v7.0.3 (#4490)
  Update dependency wp-coding-standards/wpcs to v2.3.0 (#4721)
  Update dependency @wordpress/e2e-test-utils to v4.7.0
  Suppress Site Health ICU test if site or home URL is not an IDN (#4698)
  Pin amp-experiment to v0.1 (#4690)
  Disable share icons
  Use amp-embedly-card for Tiktok embeds
  Update dependency terser-webpack-plugin to v2.3.6
  • Loading branch information
westonruter committed May 15, 2020
2 parents 7ca8824 + a400d38 commit f0ec0ff
Show file tree
Hide file tree
Showing 14 changed files with 779 additions and 243 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"phpcompatibility/phpcompatibility-wp": "2.1.0",
"roave/security-advisories": "dev-master",
"sirbrillig/phpcs-variable-analysis": "2.8.1",
"wp-coding-standards/wpcs": "2.2.1",
"wp-coding-standards/wpcs": "2.3.0",
"xwp/wp-dev-lib": "1.6.4"
},
"suggest": {
Expand Down
26 changes: 14 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions includes/amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,14 @@ function amp_register_default_scripts( $wp_scripts ) {
null
);
}

if ( $wp_scripts->query( 'amp-experiment', 'registered' ) ) {
/*
* Version 1.0 of amp-experiment is still experimental and requires the user to enable it.
* @todo Revisit once amp-experiment is no longer experimental.
*/
$wp_scripts->registered['amp-experiment']->src = 'https://cdn.ampproject.org/v0/amp-experiment-0.1.js';
}
}

/**
Expand Down
42 changes: 16 additions & 26 deletions includes/embeds/class-amp-tiktok-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function sanitize_raw_embeds( Document $dom ) {
* @return bool Whether the node is a raw embed.
*/
protected function is_raw_embed( DOMElement $node ) {
return ! $node->firstChild || ( $node->firstChild && 'amp-iframe' !== $node->firstChild->nodeName );
return ! $node->firstChild || ( $node->firstChild && 'amp-embedly-card' !== $node->firstChild->nodeName );
}

/**
Expand All @@ -59,34 +59,25 @@ protected function is_raw_embed( DOMElement $node ) {
* @param DOMElement $blockquote_node The <blockquote> node to make AMP compatible.
*/
protected function make_embed_amp_compatible( DOMElement $blockquote_node ) {
$dom = $blockquote_node->ownerDocument;
$video_id = $blockquote_node->getAttribute( 'data-video-id' );
$dom = $blockquote_node->ownerDocument;
$video_url = $blockquote_node->getAttribute( 'cite' );

// If there is no video ID, stop here as its needed for the iframe `src` attribute.
if ( empty( $video_id ) ) {
// If there is no video ID, stop here as its needed for the `data-url` parameter.
if ( empty( $video_url ) ) {
return;
}

$this->remove_embed_script( $blockquote_node );

$amp_iframe_node = AMP_DOM_Utils::create_node(
$amp_node = AMP_DOM_Utils::create_node(
Document::fromNode( $dom ),
'amp-iframe',
'amp-embedly-card',
[
'layout' => 'fixed-height',

/*
* The iframe dimensions cannot be derived from the embed, so we default to a dimension that should
* allow the embed to be fully shown.
*/
'height' => 900,

/*
* A `lang` query parameter is added to the URL via JS. This can't be determined here so it is not
* added. Whether it alters the embed in any way or not has not been determined.
*/
'src' => 'https://www.tiktok.com/embed/v2/' . $video_id,
'sandbox' => 'allow-scripts allow-same-origin allow-popups',
'layout' => 'responsive',
'height' => 700,
'width' => 340,
'data-card-controls' => 0,
'data-url' => $video_url,
]
);

Expand All @@ -99,23 +90,22 @@ protected function make_embed_amp_compatible( DOMElement $blockquote_node ) {
// Append the placeholder if it was found.
if ( 'section' === $child->nodeName ) {
/**
* Placeholder to append to the iframe.
* Placeholder to append to the AMP component.
*
* @var DOMElement $placeholder_node
*/
$placeholder_node = $blockquote_node->removeChild( $child );
$placeholder_node->setAttribute( 'placeholder', '' );
$amp_iframe_node->appendChild( $placeholder_node );
$amp_node->appendChild( $placeholder_node );
break;
}
}

// On the non-amp page the embed is wrapped with a <blockquote>, so the same is done here.
$blockquote_node->appendChild( $amp_iframe_node );
$blockquote_node->parentNode->replaceChild( $amp_node, $blockquote_node );
}

/**
* Remove TikTok's embed script if it exists.
* Remove the TikTok embed script if it exists.
*
* @param DOMElement $node The DOMNode to make AMP compatible.
*/
Expand Down
6 changes: 5 additions & 1 deletion lib/common/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ includes:
# @see https://github.com/phpstan/phpstan-src/blob/master/conf/bleedingEdge.neon
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
level: 3
level: 4
inferPrivatePropertyTypeFromConstructor: true
paths:
- %currentWorkingDirectory%/src/
autoload_files:
- %currentWorkingDirectory%/vendor/autoload.php
ignoreErrors:
- '#^PHPDoc tag @throws with type AmpProject\\Exception\\FailedRemoteRequest is not subtype of Throwable$#'
-
message: '#^If condition is always false\.$#'
path: 'src/Dom/Document.php'
# See https://github.com/phpstan/phpstan/issues/3291
38 changes: 19 additions & 19 deletions lib/common/src/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -847,26 +847,26 @@ private function restoreSelfClosingTags($html)
*/
private function maybeReplaceNoscriptElements($html)
{
if (! version_compare(LIBXML_DOTTED_VERSION, '2.8', '<')) {
return $html;
if (version_compare(LIBXML_DOTTED_VERSION, '2.8', '<')) {
$html = preg_replace_callback(
'#^.+?(?=<body)#is',
function ($headMatches) {
return preg_replace_callback(
'#<noscript[^>]*>.*?</noscript>#si',
function ($noscriptMatches) {
$placeholder = sprintf('<!--noscript:%s-->', (string)$this->rand());

$this->noscriptPlaceholderComments[$placeholder] = $noscriptMatches[0];
return $placeholder;
},
$headMatches[0]
);
},
$html
);
}

return preg_replace_callback(
'#^.+?(?=<body)#is',
function ($headMatches) {
return preg_replace_callback(
'#<noscript[^>]*>.*?</noscript>#si',
function ($noscriptMatches) {
$placeholder = sprintf('<!--noscript:%s-->', (string)$this->rand());

$this->noscriptPlaceholderComments[$placeholder] = $noscriptMatches[0];
return $placeholder;
},
$headMatches[0]
);
},
$html
);
return $html;
}

/**
Expand Down Expand Up @@ -1420,7 +1420,7 @@ public function deduplicateTag($tagName)
/**
* Main tag to keep.
*
* @var DOMElement $mainTag
* @var DOMElement|null $mainTag
*/
$mainTag = $tags->item(0);

Expand Down
2 changes: 1 addition & 1 deletion lib/common/src/Exception/FailedToGetFromRemoteUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class FailedToGetFromRemoteUrl extends RuntimeException implements FailedR
*
* This is not always set.
*
* @var int
* @var int|null
*/
private $statusCode;

Expand Down
2 changes: 1 addition & 1 deletion lib/common/src/RuntimeVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function currentVersion($options = [])
$response = $this->remoteRequest->get(self::RUNTIME_METADATA_ENDPOINT);
$statusCode = $response->getStatusCode();

if (200 < $statusCode || $statusCode >= 300) {
if ($statusCode < 200 || $statusCode >= 300) {
return '0';
}

Expand Down
Loading

0 comments on commit f0ec0ff

Please sign in to comment.