2020-08-12 14:36:18 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\VKAPI\Handlers;
|
|
|
|
use openvk\Web\Models\Entities\User;
|
2022-07-23 15:50:00 +03:00
|
|
|
use openvk\Web\Models\Entities\Notifications\{WallPostNotification, RepostNotification, CommentNotification};
|
2020-08-12 14:36:18 +03:00
|
|
|
use openvk\Web\Models\Repositories\Users as UsersRepo;
|
2020-11-01 01:36:35 +03:00
|
|
|
use openvk\Web\Models\Entities\Club;
|
|
|
|
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
|
2020-08-12 14:36:18 +03:00
|
|
|
use openvk\Web\Models\Entities\Post;
|
|
|
|
use openvk\Web\Models\Repositories\Posts as PostsRepo;
|
2022-07-23 15:50:00 +03:00
|
|
|
use openvk\Web\Models\Entities\Comment;
|
|
|
|
use openvk\Web\Models\Repositories\Comments as CommentsRepo;
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
|
|
final class Wall extends VKAPIRequestHandler
|
|
|
|
{
|
2022-07-31 13:25:00 +03:00
|
|
|
function get(int $owner_id, string $domain = "", int $offset = 0, int $count = 30, int $extended = 0): object
|
2020-08-12 14:36:18 +03:00
|
|
|
{
|
2022-12-22 01:05:49 +03:00
|
|
|
$this->requireUser();
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
$posts = new PostsRepo;
|
2020-08-12 14:36:18 +03:00
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
$items = [];
|
2021-11-24 22:24:44 +03:00
|
|
|
$profiles = [];
|
2022-07-21 22:13:09 +03:00
|
|
|
$groups = [];
|
2022-08-21 00:30:56 +03:00
|
|
|
$cnt = $posts->getPostCountOnUserWall($owner_id);
|
2020-08-12 14:36:18 +03:00
|
|
|
|
2022-10-11 03:25:20 +03:00
|
|
|
if ($owner_id > 0)
|
|
|
|
$wallOnwer = (new UsersRepo)->get($owner_id);
|
|
|
|
else
|
|
|
|
$wallOnwer = (new ClubsRepo)->get($owner_id * -1);
|
2022-07-31 13:25:00 +03:00
|
|
|
|
2022-10-11 03:25:20 +03:00
|
|
|
if ($owner_id > 0)
|
|
|
|
if(!$wallOnwer || $wallOnwer->isDeleted())
|
|
|
|
$this->fail(18, "User was deleted or banned");
|
|
|
|
else
|
|
|
|
if(!$wallOnwer)
|
|
|
|
$this->fail(15, "Access denied: wall is disabled"); // Don't search for logic here pls
|
2022-07-31 13:25:00 +03:00
|
|
|
|
|
|
|
foreach($posts->getPostsFromUsersWall($owner_id, 1, $count, $offset) as $post) {
|
2021-11-24 22:24:44 +03:00
|
|
|
$from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();
|
2022-03-25 14:05:44 +03:00
|
|
|
|
2022-05-01 17:04:59 +03:00
|
|
|
$attachments = [];
|
2022-07-23 03:25:17 +03:00
|
|
|
$repost = [];
|
2022-05-01 17:04:59 +03:00
|
|
|
foreach($post->getChildren() as $attachment) {
|
|
|
|
if($attachment instanceof \openvk\Web\Models\Entities\Photo) {
|
|
|
|
if($attachment->isDeleted())
|
|
|
|
continue;
|
|
|
|
|
2022-07-23 03:25:17 +03:00
|
|
|
$attachments[] = $this->getApiPhoto($attachment);
|
2022-10-12 01:00:52 +03:00
|
|
|
} else if($attachment instanceof \openvk\Web\Models\Entities\Poll) {
|
2022-10-12 12:23:57 +03:00
|
|
|
$attachments[] = $this->getApiPoll($attachment, $this->getUser());
|
2022-07-23 03:25:17 +03:00
|
|
|
} else if ($attachment instanceof \openvk\Web\Models\Entities\Post) {
|
|
|
|
$repostAttachments = [];
|
|
|
|
|
|
|
|
foreach($attachment->getChildren() as $repostAttachment) {
|
|
|
|
if($repostAttachment instanceof \openvk\Web\Models\Entities\Photo) {
|
2022-10-09 17:39:22 +03:00
|
|
|
if($repostAttachment->isDeleted())
|
2022-07-23 03:25:17 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
$repostAttachments[] = $this->getApiPhoto($repostAttachment);
|
|
|
|
/* Рекурсии, сука! Заказывали? */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-25 13:18:02 +03:00
|
|
|
if ($attachment->isPostedOnBehalfOfGroup())
|
|
|
|
$groups[] = $attachment->getOwner()->getId();
|
|
|
|
else
|
|
|
|
$profiles[] = $attachment->getOwner()->getId();
|
2022-10-17 23:24:10 +03:00
|
|
|
|
2022-12-17 02:03:02 +03:00
|
|
|
$post_source = [];
|
|
|
|
|
|
|
|
if($attachment->getPlatform(true) === NULL) {
|
|
|
|
$post_source = (object)["type" => "vk"];
|
|
|
|
} else {
|
|
|
|
$post_source = (object)[
|
|
|
|
"type" => "api",
|
|
|
|
"platform" => $attachment->getPlatform(true)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-07-23 03:25:17 +03:00
|
|
|
$repost[] = [
|
|
|
|
"id" => $attachment->getVirtualId(),
|
2022-07-23 03:39:05 +03:00
|
|
|
"owner_id" => $attachment->isPostedOnBehalfOfGroup() ? $attachment->getOwner()->getId() * -1 : $attachment->getOwner()->getId(),
|
|
|
|
"from_id" => $attachment->isPostedOnBehalfOfGroup() ? $attachment->getOwner()->getId() * -1 : $attachment->getOwner()->getId(),
|
2022-07-23 03:25:17 +03:00
|
|
|
"date" => $attachment->getPublicationTime()->timestamp(),
|
|
|
|
"post_type" => "post",
|
|
|
|
"text" => $attachment->getText(false),
|
|
|
|
"attachments" => $repostAttachments,
|
2022-12-17 02:03:02 +03:00
|
|
|
"post_source" => $post_source,
|
2022-03-25 14:05:44 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-17 02:03:02 +03:00
|
|
|
$post_source = [];
|
|
|
|
|
2022-12-17 03:20:14 +03:00
|
|
|
if($post->getPlatform(true) === NULL) {
|
2022-12-17 02:03:02 +03:00
|
|
|
$post_source = (object)["type" => "vk"];
|
|
|
|
} else {
|
|
|
|
$post_source = (object)[
|
|
|
|
"type" => "api",
|
2022-12-17 03:20:14 +03:00
|
|
|
"platform" => $post->getPlatform(true)
|
2022-12-17 02:03:02 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-12 14:36:18 +03:00
|
|
|
$items[] = (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"id" => $post->getVirtualId(),
|
|
|
|
"from_id" => $from_id,
|
|
|
|
"owner_id" => $post->getTargetWall(),
|
|
|
|
"date" => $post->getPublicationTime()->timestamp(),
|
|
|
|
"post_type" => "post",
|
|
|
|
"text" => $post->getText(false),
|
2022-07-23 03:25:17 +03:00
|
|
|
"copy_history" => $repost,
|
2022-07-21 22:13:09 +03:00
|
|
|
"can_edit" => 0, # TODO
|
|
|
|
"can_delete" => $post->canBeDeletedBy($this->getUser()),
|
|
|
|
"can_pin" => $post->canBePinnedBy($this->getUser()),
|
|
|
|
"can_archive" => false, # TODO MAYBE
|
|
|
|
"is_archived" => false,
|
|
|
|
"is_pinned" => $post->isPinned(),
|
|
|
|
"attachments" => $attachments,
|
2022-12-17 02:03:02 +03:00
|
|
|
"post_source" => $post_source,
|
2022-07-21 22:13:09 +03:00
|
|
|
"comments" => (object)[
|
|
|
|
"count" => $post->getCommentsCount(),
|
2020-08-12 14:36:18 +03:00
|
|
|
"can_post" => 1
|
|
|
|
],
|
|
|
|
"likes" => (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"count" => $post->getLikesCount(),
|
|
|
|
"user_likes" => (int) $post->hasLikeFrom($this->getUser()),
|
|
|
|
"can_like" => 1,
|
2020-08-12 14:36:18 +03:00
|
|
|
"can_publish" => 1,
|
|
|
|
],
|
|
|
|
"reposts" => (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"count" => $post->getRepostCount(),
|
2020-08-12 14:36:18 +03:00
|
|
|
"user_reposted" => 0
|
|
|
|
]
|
|
|
|
];
|
2021-11-24 22:24:44 +03:00
|
|
|
|
|
|
|
if ($from_id > 0)
|
|
|
|
$profiles[] = $from_id;
|
|
|
|
else
|
2022-07-21 22:13:09 +03:00
|
|
|
$groups[] = $from_id * -1;
|
2022-03-25 22:29:29 +03:00
|
|
|
|
2022-05-08 13:06:26 +03:00
|
|
|
$attachments = NULL; # free attachments so it will not clone everythingg
|
2020-08-12 14:36:18 +03:00
|
|
|
}
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
if($extended == 1) {
|
2021-11-24 22:24:44 +03:00
|
|
|
$profiles = array_unique($profiles);
|
2022-07-21 22:13:09 +03:00
|
|
|
$groups = array_unique($groups);
|
2021-11-24 22:24:44 +03:00
|
|
|
|
|
|
|
$profilesFormatted = [];
|
2022-07-21 22:13:09 +03:00
|
|
|
$groupsFormatted = [];
|
2020-08-12 14:36:18 +03:00
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
foreach($profiles as $prof) {
|
|
|
|
$user = (new UsersRepo)->get($prof);
|
2021-11-24 22:24:44 +03:00
|
|
|
$profilesFormatted[] = (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"first_name" => $user->getFirstName(),
|
|
|
|
"id" => $user->getId(),
|
|
|
|
"last_name" => $user->getLastName(),
|
2021-11-24 22:24:44 +03:00
|
|
|
"can_access_closed" => false,
|
2022-07-21 22:13:09 +03:00
|
|
|
"is_closed" => false,
|
|
|
|
"sex" => $user->isFemale() ? 1 : 2,
|
|
|
|
"screen_name" => $user->getShortCode(),
|
|
|
|
"photo_50" => $user->getAvatarUrl(),
|
|
|
|
"photo_100" => $user->getAvatarUrl(),
|
|
|
|
"online" => $user->isOnline()
|
2021-11-24 22:24:44 +03:00
|
|
|
];
|
|
|
|
}
|
2020-08-12 14:36:18 +03:00
|
|
|
|
2021-11-24 22:24:44 +03:00
|
|
|
foreach($groups as $g) {
|
2022-07-21 22:13:09 +03:00
|
|
|
$group = (new ClubsRepo)->get($g);
|
2021-11-24 22:24:44 +03:00
|
|
|
$groupsFormatted[] = (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"id" => $group->getId(),
|
|
|
|
"name" => $group->getName(),
|
2021-11-24 22:24:44 +03:00
|
|
|
"screen_name" => $group->getShortCode(),
|
2022-07-21 22:13:09 +03:00
|
|
|
"is_closed" => 0,
|
|
|
|
"type" => "group",
|
|
|
|
"photo_50" => $group->getAvatarUrl(),
|
|
|
|
"photo_100" => $group->getAvatarUrl(),
|
|
|
|
"photo_200" => $group->getAvatarUrl(),
|
2021-11-24 22:24:44 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
return (object) [
|
2022-08-21 00:30:56 +03:00
|
|
|
"count" => $cnt,
|
|
|
|
"items" => $items,
|
|
|
|
"profiles" => $profilesFormatted,
|
|
|
|
"groups" => $groupsFormatted
|
2021-11-24 22:24:44 +03:00
|
|
|
];
|
2022-07-21 22:13:09 +03:00
|
|
|
} else
|
|
|
|
return (object) [
|
2022-08-21 00:30:56 +03:00
|
|
|
"count" => $cnt,
|
|
|
|
"items" => $items
|
2021-11-24 22:24:44 +03:00
|
|
|
];
|
2020-08-12 14:36:18 +03:00
|
|
|
}
|
2020-11-01 01:36:35 +03:00
|
|
|
|
2022-05-08 13:06:26 +03:00
|
|
|
function getById(string $posts, int $extended = 0, string $fields = "", User $user = NULL)
|
2022-03-19 03:31:27 +03:00
|
|
|
{
|
2022-07-24 00:42:28 +03:00
|
|
|
if($user == NULL) {
|
|
|
|
$this->requireUser();
|
2022-07-21 22:13:09 +03:00
|
|
|
$user = $this->getUser(); # костыли костыли крылышки
|
2022-07-24 00:42:28 +03:00
|
|
|
}
|
2022-03-19 03:31:27 +03:00
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
$items = [];
|
2022-03-19 03:31:27 +03:00
|
|
|
$profiles = [];
|
2022-07-21 22:13:09 +03:00
|
|
|
$groups = [];
|
2022-03-19 03:31:27 +03:00
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
$psts = explode(',', $posts);
|
2022-03-19 03:31:27 +03:00
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
foreach($psts as $pst) {
|
|
|
|
$id = explode("_", $pst);
|
2022-03-19 03:31:27 +03:00
|
|
|
$post = (new PostsRepo)->getPostById(intval($id[0]), intval($id[1]));
|
|
|
|
if($post) {
|
|
|
|
$from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();
|
2022-07-23 03:25:17 +03:00
|
|
|
$attachments = [];
|
|
|
|
$repost = []; // чел высрал семь сигарет 😳 помянем 🕯
|
2022-07-21 22:13:09 +03:00
|
|
|
foreach($post->getChildren() as $attachment) {
|
|
|
|
if($attachment instanceof \openvk\Web\Models\Entities\Photo) {
|
2022-07-23 03:25:17 +03:00
|
|
|
$attachments[] = $this->getApiPhoto($attachment);
|
2022-10-12 01:00:52 +03:00
|
|
|
} else if($attachment instanceof \openvk\Web\Models\Entities\Poll) {
|
2022-10-12 12:23:57 +03:00
|
|
|
$attachments[] = $this->getApiPoll($attachment, $user);
|
2022-07-23 03:25:17 +03:00
|
|
|
} else if ($attachment instanceof \openvk\Web\Models\Entities\Post) {
|
|
|
|
$repostAttachments = [];
|
|
|
|
|
|
|
|
foreach($attachment->getChildren() as $repostAttachment) {
|
|
|
|
if($repostAttachment instanceof \openvk\Web\Models\Entities\Photo) {
|
|
|
|
if($attachment->isDeleted())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
$repostAttachments[] = $this->getApiPhoto($repostAttachment);
|
|
|
|
/* Рекурсии, сука! Заказывали? */
|
|
|
|
}
|
2022-10-17 23:24:10 +03:00
|
|
|
}
|
|
|
|
|
2022-10-24 19:05:41 +03:00
|
|
|
if ($attachment->isPostedOnBehalfOfGroup())
|
|
|
|
$groups[] = $attachment->getOwner()->getId();
|
|
|
|
else
|
|
|
|
$profiles[] = $attachment->getOwner()->getId();
|
2022-07-23 03:25:17 +03:00
|
|
|
|
2022-12-17 02:03:02 +03:00
|
|
|
$post_source = [];
|
|
|
|
|
|
|
|
if($attachment->getPlatform(true) === NULL) {
|
|
|
|
$post_source = (object)["type" => "vk"];
|
|
|
|
} else {
|
|
|
|
$post_source = (object)[
|
|
|
|
"type" => "api",
|
|
|
|
"platform" => $attachment->getPlatform(true)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-07-23 03:25:17 +03:00
|
|
|
$repost[] = [
|
|
|
|
"id" => $attachment->getVirtualId(),
|
2022-07-23 03:39:05 +03:00
|
|
|
"owner_id" => $attachment->isPostedOnBehalfOfGroup() ? $attachment->getOwner()->getId() * -1 : $attachment->getOwner()->getId(),
|
|
|
|
"from_id" => $attachment->isPostedOnBehalfOfGroup() ? $attachment->getOwner()->getId() * -1 : $attachment->getOwner()->getId(),
|
2022-07-23 03:25:17 +03:00
|
|
|
"date" => $attachment->getPublicationTime()->timestamp(),
|
|
|
|
"post_type" => "post",
|
|
|
|
"text" => $attachment->getText(false),
|
|
|
|
"attachments" => $repostAttachments,
|
2022-12-17 02:03:02 +03:00
|
|
|
"post_source" => $post_source,
|
2022-03-25 14:05:44 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-17 02:03:02 +03:00
|
|
|
$post_source = [];
|
|
|
|
|
|
|
|
if($post->getPlatform(true) === NULL) {
|
|
|
|
$post_source = (object)["type" => "vk"];
|
|
|
|
} else {
|
|
|
|
$post_source = (object)[
|
|
|
|
"type" => "api",
|
|
|
|
"platform" => $post->getPlatform(true)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-03-19 03:31:27 +03:00
|
|
|
$items[] = (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"id" => $post->getVirtualId(),
|
|
|
|
"from_id" => $from_id,
|
|
|
|
"owner_id" => $post->getTargetWall(),
|
|
|
|
"date" => $post->getPublicationTime()->timestamp(),
|
|
|
|
"post_type" => "post",
|
|
|
|
"text" => $post->getText(false),
|
2022-07-23 03:25:17 +03:00
|
|
|
"copy_history" => $repost,
|
2022-07-21 22:13:09 +03:00
|
|
|
"can_edit" => 0, # TODO
|
|
|
|
"can_delete" => $post->canBeDeletedBy($user),
|
|
|
|
"can_pin" => $post->canBePinnedBy($user),
|
|
|
|
"can_archive" => false, # TODO MAYBE
|
|
|
|
"is_archived" => false,
|
|
|
|
"is_pinned" => $post->isPinned(),
|
2022-12-17 02:03:02 +03:00
|
|
|
"post_source" => $post_source,
|
2022-07-21 22:13:09 +03:00
|
|
|
"attachments" => $attachments,
|
|
|
|
"comments" => (object)[
|
|
|
|
"count" => $post->getCommentsCount(),
|
2022-03-19 03:31:27 +03:00
|
|
|
"can_post" => 1
|
|
|
|
],
|
|
|
|
"likes" => (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"count" => $post->getLikesCount(),
|
|
|
|
"user_likes" => (int) $post->hasLikeFrom($user),
|
|
|
|
"can_like" => 1,
|
2022-03-19 03:31:27 +03:00
|
|
|
"can_publish" => 1,
|
|
|
|
],
|
|
|
|
"reposts" => (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"count" => $post->getRepostCount(),
|
2022-03-19 03:31:27 +03:00
|
|
|
"user_reposted" => 0
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($from_id > 0)
|
|
|
|
$profiles[] = $from_id;
|
|
|
|
else
|
2022-07-21 22:13:09 +03:00
|
|
|
$groups[] = $from_id * -1;
|
2022-03-25 22:29:29 +03:00
|
|
|
|
2022-07-23 03:25:17 +03:00
|
|
|
$attachments = NULL; # free attachments so it will not clone everything
|
|
|
|
$repost = NULL; # same
|
2022-03-19 03:31:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
if($extended == 1) {
|
2022-03-19 03:31:27 +03:00
|
|
|
$profiles = array_unique($profiles);
|
2022-07-21 22:13:09 +03:00
|
|
|
$groups = array_unique($groups);
|
2022-03-19 03:31:27 +03:00
|
|
|
|
|
|
|
$profilesFormatted = [];
|
2022-07-21 22:13:09 +03:00
|
|
|
$groupsFormatted = [];
|
2022-03-19 03:31:27 +03:00
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
foreach($profiles as $prof) {
|
|
|
|
$user = (new UsersRepo)->get($prof);
|
2022-03-19 03:31:27 +03:00
|
|
|
$profilesFormatted[] = (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"first_name" => $user->getFirstName(),
|
|
|
|
"id" => $user->getId(),
|
|
|
|
"last_name" => $user->getLastName(),
|
2022-03-19 03:31:27 +03:00
|
|
|
"can_access_closed" => false,
|
2022-07-21 22:13:09 +03:00
|
|
|
"is_closed" => false,
|
|
|
|
"sex" => $user->isFemale() ? 1 : 2,
|
|
|
|
"screen_name" => $user->getShortCode(),
|
|
|
|
"photo_50" => $user->getAvatarUrl(),
|
|
|
|
"photo_100" => $user->getAvatarUrl(),
|
|
|
|
"online" => $user->isOnline()
|
2022-03-19 03:31:27 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($groups as $g) {
|
2022-07-21 22:13:09 +03:00
|
|
|
$group = (new ClubsRepo)->get($g);
|
2022-03-19 03:31:27 +03:00
|
|
|
$groupsFormatted[] = (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
"id" => $group->getId(),
|
|
|
|
"name" => $group->getName(),
|
|
|
|
"screen_name" => $group->getShortCode(),
|
|
|
|
"is_closed" => 0,
|
|
|
|
"type" => "group",
|
|
|
|
"photo_50" => $group->getAvatarUrl(),
|
|
|
|
"photo_100" => $group->getAvatarUrl(),
|
|
|
|
"photo_200" => $group->getAvatarUrl(),
|
2022-03-19 03:31:27 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
return (object) [
|
|
|
|
"items" => (array)$items,
|
2022-03-19 03:31:27 +03:00
|
|
|
"profiles" => (array)$profilesFormatted,
|
2022-07-21 22:13:09 +03:00
|
|
|
"groups" => (array)$groupsFormatted
|
2022-03-19 03:31:27 +03:00
|
|
|
];
|
2022-07-21 22:13:09 +03:00
|
|
|
} else
|
|
|
|
return (object) [
|
2022-03-19 03:31:27 +03:00
|
|
|
"items" => (array)$items
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-01-15 19:50:03 +03:00
|
|
|
function post(string $owner_id, string $message = "", int $from_group = 0, int $signed = 0): object
|
2020-11-01 01:36:35 +03:00
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
$owner_id = intval($owner_id);
|
2020-11-01 01:36:35 +03:00
|
|
|
|
|
|
|
$wallOwner = ($owner_id > 0 ? (new UsersRepo)->get($owner_id) : (new ClubsRepo)->get($owner_id * -1))
|
|
|
|
?? $this->fail(18, "User was deleted or banned");
|
|
|
|
if($owner_id > 0)
|
|
|
|
$canPost = $wallOwner->getPrivacyPermission("wall.write", $this->getUser());
|
|
|
|
else if($owner_id < 0)
|
|
|
|
if($wallOwner->canBeModifiedBy($this->getUser()))
|
|
|
|
$canPost = true;
|
|
|
|
else
|
|
|
|
$canPost = $wallOwner->canPost();
|
|
|
|
else
|
|
|
|
$canPost = false;
|
|
|
|
|
|
|
|
if($canPost == false) $this->fail(15, "Access denied");
|
|
|
|
|
2022-01-15 18:15:37 +03:00
|
|
|
$anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"];
|
|
|
|
if($wallOwner instanceof Club && $from_group == 1 && $signed != 1 && $anon) {
|
|
|
|
$manager = $wallOwner->getManager($this->getUser());
|
|
|
|
if($manager)
|
|
|
|
$anon = $manager->isHidden();
|
|
|
|
elseif($this->getUser()->getId() === $wallOwner->getOwner()->getId())
|
|
|
|
$anon = $wallOwner->isOwnerHidden();
|
|
|
|
} else {
|
|
|
|
$anon = false;
|
|
|
|
}
|
|
|
|
|
2020-11-01 01:36:35 +03:00
|
|
|
$flags = 0;
|
2022-01-15 18:51:04 +03:00
|
|
|
if($from_group == 1 && $wallOwner instanceof Club && $wallOwner->canBeModifiedBy($this->getUser()))
|
2020-11-01 01:36:35 +03:00
|
|
|
$flags |= 0b10000000;
|
2021-11-15 11:43:15 +03:00
|
|
|
if($signed == 1)
|
|
|
|
$flags |= 0b01000000;
|
2020-11-01 01:36:35 +03:00
|
|
|
|
2022-05-08 13:06:26 +03:00
|
|
|
# TODO: Compatible implementation of this
|
2022-01-15 18:15:37 +03:00
|
|
|
try {
|
2022-05-08 13:06:26 +03:00
|
|
|
$photo = NULL;
|
|
|
|
$video = NULL;
|
2022-01-15 18:15:37 +03:00
|
|
|
if($_FILES["photo"]["error"] === UPLOAD_ERR_OK) {
|
2022-05-08 13:06:26 +03:00
|
|
|
$album = NULL;
|
2022-01-15 18:15:37 +03:00
|
|
|
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 ");
|
|
|
|
}
|
|
|
|
|
2022-01-15 19:50:03 +03:00
|
|
|
if(empty($message) && !$photo && !$video)
|
|
|
|
$this->fail(100, "Required parameter 'message' missing.");
|
|
|
|
|
2020-11-01 01:36:35 +03:00
|
|
|
try {
|
|
|
|
$post = new Post;
|
|
|
|
$post->setOwner($this->getUser()->getId());
|
|
|
|
$post->setWall($owner_id);
|
|
|
|
$post->setCreated(time());
|
|
|
|
$post->setContent($message);
|
|
|
|
$post->setFlags($flags);
|
2022-12-17 02:03:02 +03:00
|
|
|
$post->setApi_Source_Name($this->getPlatform());
|
2020-11-01 01:36:35 +03:00
|
|
|
$post->save();
|
|
|
|
} catch(\LogicException $ex) {
|
|
|
|
$this->fail(100, "One of the parameters specified was missing or invalid");
|
|
|
|
}
|
|
|
|
|
2022-01-15 18:15:37 +03:00
|
|
|
if(!is_null($photo))
|
|
|
|
$post->attach($photo);
|
|
|
|
|
|
|
|
if(!is_null($video))
|
|
|
|
$post->attach($video);
|
|
|
|
|
2020-11-01 01:36:35 +03:00
|
|
|
if($wall > 0 && $wall !== $this->user->identity->getId())
|
|
|
|
(new WallPostNotification($wallOwner, $post, $this->user->identity))->emit();
|
|
|
|
|
|
|
|
return (object)["post_id" => $post->getVirtualId()];
|
|
|
|
}
|
2022-07-23 02:24:34 +03:00
|
|
|
|
2022-07-23 03:25:17 +03:00
|
|
|
function repost(string $object, string $message = "") {
|
2022-07-23 02:24:34 +03:00
|
|
|
$this->requireUser();
|
|
|
|
|
|
|
|
$postArray;
|
|
|
|
if(preg_match('/wall((?:-?)[0-9]+)_([0-9]+)/', $object, $postArray) == 0)
|
|
|
|
$this->fail(100, "One of the parameters specified was missing or invalid: object is incorrect");
|
|
|
|
|
|
|
|
$post = (new PostsRepo)->getPostById((int) $postArray[1], (int) $postArray[2]);
|
|
|
|
if(!$post || $post->isDeleted()) $this->fail(100, "One of the parameters specified was missing or invalid");
|
|
|
|
|
|
|
|
$nPost = new Post;
|
|
|
|
$nPost->setOwner($this->user->getId());
|
|
|
|
$nPost->setWall($this->user->getId());
|
|
|
|
$nPost->setContent($message);
|
2022-12-17 02:03:02 +03:00
|
|
|
$nPost->setApi_Source_Name($this->getPlatform());
|
2022-07-23 02:24:34 +03:00
|
|
|
$nPost->save();
|
|
|
|
$nPost->attach($post);
|
|
|
|
|
|
|
|
if($post->getOwner(false)->getId() !== $this->user->getId() && !($post->getOwner() instanceof Club))
|
|
|
|
(new RepostNotification($post->getOwner(false), $post, $this->user->identity))->emit();
|
|
|
|
|
|
|
|
return (object) [
|
|
|
|
"success" => 1, // 👍
|
|
|
|
"post_id" => $nPost->getVirtualId(),
|
|
|
|
"reposts_count" => $post->getRepostCount(),
|
|
|
|
"likes_count" => $post->getLikesCount()
|
|
|
|
];
|
|
|
|
}
|
2022-07-23 03:25:17 +03:00
|
|
|
|
2022-07-23 15:50:00 +03:00
|
|
|
function getComments(int $owner_id, int $post_id, bool $need_likes = true, int $offset = 0, int $count = 10, string $fields = "sex,screen_name,photo_50,photo_100,online_info,online", string $sort = "asc", bool $extended = false) {
|
|
|
|
$this->requireUser();
|
|
|
|
|
|
|
|
$post = (new PostsRepo)->getPostById($owner_id, $post_id);
|
|
|
|
if(!$post || $post->isDeleted()) $this->fail(100, "One of the parameters specified was missing or invalid");
|
|
|
|
|
|
|
|
$comments = (new CommentsRepo)->getCommentsByTarget($post, $offset+1, $count, $sort == "desc" ? "DESC" : "ASC");
|
|
|
|
|
|
|
|
$items = [];
|
|
|
|
$profiles = [];
|
|
|
|
|
|
|
|
foreach($comments as $comment) {
|
2022-11-28 18:20:27 +03:00
|
|
|
$owner = $comment->getOwner();
|
|
|
|
$oid = $owner->getId();
|
|
|
|
if($owner instanceof Club)
|
|
|
|
$oid *= -1;
|
|
|
|
|
2022-07-23 15:50:00 +03:00
|
|
|
$item = [
|
|
|
|
"id" => $comment->getId(),
|
2022-11-28 18:20:27 +03:00
|
|
|
"from_id" => $oid,
|
2022-07-23 15:50:00 +03:00
|
|
|
"date" => $comment->getPublicationTime()->timestamp(),
|
|
|
|
"text" => $comment->getText(false),
|
|
|
|
"post_id" => $post->getVirtualId(),
|
|
|
|
"owner_id" => $post->isPostedOnBehalfOfGroup() ? $post->getOwner()->getId() * -1 : $post->getOwner()->getId(),
|
|
|
|
"parents_stack" => [],
|
|
|
|
"thread" => [
|
|
|
|
"count" => 0,
|
|
|
|
"items" => [],
|
|
|
|
"can_post" => false,
|
|
|
|
"show_reply_button" => true,
|
|
|
|
"groups_can_post" => false,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
if($need_likes == true)
|
|
|
|
$item['likes'] = [
|
|
|
|
"can_like" => 1,
|
|
|
|
"count" => $comment->getLikesCount(),
|
|
|
|
"user_likes" => (int) $comment->hasLikeFrom($this->getUser()),
|
|
|
|
"can_publish" => 1
|
|
|
|
];
|
|
|
|
|
|
|
|
$items[] = $item;
|
|
|
|
if($extended == true)
|
|
|
|
$profiles[] = $comment->getOwner()->getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
"count" => (new CommentsRepo)->getCommentsCountByTarget($post),
|
|
|
|
"items" => $items,
|
|
|
|
"current_level_count" => (new CommentsRepo)->getCommentsCountByTarget($post),
|
|
|
|
"can_post" => true,
|
|
|
|
"show_reply_button" => true,
|
|
|
|
"groups_can_post" => false
|
|
|
|
];
|
|
|
|
|
|
|
|
if($extended == true) {
|
|
|
|
$profiles = array_unique($profiles);
|
|
|
|
$response['profiles'] = (!empty($profiles) ? (new Users)->get(implode(',', $profiles), $fields) : []);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (object) $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
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); // один хуй айди всех комментов общий
|
|
|
|
|
|
|
|
$profiles = [];
|
|
|
|
|
|
|
|
$item = [
|
|
|
|
"id" => $comment->getId(),
|
|
|
|
"from_id" => $comment->getOwner()->getId(),
|
|
|
|
"date" => $comment->getPublicationTime()->timestamp(),
|
|
|
|
"text" => $comment->getText(false),
|
|
|
|
"post_id" => $comment->getTarget()->getVirtualId(),
|
|
|
|
"owner_id" => $comment->getTarget()->isPostedOnBehalfOfGroup() ? $comment->getTarget()->getOwner()->getId() * -1 : $comment->getTarget()->getOwner()->getId(),
|
|
|
|
"parents_stack" => [],
|
|
|
|
"likes" => [
|
|
|
|
"can_like" => 1,
|
|
|
|
"count" => $comment->getLikesCount(),
|
|
|
|
"user_likes" => (int) $comment->hasLikeFrom($this->getUser()),
|
|
|
|
"can_publish" => 1
|
|
|
|
],
|
|
|
|
"thread" => [
|
|
|
|
"count" => 0,
|
|
|
|
"items" => [],
|
|
|
|
"can_post" => false,
|
|
|
|
"show_reply_button" => true,
|
|
|
|
"groups_can_post" => false,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
if($extended == true)
|
|
|
|
$profiles[] = $comment->getOwner()->getId();
|
|
|
|
|
|
|
|
$response = [
|
|
|
|
"items" => [$item],
|
|
|
|
"can_post" => true,
|
|
|
|
"show_reply_button" => true,
|
|
|
|
"groups_can_post" => false
|
|
|
|
];
|
|
|
|
|
|
|
|
if($extended == true) {
|
|
|
|
$profiles = array_unique($profiles);
|
|
|
|
$response['profiles'] = (!empty($profiles) ? (new Users)->get(implode(',', $profiles), $fields) : []);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createComment(int $owner_id, int $post_id, string $message, int $from_group = 0) {
|
|
|
|
$post = (new PostsRepo)->getPostById($owner_id, $post_id);
|
|
|
|
if(!$post || $post->isDeleted()) $this->fail(100, "One of the parameters specified was missing or invalid");
|
|
|
|
|
|
|
|
if($post->getTargetWall() < 0)
|
|
|
|
$club = (new ClubsRepo)->get(abs($post->getTargetWall()));
|
|
|
|
|
|
|
|
$flags = 0;
|
|
|
|
if($from_group != 0 && !is_null($club) && $club->canBeModifiedBy($this->user))
|
|
|
|
$flags |= 0b10000000;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$comment = new Comment;
|
|
|
|
$comment->setOwner($this->user->getId());
|
|
|
|
$comment->setModel(get_class($post));
|
|
|
|
$comment->setTarget($post->getId());
|
|
|
|
$comment->setContent($message);
|
|
|
|
$comment->setCreated(time());
|
|
|
|
$comment->setFlags($flags);
|
|
|
|
$comment->save();
|
|
|
|
} catch (\LengthException $ex) {
|
|
|
|
$this->fail(1, "ошибка про то что коммент большой слишком");
|
|
|
|
}
|
|
|
|
|
|
|
|
if($post->getOwner()->getId() !== $this->user->getId())
|
|
|
|
if(($owner = $post->getOwner()) instanceof User)
|
|
|
|
(new CommentNotification($owner, $comment, $post, $this->user))->emit();
|
|
|
|
|
|
|
|
return (object) [
|
|
|
|
"comment_id" => $comment->getId(),
|
|
|
|
"parents_stack" => []
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-07-29 12:41:43 +03:00
|
|
|
function deleteComment(int $comment_id) {
|
2022-07-23 15:50:00 +03:00
|
|
|
$this->requireUser();
|
|
|
|
|
|
|
|
$comment = (new CommentsRepo)->get($comment_id);
|
|
|
|
if(!$comment) $this->fail(100, "One of the parameters specified was missing or invalid");;
|
|
|
|
if(!$comment->canBeDeletedBy($this->user))
|
|
|
|
$this->fail(7, "Access denied");
|
|
|
|
|
|
|
|
$comment->delete();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2022-10-12 01:00:52 +03:00
|
|
|
|
2022-07-23 03:25:17 +03:00
|
|
|
private function getApiPhoto($attachment) {
|
|
|
|
return [
|
|
|
|
"type" => "photo",
|
|
|
|
"photo" => [
|
|
|
|
"album_id" => $attachment->getAlbum() ? $attachment->getAlbum()->getId() : NULL,
|
|
|
|
"date" => $attachment->getPublicationTime()->timestamp(),
|
|
|
|
"id" => $attachment->getVirtualId(),
|
|
|
|
"owner_id" => $attachment->getOwner()->getId(),
|
|
|
|
"sizes" => array_values($attachment->getVkApiSizes()),
|
|
|
|
"text" => "",
|
|
|
|
"has_tags" => false
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2022-10-12 01:00:52 +03:00
|
|
|
|
2022-10-12 12:23:57 +03:00
|
|
|
private function getApiPoll($attachment, $user) {
|
2022-10-12 01:00:52 +03:00
|
|
|
$answers = array();
|
|
|
|
foreach($attachment->getResults()->options as $answer) {
|
|
|
|
$answers[] = (object)[
|
|
|
|
"id" => $answer->id,
|
|
|
|
"rate" => $answer->pct,
|
|
|
|
"text" => $answer->name,
|
|
|
|
"votes" => $answer->votes
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$userVote = array();
|
2022-10-12 12:23:57 +03:00
|
|
|
foreach($attachment->getUserVote($user) as $vote)
|
2022-10-12 01:00:52 +03:00
|
|
|
$userVote[] = $vote[0];
|
|
|
|
|
|
|
|
return [
|
|
|
|
"type" => "poll",
|
|
|
|
"poll" => [
|
2022-10-17 23:24:10 +03:00
|
|
|
"multiple" => $attachment->isMultipleChoice(),
|
|
|
|
"end_date" => $attachment->endsAt() == NULL ? 0 : $attachment->endsAt()->timestamp(),
|
|
|
|
"closed" => $attachment->hasEnded(),
|
|
|
|
"is_board" => false,
|
|
|
|
"can_edit" => false,
|
|
|
|
"can_vote" => $attachment->canVote($user),
|
|
|
|
"can_report" => false,
|
|
|
|
"can_share" => true,
|
|
|
|
"created" => 0,
|
|
|
|
"id" => $attachment->getId(),
|
|
|
|
"owner_id" => $attachment->getOwner()->getId(),
|
|
|
|
"question" => $attachment->getTitle(),
|
|
|
|
"votes" => $attachment->getVoterCount(),
|
2022-10-12 01:00:52 +03:00
|
|
|
"disable_unvote" => $attachment->isRevotable(),
|
2022-10-17 23:24:10 +03:00
|
|
|
"anonymous" => $attachment->isAnonymous(),
|
|
|
|
"answer_ids" => $userVote,
|
|
|
|
"answers" => $answers,
|
|
|
|
"author_id" => $attachment->getOwner()->getId(),
|
2022-10-12 01:00:52 +03:00
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2020-08-12 14:36:18 +03:00
|
|
|
}
|