vimeo.php
4.62 KB
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
<?php
su_add_shortcode(
array(
'id' => 'vimeo',
'callback' => 'su_shortcode_vimeo',
'image' => su_get_plugin_url() . 'admin/images/shortcodes/vimeo.svg',
'name' => __( 'Vimeo', 'shortcodes-ultimate' ),
'type' => 'single',
'group' => 'media',
'atts' => array(
'url' => array(
'default' => '',
'name' => __( 'Url', 'shortcodes-ultimate' ),
'desc' => __( 'Url of Vimeo page with video', 'shortcodes-ultimate' ),
),
'width' => array(
'type' => 'slider',
'min' => 200,
'max' => 1600,
'step' => 20,
'default' => 600,
'name' => __( 'Width', 'shortcodes-ultimate' ),
'desc' => __( 'Player width', 'shortcodes-ultimate' ),
),
'height' => array(
'type' => 'slider',
'min' => 200,
'max' => 1600,
'step' => 20,
'default' => 400,
'name' => __( 'Height', 'shortcodes-ultimate' ),
'desc' => __( 'Player height', 'shortcodes-ultimate' ),
),
'responsive' => array(
'type' => 'bool',
'default' => 'yes',
'name' => __( 'Responsive', 'shortcodes-ultimate' ),
'desc' => __( 'Ignore width and height parameters and make player responsive', 'shortcodes-ultimate' ),
),
'autoplay' => array(
'type' => 'bool',
'default' => 'no',
'name' => __( 'Autoplay', 'shortcodes-ultimate' ),
'desc' => __( 'This parameter specifies whether the video will automatically start to play when the player loads. Please note, in modern browsers autoplay option only works with the mute option enabled', 'shortcodes-ultimate' ),
),
'mute' => array(
'type' => 'bool',
'default' => 'no',
'name' => __( 'Mute', 'shortcodes-ultimate' ),
'desc' => __( 'Mute the player', 'shortcodes-ultimate' ),
),
'dnt' => array(
'type' => 'bool',
'default' => 'no',
'name' => __( 'Do not track', 'shortcodes-ultimate' ),
'desc' => __( 'Setting this parameter to YES will block the player from tracking any playback session data. Will have the same effect as enabling a Do Not Track header in your browser', 'shortcodes-ultimate' ),
),
'title' => array(
'name' => __( 'Title', 'shortcodes-ultimate' ),
'desc' => __( 'A brief description of the embedded content (used by screenreaders)', 'shortcodes-ultimate' ),
'default' => '',
),
'texttrack' => array(
'name' => __( 'Subtitles', 'shortcodes-ultimate' ),
'desc' => __( 'Use language code as the value to enable subtitles. Example values: en, es', 'shortcodes-ultimate' ),
'default' => '',
),
'class' => array(
'type' => 'extra_css_class',
'name' => __( 'Extra CSS class', 'shortcodes-ultimate' ),
'desc' => __( 'Additional CSS class name(s) separated by space(s)', 'shortcodes-ultimate' ),
'default' => '',
),
),
'desc' => __( 'Vimeo video', 'shortcodes-ultimate' ),
'example' => 'media',
'icon' => 'youtube-play',
)
);
function su_shortcode_vimeo( $atts = null, $content = null ) {
$atts = shortcode_atts(
array(
'url' => '',
'width' => 600,
'height' => 400,
'autoplay' => 'no',
'dnt' => 'no',
'mute' => 'no',
'responsive' => 'yes',
'title' => '',
'texttrack' => '',
'class' => '',
),
$atts,
'vimeo'
);
if ( ! $atts['url'] ) {
return su_error_message( 'Vimeo', __( 'please specify correct url', 'shortcodes-ultimate' ) );
}
$atts['url'] = su_do_attribute( $atts['url'] );
$video_id = preg_match( '~(?:<iframe [^>]*src=")?(?:https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/videos?)?\/([0-9]+)[^\s]*)"?(?:[^>]*></iframe>)?(?:<p>.*</p>)?~ix', $atts['url'], $match )
? $match[1]
: false;
if ( ! $video_id ) {
return su_error_message( 'Vimeo', __( 'please specify correct url', 'shortcodes-ultimate' ) );
}
$url_params = array(
'title' => 0,
'byline' => 0,
'portrait' => 0,
'color' => 'ffffff',
'autoplay' => 'yes' === $atts['autoplay'] ? 1 : 0,
'dnt' => 'yes' === $atts['dnt'] ? 1 : 0,
'muted' => 'yes' === $atts['mute'] ? 1 : 0,
'texttrack' => esc_attr( $atts['texttrack'] ),
);
su_query_asset( 'css', 'su-shortcodes' );
return '<div class="su-vimeo su-u-responsive-media-' . esc_attr( $atts['responsive'] ) . su_get_css_class( $atts ) . '"><iframe width="' . esc_attr( $atts['width'] ) . '" height="' . esc_attr( $atts['height'] ) . '" src="//player.vimeo.com/video/' . $video_id . '?' . esc_attr( http_build_query( $url_params ) ) . '" frameborder="0" allow="autoplay; fullscreen" allowfullscreen title="' . esc_attr( $atts['title'] ) . '"></iframe></div>';
}