Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ampproject/amp-wp into add/archi…
Browse files Browse the repository at this point in the history
…ve-collection-schema-type

* 'develop' of github.com:ampproject/amp-wp:
  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)
  Suppress Site Health ICU test if site or home URL is not an IDN (#4698)
  Pin amp-experiment to v0.1 (#4690)
  Strip multiple BOM characters (#4683)
  Strip leading BOM and whitespace and trailing HTML comment before parsing validation response JSON (#4679)
  Disable share icons
  Use amp-embedly-card for Tiktok embeds
  Update dependency xwp/wp-dev-lib to v1.6.4
  Update dependency eslint to v7
  Update dependency terser-webpack-plugin to v2.3.6
  • Loading branch information
westonruter committed May 15, 2020
2 parents d70c20d + 83d7964 commit 7743016
Show file tree
Hide file tree
Showing 16 changed files with 1,052 additions and 241 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"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",
"xwp/wp-dev-lib": "1.6.3"
"wp-coding-standards/wpcs": "2.3.0",
"xwp/wp-dev-lib": "1.6.4"
},
"suggest": {
"ext-intl": "Enables use of idn_to_utf8() to convert punycode domains to UTF-8 for use with an AMP Cache.",
Expand Down
106 changes: 81 additions & 25 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
11 changes: 11 additions & 0 deletions includes/validation/class-amp-validation-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,17 @@ public static function validate_url( $url ) {
$validation_url
);

// Strip byte order mark (BOM).
while ( "\xEF\xBB\xBF" === substr( $response, 0, 3 ) ) {
$response = substr( $response, 3 );
}

// Strip any leading whitespace.
$response = ltrim( $response );

// Strip HTML comments that may have been injected at the end of the response (e.g. by a caching plugin).
$response = preg_replace( '/<!--.*?-->\s*$/s', '', $response );

if ( '' === $response ) {
return new WP_Error( 'white_screen_of_death' );
}
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
Loading

0 comments on commit 7743016

Please sign in to comment.