/modules/shortcodes/twitchtv.php

  1. <?php 
  2. /** 
  3. * twitch.tv shortcode 
  4. * [twitchtv url='http://www.twitch.tv/paperbat' height='378' width='620' autoplay='false'] 
  5. * [twitchtv url='http://www.twitch.tv/paperbat/b/323486192' height='378' width='620' autoplay='false'] 
  6. **/ 
  7.  
  8. /** 
  9. * Flash: 
  10. (Live URL) http://www.twitch.tv/paperbat 
  11.   
  12. Video: 
  13. <object type="application/x-shockwave-flash" height="378" width="620" id="live_embed_player_flash" data="//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?channel=paperbat" bgcolor="#000000"> 
  14. <param name="allowFullScreen" value="true" /> 
  15. <param name="allowScriptAccess" value="always" /> 
  16. <param name="allowNetworking" value="all" /> 
  17. <param name="movie" value="//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf" /> 
  18. <param name="flashvars" value="hostname=www.twitch.tv&channel=paperbat&auto_play=true&start_volume=25" /> 
  19. </object> 
  20.   
  21. (Archive URL) http://www.twitch.tv/paperbat/v/323486192 
  22.   
  23. <object bgcolor='#000000' data='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf' height='378' id='clip_embed_player_flash' type='application/x-shockwave-flash' width='620'> 
  24. <param name='movie' value='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf'> 
  25. <param name='allowScriptAccess' value='always'> 
  26. <param name='allowNetworking' value='all'> 
  27. <param name='allowFullScreen' value='true'> 
  28. <param name='flashvars' value='videoId=v323486192&hostname=www.twitch.tv&channel=paperbat&auto_play=false&title=PBat+Live+-+Playin%27+for+funnnnn+%287%2F1%2F2012%29&start_volume=25'> 
  29. </object> 
  30. */ 
  31. function wpcom_twitchtv_shortcode( $attr, $content = NULL ) { 
  32. $attr = extract( shortcode_atts( array( 
  33. 'height' => 378,  
  34. 'width' => 620,  
  35. 'url' => '',  
  36. 'autoplay' => false 
  37. ), $attr ) ); 
  38.  
  39. if ( empty( $url ) ) 
  40. return; 
  41.  
  42. preg_match( '|^http://www.twitch.tv/([^/?]+)(/v/(\d+))?|i', $url, $match ); 
  43.  
  44. $width = (int) $width; 
  45. $height = (int) $height; 
  46. $autoplay = var_export( filter_var( $autoplay, FILTER_VALIDATE_BOOLEAN ), true ); 
  47.  
  48. $user_id = esc_attr( $match[1] ); 
  49. $video_id = 0; 
  50. if ( !empty( $match[3] ) ) 
  51. $video_id = (int) $match[3]; 
  52.  
  53. /** This action is documented in modules/widgets/social-media-icons.php */ 
  54. do_action( 'jetpack_bump_stats_extras', 'twitchtv', 'shortcode' ); 
  55.  
  56. if ( $video_id > 0 ) { 
  57. // Archive video 
  58. return "<object bgcolor='#000000' data='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf' height='$height' width='$width' id='clip_embed_player_flash' type='application/x-shockwave-flash'> 
  59. <param name='movie' value='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf'> 
  60. <param name='allowScriptAccess' value='always'> 
  61. <param name='allowNetworking' value='all'> 
  62. <param name='allowFullScreen' value='true'> 
  63. <param name='flashvars' value='videoId=v$video_id&hostname=www.twitch.tv&channel=$user_id&auto_play=$autoplay'> 
  64. </object>"; 
  65.  
  66. $html = "<object type='application/x-shockwave-flash' height='$height' width='$width' id='live_embed_player_flash' data='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?channel=$user_id' bgcolor='#000000'> 
  67. <param name='allowFullScreen' value='true' /> 
  68. <param name='allowScriptAccess' value='always' /> 
  69. <param name='allowNetworking' value='all' /> 
  70. <param name='movie' value='//www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf' /> 
  71. <param name='flashvars' value='hostname=www.twitch.tv&channel=$user_id&auto_play=$autoplay&start_volume=25' /> 
  72. </object>"; 
  73.  
  74. return $html; 
  75.  
  76. add_shortcode( 'twitch', 'wpcom_twitchtv_shortcode' ); 
  77. add_shortcode( 'twitchtv', 'wpcom_twitchtv_shortcode' ); 
.