C:\xampp\htdocs\landing\wp-content\plugins\amp\includes\sanitizers\trait-amp-noscript-fallback.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
 * Trait AMP_Noscript_Fallback.
 *
 * @package AMP
 */

use AmpProject\Dom\Document;

/**
 * Trait AMP_Noscript_Fallback
 *
 * Used for sanitizers that place <noscript> tags with the original nodes on error.
 *
 * @since 1.1
 * @internal
 */
trait AMP_Noscript_Fallback {

    
/**
     * Attributes allowed on noscript fallback elements.
     *
     * This is used to prevent duplicated validation errors.
     *
     * @since 1.1
     *
     * @var array
     */
    
private $noscript_fallback_allowed_attributes = [];

    
/**
     * Initializes the internal allowed attributes array.
     *
     * @since 1.1
     *
     * @param string $tag Tag name to get allowed attributes for.
     */
    
protected function initialize_noscript_allowed_attributes$tag ) {
        
$this->noscript_fallback_allowed_attributes array_fill_keys(
            
array_keysAMP_Allowed_Tags_Generated::get_allowed_attributes() ),
            
true
        
);

        foreach ( 
AMP_Allowed_Tags_Generated::get_allowed_tag$tag ) as $tag_spec ) { // Normally 1 iteration.
            
foreach ( $tag_spec['attr_spec_list'] as $attr_name => $attr_spec ) {
                
$this->noscript_fallback_allowed_attributes$attr_name ] = true;
                if ( isset( 
$attr_spec['alternative_names'] ) ) {
                    
$this->noscript_fallback_allowed_attributes array_merge(
                        
$this->noscript_fallback_allowed_attributes,
                        
array_fill_keys$attr_spec['alternative_names'], true )
                    );
                }
            }
        }
    }

    
/**
     * Checks whether the given node is within an AMP-specific <noscript> element.
     *
     * @since 1.1
     *
     * @param DOMNode $node DOM node to check.
     *
     * @return bool True if in an AMP noscript element, false otherwise.
     */
    
protected function is_inside_amp_noscriptDOMNode $node ) {
        return 
'noscript' === $node->parentNode->nodeName && $node->parentNode->parentNode && 'amp-' === substr$node->parentNode->parentNode->nodeName0);
    }

    
/**
     * Appends the given old node in a <noscript> element to the new node.
     *
     * @since 1.1
     *
     * @param DOMElement $new_element New element to append a noscript with the old element to.
     * @param DOMElement $old_element Old element to append in a noscript.
     * @param Document   $dom         DOM document instance.
     */
    
protected function append_old_node_noscriptDOMElement $new_elementDOMElement $old_elementDocument $dom ) {
        
$noscript $dom->createElement'noscript' );
        
$noscript->appendChild$old_element );
        
$new_element->appendChild$noscript );

        
// Remove all non-allowed attributes preemptively to prevent doubled validation errors.
        
for ( $i $old_element->attributes->length 1$i >= 0$i-- ) {
            
$attribute $old_element->attributes->item$i );
            if ( isset( 
$this->noscript_fallback_allowed_attributes$attribute->nodeName ] ) ) {
                continue;
            }
            
$old_element->removeAttribute$attribute->nodeName );
        }
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586