diff --git a/VKAPI/Handlers/Gifts.php b/VKAPI/Handlers/Gifts.php new file mode 100644 index 00000000..1cf7a6b1 --- /dev/null +++ b/VKAPI/Handlers/Gifts.php @@ -0,0 +1,232 @@ +requireUser(); + + $i = 0; + + $i+=$offset; + + $user = (new UsersRepo)->get($user_id); + if(!$user || $user->isDeleted()) + $this->fail(177, "Invalid user"); + + $gift_item = []; + + $userGifts = $user->getGifts(1, $count, false); + + if(sizeof($userGifts) < 0) { + return NULL; + } + + foreach($userGifts as $gift) { + if($i < $count) { + $gift_item[] = [ + "id" => $i, + "from_id" => $gift->anon == true ? 0 : $gift->sender->getId(), + "message" => $gift->caption == NULL ? "" : $gift->caption, + "date" => $gift->sent->timestamp(), + "gift" => [ + "id" => $gift->gift->getId(), + "thumb_256" => $gift->gift->getImage(2), + "thumb_96" => $gift->gift->getImage(2), + "thumb_48" => $gift->gift->getImage(2) + ], + "privacy" => 0 + ]; + } + $i+=1; + } + + return $gift_item; + } + + function send(int $user_ids, int $gift_id, string $message = "", int $privacy = 0) + { + $this->requireUser(); + $this->willExecuteWriteAction(); + + $user = (new UsersRepo)->get((int) $user_ids); + if(!$user || $user->isDeleted()) + $this->fail(177, "Invalid user"); + + $gift = (new GiftsRepo)->get($gift_id); + $price = $gift->getPrice(); + $coinsLeft = $this->getUser()->getCoins() - $price; + + if(!$gift->canUse($this->getUser())) + return (object) + [ + "success" => 0, + "user_ids" => $user_ids, + "error" => "You don't have any more of these gifts." + ]; + + if($coinsLeft < 0) + return (object) + [ + "success" => 0, + "user_ids" => $user_ids, + "error" => "You don't have enough voices." + ]; + + $user->gift($this->getUser(), $gift, $message); + $gift->used(); + + $this->getUser()->setCoins($coinsLeft); + $this->getUser()->save(); + + $notification = new GiftNotification($user, $this->getUser(), $gift, $message); + $notification->emit(); + + return (object) + [ + "success" => 1, + "user_ids" => $user_ids, + "withdraw_votes" => $price + ]; + } + + function delete() + { + $this->requireUser(); + $this->willExecuteWriteAction(); + # тожэ заглушка + return 0; + } + + # этих методов не было в ВК, но я их добавил чтобы можно было отобразить список подарков + function getCategories(bool $extended = false, int $count = 10, int $offset = 0) + { + $cats = (new GiftsRepo)->getCategories(1, $count); + $categ = []; + $i = 1; + + foreach($cats as $cat) { + if($i > $count) + break; + if($i > $offset) { + $categ[] = [ + "name" => $cat->getName(), + "description" => $cat->getDescription(), + "id" => $cat->getId(), + "thumbnail" => $cat->getThumbnailURL(), + "localizations" => $extended == true ? + [ + "en" => [ + "name" => $cat->getName("en"), + "desc" => $cat->getDescription("en"), + ], + "ru" => [ + "name" => $cat->getName("ru"), + "desc" => $cat->getDescription("ru"), + ], + "uk" => [ + "name" => $cat->getName("uk"), + "desc" => $cat->getDescription("uk") + ], + "by" => [ + "name" => $cat->getName("by"), + "desc" => $cat->getDescription("by") + ], + "by_lat" => [ + "name" => $cat->getName("by_lat"), + "desc" => $cat->getDescription("by_lat") + ], + "pl" => [ + "name" => $cat->getName("pl"), + "desc" => $cat->getDescription("pl") + ], + "de" => [ + "name" => $cat->getName("de"), + "desc" => $cat->getDescription("de") + ], + "hy" => [ + "name" => $cat->getName("hy"), + "desc" => $cat->getDescription("hy") + ], + "sr_cyr" => [ + "name" => $cat->getName("sr_cyr"), + "desc" => $cat->getDescription("sr_cyr") + ], + "sr_lat" => [ + "name" => $cat->getName("sr_lat"), + "desc" => $cat->getDescription("sr_lat") + ], + "tr" => [ + "name" => $cat->getName("tr"), + "desc" => $cat->getDescription("tr") + ], + "kk" => [ + "name" => $cat->getName("kk"), + "desc" => $cat->getDescription("kk") + ], + "ru_old" => [ + "name" => $cat->getName("ru_old"), + "desc" => $cat->getDescription("ru_old") + ], + "eo" => [ + "name" => $cat->getName("eo"), + "desc" => $cat->getDescription("eo") + ], + "ru_sov" => [ + "name" => $cat->getName("ru_sov"), + "desc" => $cat->getDescription("ru_sov") + ], + "udm" => [ + "name" => $cat->getName("udm"), + "desc" => $cat->getDescription("udm") + ], + "id" => [ + "name" => $cat->getName("id"), + "desc" => $cat->getDescription("id") + ], + "qqx" => [ + "name" => $cat->getName("qqx"), + "desc" => $cat->getDescription("qqx") + ], + ] : NULL]; + } else { + $i++; + } + } + + return $categ; + } + + function getGiftsInCategory(int $id, int $count = 10, int $offset = 0) + { + $this->requireUser(); + if(!(new GiftsRepo)->getCat($id)) + $this->fail(177, "Category not found"); + + $giftz = ((new GiftsRepo)->getCat($id))->getGifts(1, $count); + $gifts = []; + $i = 1; + + foreach($giftz as $gift) { + if($i > $count) + break; + if($i > $offset) { + $gifts[] = [ + "name" => $gift->getName(), + "image" => $gift->getImage(2), + "usages_left" => (int)$gift->getUsagesLeft($this->getUser()), + "price" => $gift->getPrice(), # голосов + "is_free" => $gift->isFree() + ]; + } else { + $i++; + } + } + + return $gifts; + } +} diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index 071ded81..b743eab8 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -2,6 +2,7 @@ namespace openvk\VKAPI\Handlers; use openvk\Web\Models\Repositories\Clubs as ClubsRepo; use openvk\Web\Models\Repositories\Users as UsersRepo; +use openvk\Web\Models\Entities\{Club}; final class Groups extends VKAPIRequestHandler { @@ -263,4 +264,247 @@ final class Groups extends VKAPIRequestHandler return 1; } + + function create(string $title, string $description = "", string $type = "group", int $public_category = 1, int $public_subcategory = 1, int $subtype = 1) + { + $this->requireUser(); + $this->willExecuteWriteAction(); + + $club = new Club; + + $club->setName($title); + $club->setAbout($description); + $club->setOwner($this->getUser()->getId()); + $club->save(); + + $club->toggleSubscription($this->getUser()); + + return $this->getById((string)$club->getId()); + } + + function edit( + int $group_id, + string $title = NULL, + string $description = NULL, + string $screen_name = NULL, + string $website = NULL, + int $wall = NULL, + int $topics = NULL, + int $adminlist = NULL, + int $topicsAboveVall = NULL, + int $hideFromGlobalFeed = NULL, + # дальше для совместимости с вк + int $subject = NULL, + int $access = NULL, + string $email = NULL, + string $phone = NULL, + string $rss = NULL, + int $event_start_date = NULL, + int $event_finish_date = NULL, + int $event_group_id = NULL, + int $public_category = NULL, + int $public_subcategory = NULL, + int $public_date = NULL, + int $photos = NULL, + int $video = NULL, + bool $links = NULL, + bool $events = NULL, + bool $places = NULL, + bool $contacts = NULL, + bool $wiki = NULL, + bool $messages = NULL, + bool $articles = NULL, + bool $addresses = NULL, + bool $age_limits = NULL, + bool $market = NULL, + bool $obscene_filter = NULL, + bool $obscene_stopwords = NULL, + string $obscene_words = NULL, + int $main_section = NULL, + int $secondary_section = NULL, + int $country = NULL, + int $city = NULL + ) + { + $this->requireUser(); + $this->willExecuteWriteAction(); + + $club = (new ClubsRepo)->get($group_id); + + if(!$club) + $this->fail(203, "Club not found"); + if(!$club || !$club->canBeModifiedBy($this->getUser())) + $this->fail(15, "You can't modify this group."); + if(!is_null($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($topicsAboveVall) ? $club->setDisplay_Topics_Above_Wall($topicsAboveVall) : NULL; + !is_null($hideFromGlobalFeed) ? $club->setHide_From_Global_Feed($hideFromGlobalFeed) : NULL; + + $club->save(); + + return 1; + } + + function getMembers(string $group_id, string $sort = "id_asc", int $offset = 0, int $count = 100, string $fields = "", string $filter = "any") + { + # bdate,can_post,can_see_all_posts,can_see_audio,can_write_private_message,city,common_count,connections,contacts,country,domain,education,has_mobile,last_seen,lists,online,online_mobile,photo_100,photo_200,photo_200_orig,photo_400_orig,photo_50,photo_max,photo_max_orig,relation,relatives,schools,sex,site,status,universities + $club = (new ClubsRepo)->get((int) $group_id); + if(!$club) + $this->fail(125, "Invalid group id"); + + $sorter = "follower ASC"; + + switch($sort) { + default: + case "time_asc": + case "id_asc": + $sorter = "follower ASC"; + break; + case "time_desc": + case "id_desc": + $sorter = "follower DESC"; + break; + } + + $members = array_slice(iterator_to_array($club->getFollowers(1, $count, $sorter)), $offset); + $arr = (object) [ + "count" => count($members), + "items" => array()]; + + $filds = explode(",", $fields); + + $i = 0; + foreach($members as $member) + { + if($i > $count) { + break; + } + + $arr->items[] = (object) [ + "id" => $member->getId(), + "name" => $member->getCanonicalName(), + ]; + + foreach($filds as $fild) { + $fild == "bdate" ? $arr->items[$i]->bdate = $member->getBirthday()->format('%e.%m.%Y') : NULL; + $fild == "can_post" ? $arr->items[$i]->can_post = $club->canBeModifiedBy($member) : NULL; + $fild == "can_see_all_posts" ? $arr->items[$i]->can_see_all_posts = 1 : NULL; + $fild == "can_see_audio" ? $arr->items[$i]->can_see_audio = 0 : NULL; # lul + $fild == "can_write_private_message" ? $arr->items[$i]->can_write_private_message = 0 : NULL; + $fild == "common_count" ? $arr->items[$i]->common_count = 420 : NULL; # я хэзэ чё ето + $fild == "connections" ? $arr->items[$i]->connections = 1 : NULL; + $fild == "contacts" ? $arr->items[$i]->contacts = $member->getContactEmail() : NULL; + $fild == "country" ? $arr->items[$i]->country = 1 : NULL; + $fild == "domain" ? $arr->items[$i]->domain = "" : NULL; + $fild == "education" ? $arr->items[$i]->education = "" : NULL; + $fild == "has_mobile" ? $arr->items[$i]->has_mobile = false : NULL; + $fild == "last_seen" ? $arr->items[$i]->last_seen = $member->getOnline()->timestamp() : NULL; + $fild == "lists" ? $arr->items[$i]->lists = "" : NULL; + $fild == "online" ? $arr->items[$i]->online = $member->isOnline() : NULL; + $fild == "online_mobile" ? $arr->items[$i]->online_mobile = $member->getOnlinePlatform() == "android" || $member->getOnlinePlatform() == "iphone" || $member->getOnlinePlatform() == "mobile" : NULL; + $fild == "photo_100" ? $arr->items[$i]->photo_100 = $member->getAvatarURL("tiny") : NULL; + $fild == "photo_200" ? $arr->items[$i]->photo_200 = $member->getAvatarURL("normal") : NULL; + $fild == "photo_200_orig" ? $arr->items[$i]->photo_200_orig = $member->getAvatarURL("normal") : NULL; + $fild == "photo_400_orig" ? $arr->items[$i]->photo_400_orig = $member->getAvatarURL("normal") : NULL; + $fild == "photo_max" ? $arr->items[$i]->photo_max = $member->getAvatarURL("original") : NULL; + $fild == "photo_max_orig" ? $arr->items[$i]->photo_max_orig = $member->getAvatarURL() : NULL; + $fild == "relation" ? $arr->items[$i]->relation = $member->getMaritalStatus() : NULL; + $fild == "relatives" ? $arr->items[$i]->relatives = 0 : NULL; + $fild == "schools" ? $arr->items[$i]->schools = 0 : NULL; + $fild == "sex" ? $arr->items[$i]->sex = $member->isFemale() ? 1 : 2 : NULL; + $fild == "site" ? $arr->items[$i]->site = $member->getWebsite() : NULL; + $fild == "status" ? $arr->items[$i]->status = $member->getStatus() : NULL; + $fild == "universities" ? $arr->items[$i]->universities = 0 : NULL; + } + $i++; + } + return $arr; + } + + function getSettings(string $group_id) + { + $this->requireUser(); + $club = (new ClubsRepo)->get((int)$group_id); + + if(!$club || !$club->canBeModifiedBy($this->getUser())) + $this->fail(15, "You can't get settings of this group."); + + $arr = (object) [ + "title" => $club->getName(), + "description" => $club->getDescription() != NULL ? $club->getDescription() : "", + "address" => $club->getShortcode(), + "wall" => $club->canPost() == true ? 1 : 0, + "photos" => 1, + "video" => 0, + "audio" => 0, + "docs" => 0, + "topics" => $club->isEveryoneCanCreateTopics() == true ? 1 : 0, + "wiki" => 0, + "messages" => 0, + "obscene_filter" => 0, + "obscene_stopwords" => 0, + "obscene_words" => "", + "access" => 1, + "subject" => 1, + "subject_list" => [ + 0 => "в", + 1 => "опенвк", + 2 => "нет", + 3 => "категорий", + 4 => "групп", + ], + "rss" => "/club".$club->getId()."/rss", + "website" => $club->getWebsite(), + "age_limits" => 0, + "market" => [], + ]; + + return $arr; + } + + function isMember(string $group_id, int $user_id, string $user_ids = "", bool $extended = false) + { + $this->requireUser(); + $id = $user_id != NULL ? $user_id : explode(",", $user_ids); + + if($group_id < 0) + $this->fail(228, "Remove the minus from group_id"); + + $club = (new ClubsRepo)->get((int)$group_id); + $usver = (new UsersRepo)->get((int)$id); + + if(!$club || $group_id == 0) + $this->fail(203, "Invalid club"); + + if(!$usver || $user_id == 0) + $this->fail(30, "Invalid user"); + + if($extended == false) { + return $club->getSubscriptionStatus($usver) ? 1 : 0; + } else { + return (object) + [ + "member" => $club->getSubscriptionStatus($usver) ? 1 : 0, + "request" => 0, + "invitation" => 0, + "can_invite" => 0, + "can_recall" => 0 + ]; + } + } + + function remove(int $group_id, int $user_id) + { + $this->requireUser(); + # зоглущка + return 0; + } } diff --git a/VKAPI/Handlers/Notes.php b/VKAPI/Handlers/Notes.php new file mode 100644 index 00000000..1267c9c9 --- /dev/null +++ b/VKAPI/Handlers/Notes.php @@ -0,0 +1,235 @@ +requireUser(); + $this->willExecuteWriteAction(); + + $note = new Note; + $note->setOwner($this->getUser()->getId()); + $note->setCreated(time()); + $note->setName($title); + $note->setSource($text); + $note->setEdited(time()); + $note->save(); + + return $note->getVirtualId(); + } + + function createComment(string $note_id, int $owner_id, string $message, int $reply_to = 0) + { + $this->requireUser(); + $this->willExecuteWriteAction(); + $note = (new NotesRepo)->getNoteById((int)$owner_id, (int)$note_id); + + if(!$note) + $this->fail(180, "Note not found"); + if($note->isDeleted()) + $this->fail(189, "Note is deleted"); + + $comment = new Comment; + $comment->setOwner($this->getUser()->getId()); + $comment->setModel(get_class($note)); + $comment->setTarget($note->getId()); + $comment->setContent($message); + $comment->setCreated(time()); + $comment->save(); + + return $comment->getId(); + } + + function delete(string $note_id) + { + $this->requireUser(); + $this->willExecuteWriteAction(); + + $note = (new NotesRepo)->get((int)$note_id); + + if(!$note) + $this->fail(180, "Note not found"); + + if(!$note->canBeModifiedBy($this->getUser())) + $this->fail(15, "Access to note denied"); + + $note->delete(); + + return 1; + } + + function deleteComment(int $comment_id, int $owner_id = 0) + { + $this->requireUser(); + $this->willExecuteWriteAction(); + + $comment = (new CommentsRepo)->get($comment_id); + + if(!$comment) + $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(); + $this->willExecuteWriteAction(); + + $note = (new NotesRepo)->getNoteById($this->getUser()->getId(), (int)$note_id); + + if(!$note) + $this->fail(180, "Note not found"); + + if($note->isDeleted()) + $this->fail(189, "Note is deleted"); + + !empty($title) ? $note->setName($title) : NULL; + !empty($text) ? $note->setSource($text) : NULL; + + $note->setCached_Content(NULL); + $note->setEdited(time()); + $note->save(); + + 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() != $this->getUser()->getId()) + $this->fail(15, "Access to comment denied"); + + $comment->setContent($message); + $comment->setEdited(time()); + $comment->save(); + + return 1; + } + + function get(int $user_id, string $note_ids = "", int $offset = 0, int $count = 10, int $sort = 0) + { + $this->requireUser(); + $user = (new UsersRepo)->get($user_id); + + if(!$user) + $this->fail(15, "Invalid user"); + + $notes = iterator_to_array((new NotesRepo)->getUserNotes($user, 1, $count, $sort == 0 ? "ASC" : "DESC")); + $nodez = (object) [ + "count" => (new NotesRepo)->getUserNotesCount((new UsersRepo)->get($user_id)), + "notes" => [] + ]; + + foreach($notes as $note) { + if($note->isDeleted()) + continue; + + $apiNote = new APINote; + $apiNote->id = $note->getId(); + $apiNote->owner_id = $note->getOwner()->getId(); + $apiNote->title = $note->getName(); + $apiNote->text = $note->getText(); + $apiNote->date = $note->getPublicationTime()->timestamp(); + $apiNote->comments = $note->getCommentsCount(); + $apiNote->read_comments = $note->getCommentsCount(); + $apiNote->view_url = "/note".$note->getOwner()->getId()."_".$note->getId(); + $apiNote->privacy_view = 1; + $apiNote->can_comment = 1; + $apiNote->text_wiki = "r"; + $nodez->notes[] = $apiNote; + } + + return $nodez; + } + + function getById(int $note_id, int $owner_id, bool $need_wiki = false) + { + $this->requireUser(); + + $note = (new NotesRepo)->getNoteById($owner_id, $note_id); + + if(!$note) + $this->fail(180, "Note not found"); + + if($note->isDeleted()) + $this->fail(189, "Note is deleted"); + + if(!$user || $note->getOwner()->isDeleted()) + $this->fail(177, "Owner does not exists"); + + $apiNote = new APINote; + + $apiNote->id = $note->getId(); + $apiNote->owner_id = $note->getOwner()->getId(); + $apiNote->title = $note->getName(); + $apiNote->text = $note->getText(); + $apiNote->date = $note->getPublicationTime()->timestamp(); + $apiNote->comments = $note->getCommentsCount(); + $apiNote->read_comments = $note->getCommentsCount(); + $apiNote->view_url = "/note".$note->getOwner()->getId()."_".$note->getId(); + $apiNote->privacy_view = 1; + $apiNote->can_comment = 1; + $apiNote->text_wiki = "r"; + + $nodez->notes[] = $apiNote; + + return $apiNote; + } + + function getComments(int $note_id, int $owner_id, int $sort = 1, int $offset = 0, int $count = 100) + { + $note = (new NotesRepo)->getNoteById($owner_id, $note_id); + + if(!$note) + $this->fail(180, "Note not found"); + + if($note->isDeleted()) + $this->fail(189, "Note is deleted"); + + if($note->getOwner()->isDeleted()) + $this->fail(177, "Owner does not exists"); + + $arr = (object) [ + "count" => $note->getCommentsCount(), + "comments" => []]; + $comments = $note->getComments(1, $count); + + foreach($comments as $comment) { + $comm = new APIComment; + $comm->id = $comment->getId(); + $comm->uid = $comment->getOwner()->getId(); + $comm->nid = $note->getId(); + $comm->oid = $note->getOwner()->getId(); + $comm->date = $comment->getPublicationTime()->timestamp(); + $comm->message = $comment->getText(); + $comm->reply_to = 0; + $arr->comments[] = $comm; + } + + return $arr; + } + + function getFriendsNotes(int $offset, int $count) + { + return 1; + } + + function restoreComment(int $comment_id, int $owner_id) + { + $this->fail(4, " "); + } +} diff --git a/VKAPI/Handlers/Status.php b/VKAPI/Handlers/Status.php new file mode 100644 index 00000000..b0c4b0cf --- /dev/null +++ b/VKAPI/Handlers/Status.php @@ -0,0 +1,35 @@ +requireUser(); + if ($user_id == 0 && $group_id == 0) { + return $this->getUser()->getStatus(); + } else { + if ($group_id > 0) + $this->fail(1, "OpenVK has no group statuses"); + else + return (new UsersRepo)->get($user_id)->getStatus(); + } + } + + function set(string $text, int $group_id = 0) + { + $this->requireUser(); + $this->willExecuteWriteAction(); + + if ($group_id > 0) { + $this->fail(1, "OpenVK has no group statuses"); + } else { + $this->getUser()->setStatus($text); + $this->getUser()->save(); + + return 1; + } + } +} diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index c39a3316..ccdda5bf 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -9,6 +9,10 @@ use openvk\Web\Models\Entities\Post; use openvk\Web\Models\Repositories\Posts as PostsRepo; use openvk\Web\Models\Entities\Comment; use openvk\Web\Models\Repositories\Comments as CommentsRepo; +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; final class Wall extends VKAPIRequestHandler { @@ -367,7 +371,7 @@ final class Wall extends VKAPIRequestHandler ]; } - function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0): object + function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0, string $attachments = ""): object { $this->requireUser(); $this->willExecuteWriteAction(); @@ -405,26 +409,6 @@ final class Wall extends VKAPIRequestHandler if($signed == 1) $flags |= 0b01000000; - # TODO: Compatible implementation of this - try { - $photo = NULL; - $video = NULL; - if($_FILES["photo"]["error"] === UPLOAD_ERR_OK) { - $album = NULL; - if(!$anon && $owner_id > 0 && $owner_id === $this->getUser()->getId()) - $album = (new AlbumsRepo)->getUserWallAlbum($wallOwner); - - $photo = Photo::fastMake($this->getUser()->getId(), $message, $_FILES["photo"], $album, $anon); - } - - if($_FILES["video"]["error"] === UPLOAD_ERR_OK) - $video = Video::fastMake($this->getUser()->getId(), $message, $_FILES["video"], $anon); - } catch(\DomainException $ex) { - $this->fail(-156, "The media file is corrupted"); - } catch(ISE $ex) { - $this->fail(-156, "The media file is corrupted or too large "); - } - if(empty($message) && !$photo && !$video) $this->fail(100, "Required parameter 'message' missing."); @@ -441,11 +425,35 @@ final class Wall extends VKAPIRequestHandler $this->fail(100, "One of the parameters specified was missing or invalid"); } - if(!is_null($photo)) - $post->attach($photo); + if(!empty($attachments)) { + $att = explode(" ", $attachments); + $attachmentType = $att[0]; + # Аттачи такого вида: [тип] [id владельца]_[id вложения] + # Пример: photo 1_1 - if(!is_null($video)) - $post->attach($video); + $attachmentOwner = (int)explode("_", $att[1])[0]; + $attachmentId = (int)end(explode("_", $att[1])); + + $attacc = NULL; + + if($attachmentType == "photo") { + $attacc = (new PhotosRepo)->getByOwnerAndVID($attachmentOwner, $attachmentId); + if(is_null($attacc)) + $this->fail(100, "Photo does not exists"); + if($attacc->getOwner()->getId() != $this->getUser()->getId()) + $this->fail(43, "You do not have access to this photo"); + + $post->attach($attacc); + } elseif($attachmentType == "video") { + $attacc = (new VideosRepo)->getByOwnerAndVID($attachmentOwner, $attachmentId); + if(!$attacc) + $this->fail(100, "Video does not exists"); + if($attacc->getOwner()->getId() != $this->getUser()->getId()) + $this->fail(43, "You do not have access to this video"); + + $post->attach($attacc); + } + } if($wall > 0 && $wall !== $this->user->identity->getId()) (new WallPostNotification($wallOwner, $post, $this->user->identity))->emit(); diff --git a/VKAPI/Structures/Comment.php b/VKAPI/Structures/Comment.php new file mode 100644 index 00000000..c8509b82 --- /dev/null +++ b/VKAPI/Structures/Comment.php @@ -0,0 +1,13 @@ +