diff --git a/Web/Models/Entities/Note.php b/Web/Models/Entities/Note.php index e15a838c..66afea26 100644 --- a/Web/Models/Entities/Note.php +++ b/Web/Models/Entities/Note.php @@ -72,6 +72,16 @@ class Note extends Postable $purifier = new HTMLPurifier($config); return $purifier->purify($this->getRecord()->source); } + + function getVirtualId(): int + { + return $this->getRecord()->virtual_id; + } + + function getPrettyId(): string + { + return $this->getRecord()->owner . "_" . $this->getVirtualId(); + } function getName(): string { diff --git a/Web/Models/Repositories/Notes.php b/Web/Models/Repositories/Notes.php index 205beee1..f1b19eaf 100644 --- a/Web/Models/Repositories/Notes.php +++ b/Web/Models/Repositories/Notes.php @@ -32,6 +32,15 @@ class Notes foreach($this->notes->where("owner", $user->getId())->where("deleted", 0)->page($page, $perPage) as $album) yield new Note($album); } + + function getNoteById(int $owner, int $note): ?Note + { + $note = $this->notes->where(['owner' => $owner, 'virtual_id' => $note])->fetch(); + if(!is_null($note)) + return new Note($note); + else + return null; + } function getUserNotesCount(User $user): int { diff --git a/Web/Presenters/NotesPresenter.php b/Web/Presenters/NotesPresenter.php index 8c921edb..0764faf6 100644 --- a/Web/Presenters/NotesPresenter.php +++ b/Web/Presenters/NotesPresenter.php @@ -31,10 +31,10 @@ final class NotesPresenter extends OpenVKPresenter ]; } - function renderView(int $owner, int $id): void + function renderView(int $owner, int $note_id): void { - $note = $this->notes->get($id); - if(!$note || $note->getOwner()->getId() !== $owner) + $note = $this->notes->getNoteById($owner, $note_id); + if(!$note || $note->getOwner()->getId() !== $owner || $note->isDeleted()) $this->notFound(); $this->template->cCount = $note->getCommentsCount(); @@ -65,7 +65,7 @@ final class NotesPresenter extends OpenVKPresenter $note->setSource($this->postParam("html")); $note->save(); - $this->redirect("/note" . $this->user->id . "_" . $note->getId()); + $this->redirect("/note" . $this->user->id . "_" . $note->getVirtualId()); } } diff --git a/Web/Presenters/templates/Notes/List.xml b/Web/Presenters/templates/Notes/List.xml index 2c7ceef5..44d831f5 100644 --- a/Web/Presenters/templates/Notes/List.xml +++ b/Web/Presenters/templates/Notes/List.xml @@ -21,7 +21,7 @@ {* BEGIN ELEMENTS DESCRIPTION *} {block link|strip|stripHtml} - /note{$x->getOwner()->getId()}_{$x->getId()} + /note{$x->getPrettyId()} {/block} {block preview} diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml index db68f1a2..4cddd9ae 100644 --- a/Web/Presenters/templates/User/View.xml +++ b/Web/Presenters/templates/User/View.xml @@ -296,13 +296,13 @@