Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/4616-hide-icu-site-health-test
Browse files Browse the repository at this point in the history
  • Loading branch information
pierlon committed May 13, 2020
2 parents 3422885 + cc6cc71 commit d6f0123
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
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
4 changes: 2 additions & 2 deletions tests/php/test-class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -1982,11 +1982,11 @@ static function ( $url ) {
'<link rel="dns-prefetch" href="//cdn.ampproject.org">',
'<link rel="preload" as="script" href="https://cdn.ampproject.org/v0.js">',
'<link rel="preload" as="script" href="https://cdn.ampproject.org/v0/amp-dynamic-css-classes-0.1.js">',
'<link rel="preload" as="script" href="https://cdn.ampproject.org/v0/amp-experiment-1.0.js">',
'<link rel="preload" as="script" href="https://cdn.ampproject.org/v0/amp-experiment-0.1.js">',
'<script type="text/javascript" src="https://cdn.ampproject.org/v0.js" async></script>',

'<script async custom-element="amp-dynamic-css-classes" src="https://cdn.ampproject.org/v0/amp-dynamic-css-classes-0.1.js"></script>',
'<script src="https://cdn.ampproject.org/v0/amp-experiment-1.0.js" async="" custom-element="amp-experiment"></script>',
'<script src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js" async="" custom-element="amp-experiment"></script>',

'#<script( type=[\'"]text/javascript[\'"])? src=[\'"]https\://cdn\.ampproject\.org/v0/amp-ad-0\.1\.js[\'"] async(=[\'"][\'"])? custom-element=[\'"]amp-ad[\'"]>\s*</script>#s',
'#<script src=[\'"]https\://cdn\.ampproject\.org/v0/amp-audio-0\.1\.js[\'"] async(=[\'"][\'"])? custom-element=[\'"]amp-audio[\'"]>\s*</script>#s',
Expand Down
5 changes: 2 additions & 3 deletions tests/php/test-class-amp-tiktok-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ public function get_conversion_data() {
'url_simple' => [
'https://www.tiktok.com/@scout2015/video/6718335390845095173' . PHP_EOL,

'<blockquote class="tiktok-embed" cite="https://www.tiktok.com/@scout2015/video/6718335390845095173" data-video-id="6718335390845095173" style="max-width: 605px;min-width: 325px;">' . PHP_EOL . PHP_EOL .
'<amp-iframe layout="fixed-height" height="900" src="https://www.tiktok.com/embed/v2/6718335390845095173" sandbox="allow-scripts allow-same-origin allow-popups"><section placeholder=""> <a target="_blank" title="@scout2015" href="https://www.tiktok.com/@scout2015">@scout2015</a> ' . PHP_EOL .
'<amp-embedly-card layout="responsive" height="700" width="340" data-card-controls="0" data-url="https://www.tiktok.com/@scout2015/video/6718335390845095173"><section placeholder=""> <a target="_blank" title="@scout2015" href="https://www.tiktok.com/@scout2015">@scout2015</a> ' . PHP_EOL .
'<p>Scramble up ur name &amp; I’ll try to guess it😍❤️ <a title="foryoupage" target="_blank" href="https://www.tiktok.com/tag/foryoupage">#foryoupage</a> <a title="petsoftiktok" target="_blank" href="https://www.tiktok.com/tag/petsoftiktok">#petsoftiktok</a> <a title="aesthetic" target="_blank" href="https://www.tiktok.com/tag/aesthetic">#aesthetic</a></p>' . PHP_EOL .
'<p> <a target="_blank" title="♬ original sound - 𝐇𝐚𝐰𝐚𝐢𝐢𓆉" href="https://www.tiktok.com/music/original-sound-6689804660171082501">♬ original sound – 𝐇𝐚𝐰𝐚𝐢𝐢𓆉</a> </p></section></amp-iframe></blockquote>' . PHP_EOL . PHP_EOL,
'<p> <a target="_blank" title="♬ original sound - 𝐇𝐚𝐰𝐚𝐢𝐢𓆉" href="https://www.tiktok.com/music/original-sound-6689804660171082501">♬ original sound – 𝐇𝐚𝐰𝐚𝐢𝐢𓆉</a> </p></section></amp-embedly-card>' . PHP_EOL . PHP_EOL,
],
];
}
Expand Down

0 comments on commit d6f0123

Please sign in to comment.