shortcode_handler_bandcamp

The Jetpack by WordPress.com shortcode handler bandcamp function.

Description

shortcode_handler_bandcamp( $atts ); 

Parameters (1)

0. $atts
The atts.

Usage

  1. if ( !function_exists( 'shortcode_handler_bandcamp' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/shortcodes/bandcamp.php'; 
  3.  
  4. // The atts. 
  5. $atts = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = shortcode_handler_bandcamp($atts); 
  9.  

Defined (1)

The function is defined in the following location(s).

/modules/shortcodes/bandcamp.php  
  1. function shortcode_handler_bandcamp( $atts ) { 
  2. // there are no default values, but specify here anyway 
  3. // to explicitly list supported atts 
  4. $attributes = shortcode_atts( array( 
  5. 'album' => null, // integer album id 
  6. 'track' => null, // integer track id 
  7. 'video' => null, // integer track id for video player 
  8. 'size' => 'venti', // one of the supported sizes 
  9. 'bgcol' => 'FFFFFF', // hex, no '#' prefix 
  10. 'linkcol' => null, // hex, no '#' prefix 
  11. 'layout' => null, // encoded layout url 
  12. 'width' => null, // integer with optional "%" 
  13. 'height' => null, // integer with optional "%" 
  14. 'notracklist' => null, // may be string "true" (defaults false) 
  15. 'tracklist' => null, // may be string "false" (defaults true) 
  16. 'artwork' => null, // may be string "false" (alternately: "none") or "small" (default is large) 
  17. 'minimal' => null, // may be string "true" (defaults false) 
  18. 'theme' => null, // may be theme identifier string ("light"|"dark" so far) 
  19. 'package' => null, // integer package id 
  20. 't' => null // integer track number 
  21. ), $atts, 'bandcamp' ); 
  22.  
  23. $sizes = array( 
  24. 'venti' => array( 'width' => 400, 'height' => 100 ),  
  25. 'grande' => array( 'width' => 300, 'height' => 100 ),  
  26. 'grande2' => array( 'width' => 300, 'height' => 355 ),  
  27. 'grande3' => array( 'width' => 300, 'height' => 415 ),  
  28. 'tall_album' => array( 'width' => 150, 'height' => 295 ),  
  29. 'tall_track' => array( 'width' => 150, 'height' => 270 ),  
  30. 'tall2' => array( 'width' => 150, 'height' => 450 ),  
  31. 'short' => array( 'width' => 46, 'height' => 23 ),  
  32. 'large' => array( 'width' => 350, 'height' => 470 ),  
  33. 'medium' => array( 'width' => 450, 'height' => 120 ),  
  34. 'small' => array( 'width' => 350, 'height' => 42 ) 
  35. ); 
  36.  
  37. $sizekey = $attributes['size']; 
  38. $height = null; 
  39. $width = null; 
  40.  
  41. $isVideo = false; 
  42.  
  43. // Build iframe url. For audio players, args are appended as 
  44. // extra path segments for historical reasons having to 
  45. // do with an IE-only flash bug which required this URL 
  46. // to contain no querystring. Delay the actual joining 
  47. // of args into a string until after we decide if it's 
  48. // a video player or an audio player 
  49. $argparts = array(); 
  50.  
  51. if ( !isset( $attributes['album'] ) && !isset( $attributes['track'] ) && !isset( $attributes['video'] ) ) { 
  52. return "[bandcamp: shortcode must include 'track', 'album', or 'video' param]"; 
  53.  
  54. if ( isset( $attributes['track'] ) ) { 
  55. $track = (int) $attributes['track']; 
  56. array_push( $argparts, "track={$track}" ); 
  57. } elseif ( isset( $attributes['video'] ) ) { 
  58. $track = (int) $attributes['video']; // videos are referenced by track id 
  59. $urlbase = "//bandcamp.com/EmbeddedPlayer/v=2"; 
  60. $isVideo = true; 
  61. array_push( $argparts, "track={$track}" ); 
  62. if ( isset( $attributes['album'] ) ) { 
  63. $album = (int) $attributes['album']; 
  64. array_push( $argparts, "album={$album}" ); 
  65.  
  66. if ( $sizekey == 'tall' ) { 
  67. if ( isset( $attributes['album'] ) ) { 
  68. $sizekey .= '_album'; 
  69. } else { 
  70. $sizekey .= '_track'; 
  71.  
  72. // if size specified that we don't recognize, fall back on venti 
  73. if ( empty( $sizes[$sizekey] ) ) { 
  74. $sizekey = 'venti'; 
  75. $attributes['size'] = 'venti'; 
  76.  
  77. // use strict regex for digits + optional % instead of absint for height/width 
  78. // 'width' and 'height' params in the iframe url get the exact string from the shortcode 
  79. // args, whereas the inline style attribute must have "px" added to it if it has no "%" 
  80. if ( isset( $attributes['width'] ) && preg_match( "|^([0-9]+)(%)?$|", $attributes['width'], $matches ) ) { 
  81. $width = $csswidth = $attributes['width']; 
  82. if ( sizeof( $matches ) < 3 ) { 
  83. $csswidth .= "px"; 
  84. if ( isset( $attributes['height'] ) && preg_match( "|^([0-9]+)(%)?$|", $attributes['height'], $matches ) ) { 
  85. $height = $cssheight = $attributes['height']; 
  86. if ( sizeof( $matches ) < 3 ) { 
  87. $cssheight .= "px"; 
  88.  
  89. if ( !$height ) { 
  90. $height = $sizes[$sizekey]['height']; 
  91. $cssheight = $height . "px"; 
  92.  
  93. if ( !$width ) { 
  94. $width = $sizes[$sizekey]['width']; 
  95. $csswidth = $width . "px"; 
  96.  
  97. if ( isset( $attributes['layout'] ) ) { 
  98. array_push( $argparts, "layout={$attributes['layout']}" ); 
  99. } elseif ( isset( $attributes['size'] ) && preg_match( "|^[a-zA-Z0-9]+$|", $attributes['size'] ) ) { 
  100. array_push( $argparts, "size={$attributes['size']}" ); 
  101.  
  102. if ( isset( $attributes['bgcol'] ) && preg_match( "|^[0-9A-Fa-f]+$|", $attributes['bgcol'] ) ) { 
  103. array_push( $argparts, "bgcol={$attributes['bgcol']}" ); 
  104.  
  105. if ( isset( $attributes['linkcol'] ) && preg_match( "|^[0-9A-Fa-f]+$|", $attributes['linkcol'] ) ) { 
  106. array_push( $argparts, "linkcol={$attributes['linkcol']}" ); 
  107.  
  108. if ( isset( $attributes['package'] ) && preg_match( "|^[0-9]+$|", $attributes['package'] ) ) { 
  109. array_push( $argparts, "package={$attributes['package']}" ); 
  110.  
  111. if ( isset( $attributes['t'] ) && preg_match( "|^[0-9]+$|", $attributes['t'] ) ) { 
  112. array_push( $argparts, "t={$attributes['t']}" ); 
  113.  
  114. if ( $attributes['notracklist'] == "true" ) { 
  115. array_push( $argparts, "notracklist=true" ); 
  116.  
  117. // 'tracklist' arg deprecates 'notracklist=true' to be less weird. note, behavior 
  118. // if both are specified is undefined 
  119. switch ( $attributes['tracklist'] ) { 
  120. case "false": 
  121. case "none": 
  122. array_push( $argparts, "tracklist=false" ); 
  123. break; 
  124.  
  125. switch ( $attributes['artwork'] ) { 
  126. case "false": 
  127. case "none": 
  128. case "small": 
  129. array_push( $argparts, "artwork=" . $attributes['artwork'] ); 
  130. break; 
  131.  
  132. if ( $attributes['minimal'] == "true" ) { 
  133. array_push( $argparts, "minimal=true" ); 
  134.  
  135. if ( isset( $attributes['theme'] ) && preg_match( "|^[a-zA-Z_]+$|", $attributes['theme'] ) ) { 
  136. array_push( $argparts, "theme={$attributes['theme']}" ); 
  137.  
  138. if ( $isVideo ) { 
  139. $url = "//bandcamp.com/VideoEmbed?" . join( '&', $argparts ); 
  140. $extraAttrs = " mozallowfullscreen='1' webkitallowfullscreen='1' allowfullscreen='1'"; 
  141. } else { 
  142. $url = "//bandcamp.com/EmbeddedPlayer/v=2/" . join( '/', $argparts ) . '/'; 
  143. $extraAttrs = ''; 
  144.  
  145. return "<iframe width='" . esc_attr( $width ) . "' height='" . esc_attr( $height ) . "' style='position: relative; display: block; width: " . esc_attr( $csswidth ) . "; height: " . esc_attr( $cssheight ) . ";' src='" . esc_url( $url ) . "' allowtransparency='true' frameborder='0'" . $extraAttrs . "></iframe>";