css
2 years ago
images
2 years ago
img
2 years ago
js
2 years ago
archiveorg-book.php
5 years ago
archiveorg.php
5 years ago
archives.php
5 years ago
bandcamp.php
3 years ago
brightcove.php
5 years ago
cartodb.php
5 years ago
class.filter-embedded-html-objects.php
2 years ago
codepen.php
5 years ago
crowdsignal.php
2 years ago
dailymotion.php
3 years ago
descript.php
4 years ago
facebook.php
2 years ago
flatio.php
5 years ago
flickr.php
2 years ago
getty.php
2 years ago
gist.php
3 years ago
googleapps.php
2 years ago
googlemaps.php
2 years ago
googleplus.php
5 years ago
gravatar.php
2 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
2 years ago
others.php
2 years ago
pinterest.php
2 years ago
presentations.php
2 years ago
quiz.php
4 years ago
recipe.php
2 years ago
scribd.php
5 years ago
sitemap.php
5 years ago
slideshare.php
5 years ago
slideshow.php
2 years ago
smartframe.php
3 years ago
soundcloud.php
3 years ago
spotify.php
2 years ago
ted.php
5 years ago
tweet.php
2 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
2 years ago
vine.php
5 years ago
vr.php
2 years ago
wordads.php
5 years ago
wufoo.php
3 years ago
youtube.php
1 year ago
ted.php
122 lines
| 1 | <?php |
| 2 | /** |
| 3 | * TED Player embed code |
| 4 | * http://www.ted.com |
| 5 | * |
| 6 | * Examples: |
| 7 | * http://www.ted.com/talks/view/id/210 |
| 8 | * http://www.ted.com/talks/marc_goodman_a_vision_of_crimes_in_the_future.html |
| 9 | * [ted id="210" lang="en"] |
| 10 | * [ted id="http://www.ted.com/talks/view/id/210" lang="en"] |
| 11 | * [ted id=1539 lang=fr width=560 height=315] |
| 12 | * |
| 13 | * @package automattic/jetpack |
| 14 | */ |
| 15 | |
| 16 | wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/view/id/.+!i', 'https://www.ted.com/talks/oembed.json', true ); |
| 17 | wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/[a-zA-Z\-\_]+\.html!i', 'https://www.ted.com/talks/oembed.json', true ); |
| 18 | |
| 19 | /** |
| 20 | * Get the unique ID of a TED video. |
| 21 | * Used in Jetpack_Media_Meta_Extractor. |
| 22 | * |
| 23 | * @param array $atts Shortcode attributes. |
| 24 | */ |
| 25 | function jetpack_shortcode_get_ted_id( $atts ) { |
| 26 | return ( ! empty( $atts['id'] ) ? $atts['id'] : 0 ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Handle Ted Shortcode. |
| 31 | * |
| 32 | * @param array $atts Shortcode attributes. |
| 33 | */ |
| 34 | function shortcode_ted( $atts ) { |
| 35 | global $wp_embed; |
| 36 | |
| 37 | $defaults = array( |
| 38 | 'id' => '', |
| 39 | 'width' => '', |
| 40 | 'height' => '', |
| 41 | 'lang' => 'en', |
| 42 | ); |
| 43 | $atts = shortcode_atts( $defaults, $atts, 'ted' ); |
| 44 | |
| 45 | if ( empty( $atts['id'] ) ) { |
| 46 | return '<!-- Missing TED ID -->'; |
| 47 | } |
| 48 | |
| 49 | $url = ''; |
| 50 | if ( preg_match( '#^[\d]+$#', $atts['id'], $matches ) ) { |
| 51 | $url = 'https://ted.com/talks/view/id/' . $matches[0]; |
| 52 | } elseif ( preg_match( '#^https?://(www\.)?ted\.com/talks/view/id/[0-9]+$#', $atts['id'], $matches ) ) { |
| 53 | $url = set_url_scheme( $matches[0], 'https' ); |
| 54 | } |
| 55 | |
| 56 | unset( $atts['id'] ); |
| 57 | |
| 58 | $args = array(); |
| 59 | $embed_size_w = get_option( 'embed_size_w' ); |
| 60 | |
| 61 | if ( is_numeric( $atts['width'] ) ) { |
| 62 | $args['width'] = $atts['width']; |
| 63 | } elseif ( $embed_size_w ) { |
| 64 | $args['width'] = $embed_size_w; |
| 65 | } elseif ( ! empty( $GLOBALS['content_width'] ) ) { |
| 66 | $args['width'] = (int) $GLOBALS['content_width']; |
| 67 | } else { |
| 68 | $args['width'] = 500; |
| 69 | } |
| 70 | |
| 71 | // Default to a 16x9 aspect ratio if there's no height set. |
| 72 | if ( is_numeric( $atts['height'] ) ) { |
| 73 | $args['height'] = $atts['height']; |
| 74 | } else { |
| 75 | $args['height'] = $args['width'] * 0.5625; |
| 76 | } |
| 77 | |
| 78 | if ( ! empty( $atts['lang'] ) ) { |
| 79 | $args['lang'] = sanitize_key( $atts['lang'] ); |
| 80 | add_filter( 'oembed_fetch_url', 'ted_filter_oembed_fetch_url', 10, 3 ); |
| 81 | } |
| 82 | $retval = $wp_embed->shortcode( $args, $url ); |
| 83 | remove_filter( 'oembed_fetch_url', 'ted_filter_oembed_fetch_url', 10 ); |
| 84 | |
| 85 | return $retval; |
| 86 | } |
| 87 | add_shortcode( 'ted', 'shortcode_ted' ); |
| 88 | |
| 89 | /** |
| 90 | * Filter the request URL to also include the $lang parameter |
| 91 | * |
| 92 | * @param string $provider URL of provider that supplies the tweet we're requesting. |
| 93 | * @param string $url URL of tweet to embed. |
| 94 | * @param array $args Parameters supplied to shortcode and passed to wp_oembed_get. |
| 95 | */ |
| 96 | function ted_filter_oembed_fetch_url( $provider, $url, $args ) { |
| 97 | return add_query_arg( 'lang', $args['lang'], $provider ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Filter the oembed html to set the sandbox attribute in the iframe |
| 102 | * |
| 103 | * @param string|false $cache The cached HTML result, stored in post meta. |
| 104 | * @param string $url The attempted embed URL. |
| 105 | * |
| 106 | * @return string|false |
| 107 | */ |
| 108 | function ted_filter_oembed_amp_iframe( $cache, $url ) { |
| 109 | if ( is_string( $cache ) |
| 110 | && strpos( $url, 'ted.com' ) |
| 111 | ) { |
| 112 | $cache = preg_replace( |
| 113 | '/src=[\'"].*?[\'"]/', |
| 114 | '$0 sandbox="allow-popups allow-scripts allow-same-origin"', |
| 115 | $cache |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | return $cache; |
| 120 | } |
| 121 | add_filter( 'embed_oembed_html', 'ted_filter_oembed_amp_iframe', 10, 2 ); |
| 122 |