diff --git a/VKAPI/Handlers/Gifts.php b/VKAPI/Handlers/Gifts.php index 1cf7a6b1..f4c3d301 100644 --- a/VKAPI/Handlers/Gifts.php +++ b/VKAPI/Handlers/Gifts.php @@ -6,7 +6,7 @@ use openvk\Web\Models\Entities\Notifications\GiftNotification; final class Gifts extends VKAPIRequestHandler { - function get(int $user_id, int $count = 100, int $offset = 0) + function get(int $user_id, int $count = 10, int $offset = 0) { $this->requireUser(); @@ -54,10 +54,17 @@ final class Gifts extends VKAPIRequestHandler $this->willExecuteWriteAction(); $user = (new UsersRepo)->get((int) $user_ids); + if(OPENVK_ROOT_CONF['openvk']['preferences']['commerce'] == false) + $this->fail(105, "Commerce is disabled on this instance"); + if(!$user || $user->isDeleted()) $this->fail(177, "Invalid user"); - + $gift = (new GiftsRepo)->get($gift_id); + + if(!$gift) + $this->fail(165, "Invalid gift"); + $price = $gift->getPrice(); $coinsLeft = $this->getUser()->getCoins() - $price; @@ -103,128 +110,53 @@ final class Gifts extends VKAPIRequestHandler } # этих методов не было в ВК, но я их добавил чтобы можно было отобразить список подарков - function getCategories(bool $extended = false, int $count = 10, int $offset = 0) + function getCategories(bool $extended = false, int $page = 1) { - $cats = (new GiftsRepo)->getCategories(1, $count); + $cats = (new GiftsRepo)->getCategories($page); $categ = []; - $i = 1; + $i = 0; 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 ? + $categ[$i] = [ + "name" => $cat->getName(), + "description" => $cat->getDescription(), + "id" => $cat->getId(), + "thumbnail" => $cat->getThumbnailURL(), + ]; + if($extended == true) { + $categ[$i]["localizations"] = []; + foreach(getLanguages() as $lang) { + $code = $lang["code"]; + $categ[$i]["localizations"][$code] = [ - "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++; + "name" => $cat->getName($code), + "desc" => $cat->getDescription($code), + ]; + } } + $i++; } return $categ; } - function getGiftsInCategory(int $id, int $count = 10, int $offset = 0) + function getGiftsInCategory(int $id, int $page = 1) { $this->requireUser(); if(!(new GiftsRepo)->getCat($id)) $this->fail(177, "Category not found"); - $giftz = ((new GiftsRepo)->getCat($id))->getGifts(1, $count); + $giftz = ((new GiftsRepo)->getCat($id))->getGifts($page); $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++; - } + $gifts[] = [ + "name" => $gift->getName(), + "image" => $gift->getImage(2), + "usages_left" => (int)$gift->getUsagesLeft($this->getUser()), + "price" => $gift->getPrice(), # голосов + "is_free" => $gift->isFree() + ]; } return $gifts; diff --git a/VKAPI/Handlers/Groups.php b/VKAPI/Handlers/Groups.php index b743eab8..274cc398 100644 --- a/VKAPI/Handlers/Groups.php +++ b/VKAPI/Handlers/Groups.php @@ -2,7 +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}; +use openvk\Web\Models\Entities\Club; final class Groups extends VKAPIRequestHandler { @@ -292,51 +292,16 @@ final class Groups extends VKAPIRequestHandler 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 - ) + int $hideFromGlobalFeed = 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."); + if(!$club) $this->fail(203, "Club not found"); + 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; @@ -382,8 +347,7 @@ final class Groups extends VKAPIRequestHandler $filds = explode(",", $fields); $i = 0; - foreach($members as $member) - { + foreach($members as $member) { if($i > $count) { break; } @@ -394,35 +358,95 @@ final class Groups extends VKAPIRequestHandler ]; 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; + switch($fild) { + case "bdate": + $arr->items[$i]->bdate = $member->getBirthday()->format('%e.%m.%Y'); + break; + case "can_post": + $arr->items[$i]->can_post = $club->canBeModifiedBy($member); + break; + case "can_see_all_posts": + $arr->items[$i]->can_see_all_posts = 1; + break; + case "can_see_audio": + $arr->items[$i]->can_see_audio = 0; + break; + case "can_write_private_message": + $arr->items[$i]->can_write_private_message = 0; + break; + case "common_count": + $arr->items[$i]->common_count = 420; + break; + case "connections": + $arr->items[$i]->connections = 1; + break; + case "contacts": + $arr->items[$i]->contacts = $member->getContactEmail(); + break; + case "country": + $arr->items[$i]->country = 1; + break; + case "domain": + $arr->items[$i]->domain = ""; + break; + case "education": + $arr->items[$i]->education = ""; + break; + case "has_mobile": + $arr->items[$i]->has_mobile = false; + break; + case "last_seen": + $arr->items[$i]->last_seen = $member->getOnline()->timestamp(); + break; + case "lists": + $arr->items[$i]->lists = ""; + break; + case "online": + $arr->items[$i]->online = $member->isOnline(); + break; + case "online_mobile": + $arr->items[$i]->online_mobile = $member->getOnlinePlatform() == "android" || $member->getOnlinePlatform() == "iphone" || $member->getOnlinePlatform() == "mobile"; + break; + case "photo_100": + $arr->items[$i]->photo_100 = $member->getAvatarURL("tiny"); + break; + case "photo_200": + $arr->items[$i]->photo_200 = $member->getAvatarURL("normal"); + break; + case "photo_200_orig": + $arr->items[$i]->photo_200_orig = $member->getAvatarURL("normal"); + break; + case "photo_400_orig": + $arr->items[$i]->photo_400_orig = $member->getAvatarURL("normal"); + break; + case "photo_max": + $arr->items[$i]->photo_max = $member->getAvatarURL("original"); + break; + case "photo_max_orig": + $arr->items[$i]->photo_max_orig = $member->getAvatarURL(); + break; + case "relation": + $arr->items[$i]->relation = $member->getMaritalStatus(); + break; + case "relatives": + $arr->items[$i]->relatives = 0; + break; + case "schools": + $arr->items[$i]->schools = 0; + break; + case "sex": + $arr->items[$i]->sex = $member->isFemale() ? 1 : 2; + break; + case "site": + $arr->items[$i]->site = $member->getWebsite(); + break; + case "status": + $arr->items[$i]->status = $member->getStatus(); + break; + case "universities": + $arr->items[$i]->universities = 0; + break; + } } $i++; } diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index ccdda5bf..ef40fe00 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -409,7 +409,7 @@ final class Wall extends VKAPIRequestHandler if($signed == 1) $flags |= 0b01000000; - if(empty($message) && !$photo && !$video) + if(empty($message) && empty($attachments)) $this->fail(100, "Required parameter 'message' missing."); try { @@ -426,32 +426,47 @@ final class Wall extends VKAPIRequestHandler } if(!empty($attachments)) { - $att = explode(" ", $attachments); - $attachmentType = $att[0]; - # Аттачи такого вида: [тип] [id владельца]_[id вложения] - # Пример: photo 1_1 + $attachmentsArr = explode(",", $attachments); + # Аттачи такого вида: [тип][id владельца]_[id вложения] + # Пример: photo1_1 - $attachmentOwner = (int)explode("_", $att[1])[0]; - $attachmentId = (int)end(explode("_", $att[1])); + if(count($attachmentsArr) > 10) + $this->fail(50, "Error: too many attachments"); + + foreach($attachmentsArr as $attac) { + $attachmentType = NULL; - $attacc = NULL; + if(str_contains($attac, "photo")) + $attachmentType = "photo"; + elseif(str_contains($attac, "video")) + $attachmentType = "video"; + else + $this->fail(205, "Unknown attachment type"); - 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"); + $attachment = str_replace($attachmentType, "", $attac); - $post->attach($attacc); + $attachmentOwner = (int)explode("_", $attachment)[0]; + $attachmentId = (int)end(explode("_", $attachment)); + + $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); + } } } diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index db5baa88..ada5de8e 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -262,12 +262,12 @@ class Club extends RowModel return $subbed && ($this->getOpennesStatus() === static::CLOSED ? $this->isSubscriptionAccepted($user) : true); } - function getFollowersQuery(): GroupedSelection + function getFollowersQuery(string $sort = "follower ASC"): GroupedSelection { $query = $this->getRecord()->related("subscriptions.target"); if($this->getOpennesStatus() === static::OPEN) { - $query = $query->where("model", "openvk\\Web\\Models\\Entities\\Club"); + $query = $query->where("model", "openvk\\Web\\Models\\Entities\\Club")->order($sort); } else { return false; } @@ -280,9 +280,9 @@ class Club extends RowModel return sizeof($this->getFollowersQuery()); } - function getFollowers(int $page = 1): \Traversable + function getFollowers(int $page = 1, int $perPage = 6, string $sort = "follower ASC"): \Traversable { - $rels = $this->getFollowersQuery()->page($page, 6); + $rels = $this->getFollowersQuery($sort)->page($page, $perPage); foreach($rels as $rel) { $rel = (new Users)->get($rel->follower);