ustream.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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&#038;wmode=direct" width="480" height="296" scrolling="no" frameborder="0" style="border: 0 none transparent;"></iframe>
  11. */
  12. add_shortcode( 'ustream', 'ustream_shortcode' );
  13. add_shortcode( 'ustreamsocial', 'ustreamsocial_shortcode' );
  14. /**
  15. * Parse shortcode arguments and render output for ustream single video.
  16. *
  17. * @since 4.5.0
  18. *
  19. * @param $atts array of user-supplied arguments.
  20. *
  21. * @return string HTML output.
  22. */
  23. function ustream_shortcode( $atts ) {
  24. if ( isset( $atts[0] ) ) {
  25. return '<!-- ustream error: bad parameters -->';
  26. }
  27. $defaults = array(
  28. 'width' => 480,
  29. 'height' => 296,
  30. 'id' => 0,
  31. 'live' => 0,
  32. 'highlight' => 0,
  33. 'version' => 3,
  34. 'hwaccel' => 1,
  35. );
  36. $atts = array_map( 'intval', shortcode_atts( $defaults, $atts ) );
  37. $ustream_id = $atts['id'];
  38. $width = $atts['width'];
  39. $height = $atts['height'];
  40. $live = $atts['live'];
  41. $highlight = $atts['highlight'];
  42. $version = $atts['version'];
  43. $hwaccel = $atts['hwaccel'];
  44. $version = 'v=' . esc_attr( $version );
  45. if ( 0 >= $ustream_id ) {
  46. return '<!-- ustream error: bad video ID -->';
  47. }
  48. if ( 0 >= $height ) {
  49. return '<!-- ustream error: height invalid -->';
  50. }
  51. if ( 0 >= $width ) {
  52. return '<!-- ustream error: width invalid -->';
  53. }
  54. if ( $live ) {
  55. $recorded = '';
  56. } else {
  57. $recorded = 'recorded/';
  58. }
  59. if ( ! $live && ( 0 < $highlight ) ) {
  60. $highlight = "/highlight/$highlight";
  61. } else {
  62. $highlight = '';
  63. }
  64. if ( 0 < $hwaccel ) {
  65. $wmode = '&amp;wmode=direct';
  66. } else {
  67. $wmode = '';
  68. }
  69. $url = 'http://www.ustream.tv/embed/' . $recorded . esc_attr( $ustream_id ) . $highlight . '?' . $version . $wmode;
  70. $url = set_url_scheme( $url );
  71. $output = '<iframe src="' . esc_url( $url ) . '" width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '" scrolling="no" style="border: 0 none transparent;"></iframe>';
  72. return $output;
  73. }
  74. /**
  75. * Parse shortcode arguments and render output for ustream's Social Stream.
  76. *
  77. * @since 4.5.0
  78. *
  79. * @param $atts array of user-supplied arguments.
  80. *
  81. * @return string HTML output.
  82. */
  83. function ustreamsocial_shortcode( $atts ) {
  84. $defaults = array(
  85. 'id' => 0,
  86. 'height' => 420,
  87. 'width' => 320,
  88. );
  89. $atts = array_map( 'intval', shortcode_atts( $defaults, $atts ) );
  90. $ustream_id = $atts['id'];
  91. $width = $atts['width'];
  92. $height = $atts['height'];
  93. if ( 0 >= $ustream_id ) {
  94. return '<!-- ustreamsocial error: bad social stream ID -->';
  95. }
  96. if ( 0 >= $height ) {
  97. return '<!-- ustreamsocial error: height invalid -->';
  98. }
  99. if ( 0 >= $width ) {
  100. return '<!-- ustreamsocial error: width invalid -->';
  101. }
  102. $url = set_url_scheme( "http://www.ustream.tv/socialstream/$ustream_id" );
  103. return '<iframe id="SocialStream" class="" name="SocialStream" width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '" scrolling="no" allowtransparency="true" src="' . esc_url( $url ) . '" style="visibility: visible; margin-top: 0; margin-bottom: 0; border: 0;"></iframe>';
  104. }