Example #1
0
/**
 * 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;
}
Example #2
0
/**
 * Display custom track columns.
 *
 * @since 1.0.0
 *
 * @param string $column_id The id of the column to display.
 * @param int $post_id Post ID.
 */
function audiotheme_track_display_columns($column_name, $post_id)
{
    switch ($column_name) {
        case 'artist':
            echo get_post_meta($post_id, '_audiotheme_artist', true);
            break;
        case 'download':
            if (is_audiotheme_track_downloadable($post_id)) {
                echo '<img src="' . AUDIOTHEME_URI . 'admin/images/download.png" width="16" height="16">';
            }
            break;
        case 'file':
            $url = get_audiotheme_track_file_url($post_id);
            if ($url) {
                printf('<a href="%1$s" target="_blank">%2$s</a>', esc_url($url), '<img src="' . AUDIOTHEME_URI . 'admin/images/music-note.png" width="16" height="16">');
            }
            break;
        case 'purchase':
            $url = get_audiotheme_track_purchase_url($post_id);
            if ($url) {
                printf('<a href="%1$s" target="_blank"><img src="' . AUDIOTHEME_URI . 'admin/images/link.png" width="16" height="16"></a>', esc_url($url));
            }
            break;
        case 'record':
            $track = get_post($post_id);
            $record = get_post($track->post_parent);
            if ($record) {
                printf('<a href="%1$s">%2$s</a>', get_edit_post_link($record->ID), apply_filters('the_title', $record->post_title));
            }
            break;
    }
}
Example #3
0
/**
 * Add HTML attributes to a track element.
 *
 * @since 1.0.0
 *
 * @param int $track_id Optional. The track ID. Defaults to the current track in the loop.
 */
function huesos_track_attributes($track_id = 0)
{
    $track = get_post($track_id);
    $classes = 'track';
    if (get_audiotheme_track_file_url($track->ID)) {
        $classes .= ' is-playable js-play-record';
    }
    $attributes = array('class' => $classes, 'itemprop' => 'track', 'itemtype' => 'http://schema.org/MusicRecording', 'data-record-id' => absint($track->post_parent), 'data-track-id' => absint($track->ID));
    foreach ($attributes as $key => $value) {
        printf(' %1$s="%2$s"', $key, esc_attr($value));
    }
}
 /**
  * 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;
 }
Example #5
0
/**
 * Check if a track is downloadable.
 *
 * @since 1.0.0
 *
 * @param int $post_id Optional. Post ID.
 * @return string|bool File url if downloadable, else false.
 */
function is_audiotheme_track_downloadable($post_id = null)
{
    $post_id = null === $post_id ? get_the_ID() : $post_id;
    $is_downloadable = get_post_meta($post_id, '_audiotheme_is_downloadable', true);
    $return = false;
    if ($is_downloadable) {
        $file_url = get_audiotheme_track_file_url($post_id);
        if ($file_url) {
            $return = $file_url;
        }
    }
    return apply_filters('audiotheme_track_download_url', $return, $post_id);
}
Example #6
0
/**
 * 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;
}