youtube-advanced.php
8.94 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
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
226
227
228
229
230
<?php
su_add_shortcode(
array(
'id' => 'youtube_advanced',
'callback' => 'su_shortcode_youtube_advanced',
'image' => su_get_plugin_url() . 'admin/images/shortcodes/youtube_advanced.svg',
'name' => __( 'YouTube advanced', 'shortcodes-ultimate' ),
'type' => 'single',
'group' => 'media',
'atts' => array(
'url' => array(
'values' => array(),
'default' => '',
'name' => __( 'Url', 'shortcodes-ultimate' ),
'desc' => __( 'Url of YouTube page with video. Ex: http://youtube.com/watch?v=XXXXXX', 'shortcodes-ultimate' ),
),
'playlist' => array(
'default' => '',
'name' => __( 'Playlist', 'shortcodes-ultimate' ),
'desc' => __( 'Value is a comma-separated list of video IDs to play. If you specify a value, the first video that plays will be the VIDEO_ID specified in the URL path, and the videos specified in the playlist parameter will play thereafter', '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' ),
),
'controls' => array(
'type' => 'select',
'values' => array(
'no' => __( '0 - Hide controls', 'shortcodes-ultimate' ),
'yes' => __( '1 - Show controls', 'shortcodes-ultimate' ),
'alt' => __( '2 - Show controls when playback is started', 'shortcodes-ultimate' ),
),
'default' => 'yes',
'name' => __( 'Controls', 'shortcodes-ultimate' ),
'desc' => __( 'This parameter indicates whether the video player controls will display', 'shortcodes-ultimate' ),
),
'autohide' => array(
'type' => 'select',
'values' => array(
'no' => __( '0 - Do not hide controls', 'shortcodes-ultimate' ),
'yes' => __( '1 - Hide all controls on mouse out', 'shortcodes-ultimate' ),
'alt' => __( '2 - Hide progress bar on mouse out', 'shortcodes-ultimate' ),
),
'default' => 'alt',
'name' => __( 'Autohide', 'shortcodes-ultimate' ),
'desc' => __( 'This parameter indicates whether the video controls will automatically hide after a video begins playing', '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' ),
),
'loop' => array(
'type' => 'bool',
'default' => 'no',
'name' => __( 'Loop', 'shortcodes-ultimate' ),
'desc' => __( 'Setting of YES will cause the player to play the initial video again and again', 'shortcodes-ultimate' ),
),
'rel' => array(
'type' => 'bool',
'default' => 'yes',
'name' => __( 'Display related videos from the same channel', 'shortcodes-ultimate' ),
'desc' => __( 'If this parameter is set to YES, related videos will come from the same channel as the video that was just played.', 'shortcodes-ultimate' ),
),
'fs' => array(
'type' => 'bool',
'default' => 'yes',
'name' => __( 'Show full-screen button', 'shortcodes-ultimate' ),
'desc' => __( 'Setting this parameter to NO prevents the fullscreen button from displaying', 'shortcodes-ultimate' ),
),
'modestbranding' => array(
'type' => 'bool',
'default' => 'no',
'name' => 'modestbranding',
'desc' => __( 'This parameter lets you use a YouTube player that does not show a YouTube logo. Set the parameter value to YES to prevent the YouTube logo from displaying in the control bar. Note that a small YouTube text label will still display in the upper-right corner of a paused video when the user\'s mouse pointer hovers over the player', 'shortcodes-ultimate' ),
),
'theme' => array(
'type' => 'select',
'values' => array(
'dark' => __( 'Dark theme', 'shortcodes-ultimate' ),
'light' => __( 'Light theme', 'shortcodes-ultimate' ),
),
'default' => 'dark',
'name' => __( 'Theme', 'shortcodes-ultimate' ),
'desc' => __( 'This parameter indicates whether the embedded player will display player controls (like a play button or volume control) within a dark or light control bar', 'shortcodes-ultimate' ),
),
'wmode' => array(
'default' => '',
'name' => __( 'WMode', 'shortcodes-ultimate' ),
// Translators: %1$s, %2$s - example values for shortcode attribute
'desc' => sprintf( __( 'Here you can specify wmode value for the embed URL.<br>Example values: %1$s, %2$s', 'shortcodes-ultimate' ), '<b%value>transparent</b>', '<b%value>opaque</b>' ),
),
'playsinline' => array(
'type' => 'bool',
'default' => 'no',
'name' => __( 'Plays inline', 'shortcodes-ultimate' ),
'desc' => __( 'This parameter controls whether videos play inline or fullscreen in an HTML5 player on iOS', 'shortcodes-ultimate' ),
),
'title' => array(
'name' => __( 'Title', 'shortcodes-ultimate' ),
'desc' => __( 'A brief description of the embedded content (used by screenreaders)', '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' => __( 'YouTube video player with advanced settings', 'shortcodes-ultimate' ),
'example' => 'media',
'icon' => 'youtube-play',
)
);
function su_shortcode_youtube_advanced( $atts = null, $content = null ) {
$atts = shortcode_atts(
array(
'url' => false,
'width' => 600,
'height' => 400,
'responsive' => 'yes',
'autohide' => 'alt',
'autoplay' => 'no',
'mute' => 'no',
'controls' => 'yes',
'fs' => 'yes',
'loop' => 'no',
'modestbranding' => 'no',
'playlist' => '',
'rel' => 'yes',
'showinfo' => 'yes',
'theme' => 'dark',
'wmode' => '',
'playsinline' => 'no',
'title' => '',
'class' => '',
),
$atts,
'youtube_advanced'
);
if ( ! $atts['url'] ) {
return su_error_message( 'YouTube Advanced', __( 'please specify correct url', 'shortcodes-ultimate' ) );
}
$atts['url'] = su_do_attribute( $atts['url'] );
$video_id = preg_match( '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $atts['url'], $match )
? $match[1]
: false;
if ( ! $video_id ) {
return su_error_message( 'YouTube Advanced', __( 'please specify correct url', 'shortcodes-ultimate' ) );
}
if ( 'alt' === $atts['controls'] ) {
$atts['controls'] = 'yes';
}
$url_params = array();
$yt_options = array(
'autohide',
'autoplay',
'mute',
'controls',
'fs',
'loop',
'modestbranding',
'playlist',
'rel',
'showinfo',
'theme',
'wmode',
'playsinline',
);
foreach ( $yt_options as $yt_option ) {
$url_params[ $yt_option ] = str_replace( array( 'no', 'yes', 'alt' ), array( '0', '1', '2' ), $atts[ $yt_option ] );
}
if ( '1' === $url_params['loop'] && '' === $url_params['playlist'] ) {
$url_params['playlist'] = $video_id;
}
if ( empty( $url_params['playlist'] ) ) {
unset( $url_params['playlist'] );
}
$url_params = http_build_query( $url_params );
$domain = strpos( $atts['url'], 'youtube-nocookie.com' ) !== false
? 'www.youtube-nocookie.com'
: 'www.youtube.com';
su_query_asset( 'css', 'su-shortcodes' );
return '<div class="su-youtube 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="https://' . $domain . '/embed/' . $video_id . '?' . esc_attr( $url_params ) . '" frameborder="0" allowfullscreen allow="autoplay; encrypted-media; picture-in-picture" title="' . esc_attr( $atts['title'] ) . '"></iframe></div>';
}