C:\xampp\htdocs\landing\wp-content\plugins\amp\includes\embeds\class-amp-vimeo-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
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
<?php
/**
 * Class AMP_Vimeo_Embed_Handler
 *
 * @package AMP
 */

/**
 * Class AMP_Vimeo_Embed_Handler
 *
 * Much of this class is borrowed from Jetpack embeds
 *
 * @internal
 */
class AMP_Vimeo_Embed_Handler extends AMP_Base_Embed_Handler {

    
/**
     * The embed URL pattern.
     *
     * @var string
     */
    
const URL_PATTERN '#https?:\/\/(.+\.)?vimeo\.com\/.*#i';

    
/**
     * The aspect ratio.
     *
     * @var float
     */
    
const RATIO 0.5625;

    
/**
     * Default width.
     *
     * @var int
     */
    
protected $DEFAULT_WIDTH 600;

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

    
/**
     * AMP_Vimeo_Embed_Handler constructor.
     *
     * @param array $args Height, width and maximum width for embed.
     */
    
public function __construct$args = [] ) {
        
parent::__construct$args );

        if ( isset( 
$this->args['content_max_width'] ) ) {
            
$max_width            $this->args['content_max_width'];
            
$this->args['width']  = $max_width;
            
$this->args['height'] = round$max_width self::RATIO );
        }
    }

    
/**
     * Register embed.
     */
    
public function register_embed() {
        
wp_embed_register_handler'amp-vimeo'self::URL_PATTERN, [ $this'oembed' ], -);
        
add_filter'wp_video_shortcode_override', [ $this'video_override' ], 10);
    }

    
/**
     * Unregister embed.
     */
    
public function unregister_embed() {
        
wp_embed_unregister_handler'amp-vimeo', -);
    }

    
/**
     * Render oEmbed.
     *
     * @see \WP_Embed::shortcode()
     *
     * @param array  $matches URL pattern matches.
     * @param array  $attr    Shortcode attribues.
     * @param string $url     URL.
     * @return string Rendered oEmbed.
     */
    
public function oembed$matches$attr$url ) {
        
$video_id $this->get_video_id_from_url$url );

        return 
$this->render(
            [
                
'url'      => $url,
                
'video_id' => $video_id,
            ]
        );
    }

    
/**
     * Render.
     *
     * @param array $args Args.
     * @return string Rendered.
     */
    
public function render$args ) {
        
$args wp_parse_args(
            
$args,
            [
                
'video_id' => false,
            ]
        );

        if ( empty( 
$args['video_id'] ) ) {
            return 
AMP_HTML_Utils::build_tag(
                
'a',
                [
                    
'href'  => esc_url_raw$args['url'] ),
                    
'class' => 'amp-wp-embed-fallback',
                ],
                
esc_html$args['url'] )
            );
        }

        
$this->did_convert_elements true;

        return 
AMP_HTML_Utils::build_tag(
            
'amp-vimeo',
            [
                
'data-videoid' => $args['video_id'],
                
'layout'       => 'responsive',
                
'width'        => $this->args['width'],
                
'height'       => $this->args['height'],
            ]
        );
    }

    
/**
     * Determine the video ID from the URL.
     *
     * @param string $url URL.
     * @return int Video ID.
     */
    
private function get_video_id_from_url$url ) {
        
$path wp_parse_url$urlPHP_URL_PATH );

        
// @todo This will not get the private key for unlisted videos (which look like https://vimeo.com/123456789/abcdef0123), but amp-vimeo doesn't support them currently anyway.
        
$video_id '';
        if ( 
$path && preg_match':/(\d+):'$path$matches ) ) {
            
$video_id $matches[1];
        }

        return 
$video_id;
    }

    
/**
     * Override the output of Vimeo videos.
     *
     * This overrides the value in wp_video_shortcode().
     * The pattern matching is copied from WP_Widget_Media_Video::render().
     *
     * @param string $html Empty variable to be replaced with shortcode markup.
     * @param array  $attr The shortcode attributes.
     * @return string|null $markup The markup to output.
     */
    
public function video_override$html$attr ) {
        if ( ! isset( 
$attr['src'] ) ) {
            return 
$html;
        }
        
$src           $attr['src'];
        
$vimeo_pattern '#^https?://(.+\.)?vimeo\.com/.*#';
        if ( 
!== preg_match$vimeo_pattern$src ) ) {
            return 
$html;
        }

        
$video_id $this->get_video_id_from_url$src );
        if ( empty( 
$video_id ) ) {
            return 
'';
        }

        return 
$this->rendercompact'video_id' ) );
    }
}
x

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