Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod...
File: bandcamp.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Shortcode handler for [bandcamp], which inserts a bandcamp.com
[2] Fix | Delete
* music player (iframe, html5)
[3] Fix | Delete
*
[4] Fix | Delete
* [bandcamp album=119385304]
[5] Fix | Delete
* [bandcamp album=3462839126 bgcol=FFFFFF linkcol=4285BB size=venti]
[6] Fix | Delete
* [bandcamp track=2446959313]
[7] Fix | Delete
*
[8] Fix | Delete
* @package automattic/jetpack
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[12] Fix | Delete
exit( 0 );
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Display the Bandcamp shortcode.
[17] Fix | Delete
*
[18] Fix | Delete
* @param array $atts Shortcode attributes.
[19] Fix | Delete
*/
[20] Fix | Delete
function shortcode_handler_bandcamp( $atts ) {
[21] Fix | Delete
$csswidth = null;
[22] Fix | Delete
$cssheight = null;
[23] Fix | Delete
// there are no default values, but specify here anyway to explicitly list supported atts.
[24] Fix | Delete
$attributes = shortcode_atts(
[25] Fix | Delete
array(
[26] Fix | Delete
'album' => null, // integer album id.
[27] Fix | Delete
'track' => null, // integer track id.
[28] Fix | Delete
'video' => null, // integer track id for video player.
[29] Fix | Delete
'size' => 'venti', // one of the supported sizes.
[30] Fix | Delete
'bgcol' => 'FFFFFF', // hex, no '#' prefix.
[31] Fix | Delete
'linkcol' => null, // hex, no '#' prefix.
[32] Fix | Delete
'layout' => null, // encoded layout url.
[33] Fix | Delete
'width' => null, // integer with optional "%".
[34] Fix | Delete
'height' => null, // integer with optional "%".
[35] Fix | Delete
'notracklist' => null, // may be string "true" (defaults false).
[36] Fix | Delete
'tracklist' => null, // may be string "false" (defaults true).
[37] Fix | Delete
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- false positive
[38] Fix | Delete
'artwork' => null, // may be string "false" (alternately: "none") or "small" (default is large).
[39] Fix | Delete
'minimal' => null, // may be string "true" (defaults false).
[40] Fix | Delete
'theme' => null, // may be theme identifier string ("light"|"dark" so far).
[41] Fix | Delete
'package' => null, // integer package id.
[42] Fix | Delete
't' => null, // integer track number.
[43] Fix | Delete
'tracks' => null, // comma-separated list of allowed tracks.
[44] Fix | Delete
'esig' => null, // hex, no '#' prefix.
[45] Fix | Delete
),
[46] Fix | Delete
$atts,
[47] Fix | Delete
'bandcamp'
[48] Fix | Delete
);
[49] Fix | Delete
[50] Fix | Delete
$sizes = array(
[51] Fix | Delete
'venti' => array(
[52] Fix | Delete
'width' => 400,
[53] Fix | Delete
'height' => 100,
[54] Fix | Delete
),
[55] Fix | Delete
'grande' => array(
[56] Fix | Delete
'width' => 300,
[57] Fix | Delete
'height' => 100,
[58] Fix | Delete
),
[59] Fix | Delete
'grande2' => array(
[60] Fix | Delete
'width' => 300,
[61] Fix | Delete
'height' => 355,
[62] Fix | Delete
),
[63] Fix | Delete
'grande3' => array(
[64] Fix | Delete
'width' => 300,
[65] Fix | Delete
'height' => 415,
[66] Fix | Delete
),
[67] Fix | Delete
'tall_album' => array(
[68] Fix | Delete
'width' => 150,
[69] Fix | Delete
'height' => 295,
[70] Fix | Delete
),
[71] Fix | Delete
'tall_track' => array(
[72] Fix | Delete
'width' => 150,
[73] Fix | Delete
'height' => 270,
[74] Fix | Delete
),
[75] Fix | Delete
'tall2' => array(
[76] Fix | Delete
'width' => 150,
[77] Fix | Delete
'height' => 450,
[78] Fix | Delete
),
[79] Fix | Delete
'short' => array(
[80] Fix | Delete
'width' => 46,
[81] Fix | Delete
'height' => 23,
[82] Fix | Delete
),
[83] Fix | Delete
'large' => array(
[84] Fix | Delete
'width' => 350,
[85] Fix | Delete
'height' => 470,
[86] Fix | Delete
),
[87] Fix | Delete
'medium' => array(
[88] Fix | Delete
'width' => 450,
[89] Fix | Delete
'height' => 120,
[90] Fix | Delete
),
[91] Fix | Delete
'small' => array(
[92] Fix | Delete
'width' => 350,
[93] Fix | Delete
'height' => 42,
[94] Fix | Delete
),
[95] Fix | Delete
);
[96] Fix | Delete
[97] Fix | Delete
$sizekey = $attributes['size'];
[98] Fix | Delete
$height = null;
[99] Fix | Delete
$width = null;
[100] Fix | Delete
[101] Fix | Delete
$is_video = false;
[102] Fix | Delete
[103] Fix | Delete
/*
[104] Fix | Delete
* Build iframe url. For audio players, args are appended as
[105] Fix | Delete
* extra path segments for historical reasons having to
[106] Fix | Delete
* do with an IE-only flash bug which required this URL
[107] Fix | Delete
* to contain no querystring. Delay the actual joining
[108] Fix | Delete
* of args into a string until after we decide if it's
[109] Fix | Delete
* a video player or an audio player
[110] Fix | Delete
*/
[111] Fix | Delete
$argparts = array();
[112] Fix | Delete
[113] Fix | Delete
if ( ! isset( $attributes['album'] ) && ! isset( $attributes['track'] ) && ! isset( $attributes['video'] ) ) {
[114] Fix | Delete
return "[bandcamp: shortcode must include 'track', 'album', or 'video' param]";
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
if ( isset( $attributes['track'] ) && is_numeric( $attributes['track'] ) ) {
[118] Fix | Delete
$track = esc_attr( $attributes['track'] );
[119] Fix | Delete
array_push( $argparts, "track={$track}" );
[120] Fix | Delete
} elseif ( isset( $attributes['video'] ) && is_numeric( $attributes['video'] ) ) {
[121] Fix | Delete
$track = esc_attr( $attributes['video'] ); // videos are referenced by track id.
[122] Fix | Delete
$url = '//bandcamp.com/EmbeddedPlayer/v=2';
[123] Fix | Delete
$is_video = true;
[124] Fix | Delete
array_push( $argparts, "track={$track}" );
[125] Fix | Delete
}
[126] Fix | Delete
if ( isset( $attributes['album'] ) && is_numeric( $attributes['album'] ) ) {
[127] Fix | Delete
$album = esc_attr( $attributes['album'] );
[128] Fix | Delete
array_push( $argparts, "album={$album}" );
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
if ( 'tall' === $sizekey ) {
[132] Fix | Delete
if ( isset( $attributes['album'] ) ) {
[133] Fix | Delete
$sizekey .= '_album';
[134] Fix | Delete
} else {
[135] Fix | Delete
$sizekey .= '_track';
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
// if size specified that we don't recognize, fall back on venti.
[140] Fix | Delete
if ( empty( $sizes[ $sizekey ] ) ) {
[141] Fix | Delete
$sizekey = 'venti';
[142] Fix | Delete
$attributes['size'] = 'venti';
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
/*
[146] Fix | Delete
* use strict regex for digits + optional % instead of absint for height/width
[147] Fix | Delete
* 'width' and 'height' params in the iframe url get the exact string from the shortcode
[148] Fix | Delete
* args, whereas the inline style attribute must have "px" added to it if it has no "%"
[149] Fix | Delete
*/
[150] Fix | Delete
if ( isset( $attributes['width'] ) && preg_match( '|^([0-9]+)(%)?$|', $attributes['width'], $matches ) ) {
[151] Fix | Delete
$width = $attributes['width'];
[152] Fix | Delete
$csswidth = $attributes['width'];
[153] Fix | Delete
if ( count( $matches ) < 3 ) {
[154] Fix | Delete
$csswidth .= 'px';
[155] Fix | Delete
}
[156] Fix | Delete
}
[157] Fix | Delete
if ( isset( $attributes['height'] ) && preg_match( '|^([0-9]+)(%)?$|', $attributes['height'], $matches ) ) {
[158] Fix | Delete
$height = $attributes['height'];
[159] Fix | Delete
$cssheight = $attributes['height'];
[160] Fix | Delete
if ( count( $matches ) < 3 ) {
[161] Fix | Delete
$cssheight .= 'px';
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
if ( ! $height ) {
[166] Fix | Delete
$height = $sizes[ $sizekey ]['height'];
[167] Fix | Delete
$cssheight = $height . 'px';
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
if ( ! $width ) {
[171] Fix | Delete
$width = $sizes[ $sizekey ]['width'];
[172] Fix | Delete
$csswidth = $width . 'px';
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
if ( isset( $attributes['layout'] ) ) {
[176] Fix | Delete
array_push( $argparts, "layout={$attributes['layout']}" );
[177] Fix | Delete
} elseif ( isset( $attributes['size'] ) && preg_match( '|^[a-zA-Z0-9]+$|', $attributes['size'] ) ) {
[178] Fix | Delete
array_push( $argparts, "size={$attributes['size']}" );
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
if ( isset( $attributes['bgcol'] ) && preg_match( '|^[0-9A-Fa-f]+$|', $attributes['bgcol'] ) ) {
[182] Fix | Delete
array_push( $argparts, "bgcol={$attributes['bgcol']}" );
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
if ( isset( $attributes['linkcol'] ) && preg_match( '|^[0-9A-Fa-f]+$|', $attributes['linkcol'] ) ) {
[186] Fix | Delete
array_push( $argparts, "linkcol={$attributes['linkcol']}" );
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
if ( isset( $attributes['package'] ) && preg_match( '|^[0-9]+$|', $attributes['package'] ) ) {
[190] Fix | Delete
array_push( $argparts, "package={$attributes['package']}" );
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
if ( isset( $attributes['t'] ) && preg_match( '|^[0-9]+$|', $attributes['t'] ) ) {
[194] Fix | Delete
array_push( $argparts, "t={$attributes['t']}" );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
if ( 'true' === $attributes['notracklist'] ) {
[198] Fix | Delete
array_push( $argparts, 'notracklist=true' );
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
// 'tracklist' arg deprecates 'notracklist=true' to be less weird. note, behavior
[202] Fix | Delete
// if both are specified is undefined
[203] Fix | Delete
switch ( $attributes['tracklist'] ) {
[204] Fix | Delete
case 'false':
[205] Fix | Delete
case 'none':
[206] Fix | Delete
array_push( $argparts, 'tracklist=false' );
[207] Fix | Delete
break;
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
switch ( $attributes['artwork'] ) {
[211] Fix | Delete
case 'false':
[212] Fix | Delete
case 'none':
[213] Fix | Delete
case 'small':
[214] Fix | Delete
array_push( $argparts, 'artwork=' . $attributes['artwork'] );
[215] Fix | Delete
break;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
if ( 'true' === $attributes['minimal'] ) {
[219] Fix | Delete
array_push( $argparts, 'minimal=true' );
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
if ( isset( $attributes['theme'] ) && preg_match( '|^[a-zA-Z_]+$|', $attributes['theme'] ) ) {
[223] Fix | Delete
array_push( $argparts, "theme={$attributes['theme']}" );
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
// param 'tracks' is signed digest param 'esig'.
[227] Fix | Delete
if ( isset( $attributes['tracks'] ) && preg_match( '|^[0-9\,]+$|', $attributes['tracks'] ) ) {
[228] Fix | Delete
if ( isset( $attributes['esig'] ) && preg_match( '|^[0-9A-Fa-f]+$|', $attributes['esig'] ) ) {
[229] Fix | Delete
array_push( $argparts, "tracks={$attributes['tracks']}" );
[230] Fix | Delete
array_push( $argparts, "esig={$attributes['esig']}" );
[231] Fix | Delete
}
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
if ( $is_video ) {
[235] Fix | Delete
$url = '//bandcamp.com/VideoEmbed?' . implode( '&', $argparts );
[236] Fix | Delete
$extra_attrs = " mozallowfullscreen='1' webkitallowfullscreen='1' allowfullscreen='1'";
[237] Fix | Delete
} else {
[238] Fix | Delete
$url = '//bandcamp.com/EmbeddedPlayer/v=2/' . implode( '/', $argparts ) . '/';
[239] Fix | Delete
$extra_attrs = '';
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
$iframe = '<iframe width="%s" height="%s" style="position: relative; display: block; width: %s; height: %s;" src="%s" allowtransparency="true" frameborder="0"%s></iframe>';
[243] Fix | Delete
$iframe = sprintf( $iframe, esc_attr( $width ), esc_attr( $height ), esc_attr( $csswidth ), esc_attr( $cssheight ), esc_url( $url ), $extra_attrs );
[244] Fix | Delete
[245] Fix | Delete
return $iframe;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
add_shortcode( 'bandcamp', 'shortcode_handler_bandcamp' );
[249] Fix | Delete
[250] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function