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

Jetpack_AMP_Feature_Assets_Sanitizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A sanitize() 0 12 4
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