| 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 |
add_shortcode( 'ustream', 'ustream_shortcode' ); |
| 16 |
add_shortcode( 'ustreamsocial', 'ustreamsocial_shortcode' ); |
| 17 |
|
| 18 |
/** |
| 19 |
* Parse shortcode arguments and render output for ustream single video. |
| 20 |
* |
| 21 |
* @since 4.5.0 |
| 22 |
* |
| 23 |
* @param array $atts array of user-supplied arguments. |
| 24 |
* |
| 25 |
* @return string HTML output. |
| 26 |
*/ |
| 27 |
function ustream_shortcode( $atts ) { |
| 28 |
if ( isset( $atts[0] ) ) { |
| 29 |
return '<!-- ustream error: bad parameters -->'; |
| 30 |
} |
| 31 |
|
| 32 |
$defaults = array( |
| 33 |
'width' => 480, |
| 34 |
'height' => 296, |
| 35 |
'id' => 0, |
| 36 |
'live' => 0, |
| 37 |
'highlight' => 0, |
| 38 |
'version' => 3, |
| 39 |
'hwaccel' => 1, |
| 40 |
); |
| 41 |
$atts = array_map( 'intval', shortcode_atts( $defaults, $atts ) ); |
| 42 |
|
| 43 |
if ( 0 >= $atts['id'] ) { |
| 44 |
return '<!-- ustream error: bad video ID -->'; |
| 45 |
} |
| 46 |
|
| 47 |
if ( 0 >= $atts['height'] ) { |
| 48 |
return '<!-- ustream error: height invalid -->'; |
| 49 |
} |
| 50 |
|
| 51 |
if ( 0 >= $atts['width'] ) { |
| 52 |
return '<!-- ustream error: width invalid -->'; |
| 53 |
} |
| 54 |
|
| 55 |
if ( $atts['live'] ) { |
| 56 |
$recorded = ''; |
| 57 |
} else { |
| 58 |
$recorded = 'recorded/'; |
| 59 |
} |
| 60 |
|
| 61 |
if ( ! $atts['live'] && ( 0 < $atts['highlight'] ) ) { |
| 62 |
$highlight = sprintf( '/highlight/%d', esc_attr( $atts['highlight'] ) ); |
| 63 |
} else { |
| 64 |
$highlight = ''; |
| 65 |
} |
| 66 |
|
| 67 |
$url_base = sprintf( |
| 68 |
'https://www.ustream.tv/embed/%s%d%s', |
| 69 |
$recorded, |
| 70 |
esc_attr( $atts['id'] ), |
| 71 |
$highlight |
| 72 |
); |
| 73 |
|
| 74 |
$video_options = array( |
| 75 |
'html5ui' => 1, |
| 76 |
'v' => absint( $atts['version'] ), |
| 77 |
); |
| 78 |
|
| 79 |
if ( 0 < $atts['hwaccel'] ) { |
| 80 |
$video_options['wmode'] = 'direct'; |
| 81 |
} |
| 82 |
|
| 83 |
$url = add_query_arg( |
| 84 |
$video_options, |
| 85 |
$url_base |
| 86 |
); |
| 87 |
|
| 88 |
$output = sprintf( |
| 89 |
'<iframe src="%1$s" width="%2$d" height="%3$d" scrolling="no" style="border: 0 none transparent;"></iframe>', |
| 90 |
esc_url( $url ), |
| 91 |
absint( $atts['width'] ), |
| 92 |
absint( $atts['height'] ) |
| 93 |
); |
| 94 |
|
| 95 |
return $output; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Parse shortcode arguments and render output for ustream's Social Stream. |
| 100 |
* |
| 101 |
* @since 4.5.0 |
| 102 |
* |
| 103 |
* @param array $atts array of user-supplied arguments. |
| 104 |
* |
| 105 |
* @return string HTML output. |
| 106 |
*/ |
| 107 |
function ustreamsocial_shortcode( $atts ) { |
| 108 |
$defaults = array( |
| 109 |
'id' => 0, |
| 110 |
'height' => 420, |
| 111 |
'width' => 320, |
| 112 |
); |
| 113 |
$atts = array_map( 'intval', shortcode_atts( $defaults, $atts ) ); |
| 114 |
|
| 115 |
if ( 0 >= $atts['id'] ) { |
| 116 |
return '<!-- ustreamsocial error: bad social stream ID -->'; |
| 117 |
} |
| 118 |
|
| 119 |
if ( 0 >= $atts['height'] ) { |
| 120 |
return '<!-- ustreamsocial error: height invalid -->'; |
| 121 |
} |
| 122 |
|
| 123 |
if ( 0 >= $atts['width'] ) { |
| 124 |
return '<!-- ustreamsocial error: width invalid -->'; |
| 125 |
} |
| 126 |
|
| 127 |
$url = 'https://www.ustream.tv/socialstream/' . esc_attr( $atts['id'] ); |
| 128 |
|
| 129 |
return sprintf( |
| 130 |
'<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>', |
| 131 |
esc_url( $url ), |
| 132 |
absint( $atts['width'] ), |
| 133 |
absint( $atts['height'] ) |
| 134 |
); |
| 135 |
} |
| 136 |
|