C:\xampp\htdocs\landing\wp-content\plugins\amp\includes\templates\class-amp-content.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
/**
 * Class AMP_Content
 *
 * @package AMP
 */

/**
 * Class AMP_Content
 *
 * @codeCoverageIgnore
 * @deprecated 1.5 Reader mode now sanitizes its entire template through the standard post-processor.
 * @internal
 */
class AMP_Content {

    
/**
     * Content.
     *
     * @var string
     */
    
private $content;

    
/**
     * AMP content.
     *
     * @var string
     */
    
private $amp_content '';

    
/**
     * AMP scripts.
     *
     * @var array
     */
    
private $amp_scripts = [];

    
/**
     * AMP stylesheets.
     *
     * @since 1.0
     * @var array
     */
    
private $amp_stylesheets = [];

    
/**
     * Args.
     *
     * @var array
     */
    
private $args;

    
/**
     * Embed handlers.
     *
     * @var AMP_Base_Embed_Handler[]
     */
    
private $embed_handlers;

    
/**
     * Sanitizers, with keys as class names and values as arguments.
     *
     * @var array[]
     */
    
private $sanitizer_classes;

    
/**
     * AMP_Content constructor.
     *
     * @param string  $content               Content.
     * @param array[] $embed_handler_classes Embed handlers, with keys as class names and values as arguments.
     * @param array[] $sanitizer_classes     Sanitizers, with keys as class names and values as arguments.
     * @param array   $args                  Args.
     */
    
public function __construct$content$embed_handler_classes$sanitizer_classes$args = [] ) {
        
$this->content           $content;
        
$this->args              $args;
        
$this->embed_handlers    $this->register_embed_handlers$embed_handler_classes );
        
$this->sanitizer_classes $sanitizer_classes;

        
$this->sanitizer_classes['AMP_Embed_Sanitizer']['embed_handlers'] = $this->embed_handlers;

        
$this->transform();
    }

    
/**
     * Get AMP content.
     *
     * @return string
     */
    
public function get_amp_content() {
        return 
$this->amp_content;
    }

    
/**
     * Get AMP scripts.
     *
     * @return array
     */
    
public function get_amp_scripts() {
        return 
$this->amp_scripts;
    }

    
/**
     * Get AMP styles.
     *
     * @deprecated Since 1.0 in favor of the get_amp_stylesheets method.
     * @return array Empty list.
     */
    
public function get_amp_styles() {
        
_deprecated_function__METHOD__'1.0'__CLASS__ '::get_amp_stylesheets' );
        return [];
    }

    
/**
     * Get AMP styles.
     *
     * @since 1.0
     * @return array
     */
    
public function get_amp_stylesheets() {
        return 
$this->amp_stylesheets;
    }

    
/**
     * Transform.
     */
    
private function transform() {
        
$content $this->content;

        
// First, embeds + the_content filter.
        /** This filter is documented in wp-includes/post-template.php */
        
$content apply_filters'the_content'$content );
        
$this->unregister_embed_handlers$this->embed_handlers );

        
// Then, sanitize to strip and/or convert non-amp content.
        
$content $this->sanitize$content );

        
$this->amp_content $content;
    }

    
/**
     * Add scripts.
     *
     * @param array $scripts Scripts.
     */
    
private function add_scripts$scripts ) {
        
$this->amp_scripts array_merge$this->amp_scripts$scripts );
    }

    
/**
     * Add stylesheets.
     *
     * @since 1.0
     * @param array $stylesheets Styles.
     */
    
private function add_stylesheets$stylesheets ) {
        
$this->amp_stylesheets array_merge$this->amp_stylesheets$stylesheets );
    }

    
/**
     * Register embed handlers.
     *
     * @param array[] $embed_handler_classes Embed handlers, with keys as class names and values as arguments.
     * @return AMP_Base_Embed_Handler[] Registered embed handlers.
     */
    
private function register_embed_handlers$embed_handler_classes ) {
        
$embed_handlers = [];

        foreach ( 
$embed_handler_classes as $embed_handler_class => $args ) {
            
$embed_handler = new $embed_handler_classarray_merge$this->args$args ) );

            if ( ! 
$embed_handler instanceof AMP_Base_Embed_Handler ) {
                
_doing_it_wrong(
                    
__METHOD__,
                    
esc_html(
                        
sprintf(
                            
/* translators: 1: embed handler. 2: AMP_Embed_Handler */
                            
__'Embed Handler (%1$s) must extend `%2$s`''amp' ),
                            
esc_html$embed_handler_class ),
                            
'AMP_Embed_Handler'
                        
)
                    ),
                    
'0.1'
                
);
                continue;
            }

            
$embed_handler->register_embed();
            
$embed_handlers[] = $embed_handler;
        }

        return 
$embed_handlers;
    }

    
/**
     * Unregister embed handlers.
     *
     * @param AMP_Base_Embed_Handler[] $embed_handlers Embed handlers.
     */
    
private function unregister_embed_handlers$embed_handlers ) {
        foreach ( 
$embed_handlers as $embed_handler ) {
            
$this->add_scripts$embed_handler->get_scripts() ); // @todo Why add_scripts here? Shouldn't it be array_diff()?
            
$embed_handler->unregister_embed();
        }
    }

    
/**
     * Sanitize.
     *
     * @see AMP_Content_Sanitizer::sanitize()
     * @param string $content Content.
     * @return string Sanitized content.
     */
    
private function sanitize$content ) {
        
$dom AMP_DOM_Utils::get_dom_from_content$content );

        
$results AMP_Content_Sanitizer::sanitize_document$dom$this->sanitizer_classes$this->args );

        
$this->add_scripts$results['scripts'] );
        
$this->add_stylesheets$results['stylesheets'] );

        return 
AMP_DOM_Utils::get_content_from_dom$dom );
    }
}
x

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