Nessuna descrizione

ustream.php 3.1KB

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