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

Conversation

Projects
None yet
2 participants
@juanchaur1
Contributor

juanchaur1 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>
*/
public function __construct( DOMDocument $dom, array $args = array() ) {
parent::__construct( $dom, $args );
$this->xpath = new DOMXPath( $dom );

This comment has been minimized.

@westonruter

westonruter Jun 10, 2018

Member

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.

This comment has been minimized.

@westonruter

westonruter Jun 10, 2018

Member

Should be O2 not 02.

public static $xpath_selector = '//div[ contains( @class, \'vdb_player\' ) ]/script';
/**
* Height to set for 02 Player elements.

This comment has been minimized.

@westonruter

westonruter Jun 10, 2018

Member

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';

This comment has been minimized.

@westonruter

westonruter Jun 10, 2018

Member

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';

This comment has been minimized.

@westonruter

westonruter Jun 10, 2018

Member

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>
*

This comment has been minimized.

@westonruter

westonruter Jun 10, 2018

Member

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

This comment has been minimized.

@juanchaur1

juanchaur1 Jun 19, 2018

Contributor

done

juanchaur1 and others added some commits Jun 19, 2018

@westonruter westonruter added this to the v1.0 milestone Jun 20, 2018

@westonruter westonruter merged commit 554400c into ampproject:develop Jun 20, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment