PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 3.1.5
Jetpack – WP Security, Backup, Speed, & Growth v3.1.5
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / ted.php

ted.php in Jetpack – WP Security, Backup, Speed, & Growth 3.1.5, at modules/shortcodes/ted.php

73 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * TED Player embed code
4 * http://www.ted.com
5 *
6 * http://www.ted.com/talks/view/id/210
7 * http://www.ted.com/talks/marc_goodman_a_vision_of_crimes_in_the_future.html
8 * [ted id="210" lang="eng"]
9 * [ted id="http://www.ted.com/talks/view/id/210" lang="eng"]
10 * [ted id=1539 lang=fr width=560 height=315]
11 */
12
13 wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/view/id/.+!i', 'http://www.ted.com/talks/oembed.json', true );
14 wp_oembed_add_provider( '!https?://(www\.)?ted.com/talks/[a-zA-Z\-\_]+\.html!i', 'http://www.ted.com/talks/oembed.json', true );
15
16 function jetpack_shortcode_get_ted_id( $atts ) {
17 return ( ! empty( $atts['id'] ) ? $atts['id'] : 0 );
18 }
19
20 add_shortcode( 'ted', 'shortcode_ted' );
21 function shortcode_ted( $atts, $content = '' ) {
22 global $wp_embed;
23
24 $defaults = array(
25 'id' => '',
26 'width' => '',
27 'height' => '',
28 'lang' => 'eng',
29 );
30 $atts = shortcode_atts( $defaults, $atts );
31
32 if ( empty( $atts['id'] ) )
33 return '<!-- Missing TED ID -->';
34
35 if ( preg_match( "#^[\d]+$#", $atts['id'], $matches ) )
36 $url = 'http://ted.com/talks/view/id/' . $matches[0];
37 elseif ( preg_match( "#^https?://(www\.)?ted\.com/talks/view/id/[0-9]+$#", $atts['id'], $matches ) )
38 $url = $matches[0];
39
40 unset( $atts['id'] );
41
42 $args = array();
43 if ( is_numeric( $atts['width'] ) )
44 $args['width'] = $atts['width'];
45 else if ( $embed_size_w = get_option( 'embed_size_w' ) )
46 $args['width'] = $embed_size_w;
47 else if ( ! empty( $GLOBALS['content_width'] ) )
48 $args['width'] = (int)$GLOBALS['content_width'];
49 else
50 $args['width'] = 500;
51
52 // Default to a 16x9 aspect ratio if there's no height set
53 if ( is_numeric( $atts['height'] ) )
54 $args['height'] = $atts['height'];
55 else
56 $args['height'] = $args['width'] * 0.5625;
57
58 if ( ! empty( $atts['lang'] ) ) {
59 $args['lang'] = sanitize_key( $atts['lang'] );
60 add_filter( 'oembed_fetch_url', 'ted_filter_oembed_fetch_url', 10, 3 );
61 }
62 $retval = $wp_embed->shortcode( $args, $url );
63 remove_filter( 'oembed_fetch_url', 'ted_filter_oembed_fetch_url', 10 );
64 return $retval;
65 }
66
67 /**
68 * Filter the request URL to also include the $lang parameter
69 */
70 function ted_filter_oembed_fetch_url( $provider, $url, $args ) {
71 return add_query_arg( 'lang', $args['lang'], $provider );
72 }
73