/
single-episode-template.php
113 lines (104 loc) · 4.08 KB
/
single-episode-template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* We're going to override the_content through a filter.
*/
function cap_podcast_player( $id = null, $player_type = 'default' ) {
if (empty($id)) {
$post_id = get_the_ID();
} else {
$post_id = $id;
}
$episode_number = get_post_meta( $post_id, 'episode_number', true );
// Get Episode Media Source
$episode_attachment_id = get_post_meta( $post_id, 'episode_file', true );
$episode_external_file = get_post_meta( $post_id, 'external_episode_file', true );
if (!empty($episode_attachment_id)) {
$player_src = wp_get_attachment_url( $episode_attachment_id );
} elseif (!empty($episode_external_file)) {
$player_src = $episode_external_file;
}
$attr = array(
'src' => ''.$player_src.'',
'loop' => '',
'autoplay' => '',
'preload' => 'metadata'
);
$player = wp_audio_shortcode( $attr );
$download_link = '<small><a href="'.$player_src.'" download="episode'.$episode_number.'.mp3">Download this Episode</a></small>';
// Get Episode Artwork //
$episode_artwork_id = get_post_thumbnail_id( $post_id );
$episode_artwork = wp_get_attachment_image_src( $episode_artwork_id, 'cap-podcast-thumbnail' );
$episode_artwork_src = $episode_artwork[0];
if ( 'default' == $player_type ) {
$episode_title = '
<div class="episode-info">
<h4>Episode #'.$episode_number.'</h4>
<h2>'.get_the_title($post_id).'</h2>
</div>
';
} elseif ( 'large' == $player_type ) {
$post_object = get_post($post_id);
$episode_title = '
<a href="'.get_permalink($post_id).'" class="episode-info">
<h4>Episode #'.$episode_number.'</h4>
<h2>'.get_the_title($post_id).'</h2>
<span class="description">'.wp_trim_words( $post_object->post_content , '60' ).'</span>
</a>
';
} elseif ( 'mini' == $player_type ) {
$episode_title = '';
}
// Construct Markup
$markup = '
<div class="episode-header">
<div class="episode-artwork-container">
<div class="episode-artwork" style="background-image: url('.$episode_artwork_src.');">
<div id="play-episode" class="maintain-ratio">
<span class="dashicons"></span>
</div>
</div>
</div>
'.$episode_title.'
</div>';
$script = "
<script type='text/javascript'>
var playerID = jQuery('#episode-".$episode_number."-".$post_id." audio').attr('id');
var player".$post_id." = document.getElementById(playerID);
jQuery('#episode-".$episode_number."-".$post_id." #play-episode').click(function(){
jQuery('#episode-".$episode_number."-".$post_id." #play-episode .dashicons').toggleClass('paused');
});
jQuery('#episode-".$episode_number."-".$post_id." #play-episode').click(function() {
if ( jQuery('#episode-".$episode_number."-".$post_id." #play-episode .dashicons').hasClass('paused') ) {
player".$post_id.".play();
}
if ( !jQuery('#episode-".$episode_number."-".$post_id." #play-episode .dashicons').hasClass('paused') ) {
player".$post_id.".pause();
}
});
</script>
";
if (function_exists('cap_podcast_player_colors')) {
$player .= cap_podcast_player_colors($post_id);
}
return '<div id="episode-'.$episode_number.'-'.$post_id.'" class="podcast-player '.$player_type.'">'.$markup.$player.$download_link.$script.'</div>';
}
function cap_podcast_single_display($content) {
if (is_singular('cap_podcast')) {
$player = cap_podcast_player();
$content = $player.$content;
}
return $content;
}
add_filter('the_content','cap_podcast_single_display');
function cap_podcast_player_waves_effect() {
if ( is_singular('cap_podcast') || is_post_type_archive('cap_podcast') ):
?>
<script type="text/javascript">
jQuery(document).ready(function(){
Waves.attach('#play-episode');
Waves.init();
});
</script>
<?php endif;
}
add_action('wp_footer','cap_podcast_player_waves_effect');