css
4 years ago
images
12 years ago
img
13 years ago
js
4 years ago
archiveorg-book.php
5 years ago
archiveorg.php
5 years ago
archives.php
5 years ago
bandcamp.php
5 years ago
brightcove.php
5 years ago
cartodb.php
5 years ago
class.filter-embedded-html-objects.php
3 years ago
codepen.php
5 years ago
crowdsignal.php
3 years ago
dailymotion.php
3 years ago
descript.php
4 years ago
facebook.php
3 years ago
flatio.php
5 years ago
flickr.php
5 years ago
getty.php
3 years ago
gist.php
5 years ago
googleapps.php
3 years ago
googlemaps.php
5 years ago
googleplus.php
5 years ago
gravatar.php
3 years ago
houzz.php
5 years ago
inline-pdfs.php
4 years ago
instagram.php
3 years ago
kickstarter.php
3 years ago
mailchimp.php
3 years ago
medium.php
3 years ago
mixcloud.php
3 years ago
others.php
3 years ago
pinterest.php
5 years ago
presentations.php
3 years ago
quiz.php
4 years ago
recipe.php
3 years ago
scribd.php
5 years ago
sitemap.php
5 years ago
slideshare.php
5 years ago
slideshow.php
3 years ago
smartframe.php
4 years ago
soundcloud.php
3 years ago
spotify.php
4 years ago
ted.php
5 years ago
tweet.php
5 years ago
twitchtv.php
5 years ago
twitter-timeline.php
5 years ago
unavailable.php
3 years ago
untappd-menu.php
3 years ago
upcoming-events.php
3 years ago
ustream.php
5 years ago
videopress.php
4 years ago
vimeo.php
3 years ago
vine.php
5 years ago
vr.php
3 years ago
wordads.php
5 years ago
wufoo.php
3 years ago
youtube.php
3 years ago
twitchtv.php
84 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Twitch.tv shortcode |
| 4 | * |
| 5 | * Examples: |
| 6 | * [twitchtv url='https://www.twitch.tv/paperbat' height='378' width='620' autoplay='false'] |
| 7 | * [twitchtv url='https://www.twitch.tv/paperbat/b/323486192' height='378' width='620' autoplay='false'] |
| 8 | * |
| 9 | * @package automattic/jetpack |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * (Live URL) https://www.twitch.tv/paperbat |
| 14 | * |
| 15 | * <iframe src="https://player.twitch.tv/?autoplay=false&muted=false&channel=paperbat" width="620" height="378" frameborder="0" scrolling="no" allowfullscreen></iframe> |
| 16 | * |
| 17 | * (Archive URL) https://www.twitch.tv/paperbat/v/323486192 |
| 18 | * |
| 19 | * <iframe src="https://player.twitch.tv/?autoplay=false&muted=false&video=v323486192" width="620" height="378" frameborder="0" scrolling="no" allowfullscreen></iframe> |
| 20 | * |
| 21 | * @param array $atts User supplied shortcode arguments. |
| 22 | * |
| 23 | * @return string HTML output of the shortcode. |
| 24 | */ |
| 25 | function wpcom_twitchtv_shortcode( $atts ) { |
| 26 | $attr = shortcode_atts( |
| 27 | array( |
| 28 | 'height' => 378, |
| 29 | 'width' => 620, |
| 30 | 'url' => '', |
| 31 | 'autoplay' => 'false', |
| 32 | 'muted' => 'false', |
| 33 | 'time' => null, |
| 34 | ), |
| 35 | $atts |
| 36 | ); |
| 37 | |
| 38 | if ( empty( $attr['url'] ) ) { |
| 39 | return '<!-- Invalid twitchtv URL -->'; |
| 40 | } |
| 41 | |
| 42 | preg_match( '|^https?://www.twitch.tv/([^/?]+)(/v/(\d+))?|i', $attr['url'], $match ); |
| 43 | |
| 44 | $url_args = array( |
| 45 | 'autoplay' => ( false !== $attr['autoplay'] && 'false' !== $attr['autoplay'] ) ? 'true' : 'false', |
| 46 | 'muted' => ( false !== $attr['muted'] && 'false' !== $attr['muted'] ) ? 'true' : 'false', |
| 47 | 'time' => $attr['time'], |
| 48 | ); |
| 49 | |
| 50 | $width = (int) $attr['width']; |
| 51 | $height = (int) $attr['height']; |
| 52 | |
| 53 | $user_id = $match[1]; |
| 54 | $video_id = 0; |
| 55 | if ( ! empty( $match[3] ) ) { |
| 56 | $video_id = (int) $match[3]; |
| 57 | } |
| 58 | |
| 59 | do_action( 'jetpack_bump_stats_extras', 'twitchtv', 'shortcode' ); |
| 60 | |
| 61 | if ( $video_id > 0 ) { |
| 62 | $url_args['video'] = 'v' . $video_id; |
| 63 | } else { |
| 64 | $url_args['channel'] = $user_id; |
| 65 | } |
| 66 | |
| 67 | // See https://discuss.dev.twitch.tv/t/twitch-embedded-player-updates-in-2020/23956. |
| 68 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 69 | $url_args['parent'] = isset( $_SERVER['HTTP_HOST'] ) |
| 70 | ? rawurlencode( wp_unslash( $_SERVER['HTTP_HOST'] ) ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 71 | : ''; |
| 72 | |
| 73 | $url = add_query_arg( $url_args, 'https://player.twitch.tv/' ); |
| 74 | |
| 75 | return sprintf( |
| 76 | '<iframe src="%s" width="%d" height="%d" frameborder="0" scrolling="no" allowfullscreen sandbox="allow-popups allow-scripts allow-same-origin allow-presentation"></iframe>', |
| 77 | esc_url( $url ), |
| 78 | esc_attr( $width ), |
| 79 | esc_attr( $height ) |
| 80 | ); |
| 81 | } |
| 82 | add_shortcode( 'twitch', 'wpcom_twitchtv_shortcode' ); |
| 83 | add_shortcode( 'twitchtv', 'wpcom_twitchtv_shortcode' ); |
| 84 |