diff --git a/VKAPI/Handlers/Audio.php b/VKAPI/Handlers/Audio.php index 35d2b8aa..58bce510 100644 --- a/VKAPI/Handlers/Audio.php +++ b/VKAPI/Handlers/Audio.php @@ -487,6 +487,7 @@ final class Audio extends VKAPIRequestHandler $audio->setName($title); $audio->setSearchability(!((bool) $no_search)); + $audio->setEdited(time()); $audio->save(); return $lyrics; @@ -654,6 +655,9 @@ final class Audio extends VKAPIRequestHandler if(!is_null($description)) $album->setDescription($description); + $album->setEdited(time()); + $album->save(); + return (int) !(!$title && !$description); } diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index 3123a43f..85a251da 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -292,7 +292,8 @@ final class Groups extends VKAPIRequestHandler int $topics = NULL, int $adminlist = NULL, int $topicsAboveWall = NULL, - int $hideFromGlobalFeed = NULL) + int $hideFromGlobalFeed = NULL, + int $audio = NULL) { $this->requireUser(); $this->willExecuteWriteAction(); @@ -303,17 +304,22 @@ final class Groups extends VKAPIRequestHandler if(!$club || !$club->canBeModifiedBy($this->getUser())) $this->fail(15, "You can't modify this group."); if(!empty($screen_name) && !$club->setShortcode($screen_name)) $this->fail(103, "Invalid shortcode."); - !is_null($title) ? $club->setName($title) : NULL; - !is_null($description) ? $club->setAbout($description) : NULL; - !is_null($screen_name) ? $club->setShortcode($screen_name) : NULL; - !is_null($website) ? $club->setWebsite((!parse_url($website, PHP_URL_SCHEME) ? "https://" : "") . $website) : NULL; - !is_null($wall) ? $club->setWall($wall) : NULL; - !is_null($topics) ? $club->setEveryone_Can_Create_Topics($topics) : NULL; - !is_null($adminlist) ? $club->setAdministrators_List_Display($adminlist) : NULL; - !is_null($topicsAboveWall) ? $club->setDisplay_Topics_Above_Wall($topicsAboveWall) : NULL; - !is_null($hideFromGlobalFeed) ? $club->setHide_From_Global_Feed($hideFromGlobalFeed) : NULL; + !empty($title) ? $club->setName($title) : NULL; + !empty($description) ? $club->setAbout($description) : NULL; + !empty($screen_name) ? $club->setShortcode($screen_name) : NULL; + !empty($website) ? $club->setWebsite((!parse_url($website, PHP_URL_SCHEME) ? "https://" : "") . $website) : NULL; + !empty($wall) ? $club->setWall($wall) : NULL; + !empty($topics) ? $club->setEveryone_Can_Create_Topics($topics) : NULL; + !empty($adminlist) ? $club->setAdministrators_List_Display($adminlist) : NULL; + !empty($topicsAboveWall) ? $club->setDisplay_Topics_Above_Wall($topicsAboveWall) : NULL; + !empty($hideFromGlobalFeed) ? $club->setHide_From_Global_Feed($hideFromGlobalFeed) : NULL; + in_array($audio, [0, 1]) ? $club->setEveryone_can_upload_audios($audio) : NULL; - $club->save(); + try { + $club->save(); + } catch(\TypeError $e) { + $this->fail(8, "Nothing changed"); + } return 1; } @@ -370,7 +376,7 @@ final class Groups extends VKAPIRequestHandler $arr->items[$i]->can_see_all_posts = 1; break; case "can_see_audio": - $arr->items[$i]->can_see_audio = 0; + $arr->items[$i]->can_see_audio = 1; break; case "can_write_private_message": $arr->items[$i]->can_write_private_message = 0; @@ -469,7 +475,7 @@ final class Groups extends VKAPIRequestHandler "wall" => $club->canPost() == true ? 1 : 0, "photos" => 1, "video" => 0, - "audio" => 0, + "audio" => $club->isEveryoneCanUploadAudios() ? 1 : 0, "docs" => 0, "topics" => $club->isEveryoneCanCreateTopics() == true ? 1 : 0, "wiki" => 0, diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index d662d44d..c89f0b47 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -372,10 +372,23 @@ class Club extends RowModel return $this->getRecord()->alert; } - function getRealId() + function getRealId(): int { return $this->getId() * -1; } + + function isEveryoneCanUploadAudios(): bool + { + return (bool) $this->getRecord()->everyone_can_upload_audios; + } + + function canUploadAudio(?User $user): bool + { + if(!$user) + return NULL; + + return $this->isEveryoneCanUploadAudios() || $this->canBeModifiedBy($user); + } function toVkApiStruct(?User $user = NULL): object { diff --git a/Web/Models/Entities/Playlist.php b/Web/Models/Entities/Playlist.php index 0da1dd49..813edbe0 100644 --- a/Web/Models/Entities/Playlist.php +++ b/Web/Models/Entities/Playlist.php @@ -150,8 +150,8 @@ class Playlist extends MediaCollection "description" => $this->getDescription(), "size" => $this->size(), "length" => $this->getLength(), - "created" => $this->getCreationTime()->relative(), - "modified" => $this->getCreationTime()->relative(), + "created" => $this->getCreationTime()->timestamp(), + "modified" => $this->getEditTime() ? $this->getEditTime()->timestamp() : NULL, "accessible" => $this->canBeViewedBy($user), "editable" => $this->canBeModifiedBy($user), "bookmarked" => $this->isBookmarkedBy($user), diff --git a/Web/Models/Repositories/Audios.php b/Web/Models/Repositories/Audios.php index 70abd6e0..deae943e 100644 --- a/Web/Models/Repositories/Audios.php +++ b/Web/Models/Repositories/Audios.php @@ -123,6 +123,11 @@ class Audios { return $this->getPlaylistsByEntityId($club->getId() * -1, ($perPage * ($page - 1)), $perPage, $deleted); } + + function getCollectionSizeByEntityId(int $id): int + { + return sizeof($this->rels->where("entity", $id)); + } function getUserCollectionSize(User $user): int { diff --git a/Web/Presenters/AudioPresenter.php b/Web/Presenters/AudioPresenter.php index 5cc82106..a8f49dfb 100644 --- a/Web/Presenters/AudioPresenter.php +++ b/Web/Presenters/AudioPresenter.php @@ -93,6 +93,7 @@ final class AudioPresenter extends OpenVKPresenter $this->template->playlistsCount = $playlistsCount; $this->template->owner = $entity; $this->template->ownerId = $owner; + $this->template->club = $owner < 0 ? $entity : NULL; $this->template->isMy = ($owner > 0 && ($entity->getId() === $this->user->id)); $this->template->isMyClub = ($owner < 0 && $entity->canBeModifiedBy($this->user->identity)); } else { @@ -138,15 +139,15 @@ final class AudioPresenter extends OpenVKPresenter $this->assertUserLoggedIn(); $group = NULL; + $isAjax = $this->postParam("ajax", false) == 1; if(!is_null($this->queryParam("gid"))) { $gid = (int) $this->queryParam("gid"); $group = (new Clubs)->get($gid); if(!$group) - $this->flashFail("err", tr("forbidden"), tr("not_enough_permissions_comment")); + $this->flashFail("err", tr("forbidden"), tr("not_enough_permissions_comment"), null, $isAjax); - // TODO check if group allows uploads to anyone - if(!$group->canBeModifiedBy($this->user->identity)) - $this->flashFail("err", tr("forbidden"), tr("not_enough_permissions_comment")); + if(!$group->canUploadAudio($this->user->identity)) + $this->flashFail("err", tr("forbidden"), tr("not_enough_permissions_comment"), null, $isAjax); } $this->template->group = $group; @@ -157,20 +158,20 @@ final class AudioPresenter extends OpenVKPresenter $upload = $_FILES["blob"]; if(isset($upload) && file_exists($upload["tmp_name"])) { if($upload["size"] > self::MAX_AUDIO_SIZE) - $this->flashFail("err", tr("error"), tr("media_file_corrupted_or_too_large")); + $this->flashFail("err", tr("error"), tr("media_file_corrupted_or_too_large"), null, $isAjax); } else { $err = !isset($upload) ? 65536 : $upload["error"]; $err = str_pad(dechex($err), 9, "0", STR_PAD_LEFT); - $this->flashFail("err", tr("error"), tr("error_generic") . "Upload error: 0x$err"); + $this->flashFail("err", tr("error"), tr("error_generic") . "Upload error: 0x$err", null, $isAjax); } $performer = $this->postParam("performer"); $name = $this->postParam("name"); $lyrics = $this->postParam("lyrics"); - $genre = empty($this->postParam("genre")) ? "undefined" : $this->postParam("genre"); + $genre = empty($this->postParam("genre")) ? "Other" : $this->postParam("genre"); $nsfw = ($this->postParam("explicit") ?? "off") === "on"; if(empty($performer) || empty($name) || iconv_strlen($performer . $name) > 128) # FQN of audio must not be more than 128 chars - $this->flashFail("err", tr("error"), tr("error_insufficient_info")); + $this->flashFail("err", tr("error"), tr("error_insufficient_info"), null, $isAjax); $audio = new Audio; $audio->setOwner($this->user->id); @@ -184,13 +185,30 @@ final class AudioPresenter extends OpenVKPresenter $audio->setFile($upload); } catch(\DomainException $ex) { $e = $ex->getMessage(); - $this->flashFail("err", tr("error"), tr("media_file_corrupted_or_too_large") . " $e."); + $this->flashFail("err", tr("error"), tr("media_file_corrupted_or_too_large") . " $e.", null, $isAjax); } $audio->save(); $audio->add($group ?? $this->user->identity); - $this->redirect(is_null($group) ? "/audios" . $this->user->id : "/audios-" . $group->getId()); + if(!$isAjax) + $this->redirect(is_null($group) ? "/audios" . $this->user->id : "/audios-" . $group->getId()); + else { + $redirectLink = "/audios"; + + if(!is_null($group)) + $redirectLink .= $group->getRealId(); + else + $redirectLink .= $this->user->id; + + $pagesCount = (int)ceil((new Audios)->getCollectionSizeByEntityId(isset($group) ? $group->getRealId() : $this->user->id) / 10); + $redirectLink .= "?p=".$pagesCount; + + $this->returnJson([ + "success" => true, + "redirect_link" => $redirectLink, + ]); + } } function renderListen(int $id): void @@ -222,8 +240,8 @@ final class AudioPresenter extends OpenVKPresenter $owner = $this->user->id; - if ($this->requestParam("owner")) { - $club = (new Clubs)->get((int) abs($this->requestParam("owner"))); + if ($this->requestParam("gid")) { + $club = (new Clubs)->get((int) abs((int)$this->requestParam("gid"))); if (!$club || $club->isBanned() || !$club->canBeModifiedBy($this->user->identity)) $this->redirect("/audios" . $this->user->id); @@ -367,6 +385,7 @@ final class AudioPresenter extends OpenVKPresenter $playlist->setName(ovk_proc_strtr($title, 128)); $playlist->setDescription(ovk_proc_strtr($description, 2048)); + $playlist->setEdited(time()); $playlist->resetLength(); if($_FILES["new_cover"]["error"] === UPLOAD_ERR_OK) { @@ -504,6 +523,7 @@ final class AudioPresenter extends OpenVKPresenter $audio->setGenre($genre); $audio->setExplicit($nsfw); $audio->setSearchability($unlisted); + $audio->setEdited(time()); $audio->save(); $this->returnJson(["success" => true, "new_info" => [ diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index 27d626cc..adf536de 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -220,6 +220,7 @@ final class GroupPresenter extends OpenVKPresenter $club->setAdministrators_List_Display(empty($this->postParam("administrators_list_display")) ? 0 : $this->postParam("administrators_list_display")); $club->setEveryone_Can_Create_Topics(empty($this->postParam("everyone_can_create_topics")) ? 0 : 1); $club->setDisplay_Topics_Above_Wall(empty($this->postParam("display_topics_above_wall")) ? 0 : 1); + $club->setEveryone_can_upload_audios(empty($this->postParam("upload_audios")) ? 0 : 1); $club->setHide_From_Global_Feed(empty($this->postParam("hide_from_global_feed")) ? 0 : 1); $website = $this->postParam("website") ?? ""; diff --git a/Web/Presenters/templates/Audio/List.xml b/Web/Presenters/templates/Audio/List.xml index 2d20932c..27822908 100644 --- a/Web/Presenters/templates/Audio/List.xml +++ b/Web/Presenters/templates/Audio/List.xml @@ -94,7 +94,7 @@ - {ovk_proc_strtr($playlist->getOwner()->getCanonicalName(), 15)} + {ovk_proc_strtr($playlist->getOwner()->getCanonicalName(), 20)} diff --git a/Web/Presenters/templates/Audio/NewPlaylist.xml b/Web/Presenters/templates/Audio/NewPlaylist.xml index abbec8ff..4512b10e 100644 --- a/Web/Presenters/templates/Audio/NewPlaylist.xml +++ b/Web/Presenters/templates/Audio/NewPlaylist.xml @@ -5,7 +5,7 @@ {/block} {block header} - {if !$_GET["owner"]} + {if !$_GET["gid"]} {$thisUser->getCanonicalName()} » {_audios} @@ -37,15 +37,16 @@ -