<script> if (St === undefined) { var St = {}; } St.user_id = ' . $user->id . '; </script> '; ?> <table id="just_played"> <th>Artist</th> <th>Album</th> <th>Title</th> <th>Played</th> <?php $songs = $user->get_latest_songs(20); foreach ($songs as $song) { print "<tr>"; print "<td>" . htmlspecialchars($song->artist) . "</td>"; print "<td>" . htmlspecialchars($song->album) . "</td>"; print "<td>" . htmlspecialchars($song->title) . "</td>"; print "<td>" . htmlspecialchars($song->play->time_since) . "</td>"; print "</tr>"; } ?> </table> <br /> <?php print '<br/>';
require_once __DIR__ . '/src/model.User.php'; require_once __DIR__ . '/src/API.php'; header('Content-type: text/plain; charset=utf-8'); // a play was sent. if (isset($_POST['artist']) && isset($_POST['album']) && isset($_POST['title']) && isset($_POST['length']) && isset($_POST['pass']) && isset($_POST['user'])) { if (!API::add_user_play($_POST['user'], $_POST['pass'], $_POST['artist'], $_POST['album'], $_POST['title'], $_POST['length'])) { print "Error recording the play.\n"; print "api.php: Artist: " . $_POST['artist'] . " album: " . $_POST['album'] . " title: " . $_POST['title'] . " length " . $_POST['length'] . "\n"; exit; } print "Play recorded.\n"; exit; } // Last song played in plain text for script (for now playing) if (isset($_GET['last']) && isset($_GET['user'])) { $user = new User(); if ($user->query_by_name($_GET['user'])) { $lastSongPlay = $user->get_latest_songs(1); if (count($lastSongPlay) === 1) { $song = $lastSongPlay[0]; print $song->artist . " - " . $song->album . " - " . $song->title . " (" . $song->length . ")\n"; exit; } print "Error fetching song.\n"; exit; } print "Invalid user.\n"; exit; } // unknown api request. print "Unknown request.\n";