Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
84.29% |
59 / 70 |
|
0.00% |
0 / 2 |
CRAP | n/a |
0 / 0 |
|
| ustream_shortcode | |
89.36% |
42 / 47 |
|
0.00% |
0 / 1 |
9.10 | |||
| ustreamsocial_shortcode | |
89.47% |
17 / 19 |
|
0.00% |
0 / 1 |
4.02 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Ustream.tv shortcode |
| 4 | * |
| 5 | * Example: |
| 6 | * [ustream id=1524 live=1] |
| 7 | * [ustreamsocial id=12980237 width="500"] |
| 8 | * |
| 9 | * Embed code example, from http://www.ustream.tv/leolaporte |
| 10 | * <iframe src="http://www.ustream.tv/embed/recorded/1524?v=3&wmode=direct" width="480" height="296" scrolling="no" frameborder="0" style="border: 0 none transparent;"></iframe> |
| 11 | * |
| 12 | * @package automattic/jetpack |
| 13 | */ |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit( 0 ); |
| 17 | } |
| 18 | |
| 19 | add_shortcode( 'ustream', 'ustream_shortcode' ); |
| 20 | add_shortcode( 'ustreamsocial', 'ustreamsocial_shortcode' ); |
| 21 | |
| 22 | /** |
| 23 | * Parse shortcode arguments and render output for ustream single video. |
| 24 | * |
| 25 | * @since 4.5.0 |
| 26 | * |
| 27 | * @param array $atts array of user-supplied arguments. |
| 28 | * |
| 29 | * @return string HTML output. |
| 30 | */ |
| 31 | function ustream_shortcode( $atts ) { |
| 32 | if ( isset( $atts[0] ) ) { |
| 33 | return '<!-- ustream error: bad parameters -->'; |
| 34 | } |
| 35 | |
| 36 | $defaults = array( |
| 37 | 'width' => 480, |
| 38 | 'height' => 296, |
| 39 | 'id' => 0, |
| 40 | 'live' => 0, |
| 41 | 'highlight' => 0, |
| 42 | 'version' => 3, |
| 43 | 'hwaccel' => 1, |
| 44 | ); |
| 45 | $atts = array_map( 'intval', shortcode_atts( $defaults, $atts ) ); |
| 46 | |
| 47 | if ( 0 >= $atts['id'] ) { |
| 48 | return '<!-- ustream error: bad video ID -->'; |
| 49 | } |
| 50 | |
| 51 | if ( 0 >= $atts['height'] ) { |
| 52 | return '<!-- ustream error: height invalid -->'; |
| 53 | } |
| 54 | |
| 55 | if ( 0 >= $atts['width'] ) { |
| 56 | return '<!-- ustream error: width invalid -->'; |
| 57 | } |
| 58 | |
| 59 | if ( $atts['live'] ) { |
| 60 | $recorded = ''; |
| 61 | } else { |
| 62 | $recorded = 'recorded/'; |
| 63 | } |
| 64 | |
| 65 | if ( ! $atts['live'] && ( 0 < $atts['highlight'] ) ) { |
| 66 | $highlight = sprintf( '/highlight/%d', esc_attr( $atts['highlight'] ) ); |
| 67 | } else { |
| 68 | $highlight = ''; |
| 69 | } |
| 70 | |
| 71 | $url_base = sprintf( |
| 72 | 'https://www.ustream.tv/embed/%s%d%s', |
| 73 | $recorded, |
| 74 | esc_attr( $atts['id'] ), |
| 75 | $highlight |
| 76 | ); |
| 77 | |
| 78 | $video_options = array( |
| 79 | 'html5ui' => 1, |
| 80 | 'v' => absint( $atts['version'] ), |
| 81 | ); |
| 82 | |
| 83 | if ( 0 < $atts['hwaccel'] ) { |
| 84 | $video_options['wmode'] = 'direct'; |
| 85 | } |
| 86 | |
| 87 | $url = add_query_arg( |
| 88 | $video_options, |
| 89 | $url_base |
| 90 | ); |
| 91 | |
| 92 | $output = sprintf( |
| 93 | '<iframe src="%1$s" width="%2$d" height="%3$d" scrolling="no" style="border: 0 none transparent;"></iframe>', |
| 94 | esc_url( $url ), |
| 95 | absint( $atts['width'] ), |
| 96 | absint( $atts['height'] ) |
| 97 | ); |
| 98 | |
| 99 | return $output; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Parse shortcode arguments and render output for ustream's Social Stream. |
| 104 | * |
| 105 | * @since 4.5.0 |
| 106 | * |
| 107 | * @param array $atts array of user-supplied arguments. |
| 108 | * |
| 109 | * @return string HTML output. |
| 110 | */ |
| 111 | function ustreamsocial_shortcode( $atts ) { |
| 112 | $defaults = array( |
| 113 | 'id' => 0, |
| 114 | 'height' => 420, |
| 115 | 'width' => 320, |
| 116 | ); |
| 117 | $atts = array_map( 'intval', shortcode_atts( $defaults, $atts ) ); |
| 118 | |
| 119 | if ( 0 >= $atts['id'] ) { |
| 120 | return '<!-- ustreamsocial error: bad social stream ID -->'; |
| 121 | } |
| 122 | |
| 123 | if ( 0 >= $atts['height'] ) { |
| 124 | return '<!-- ustreamsocial error: height invalid -->'; |
| 125 | } |
| 126 | |
| 127 | if ( 0 >= $atts['width'] ) { |
| 128 | return '<!-- ustreamsocial error: width invalid -->'; |
| 129 | } |
| 130 | |
| 131 | $url = 'https://www.ustream.tv/socialstream/' . esc_attr( $atts['id'] ); |
| 132 | |
| 133 | return sprintf( |
| 134 | '<iframe id="SocialStream" src="%1$s" class="" name="SocialStream" width="%2$d" height="%3$d" scrolling="no" allowtransparency="true" style="visibility: visible; margin-top: 0; margin-bottom: 0; border: 0;"></iframe>', |
| 135 | esc_url( $url ), |
| 136 | absint( $atts['width'] ), |
| 137 | absint( $atts['height'] ) |
| 138 | ); |
| 139 | } |