diff --git a/ServiceAPI/Wall.php b/ServiceAPI/Wall.php index 628ceb22..b052f687 100644 --- a/ServiceAPI/Wall.php +++ b/ServiceAPI/Wall.php @@ -2,17 +2,19 @@ namespace openvk\ServiceAPI; use openvk\Web\Models\Entities\Post; use openvk\Web\Models\Entities\User; -use openvk\Web\Models\Repositories\Posts; +use openvk\Web\Models\Repositories\{Posts, Notes}; class Wall implements Handler { protected $user; protected $posts; + protected $notes; function __construct(?User $user) { $this->user = $user; $this->posts = new Posts; + $this->notes = new Notes; } function getPost(int $id, callable $resolve, callable $reject): void @@ -71,4 +73,24 @@ class Wall implements Handler $resolve($post->getId()); } + + function getMyNotes(callable $resolve, callable $reject) + { + $myNotes = $this->notes->getUserNotes($this->user, 1, $this->notes->getUserNotesCount($this->user)); + + $arr = [ + "count" => sizeof($myNotes), + "items" => [] + ]; + + foreach($myNotes as $note) { + $arr["items"][] = [ + "id" => $note->getId(), + "name" => ovk_proc_strtr($note->getName(), 30), + #"preview" => $note->getPreview() + ]; + } + + $resolve($arr); + } } diff --git a/VKAPI/Handlers/Notes.php b/VKAPI/Handlers/Notes.php index d3dc3468..b81df7f2 100644 --- a/VKAPI/Handlers/Notes.php +++ b/VKAPI/Handlers/Notes.php @@ -40,6 +40,9 @@ final class Notes extends VKAPIRequestHandler if($note->getOwner()->isDeleted()) $this->fail(403, "Owner is deleted"); + if(!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) + $this->fail(43, "No access"); + if(empty($message) && empty($attachments)) $this->fail(100, "Required parameter 'message' missing."); @@ -183,6 +186,9 @@ final class Notes extends VKAPIRequestHandler if(!$user || $user->isDeleted()) $this->fail(15, "Invalid user"); + if(!$user->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) + $this->fail(43, "No access"); + if(empty($note_ids)) { $notes = array_slice(iterator_to_array((new NotesRepo)->getUserNotes($user, 1, $count + $offset, $sort == 0 ? "ASC" : "DESC")), $offset); $nodez = (object) [ @@ -226,7 +232,7 @@ final class Notes extends VKAPIRequestHandler if($note->isDeleted()) $this->fail(189, "Note is deleted"); - if(!$note->getOwner() || $note->getOwner()->isDeleted()) + if(!$note->getOwner() || $note->getOwner()->isDeleted() || !$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) $this->fail(177, "Owner does not exists"); return $note->toVkApiStruct(); @@ -246,6 +252,9 @@ final class Notes extends VKAPIRequestHandler if(!$note->getOwner()) $this->fail(177, "Owner does not exists"); + + if(!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) + $this->fail(14, "No access"); $arr = (object) [ "count" => $note->getCommentsCount(), diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index ee07f3c1..fa61b84b 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -13,6 +13,8 @@ use openvk\Web\Models\Entities\Photo; use openvk\Web\Models\Repositories\Photos as PhotosRepo; use openvk\Web\Models\Entities\Video; use openvk\Web\Models\Repositories\Videos as VideosRepo; +use openvk\Web\Models\Entities\Note; +use openvk\Web\Models\Repositories\Notes as NotesRepo; final class Wall extends VKAPIRequestHandler { @@ -54,6 +56,8 @@ final class Wall extends VKAPIRequestHandler $attachments[] = $this->getApiPoll($attachment, $this->getUser()); } else if ($attachment instanceof \openvk\Web\Models\Entities\Video) { $attachments[] = $attachment->getApiStructure(); + } else if ($attachment instanceof \openvk\Web\Models\Entities\Note) { + $attachments[] = $attachment->toVkApiStruct(); } else if ($attachment instanceof \openvk\Web\Models\Entities\Post) { $repostAttachments = []; @@ -226,6 +230,8 @@ final class Wall extends VKAPIRequestHandler $attachments[] = $this->getApiPoll($attachment, $user); } else if ($attachment instanceof \openvk\Web\Models\Entities\Video) { $attachments[] = $attachment->getApiStructure(); + } else if ($attachment instanceof \openvk\Web\Models\Entities\Note) { + $attachments[] = $attachment->toVkApiStruct(); } else if ($attachment instanceof \openvk\Web\Models\Entities\Post) { $repostAttachments = []; @@ -440,6 +446,8 @@ final class Wall extends VKAPIRequestHandler $attachmentType = "photo"; elseif(str_contains($attac, "video")) $attachmentType = "video"; + elseif(str_contains($attac, "note")) + $attachmentType = "note"; else $this->fail(205, "Unknown attachment type"); @@ -465,6 +473,14 @@ final class Wall extends VKAPIRequestHandler if($attacc->getOwner()->getId() != $this->getUser()->getId()) $this->fail(43, "You do not have access to this video"); + $post->attach($attacc); + } elseif($attachmentType == "note") { + $attacc = (new NotesRepo)->getNoteById($attachmentOwner, $attachmentId); + if(!$attacc || $attacc->isDeleted()) + $this->fail(100, "Note does not exists"); + if($attacc->getOwner()->getId() != $this->getUser()->getId()) + $this->fail(43, "You do not have access to this note"); + $post->attach($attacc); } } @@ -542,6 +558,8 @@ final class Wall extends VKAPIRequestHandler foreach($comment->getChildren() as $attachment) { if($attachment instanceof \openvk\Web\Models\Entities\Photo) { $attachments[] = $this->getApiPhoto($attachment); + } elseif($attachment instanceof \openvk\Web\Models\Entities\Note) { + $attachments[] = $attachment->toVkApiStruct(); } } @@ -599,8 +617,8 @@ final class Wall extends VKAPIRequestHandler function getComment(int $owner_id, int $comment_id, bool $extended = false, string $fields = "sex,screen_name,photo_50,photo_100,online_info,online") { $this->requireUser(); - $comment = (new CommentsRepo)->get($comment_id); // один хуй айди всех комментов общий - + $comment = (new CommentsRepo)->get($comment_id); # один хуй айди всех комментов общий + $profiles = []; $attachments = []; diff --git a/Web/Models/Entities/Note.php b/Web/Models/Entities/Note.php index d259c2a5..37d9ac29 100644 --- a/Web/Models/Entities/Note.php +++ b/Web/Models/Entities/Note.php @@ -123,6 +123,7 @@ class Note extends Postable { $res = (object) []; + $res->type = "note"; $res->id = $this->getId(); $res->owner_id = $this->getOwner()->getId(); $res->title = $this->getName(); diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 6b9ec183..7beb5c2a 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -3,7 +3,7 @@ namespace openvk\Web\Presenters; use openvk\Web\Models\Exceptions\TooMuchOptionsException; use openvk\Web\Models\Entities\{Poll, Post, Photo, Video, Club, User}; use openvk\Web\Models\Entities\Notifications\{MentionNotification, RepostNotification, WallPostNotification}; -use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums}; +use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes}; use Chandler\Database\DatabaseConnection; use Nette\InvalidStateException as ISE; use Bhaktaraz\RSSGenerator\Item; @@ -278,8 +278,18 @@ final class WallPresenter extends OpenVKPresenter } catch(\UnexpectedValueException $e) { $this->flashFail("err", tr("failed_to_publish_post"), "Poll format invalid"); } + + $note = NULL; + + if(!is_null($this->postParam("note")) && $this->postParam("note") != "none") { + $note = (new Notes)->get((int)$this->postParam("note")); + + if(!$note || $note->isDeleted() || $note->getOwner()->getId() != $this->user->id) { + $this->flashFail("err", tr("error"), tr("error_attaching_note")); + } + } - if(empty($this->postParam("text")) && !$photo && !$video && !$poll) + if(empty($this->postParam("text")) && !$photo && !$video && !$poll && !$note) $this->flashFail("err", tr("failed_to_publish_post"), tr("post_is_empty_or_too_big")); try { @@ -304,6 +314,9 @@ final class WallPresenter extends OpenVKPresenter if(!is_null($poll)) $post->attach($poll); + + if(!is_null($note)) + $post->attach($note); if($wall > 0 && $wall !== $this->user->identity->getId()) (new WallPostNotification($wallOwner, $post, $this->user->identity))->emit(); diff --git a/Web/Presenters/templates/Wall/Feed.xml b/Web/Presenters/templates/Wall/Feed.xml index b7f405a4..5ed1e2fb 100644 --- a/Web/Presenters/templates/Wall/Feed.xml +++ b/Web/Presenters/templates/Wall/Feed.xml @@ -16,7 +16,7 @@