mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
new api methods: wall.post, utils.getServerTime
This commit is contained in:
parent
eedcf13466
commit
0f784212df
2 changed files with 55 additions and 0 deletions
10
VKAPI/Handlers/Utils.php
Normal file
10
VKAPI/Handlers/Utils.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\VKAPI\Handlers;
|
||||
|
||||
final class Utils extends VKAPIRequestHandler
|
||||
{
|
||||
function getServerTime(): int
|
||||
{
|
||||
return time();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\VKAPI\Handlers;
|
||||
use openvk\Web\Models\Entities\User;
|
||||
use openvk\Web\Models\Entities\Notifications\{WallPostNotification};
|
||||
use openvk\Web\Models\Repositories\Users as UsersRepo;
|
||||
use openvk\Web\Models\Entities\Club;
|
||||
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
|
||||
use openvk\Web\Models\Entities\Post;
|
||||
use openvk\Web\Models\Entities\Postable;
|
||||
use openvk\Web\Models\Repositories\Posts as PostsRepo;
|
||||
|
@ -61,4 +64,46 @@ final class Wall extends VKAPIRequestHandler
|
|||
"items" => (array)$items
|
||||
];
|
||||
}
|
||||
|
||||
function post(string $owner_id, string $message, int $from_group = 0): object
|
||||
{
|
||||
$this->requireUser();
|
||||
|
||||
$owner_id = intval($owner_id);
|
||||
|
||||
$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");
|
||||
|
||||
$flags = 0;
|
||||
if($from_group == 1)
|
||||
$flags |= 0b10000000;
|
||||
|
||||
try {
|
||||
$post = new Post;
|
||||
$post->setOwner($this->getUser()->getId());
|
||||
$post->setWall($owner_id);
|
||||
$post->setCreated(time());
|
||||
$post->setContent($message);
|
||||
$post->setFlags($flags);
|
||||
$post->save();
|
||||
} catch(\LogicException $ex) {
|
||||
$this->fail(100, "One of the parameters specified was missing or invalid");
|
||||
}
|
||||
|
||||
if($wall > 0 && $wall !== $this->user->identity->getId())
|
||||
(new WallPostNotification($wallOwner, $post, $this->user->identity))->emit();
|
||||
|
||||
return (object)["post_id" => $post->getVirtualId()];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue