/** * Convert a track into the format expected by the Cue plugin. * * @since 1.5.0 * * @param int|WP_Post $post Post object or ID. * @return object Track object expected by Cue. */ function get_audiotheme_playlist_track($post = 0) { $post = get_post($post); $track = new stdClass(); $track->id = $post->ID; $track->artist = get_audiotheme_track_artist($post->ID); $track->audioUrl = get_audiotheme_track_file_url($post->ID); $track->title = get_the_title($post->ID); if ($thumbnail_id = get_audiotheme_track_thumbnail_id($post->ID)) { $size = apply_filters('cue_artwork_size', array(300, 300)); $image = image_downsize($thumbnail_id, $size); $track->artworkUrl = $image[0]; } return $track; }
<?php while (have_posts()) { the_post(); ?> <article id="post-<?php the_ID(); ?> " <?php post_class('audiotheme-record-single audiotheme-track-single'); ?> itemscope itemtype="http://schema.org/MusicRecording" role="article"> <?php if ($thumbnail_id = get_audiotheme_track_thumbnail_id()) { ?> <p class="audiotheme-record-artwork"> <a href="<?php echo esc_url(wp_get_attachment_url($thumbnail_id)); ?> " itemprop="image"> <?php echo wp_get_attachment_image($thumbnail_id, 'record-thumbnail'); ?> </a> </p> <?php }
/** * Transform a track id or array of data into the expected format for use as a * JavaScript object. * * @since 1.1.0 * * @param int|array $track Track ID or array of expected track properties. * @return array */ function audiotheme_prepare_track_for_js($track) { $data = array('artist' => '', 'artwork' => '', 'mp3' => '', 'record' => '', 'title' => ''); // Enqueue a track post type. if ('audiotheme_track' === get_post_type($track)) { $track = get_post($track); $record = get_post($track->post_parent); $data['artist'] = get_audiotheme_track_artist($track->ID); $data['mp3'] = get_audiotheme_track_file_url($track->ID); $data['record'] = $record->post_title; $data['title'] = $track->post_title; // WP playlist format. $data['format'] = 'mp3'; $data['meta']['artist'] = $data['artist']; $data['meta']['length_formatted'] = '0:00'; $data['src'] = $data['mp3']; if ($thumbnail_id = get_audiotheme_track_thumbnail_id($track)) { $image = wp_get_attachment_image_src($thumbnail_id, apply_filters('audiotheme_track_js_artwork_size', 'thumbnail')); $data['artwork'] = $image[0]; } } elseif (is_array($track)) { if (isset($track['artwork'])) { $data['artwork'] = esc_url($track['artwork']); } if (isset($track['file'])) { $data['mp3'] = esc_url_raw(audiotheme_encode_url_path($track['file'])); } if (isset($track['mp3'])) { $data['mp3'] = esc_url_raw(audiotheme_encode_url_path($track['mp3'])); } if (isset($track['title'])) { $data['title'] = wp_strip_all_tags($track['title']); } $data = array_merge($track, $data); } $data = apply_filters('audiotheme_track_js_data', $data, $track); return $data; }
/** * Retrieve data about a record's tracks. * * @since 1.0.0 * * @param int $record_id Record post ID. * @return array */ protected function get_track_data($record_id) { $tracks = array(); $posts = get_audiotheme_record_tracks($record_id, array('has_file' => true)); if (empty($posts)) { return $tracks; } foreach ($posts as $track) { $data = array(); $track = get_post($track); $record = get_post($track->post_parent); $data['track_id'] = $track->ID; $data['title'] = $track->post_title; $data['artist'] = get_audiotheme_track_artist($track->ID); $data['album'] = $record->post_title; $data['src'] = get_audiotheme_track_file_url($track->ID); $data['length'] = get_audiotheme_track_length($track->ID); if ($thumbnail_id = get_audiotheme_track_thumbnail_id($track)) { $image = wp_get_attachment_image_src($thumbnail_id, 'thumbnail'); $data['artwork'] = $image[0]; } $data['id'] = md5($data['artist'] . $data['title'] . $data['src']); $data['recordId'] = $record->ID; $data['trackId'] = $track->ID; $tracks[] = $data; } return $tracks; }
<?php /** * Template to display a Track widget. * * @package Huesos * @since 1.0.0 */ ?> <?php if ($thumbnail_id = get_audiotheme_track_thumbnail_id($post->ID)) { ?> <figure class="featured-image"> <a class="post-thumbnail" href="<?php echo esc_url(get_permalink($post->ID)); ?> "> <?php echo wp_get_attachment_image($thumbnail_id, $image_size); ?> </a> </figure> <?php } ?> <?php if (!empty($title)) { printf(' <a href="%s">%s</a>', esc_url(get_permalink($post->ID)), $before_title . $title . $after_title); }