You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
<?php |
|
/** |
|
* Class AMP_Dev_Mode_Sanitizer |
|
* |
|
* Add the data-ampdevmode to the document element and to the elements specified by the supplied args. |
|
* |
|
* @since 1.3 |
|
* @package AMP |
|
*/ |
|
|
|
/** |
|
* Class AMP_Dev_Mode_Sanitizer |
|
* |
|
* @since 1.3 |
|
*/ |
|
final class AMP_Dev_Mode_Sanitizer extends AMP_Base_Sanitizer { |
|
|
|
/** |
|
* Array of flags used to control sanitization. |
|
* |
|
* @var array { |
|
* @type string[] $element_xpaths XPath expressions for elements to add the data-ampdevmode attribute to. |
|
* } |
|
*/ |
|
protected $args; |
|
|
|
/** |
|
* Sanitize document for dev mode. |
|
* |
|
* @since 1.3 |
|
*/ |
|
public function sanitize() { |
|
$this->dom->documentElement->setAttribute( AMP_Rule_Spec::DEV_MODE_ATTRIBUTE, '' ); |
|
|
|
$xpath = new DOMXPath( $this->dom ); |
|
$element_xpaths = ! empty( $this->args['element_xpaths'] ) ? $this->args['element_xpaths'] : []; |
|
foreach ( $element_xpaths as $element_xpath ) { |
|
foreach ( $xpath->query( $element_xpath ) as $node ) { |
|
if ( $node instanceof DOMElement ) { |
|
$node->setAttribute( AMP_Rule_Spec::DEV_MODE_ATTRIBUTE, '' ); |
|
} |
|
} |
|
} |
|
} |
|
}
|
|
|