Completed
Push — try/allow-embeds-in-amp ( 8ebcd5 )
by
unknown
153:05 queued 145:20
created

Jetpack_AMP_Feature_Assets_Sanitizer::sanitize()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Provides AMP validation carve-outs for Jetpack features
4
 *
5
 * @see https://github.com/Automattic/amp-wp
6
 * @package Jetpack
7
 */
8
9
/**
10
 * This sanitizer class sets AMP devmode on the html element and each other element to be ignored (and not stripped out) for validation purposes.
11
 */
12
class Jetpack_AMP_Feature_Assets_Sanitizer extends AMP_Base_Sanitizer {
13
	/**
14
	 * List of xpaths selecting assets to be ignored
15
	 *
16
	 * @var asset_xpaths.
17
	 */
18
	private static $asset_xpaths = array(
19
		'//script[contains(@src,\'www.opentable.com/widget\')]',
20
	);
21
22
	/**
23
	 * Sanitize document for dev mode.
24
	 *
25
	 * @since 1.3
26
	 */
27
	public function sanitize() {
28
		$this->dom->documentElement->setAttribute( AMP_Rule_Spec::DEV_MODE_ATTRIBUTE, '' );
29
30
		$xpath = new DOMXPath( $this->dom );
31
		foreach ( self::$asset_xpaths as $element_xpath ) {
32
			foreach ( $xpath->query( $element_xpath ) as $node ) {
33
				if ( $node instanceof DOMElement ) {
34
					$node->setAttribute( AMP_Rule_Spec::DEV_MODE_ATTRIBUTE, '' );
35
				}
36
			}
37
		}
38
	}
39
}
40