-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-playlist.php
116 lines (108 loc) · 4.61 KB
/
page-playlist.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
114
115
116
<?php
/**
* The template for displaying show pages.
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site may use a
* different template.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package xx
*/
get_header(); ?>
<?php
/*
permalink rewrite
playlist/41142 => playlist/?playlist=42141
*/
include(get_template_directory() . '/inc/SpinPapiConf.inc.php');
$sp = new SpinPapiClient($mySpUserID, $mySpSecret, $myStation, true, $papiVersion);
$sp->fcInit(get_template_directory() . '/.fc');
$playlist = get_query_var('playlist');
function isInteger($input) {
return(ctype_digit(strval($input)));
}
if (!isInteger($playlist)) {
status_header( 404 );
get_template_part( 404 ); exit();
} else if ($playlist) {
$playlistQ = $sp->query(array(
'method' => 'getPlaylistInfo',
'PlaylistID' => $playlist
));
if ($playlistQ['success'] && $playlistQ['results']) {
$playlist = $playlistQ['results'];
$songs = $sp->query(array(
'method' => 'getSongs',
'PlaylistID' => $playlist['PlaylistID']
))['results'];
} else {
status_header( 404 );
get_template_part( 404 ); exit();
}
} else {
status_header( 404 );
get_template_part( 404 ); exit();
}
function get_times($show) {
$weekday = DateTime::CreateFromFormat('D', $show['Weekdays'][0]);
$start = DateTime::CreateFromFormat('G:i:s', $show['OnairTime']);
$end = DateTime::CreateFromFormat('G:i:s', $show['OffairTime']);
return $weekday->format('l\s') . ' from ' . $start->format('ga') . '-' . $end->format('ga');
}
function timestamp($time) {
$time = DateTime::CreateFromFormat('G:i:s', $time);
return $time->format('g:ia');
}
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div class="container">
<article class="page playlist">
<div class="entry-content">
<div class="show">
<div class="row">
<div class="col-lg-3 offset-lg-3 col-md-12 info">
<span class="title"><a class="cya-styles" href="/show/<?php echo $playlist['ShowName']; ?>"><?php echo $playlist['ShowName']; ?></a></span>
<span class="playlist-date">Playlist on <?php echo $playlist['PlaylistDate']; ?></span>
<link rel="stylesheet" href="<?php echo get_template_directory_uri() . '/sass/plyr.css'; ?>" type="text/css" />
<audio controls src="/playlists/<?php echo $playlist['PlaylistID'] . '.mp3' ?>">
Your browser does not support the <code>audio</code> element.
</audio>
<script src="<?php echo get_template_directory_uri() . '/js/plyr.js'; ?>"></script>
<script>
var $ = $ ? $ : jQuery;
var audios = plyr.setup({
controls: ['play', 'progress', 'current-time', 'mute', 'volume']
});
audios.forEach(function (audio) {
audio.on('error', function(e) {
console.log(e);
audio.destroy();
$('audio').replaceWith('Error retrieving show.');
});
});
</script>
</div>
<div class="col-lg-6 col-md-12 other-info">
<ul class="songs">
<?php foreach($songs as $song): ?>
<li>
<span class="timestamp"><?php echo timestamp($song['Timestamp']); ?></span>
<span class="song"><?php echo $song['SongName']; ?></span>
<span class="artist"><?php echo $song['ArtistName']; ?></span>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
</div><!-- .entry-content -->
</article><!-- #post-## -->
</div>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();