Esempio n. 1
0
/**
 * Tracklist editor.
 *
 * @since 1.0.0
 */
function audiotheme_edit_record_tracklist()
{
    global $post;
    wp_enqueue_script('audiotheme-media');
    $tracks = get_audiotheme_record_tracks($post->ID);
    if ($tracks) {
        foreach ($tracks as $key => $track) {
            $tracks[$key] = array('key' => $key, 'id' => $track->ID, 'title' => esc_attr($track->post_title), 'artist' => esc_attr(get_post_meta($track->ID, '_audiotheme_artist', true)), 'fileUrl' => esc_attr(get_post_meta($track->ID, '_audiotheme_file_url', true)), 'downloadable' => is_audiotheme_track_downloadable($track->ID), 'purchaseUrl' => esc_url(get_post_meta($track->ID, '_audiotheme_purchase_url', true)));
        }
    }
    require AUDIOTHEME_DIR . 'modules/discography/admin/views/edit-record-tracklist.php';
}
Esempio n. 2
0
</h2>
				<ul class="audiotheme-record-links-list">
					<?php 
        foreach ($links as $link) {
            printf('<li class="audiotheme-record-links-item"><a href="%s" class="audiotheme-record-link"%s itemprop="url">%s</a></li>', $link['url'], false === strpos($link['url'], home_url()) ? ' target="_blank"' : '', $link['name']);
        }
        ?>
				</ul>
			</div><!-- /.record-links -->

		<?php 
    }
    ?>

		<?php 
    if ($tracks = get_audiotheme_record_tracks()) {
        ?>

			<div class="audiotheme-tracklist-section">
				<h2 class="audiotheme-tracklist-title audiotheme-label"><?php 
        _e('Track List', 'audiotheme');
        ?>
</h2>
				<ol class="audiotheme-tracklist">

					<?php 
        foreach ($tracks as $track) {
            ?>

						<li id="track-<?php 
            echo $track->ID;
 /**
  * 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;
 }
Esempio n. 4
0
/**
 * Convert enqueued track lists into an array of tracks prepared for JavaScript
 * and output the JSON-encoded object in the footer.
 *
 * @since 1.1.0
 */
function audiotheme_print_tracks_js()
{
    global $audiotheme_enqueued_tracks;
    if (empty($audiotheme_enqueued_tracks) || !is_array($audiotheme_enqueued_tracks)) {
        return;
    }
    $lists = array();
    // @todo The track & record ids should be collected at some point so they can all be fetched in a single query.
    foreach ($audiotheme_enqueued_tracks as $list => $tracks) {
        if (empty($tracks) || !is_array($tracks)) {
            continue;
        }
        do_action('audiotheme_prepare_tracks', $list);
        foreach ($tracks as $track) {
            if ('audiotheme_record' === get_post_type($track)) {
                $record_tracks = get_audiotheme_record_tracks($track, array('has_file' => true));
                if ($record_tracks) {
                    foreach ($record_tracks as $record_track) {
                        if ($track_data = audiotheme_prepare_track_for_js($record_track)) {
                            $lists[$list][] = $track_data;
                        }
                    }
                }
            } elseif ($track_data = audiotheme_prepare_track_for_js($track)) {
                $lists[$list][] = $track_data;
            }
        }
    }
    // Print a JavaScript object.
    if (!empty($lists)) {
        ?>
		<script type="text/javascript">
		/* <![CDATA[ */
		window.AudiothemeTracks = window.AudiothemeTracks || {};

		(function( window ) {
			var tracks = <?php 
        echo json_encode($lists);
        ?>
,
				i;

			for ( i in tracks ) {
				window.AudiothemeTracks[ i ] = tracks[ i ];
			}
		})( this );
		/* ]]> */
		</script>
		<?php 
    }
}