C:\xampp\htdocs\landing\wp-content\plugins\amp\includes\sanitizers\class-amp-script-sanitizer.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
<?php
/**
 * Class AMP_Script_Sanitizer
 *
 * @since 1.0
 * @package AMP
 */

use AmpProject\DevMode;

/**
 * Class AMP_Script_Sanitizer
 *
 * @since 1.0
 * @internal
 */
class AMP_Script_Sanitizer extends AMP_Base_Sanitizer {

    
/**
     * Sanitize noscript elements.
     *
     * Eventually this should also handle script elements, if there is a known AMP equivalent.
     * If nothing is done with script elements, the validating sanitizer will deal with them ultimately.
     *
     * @todo Eventually this try to automatically convert script tags to AMP when they are recognized. See <https://github.com/ampproject/amp-wp/issues/1032>.
     * @todo When a script has an adjacent noscript, consider removing the script here to prevent validation error later. See <https://github.com/ampproject/amp-wp/issues/1213>.
     *
     * @since 1.0
     */
    
public function sanitize() {
        
$noscripts $this->dom->getElementsByTagName'noscript' );

        for ( 
$i $noscripts->length 1$i >= 0$i-- ) {
            
$noscript $noscripts->item$i );

            
// Skip AMP boilerplate.
            
if ( $noscript->firstChild instanceof DOMElement && $noscript->firstChild->hasAttribute'amp-boilerplate' ) ) {
                continue;
            }

            
/*
             * Skip noscript elements inside of amp-img or other AMP components for fallbacks.
             * See \AMP_Img_Sanitizer::adjust_and_replace_node(). Also skip if the element has dev mode.
             */
            
if ( 'amp-' === substr$noscript->parentNode->nodeName0) || DevMode::hasExemptionForNode$noscript ) ) {
                continue;
            }

            
$is_inside_head_el = ( $noscript->parentNode && 'head' === $noscript->parentNode->nodeName );
            
$must_move_to_body false;

            
$fragment $this->dom->createDocumentFragment();
            
$fragment->appendChild$this->dom->createComment'noscript' ) );
            while ( 
$noscript->firstChild ) {
                if ( 
$is_inside_head_el && ! $must_move_to_body ) {
                    
$must_move_to_body = ! $this->dom->isValidHeadNode$noscript->firstChild );
                }
                
$fragment->appendChild$noscript->firstChild );
            }
            
$fragment->appendChild$this->dom->createComment'/noscript' ) );

            if ( 
$must_move_to_body ) {
                
$this->dom->body->insertBefore$fragment$this->dom->body->firstChild );
                
$noscript->parentNode->removeChild$noscript );
            } else {
                
$noscript->parentNode->replaceChild$fragment$noscript );
            }

            
$this->did_convert_elements true;
        }
    }
}
x

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