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

Adding sanitizer to support amp-o2-player #1202

Merged
merged 7 commits into from Jun 20, 2018
Merged

Adding sanitizer to support amp-o2-player #1202

merged 7 commits into from Jun 20, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jun 6, 2018

Adding support for amp-o2-player

e.g: If we have the following markup

<div id="579a115aa01b4d2db062aa85" class="vdb_player vdb_579a115aa01b4d2db062aa85545db032e4b0af1a81424b48">
        <script type="text/javascript" src="http://delivery.vidible.tv/jsonp/pid=579a115aa01b4d2db062aa85/545db032e4b0af1a81424b48.js"></script>
    </div>

We should be able to render:

<amp-o2-player data-pid="579a115aa01b4d2db062aa85"
  data-bcid="545db032e4b0af1a81424b48"
  data-macros="m.playback=click"
  layout="responsive"
  width="480"
  height="270">
</amp-o2-player>

@ghost ghost mentioned this pull request Jun 6, 2018
*/
public function __construct( DOMDocument $dom, array $args = array() ) {
parent::__construct( $dom, $args );
$this->xpath = new DOMXPath( $dom );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The xpath setting here could just as well be moved to the sanitize method since that is where it is used. This would avoid needing to override the constructor at all, and if the sanitizers are instantiated but never call sanitize then we could avoid needlessly instantiating this object (however rare that may be).

private static $height = '270';

/**
* Width to set for 02 Player elements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be O2 not 02.

public static $xpath_selector = '//div[ contains( @class, \'vdb_player\' ) ]/script';

/**
* Height to set for 02 Player elements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be O2 not 02.

* @see https://www.ampproject.org/docs/reference/components/amp-o2-player
*/
class AMP_O2_Player_Sanitizer extends AMP_Base_Sanitizer {
const URL_PATTERN = '#.*delivery.vidible.tv\/jsonp\/pid=(.*)\/vid=(.*)\/(.*).js.*#i';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add phpdoc for this.

* @see https://www.ampproject.org/docs/reference/components/amp-o2-player
*/
class AMP_O2_Player_Sanitizer extends AMP_Base_Sanitizer {
const URL_PATTERN = '#.*delivery.vidible.tv\/jsonp\/pid=(.*)\/vid=(.*)\/(.*).js.*#i';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to use named capture groups to make it easier to reference the $matches.

* Class AMP_O2_Player_Sanitizer
*
* Converts <div class="vdb_player><script></script></div> embed to <amp-o2-player>
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add @since 1.0 tag to the class (at least)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@westonruter westonruter added this to the v1.0 milestone Jun 20, 2018
@westonruter westonruter merged commit 554400c into ampproject:develop Jun 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant