diff --git a/VKAPI/Handlers/Newsfeed.php b/VKAPI/Handlers/Newsfeed.php index e5e687c7..52e7b5fa 100644 --- a/VKAPI/Handlers/Newsfeed.php +++ b/VKAPI/Handlers/Newsfeed.php @@ -51,8 +51,8 @@ final class Newsfeed extends VKAPIRequestHandler { $this->requireUser(); - $queryBase = "FROM `posts` JOIN `profiles` ON `profiles`.`id` = ABS(`posts`.`wall`) LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`)"; - $queryBase .= "WHERE (`profiles`.`profile_type` = 0 OR `profiles`.`first_name` IS NULL) AND (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND `posts`.`deleted` = 0"; + $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) LEFT JOIN `profiles` ON LEAST(`posts`.`wall`, 0) = 0 AND `profiles`.`id` = ABS(`posts`.`wall`)"; + $queryBase .= "WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND (`profiles`.`profile_type` = 0 OR `profiles`.`first_name` IS NULL) AND `posts`.`deleted` = 0"; if($this->getUser()->getNsfwTolerance() === User::NSFW_INTOLERANT) $queryBase .= " AND `nsfw` = 0"; diff --git a/VKAPI/Handlers/Polls.php b/VKAPI/Handlers/Polls.php index f901ab77..87852dc0 100755 --- a/VKAPI/Handlers/Polls.php +++ b/VKAPI/Handlers/Polls.php @@ -35,7 +35,11 @@ final class Polls extends VKAPIRequestHandler foreach($poll->getUserVote($this->getUser()) as $vote) $userVote[] = $vote[0]; - $ownerr = $poll->getAttachedPost()->getOwner() instanceof User ? $poll->getAttachedPost()->getOwner()->getId() : $poll->getAttachedPost()->getOwner()->getId() * -1; + $ownerr = 0; + if(!is_null($poll->getAttachedPost())) { + $ownerr = $poll->getAttachedPost()->getOwner() instanceof User ? $poll->getAttachedPost()->getOwner()->getId() : $poll->getAttachedPost()->getOwner()->getId() * -1; + } + $response = [ "multiple" => $poll->isMultipleChoice(), "end_date" => $poll->endsAt() == NULL ? 0 : $poll->endsAt()->timestamp(), @@ -45,7 +49,7 @@ final class Polls extends VKAPIRequestHandler "can_vote" => $poll->canVote($this->getUser()), "can_report" => false, "can_share" => true, - "created" => $poll->getAttachedPost()->getPublicationTime()->timestamp(), + "created" => $poll->getAttachedPost() ? $poll->getAttachedPost()->getPublicationTime()->timestamp() : 0, "id" => $poll->getId(), "owner_id" => $ownerr, "question" => $poll->getTitle(), diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 956c8428..dd7f1717 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -879,7 +879,12 @@ final class Wall extends VKAPIRequestHandler foreach($attachment->getUserVote($user) as $vote) $userVote[] = $vote[0]; - $ownerr = $attachment->getAttachedPost()->getOwner() instanceof User ? $attachment->getAttachedPost()->getOwner()->getId() : $attachment->getAttachedPost()->getOwner()->getId() * -1; + $ownerr = 0; + + if(!is_null($attachment->getAttachedPost())) { + $ownerr = $attachment->getAttachedPost()->getOwner() instanceof User ? $attachment->getAttachedPost()->getOwner()->getId() : $attachment->getAttachedPost()->getOwner()->getId() * -1; + } + return [ "type" => "poll", "poll" => [ @@ -891,7 +896,7 @@ final class Wall extends VKAPIRequestHandler "can_vote" => $attachment->canVote($user), "can_report" => false, "can_share" => true, - "created" => $attachment->getAttachedPost()->getPublicationTime()->timestamp(), + "created" => $attachment->getAttachedPost() ? $attachment->getAttachedPost()->getPublicationTime()->timestamp() : 0, "id" => $attachment->getId(), "owner_id" => $ownerr, "question" => $attachment->getTitle(), diff --git a/Web/Models/Entities/Poll.php b/Web/Models/Entities/Poll.php index b8bf0855..f466ac67 100644 --- a/Web/Models/Entities/Poll.php +++ b/Web/Models/Entities/Poll.php @@ -300,11 +300,20 @@ class Poll extends Attachable ["attachable_type" => static::class, "attachable_id" => $this->getId()])->fetch(); - return (new Posts)->get($post->target_id); + if(!is_null($post->target_id)) { + return (new Posts)->get($post->target_id); + } else { + return NULL; + } } function canBeViewedBy(?User $user = NULL): bool { - return $this->getAttachedPost()->canBeViewedBy($user); + if(!is_null($this->getAttachedPost())) { + return $this->getAttachedPost()->canBeViewedBy($user); + } else { + return true; + } + } } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 5ea1bf17..81149fb8 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -177,8 +177,8 @@ final class WallPresenter extends OpenVKPresenter $page = (int) ($_GET["p"] ?? 1); $pPage = min((int) ($_GET["posts"] ?? OPENVK_DEFAULT_PER_PAGE), 50); - $queryBase = "FROM `posts` JOIN `profiles` ON `profiles`.`id` = ABS(`posts`.`wall`) LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`)"; - $queryBase .= "WHERE (`profiles`.`profile_type` = 0 OR `profiles`.`first_name` IS NULL) AND (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND `posts`.`deleted` = 0"; + $queryBase = "FROM `posts` LEFT JOIN `groups` ON GREATEST(`posts`.`wall`, 0) = 0 AND `groups`.`id` = ABS(`posts`.`wall`) LEFT JOIN `profiles` ON LEAST(`posts`.`wall`, 0) = 0 AND `profiles`.`id` = ABS(`posts`.`wall`)"; + $queryBase .= "WHERE (`groups`.`hide_from_global_feed` = 0 OR `groups`.`name` IS NULL) AND (`profiles`.`profile_type` = 0 OR `profiles`.`first_name` IS NULL) AND `posts`.`deleted` = 0"; if($this->user->identity->getNsfwTolerance() === User::NSFW_INTOLERANT) $queryBase .= " AND `nsfw` = 0";