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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,18 @@ FAIL

<a style="color: red;" href="javascript:run();"> on line 1
- The attribute 'style' may not appear in tag 'a'.
[code: DISALLOWED_ATTR category: DISALLOWED_HTML]
[code: DISALLOWED_ATTR category: DISALLOWED_HTML see: https://www.ampproject.org/docs/reference/spec.html#links]
ACTION TAKEN: a.style attribute was removed due to validation issues.
- Invalid URL protocol 'javascript:' for attribute 'href' in tag 'a'.
[code: INVALID_URL_PROTOCOL category: DISALLOWED_HTML]
[code: INVALID_URL_PROTOCOL category: DISALLOWED_HTML see: https://www.ampproject.org/docs/reference/spec.html#links]
ACTION TAKEN: a.href attribute was removed due to validation issues.

<a style="margin: 2px;" href="http://www.cnn.com" target="_parent"> on line 2
- The attribute 'style' may not appear in tag 'a'.
[code: DISALLOWED_ATTR category: DISALLOWED_HTML]
[code: DISALLOWED_ATTR category: DISALLOWED_HTML see: https://www.ampproject.org/docs/reference/spec.html#links]
ACTION TAKEN: a.style attribute was removed due to validation issues.
- The attribute 'target' in tag 'a' is set to the invalid value '_parent'.
[code: INVALID_ATTR_VALUE category: DISALLOWED_HTML]
[code: INVALID_ATTR_VALUE category: DISALLOWED_HTML see: https://www.ampproject.org/docs/reference/spec.html#html-tags]
ACTION TAKEN: a.target attribute was removed due to validation issues.

<input type="submit" value="submit"> on line 5
Expand All @@ -182,7 +182,7 @@ FAIL

<div onmouseover="hello();"> on line 6
- The attribute 'onmouseover' may not appear in tag 'div'.
[code: DISALLOWED_ATTR category: DISALLOWED_HTML]
[code: DISALLOWED_ATTR category: DISALLOWED_HTML see: https://www.ampproject.org/docs/reference/spec.html#links]
ACTION TAKEN: div.onmouseover attribute was removed due to validation issues.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> on line 8
Expand Down
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
65 changes: 65 additions & 0 deletions src/Pass/IframeHuluTagTransformPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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);

if ($eid = $this->getArtifactId($el, '&(*UTF8)hulu\.com/embed\.html\?eid=(\w+)&i')) {
$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;
}
}
Loading