ktk_mediaserve/modules/Playlist.php

79 lines
2.6 KiB
PHP

<?php
namespace ktk\MediaServe;
class Playlist {
const PATH_SHORT = 0;
const PATH_FULL = 1;
static public function onInit() {
if (!MediaServe::getData('playlist')) {
MediaServe::storeData('playlist', array());
MediaServe::storeData('path_detail', self::PATH_SHORT);
}
}
static public function onProcess() {
}
static public function onRender() {
$detail = MediaServe::getData('path_detail');
echo ' <div id="ktk_MediaServe_Playlist_Controls">',PHP_EOL;
echo ' <form action="" method="POST">';
echo ' <input type="hidden" name="m" value="Playlist" />';
echo ' <input type="hidden" name="c" value="changePathDetail" />';
echo ' <label for="p">Pathnames: </label>';
echo ' <button type="submit" name="p" value="',self::PATH_SHORT,'">Short</button>';
echo ' <button type="submit" name="p" value="',self::PATH_FULL,'">Full</button>';
echo ' </form>';
echo ' <form action="" method="POST">';
echo ' <input type="hidden" name="m" value="Playlist" />';
echo ' <button type="submit" name="c" value="clearPlaylist">Clear Playlist</button>';
echo ' </form>';
echo ' </div>',PHP_EOL;
echo ' <div id="ktk_MediaServe_Playlist">',PHP_EOL;
echo ' <form action="" method="POST">',PHP_EOL;
echo ' <input type="hidden" name="m" value="Playlist" />';
echo ' <input type="hidden" name="c" value="openFile" />';
echo ' <ul>';
if ($detail == self::PATH_FULL) {
foreach (MediaServe::getData('playlist') as $file) {
echo ' <li>';
echo '<button type="submit" name="p" value="',$file,'">',$file,'</button>';
echo ' </li>';
}
} else {
foreach (MediaServe::getData('playlist') as $file) {
echo ' <li>';
echo '<button type="submit" name="p" value="',$file,'">',basename($file),'</button>';
echo ' </li>';
}
}
echo ' </ul>',PHP_EOL;
echo ' </form>',PHP_EOL;
echo ' </div>',PHP_EOL;
}
static public function onClose() {
}
static public function addFile($file) {
array_push(MediaServe::getData('playlist'), $file);
}
static public function openFile($file) {
if (MediaServe::checkModule("Player")) {
Player::openFile($file);
}
}
static public function clearPlaylist() {
MediaServe::storeData('playlist', array());
}
static function changePathDetail($detail) {
if ($detail != self::PATH_SHORT && $detail != self::PATH_FULL) {
return NULL;
}
MediaServe::storeData('path_detail', $detail);
}
}
?>