Skip to content

Commit

Permalink
Repair playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
mrilyew committed Dec 1, 2024
1 parent 5bc306e commit 187250b
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 303 deletions.
56 changes: 24 additions & 32 deletions Web/Presenters/AudioPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,15 @@ function renderNewPlaylist(): void
$this->template->club = $club;
}

$this->template->owner = $owner;

if ($_SERVER["REQUEST_METHOD"] === "POST") {
$title = $this->postParam("title");
$description = $this->postParam("description");
$is_unlisted = (int)$this->postParam('is_unlisted');

$audios = !empty($this->postParam("audios")) ? array_slice(explode(",", $this->postParam("audios")), 0, 1000) : [];
$is_ajax = (int)$this->postParam('ajax') == 1;
$audios = array_slice(explode(",", $this->postParam("audios")), 0, 1000);

if(empty($title) || iconv_strlen($title) < 1)
$this->flashFail("err", tr("error"), tr("set_playlist_name"));
$this->flashFail("err", tr("error"), tr("set_playlist_name"), NULL, $is_ajax);

$playlist = new Playlist;
$playlist->setOwner($owner);
Expand All @@ -364,38 +362,35 @@ function renderNewPlaylist(): void

if($_FILES["cover"]["error"] === UPLOAD_ERR_OK) {
if(!str_starts_with($_FILES["cover"]["type"], "image"))
$this->flashFail("err", tr("error"), tr("not_a_photo"));
$this->flashFail("err", tr("error"), tr("not_a_photo"), NULL, $is_ajax);

try {
$playlist->fastMakeCover($this->user->id, $_FILES["cover"]);
} catch(\Throwable $e) {
$this->flashFail("err", tr("error"), tr("invalid_cover_photo"));
$this->flashFail("err", tr("error"), tr("invalid_cover_photo"), NULL, $is_ajax);
}
}

$playlist->save();

foreach($audios as $audio) {
$audio = $this->audios->get((int)$audio);

if(!$audio || $audio->isDeleted() || !$audio->canBeViewedBy($this->user->identity))
if(!$audio || $audio->isDeleted())
continue;

$playlist->add($audio);
}

$playlist->bookmark(isset($club) ? $club : $this->user->identity);
if($is_ajax) {
$this->returnJson([
'success' => true,
'redirect' => '/playlist' . $owner . "_" . $playlist->getId()
]);
}
$this->redirect("/playlist" . $owner . "_" . $playlist->getId());
} else {
if(isset($club)) {
$this->template->audios = iterator_to_array($this->audios->getByClub($club, 1, 10));
$count = (new Audios)->getClubCollectionSize($club);
} else {
$this->template->audios = iterator_to_array($this->audios->getByUser($this->user->identity, 1, 10));
$count = (new Audios)->getUserCollectionSize($this->user->identity);
}

$this->template->pagesCount = ceil($count / 10);
$this->template->owner = $owner;
}
}

Expand Down Expand Up @@ -451,28 +446,20 @@ function renderEditPlaylist(int $owner_id, int $virtual_id)
$this->willExecuteWriteAction();

$playlist = $this->audios->getPlaylistByOwnerAndVID($owner_id, $virtual_id);
$page = (int)($this->queryParam("p") ?? 1);
if (!$playlist || $playlist->isDeleted() || !$playlist->canBeModifiedBy($this->user->identity))
$this->notFound();

$this->template->playlist = $playlist;
$this->template->page = $page;

$audios = iterator_to_array($playlist->fetch(1, $playlist->size()));
$this->template->audios = array_slice($audios, 0, 10);
$audiosIds = [];

foreach($audios as $aud)
$audiosIds[] = $aud->getId();

$this->template->audiosIds = implode(",", array_unique($audiosIds)) . ",";
$this->template->audios = array_slice($audios, 0, 1000);
$this->template->ownerId = $owner_id;
$this->template->owner = $playlist->getOwner();
$this->template->pagesCount = $pagesCount = ceil($playlist->size() / 10);

if($_SERVER["REQUEST_METHOD"] !== "POST")
return;

$is_ajax = (int)$this->postParam('ajax') == 1;
$title = $this->postParam("title");
$description = $this->postParam("description");
$is_unlisted = (int)$this->postParam('is_unlisted');
Expand All @@ -487,12 +474,12 @@ function renderEditPlaylist(int $owner_id, int $virtual_id)
$playlist->resetLength();
$playlist->setUnlisted((bool)$is_unlisted);

if($_FILES["new_cover"]["error"] === UPLOAD_ERR_OK) {
if(!str_starts_with($_FILES["new_cover"]["type"], "image"))
if($_FILES["cover"]["error"] === UPLOAD_ERR_OK) {
if(!str_starts_with($_FILES["cover"]["type"], "image"))
$this->flashFail("err", tr("error"), tr("not_a_photo"));

try {
$playlist->fastMakeCover($this->user->id, $_FILES["new_cover"]);
$playlist->fastMakeCover($this->user->id, $_FILES["cover"]);
} catch(\Throwable $e) {
$this->flashFail("err", tr("error"), tr("invalid_cover_photo"));
}
Expand All @@ -506,13 +493,18 @@ function renderEditPlaylist(int $owner_id, int $virtual_id)

foreach ($new_audios as $new_audio) {
$audio = (new Audios)->get((int)$new_audio);

if(!$audio || $audio->isDeleted())
continue;

$playlist->add($audio);
}

if($is_ajax) {
$this->returnJson([
'success' => true,
'redirect' => '/playlist' . $playlist->getPrettyId()
]);
}
$this->redirect("/playlist".$playlist->getPrettyId());
}

Expand Down
77 changes: 30 additions & 47 deletions Web/Presenters/templates/Audio/EditPlaylist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,44 @@
{/block}

{block content}
<div class="playlistBlock" style="display: flex;margin-top: 0px;">
<div class="playlistCover">
<a>
<img src="{$playlist->getCoverURL('normal')}" alt="{_playlist_cover}">
</a>

<div class="profile_links" style="width: 139px;">
<a class="profile_link" style="width: 98%;" id="_deletePlaylist" data-id="{$playlist->getId()}">{_delete_playlist}</a>
</div>
</div>

<div style="padding-left: 13px;width:75%">
<div class="playlistInfo">
<input value="{$playlist->getName()}" type="text" name="title" maxlength="125">
<div class='PE_wrapper'>
<div class='PE_playlistEditPage'>
<div class="playlistCover">
<a onclick="document.querySelector(`input[name='cover']`).click()">
<input type='file' name='cover' style='display:none;' accept=".jpg,.png">
<img src="{$playlist->getCoverURL('normal')}" alt="{_playlist_cover}">
</a>
<div class="profile_links" style="width: 139px;">
<a class="profile_link" style="width: 98%;" id="_deletePlaylist" data-id="{$playlist->getId()}">{_delete_playlist}</a>
</div>
</div>

<div class="moreInfo">
<textarea placeholder="{_description}" name="description" maxlength="2045" style="margin-top: 11px;">{$playlist->getDescription()}</textarea>
<div class="PE_playlistInfo">
<div>
<input value='{$playlist->getName()}' type="text" name="title" placeholder="{_title}" maxlength="125" />
</div>
<div class="moreInfo">
<textarea placeholder="{_description}" name="description" maxlength="2045">{$playlist->getDescription()}</textarea>
</div>
<label>
<input type='checkbox' name='is_unlisted' value='1' n:attr='checked => $playlist->isUnlisted()'>
{_playlist_hide_from_search}
</label>
<a id='_playlistAppendTracks'>{_add_audio_verb}</a>
</div>

<label>
<input type='checkbox' name='is_unlisted' n:attr='checked => $playlist->isUnlisted()'>
{_playlist_hide_from_search}
</label>
</div>
</div>

<div style="margin-top: 19px;">
<input id="playlist_query" type="text" style="height: 26px;" placeholder="{_header_search}">
<div class="playlistAudiosContainer editContainer">
<div id="newPlaylistAudios" n:foreach="$audios as $audio">
<div class="playerContainer">
{include "player.xml", audio => $audio, hideButtons => true}
<div class='PE_audios generic_audio_list'>
<div n:foreach='$audios as $audio' class='vertical-attachment upload-item' data-id='{$audio->getId()}'>
<div class='vertical-attachment-content'>
{include 'player.xml', audio => $audio, hideButtons => true}
</div>
<div class="attachAudio addToPlaylist" data-id="{$audio->getId()}">
<span>{_remove_from_playlist}</span>
<div class="vertical-attachment-remove">
<div id="small_remove_button"></div>
</div>
</div>
</div>

<div class="showMoreAudiosPlaylist" data-page="2" data-playlist="{$playlist->getId()}" n:if="$pagesCount > 1">
{_show_more_audios}
<div class='PE_end'>
<input class="button" type="button" id='playlist_edit' value="{_save}">
</div>
</div>

<form method="post" id="editPlaylistForm" data-id="{$playlist->getId()}" enctype="multipart/form-data">
<input type="hidden" name="title" maxlength="128" />
<input type="hidden" name="hash" value="{$csrfToken}" />
<input type="hidden" name="is_unlisted" value="0" />
<textarea style="display:none;" name="description" maxlength="2048" />
<input type="hidden" name="audios">
<input type="file" style="display:none;" name="new_cover" accept=".jpg,.png">

<div style="float:right;margin-top: 8px;">
<button class="button" type="submit">{_save}</button>
</div>
</form>
{/block}
64 changes: 24 additions & 40 deletions Web/Presenters/templates/Audio/NewPlaylist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,32 @@
{/block}

{block content}
<style>
textarea[name='description'] {
padding: 4px;
}

.playlistInfo {
width: 76%;
margin-left: 8px;
}
</style>

<div style="display:flex;">
<div class="playlistCover" onclick="document.querySelector(`#newPlaylistForm input[name='cover']`).click()">
<a>
<img src="/assets/packages/static/openvk/img/song.jpg" alt="{_playlist_cover}">
</a>
</div>

<div style="padding-left: 17px;width: 75%;" class="plinfo">
<div>
<input type="text" name="title" placeholder="{_title}" maxlength="125" />
<div class='PE_wrapper'>
<div class='PE_playlistEditPage'>
<div class="playlistCover" onclick="document.querySelector(`input[name='cover']`).click()">
<a>
<input type='file' name='cover' style='display:none;' accept=".jpg,.png">
<img src="/assets/packages/static/openvk/img/song.jpg" alt="{_playlist_cover}">
</a>
</div>
<div class="moreInfo" style="margin-top: 11px;">
<textarea placeholder="{_description}" name="description" maxlength="2045" />

<div class="PE_playlistInfo">
<div>
<input type="text" name="title" placeholder="{_title}" maxlength="125" />
</div>
<div class="moreInfo">
<textarea placeholder="{_description}" name="description" maxlength="2045" />
</div>
<label>
<input type='checkbox' name='is_unlisted' value='1'>
{_playlist_hide_from_search}
</label>
<a id='_playlistAppendTracks'>{_add_audio_verb}</a>
</div>
<label>
<input type='checkbox' name='is_unlisted'>
{_playlist_hide_from_search}
</label>
</div>
</div>

<form method="post" id="newPlaylistForm" enctype="multipart/form-data">
<input type="hidden" name="title" maxlength="125" />
<input type="hidden" name="hash" value="{$csrfToken}" />
<input type="hidden" name="is_unlisted" value="0" />
<textarea style="display:none;" name="description" maxlength="2045" />
<input type="hidden" name="audios">
<input type="file" style="display:none;" name="cover" accept=".jpg,.png">

<div style="float: right;margin-top: 9px;">
<button class="button" type="submit">{_create}</button>
<div class='PE_audios generic_audio_list'></div>
<div class='PE_end'>
<input class="button" type="button" id='playlist_create' value="{_create}">
</div>
</form>
</div>
{/block}
22 changes: 22 additions & 0 deletions Web/static/css/audios.css
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,28 @@
width: 100%;
}

.PE_playlistEditPage {
display: flex;
gap: 10px;
}

.PE_playlistEditPage .PE_playlistInfo {
width: 76%;
display: flex;
flex-direction: column;
gap: 10px;
}

.PE_playlistEditPage textarea[name='description'] {
padding: 4px;
font-size: 11px;
}

.PE_end {
text-align: right;
margin-top: 10px;
}

/* playlist listview */

.playlistListView {
Expand Down
26 changes: 13 additions & 13 deletions Web/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2573,55 +2573,55 @@ a.poll-retract-vote {
border-radius: 3px;
}

.post-vertical .vertical-attachment {
.vertical-attachment {
display: grid;
grid-template-columns: 1fr 0fr;
}

.post-vertical .vertical-attachment:first-of-type {
.vertical-attachment:first-of-type {
margin-top: 7px;
}

.post-vertical .vertical-attachment .audioEntry {
.vertical-attachment .audioEntry {
max-height: 28px;
min-height: 18px;
}

.post-vertical .vertical-attachment .audioEntry:hover {
.vertical-attachment .audioEntry:hover {
background: unset !important;
}

.post-vertical .vertical-attachment .audioEntry .buttons {
.vertical-attachment .audioEntry .buttons {
display: none;
}

.post-vertical .vertical-attachment .audioEntry .status {
.vertical-attachment .audioEntry .status {
margin-top: 1px;
margin-left: 2px;
height: 15px;
}

.post-vertical .vertical-attachment .audioEntry .nobold {
.vertical-attachment .audioEntry .nobold {
margin-top: 1px;
}

.post-vertical .vertical-attachment .audioEntry .subTracks {
padding-bottom: 2px;
padding-left: 3px;
.vertical-attachment .audioEntry .subTracks {
padding-left: 0px;
padding-right: 0px;
margin-top: 2px;
}

.post-vertical .vertical-attachment .audioEntry .audioEntryWrapper {
.vertical-attachment .audioEntry .audioEntryWrapper {
height: 14px;
padding: 0px 4px 0px 0px;
gap: 2px;
}

.post-vertical .vertical-attachment .vertical-attachment-content {
.vertical-attachment .vertical-attachment-content {
max-height: 27px;
}

.post-vertical .vertical-attachment .vertical-attachment-content .overflowedName {
.vertical-attachment .vertical-attachment-content .overflowedName {
position: initial;
width: 100% !important;
}
Expand Down
Loading

0 comments on commit 187250b

Please sign in to comment.