C:\xampp\htdocs\landing\wp-content\plugins\amp\includes\embeds\class-amp-base-embed-handler.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
 * Class AMP_Base_Embed_Handler
 *
 * Used by some children.
 *
 * @package  AMP
 */

/**
 * Class AMP_Base_Embed_Handler
 *
 * @since 0.2
 */
abstract class AMP_Base_Embed_Handler {
    
/**
     * Default width.
     *
     * @var int
     */
    
protected $DEFAULT_WIDTH 600;

    
/**
     * Default height.
     *
     * @var int
     */
    
protected $DEFAULT_HEIGHT 480;

    
/**
     * Default arguments.
     *
     * @var array
     */
    
protected $args = [];

    
/**
     * Whether or not conversion was completed.
     *
     * @var boolean
     */
    
protected $did_convert_elements false;

    
/**
     * Registers embed.
     */
    
abstract public function register_embed();

    
/**
     * Unregisters embed.
     */
    
abstract public function unregister_embed();

    
/**
     * Constructor.
     *
     * @param array $args Height and width for embed.
     */
    
public function __construct$args = [] ) {
        
$this->args wp_parse_args(
            
$args,
            [
                
'width'  => $this->DEFAULT_WIDTH,
                
'height' => $this->DEFAULT_HEIGHT,
            ]
        );
    }

    
/**
     * Get mapping of AMP component names to AMP script URLs.
     *
     * This is normally no longer needed because the validating
     * sanitizer will automatically detect the need for them via
     * the spec.
     *
     * @see AMP_Tag_And_Attribute_Sanitizer::get_scripts()
     * @return array Scripts.
     */
    
public function get_scripts() {
        return [];
    }

    
/**
     * Get regex pattern for matching HTML attributes from a given tag name.
     *
     * @since 1.5.0
     *
     * @param string   $html            HTML source haystack.
     * @param string   $tag_name        Tag name.
     * @param string[] $attribute_names Attribute names.
     * @return string[]|null Matched attributes, or null if the element was not matched at all.
     */
    
protected function match_element_attributes$html$tag_name$attribute_names ) {
        
$pattern sprintf(
            
'/<%s%s/',
            
preg_quote$tag_name'/' ),
            
implode(
                
'',
                
array_map(
                    static function ( 
$attr_name ) {
                        return 
sprintf'(?=[^>]*?%1$s="(?P<%1$s>[^"]+)")?'preg_quote$attr_name'/' ) );
                    },
                    
$attribute_names
                
)
            )
        );
        if ( ! 
preg_match$pattern$html$matches ) ) {
            return 
null;
        }
        return 
wp_array_slice_assoc$matches$attribute_names );
    }

    
/**
     * Get all child elements of the specified element.
     *
     * @since 2.0.6
     *
     * @param DOMElement $node Element.
     * @return DOMElement[] Array of child elements for specified element.
     */
    
protected function get_child_elementsDOMElement $node ) {
        return 
array_filter(
            
iterator_to_array$node->childNodes ),
            static function ( 
DOMNode $child ) {
                return 
$child instanceof DOMElement;
            }
        );
    }

    
/**
     * Replace an element's parent with itself if the parent is a <p> tag which has no attributes and has no other children.
     *
     * This usually happens while `wpautop()` processes the element.
     *
     * @since 2.0.6
     * @see AMP_Tag_And_Attribute_Sanitizer::remove_node()
     *
     * @param DOMElement $node Node.
     */
    
protected function unwrap_p_elementDOMElement $node ) {
        
$parent_node $node->parentNode;
        if (
            
$parent_node instanceof DOMElement
            
&&
            
'p' === $parent_node->tagName
            
&&
            
false === $parent_node->hasAttributes()
            &&
            
=== count$this->get_child_elements$parent_node ) )
        ) {
            
$parent_node->parentNode->replaceChild$node$parent_node );
        }
    }
}
x

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