';
}
if ( ! isset( $atts[0] ) ) {
if ( isset( $atts['src'] ) ) {
$atts[0] = $atts['src'];
unset( $atts['src'] );
} else {
return '';
}
}
$post_id = 0;
if ( isset( $post ) ) {
$post_id = $post->ID;
}
// add the special .js
wp_enqueue_script(
'audio-shortcode',
plugins_url( 'js/audio-shortcode.js', __FILE__ ),
array( 'jquery' ),
'1.1',
true);
// alert the infinite scroll renderer that it should try to load the script
self::$add_script = true;
$atts[0] = strip_tags( join( ' ', $atts ) );
$src = ltrim( $atts[0], '=' );
/**
* Set the audio player default colors.
*
* @module shortcodes
*
* @since 1.4.0
*
* @param array $ap_options {
* The default colors for the audio player in hexidecimal format (e.g. 0x#F8F8F8).
*
* @type string $bg Background color.
* @type string $leftbg Left background color.
* @type string $lefticon Left icon color.
* @type string $rightbg Right background color.
* @type string $rightbghover Right background hover color.
* @type string $righticon Right icon color.
* @type string $righticonhover Right icon hover color.
* @type string $text Text color.
* @type string $slider Slider color.
* @type string $track Track color.
* @type string $border Border color.
* @type string $loader Loader color.
*/
$ap_options = apply_filters(
'audio_player_default_colors',
array(
"bg" => "0xF8F8F8",
"leftbg" => "0xEEEEEE",
"lefticon" => "0x666666",
"rightbg" => "0xCCCCCC",
"rightbghover" => "0x999999",
"righticon" => "0x666666",
"righticonhover" => "0xFFFFFF",
"text" => "0x666666",
"slider" => "0x666666",
"track" => "0xFFFFFF",
"border" => "0x666666",
"loader" => "0x9FFFB8"
) );
if ( ! isset( $ap_playerID ) ) {
$ap_playerID = 1;
} else {
$ap_playerID++;
}
if ( ! isset( $load_audio_script ) ) {
$load_audio_script = true;
}
// prep the audio files
$src = trim( $src, ' "' );
$options = array();
$data = preg_split( "/\|/", $src );
$sound_file = $data[0];
$sound_files = explode( ',', $sound_file );
if ( is_ssl() ) {
for ( $i = 0; $i < count( $sound_files ); $i++ ) {
$sound_files[ $i ] = preg_replace( '#^http://([^.]+).files.wordpress.com/#', 'https://$1.files.wordpress.com/', $sound_files[ $i ] );
}
}
$sound_files = array_map( 'trim', $sound_files );
$sound_files = array_map( array( $this, 'rawurlencode_spaces' ), $sound_files );
$sound_files = array_map( 'esc_url_raw', $sound_files ); // Ensure each is a valid URL
$num_files = count( $sound_files );
$sound_types = array(
'mp3' => 'mpeg',
'wav' => 'wav',
'ogg' => 'ogg',
'oga' => 'ogg',
'm4a' => 'mp4',
'aac' => 'mp4',
'webm' => 'webm'
);
for ( $i = 1; $i < count( $data ); $i++ ) {
$pair = explode( "=", $data[$i] );
if ( strtolower( $pair[0] ) != 'autostart' ) {
$options[$pair[0]] = $pair[1];
}
}
// Merge runtime options to default colour options
// (runtime options overwrite default options)
foreach ( $ap_options as $key => $default ) {
if ( isset( $options[$key] ) ) {
if ( preg_match( '/^(0x)?[a-f0-9]{6}$/i', $default ) && !preg_match( '/^(0x)?[a-f0-9]{6}$/i', $options[$key] ) ) {
// Default is a hex color, but input is not
$options[$key] = $default;
}
} else {
$options[$key] = $default;
}
}
$options['soundFile'] = join( ',', $sound_files ); // Rebuild the option with our now sanitized data
$flash_vars = array();
foreach ( $options as $key => $value ) {
$flash_vars[] = rawurlencode( $key ) . '=' . rawurlencode( $value );
}
$flash_vars = implode( '&', $flash_vars );
$flash_vars = esc_attr( $flash_vars );
// extract some of the options to insert into the markup
if ( isset( $options['bgcolor'] ) && preg_match( '/^(0x)?[a-f0-9]{6}$/i', $options['bgcolor'] ) ) {
$bgcolor = preg_replace( '/^(0x)?/', '#', $options['bgcolor'] );
$bgcolor = esc_attr( $bgcolor );
} else {
$bgcolor = '#FFFFFF';
}
if ( isset( $options['width'] ) ) {
$width = intval( $options['width'] );
} else {
$width = 290;
}
$loop = '';
$script_loop = 'false';
if ( isset( $options['loop'] ) && 'yes' == $options['loop'] ) {
$script_loop = 'true';
if ( 1 == $num_files ) {
$loop = 'loop';
}
}
$volume = 0.6;
if ( isset( $options['initialvolume'] ) &&
0.0 < floatval( $options['initialvolume'] ) &&
100.0 >= floatval( $options['initialvolume'] ) ) {
$volume = floatval( $options['initialvolume'] )/100.0;
}
$file_artists = array_pad( array(), $num_files, '' );
if ( isset( $options['artists'] ) ) {
$artists = preg_split( '/,/', $options['artists'] );
foreach ( $artists as $i => $artist ) {
$file_artists[$i] = esc_html( $artist ) . ' - ';
}
}
// generate default titles
$file_titles = array();
for ( $i = 0; $i < $num_files; $i++ ) {
$file_titles[] = 'Track #' . ($i+1);
}
// replace with real titles if they exist
if ( isset( $options['titles'] ) ) {
$titles = preg_split( '/,/', $options['titles'] );
foreach ( $titles as $i => $title ) {
$file_titles[$i] = esc_html( $title );
}
}
// fallback for the fallback, just a download link
$not_supported = '';
foreach ( $sound_files as $sfile ) {
$not_supported .= sprintf(
__( 'Download: %s
', 'jetpack' ),
esc_url( $sfile ),
esc_html( basename( $sfile ) ) );
}
// HTML5 audio tag
$html5_audio = '';
$all_mp3 = true;
$add_audio = true;
$num_good = 0;
$to_remove = array();
foreach ( $sound_files as $i => $sfile ) {
$file_extension = pathinfo( $sfile, PATHINFO_EXTENSION );
if ( ! preg_match( '/^(mp3|wav|ogg|oga|m4a|aac|webm)$/i', $file_extension ) ) {
$html5_audio .= '';
if ( 1 == $num_files ) {
$html5_audio .= $not_supported;
}
$to_remove[] = $i; // make a note of the bad files
$all_mp3 = false;
continue;
} elseif ( ! preg_match( '/^mp3$/i', $file_extension ) ) {
$all_mp3 = false;
}
if ( 0 == $i ) { // only need one player
$html5_audio .= <<