Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to integrate the amp-hulu tag #162

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions src/AMP.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class AMP
'Lullabot\AMP\Pass\IframeVineTagTransformPass',
'Lullabot\AMP\Pass\IframeDailymotionTagTransformPass',
'Lullabot\AMP\Pass\IframeYouTubeTagTransformPass',
'Lullabot\AMP\Pass\IframeHuluTagTransformPass',
'Lullabot\AMP\Pass\IframeTagTransformPass',
'Lullabot\AMP\Pass\InstagramTransformPass',
'Lullabot\AMP\Pass\PinterestTagTransformPass',
Expand Down
69 changes: 69 additions & 0 deletions src/Pass/IframeHuluTagTransformPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/*
* Copyright 2016 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


namespace Lullabot\AMP\Pass;

use QueryPath\DOMQuery;

use Lullabot\AMP\Utility\ActionTakenLine;
use Lullabot\AMP\Utility\ActionTakenType;

/**
* Class IframeHuluTagTransformPass
* @package Lullabot\AMP\Pass
*
* Sample hulu embed code:
* <iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="//www.hulu.com/embed.html?eid=_hHzwnAcj3RrXMJFDDvkuw"></iframe>
*
* @see https://www.ampproject.org/docs/reference/extended/amp-hulu.html
* @see https://ampbyexample.com/components/amp-hulu/
*/
class IframeHuluTagTransformPass extends BasePass
{
function pass()
{
$all_iframes = $this->q->find('iframe:not(noscript iframe)');
/** @var DOMQuery $el */
foreach ($all_iframes as $el) {
/** @var \DOMElement $dom_el */
$dom_el = $el->get(0);
$lineno = $this->getLineNo($dom_el);
$query = $this->getQueryArray($el);
// If we can't get the videoid, abort
if (empty($query['eid'])) {
continue;
}
$eid = $query['eid'];
$width = $el->attr('width') ?: 800;
$height = $el->attr('height') ?: 600;

$context_string = $this->getContextString($dom_el);

// width and height are intended to be aspect ratios here
$el->after('<amp-hulu width="' . $width . '" height="' . $height . '" layout="responsive" data-eid="' . $eid . '"></amp-hulu>');
$new_dom_el = $el->next()->get(0);

$el->removeChildren()->remove();
$this->addActionTaken(new ActionTakenLine('iframe', ActionTakenType::HULU_CONVERTED, $lineno, $context_string));

$this->context->addLineAssociation($new_dom_el, $lineno);
}

return $this->transformations;
}
}
1 change: 1 addition & 0 deletions src/Utility/ActionTakenType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ActionTakenType
const FACEBOOK_JSDK_CONVERTED = 'facebook javascript sdk embed code was converted to the amp-facebook tag.';
const FACEBOOK_SCRIPT_REMOVED = 'facebook script tag was removed.';
const VIMEO_CONVERTED = 'vimeo embed code was converted to the amp-vimeo tag.';
const HULU_CONVERTED = 'hulu embed code was converted to the amp-hulu tag.';
const DAILYMOTION_CONVERTED = 'dailymotion embed code was converted to the amp-dailymotion tag.';
const TWITTER_CONVERTED = 'twitter embed code was converted to the amp-twitter tag.';
const IFRAME_CONVERTED = 'tag was converted to the amp-iframe tag.';
Expand Down
1 change: 1 addition & 0 deletions tests/test-data/fragment-html/hulu-fragment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="//www.hulu.com/embed.html?eid=_hHzwnAcj3RrXMJFDDvkuw"></iframe>
25 changes: 25 additions & 0 deletions tests/test-data/fragment-html/hulu-fragment.html.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<amp-vine layout="responsive" data-vineid="ixtpg1zrLQt" height="600" width="600"></amp-vine>



ORIGINAL HTML
---------------
Line 1: <iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="//www.hulu.com/embed.html?eid=_hHzwnAcj3RrXMJFDDvkuw"></iframe>
Line 2:


Transformations made from HTML tags to AMP custom tags
-------------------------------------------------------

<amp-hulu width="854" height="480" layout="responsive" data-eid="_hHzwnAcj3RrXMJFDDvkuw"></amp-hulu> at line 1
ACTION TAKEN: iframe (with associated script tag) hulu embed code was converted to the amp-hulu tag.


AMP-HTML Validation Issues and Fixes
-------------------------------------
PASS

COMPONENT NAMES WITH JS PATH
------------------------------
'amp-vine', include path 'https://cdn.ampproject.org/v0/amp-vine-0.1.js'