|
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
|
|
|
'//script[contains(@src,\'//assets.pinterest.com/js/pinit.js\')]', |
|
21
|
|
|
'//script[ @id = \'eventbrite-widget-js\' ]', |
|
22
|
|
|
'//script[ @id = \'eventbrite-widget-js-after\' ]', |
|
23
|
|
|
'//script[ @id = \'jetpack-block-calendly-js-extra\' ]', |
|
24
|
|
|
'//script[ @id = \'jetpack-block-calendly-js\' ]', |
|
25
|
|
|
'//script[ @id = \'jetpack-calendly-external-js-js\' ]', |
|
26
|
|
|
'//script[ @id = \'jetpack-calendly-external-js-js-after\' ]', |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Sanitize document for dev mode. |
|
31
|
|
|
* |
|
32
|
|
|
* @since 1.3 |
|
33
|
|
|
*/ |
|
34
|
|
|
public function sanitize() { |
|
35
|
|
|
$this->dom->documentElement->setAttribute( AMP_Rule_Spec::DEV_MODE_ATTRIBUTE, '' ); |
|
36
|
|
|
|
|
37
|
|
|
$xpath = new DOMXPath( $this->dom ); |
|
38
|
|
|
foreach ( self::$asset_xpaths as $element_xpath ) { |
|
39
|
|
|
foreach ( $xpath->query( $element_xpath ) as $node ) { |
|
40
|
|
|
if ( $node instanceof DOMElement ) { |
|
41
|
|
|
$node->setAttribute( AMP_Rule_Spec::DEV_MODE_ATTRIBUTE, '' ); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|